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