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