]>
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 | { |
a6aa9b1e | 85 | if (g_isIdle) |
587ce561 | 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 ); | |
a6aa9b1e | 93 | |
587ce561 RR |
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 | { |
a6aa9b1e | 114 | if (g_isIdle) |
587ce561 | 115 | wxapp_install_idle_handler(); |
6d693bb4 | 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 | } |
a6aa9b1e | 124 | |
b292e2f5 | 125 | win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); |
f861258f | 126 | |
6d693bb4 RR |
127 | } |
128 | ||
129 | //----------------------------------------------------------------------------- | |
130 | // "realize" from m_widget | |
131 | //----------------------------------------------------------------------------- | |
132 | ||
a6aa9b1e | 133 | /* GTK 1.2 up to version 1.2.5 is broken so that we have to call a queue_resize |
6d693bb4 RR |
134 | here in order to take repositioning before showing to take effect. */ |
135 | ||
136 | static gint | |
137 | gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win ) | |
138 | { | |
139 | if (g_isIdle) | |
140 | wxapp_install_idle_handler(); | |
141 | ||
142 | gtk_widget_queue_resize( win->m_widget ); | |
143 | ||
144 | return FALSE; | |
b292e2f5 RR |
145 | } |
146 | ||
6ca41e57 RR |
147 | //----------------------------------------------------------------------------- |
148 | // InsertChild callback for wxNotebook | |
149 | //----------------------------------------------------------------------------- | |
150 | ||
587ce561 | 151 | static void wxInsertChildInNotebook( wxNotebook* WXUNUSED(parent), wxWindow* WXUNUSED(child) ) |
6ca41e57 | 152 | { |
587ce561 | 153 | /* we don't do anything here but pray */ |
6ca41e57 RR |
154 | } |
155 | ||
53b28675 RR |
156 | //----------------------------------------------------------------------------- |
157 | // wxNotebook | |
158 | //----------------------------------------------------------------------------- | |
159 | ||
53b28675 RR |
160 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) |
161 | ||
b98d804b RR |
162 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) |
163 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
164 | END_EVENT_TABLE() | |
f861258f | 165 | |
ff829f3f | 166 | void wxNotebook::Init() |
53b28675 | 167 | { |
b292e2f5 RR |
168 | m_imageList = (wxImageList *) NULL; |
169 | m_pages.DeleteContents( TRUE ); | |
29f538ce | 170 | m_lastSelection = -1; |
ff829f3f VZ |
171 | } |
172 | ||
173 | wxNotebook::wxNotebook() | |
174 | { | |
b292e2f5 | 175 | Init(); |
ff7b1510 | 176 | } |
53b28675 | 177 | |
debe6624 | 178 | wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, |
53b28675 | 179 | const wxPoint& pos, const wxSize& size, |
debe6624 | 180 | long style, const wxString& name ) |
53b28675 | 181 | { |
b292e2f5 RR |
182 | Init(); |
183 | Create( parent, id, pos, size, style, name ); | |
ff7b1510 | 184 | } |
53b28675 | 185 | |
ff829f3f | 186 | wxNotebook::~wxNotebook() |
53b28675 | 187 | { |
587ce561 | 188 | /* don't generate change page events any more */ |
a6aa9b1e | 189 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget), |
587ce561 | 190 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this ); |
ff829f3f | 191 | |
b292e2f5 | 192 | DeleteAllPages(); |
ff7b1510 | 193 | } |
53b28675 | 194 | |
debe6624 | 195 | bool wxNotebook::Create(wxWindow *parent, wxWindowID id, |
53b28675 | 196 | const wxPoint& pos, const wxSize& size, |
debe6624 | 197 | long style, const wxString& name ) |
53b28675 | 198 | { |
b292e2f5 RR |
199 | m_needParent = TRUE; |
200 | m_acceptsFocus = TRUE; | |
201 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; | |
202 | ||
4dcaf11a RR |
203 | if (!PreCreation( parent, pos, size ) || |
204 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
205 | { | |
223d09f6 | 206 | wxFAIL_MSG( wxT("wxNoteBook creation failed") ); |
4dcaf11a RR |
207 | return FALSE; |
208 | } | |
209 | ||
ff829f3f | 210 | |
b292e2f5 | 211 | m_widget = gtk_notebook_new(); |
53b28675 | 212 | |
2e563988 | 213 | #ifdef __WXDEBUG__ |
223d09f6 | 214 | debug_focus_in( m_widget, wxT("wxNotebook::m_widget"), name ); |
2e563988 RR |
215 | #endif |
216 | ||
b292e2f5 | 217 | gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); |
caac5181 | 218 | |
587ce561 RR |
219 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", |
220 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this ); | |
ff829f3f | 221 | |
f03fc89f | 222 | m_parent->DoAddChild( this ); |
ef44a621 | 223 | |
a3a7f879 RS |
224 | if(m_windowStyle & wxNB_RIGHT) |
225 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT ); | |
226 | if(m_windowStyle & wxNB_LEFT) | |
227 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT ); | |
228 | if(m_windowStyle & wxNB_BOTTOM) | |
229 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM ); | |
230 | ||
b292e2f5 | 231 | PostCreation(); |
ff829f3f | 232 | |
6d693bb4 RR |
233 | gtk_signal_connect( GTK_OBJECT(m_widget), "realize", |
234 | GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this ); | |
a6aa9b1e | 235 | |
b292e2f5 RR |
236 | Show( TRUE ); |
237 | ||
238 | return TRUE; | |
ff7b1510 | 239 | } |
53b28675 | 240 | |
ed58dbea RR |
241 | void wxNotebook::SetFocus() |
242 | { | |
243 | if (m_pages.GetCount() == 0) return; | |
244 | ||
245 | wxNode *node = m_pages.Nth( GetSelection() ); | |
246 | ||
247 | if (!node) return; | |
248 | ||
249 | wxNotebookPage *page = (wxNotebookPage*) node->Data(); | |
250 | ||
251 | page->m_client->SetFocus(); | |
252 | } | |
253 | ||
ff829f3f | 254 | int wxNotebook::GetSelection() const |
53b28675 | 255 | { |
223d09f6 | 256 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); |
53b28675 | 257 | |
587ce561 | 258 | GList *pages = GTK_NOTEBOOK(m_widget)->children; |
ef44a621 | 259 | |
587ce561 | 260 | if (g_list_length(pages) == 0) return -1; |
53b28675 | 261 | |
587ce561 | 262 | GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); |
a6aa9b1e | 263 | |
29f538ce | 264 | if (notebook->cur_page == NULL) return m_lastSelection; |
a6aa9b1e | 265 | |
29f538ce | 266 | return g_list_index( pages, (gpointer)(notebook->cur_page) ); |
ff7b1510 | 267 | } |
53b28675 | 268 | |
ff829f3f | 269 | int wxNotebook::GetPageCount() const |
53b28675 | 270 | { |
587ce561 | 271 | return (int) g_list_length( GTK_NOTEBOOK(m_widget)->children ); |
ff7b1510 | 272 | } |
53b28675 | 273 | |
ff829f3f | 274 | int wxNotebook::GetRowCount() const |
53b28675 | 275 | { |
b292e2f5 | 276 | return 1; |
ff7b1510 | 277 | } |
53b28675 | 278 | |
ff829f3f | 279 | wxString wxNotebook::GetPageText( int page ) const |
53b28675 | 280 | { |
223d09f6 | 281 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid notebook") ); |
ef44a621 | 282 | |
b292e2f5 RR |
283 | wxNotebookPage* nb_page = GetNotebookPage(page); |
284 | if (nb_page) | |
285 | return nb_page->m_text; | |
286 | else | |
223d09f6 | 287 | return wxT(""); |
ff7b1510 | 288 | } |
53b28675 | 289 | |
ff829f3f | 290 | int wxNotebook::GetPageImage( int page ) const |
53b28675 | 291 | { |
223d09f6 | 292 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); |
a81258be | 293 | |
b292e2f5 RR |
294 | wxNotebookPage* nb_page = GetNotebookPage(page); |
295 | if (nb_page) | |
296 | return nb_page->m_image; | |
297 | else | |
587ce561 | 298 | return -1; |
ff7b1510 | 299 | } |
53b28675 | 300 | |
587ce561 | 301 | wxNotebookPage* wxNotebook::GetNotebookPage( int page ) const |
53b28675 | 302 | { |
223d09f6 | 303 | wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*) NULL, wxT("invalid notebook") ); |
ff829f3f | 304 | |
223d09f6 | 305 | wxCHECK_MSG( page < (int)m_pages.GetCount(), (wxNotebookPage*) NULL, wxT("invalid notebook index") ); |
a6aa9b1e | 306 | |
587ce561 | 307 | wxNode *node = m_pages.Nth( page ); |
a6aa9b1e | 308 | |
587ce561 | 309 | return (wxNotebookPage *) node->Data(); |
ff7b1510 | 310 | } |
53b28675 | 311 | |
ff829f3f | 312 | int wxNotebook::SetSelection( int page ) |
53b28675 | 313 | { |
223d09f6 | 314 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); |
a81258be | 315 | |
223d09f6 | 316 | wxCHECK_MSG( page < (int)m_pages.GetCount(), -1, wxT("invalid notebook index") ); |
ff829f3f | 317 | |
587ce561 | 318 | int selOld = GetSelection(); |
a6aa9b1e | 319 | |
587ce561 | 320 | gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page ); |
ff829f3f | 321 | |
3eb78d7e | 322 | return selOld; |
ff7b1510 | 323 | } |
53b28675 | 324 | |
587ce561 | 325 | void wxNotebook::AdvanceSelection( bool forward ) |
ff829f3f | 326 | { |
223d09f6 | 327 | wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") ); |
a81258be | 328 | |
3eb78d7e RR |
329 | int sel = GetSelection(); |
330 | int max = GetPageCount(); | |
ff829f3f | 331 | |
587ce561 | 332 | if (forward) |
3eb78d7e RR |
333 | SetSelection( sel == max ? 0 : sel + 1 ); |
334 | else | |
b98d804b | 335 | SetSelection( sel == 0 ? max-1 : sel - 1 ); |
ff829f3f VZ |
336 | } |
337 | ||
53b28675 RR |
338 | void wxNotebook::SetImageList( wxImageList* imageList ) |
339 | { | |
3eb78d7e | 340 | m_imageList = imageList; |
ff7b1510 | 341 | } |
53b28675 | 342 | |
ff829f3f | 343 | bool wxNotebook::SetPageText( int page, const wxString &text ) |
53b28675 | 344 | { |
223d09f6 | 345 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") ); |
a81258be | 346 | |
3eb78d7e | 347 | wxNotebookPage* nb_page = GetNotebookPage(page); |
ef44a621 | 348 | |
223d09f6 | 349 | wxCHECK_MSG( nb_page, FALSE, wxT("SetPageText: invalid page index") ); |
ff829f3f | 350 | |
3eb78d7e | 351 | nb_page->m_text = text; |
ff829f3f | 352 | |
587ce561 | 353 | gtk_label_set( nb_page->m_label, nb_page->m_text.mbc_str() ); |
a6aa9b1e | 354 | |
3eb78d7e | 355 | return TRUE; |
ff7b1510 | 356 | } |
53b28675 | 357 | |
debe6624 | 358 | bool wxNotebook::SetPageImage( int page, int image ) |
53b28675 | 359 | { |
3eb78d7e | 360 | /* HvdH 28-12-98: now it works, but it's a bit of a kludge */ |
f861258f | 361 | |
3eb78d7e | 362 | wxNotebookPage* nb_page = GetNotebookPage(page); |
ef44a621 | 363 | |
3eb78d7e | 364 | if (!nb_page) return FALSE; |
f861258f | 365 | |
3eb78d7e RR |
366 | /* Optimization posibility: return immediately if image unchanged. |
367 | * Not enabled because it may break existing (stupid) code that | |
368 | * manipulates the imagelist to cycle images */ | |
f861258f | 369 | |
3eb78d7e | 370 | /* if (image == nb_page->m_image) return TRUE; */ |
f861258f VZ |
371 | |
372 | /* For different cases: | |
3eb78d7e RR |
373 | 1) no image -> no image |
374 | 2) image -> no image | |
375 | 3) no image -> image | |
376 | 4) image -> image */ | |
f861258f | 377 | |
3eb78d7e RR |
378 | if (image == -1 && nb_page->m_image == -1) |
379 | return TRUE; /* Case 1): Nothing to do. */ | |
f861258f | 380 | |
bbe0af5b | 381 | GtkWidget *pixmapwid = (GtkWidget*) NULL; |
f861258f VZ |
382 | |
383 | if (nb_page->m_image != -1) | |
3eb78d7e RR |
384 | { |
385 | /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */ | |
f861258f | 386 | |
3eb78d7e RR |
387 | GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box)); |
388 | while (child) | |
389 | { | |
f861258f | 390 | if (GTK_IS_PIXMAP(child->data)) |
3eb78d7e RR |
391 | { |
392 | pixmapwid = GTK_WIDGET(child->data); | |
393 | break; | |
394 | } | |
395 | child = child->next; | |
396 | } | |
f861258f | 397 | |
3eb78d7e | 398 | /* We should have the pixmap widget now */ |
f861258f VZ |
399 | wxASSERT(pixmapwid != NULL); |
400 | ||
401 | if (image == -1) | |
3eb78d7e RR |
402 | { |
403 | /* If there's no new widget, just remove the old from the box */ | |
404 | gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid); | |
405 | nb_page->m_image = -1; | |
53b28675 | 406 | |
3eb78d7e RR |
407 | return TRUE; /* Case 2) */ |
408 | } | |
409 | } | |
f861258f | 410 | |
3eb78d7e RR |
411 | /* Only cases 3) and 4) left */ |
412 | wxASSERT( m_imageList != NULL ); /* Just in case */ | |
f861258f | 413 | |
3eb78d7e RR |
414 | /* Construct the new pixmap */ |
415 | const wxBitmap *bmp = m_imageList->GetBitmap(image); | |
416 | GdkPixmap *pixmap = bmp->GetPixmap(); | |
417 | GdkBitmap *mask = (GdkBitmap*) NULL; | |
f861258f | 418 | if ( bmp->GetMask() ) |
3eb78d7e RR |
419 | { |
420 | mask = bmp->GetMask()->GetBitmap(); | |
421 | } | |
f861258f VZ |
422 | |
423 | if (pixmapwid == NULL) | |
3eb78d7e RR |
424 | { |
425 | /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */ | |
426 | pixmapwid = gtk_pixmap_new (pixmap, mask ); | |
f861258f | 427 | |
3eb78d7e RR |
428 | /* CHECKME: Are these pack flags okay? */ |
429 | gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, 3); | |
430 | gtk_widget_show(pixmapwid); | |
431 | } | |
f861258f | 432 | else |
3eb78d7e RR |
433 | { |
434 | /* Case 4) Simply replace the pixmap */ | |
435 | gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask); | |
436 | } | |
f861258f | 437 | |
3eb78d7e | 438 | nb_page->m_image = image; |
53b28675 | 439 | |
3eb78d7e | 440 | return TRUE; |
ff7b1510 | 441 | } |
53b28675 RR |
442 | |
443 | void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) ) | |
444 | { | |
223d09f6 | 445 | wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") ); |
ff7b1510 | 446 | } |
53b28675 RR |
447 | |
448 | void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) ) | |
449 | { | |
223d09f6 | 450 | wxFAIL_MSG( wxT("wxNotebook::SetPadding not implemented") ); |
ff7b1510 | 451 | } |
53b28675 | 452 | |
74e3313b | 453 | void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz)) |
ca8b28f2 | 454 | { |
223d09f6 | 455 | wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") ); |
ca8b28f2 JS |
456 | } |
457 | ||
ff829f3f | 458 | bool wxNotebook::DeleteAllPages() |
53b28675 | 459 | { |
223d09f6 | 460 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") ); |
a81258be | 461 | |
587ce561 RR |
462 | while (m_pages.GetCount() > 0) |
463 | DeletePage( m_pages.GetCount()-1 ); | |
ff829f3f | 464 | |
3eb78d7e | 465 | return TRUE; |
ff7b1510 | 466 | } |
53b28675 | 467 | |
ff829f3f | 468 | bool wxNotebook::DeletePage( int page ) |
53b28675 | 469 | { |
3eb78d7e RR |
470 | wxNotebookPage* nb_page = GetNotebookPage(page); |
471 | if (!nb_page) return FALSE; | |
53b28675 | 472 | |
29f538ce RR |
473 | /* GTK sets GtkNotebook.cur_page to NULL before sending |
474 | the switvh page event */ | |
475 | m_lastSelection = GetSelection(); | |
a6aa9b1e | 476 | |
587ce561 | 477 | nb_page->m_client->Destroy(); |
3eb78d7e | 478 | m_pages.DeleteObject( nb_page ); |
a6aa9b1e | 479 | |
29f538ce | 480 | m_lastSelection = -1; |
fed46e72 | 481 | |
3eb78d7e | 482 | return TRUE; |
fed46e72 RR |
483 | } |
484 | ||
485 | bool wxNotebook::RemovePage( int page ) | |
486 | { | |
3eb78d7e | 487 | wxNotebookPage* nb_page = GetNotebookPage(page); |
a6aa9b1e | 488 | |
3eb78d7e | 489 | if (!nb_page) return FALSE; |
fed46e72 | 490 | |
587ce561 | 491 | gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page ); |
ff829f3f | 492 | |
3eb78d7e | 493 | m_pages.DeleteObject( nb_page ); |
ff829f3f | 494 | |
3eb78d7e | 495 | return TRUE; |
ff7b1510 | 496 | } |
53b28675 | 497 | |
587ce561 RR |
498 | bool wxNotebook::InsertPage( int position, wxWindow* win, const wxString& text, |
499 | bool select, int imageId ) | |
53b28675 | 500 | { |
223d09f6 | 501 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") ); |
a81258be | 502 | |
587ce561 | 503 | wxCHECK_MSG( win->GetParent() == this, FALSE, |
223d09f6 | 504 | wxT("Can't add a page whose parent is not the notebook!") ); |
8aadf227 | 505 | |
a6aa9b1e RD |
506 | /* don't receive switch page during addition */ |
507 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget), | |
587ce561 | 508 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this ); |
a6aa9b1e | 509 | |
587ce561 | 510 | GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); |
53b28675 | 511 | |
587ce561 | 512 | wxNotebookPage *page = new wxNotebookPage(); |
a6aa9b1e | 513 | |
587ce561 RR |
514 | if (position < 0) |
515 | m_pages.Append( page ); | |
516 | else | |
517 | m_pages.Insert( m_pages.Nth( position ), page ); | |
a6aa9b1e | 518 | |
587ce561 | 519 | page->m_client = win; |
8aadf227 | 520 | |
587ce561 RR |
521 | page->m_box = gtk_hbox_new( FALSE, 0 ); |
522 | gtk_container_border_width( GTK_CONTAINER(page->m_box), 2 ); | |
523 | ||
d1af991f RR |
524 | gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", |
525 | GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); | |
526 | ||
587ce561 RR |
527 | if (position < 0) |
528 | gtk_notebook_append_page( notebook, win->m_widget, page->m_box ); | |
a6aa9b1e | 529 | else |
587ce561 RR |
530 | gtk_notebook_insert_page( notebook, win->m_widget, page->m_box, position ); |
531 | ||
c693edf3 | 532 | page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data; |
ef44a621 | 533 | |
587ce561 RR |
534 | /* set the label image */ |
535 | page->m_image = imageId; | |
a6aa9b1e | 536 | |
3eb78d7e | 537 | if (imageId != -1) |
e4a81a2e | 538 | { |
3eb78d7e RR |
539 | wxASSERT( m_imageList != NULL ); |
540 | ||
541 | const wxBitmap *bmp = m_imageList->GetBitmap(imageId); | |
542 | GdkPixmap *pixmap = bmp->GetPixmap(); | |
543 | GdkBitmap *mask = (GdkBitmap*) NULL; | |
544 | if ( bmp->GetMask() ) | |
545 | { | |
546 | mask = bmp->GetMask()->GetBitmap(); | |
547 | } | |
e4a81a2e | 548 | |
3eb78d7e | 549 | GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask ); |
24d20a8f | 550 | |
3eb78d7e | 551 | gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3); |
24d20a8f | 552 | |
3eb78d7e RR |
553 | gtk_widget_show(pixmapwid); |
554 | } | |
24d20a8f | 555 | |
587ce561 | 556 | /* set the label text */ |
3eb78d7e | 557 | page->m_text = text; |
223d09f6 | 558 | if (page->m_text.IsEmpty()) page->m_text = wxT(""); |
a6aa9b1e | 559 | |
587ce561 RR |
560 | page->m_label = GTK_LABEL( gtk_label_new(page->m_text.mbc_str()) ); |
561 | gtk_box_pack_end( GTK_BOX(page->m_box), GTK_WIDGET(page->m_label), FALSE, FALSE, 3 ); | |
741fd203 | 562 | |
587ce561 RR |
563 | /* show the label */ |
564 | gtk_widget_show( GTK_WIDGET(page->m_label) ); | |
741fd203 | 565 | |
587ce561 RR |
566 | if (select && (m_pages.GetCount() > 1)) |
567 | { | |
568 | if (position < 0) | |
569 | SetSelection( GetPageCount()-1 ); | |
570 | else | |
571 | SetSelection( position ); | |
572 | } | |
741fd203 | 573 | |
587ce561 RR |
574 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", |
575 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this ); | |
ff829f3f | 576 | |
3eb78d7e | 577 | return TRUE; |
ff7b1510 | 578 | } |
53b28675 | 579 | |
587ce561 RR |
580 | bool wxNotebook::AddPage(wxWindow* win, const wxString& text, |
581 | bool select, int imageId) | |
582 | { | |
583 | return InsertPage( -1, win, text, select, imageId ); | |
584 | } | |
585 | ||
b98d804b RR |
586 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) |
587 | { | |
f861258f | 588 | if (event.IsWindowChange()) |
b98d804b | 589 | AdvanceSelection( event.GetDirection() ); |
f861258f | 590 | else |
b98d804b RR |
591 | event.Skip(); |
592 | } | |
593 | ||
ff829f3f | 594 | wxWindow *wxNotebook::GetPage( int page ) const |
53b28675 | 595 | { |
223d09f6 | 596 | wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, wxT("invalid notebook") ); |
a81258be | 597 | |
b292e2f5 RR |
598 | wxNotebookPage* nb_page = GetNotebookPage(page); |
599 | if (!nb_page) | |
600 | return (wxWindow *) NULL; | |
601 | else | |
602 | return nb_page->m_client; | |
ff7b1510 | 603 | } |
53b28675 | 604 | |
5a8c929e | 605 | // override these 2 functions to do nothing: everything is done in OnSize |
e3e65dac | 606 | void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) |
5a8c929e | 607 | { |
b292e2f5 RR |
608 | // don't set the sizes of the pages - their correct size is not yet known |
609 | wxControl::SetConstraintSizes(FALSE); | |
5a8c929e VZ |
610 | } |
611 | ||
e3e65dac | 612 | bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) |
5a8c929e | 613 | { |
b292e2f5 | 614 | return TRUE; |
5a8c929e VZ |
615 | } |
616 | ||
58614078 | 617 | void wxNotebook::ApplyWidgetStyle() |
a81258be | 618 | { |
b292e2f5 RR |
619 | SetWidgetStyle(); |
620 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
a81258be RR |
621 | } |
622 | ||
58d1c1ae RR |
623 | bool wxNotebook::IsOwnGtkWindow( GdkWindow *window ) |
624 | { | |
625 | return ((m_widget->window == window) || | |
626 | (GTK_NOTEBOOK(m_widget)->panel == window)); | |
627 | } | |
628 | ||
53b28675 | 629 | //----------------------------------------------------------------------------- |
ff829f3f | 630 | // wxNotebookEvent |
53b28675 RR |
631 | //----------------------------------------------------------------------------- |
632 | ||
92976ab6 | 633 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) |
5b011451 | 634 | |
a3a7f879 | 635 | #endif |