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