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