1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/nbkbase.cpp
3 // Purpose: common wxNotebook methods
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2001 Vadim Zeitlin
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
31 #include "wx/notebook.h"
33 // ============================================================================
35 // ============================================================================
37 extern WXDLLEXPORT_DATA(const char) wxNotebookNameStr
[] = "notebook";
39 wxDEFINE_EVENT( wxEVT_NOTEBOOK_PAGE_CHANGED
, wxBookCtrlEvent
);
40 wxDEFINE_EVENT( wxEVT_NOTEBOOK_PAGE_CHANGING
, wxBookCtrlEvent
);
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
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
)
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
)
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
)
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
)
86 #if wxUSE_EXTENDED_RTTI
88 WX_DEFINE_LIST( wxNotebookPageInfoList
)
90 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo
, wxObject
, "wx/notebook.h" )
92 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo
*, wxNotebookPageInfoList
);
94 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
,
97 wxListCollectionToAnyList
<wxNotebookPageInfoList::compatibility_iterator
>( theList
, value
);
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()
111 wxEMPTY_HANDLERS_TABLE(wxNotebookPageInfo
)
113 wxCONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
*, Page
, \
114 wxString
, Text
, bool, Selected
, int, ImageId
)
116 // WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxNotebookPageInfo**>)
119 void wxNotebookBase::AddPageInfo( wxNotebookPageInfo
* info
)
121 AddPage( info
->GetPage(), info
->GetText(), info
->GetSelected(), info
->GetImageId() );
124 const wxNotebookPageInfoList
& wxNotebookBase::GetPageInfos() const
126 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
);
127 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
);
128 for( size_t i
= 0; i
< GetPageCount(); ++i
)
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
);
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
)
145 wxPROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
*, \
146 AddPageInfo
, GetPageInfos
, 0 /*flags*/, wxT("Helpstring"), \
148 wxPROPERTY_FLAGS( WindowStyle
, wxNotebookStyle
, long, SetWindowStyleFlag
, \
149 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
150 wxT("Helpstring"), wxT("group")) // style
151 wxEND_PROPERTIES_TABLE()
153 wxEMPTY_HANDLERS_TABLE(wxNotebook
)
155 wxCONSTRUCTOR_5( wxNotebook
, wxWindow
*, Parent
, wxWindowID
, Id
, \
156 wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 wxSize
wxNotebookBase::CalcSizeFromPage(const wxSize
& sizePage
) const
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
;
168 if ( HasFlag(wxBK_LEFT
) || HasFlag(wxBK_RIGHT
) )
173 else // tabs on top/bottom side
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 bool wxNotebookBase::SendPageChangingEvent(int nPage
)
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();
195 void wxNotebookBase::SendPageChangedEvent(int nPageOld
, int nPageNew
)
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
);
204 #endif // wxUSE_NOTEBOOK