1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/nbkbase.cpp
3 // Purpose: common wxNotebook methods
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
32 #include "wx/notebook.h"
34 // ============================================================================
36 // ============================================================================
38 extern WXDLLEXPORT_DATA(const char) wxNotebookNameStr
[] = "notebook";
40 wxDEFINE_EVENT( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, wxBookCtrlEvent
);
41 wxDEFINE_EVENT( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, wxBookCtrlEvent
);
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 #include "wx/listimpl.cpp"
48 wxDEFINE_FLAGS( wxNotebookStyle
)
49 wxBEGIN_FLAGS( wxNotebookStyle
)
50 // new style border flags, we put them first to
51 // use them for streaming out
52 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
53 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
54 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
55 wxFLAGS_MEMBER(wxBORDER_RAISED
)
56 wxFLAGS_MEMBER(wxBORDER_STATIC
)
57 wxFLAGS_MEMBER(wxBORDER_NONE
)
59 // old style border flags
60 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
61 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
62 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
63 wxFLAGS_MEMBER(wxRAISED_BORDER
)
64 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
65 wxFLAGS_MEMBER(wxBORDER
)
67 // standard window styles
68 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
69 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
70 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
71 wxFLAGS_MEMBER(wxWANTS_CHARS
)
72 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
73 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
74 wxFLAGS_MEMBER(wxVSCROLL
)
75 wxFLAGS_MEMBER(wxHSCROLL
)
77 wxFLAGS_MEMBER(wxNB_FIXEDWIDTH
)
78 wxFLAGS_MEMBER(wxBK_DEFAULT
)
79 wxFLAGS_MEMBER(wxBK_TOP
)
80 wxFLAGS_MEMBER(wxBK_LEFT
)
81 wxFLAGS_MEMBER(wxBK_RIGHT
)
82 wxFLAGS_MEMBER(wxBK_BOTTOM
)
83 wxFLAGS_MEMBER(wxNB_NOPAGETHEME
)
84 wxFLAGS_MEMBER(wxNB_FLAT
)
85 wxEND_FLAGS( wxNotebookStyle
)
87 #if wxUSE_EXTENDED_RTTI
89 WX_DEFINE_LIST( wxNotebookPageInfoList
)
91 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo
, wxObject
, "wx/notebook.h" )
93 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo
*, wxNotebookPageInfoList
);
95 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
,
98 wxListCollectionToAnyList
<wxNotebookPageInfoList::compatibility_iterator
>( theList
, value
);
101 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo
)
102 wxREADONLY_PROPERTY( Page
, wxNotebookPage
*, GetPage
, wxEMPTY_PARAMETER_VALUE
, \
103 0 /*flags*/, wxT("Helpstring"), wxT("group"))
104 wxREADONLY_PROPERTY( Text
, wxString
, GetText
, wxString(), 0 /*flags*/, \
105 wxT("Helpstring"), wxT("group"))
106 wxREADONLY_PROPERTY( Selected
, bool, GetSelected
, false, 0 /*flags*/, \
107 wxT("Helpstring"), wxT("group") )
108 wxREADONLY_PROPERTY( ImageId
, int, GetImageId
, -1, 0 /*flags*/, \
109 wxT("Helpstring"), wxT("group"))
110 wxEND_PROPERTIES_TABLE()
112 wxEMPTY_HANDLERS_TABLE(wxNotebookPageInfo
)
114 wxCONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
*, Page
, \
115 wxString
, Text
, bool, Selected
, int, ImageId
)
117 // WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxNotebookPageInfo**>)
120 void wxNotebookBase::AddPageInfo( wxNotebookPageInfo
* info
)
122 AddPage( info
->GetPage(), info
->GetText(), info
->GetSelected(), info
->GetImageId() );
125 const wxNotebookPageInfoList
& wxNotebookBase::GetPageInfos() const
127 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
);
128 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
);
129 for( size_t i
= 0; i
< GetPageCount(); ++i
)
131 wxNotebookPageInfo
*info
= new wxNotebookPageInfo();
132 info
->Create( const_cast<wxNotebookBase
*>(this)->GetPage(i
), GetPageText(i
),
133 GetSelection() == int(i
), GetPageImage(i
) );
134 list
->Append( info
);
141 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook
, wxControl
, "wx/notebook.h")
142 wxBEGIN_PROPERTIES_TABLE(wxNotebook
)
143 wxEVENT_PROPERTY( PageChanging
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, wxNotebookEvent
)
144 wxEVENT_PROPERTY( PageChanged
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, wxNotebookEvent
)
146 wxPROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
*, \
147 AddPageInfo
, GetPageInfos
, 0 /*flags*/, wxT("Helpstring"), \
149 wxPROPERTY_FLAGS( WindowStyle
, wxNotebookStyle
, long, SetWindowStyleFlag
, \
150 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
151 wxT("Helpstring"), wxT("group")) // style
152 wxEND_PROPERTIES_TABLE()
154 wxEMPTY_HANDLERS_TABLE(wxNotebook
)
156 wxCONSTRUCTOR_5( wxNotebook
, wxWindow
*, Parent
, wxWindowID
, Id
, \
157 wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 wxSize
wxNotebookBase::CalcSizeFromPage(const wxSize
& sizePage
) const
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
;
169 if ( HasFlag(wxBK_LEFT
) || HasFlag(wxBK_RIGHT
) )
174 else // tabs on top/bottom side
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 bool wxNotebookBase::SendPageChangingEvent(int nPage
)
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();
196 void wxNotebookBase::SendPageChangedEvent(int nPageOld
, int nPageNew
)
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
);
205 #endif // wxUSE_NOTEBOOK