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