move variable definitions to more appropriate places, remove now-empty src/common...
[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 #if wxUSE_EXTENDED_RTTI
97 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList,
98 wxVariantBaseArray &value)
99 {
100 wxListCollectionToVariantArray<wxNotebookPageInfoList::compatibility_iterator>( theList, value );
101 }
102 #endif
103
104 wxBEGIN_PROPERTIES_TABLE(wxNotebook)
105 wxEVENT_PROPERTY( PageChanging, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEvent )
106 wxEVENT_PROPERTY( PageChanged, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEvent )
107
108 wxPROPERTY_COLLECTION( PageInfos, wxNotebookPageInfoList, wxNotebookPageInfo*, \
109 AddPageInfo, GetPageInfos, 0 /*flags*/, wxT("Helpstring"), \
110 wxT("group"))
111 wxPROPERTY_FLAGS( WindowStyle, wxNotebookStyle, long, SetWindowStyleFlag, \
112 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
113 wxT("Helpstring"), wxT("group")) // style
114 wxEND_PROPERTIES_TABLE()
115
116 wxEMPTY_HANDLERS_TABLE(wxNotebook)
117
118 wxCONSTRUCTOR_5( wxNotebook, wxWindow*, Parent, wxWindowID, Id, \
119 wxPoint, Position, wxSize, Size, long, WindowStyle)
120
121 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo)
122 wxREADONLY_PROPERTY( Page, wxNotebookPage*, GetPage, wxEMPTY_PARAMETER_VALUE, \
123 0 /*flags*/, wxT("Helpstring"), wxT("group"))
124 wxREADONLY_PROPERTY( Text, wxString, GetText, wxString(), 0 /*flags*/, \
125 wxT("Helpstring"), wxT("group"))
126 wxREADONLY_PROPERTY( Selected, bool, GetSelected, false, 0 /*flags*/, \
127 wxT("Helpstring"), wxT("group") )
128 wxREADONLY_PROPERTY( ImageId, int, GetImageId, -1, 0 /*flags*/, \
129 wxT("Helpstring"), wxT("group"))
130 wxEND_PROPERTIES_TABLE()
131
132 wxEMPTY_HANDLERS_TABLE(wxNotebookPageInfo)
133
134 wxCONSTRUCTOR_4( wxNotebookPageInfo, wxNotebookPage*, Page, \
135 wxString, Text, bool, Selected, int, ImageId )
136
137 // XTI accessors:
138
139 void wxNotebookBase::AddPageInfo( wxNotebookPageInfo* info )
140 {
141 AddPage( info->GetPage(), info->GetText(), info->GetSelected(), info->GetImageId() );
142 }
143
144 const wxNotebookPageInfoList& wxNotebookBase::GetPageInfos() const
145 {
146 wxNotebookPageInfoList* list = const_cast< wxNotebookPageInfoList* >( &m_pageInfos );
147 WX_CLEAR_LIST( wxNotebookPageInfoList, *list );
148 for( size_t i = 0; i < GetPageCount(); ++i )
149 {
150 wxNotebookPageInfo *info = new wxNotebookPageInfo();
151 info->Create( const_cast<wxNotebookBase*>(this)->GetPage(i), GetPageText(i),
152 GetSelection() == int(i), GetPageImage(i) );
153 list->Append( info );
154 }
155 return m_pageInfos;
156 }
157
158 #endif
159
160 // ----------------------------------------------------------------------------
161 // geometry
162 // ----------------------------------------------------------------------------
163
164 wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
165 {
166 // this is, of course, totally bogus -- but we must do something by
167 // default because not all ports implement this
168 wxSize sizeTotal = sizePage;
169
170 if ( HasFlag(wxBK_LEFT) || HasFlag(wxBK_RIGHT) )
171 {
172 sizeTotal.x += 90;
173 sizeTotal.y += 10;
174 }
175 else // tabs on top/bottom side
176 {
177 sizeTotal.x += 10;
178 sizeTotal.y += 40;
179 }
180
181 return sizeTotal;
182 }
183
184 // ----------------------------------------------------------------------------
185 // events
186 // ----------------------------------------------------------------------------
187
188 bool wxNotebookBase::SendPageChangingEvent(int nPage)
189 {
190 wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, GetId());
191 event.SetSelection(nPage);
192 event.SetOldSelection(GetSelection());
193 event.SetEventObject(this);
194 return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed();
195 }
196
197 void wxNotebookBase::SendPageChangedEvent(int nPageOld, int nPageNew)
198 {
199 wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, GetId());
200 event.SetSelection(nPageNew == -1 ? GetSelection() : nPageNew);
201 event.SetOldSelection(nPageOld);
202 event.SetEventObject(this);
203 GetEventHandler()->ProcessEvent(event);
204 }
205
206 #endif // wxUSE_NOTEBOOK