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