]>
Commit | Line | Data |
---|---|---|
53b28675 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: notebook.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin |
ff829f3f | 7 | // Licence: wxWindows licence |
53b28675 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "notebook.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/notebook.h" | |
dcf924a3 RR |
15 | |
16 | #if wxUSE_NOTEBOOK | |
17 | ||
53b28675 RR |
18 | #include "wx/panel.h" |
19 | #include "wx/utils.h" | |
20 | #include "wx/imaglist.h" | |
30dea054 | 21 | #include "wx/intl.h" |
4bf58c62 | 22 | #include "wx/log.h" |
83624f79 RR |
23 | |
24 | #include "gdk/gdk.h" | |
25 | #include "gtk/gtk.h" | |
26 | #include "wx/gtk/win_gtk.h" | |
b292e2f5 RR |
27 | #include "gdk/gdkkeysyms.h" |
28 | ||
acfd422a RR |
29 | //----------------------------------------------------------------------------- |
30 | // idle system | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | extern void wxapp_install_idle_handler(); | |
34 | extern bool g_isIdle; | |
35 | ||
b292e2f5 RR |
36 | //----------------------------------------------------------------------------- |
37 | // data | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
40 | extern bool g_blockEventsOnDrag; | |
53b28675 | 41 | |
2e563988 RR |
42 | //----------------------------------------------------------------------------- |
43 | // debug | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | #ifdef __WXDEBUG__ | |
47 | ||
48 | extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ); | |
49 | ||
50 | #endif | |
51 | ||
219f895a RR |
52 | //----------------------------------------------------------------------------- |
53 | // wxNotebookPage | |
54 | //----------------------------------------------------------------------------- | |
55 | ||
56 | class wxNotebookPage: public wxObject | |
57 | { | |
58 | public: | |
59 | wxNotebookPage() | |
60 | { | |
219f895a RR |
61 | m_text = ""; |
62 | m_image = -1; | |
c67daf87 UR |
63 | m_page = (GtkNotebookPage *) NULL; |
64 | m_client = (wxWindow *) NULL; | |
24d20a8f | 65 | m_box = (GtkWidget *) NULL; |
ff7b1510 | 66 | } |
219f895a | 67 | |
219f895a RR |
68 | wxString m_text; |
69 | int m_image; | |
70 | GtkNotebookPage *m_page; | |
71 | GtkLabel *m_label; | |
72 | wxWindow *m_client; | |
24d20a8f | 73 | GtkWidget *m_box; // in which the label and image are packed |
219f895a RR |
74 | }; |
75 | ||
ff829f3f | 76 | //----------------------------------------------------------------------------- |
5b011451 | 77 | // "switch_page" |
ff829f3f VZ |
78 | //----------------------------------------------------------------------------- |
79 | ||
219f895a RR |
80 | static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), |
81 | GtkNotebookPage *WXUNUSED(page), | |
587ce561 RR |
82 | gint page, |
83 | wxNotebook *notebook ) | |
ff829f3f | 84 | { |
587ce561 RR |
85 | if (g_isIdle) |
86 | wxapp_install_idle_handler(); | |
ff829f3f | 87 | |
b292e2f5 | 88 | int old = notebook->GetSelection(); |
ff829f3f | 89 | |
587ce561 RR |
90 | wxNotebookEvent event1( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, |
91 | notebook->GetId(), page, old ); | |
92 | event1.SetEventObject( notebook ); | |
93 | ||
94 | if ((notebook->GetEventHandler()->ProcessEvent( event1 )) && | |
95 | !event1.IsAllowed() ) | |
96 | { | |
97 | /* program doesn't allow the page change */ | |
98 | gtk_signal_emit_stop_by_name( GTK_OBJECT(notebook->m_widget), "switch_page" ); | |
99 | return; | |
100 | } | |
ef44a621 | 101 | |
587ce561 RR |
102 | wxNotebookEvent event2( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, |
103 | notebook->GetId(), page, old ); | |
104 | event2.SetEventObject( notebook ); | |
105 | notebook->GetEventHandler()->ProcessEvent( event2 ); | |
ff829f3f VZ |
106 | } |
107 | ||
5b011451 RR |
108 | //----------------------------------------------------------------------------- |
109 | // "size_allocate" | |
110 | //----------------------------------------------------------------------------- | |
111 | ||
33d0b396 | 112 | static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) |
caac5181 | 113 | { |
587ce561 RR |
114 | if (g_isIdle) |
115 | wxapp_install_idle_handler(); | |
e208b369 | 116 | |
a2053b27 RR |
117 | if ((win->m_x == alloc->x) && |
118 | (win->m_y == alloc->y) && | |
119 | (win->m_width == alloc->width) && | |
120 | (win->m_height == alloc->height)) | |
b292e2f5 | 121 | { |
58dea4b0 | 122 | return; |
b292e2f5 | 123 | } |
2b07d713 | 124 | |
b292e2f5 | 125 | win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); |
f861258f | 126 | |
b292e2f5 RR |
127 | if (win->GetAutoLayout()) win->Layout(); |
128 | } | |
129 | ||
6ca41e57 RR |
130 | //----------------------------------------------------------------------------- |
131 | // InsertChild callback for wxNotebook | |
132 | //----------------------------------------------------------------------------- | |
133 | ||
587ce561 | 134 | static void wxInsertChildInNotebook( wxNotebook* WXUNUSED(parent), wxWindow* WXUNUSED(child) ) |
6ca41e57 | 135 | { |
587ce561 | 136 | /* we don't do anything here but pray */ |
6ca41e57 RR |
137 | } |
138 | ||
53b28675 RR |
139 | //----------------------------------------------------------------------------- |
140 | // wxNotebook | |
141 | //----------------------------------------------------------------------------- | |
142 | ||
53b28675 RR |
143 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) |
144 | ||
b98d804b RR |
145 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) |
146 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
147 | END_EVENT_TABLE() | |
f861258f | 148 | |
ff829f3f | 149 | void wxNotebook::Init() |
53b28675 | 150 | { |
b292e2f5 RR |
151 | m_imageList = (wxImageList *) NULL; |
152 | m_pages.DeleteContents( TRUE ); | |
29f538ce | 153 | m_lastSelection = -1; |
ff829f3f VZ |
154 | } |
155 | ||
156 | wxNotebook::wxNotebook() | |
157 | { | |
b292e2f5 | 158 | Init(); |
ff7b1510 | 159 | } |
53b28675 | 160 | |
debe6624 | 161 | wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, |
53b28675 | 162 | const wxPoint& pos, const wxSize& size, |
debe6624 | 163 | long style, const wxString& name ) |
53b28675 | 164 | { |
b292e2f5 RR |
165 | Init(); |
166 | Create( parent, id, pos, size, style, name ); | |
ff7b1510 | 167 | } |
53b28675 | 168 | |
ff829f3f | 169 | wxNotebook::~wxNotebook() |
53b28675 | 170 | { |
587ce561 RR |
171 | /* don't generate change page events any more */ |
172 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget), | |
173 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this ); | |
ff829f3f | 174 | |
b292e2f5 | 175 | DeleteAllPages(); |
ff7b1510 | 176 | } |
53b28675 | 177 | |
debe6624 | 178 | bool wxNotebook::Create(wxWindow *parent, wxWindowID id, |
53b28675 | 179 | const wxPoint& pos, const wxSize& size, |
debe6624 | 180 | long style, const wxString& name ) |
53b28675 | 181 | { |
b292e2f5 RR |
182 | m_needParent = TRUE; |
183 | m_acceptsFocus = TRUE; | |
184 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; | |
185 | ||
4dcaf11a RR |
186 | if (!PreCreation( parent, pos, size ) || |
187 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
188 | { | |
189 | wxFAIL_MSG( _T("wxNoteBook creation failed") ); | |
190 | return FALSE; | |
191 | } | |
192 | ||
ff829f3f | 193 | |
b292e2f5 | 194 | m_widget = gtk_notebook_new(); |
53b28675 | 195 | |
2e563988 RR |
196 | #ifdef __WXDEBUG__ |
197 | debug_focus_in( m_widget, _T("wxNotebook::m_widget"), name ); | |
198 | #endif | |
199 | ||
b292e2f5 | 200 | gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); |
caac5181 | 201 | |
587ce561 RR |
202 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", |
203 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this ); | |
ff829f3f | 204 | |
f03fc89f | 205 | m_parent->DoAddChild( this ); |
ef44a621 | 206 | |
b292e2f5 | 207 | PostCreation(); |
ff829f3f | 208 | |
b292e2f5 RR |
209 | Show( TRUE ); |
210 | ||
211 | return TRUE; | |
ff7b1510 | 212 | } |
53b28675 | 213 | |
ed58dbea RR |
214 | void wxNotebook::SetFocus() |
215 | { | |
216 | if (m_pages.GetCount() == 0) return; | |
217 | ||
218 | wxNode *node = m_pages.Nth( GetSelection() ); | |
219 | ||
220 | if (!node) return; | |
221 | ||
222 | wxNotebookPage *page = (wxNotebookPage*) node->Data(); | |
223 | ||
224 | page->m_client->SetFocus(); | |
225 | } | |
226 | ||
ff829f3f | 227 | int wxNotebook::GetSelection() const |
53b28675 | 228 | { |
b019151f | 229 | wxCHECK_MSG( m_widget != NULL, -1, _T("invalid notebook") ); |
53b28675 | 230 | |
587ce561 | 231 | GList *pages = GTK_NOTEBOOK(m_widget)->children; |
ef44a621 | 232 | |
587ce561 | 233 | if (g_list_length(pages) == 0) return -1; |
53b28675 | 234 | |
587ce561 RR |
235 | GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); |
236 | ||
29f538ce | 237 | if (notebook->cur_page == NULL) return m_lastSelection; |
587ce561 | 238 | |
29f538ce | 239 | return g_list_index( pages, (gpointer)(notebook->cur_page) ); |
ff7b1510 | 240 | } |
53b28675 | 241 | |
ff829f3f | 242 | int wxNotebook::GetPageCount() const |
53b28675 | 243 | { |
587ce561 | 244 | return (int) g_list_length( GTK_NOTEBOOK(m_widget)->children ); |
ff7b1510 | 245 | } |
53b28675 | 246 | |
ff829f3f | 247 | int wxNotebook::GetRowCount() const |
53b28675 | 248 | { |
b292e2f5 | 249 | return 1; |
ff7b1510 | 250 | } |
53b28675 | 251 | |
ff829f3f | 252 | wxString wxNotebook::GetPageText( int page ) const |
53b28675 | 253 | { |
b019151f | 254 | wxCHECK_MSG( m_widget != NULL, _T(""), _T("invalid notebook") ); |
ef44a621 | 255 | |
b292e2f5 RR |
256 | wxNotebookPage* nb_page = GetNotebookPage(page); |
257 | if (nb_page) | |
258 | return nb_page->m_text; | |
259 | else | |
ed58dbea | 260 | return _T(""); |
ff7b1510 | 261 | } |
53b28675 | 262 | |
ff829f3f | 263 | int wxNotebook::GetPageImage( int page ) const |
53b28675 | 264 | { |
587ce561 | 265 | wxCHECK_MSG( m_widget != NULL, -1, _T("invalid notebook") ); |
a81258be | 266 | |
b292e2f5 RR |
267 | wxNotebookPage* nb_page = GetNotebookPage(page); |
268 | if (nb_page) | |
269 | return nb_page->m_image; | |
270 | else | |
587ce561 | 271 | return -1; |
ff7b1510 | 272 | } |
53b28675 | 273 | |
587ce561 | 274 | wxNotebookPage* wxNotebook::GetNotebookPage( int page ) const |
53b28675 | 275 | { |
587ce561 | 276 | wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*) NULL, _T("invalid notebook") ); |
ff829f3f | 277 | |
587ce561 RR |
278 | wxCHECK_MSG( page < (int)m_pages.GetCount(), (wxNotebookPage*) NULL, _T("invalid notebook index") ); |
279 | ||
280 | wxNode *node = m_pages.Nth( page ); | |
281 | ||
282 | return (wxNotebookPage *) node->Data(); | |
ff7b1510 | 283 | } |
53b28675 | 284 | |
ff829f3f | 285 | int wxNotebook::SetSelection( int page ) |
53b28675 | 286 | { |
b019151f | 287 | wxCHECK_MSG( m_widget != NULL, -1, _T("invalid notebook") ); |
a81258be | 288 | |
587ce561 | 289 | wxCHECK_MSG( page < (int)m_pages.GetCount(), -1, _T("invalid notebook index") ); |
ff829f3f | 290 | |
587ce561 RR |
291 | int selOld = GetSelection(); |
292 | ||
293 | gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page ); | |
ff829f3f | 294 | |
3eb78d7e | 295 | return selOld; |
ff7b1510 | 296 | } |
53b28675 | 297 | |
587ce561 | 298 | void wxNotebook::AdvanceSelection( bool forward ) |
ff829f3f | 299 | { |
b019151f | 300 | wxCHECK_RET( m_widget != NULL, _T("invalid notebook") ); |
a81258be | 301 | |
3eb78d7e RR |
302 | int sel = GetSelection(); |
303 | int max = GetPageCount(); | |
ff829f3f | 304 | |
587ce561 | 305 | if (forward) |
3eb78d7e RR |
306 | SetSelection( sel == max ? 0 : sel + 1 ); |
307 | else | |
b98d804b | 308 | SetSelection( sel == 0 ? max-1 : sel - 1 ); |
ff829f3f VZ |
309 | } |
310 | ||
53b28675 RR |
311 | void wxNotebook::SetImageList( wxImageList* imageList ) |
312 | { | |
3eb78d7e | 313 | m_imageList = imageList; |
ff7b1510 | 314 | } |
53b28675 | 315 | |
ff829f3f | 316 | bool wxNotebook::SetPageText( int page, const wxString &text ) |
53b28675 | 317 | { |
b019151f | 318 | wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid notebook") ); |
a81258be | 319 | |
3eb78d7e | 320 | wxNotebookPage* nb_page = GetNotebookPage(page); |
ef44a621 | 321 | |
f861258f | 322 | wxCHECK_MSG( nb_page, FALSE, _T("SetPageText: invalid page index") ); |
ff829f3f | 323 | |
3eb78d7e | 324 | nb_page->m_text = text; |
ff829f3f | 325 | |
587ce561 | 326 | gtk_label_set( nb_page->m_label, nb_page->m_text.mbc_str() ); |
3eb78d7e RR |
327 | |
328 | return TRUE; | |
ff7b1510 | 329 | } |
53b28675 | 330 | |
debe6624 | 331 | bool wxNotebook::SetPageImage( int page, int image ) |
53b28675 | 332 | { |
3eb78d7e | 333 | /* HvdH 28-12-98: now it works, but it's a bit of a kludge */ |
f861258f | 334 | |
3eb78d7e | 335 | wxNotebookPage* nb_page = GetNotebookPage(page); |
ef44a621 | 336 | |
3eb78d7e | 337 | if (!nb_page) return FALSE; |
f861258f | 338 | |
3eb78d7e RR |
339 | /* Optimization posibility: return immediately if image unchanged. |
340 | * Not enabled because it may break existing (stupid) code that | |
341 | * manipulates the imagelist to cycle images */ | |
f861258f | 342 | |
3eb78d7e | 343 | /* if (image == nb_page->m_image) return TRUE; */ |
f861258f VZ |
344 | |
345 | /* For different cases: | |
3eb78d7e RR |
346 | 1) no image -> no image |
347 | 2) image -> no image | |
348 | 3) no image -> image | |
349 | 4) image -> image */ | |
f861258f | 350 | |
3eb78d7e RR |
351 | if (image == -1 && nb_page->m_image == -1) |
352 | return TRUE; /* Case 1): Nothing to do. */ | |
f861258f | 353 | |
bbe0af5b | 354 | GtkWidget *pixmapwid = (GtkWidget*) NULL; |
f861258f VZ |
355 | |
356 | if (nb_page->m_image != -1) | |
3eb78d7e RR |
357 | { |
358 | /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */ | |
f861258f | 359 | |
3eb78d7e RR |
360 | GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box)); |
361 | while (child) | |
362 | { | |
f861258f | 363 | if (GTK_IS_PIXMAP(child->data)) |
3eb78d7e RR |
364 | { |
365 | pixmapwid = GTK_WIDGET(child->data); | |
366 | break; | |
367 | } | |
368 | child = child->next; | |
369 | } | |
f861258f | 370 | |
3eb78d7e | 371 | /* We should have the pixmap widget now */ |
f861258f VZ |
372 | wxASSERT(pixmapwid != NULL); |
373 | ||
374 | if (image == -1) | |
3eb78d7e RR |
375 | { |
376 | /* If there's no new widget, just remove the old from the box */ | |
377 | gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid); | |
378 | nb_page->m_image = -1; | |
53b28675 | 379 | |
3eb78d7e RR |
380 | return TRUE; /* Case 2) */ |
381 | } | |
382 | } | |
f861258f | 383 | |
3eb78d7e RR |
384 | /* Only cases 3) and 4) left */ |
385 | wxASSERT( m_imageList != NULL ); /* Just in case */ | |
f861258f | 386 | |
3eb78d7e RR |
387 | /* Construct the new pixmap */ |
388 | const wxBitmap *bmp = m_imageList->GetBitmap(image); | |
389 | GdkPixmap *pixmap = bmp->GetPixmap(); | |
390 | GdkBitmap *mask = (GdkBitmap*) NULL; | |
f861258f | 391 | if ( bmp->GetMask() ) |
3eb78d7e RR |
392 | { |
393 | mask = bmp->GetMask()->GetBitmap(); | |
394 | } | |
f861258f VZ |
395 | |
396 | if (pixmapwid == NULL) | |
3eb78d7e RR |
397 | { |
398 | /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */ | |
399 | pixmapwid = gtk_pixmap_new (pixmap, mask ); | |
f861258f | 400 | |
3eb78d7e RR |
401 | /* CHECKME: Are these pack flags okay? */ |
402 | gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, 3); | |
403 | gtk_widget_show(pixmapwid); | |
404 | } | |
f861258f | 405 | else |
3eb78d7e RR |
406 | { |
407 | /* Case 4) Simply replace the pixmap */ | |
408 | gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask); | |
409 | } | |
f861258f | 410 | |
3eb78d7e | 411 | nb_page->m_image = image; |
53b28675 | 412 | |
3eb78d7e | 413 | return TRUE; |
ff7b1510 | 414 | } |
53b28675 RR |
415 | |
416 | void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) ) | |
417 | { | |
b019151f | 418 | wxFAIL_MSG( _T("wxNotebook::SetPageSize not implemented") ); |
ff7b1510 | 419 | } |
53b28675 RR |
420 | |
421 | void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) ) | |
422 | { | |
b019151f | 423 | wxFAIL_MSG( _T("wxNotebook::SetPadding not implemented") ); |
ff7b1510 | 424 | } |
53b28675 | 425 | |
74e3313b | 426 | void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz)) |
ca8b28f2 | 427 | { |
b019151f | 428 | wxFAIL_MSG( _T("wxNotebook::SetTabSize not implemented") ); |
ca8b28f2 JS |
429 | } |
430 | ||
ff829f3f | 431 | bool wxNotebook::DeleteAllPages() |
53b28675 | 432 | { |
b019151f | 433 | wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid notebook") ); |
a81258be | 434 | |
587ce561 RR |
435 | while (m_pages.GetCount() > 0) |
436 | DeletePage( m_pages.GetCount()-1 ); | |
ff829f3f | 437 | |
3eb78d7e | 438 | return TRUE; |
ff7b1510 | 439 | } |
53b28675 | 440 | |
ff829f3f | 441 | bool wxNotebook::DeletePage( int page ) |
53b28675 | 442 | { |
3eb78d7e RR |
443 | wxNotebookPage* nb_page = GetNotebookPage(page); |
444 | if (!nb_page) return FALSE; | |
53b28675 | 445 | |
29f538ce RR |
446 | /* GTK sets GtkNotebook.cur_page to NULL before sending |
447 | the switvh page event */ | |
448 | m_lastSelection = GetSelection(); | |
449 | ||
587ce561 | 450 | nb_page->m_client->Destroy(); |
3eb78d7e | 451 | m_pages.DeleteObject( nb_page ); |
29f538ce RR |
452 | |
453 | m_lastSelection = -1; | |
fed46e72 | 454 | |
3eb78d7e | 455 | return TRUE; |
fed46e72 RR |
456 | } |
457 | ||
458 | bool wxNotebook::RemovePage( int page ) | |
459 | { | |
3eb78d7e | 460 | wxNotebookPage* nb_page = GetNotebookPage(page); |
587ce561 | 461 | |
3eb78d7e | 462 | if (!nb_page) return FALSE; |
fed46e72 | 463 | |
587ce561 | 464 | gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page ); |
ff829f3f | 465 | |
3eb78d7e | 466 | m_pages.DeleteObject( nb_page ); |
ff829f3f | 467 | |
3eb78d7e | 468 | return TRUE; |
ff7b1510 | 469 | } |
53b28675 | 470 | |
587ce561 RR |
471 | bool wxNotebook::InsertPage( int position, wxWindow* win, const wxString& text, |
472 | bool select, int imageId ) | |
53b28675 | 473 | { |
b019151f | 474 | wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid notebook") ); |
a81258be | 475 | |
587ce561 RR |
476 | wxCHECK_MSG( win->GetParent() == this, FALSE, |
477 | _T("Can't add a page whose parent is not the notebook!") ); | |
8aadf227 | 478 | |
587ce561 RR |
479 | /* don't receive switch page during addition */ |
480 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget), | |
481 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this ); | |
482 | ||
483 | GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); | |
53b28675 | 484 | |
587ce561 RR |
485 | wxNotebookPage *page = new wxNotebookPage(); |
486 | ||
487 | if (position < 0) | |
488 | m_pages.Append( page ); | |
489 | else | |
490 | m_pages.Insert( m_pages.Nth( position ), page ); | |
491 | ||
492 | page->m_client = win; | |
8aadf227 | 493 | |
587ce561 RR |
494 | page->m_box = gtk_hbox_new( FALSE, 0 ); |
495 | gtk_container_border_width( GTK_CONTAINER(page->m_box), 2 ); | |
496 | ||
d1af991f RR |
497 | gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", |
498 | GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); | |
499 | ||
587ce561 RR |
500 | if (position < 0) |
501 | gtk_notebook_append_page( notebook, win->m_widget, page->m_box ); | |
502 | else | |
503 | gtk_notebook_insert_page( notebook, win->m_widget, page->m_box, position ); | |
504 | ||
c693edf3 | 505 | page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data; |
ef44a621 | 506 | |
587ce561 RR |
507 | /* set the label image */ |
508 | page->m_image = imageId; | |
509 | ||
3eb78d7e | 510 | if (imageId != -1) |
e4a81a2e | 511 | { |
3eb78d7e RR |
512 | wxASSERT( m_imageList != NULL ); |
513 | ||
514 | const wxBitmap *bmp = m_imageList->GetBitmap(imageId); | |
515 | GdkPixmap *pixmap = bmp->GetPixmap(); | |
516 | GdkBitmap *mask = (GdkBitmap*) NULL; | |
517 | if ( bmp->GetMask() ) | |
518 | { | |
519 | mask = bmp->GetMask()->GetBitmap(); | |
520 | } | |
e4a81a2e | 521 | |
3eb78d7e | 522 | GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask ); |
24d20a8f | 523 | |
3eb78d7e | 524 | gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3); |
24d20a8f | 525 | |
3eb78d7e RR |
526 | gtk_widget_show(pixmapwid); |
527 | } | |
24d20a8f | 528 | |
587ce561 | 529 | /* set the label text */ |
3eb78d7e | 530 | page->m_text = text; |
b019151f | 531 | if (page->m_text.IsEmpty()) page->m_text = _T(""); |
587ce561 RR |
532 | |
533 | page->m_label = GTK_LABEL( gtk_label_new(page->m_text.mbc_str()) ); | |
534 | gtk_box_pack_end( GTK_BOX(page->m_box), GTK_WIDGET(page->m_label), FALSE, FALSE, 3 ); | |
741fd203 | 535 | |
587ce561 RR |
536 | /* show the label */ |
537 | gtk_widget_show( GTK_WIDGET(page->m_label) ); | |
741fd203 | 538 | |
587ce561 RR |
539 | if (select && (m_pages.GetCount() > 1)) |
540 | { | |
541 | if (position < 0) | |
542 | SetSelection( GetPageCount()-1 ); | |
543 | else | |
544 | SetSelection( position ); | |
545 | } | |
741fd203 | 546 | |
587ce561 RR |
547 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", |
548 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this ); | |
ff829f3f | 549 | |
3eb78d7e | 550 | return TRUE; |
ff7b1510 | 551 | } |
53b28675 | 552 | |
587ce561 RR |
553 | bool wxNotebook::AddPage(wxWindow* win, const wxString& text, |
554 | bool select, int imageId) | |
555 | { | |
556 | return InsertPage( -1, win, text, select, imageId ); | |
557 | } | |
558 | ||
b98d804b RR |
559 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) |
560 | { | |
f861258f | 561 | if (event.IsWindowChange()) |
b98d804b | 562 | AdvanceSelection( event.GetDirection() ); |
f861258f | 563 | else |
b98d804b RR |
564 | event.Skip(); |
565 | } | |
566 | ||
ff829f3f | 567 | wxWindow *wxNotebook::GetPage( int page ) const |
53b28675 | 568 | { |
b019151f | 569 | wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, _T("invalid notebook") ); |
a81258be | 570 | |
b292e2f5 RR |
571 | wxNotebookPage* nb_page = GetNotebookPage(page); |
572 | if (!nb_page) | |
573 | return (wxWindow *) NULL; | |
574 | else | |
575 | return nb_page->m_client; | |
ff7b1510 | 576 | } |
53b28675 | 577 | |
5a8c929e | 578 | // override these 2 functions to do nothing: everything is done in OnSize |
e3e65dac | 579 | void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) |
5a8c929e | 580 | { |
b292e2f5 RR |
581 | // don't set the sizes of the pages - their correct size is not yet known |
582 | wxControl::SetConstraintSizes(FALSE); | |
5a8c929e VZ |
583 | } |
584 | ||
e3e65dac | 585 | bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) |
5a8c929e | 586 | { |
b292e2f5 | 587 | return TRUE; |
5a8c929e VZ |
588 | } |
589 | ||
58614078 | 590 | void wxNotebook::ApplyWidgetStyle() |
a81258be | 591 | { |
b292e2f5 RR |
592 | SetWidgetStyle(); |
593 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
a81258be RR |
594 | } |
595 | ||
58d1c1ae RR |
596 | bool wxNotebook::IsOwnGtkWindow( GdkWindow *window ) |
597 | { | |
598 | return ((m_widget->window == window) || | |
599 | (GTK_NOTEBOOK(m_widget)->panel == window)); | |
600 | } | |
601 | ||
53b28675 | 602 | //----------------------------------------------------------------------------- |
ff829f3f | 603 | // wxNotebookEvent |
53b28675 RR |
604 | //----------------------------------------------------------------------------- |
605 | ||
92976ab6 | 606 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) |
5b011451 | 607 | |
dcf924a3 | 608 | #endif |