]> git.saurik.com Git - wxWidgets.git/blob - src/common/nbkbase.cpp
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[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 // Copyright: (c) 2001 Vadim Zeitlin
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
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
29 #endif //WX_PRECOMP
30
31 #include "wx/notebook.h"
32
33 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 extern WXDLLEXPORT_DATA(const char) wxNotebookNameStr[] = "notebook";
38
39 wxDEFINE_EVENT( wxEVT_NOTEBOOK_PAGE_CHANGED, wxBookCtrlEvent );
40 wxDEFINE_EVENT( wxEVT_NOTEBOOK_PAGE_CHANGING, wxBookCtrlEvent );
41
42 // ----------------------------------------------------------------------------
43 // XTI
44 // ----------------------------------------------------------------------------
45
46 #include "wx/listimpl.cpp"
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
86 #if wxUSE_EXTENDED_RTTI
87
88 WX_DEFINE_LIST( wxNotebookPageInfoList )
89
90 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject, "wx/notebook.h" )
91
92 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo *, wxNotebookPageInfoList );
93
94 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList,
95 wxAnyList &value)
96 {
97 wxListCollectionToAnyList<wxNotebookPageInfoList::compatibility_iterator>( theList, value );
98 }
99
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
116 // WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxNotebookPageInfo**>)
117 // XTI accessors:
118
119 void wxNotebookBase::AddPageInfo( wxNotebookPageInfo* info )
120 {
121 AddPage( info->GetPage(), info->GetText(), info->GetSelected(), info->GetImageId() );
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
140 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxBookCtrlBase, "wx/notebook.h")
141 wxBEGIN_PROPERTIES_TABLE(wxNotebook)
142 wxEVENT_PROPERTY( PageChanging, wxEVT_NOTEBOOK_PAGE_CHANGING, wxNotebookEvent )
143 wxEVENT_PROPERTY( PageChanged, wxEVT_NOTEBOOK_PAGE_CHANGED, wxNotebookEvent )
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
158 // ----------------------------------------------------------------------------
159 // geometry
160 // ----------------------------------------------------------------------------
161
162 wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
163 {
164 // this is, of course, totally bogus -- but we must do something by
165 // default because not all ports implement this
166 wxSize sizeTotal = sizePage;
167
168 if ( HasFlag(wxBK_LEFT) || HasFlag(wxBK_RIGHT) )
169 {
170 sizeTotal.x += 90;
171 sizeTotal.y += 10;
172 }
173 else // tabs on top/bottom side
174 {
175 sizeTotal.x += 10;
176 sizeTotal.y += 40;
177 }
178
179 return sizeTotal;
180 }
181
182 // ----------------------------------------------------------------------------
183 // events
184 // ----------------------------------------------------------------------------
185
186 bool wxNotebookBase::SendPageChangingEvent(int nPage)
187 {
188 wxBookCtrlEvent event(wxEVT_NOTEBOOK_PAGE_CHANGING, GetId());
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 {
197 wxBookCtrlEvent event(wxEVT_NOTEBOOK_PAGE_CHANGED, GetId());
198 event.SetSelection(nPageNew == -1 ? GetSelection() : nPageNew);
199 event.SetOldSelection(nPageOld);
200 event.SetEventObject(this);
201 GetEventHandler()->ProcessEvent(event);
202 }
203
204 #endif // wxUSE_NOTEBOOK