]> git.saurik.com Git - wxWidgets.git/blob - src/common/nbkbase.cpp
xti changes
[wxWidgets.git] / src / common / nbkbase.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/nbkbase.cpp
3 // Purpose: common wxNotebook methods
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 02.07.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_NOTEBOOK
28
29 #ifndef WX_PRECOMP
30 #endif //WX_PRECOMP
31
32 #include "wx/notebook.h"
33
34 // ============================================================================
35 // implementation
36 // ============================================================================
37
38 extern WXDLLEXPORT_DATA(const char) wxNotebookNameStr[] = "notebook";
39
40 wxDEFINE_EVENT( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxBookCtrlEvent );
41 wxDEFINE_EVENT( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxBookCtrlEvent );
42
43 #if wxUSE_EXTENDED_RTTI
44
45 // ----------------------------------------------------------------------------
46 // XTI
47 // ----------------------------------------------------------------------------
48
49 #include "wx/listimpl.cpp"
50 WX_DEFINE_LIST( wxNotebookPageInfoList )
51
52 wxDEFINE_FLAGS( wxNotebookStyle )
53 wxBEGIN_FLAGS( wxNotebookStyle )
54 // new style border flags, we put them first to
55 // use them for streaming out
56 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
57 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
58 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
59 wxFLAGS_MEMBER(wxBORDER_RAISED)
60 wxFLAGS_MEMBER(wxBORDER_STATIC)
61 wxFLAGS_MEMBER(wxBORDER_NONE)
62
63 // old style border flags
64 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
65 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
66 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
67 wxFLAGS_MEMBER(wxRAISED_BORDER)
68 wxFLAGS_MEMBER(wxSTATIC_BORDER)
69 wxFLAGS_MEMBER(wxBORDER)
70
71 // standard window styles
72 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
73 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
74 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
75 wxFLAGS_MEMBER(wxWANTS_CHARS)
76 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
77 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
78 wxFLAGS_MEMBER(wxVSCROLL)
79 wxFLAGS_MEMBER(wxHSCROLL)
80
81 wxFLAGS_MEMBER(wxNB_FIXEDWIDTH)
82 wxFLAGS_MEMBER(wxBK_DEFAULT)
83 wxFLAGS_MEMBER(wxBK_TOP)
84 wxFLAGS_MEMBER(wxBK_LEFT)
85 wxFLAGS_MEMBER(wxBK_RIGHT)
86 wxFLAGS_MEMBER(wxBK_BOTTOM)
87 wxFLAGS_MEMBER(wxNB_NOPAGETHEME)
88 wxFLAGS_MEMBER(wxNB_FLAT)
89 wxEND_FLAGS( wxNotebookStyle )
90
91 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl, "wx/notebook.h")
92 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject, "wx/notebook.h" )
93
94 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo *, wxNotebookPageInfoList );
95
96 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList,
97 wxAnyList &value)
98 {
99 wxListCollectionToAnyList<wxNotebookPageInfoList::compatibility_iterator>( theList, value );
100 }
101
102 wxBEGIN_PROPERTIES_TABLE(wxNotebook)
103 wxEVENT_PROPERTY( PageChanging, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEvent )
104 wxEVENT_PROPERTY( PageChanged, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEvent )
105
106 wxPROPERTY_COLLECTION( PageInfos, wxNotebookPageInfoList, wxNotebookPageInfo*, \
107 AddPageInfo, GetPageInfos, 0 /*flags*/, wxT("Helpstring"), \
108 wxT("group"))
109 wxPROPERTY_FLAGS( WindowStyle, wxNotebookStyle, long, SetWindowStyleFlag, \
110 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
111 wxT("Helpstring"), wxT("group")) // style
112 wxEND_PROPERTIES_TABLE()
113
114 wxEMPTY_HANDLERS_TABLE(wxNotebook)
115
116 wxCONSTRUCTOR_5( wxNotebook, wxWindow*, Parent, wxWindowID, Id, \
117 wxPoint, Position, wxSize, Size, long, WindowStyle)
118
119 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo)
120 wxREADONLY_PROPERTY( Page, wxNotebookPage*, GetPage, wxEMPTY_PARAMETER_VALUE, \
121 0 /*flags*/, wxT("Helpstring"), wxT("group"))
122 wxREADONLY_PROPERTY( Text, wxString, GetText, wxString(), 0 /*flags*/, \
123 wxT("Helpstring"), wxT("group"))
124 wxREADONLY_PROPERTY( Selected, bool, GetSelected, false, 0 /*flags*/, \
125 wxT("Helpstring"), wxT("group") )
126 wxREADONLY_PROPERTY( ImageId, int, GetImageId, -1, 0 /*flags*/, \
127 wxT("Helpstring"), wxT("group"))
128 wxEND_PROPERTIES_TABLE()
129
130 wxEMPTY_HANDLERS_TABLE(wxNotebookPageInfo)
131
132 wxCONSTRUCTOR_4( wxNotebookPageInfo, wxNotebookPage*, Page, \
133 wxString, Text, bool, Selected, int, ImageId )
134
135 WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxNotebookPageInfo**>)
136 // XTI accessors:
137
138 void wxNotebookBase::AddPageInfo( wxNotebookPageInfo* info )
139 {
140 AddPage( info->GetPage(), info->GetText(), info->GetSelected(), info->GetImageId() );
141 }
142
143 const wxNotebookPageInfoList& wxNotebookBase::GetPageInfos() const
144 {
145 wxNotebookPageInfoList* list = const_cast< wxNotebookPageInfoList* >( &m_pageInfos );
146 WX_CLEAR_LIST( wxNotebookPageInfoList, *list );
147 for( size_t i = 0; i < GetPageCount(); ++i )
148 {
149 wxNotebookPageInfo *info = new wxNotebookPageInfo();
150 info->Create( const_cast<wxNotebookBase*>(this)->GetPage(i), GetPageText(i),
151 GetSelection() == int(i), GetPageImage(i) );
152 list->Append( info );
153 }
154 return m_pageInfos;
155 }
156
157 #endif
158
159 // ----------------------------------------------------------------------------
160 // geometry
161 // ----------------------------------------------------------------------------
162
163 wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
164 {
165 // this is, of course, totally bogus -- but we must do something by
166 // default because not all ports implement this
167 wxSize sizeTotal = sizePage;
168
169 if ( HasFlag(wxBK_LEFT) || HasFlag(wxBK_RIGHT) )
170 {
171 sizeTotal.x += 90;
172 sizeTotal.y += 10;
173 }
174 else // tabs on top/bottom side
175 {
176 sizeTotal.x += 10;
177 sizeTotal.y += 40;
178 }
179
180 return sizeTotal;
181 }
182
183 // ----------------------------------------------------------------------------
184 // events
185 // ----------------------------------------------------------------------------
186
187 bool wxNotebookBase::SendPageChangingEvent(int nPage)
188 {
189 wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, GetId());
190 event.SetSelection(nPage);
191 event.SetOldSelection(GetSelection());
192 event.SetEventObject(this);
193 return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed();
194 }
195
196 void wxNotebookBase::SendPageChangedEvent(int nPageOld, int nPageNew)
197 {
198 wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, GetId());
199 event.SetSelection(nPageNew == -1 ? GetSelection() : nPageNew);
200 event.SetOldSelection(nPageOld);
201 event.SetEventObject(this);
202 GetEventHandler()->ProcessEvent(event);
203 }
204
205 #endif // wxUSE_NOTEBOOK