| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: _notebook.i |
| 3 | // Purpose: SWIG interface defs for wxNotebook and such |
| 4 | // |
| 5 | // Author: Robin Dunn |
| 6 | // |
| 7 | // Created: 2-June-1998 |
| 8 | // RCS-ID: $Id$ |
| 9 | // Copyright: (c) 2003 by Total Control Software |
| 10 | // Licence: wxWindows license |
| 11 | ///////////////////////////////////////////////////////////////////////////// |
| 12 | |
| 13 | // Not a %module |
| 14 | |
| 15 | |
| 16 | //--------------------------------------------------------------------------- |
| 17 | |
| 18 | MAKE_CONST_WXSTRING(NOTEBOOK_NAME); |
| 19 | |
| 20 | //--------------------------------------------------------------------------- |
| 21 | %newgroup |
| 22 | |
| 23 | // TODO: Virtualize this class so other book controls can be derived in Python |
| 24 | |
| 25 | MustHaveApp(wxBookCtrlBase); |
| 26 | |
| 27 | // Common base class for wxList/Tree/Notebook |
| 28 | class wxBookCtrlBase : public wxControl |
| 29 | { |
| 30 | public: |
| 31 | // This is an ABC, it can't be constructed... |
| 32 | |
| 33 | // wxBookCtrlBase(wxWindow *parent, |
| 34 | // wxWindowID id, |
| 35 | // const wxPoint& pos = wxDefaultPosition, |
| 36 | // const wxSize& size = wxDefaultSize, |
| 37 | // long style = 0, |
| 38 | // const wxString& name = wxPyEmptyString); |
| 39 | // %name(PreBookCtrlBase)wxBookCtrlBase(); |
| 40 | // bool Create(wxWindow *parent, |
| 41 | // wxWindowID id, |
| 42 | // const wxPoint& pos = wxDefaultPosition, |
| 43 | // const wxSize& size = wxDefaultSize, |
| 44 | // long style = 0, |
| 45 | // const wxString& name = wxPyEmptyString); |
| 46 | |
| 47 | |
| 48 | // get number of pages in the dialog |
| 49 | virtual size_t GetPageCount() const; |
| 50 | |
| 51 | // get the panel which represents the given page |
| 52 | virtual wxWindow *GetPage(size_t n); |
| 53 | |
| 54 | // get the current page or NULL if none |
| 55 | wxWindow* GetCurrentPage() const; |
| 56 | |
| 57 | // get the currently selected page or wxNOT_FOUND if none |
| 58 | virtual int GetSelection() const/* = 0*/; |
| 59 | |
| 60 | // set/get the title of a page |
| 61 | virtual bool SetPageText(size_t n, const wxString& strText)/* = 0*/; |
| 62 | virtual wxString GetPageText(size_t n) const/* = 0*/; |
| 63 | |
| 64 | |
| 65 | // image list stuff: each page may have an image associated with it (all |
| 66 | // images belong to the same image list) |
| 67 | |
| 68 | // sets the image list to use, it is *not* deleted by the control |
| 69 | virtual void SetImageList(wxImageList *imageList); |
| 70 | |
| 71 | // as SetImageList() but we will delete the image list ourselves |
| 72 | %apply SWIGTYPE *DISOWN { wxImageList *imageList }; |
| 73 | void AssignImageList(wxImageList *imageList); |
| 74 | %clear wxImageList *imageList; |
| 75 | |
| 76 | // get pointer (may be NULL) to the associated image list |
| 77 | wxImageList* GetImageList() const; |
| 78 | |
| 79 | // sets/returns item's image index in the current image list |
| 80 | virtual int GetPageImage(size_t n) const/* = 0*/; |
| 81 | virtual bool SetPageImage(size_t n, int imageId)/* = 0*/; |
| 82 | |
| 83 | |
| 84 | // resize the notebook so that all pages will have the specified size |
| 85 | virtual void SetPageSize(const wxSize& size); |
| 86 | |
| 87 | // calculate the size of the control from the size of its page |
| 88 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const/* = 0*/; |
| 89 | |
| 90 | |
| 91 | |
| 92 | // remove one page from the control and delete it |
| 93 | virtual bool DeletePage(size_t n); |
| 94 | |
| 95 | // remove one page from the notebook, without deleting it |
| 96 | virtual bool RemovePage(size_t n); |
| 97 | |
| 98 | // remove all pages and delete them |
| 99 | virtual bool DeleteAllPages(); |
| 100 | |
| 101 | // adds a new page to the control |
| 102 | virtual bool AddPage(wxWindow *page, |
| 103 | const wxString& text, |
| 104 | bool select = false, |
| 105 | int imageId = -1); |
| 106 | |
| 107 | // the same as AddPage(), but adds the page at the specified position |
| 108 | virtual bool InsertPage(size_t n, |
| 109 | wxWindow *page, |
| 110 | const wxString& text, |
| 111 | bool select = false, |
| 112 | int imageId = -1)/* = 0*/; |
| 113 | |
| 114 | // set the currently selected page, return the index of the previously |
| 115 | // selected one (or -1 on error) |
| 116 | // |
| 117 | // NB: this function will _not_ generate PAGE_CHANGING/ED events |
| 118 | virtual int SetSelection(size_t n)/* = 0*/; |
| 119 | |
| 120 | |
| 121 | // cycle thru the pages |
| 122 | void AdvanceSelection(bool forward = true); |
| 123 | |
| 124 | static wxVisualAttributes |
| 125 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); |
| 126 | }; |
| 127 | |
| 128 | |
| 129 | |
| 130 | class wxBookCtrlBaseEvent : public wxNotifyEvent |
| 131 | { |
| 132 | public: |
| 133 | wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int id = 0, |
| 134 | int nSel = -1, int nOldSel = -1); |
| 135 | |
| 136 | // the currently selected page (-1 if none) |
| 137 | int GetSelection() const; |
| 138 | void SetSelection(int nSel); |
| 139 | // the page that was selected before the change (-1 if none) |
| 140 | int GetOldSelection() const; |
| 141 | void SetOldSelection(int nOldSel); |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | |
| 146 | //--------------------------------------------------------------------------- |
| 147 | %newgroup |
| 148 | |
| 149 | enum { |
| 150 | // styles |
| 151 | wxNB_FIXEDWIDTH, |
| 152 | wxNB_TOP, |
| 153 | wxNB_LEFT, |
| 154 | wxNB_RIGHT, |
| 155 | wxNB_BOTTOM, |
| 156 | wxNB_MULTILINE, |
| 157 | |
| 158 | // hittest flags |
| 159 | wxNB_HITTEST_NOWHERE = 1, // not on tab |
| 160 | wxNB_HITTEST_ONICON = 2, // on icon |
| 161 | wxNB_HITTEST_ONLABEL = 4, // on label |
| 162 | wxNB_HITTEST_ONITEM = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL, |
| 163 | |
| 164 | }; |
| 165 | |
| 166 | |
| 167 | |
| 168 | MustHaveApp(wxNotebook); |
| 169 | |
| 170 | class wxNotebook : public wxBookCtrlBase { |
| 171 | public: |
| 172 | %pythonAppend wxNotebook "self._setOORInfo(self)" |
| 173 | %pythonAppend wxNotebook() "" |
| 174 | %typemap(out) wxNotebook*; // turn off this typemap |
| 175 | |
| 176 | wxNotebook(wxWindow *parent, |
| 177 | wxWindowID id=-1, |
| 178 | const wxPoint& pos = wxDefaultPosition, |
| 179 | const wxSize& size = wxDefaultSize, |
| 180 | long style = 0, |
| 181 | const wxString& name = wxPyNOTEBOOK_NAME); |
| 182 | %name(PreNotebook)wxNotebook(); |
| 183 | |
| 184 | // Turn it back on again |
| 185 | %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); } |
| 186 | |
| 187 | bool Create(wxWindow *parent, |
| 188 | wxWindowID id=-1, |
| 189 | const wxPoint& pos = wxDefaultPosition, |
| 190 | const wxSize& size = wxDefaultSize, |
| 191 | long style = 0, |
| 192 | const wxString& name = wxPyNOTEBOOK_NAME); |
| 193 | |
| 194 | |
| 195 | // get the number of rows for a control with wxNB_MULTILINE style (not all |
| 196 | // versions support it - they will always return 1 then) |
| 197 | virtual int GetRowCount() const; |
| 198 | |
| 199 | // set the padding between tabs (in pixels) |
| 200 | virtual void SetPadding(const wxSize& padding); |
| 201 | |
| 202 | // set the size of the tabs for wxNB_FIXEDWIDTH controls |
| 203 | virtual void SetTabSize(const wxSize& sz); |
| 204 | |
| 205 | // hit test, returns which tab is hit and, optionally, where (icon, label) |
| 206 | // (not implemented on all platforms) |
| 207 | DocDeclAStr( |
| 208 | virtual int, HitTest(const wxPoint& pt, long* OUTPUT) const, |
| 209 | "HitTest(Point pt) -> (tab, where)", |
| 210 | "Returns the tab which is hit, and flags indicating where using |
| 211 | wx.NB_HITTEST flags.", ""); |
| 212 | |
| 213 | // implement some base class functions |
| 214 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; |
| 215 | |
| 216 | static wxVisualAttributes |
| 217 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); |
| 218 | }; |
| 219 | |
| 220 | |
| 221 | |
| 222 | class wxNotebookEvent : public wxBookCtrlBaseEvent |
| 223 | { |
| 224 | public: |
| 225 | wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, |
| 226 | int nSel = -1, int nOldSel = -1); |
| 227 | |
| 228 | }; |
| 229 | |
| 230 | // notebook control event types |
| 231 | %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED; |
| 232 | %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING; |
| 233 | |
| 234 | |
| 235 | %pythoncode { |
| 236 | %# wxNotebook events |
| 237 | EVT_NOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 1 ) |
| 238 | EVT_NOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 1 ) |
| 239 | } |
| 240 | |
| 241 | |
| 242 | %pythoncode { |
| 243 | %#---------------------------------------------------------------------------- |
| 244 | |
| 245 | class NotebookPage(wx.Panel): |
| 246 | """ |
| 247 | There is an old (and apparently unsolvable) bug when placing a |
| 248 | window with a nonstandard background colour in a wxNotebook on |
| 249 | wxGTK, as the notbooks's background colour would always be used |
| 250 | when the window is refreshed. The solution is to place a panel in |
| 251 | the notbook and the coloured window on the panel, sized to cover |
| 252 | the panel. This simple class does that for you, just put an |
| 253 | instance of this in the notebook and make your regular window a |
| 254 | child of this one and it will handle the resize for you. |
| 255 | """ |
| 256 | def __init__(self, parent, id=-1, |
| 257 | pos=wx.DefaultPosition, size=wx.DefaultSize, |
| 258 | style=wx.TAB_TRAVERSAL, name="panel"): |
| 259 | wx.Panel.__init__(self, parent, id, pos, size, style, name) |
| 260 | self.child = None |
| 261 | EVT_SIZE(self, self.OnSize) |
| 262 | |
| 263 | def OnSize(self, evt): |
| 264 | if self.child is None: |
| 265 | children = self.GetChildren() |
| 266 | if len(children): |
| 267 | self.child = children[0] |
| 268 | if self.child: |
| 269 | self.child.SetPosition((0,0)) |
| 270 | self.child.SetSize(self.GetSize()) |
| 271 | |
| 272 | } |
| 273 | |
| 274 | //--------------------------------------------------------------------------- |
| 275 | %newgroup |
| 276 | |
| 277 | |
| 278 | enum |
| 279 | { |
| 280 | // default alignment: left everywhere except Mac where it is top |
| 281 | wxLB_DEFAULT = 0, |
| 282 | |
| 283 | // put the list control to the left/right/top/bottom of the page area |
| 284 | wxLB_TOP = 0x1, |
| 285 | wxLB_BOTTOM = 0x2, |
| 286 | wxLB_LEFT = 0x4, |
| 287 | wxLB_RIGHT = 0x8, |
| 288 | |
| 289 | // the mask which can be used to extract the alignment from the style |
| 290 | wxLB_ALIGN_MASK = 0xf, |
| 291 | }; |
| 292 | |
| 293 | |
| 294 | |
| 295 | MustHaveApp(wxListbook); |
| 296 | |
| 297 | // wxListCtrl and wxNotebook combination |
| 298 | class wxListbook : public wxBookCtrlBase |
| 299 | { |
| 300 | public: |
| 301 | %pythonAppend wxListbook "self._setOORInfo(self)" |
| 302 | %pythonAppend wxListbook() "" |
| 303 | |
| 304 | wxListbook(wxWindow *parent, |
| 305 | wxWindowID id=-1, |
| 306 | const wxPoint& pos = wxDefaultPosition, |
| 307 | const wxSize& size = wxDefaultSize, |
| 308 | long style = 0, |
| 309 | const wxString& name = wxPyEmptyString); |
| 310 | %name(PreListbook)wxListbook(); |
| 311 | |
| 312 | bool Create(wxWindow *parent, |
| 313 | wxWindowID id=-1, |
| 314 | const wxPoint& pos = wxDefaultPosition, |
| 315 | const wxSize& size = wxDefaultSize, |
| 316 | long style = 0, |
| 317 | const wxString& name = wxPyEmptyString); |
| 318 | |
| 319 | // returns True if we have wxLB_TOP or wxLB_BOTTOM style |
| 320 | bool IsVertical() const; |
| 321 | |
| 322 | wxListView* GetListView(); |
| 323 | }; |
| 324 | |
| 325 | |
| 326 | |
| 327 | class wxListbookEvent : public wxBookCtrlBaseEvent |
| 328 | { |
| 329 | public: |
| 330 | wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, |
| 331 | int nSel = -1, int nOldSel = -1); |
| 332 | }; |
| 333 | |
| 334 | |
| 335 | %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED; |
| 336 | %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING; |
| 337 | |
| 338 | %pythoncode { |
| 339 | EVT_LISTBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, 1 ) |
| 340 | EVT_LISTBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, 1 ) |
| 341 | } |
| 342 | |
| 343 | |
| 344 | //--------------------------------------------------------------------------- |
| 345 | |
| 346 | |
| 347 | /* |
| 348 | * wxChoicebook flags |
| 349 | */ |
| 350 | enum { |
| 351 | wxCHB_DEFAULT, |
| 352 | wxCHB_TOP, |
| 353 | wxCHB_BOTTOM, |
| 354 | wxCHB_LEFT, |
| 355 | wxCHB_RIGHT, |
| 356 | wxCHB_ALIGN_MASK |
| 357 | }; |
| 358 | |
| 359 | |
| 360 | MustHaveApp(wxChoicebook); |
| 361 | |
| 362 | class wxChoicebook : public wxBookCtrlBase |
| 363 | { |
| 364 | public: |
| 365 | %pythonAppend wxChoicebook "self._setOORInfo(self)" |
| 366 | %pythonAppend wxChoicebook() "" |
| 367 | |
| 368 | wxChoicebook(wxWindow *parent, |
| 369 | wxWindowID id, |
| 370 | const wxPoint& pos = wxDefaultPosition, |
| 371 | const wxSize& size = wxDefaultSize, |
| 372 | long style = 0, |
| 373 | const wxString& name = wxPyEmptyString); |
| 374 | %name(PreChoicebook)wxChoicebook(); |
| 375 | |
| 376 | // quasi ctor |
| 377 | bool Create(wxWindow *parent, |
| 378 | wxWindowID id, |
| 379 | const wxPoint& pos = wxDefaultPosition, |
| 380 | const wxSize& size = wxDefaultSize, |
| 381 | long style = 0, |
| 382 | const wxString& name = wxPyEmptyString); |
| 383 | |
| 384 | |
| 385 | // returns true if we have wxCHB_TOP or wxCHB_BOTTOM style |
| 386 | bool IsVertical() const { return HasFlag(wxCHB_BOTTOM | wxCHB_TOP); } |
| 387 | |
| 388 | virtual bool DeleteAllPages(); |
| 389 | }; |
| 390 | |
| 391 | |
| 392 | class wxChoicebookEvent : public wxBookCtrlBaseEvent |
| 393 | { |
| 394 | public: |
| 395 | wxChoicebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, |
| 396 | int nSel = -1, int nOldSel = -1); |
| 397 | }; |
| 398 | |
| 399 | %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED; |
| 400 | %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING; |
| 401 | |
| 402 | %pythoncode { |
| 403 | EVT_CHOICEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, 1 ) |
| 404 | EVT_CHOICEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, 1 ) |
| 405 | } |
| 406 | |
| 407 | //--------------------------------------------------------------------------- |
| 408 | %newgroup; |
| 409 | |
| 410 | |
| 411 | class wxBookCtrlSizer: public wxSizer |
| 412 | { |
| 413 | public: |
| 414 | %pythonAppend wxBookCtrlSizer "self._setOORInfo(self)" |
| 415 | |
| 416 | wxBookCtrlSizer( wxBookCtrlBase *nb ); |
| 417 | |
| 418 | void RecalcSizes(); |
| 419 | wxSize CalcMin(); |
| 420 | wxBookCtrlBase *GetControl(); |
| 421 | }; |
| 422 | |
| 423 | |
| 424 | class wxNotebookSizer: public wxSizer { |
| 425 | public: |
| 426 | %pythonAppend wxNotebookSizer "self._setOORInfo(self)" |
| 427 | |
| 428 | wxNotebookSizer( wxNotebook *nb ); |
| 429 | |
| 430 | void RecalcSizes(); |
| 431 | wxSize CalcMin(); |
| 432 | wxNotebook *GetNotebook(); |
| 433 | }; |
| 434 | |
| 435 | //--------------------------------------------------------------------------- |