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