]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/notebook.cpp
don't assign the returned value in wxMDIParentFrame::OnCreateClient() to any member...
[wxWidgets.git] / src / gtk / notebook.cpp
CommitLineData
53b28675 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/gtk/notebook.cpp
53b28675
RR
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
65571936 7// Licence: wxWindows licence
53b28675
RR
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
88a7a4e1
WS
13#if wxUSE_NOTEBOOK
14
53b28675 15#include "wx/notebook.h"
dcf924a3 16
88a7a4e1
WS
17#ifndef WX_PRECOMP
18 #include "wx/intl.h"
e4db172a 19 #include "wx/log.h"
de6185e2 20 #include "wx/utils.h"
246c5004 21 #include "wx/msgdlg.h"
0bca0373 22 #include "wx/bitmap.h"
88a7a4e1 23#endif
dcf924a3 24
53b28675 25#include "wx/imaglist.h"
c077ee94 26#include "wx/fontutil.h"
83624f79 27
9e691f46 28#include "wx/gtk/private.h"
9e691f46 29
5e7e9e1b 30#include <gdk/gdkkeysyms.h>
b292e2f5 31
2e4df4bf
VZ
32// ----------------------------------------------------------------------------
33// events
34// ----------------------------------------------------------------------------
35
36DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
37DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
38
b292e2f5
RR
39//-----------------------------------------------------------------------------
40// data
41//-----------------------------------------------------------------------------
42
07b8d7ec 43extern bool g_blockEventsOnDrag;
53b28675 44
219f895a 45//-----------------------------------------------------------------------------
80a58c99 46// wxGtkNotebookPage
219f895a
RR
47//-----------------------------------------------------------------------------
48
07b8d7ec
VZ
49// VZ: this is rather ugly as we keep the pages themselves in an array (it
50// allows us to have quite a few functions implemented in the base class)
51// but the page data is kept in a separate list, so we must maintain them
52// in sync manually... of course, the list had been there before the base
53// class which explains it but it still would be nice to do something
54// about this one day
55
80a58c99 56class wxGtkNotebookPage: public wxObject
219f895a
RR
57{
58public:
c077ee94
RR
59 wxGtkNotebookPage()
60 {
61 m_image = -1;
62 m_page = (GtkNotebookPage *) NULL;
63 m_box = (GtkWidget *) NULL;
c077ee94 64 }
88d19775 65
c077ee94
RR
66 wxString m_text;
67 int m_image;
68 GtkNotebookPage *m_page;
69 GtkLabel *m_label;
70 GtkWidget *m_box; // in which the label and image are packed
219f895a
RR
71};
72
c077ee94 73
07b8d7ec 74#include "wx/listimpl.cpp"
28c91b7d 75WX_DEFINE_LIST(wxGtkNotebookPagesList)
07b8d7ec 76
c077ee94 77
ff829f3f 78//-----------------------------------------------------------------------------
5b011451 79// "switch_page"
ff829f3f
VZ
80//-----------------------------------------------------------------------------
81
865bb325 82extern "C" {
c9882624
RR
83static void gtk_notebook_page_changing_callback( GtkNotebook *widget,
84 GtkNotebookPage *WXUNUSED(gpage),
85 guint page,
86 wxNotebook *notebook )
ff829f3f 87{
c9882624 88 int old = gtk_notebook_get_current_page( widget );
36202885 89
c9882624 90 if ( !notebook->SendPageChangingEvent(page) )
36202885 91 {
c9882624
RR
92 // program doesn't allow the page change
93 g_signal_stop_emission_by_name(notebook->m_widget, "switch_page");
1d6fcbcc
VZ
94 }
95 else
96 {
c9882624
RR
97 // the page change event also reports the old page
98 notebook->m_oldSelection = old;
587ce561 99 }
c9882624
RR
100}
101}
ef44a621 102
c9882624 103extern "C" {
e4161a2a 104static void gtk_notebook_page_changed_callback( GtkNotebook * WXUNUSED(widget),
c9882624 105 GtkNotebookPage *WXUNUSED(gpage),
e4161a2a 106 guint WXUNUSED(page),
c9882624
RR
107 wxNotebook *notebook )
108{
109 int old = notebook->m_oldSelection;
110 notebook->SendPageChangedEvent( old );
ff829f3f 111}
865bb325 112}
ff829f3f 113
6d693bb4
RR
114//-----------------------------------------------------------------------------
115// "realize" from m_widget
116//-----------------------------------------------------------------------------
117
865bb325 118extern "C" {
a237731e 119static void
6d693bb4
RR
120gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
121{
d7928388
RR
122 /* GTK 1.2 up to version 1.2.5 is broken so that we have to call a queue_resize
123 here in order to make repositioning before showing to take effect. */
6d693bb4 124 gtk_widget_queue_resize( win->m_widget );
b292e2f5 125}
865bb325 126}
b292e2f5 127
6ca41e57
RR
128//-----------------------------------------------------------------------------
129// InsertChild callback for wxNotebook
130//-----------------------------------------------------------------------------
131
c821db16 132static void wxInsertChildInNotebook(wxWindow* parent, wxWindow* child)
6ca41e57 133{
fff8475e
RD
134 // Hack Alert! (Part I): This sets the notebook as the parent of the child
135 // widget, and takes care of some details such as updating the state and
136 // style of the child to reflect its new location. We do this early
137 // because without it GetBestSize (which is used to set the initial size
138 // of controls if an explicit size is not given) will often report
139 // incorrect sizes since the widget's style context is not fully known.
140 // See bug #901694 for details
2ded391d 141 // (http://sourceforge.net/tracker/?func=detail&aid=901694&group_id=9863&atid=109863)
fff8475e
RD
142 gtk_widget_set_parent(child->m_widget, parent->m_widget);
143
144 // NOTE: This should be considered a temporary workaround until we can
145 // work out the details and implement delaying the setting of the initial
146 // size of widgets until the size is really needed.
6ca41e57
RR
147}
148
53b28675
RR
149//-----------------------------------------------------------------------------
150// wxNotebook
151//-----------------------------------------------------------------------------
152
8dba4c72 153IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxBookCtrlBase)
53b28675 154
8dba4c72 155BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
b98d804b
RR
156 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
157END_EVENT_TABLE()
f861258f 158
ff829f3f 159void wxNotebook::Init()
53b28675 160{
b318dc42 161 m_padding = 0;
2b5f62a0 162
b292e2f5 163 m_imageList = (wxImageList *) NULL;
c9882624 164 m_oldSelection = -1;
de6185e2 165 m_themeEnabled = true;
ff829f3f
VZ
166}
167
168wxNotebook::wxNotebook()
169{
b292e2f5 170 Init();
ff7b1510 171}
53b28675 172
debe6624 173wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
53b28675 174 const wxPoint& pos, const wxSize& size,
debe6624 175 long style, const wxString& name )
53b28675 176{
b292e2f5
RR
177 Init();
178 Create( parent, id, pos, size, style, name );
ff7b1510 179}
53b28675 180
ff829f3f 181wxNotebook::~wxNotebook()
53b28675 182{
b292e2f5 183 DeleteAllPages();
ff7b1510 184}
53b28675 185
debe6624 186bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
07b8d7ec
VZ
187 const wxPoint& pos, const wxSize& size,
188 long style, const wxString& name )
53b28675 189{
c821db16 190 m_insertCallback = wxInsertChildInNotebook;
b292e2f5 191
90f9b8ef
JS
192 if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
193 style |= wxBK_TOP;
194
4dcaf11a
RR
195 if (!PreCreation( parent, pos, size ) ||
196 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
197 {
223d09f6 198 wxFAIL_MSG( wxT("wxNoteBook creation failed") );
de6185e2 199 return false;
4dcaf11a
RR
200 }
201
ff829f3f 202
b292e2f5 203 m_widget = gtk_notebook_new();
53b28675 204
b292e2f5 205 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
caac5181 206
9fa72bd2 207 g_signal_connect (m_widget, "switch_page",
c9882624
RR
208 G_CALLBACK (gtk_notebook_page_changing_callback), this);
209
210 g_signal_connect_after (m_widget, "switch_page",
211 G_CALLBACK (gtk_notebook_page_changed_callback), this);
ff829f3f 212
f03fc89f 213 m_parent->DoAddChild( this );
ef44a621 214
df034cc6 215 if (m_windowStyle & wxBK_RIGHT)
8712c6e7 216 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT );
df034cc6 217 if (m_windowStyle & wxBK_LEFT)
8712c6e7 218 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT );
df034cc6 219 if (m_windowStyle & wxBK_BOTTOM)
8712c6e7 220 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM );
a3a7f879 221
abdeb9e7 222 PostCreation(size);
ff829f3f 223
9fa72bd2
MR
224 g_signal_connect (m_widget, "realize",
225 G_CALLBACK (gtk_notebook_realized_callback), this);
a6aa9b1e 226
de6185e2 227 return true;
ff7b1510 228}
53b28675 229
ff829f3f 230int wxNotebook::GetSelection() const
53b28675 231{
223d09f6 232 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
53b28675 233
c9882624 234 return gtk_notebook_get_current_page( GTK_NOTEBOOK(m_widget) );
ff7b1510 235}
53b28675 236
789d0a3d 237wxString wxNotebook::GetPageText( size_t page ) const
53b28675 238{
88a7a4e1 239 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid notebook") );
ef44a621 240
80a58c99 241 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
b292e2f5
RR
242 if (nb_page)
243 return nb_page->m_text;
244 else
88a7a4e1 245 return wxEmptyString;
ff7b1510 246}
53b28675 247
789d0a3d 248int wxNotebook::GetPageImage( size_t page ) const
53b28675 249{
223d09f6 250 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 251
80a58c99 252 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
b292e2f5
RR
253 if (nb_page)
254 return nb_page->m_image;
255 else
587ce561 256 return -1;
ff7b1510 257}
53b28675 258
80a58c99 259wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const
53b28675 260{
80a58c99 261 wxCHECK_MSG( m_widget != NULL, (wxGtkNotebookPage*) NULL, wxT("invalid notebook") );
ff829f3f 262
07b8d7ec 263 wxCHECK_MSG( page < (int)m_pagesData.GetCount(), (wxGtkNotebookPage*) NULL, wxT("invalid notebook index") );
a6aa9b1e 264
07b8d7ec 265 return m_pagesData.Item(page)->GetData();
ff7b1510 266}
53b28675 267
1d6fcbcc 268int wxNotebook::DoSetSelection( size_t page, int flags )
53b28675 269{
223d09f6 270 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 271
789d0a3d 272 wxCHECK_MSG( page < m_pagesData.GetCount(), -1, wxT("invalid notebook index") );
ff829f3f 273
587ce561 274 int selOld = GetSelection();
a6aa9b1e 275
1d6fcbcc 276 if ( !(flags & SetSelection_SendEvent) )
c9882624 277 {
98264520
PC
278 g_signal_handlers_block_by_func(m_widget,
279 (gpointer)gtk_notebook_page_changing_callback, this);
c9882624 280
98264520
PC
281 g_signal_handlers_block_by_func(m_widget,
282 (gpointer)gtk_notebook_page_changed_callback, this);
c9882624 283 }
1d6fcbcc 284
38f1df7c 285 gtk_notebook_set_current_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 286
1d6fcbcc
VZ
287 if ( !(flags & SetSelection_SendEvent) )
288 {
98264520
PC
289 g_signal_handlers_unblock_by_func(m_widget,
290 (gpointer)gtk_notebook_page_changing_callback, this);
f4322df6 291
98264520
PC
292 g_signal_handlers_unblock_by_func(m_widget,
293 (gpointer)gtk_notebook_page_changed_callback, this);
1d6fcbcc 294 }
1d6fcbcc 295
07b8d7ec
VZ
296 wxNotebookPage *client = GetPage(page);
297 if ( client )
298 client->SetFocus();
b656febd 299
07b8d7ec 300 return selOld;
ff7b1510 301}
53b28675 302
789d0a3d 303bool wxNotebook::SetPageText( size_t page, const wxString &text )
53b28675 304{
de6185e2 305 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid notebook") );
a81258be 306
80a58c99 307 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 308
de6185e2 309 wxCHECK_MSG( nb_page, false, wxT("SetPageText: invalid page index") );
ff829f3f 310
3eb78d7e 311 nb_page->m_text = text;
ff829f3f 312
a7c12d28 313 gtk_label_set_text( nb_page->m_label, wxGTK_CONV( nb_page->m_text ) );
a6aa9b1e 314
de6185e2 315 return true;
ff7b1510 316}
53b28675 317
789d0a3d 318bool wxNotebook::SetPageImage( size_t page, int image )
53b28675 319{
3eb78d7e 320 /* HvdH 28-12-98: now it works, but it's a bit of a kludge */
f861258f 321
80a58c99 322 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 323
de6185e2 324 if (!nb_page) return false;
f861258f 325
3eb78d7e
RR
326 /* Optimization posibility: return immediately if image unchanged.
327 * Not enabled because it may break existing (stupid) code that
328 * manipulates the imagelist to cycle images */
f861258f 329
de6185e2 330 /* if (image == nb_page->m_image) return true; */
f861258f
VZ
331
332 /* For different cases:
3eb78d7e
RR
333 1) no image -> no image
334 2) image -> no image
335 3) no image -> image
336 4) image -> image */
f861258f 337
3eb78d7e 338 if (image == -1 && nb_page->m_image == -1)
de6185e2 339 return true; /* Case 1): Nothing to do. */
f861258f 340
bbe0af5b 341 GtkWidget *pixmapwid = (GtkWidget*) NULL;
f861258f
VZ
342
343 if (nb_page->m_image != -1)
3eb78d7e
RR
344 {
345 /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */
f861258f 346
2e14a116 347 GList *child = gtk_container_get_children(GTK_CONTAINER(nb_page->m_box));
279b5e2e 348 while (child)
8712c6e7 349 {
d41e1ab4 350 if (GTK_IS_IMAGE(child->data))
8712c6e7
VZ
351 {
352 pixmapwid = GTK_WIDGET(child->data);
353 break;
3eb78d7e 354 }
279b5e2e 355 child = child->next;
8712c6e7 356 }
f861258f 357
3eb78d7e 358 /* We should have the pixmap widget now */
f861258f
VZ
359 wxASSERT(pixmapwid != NULL);
360
361 if (image == -1)
8712c6e7 362 {
3eb78d7e
RR
363 /* If there's no new widget, just remove the old from the box */
364 gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid);
365 nb_page->m_image = -1;
53b28675 366
de6185e2 367 return true; /* Case 2) */
3eb78d7e
RR
368 }
369 }
f861258f 370
3eb78d7e
RR
371 /* Only cases 3) and 4) left */
372 wxASSERT( m_imageList != NULL ); /* Just in case */
f861258f 373
3eb78d7e 374 /* Construct the new pixmap */
49bf4e3e 375 const wxBitmap *bmp = m_imageList->GetBitmapPtr(image);
f861258f
VZ
376
377 if (pixmapwid == NULL)
3eb78d7e
RR
378 {
379 /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
d41e1ab4 380 pixmapwid = gtk_image_new_from_pixbuf(bmp->GetPixbuf());
f861258f 381
3eb78d7e 382 /* CHECKME: Are these pack flags okay? */
b318dc42 383 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);
3eb78d7e
RR
384 gtk_widget_show(pixmapwid);
385 }
f861258f 386 else
3eb78d7e
RR
387 {
388 /* Case 4) Simply replace the pixmap */
d41e1ab4 389 gtk_image_set_from_pixbuf((GtkImage*)pixmapwid, bmp->GetPixbuf());
3eb78d7e 390 }
f861258f 391
3eb78d7e 392 nb_page->m_image = image;
53b28675 393
de6185e2 394 return true;
ff7b1510 395}
53b28675
RR
396
397void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) )
398{
223d09f6 399 wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") );
ff7b1510 400}
53b28675 401
b318dc42 402void wxNotebook::SetPadding( const wxSize &padding )
53b28675 403{
b318dc42
JS
404 wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") );
405
406 m_padding = padding.GetWidth();
407
408 int i;
409 for (i=0; i<int(GetPageCount()); i++)
410 {
411 wxGtkNotebookPage* nb_page = GetNotebookPage(i);
412 wxASSERT(nb_page != NULL);
413
414 if (nb_page->m_image != -1)
415 {
416 // gtk_box_set_child_packing sets padding on BOTH sides
417 // icon provides left padding, label provides center and right
418 int image = nb_page->m_image;
419 SetPageImage(i,-1);
420 SetPageImage(i,image);
421 }
422 wxASSERT(nb_page->m_label);
423 gtk_box_set_child_packing(GTK_BOX(nb_page->m_box),
424 GTK_WIDGET(nb_page->m_label),
425 FALSE, FALSE, m_padding, GTK_PACK_END);
426 }
ff7b1510 427}
53b28675 428
74e3313b 429void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
ca8b28f2 430{
223d09f6 431 wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
ca8b28f2
JS
432}
433
ff829f3f 434bool wxNotebook::DeleteAllPages()
53b28675 435{
de6185e2 436 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid notebook") );
a81258be 437
07b8d7ec
VZ
438 while (m_pagesData.GetCount() > 0)
439 DeletePage( m_pagesData.GetCount()-1 );
440
441 wxASSERT_MSG( GetPageCount() == 0, _T("all pages must have been deleted") );
ff829f3f 442
37144cf0 443 InvalidateBestSize();
10199e27 444 return wxNotebookBase::DeleteAllPages();
ff7b1510 445}
53b28675 446
acb69c13 447wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
53b28675 448{
a27555e4
RR
449 // We cannot remove the page yet, as GTK sends the "switch_page"
450 // signal before it has removed the notebook-page from its
451 // corresponding list. Thus, if we were to remove the page from
452 // m_pages at this point, the two lists of pages would be out
453 // of sync during the PAGE_CHANGING/PAGE_CHANGED events.
454 wxNotebookPage *client = GetPage(page);
10199e27
VZ
455 if ( !client )
456 return NULL;
fed46e72 457
07b8d7ec
VZ
458 gtk_widget_ref( client->m_widget );
459 gtk_widget_unrealize( client->m_widget );
9c862cfb
RR
460
461 // we don't need to unparent the client->m_widget; GTK+ will do
462 // that for us (and will throw a warning if we do it!)
587ce561 463 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 464
a27555e4
RR
465 // It's safe to remove the page now.
466 wxASSERT_MSG(GetPage(page) == client, wxT("pages changed during delete"));
467 wxNotebookBase::DoRemovePage(page);
468
222ed1d6
MB
469 wxGtkNotebookPage* p = GetNotebookPage(page);
470 m_pagesData.DeleteObject(p);
471 delete p;
a27555e4 472
07b8d7ec 473 return client;
ff7b1510 474}
53b28675 475
789d0a3d 476bool wxNotebook::InsertPage( size_t position,
07b8d7ec
VZ
477 wxNotebookPage* win,
478 const wxString& text,
479 bool select,
480 int imageId )
53b28675 481{
de6185e2 482 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid notebook") );
a81258be 483
de6185e2 484 wxCHECK_MSG( win->GetParent() == this, false,
223d09f6 485 wxT("Can't add a page whose parent is not the notebook!") );
8aadf227 486
de6185e2 487 wxCHECK_MSG( position <= GetPageCount(), false,
07b8d7ec
VZ
488 _T("invalid page index in wxNotebookPage::InsertPage()") );
489
fff8475e
RD
490 // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
491 // why this has to be done. NOTE: using gtk_widget_unparent here does not
492 // work as it seems to undo too much and will cause errors in the
493 // gtk_notebook_insert_page below, so instead just clear the parent by
494 // hand here.
d7f1759a
RR
495 win->m_widget->parent = NULL;
496
a2d93e73 497 if (m_themeEnabled)
de6185e2 498 win->SetThemeEnabled(true);
a2d93e73 499
587ce561 500 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
53b28675 501
b318dc42 502 wxGtkNotebookPage *nb_page = new wxGtkNotebookPage();
a6aa9b1e 503
07b8d7ec 504 if ( position == GetPageCount() )
b318dc42 505 m_pagesData.Append( nb_page );
587ce561 506 else
1c36a9d3 507 m_pagesData.Insert( position, nb_page );
a6aa9b1e 508
07b8d7ec 509 m_pages.Insert(win, position);
8aadf227 510
f986fe76
VZ
511 // set the label image and text
512 // this must be done before adding the page, as GetPageText
513 // and GetPageImage will otherwise return wrong values in
514 // the page-changed event that results from inserting the
515 // first page.
516 nb_page->m_image = imageId;
517 nb_page->m_text = wxStripMenuCodes(text);
518
b318dc42 519 nb_page->m_box = gtk_hbox_new( FALSE, 1 );
d41e1ab4 520 gtk_container_set_border_width((GtkContainer*)nb_page->m_box, 2);
587ce561 521
f986fe76
VZ
522 gint idx = gtk_notebook_insert_page(notebook, win->m_widget,
523 nb_page->m_box, position);
ef44a621 524
f986fe76 525 nb_page->m_page = (GtkNotebookPage *)gtk_notebook_get_nth_page(notebook, idx);
a6aa9b1e 526
3eb78d7e 527 if (imageId != -1)
e4a81a2e 528 {
3eb78d7e
RR
529 wxASSERT( m_imageList != NULL );
530
49bf4e3e 531 const wxBitmap *bmp = m_imageList->GetBitmapPtr(imageId);
d41e1ab4 532 GtkWidget* pixmapwid = gtk_image_new_from_pixbuf(bmp->GetPixbuf());
b318dc42 533 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);
3eb78d7e
RR
534 gtk_widget_show(pixmapwid);
535 }
24d20a8f 536
587ce561 537 /* set the label text */
73e68c1d 538 nb_page->m_label = GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page->m_text)) );
b318dc42 539 gtk_box_pack_end( GTK_BOX(nb_page->m_box), GTK_WIDGET(nb_page->m_label), FALSE, FALSE, m_padding );
279b5e2e 540
97357eec
VS
541 /* apply current style */
542 GtkRcStyle *style = CreateWidgetStyle();
543 if ( style )
544 {
545 gtk_widget_modify_style(GTK_WIDGET(nb_page->m_label), style);
546 gtk_rc_style_unref(style);
88d19775
MR
547 }
548
587ce561 549 /* show the label */
b318dc42 550 gtk_widget_show( GTK_WIDGET(nb_page->m_label) );
f4322df6 551
07b8d7ec 552 if (select && (m_pagesData.GetCount() > 1))
587ce561 553 {
c9882624 554 SetSelection( position );
587ce561 555 }
741fd203 556
37144cf0 557 InvalidateBestSize();
de6185e2 558 return true;
ff7b1510 559}
53b28675 560
279b5e2e
VZ
561// helper for HitTest(): check if the point lies inside the given widget which
562// is the child of the notebook whose position and border size are passed as
563// parameters
564static bool
565IsPointInsideWidget(const wxPoint& pt, GtkWidget *w,
566 gint x, gint y, gint border = 0)
567{
568 return
569 (pt.x >= w->allocation.x - x - border) &&
570 (pt.x <= w->allocation.x - x + border + w->allocation.width) &&
571 (pt.y >= w->allocation.y - y - border) &&
572 (pt.y <= w->allocation.y - y + border + w->allocation.height);
573}
574
575int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
576{
577 const gint x = m_widget->allocation.x;
578 const gint y = m_widget->allocation.y;
579
580 const size_t count = GetPageCount();
f660b206
MR
581 size_t i = 0;
582
f660b206 583 GtkNotebook * notebook = GTK_NOTEBOOK(m_widget);
a5bb4f82 584 if (gtk_notebook_get_scrollable(notebook))
f660b206 585 i = g_list_position( notebook->children, notebook->first_tab );
f660b206
MR
586
587 for ( ; i < count; i++ )
279b5e2e
VZ
588 {
589 wxGtkNotebookPage* nb_page = GetNotebookPage(i);
590 GtkWidget *box = nb_page->m_box;
591
279b5e2e 592 const gint border = gtk_container_get_border_width(GTK_CONTAINER(box));
68567a96 593
279b5e2e
VZ
594 if ( IsPointInsideWidget(pt, box, x, y, border) )
595 {
596 // ok, we're inside this tab -- now find out where, if needed
597 if ( flags )
598 {
599 GtkWidget *pixmap = NULL;
600
2e14a116 601 GList *children = gtk_container_get_children(GTK_CONTAINER(box));
279b5e2e
VZ
602 for ( GList *child = children; child; child = child->next )
603 {
d41e1ab4 604 if (GTK_IS_IMAGE(child->data))
279b5e2e
VZ
605 {
606 pixmap = GTK_WIDGET(child->data);
607 break;
608 }
609 }
610
611 if ( children )
612 g_list_free(children);
613
614 if ( pixmap && IsPointInsideWidget(pt, pixmap, x, y) )
615 {
9804d540 616 *flags = wxBK_HITTEST_ONICON;
279b5e2e
VZ
617 }
618 else if ( IsPointInsideWidget(pt, GTK_WIDGET(nb_page->m_label), x, y) )
619 {
9804d540 620 *flags = wxBK_HITTEST_ONLABEL;
279b5e2e
VZ
621 }
622 else
623 {
9804d540 624 *flags = wxBK_HITTEST_ONITEM;
279b5e2e
VZ
625 }
626 }
627
628 return i;
629 }
630 }
631
632 if ( flags )
d0a84b63 633 {
9804d540 634 *flags = wxBK_HITTEST_NOWHERE;
d0a84b63
VZ
635 wxWindowBase * page = GetCurrentPage();
636 if ( page )
637 {
638 // rect origin is in notebook's parent coordinates
639 wxRect rect = page->GetRect();
640
641 // adjust it to the notebook's coordinates
642 wxPoint pos = GetPosition();
643 rect.x -= pos.x;
644 rect.y -= pos.y;
22a35096 645 if ( rect.Contains( pt ) )
9804d540 646 *flags |= wxBK_HITTEST_ONPAGE;
d0a84b63
VZ
647 }
648 }
279b5e2e
VZ
649
650 return wxNOT_FOUND;
651}
652
b98d804b
RR
653void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
654{
f861258f 655 if (event.IsWindowChange())
b98d804b 656 AdvanceSelection( event.GetDirection() );
f861258f 657 else
b98d804b
RR
658 event.Skip();
659}
660
93d38175
VS
661#if wxUSE_CONSTRAINTS
662
5a8c929e 663// override these 2 functions to do nothing: everything is done in OnSize
e3e65dac 664void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
5a8c929e 665{
b292e2f5 666 // don't set the sizes of the pages - their correct size is not yet known
de6185e2 667 wxControl::SetConstraintSizes(false);
5a8c929e
VZ
668}
669
e3e65dac 670bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
5a8c929e 671{
de6185e2 672 return true;
5a8c929e
VZ
673}
674
93d38175
VS
675#endif
676
f40fdaa3 677void wxNotebook::DoApplyWidgetStyle(GtkRcStyle *style)
a81258be 678{
97357eec
VS
679 gtk_widget_modify_style(m_widget, style);
680 size_t cnt = m_pagesData.GetCount();
681 for (size_t i = 0; i < cnt; i++)
682 gtk_widget_modify_style(GTK_WIDGET(GetNotebookPage(i)->m_label), style);
a81258be
RR
683}
684
ef5c70f9 685GdkWindow *wxNotebook::GTKGetWindow(wxArrayGdkWindows& windows) const
58d1c1ae 686{
ef5c70f9
VZ
687 windows.push_back(m_widget->window);
688 windows.push_back(GTK_NOTEBOOK(m_widget)->event_window);
689
690 return NULL;
58d1c1ae
RR
691}
692
9d522606
RD
693// static
694wxVisualAttributes
695wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
696{
697 return GetDefaultAttributesFromGTKWidget(gtk_notebook_new);
698}
699
53b28675 700//-----------------------------------------------------------------------------
ff829f3f 701// wxNotebookEvent
53b28675
RR
702//-----------------------------------------------------------------------------
703
92976ab6 704IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
5b011451 705
a3a7f879 706#endif