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