]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: notebook.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "notebook.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/notebook.h" | |
15 | ||
16 | #if wxUSE_NOTEBOOK | |
17 | ||
18 | #include "wx/panel.h" | |
19 | #include "wx/utils.h" | |
20 | #include "wx/imaglist.h" | |
21 | #include "wx/intl.h" | |
22 | #include "wx/log.h" | |
23 | ||
24 | #include <gdk/gdk.h> | |
25 | #include <gtk/gtk.h> | |
26 | #include "wx/gtk/win_gtk.h" | |
27 | #include <gdk/gdkkeysyms.h> | |
28 | ||
29 | // ---------------------------------------------------------------------------- | |
30 | // events | |
31 | // ---------------------------------------------------------------------------- | |
32 | ||
33 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) | |
34 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
35 | ||
36 | //----------------------------------------------------------------------------- | |
37 | // idle system | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
40 | extern void wxapp_install_idle_handler(); | |
41 | extern bool g_isIdle; | |
42 | ||
43 | //----------------------------------------------------------------------------- | |
44 | // data | |
45 | //----------------------------------------------------------------------------- | |
46 | ||
47 | extern bool g_blockEventsOnDrag; | |
48 | ||
49 | //----------------------------------------------------------------------------- | |
50 | // debug | |
51 | //----------------------------------------------------------------------------- | |
52 | ||
53 | #ifdef __WXDEBUG__ | |
54 | ||
55 | extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ); | |
56 | ||
57 | #endif | |
58 | ||
59 | //----------------------------------------------------------------------------- | |
60 | // wxGtkNotebookPage | |
61 | //----------------------------------------------------------------------------- | |
62 | ||
63 | class wxGtkNotebookPage: public wxObject | |
64 | { | |
65 | public: | |
66 | wxGtkNotebookPage() | |
67 | { | |
68 | m_text = ""; | |
69 | m_image = -1; | |
70 | m_page = (GtkNotebookPage *) NULL; | |
71 | m_client = (wxNotebookPage *) NULL; | |
72 | m_box = (GtkWidget *) NULL; | |
73 | } | |
74 | ||
75 | wxString m_text; | |
76 | int m_image; | |
77 | GtkNotebookPage *m_page; | |
78 | GtkLabel *m_label; | |
79 | wxNotebookPage *m_client; | |
80 | GtkWidget *m_box; // in which the label and image are packed | |
81 | }; | |
82 | ||
83 | //----------------------------------------------------------------------------- | |
84 | // "switch_page" | |
85 | //----------------------------------------------------------------------------- | |
86 | ||
87 | static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), | |
88 | GtkNotebookPage *WXUNUSED(page), | |
89 | gint page, | |
90 | wxNotebook *notebook ) | |
91 | { | |
92 | static bool s_inPageChange = FALSE; | |
93 | ||
94 | // are you trying to call SetSelection() from a notebook event handler? | |
95 | // you shouldn't! | |
96 | wxCHECK_RET( !s_inPageChange, | |
97 | _T("gtk_notebook_page_change_callback reentered") ); | |
98 | ||
99 | s_inPageChange = TRUE; | |
100 | if (g_isIdle) | |
101 | wxapp_install_idle_handler(); | |
102 | ||
103 | int old = notebook->GetSelection(); | |
104 | ||
105 | wxNotebookEvent eventChanging( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, | |
106 | notebook->GetId(), page, old ); | |
107 | eventChanging.SetEventObject( notebook ); | |
108 | ||
109 | if ( (notebook->GetEventHandler()->ProcessEvent(eventChanging)) && | |
110 | !eventChanging.IsAllowed() ) | |
111 | { | |
112 | /* program doesn't allow the page change */ | |
113 | gtk_signal_emit_stop_by_name( GTK_OBJECT(notebook->m_widget), | |
114 | "switch_page" ); | |
115 | } | |
116 | else // change allowed | |
117 | { | |
118 | // make wxNotebook::GetSelection() return the correct (i.e. consistent | |
119 | // with wxNotebookEvent::GetSelection()) value even though the page is | |
120 | // not really changed in GTK+ | |
121 | notebook->m_selection = page; | |
122 | ||
123 | wxNotebookEvent eventChanged( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, | |
124 | notebook->GetId(), page, old ); | |
125 | eventChanged.SetEventObject( notebook ); | |
126 | notebook->GetEventHandler()->ProcessEvent( eventChanged ); | |
127 | } | |
128 | ||
129 | s_inPageChange = FALSE; | |
130 | } | |
131 | ||
132 | //----------------------------------------------------------------------------- | |
133 | // "size_allocate" | |
134 | //----------------------------------------------------------------------------- | |
135 | ||
136 | static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) | |
137 | { | |
138 | if (g_isIdle) | |
139 | wxapp_install_idle_handler(); | |
140 | ||
141 | if ((win->m_x == alloc->x) && | |
142 | (win->m_y == alloc->y) && | |
143 | (win->m_width == alloc->width) && | |
144 | (win->m_height == alloc->height)) | |
145 | { | |
146 | return; | |
147 | } | |
148 | ||
149 | win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); | |
150 | ||
151 | /* GTK 1.2 up to version 1.2.5 is broken so that we have to call allocate | |
152 | here in order to make repositioning after resizing to take effect. */ | |
153 | if ((gtk_major_version == 1) && | |
154 | (gtk_minor_version == 2) && | |
155 | (gtk_micro_version < 6) && | |
156 | (win->m_wxwindow) && | |
157 | (GTK_WIDGET_REALIZED(win->m_wxwindow))) | |
158 | { | |
159 | gtk_widget_size_allocate( win->m_wxwindow, alloc ); | |
160 | } | |
161 | } | |
162 | ||
163 | //----------------------------------------------------------------------------- | |
164 | // "realize" from m_widget | |
165 | //----------------------------------------------------------------------------- | |
166 | ||
167 | static gint | |
168 | gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win ) | |
169 | { | |
170 | if (g_isIdle) | |
171 | wxapp_install_idle_handler(); | |
172 | ||
173 | /* GTK 1.2 up to version 1.2.5 is broken so that we have to call a queue_resize | |
174 | here in order to make repositioning before showing to take effect. */ | |
175 | gtk_widget_queue_resize( win->m_widget ); | |
176 | ||
177 | return FALSE; | |
178 | } | |
179 | ||
180 | //----------------------------------------------------------------------------- | |
181 | // "key_press_event" | |
182 | //----------------------------------------------------------------------------- | |
183 | ||
184 | static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *win ) | |
185 | { | |
186 | if (g_isIdle) | |
187 | wxapp_install_idle_handler(); | |
188 | ||
189 | if (!win->m_hasVMT) return FALSE; | |
190 | if (g_blockEventsOnDrag) return FALSE; | |
191 | ||
192 | /* win is a control: tab can be propagated up */ | |
193 | if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) | |
194 | { | |
195 | wxNode *node = win->m_pages.Nth( win->GetSelection() ); | |
196 | if (!node) return FALSE; | |
197 | ||
198 | wxGtkNotebookPage *page = (wxGtkNotebookPage*) node->Data(); | |
199 | ||
200 | wxNavigationKeyEvent event; | |
201 | event.SetEventObject( win ); | |
202 | /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ | |
203 | event.SetDirection( (gdk_event->keyval == GDK_Tab) ); | |
204 | /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ | |
205 | event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); | |
206 | event.SetCurrentFocus( win ); | |
207 | if (!page->m_client->GetEventHandler()->ProcessEvent( event )) | |
208 | { | |
209 | page->m_client->SetFocus(); | |
210 | } | |
211 | ||
212 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); | |
213 | return TRUE; | |
214 | } | |
215 | ||
216 | return FALSE; | |
217 | } | |
218 | ||
219 | //----------------------------------------------------------------------------- | |
220 | // InsertChild callback for wxNotebook | |
221 | //----------------------------------------------------------------------------- | |
222 | ||
223 | static void wxInsertChildInNotebook( wxNotebook* WXUNUSED(parent), wxWindow* WXUNUSED(child) ) | |
224 | { | |
225 | /* we don't do anything here but pray */ | |
226 | } | |
227 | ||
228 | //----------------------------------------------------------------------------- | |
229 | // wxNotebook | |
230 | //----------------------------------------------------------------------------- | |
231 | ||
232 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) | |
233 | ||
234 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) | |
235 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
236 | END_EVENT_TABLE() | |
237 | ||
238 | void wxNotebook::Init() | |
239 | { | |
240 | m_imageList = (wxImageList *) NULL; | |
241 | m_ownsImageList = FALSE; | |
242 | m_pages.DeleteContents( TRUE ); | |
243 | m_selection = -1; | |
244 | m_themeEnabled = TRUE; | |
245 | } | |
246 | ||
247 | wxNotebook::wxNotebook() | |
248 | { | |
249 | Init(); | |
250 | } | |
251 | ||
252 | wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, | |
253 | const wxPoint& pos, const wxSize& size, | |
254 | long style, const wxString& name ) | |
255 | { | |
256 | Init(); | |
257 | Create( parent, id, pos, size, style, name ); | |
258 | } | |
259 | ||
260 | wxNotebook::~wxNotebook() | |
261 | { | |
262 | /* don't generate change page events any more */ | |
263 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget), | |
264 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this ); | |
265 | ||
266 | DeleteAllPages(); | |
267 | if (m_ownsImageList) delete m_imageList; | |
268 | } | |
269 | ||
270 | bool wxNotebook::Create(wxWindow *parent, wxWindowID id, | |
271 | const wxPoint& pos, const wxSize& size, | |
272 | long style, const wxString& name ) | |
273 | { | |
274 | m_needParent = TRUE; | |
275 | m_acceptsFocus = TRUE; | |
276 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; | |
277 | ||
278 | if (!PreCreation( parent, pos, size ) || | |
279 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
280 | { | |
281 | wxFAIL_MSG( wxT("wxNoteBook creation failed") ); | |
282 | return FALSE; | |
283 | } | |
284 | ||
285 | ||
286 | m_widget = gtk_notebook_new(); | |
287 | ||
288 | #ifdef __WXDEBUG__ | |
289 | debug_focus_in( m_widget, wxT("wxNotebook::m_widget"), name ); | |
290 | #endif | |
291 | ||
292 | gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); | |
293 | ||
294 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", | |
295 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this ); | |
296 | ||
297 | m_parent->DoAddChild( this ); | |
298 | ||
299 | if (m_windowStyle & wxNB_RIGHT) | |
300 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT ); | |
301 | if (m_windowStyle & wxNB_LEFT) | |
302 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT ); | |
303 | if (m_windowStyle & wxNB_BOTTOM) | |
304 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM ); | |
305 | ||
306 | gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event", | |
307 | GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this ); | |
308 | ||
309 | PostCreation(); | |
310 | ||
311 | SetFont( parent->GetFont() ); | |
312 | ||
313 | gtk_signal_connect( GTK_OBJECT(m_widget), "realize", | |
314 | GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this ); | |
315 | ||
316 | Show( TRUE ); | |
317 | ||
318 | return TRUE; | |
319 | } | |
320 | ||
321 | int wxNotebook::GetSelection() const | |
322 | { | |
323 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); | |
324 | ||
325 | if ( m_selection == -1 ) | |
326 | { | |
327 | GList *pages = GTK_NOTEBOOK(m_widget)->children; | |
328 | ||
329 | if (g_list_length(pages) != 0) | |
330 | { | |
331 | GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); | |
332 | ||
333 | gpointer cur = notebook->cur_page; | |
334 | if ( cur != NULL ) | |
335 | { | |
336 | wxConstCast(this, wxNotebook)->m_selection = | |
337 | g_list_index( pages, cur ); | |
338 | } | |
339 | } | |
340 | } | |
341 | ||
342 | return m_selection; | |
343 | } | |
344 | ||
345 | wxString wxNotebook::GetPageText( int page ) const | |
346 | { | |
347 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid notebook") ); | |
348 | ||
349 | wxGtkNotebookPage* nb_page = GetNotebookPage(page); | |
350 | if (nb_page) | |
351 | return nb_page->m_text; | |
352 | else | |
353 | return wxT(""); | |
354 | } | |
355 | ||
356 | int wxNotebook::GetPageImage( int page ) const | |
357 | { | |
358 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); | |
359 | ||
360 | wxGtkNotebookPage* nb_page = GetNotebookPage(page); | |
361 | if (nb_page) | |
362 | return nb_page->m_image; | |
363 | else | |
364 | return -1; | |
365 | } | |
366 | ||
367 | wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const | |
368 | { | |
369 | wxCHECK_MSG( m_widget != NULL, (wxGtkNotebookPage*) NULL, wxT("invalid notebook") ); | |
370 | ||
371 | wxCHECK_MSG( page < (int)m_pages.GetCount(), (wxGtkNotebookPage*) NULL, wxT("invalid notebook index") ); | |
372 | ||
373 | wxNode *node = m_pages.Nth( page ); | |
374 | ||
375 | return (wxGtkNotebookPage *) node->Data(); | |
376 | } | |
377 | ||
378 | int wxNotebook::SetSelection( int page ) | |
379 | { | |
380 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); | |
381 | ||
382 | wxCHECK_MSG( page < (int)m_pages.GetCount(), -1, wxT("invalid notebook index") ); | |
383 | ||
384 | int selOld = GetSelection(); | |
385 | ||
386 | // cache the selection | |
387 | m_selection = page; | |
388 | gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page ); | |
389 | ||
390 | wxGtkNotebookPage* g_page = GetNotebookPage( page ); | |
391 | if (g_page->m_client) | |
392 | g_page->m_client->SetFocus(); | |
393 | ||
394 | return selOld; | |
395 | } | |
396 | ||
397 | void wxNotebook::SetImageList( wxImageList* imageList ) | |
398 | { | |
399 | if (m_ownsImageList) delete m_imageList; | |
400 | m_imageList = imageList; | |
401 | m_ownsImageList = FALSE; | |
402 | } | |
403 | ||
404 | void wxNotebook::AssignImageList( wxImageList* imageList ) | |
405 | { | |
406 | SetImageList(imageList); | |
407 | m_ownsImageList = TRUE; | |
408 | } | |
409 | ||
410 | bool wxNotebook::SetPageText( int page, const wxString &text ) | |
411 | { | |
412 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") ); | |
413 | ||
414 | wxGtkNotebookPage* nb_page = GetNotebookPage(page); | |
415 | ||
416 | wxCHECK_MSG( nb_page, FALSE, wxT("SetPageText: invalid page index") ); | |
417 | ||
418 | nb_page->m_text = text; | |
419 | ||
420 | gtk_label_set( nb_page->m_label, nb_page->m_text.mbc_str() ); | |
421 | ||
422 | return TRUE; | |
423 | } | |
424 | ||
425 | bool wxNotebook::SetPageImage( int page, int image ) | |
426 | { | |
427 | /* HvdH 28-12-98: now it works, but it's a bit of a kludge */ | |
428 | ||
429 | wxGtkNotebookPage* nb_page = GetNotebookPage(page); | |
430 | ||
431 | if (!nb_page) return FALSE; | |
432 | ||
433 | /* Optimization posibility: return immediately if image unchanged. | |
434 | * Not enabled because it may break existing (stupid) code that | |
435 | * manipulates the imagelist to cycle images */ | |
436 | ||
437 | /* if (image == nb_page->m_image) return TRUE; */ | |
438 | ||
439 | /* For different cases: | |
440 | 1) no image -> no image | |
441 | 2) image -> no image | |
442 | 3) no image -> image | |
443 | 4) image -> image */ | |
444 | ||
445 | if (image == -1 && nb_page->m_image == -1) | |
446 | return TRUE; /* Case 1): Nothing to do. */ | |
447 | ||
448 | GtkWidget *pixmapwid = (GtkWidget*) NULL; | |
449 | ||
450 | if (nb_page->m_image != -1) | |
451 | { | |
452 | /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */ | |
453 | ||
454 | GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box)); | |
455 | while (child) | |
456 | { | |
457 | if (GTK_IS_PIXMAP(child->data)) | |
458 | { | |
459 | pixmapwid = GTK_WIDGET(child->data); | |
460 | break; | |
461 | } | |
462 | child = child->next; | |
463 | } | |
464 | ||
465 | /* We should have the pixmap widget now */ | |
466 | wxASSERT(pixmapwid != NULL); | |
467 | ||
468 | if (image == -1) | |
469 | { | |
470 | /* If there's no new widget, just remove the old from the box */ | |
471 | gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid); | |
472 | nb_page->m_image = -1; | |
473 | ||
474 | return TRUE; /* Case 2) */ | |
475 | } | |
476 | } | |
477 | ||
478 | /* Only cases 3) and 4) left */ | |
479 | wxASSERT( m_imageList != NULL ); /* Just in case */ | |
480 | ||
481 | /* Construct the new pixmap */ | |
482 | const wxBitmap *bmp = m_imageList->GetBitmap(image); | |
483 | GdkPixmap *pixmap = bmp->GetPixmap(); | |
484 | GdkBitmap *mask = (GdkBitmap*) NULL; | |
485 | if ( bmp->GetMask() ) | |
486 | { | |
487 | mask = bmp->GetMask()->GetBitmap(); | |
488 | } | |
489 | ||
490 | if (pixmapwid == NULL) | |
491 | { | |
492 | /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */ | |
493 | pixmapwid = gtk_pixmap_new (pixmap, mask ); | |
494 | ||
495 | /* CHECKME: Are these pack flags okay? */ | |
496 | gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, 3); | |
497 | gtk_widget_show(pixmapwid); | |
498 | } | |
499 | else | |
500 | { | |
501 | /* Case 4) Simply replace the pixmap */ | |
502 | gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask); | |
503 | } | |
504 | ||
505 | nb_page->m_image = image; | |
506 | ||
507 | return TRUE; | |
508 | } | |
509 | ||
510 | void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) ) | |
511 | { | |
512 | wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") ); | |
513 | } | |
514 | ||
515 | void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) ) | |
516 | { | |
517 | wxFAIL_MSG( wxT("wxNotebook::SetPadding not implemented") ); | |
518 | } | |
519 | ||
520 | void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz)) | |
521 | { | |
522 | wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") ); | |
523 | } | |
524 | ||
525 | bool wxNotebook::DeleteAllPages() | |
526 | { | |
527 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") ); | |
528 | ||
529 | while (m_pages.GetCount() > 0) | |
530 | DeletePage( m_pages.GetCount()-1 ); | |
531 | ||
532 | return TRUE; | |
533 | } | |
534 | ||
535 | bool wxNotebook::DeletePage( int page ) | |
536 | { | |
537 | wxGtkNotebookPage* nb_page = GetNotebookPage(page); | |
538 | wxCHECK_MSG( nb_page, FALSE, _T("invalid page in wxNotebook::DeletePage") ); | |
539 | ||
540 | // GTK sets GtkNotebook.cur_page to NULL before sending the switch page | |
541 | // event so we have to store the selection internally | |
542 | if ( m_selection == -1 ) | |
543 | { | |
544 | m_selection = GetSelection(); | |
545 | if ( m_selection == (int)m_pages.GetCount() - 1 ) | |
546 | { | |
547 | // the index will become invalid after the page is deleted | |
548 | m_selection = -1; | |
549 | } | |
550 | } | |
551 | ||
552 | nb_page->m_client->Destroy(); | |
553 | m_pages.DeleteObject( nb_page ); | |
554 | ||
555 | return TRUE; | |
556 | } | |
557 | ||
558 | wxNotebookPage *wxNotebook::DoRemovePage( int page ) | |
559 | { | |
560 | wxGtkNotebookPage* nb_page = GetNotebookPage(page); | |
561 | ||
562 | wxCHECK_MSG( nb_page, NULL, _T("wxNotebook::RemovePage: invalid page") ); | |
563 | ||
564 | gtk_widget_ref( nb_page->m_client->m_widget ); | |
565 | gtk_widget_unrealize( nb_page->m_client->m_widget ); | |
566 | gtk_widget_unparent( nb_page->m_client->m_widget ); | |
567 | ||
568 | gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page ); | |
569 | ||
570 | wxNotebookPage *pageRemoved = (wxNotebookPage *)m_pages[page]; | |
571 | m_pages.DeleteObject( nb_page ); | |
572 | ||
573 | return pageRemoved; | |
574 | } | |
575 | ||
576 | bool wxNotebook::InsertPage( int position, wxNotebookPage* win, const wxString& text, | |
577 | bool select, int imageId ) | |
578 | { | |
579 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") ); | |
580 | ||
581 | wxCHECK_MSG( win->GetParent() == this, FALSE, | |
582 | wxT("Can't add a page whose parent is not the notebook!") ); | |
583 | ||
584 | /* don't receive switch page during addition */ | |
585 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget), | |
586 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this ); | |
587 | ||
588 | if (m_themeEnabled) | |
589 | win->SetThemeEnabled(TRUE); | |
590 | ||
591 | GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); | |
592 | ||
593 | wxGtkNotebookPage *page = new wxGtkNotebookPage(); | |
594 | ||
595 | if (position < 0) | |
596 | m_pages.Append( page ); | |
597 | else | |
598 | m_pages.Insert( m_pages.Nth( position ), page ); | |
599 | ||
600 | page->m_client = win; | |
601 | ||
602 | page->m_box = gtk_hbox_new( FALSE, 0 ); | |
603 | gtk_container_border_width( GTK_CONTAINER(page->m_box), 2 ); | |
604 | ||
605 | gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", | |
606 | GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); | |
607 | ||
608 | if (position < 0) | |
609 | gtk_notebook_append_page( notebook, win->m_widget, page->m_box ); | |
610 | else | |
611 | gtk_notebook_insert_page( notebook, win->m_widget, page->m_box, position ); | |
612 | ||
613 | page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data; | |
614 | ||
615 | /* set the label image */ | |
616 | page->m_image = imageId; | |
617 | ||
618 | if (imageId != -1) | |
619 | { | |
620 | wxASSERT( m_imageList != NULL ); | |
621 | ||
622 | const wxBitmap *bmp = m_imageList->GetBitmap(imageId); | |
623 | GdkPixmap *pixmap = bmp->GetPixmap(); | |
624 | GdkBitmap *mask = (GdkBitmap*) NULL; | |
625 | if ( bmp->GetMask() ) | |
626 | { | |
627 | mask = bmp->GetMask()->GetBitmap(); | |
628 | } | |
629 | ||
630 | GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask ); | |
631 | ||
632 | gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3); | |
633 | ||
634 | gtk_widget_show(pixmapwid); | |
635 | } | |
636 | ||
637 | /* set the label text */ | |
638 | page->m_text = text; | |
639 | if (page->m_text.IsEmpty()) page->m_text = wxT(""); | |
640 | ||
641 | page->m_label = GTK_LABEL( gtk_label_new(page->m_text.mbc_str()) ); | |
642 | gtk_box_pack_end( GTK_BOX(page->m_box), GTK_WIDGET(page->m_label), FALSE, FALSE, 3 ); | |
643 | ||
644 | /* show the label */ | |
645 | gtk_widget_show( GTK_WIDGET(page->m_label) ); | |
646 | ||
647 | if (select && (m_pages.GetCount() > 1)) | |
648 | { | |
649 | if (position < 0) | |
650 | SetSelection( GetPageCount()-1 ); | |
651 | else | |
652 | SetSelection( position ); | |
653 | } | |
654 | ||
655 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", | |
656 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this ); | |
657 | ||
658 | return TRUE; | |
659 | } | |
660 | ||
661 | bool wxNotebook::AddPage(wxNotebookPage* win, const wxString& text, | |
662 | bool select, int imageId) | |
663 | { | |
664 | return InsertPage( -1, win, text, select, imageId ); | |
665 | } | |
666 | ||
667 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
668 | { | |
669 | if (event.IsWindowChange()) | |
670 | AdvanceSelection( event.GetDirection() ); | |
671 | else | |
672 | event.Skip(); | |
673 | } | |
674 | ||
675 | #if wxUSE_CONSTRAINTS | |
676 | ||
677 | // override these 2 functions to do nothing: everything is done in OnSize | |
678 | void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) | |
679 | { | |
680 | // don't set the sizes of the pages - their correct size is not yet known | |
681 | wxControl::SetConstraintSizes(FALSE); | |
682 | } | |
683 | ||
684 | bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) | |
685 | { | |
686 | return TRUE; | |
687 | } | |
688 | ||
689 | #endif | |
690 | ||
691 | void wxNotebook::ApplyWidgetStyle() | |
692 | { | |
693 | // TODO, font for labels etc | |
694 | ||
695 | SetWidgetStyle(); | |
696 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
697 | } | |
698 | ||
699 | bool wxNotebook::IsOwnGtkWindow( GdkWindow *window ) | |
700 | { | |
701 | return ((m_widget->window == window) || | |
702 | (GTK_NOTEBOOK(m_widget)->panel == window)); | |
703 | } | |
704 | ||
705 | //----------------------------------------------------------------------------- | |
706 | // wxNotebookEvent | |
707 | //----------------------------------------------------------------------------- | |
708 | ||
709 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) | |
710 | ||
711 | #endif |