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