]>
Commit | Line | Data |
---|---|---|
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 | |
9dc44eff | 28 | #include <gtk/gtk.h> |
9e691f46 | 29 | #include "wx/gtk/private.h" |
9dc44eff | 30 | #include "wx/gtk/private/gtk2-compat.h" |
9e691f46 | 31 | |
219f895a | 32 | //----------------------------------------------------------------------------- |
80a58c99 | 33 | // wxGtkNotebookPage |
219f895a RR |
34 | //----------------------------------------------------------------------------- |
35 | ||
07b8d7ec VZ |
36 | // VZ: this is rather ugly as we keep the pages themselves in an array (it |
37 | // allows us to have quite a few functions implemented in the base class) | |
38 | // but the page data is kept in a separate list, so we must maintain them | |
39 | // in sync manually... of course, the list had been there before the base | |
40 | // class which explains it but it still would be nice to do something | |
41 | // about this one day | |
42 | ||
80a58c99 | 43 | class wxGtkNotebookPage: public wxObject |
219f895a RR |
44 | { |
45 | public: | |
c58d2238 PC |
46 | GtkWidget* m_box; |
47 | GtkWidget* m_label; | |
48 | GtkWidget* m_image; | |
49 | int m_imageIndex; | |
219f895a RR |
50 | }; |
51 | ||
c077ee94 | 52 | |
07b8d7ec | 53 | #include "wx/listimpl.cpp" |
28c91b7d | 54 | WX_DEFINE_LIST(wxGtkNotebookPagesList) |
07b8d7ec | 55 | |
75c6febf PC |
56 | extern "C" { |
57 | static void event_after(GtkNotebook*, GdkEvent*, wxNotebook*); | |
58 | } | |
c077ee94 | 59 | |
ff829f3f | 60 | //----------------------------------------------------------------------------- |
5b011451 | 61 | // "switch_page" |
ff829f3f VZ |
62 | //----------------------------------------------------------------------------- |
63 | ||
865bb325 | 64 | extern "C" { |
75c6febf | 65 | static void |
681be2ef | 66 | switch_page_after(GtkNotebook* widget, GtkNotebookPage*, guint, wxNotebook* win) |
ff829f3f | 67 | { |
75c6febf | 68 | g_signal_handlers_block_by_func(widget, (void*)switch_page_after, win); |
681be2ef VZ |
69 | |
70 | win->GTKOnPageChanged(); | |
75c6febf PC |
71 | } |
72 | } | |
36202885 | 73 | |
75c6febf PC |
74 | extern "C" { |
75 | static void | |
76 | switch_page(GtkNotebook* widget, GtkNotebookPage*, int page, wxNotebook* win) | |
77 | { | |
78 | win->m_oldSelection = gtk_notebook_get_current_page(widget); | |
79 | ||
80 | if (win->SendPageChangingEvent(page)) | |
81 | // allow change, unblock handler for changed event | |
82 | g_signal_handlers_unblock_by_func(widget, (void*)switch_page_after, win); | |
1d6fcbcc | 83 | else |
75c6febf PC |
84 | // change vetoed, unblock handler to set selection back |
85 | g_signal_handlers_unblock_by_func(widget, (void*)event_after, win); | |
c9882624 RR |
86 | } |
87 | } | |
ef44a621 | 88 | |
75c6febf PC |
89 | //----------------------------------------------------------------------------- |
90 | // "event_after" from m_widget | |
91 | //----------------------------------------------------------------------------- | |
92 | ||
c9882624 | 93 | extern "C" { |
75c6febf | 94 | static void event_after(GtkNotebook* widget, GdkEvent*, wxNotebook* win) |
c9882624 | 95 | { |
75c6febf PC |
96 | g_signal_handlers_block_by_func(widget, (void*)event_after, win); |
97 | g_signal_handlers_block_by_func(widget, (void*)switch_page, win); | |
98 | ||
99 | // restore previous selection | |
100 | gtk_notebook_set_current_page(widget, win->m_oldSelection); | |
101 | ||
102 | g_signal_handlers_unblock_by_func(widget, (void*)switch_page, win); | |
ff829f3f | 103 | } |
865bb325 | 104 | } |
ff829f3f | 105 | |
6ca41e57 RR |
106 | //----------------------------------------------------------------------------- |
107 | // InsertChild callback for wxNotebook | |
108 | //----------------------------------------------------------------------------- | |
109 | ||
48200154 | 110 | void wxNotebook::AddChildGTK(wxWindowGTK* child) |
6ca41e57 | 111 | { |
fff8475e RD |
112 | // Hack Alert! (Part I): This sets the notebook as the parent of the child |
113 | // widget, and takes care of some details such as updating the state and | |
114 | // style of the child to reflect its new location. We do this early | |
115 | // because without it GetBestSize (which is used to set the initial size | |
116 | // of controls if an explicit size is not given) will often report | |
117 | // incorrect sizes since the widget's style context is not fully known. | |
118 | // See bug #901694 for details | |
2ded391d | 119 | // (http://sourceforge.net/tracker/?func=detail&aid=901694&group_id=9863&atid=109863) |
48200154 | 120 | gtk_widget_set_parent(child->m_widget, m_widget); |
fff8475e RD |
121 | |
122 | // NOTE: This should be considered a temporary workaround until we can | |
123 | // work out the details and implement delaying the setting of the initial | |
124 | // size of widgets until the size is really needed. | |
6ca41e57 RR |
125 | } |
126 | ||
53b28675 RR |
127 | //----------------------------------------------------------------------------- |
128 | // wxNotebook | |
129 | //----------------------------------------------------------------------------- | |
130 | ||
8dba4c72 | 131 | BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase) |
b98d804b RR |
132 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) |
133 | END_EVENT_TABLE() | |
f861258f | 134 | |
ff829f3f | 135 | void wxNotebook::Init() |
53b28675 | 136 | { |
b318dc42 | 137 | m_padding = 0; |
c9882624 | 138 | m_oldSelection = -1; |
de6185e2 | 139 | m_themeEnabled = true; |
ff829f3f VZ |
140 | } |
141 | ||
142 | wxNotebook::wxNotebook() | |
143 | { | |
b292e2f5 | 144 | Init(); |
ff7b1510 | 145 | } |
53b28675 | 146 | |
debe6624 | 147 | wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, |
53b28675 | 148 | const wxPoint& pos, const wxSize& size, |
debe6624 | 149 | long style, const wxString& name ) |
53b28675 | 150 | { |
b292e2f5 RR |
151 | Init(); |
152 | Create( parent, id, pos, size, style, name ); | |
ff7b1510 | 153 | } |
53b28675 | 154 | |
ff829f3f | 155 | wxNotebook::~wxNotebook() |
53b28675 | 156 | { |
b292e2f5 | 157 | DeleteAllPages(); |
ff7b1510 | 158 | } |
53b28675 | 159 | |
debe6624 | 160 | bool wxNotebook::Create(wxWindow *parent, wxWindowID id, |
07b8d7ec VZ |
161 | const wxPoint& pos, const wxSize& size, |
162 | long style, const wxString& name ) | |
53b28675 | 163 | { |
90f9b8ef JS |
164 | if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) |
165 | style |= wxBK_TOP; | |
166 | ||
4dcaf11a RR |
167 | if (!PreCreation( parent, pos, size ) || |
168 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
169 | { | |
223d09f6 | 170 | wxFAIL_MSG( wxT("wxNoteBook creation failed") ); |
de6185e2 | 171 | return false; |
4dcaf11a RR |
172 | } |
173 | ||
ff829f3f | 174 | |
b292e2f5 | 175 | m_widget = gtk_notebook_new(); |
9ff9d30c | 176 | g_object_ref(m_widget); |
53b28675 | 177 | |
b292e2f5 | 178 | gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); |
caac5181 | 179 | |
9fa72bd2 | 180 | g_signal_connect (m_widget, "switch_page", |
75c6febf | 181 | G_CALLBACK(switch_page), this); |
c9882624 RR |
182 | |
183 | g_signal_connect_after (m_widget, "switch_page", | |
75c6febf PC |
184 | G_CALLBACK(switch_page_after), this); |
185 | g_signal_handlers_block_by_func(m_widget, (void*)switch_page_after, this); | |
186 | ||
187 | g_signal_connect(m_widget, "event_after", G_CALLBACK(event_after), this); | |
188 | g_signal_handlers_block_by_func(m_widget, (void*)event_after, this); | |
ff829f3f | 189 | |
f03fc89f | 190 | m_parent->DoAddChild( this ); |
ef44a621 | 191 | |
df034cc6 | 192 | if (m_windowStyle & wxBK_RIGHT) |
8712c6e7 | 193 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT ); |
df034cc6 | 194 | if (m_windowStyle & wxBK_LEFT) |
8712c6e7 | 195 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT ); |
df034cc6 | 196 | if (m_windowStyle & wxBK_BOTTOM) |
8712c6e7 | 197 | gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM ); |
a3a7f879 | 198 | |
abdeb9e7 | 199 | PostCreation(size); |
ff829f3f | 200 | |
de6185e2 | 201 | return true; |
ff7b1510 | 202 | } |
53b28675 | 203 | |
ff829f3f | 204 | int wxNotebook::GetSelection() const |
53b28675 | 205 | { |
7e837615 | 206 | wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid notebook") ); |
53b28675 | 207 | |
c9882624 | 208 | return gtk_notebook_get_current_page( GTK_NOTEBOOK(m_widget) ); |
ff7b1510 | 209 | } |
53b28675 | 210 | |
789d0a3d | 211 | wxString wxNotebook::GetPageText( size_t page ) const |
53b28675 | 212 | { |
c58d2238 | 213 | wxCHECK_MSG(page < GetPageCount(), wxEmptyString, "invalid notebook index"); |
ef44a621 | 214 | |
c58d2238 PC |
215 | GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label); |
216 | return wxGTK_CONV_BACK(gtk_label_get_text(label)); | |
ff7b1510 | 217 | } |
53b28675 | 218 | |
789d0a3d | 219 | int wxNotebook::GetPageImage( size_t page ) const |
53b28675 | 220 | { |
7e837615 | 221 | wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index"); |
a81258be | 222 | |
c58d2238 | 223 | return GetNotebookPage(page)->m_imageIndex; |
ff7b1510 | 224 | } |
53b28675 | 225 | |
80a58c99 | 226 | wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const |
53b28675 | 227 | { |
07b8d7ec | 228 | return m_pagesData.Item(page)->GetData(); |
ff7b1510 | 229 | } |
53b28675 | 230 | |
1d6fcbcc | 231 | int wxNotebook::DoSetSelection( size_t page, int flags ) |
53b28675 | 232 | { |
7e837615 | 233 | wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index"); |
ff829f3f | 234 | |
587ce561 | 235 | int selOld = GetSelection(); |
a6aa9b1e | 236 | |
1d6fcbcc | 237 | if ( !(flags & SetSelection_SendEvent) ) |
c9882624 | 238 | { |
75c6febf | 239 | g_signal_handlers_block_by_func(m_widget, (void*)switch_page, this); |
c9882624 | 240 | } |
1d6fcbcc | 241 | |
38f1df7c | 242 | gtk_notebook_set_current_page( GTK_NOTEBOOK(m_widget), page ); |
ff829f3f | 243 | |
1d6fcbcc VZ |
244 | if ( !(flags & SetSelection_SendEvent) ) |
245 | { | |
75c6febf | 246 | g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this); |
1d6fcbcc | 247 | } |
1d6fcbcc | 248 | |
681be2ef VZ |
249 | m_selection = page; |
250 | ||
07b8d7ec VZ |
251 | wxNotebookPage *client = GetPage(page); |
252 | if ( client ) | |
253 | client->SetFocus(); | |
b656febd | 254 | |
07b8d7ec | 255 | return selOld; |
ff7b1510 | 256 | } |
53b28675 | 257 | |
681be2ef VZ |
258 | void wxNotebook::GTKOnPageChanged() |
259 | { | |
260 | m_selection = gtk_notebook_get_current_page(GTK_NOTEBOOK(m_widget)); | |
261 | ||
262 | SendPageChangedEvent(m_oldSelection); | |
263 | } | |
264 | ||
789d0a3d | 265 | bool wxNotebook::SetPageText( size_t page, const wxString &text ) |
53b28675 | 266 | { |
c58d2238 | 267 | wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index"); |
ff829f3f | 268 | |
c58d2238 PC |
269 | GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label); |
270 | gtk_label_set_text(label, wxGTK_CONV(text)); | |
a6aa9b1e | 271 | |
de6185e2 | 272 | return true; |
ff7b1510 | 273 | } |
53b28675 | 274 | |
789d0a3d | 275 | bool wxNotebook::SetPageImage( size_t page, int image ) |
53b28675 | 276 | { |
c58d2238 | 277 | wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index"); |
f861258f | 278 | |
c58d2238 PC |
279 | wxGtkNotebookPage* pageData = GetNotebookPage(page); |
280 | if (image >= 0) | |
3eb78d7e | 281 | { |
abfdefed VZ |
282 | wxCHECK_MSG(HasImageList(), false, "invalid notebook imagelist"); |
283 | const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(image); | |
c58d2238 PC |
284 | if (bitmap == NULL) |
285 | return false; | |
286 | if (pageData->m_image) | |
8712c6e7 | 287 | { |
c58d2238 PC |
288 | gtk_image_set_from_pixbuf( |
289 | GTK_IMAGE(pageData->m_image), bitmap->GetPixbuf()); | |
8712c6e7 | 290 | } |
c58d2238 | 291 | else |
8712c6e7 | 292 | { |
c58d2238 PC |
293 | pageData->m_image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf()); |
294 | gtk_widget_show(pageData->m_image); | |
295 | gtk_box_pack_start(GTK_BOX(pageData->m_box), | |
296 | pageData->m_image, false, false, m_padding); | |
3eb78d7e RR |
297 | } |
298 | } | |
c58d2238 | 299 | else if (pageData->m_image) |
3eb78d7e | 300 | { |
c58d2238 PC |
301 | gtk_widget_destroy(pageData->m_image); |
302 | pageData->m_image = NULL; | |
3eb78d7e | 303 | } |
c58d2238 | 304 | pageData->m_imageIndex = image; |
53b28675 | 305 | |
de6185e2 | 306 | return true; |
ff7b1510 | 307 | } |
53b28675 | 308 | |
864181f4 | 309 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const |
53b28675 | 310 | { |
864181f4 VZ |
311 | // Compute the max size of the tab labels. |
312 | wxSize sizeTabMax; | |
313 | const size_t pageCount = GetPageCount(); | |
314 | for ( size_t n = 0; n < pageCount; n++ ) | |
315 | { | |
316 | GtkRequisition req; | |
317 | gtk_widget_size_request(GetNotebookPage(n)->m_box, &req); | |
318 | sizeTabMax.IncTo(wxSize(req.width, req.height)); | |
319 | } | |
320 | ||
321 | // Unfortunately this doesn't account for the real tab size and I don't | |
322 | // know how to find it, e.g. where do the margins below come from. | |
323 | const int PAGE_MARGIN = 3; | |
324 | const int TAB_MARGIN = 4; | |
325 | ||
326 | sizeTabMax.IncBy(3*TAB_MARGIN); | |
327 | ||
328 | wxSize sizeFull(sizePage); | |
329 | if ( IsVertical() ) | |
330 | sizeFull.y += sizeTabMax.y; | |
331 | else | |
332 | sizeFull.x += sizeTabMax.x; | |
333 | ||
334 | sizeFull.IncBy(2*PAGE_MARGIN); | |
335 | ||
336 | return sizeFull; | |
ff7b1510 | 337 | } |
53b28675 | 338 | |
b318dc42 | 339 | void wxNotebook::SetPadding( const wxSize &padding ) |
53b28675 | 340 | { |
b318dc42 JS |
341 | wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") ); |
342 | ||
343 | m_padding = padding.GetWidth(); | |
344 | ||
c58d2238 | 345 | for (size_t i = GetPageCount(); i--;) |
b318dc42 | 346 | { |
c58d2238 PC |
347 | wxGtkNotebookPage* pageData = GetNotebookPage(i); |
348 | if (pageData->m_image) | |
b318dc42 | 349 | { |
c58d2238 PC |
350 | gtk_box_set_child_packing(GTK_BOX(pageData->m_box), |
351 | pageData->m_image, false, false, m_padding, GTK_PACK_START); | |
b318dc42 | 352 | } |
c58d2238 PC |
353 | gtk_box_set_child_packing(GTK_BOX(pageData->m_box), |
354 | pageData->m_label, false, false, m_padding, GTK_PACK_END); | |
b318dc42 | 355 | } |
ff7b1510 | 356 | } |
53b28675 | 357 | |
74e3313b | 358 | void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz)) |
ca8b28f2 | 359 | { |
223d09f6 | 360 | wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") ); |
ca8b28f2 JS |
361 | } |
362 | ||
ff829f3f | 363 | bool wxNotebook::DeleteAllPages() |
53b28675 | 364 | { |
c58d2238 PC |
365 | for (size_t i = GetPageCount(); i--;) |
366 | DeletePage(i); | |
a81258be | 367 | |
10199e27 | 368 | return wxNotebookBase::DeleteAllPages(); |
ff7b1510 | 369 | } |
53b28675 | 370 | |
acb69c13 | 371 | wxNotebookPage *wxNotebook::DoRemovePage( size_t page ) |
53b28675 | 372 | { |
a27555e4 RR |
373 | // We cannot remove the page yet, as GTK sends the "switch_page" |
374 | // signal before it has removed the notebook-page from its | |
375 | // corresponding list. Thus, if we were to remove the page from | |
376 | // m_pages at this point, the two lists of pages would be out | |
377 | // of sync during the PAGE_CHANGING/PAGE_CHANGED events. | |
378 | wxNotebookPage *client = GetPage(page); | |
10199e27 VZ |
379 | if ( !client ) |
380 | return NULL; | |
fed46e72 | 381 | |
9c862cfb RR |
382 | // we don't need to unparent the client->m_widget; GTK+ will do |
383 | // that for us (and will throw a warning if we do it!) | |
587ce561 | 384 | gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page ); |
ff829f3f | 385 | |
a27555e4 RR |
386 | // It's safe to remove the page now. |
387 | wxASSERT_MSG(GetPage(page) == client, wxT("pages changed during delete")); | |
388 | wxNotebookBase::DoRemovePage(page); | |
389 | ||
222ed1d6 MB |
390 | wxGtkNotebookPage* p = GetNotebookPage(page); |
391 | m_pagesData.DeleteObject(p); | |
392 | delete p; | |
03647350 | 393 | |
07b8d7ec | 394 | return client; |
ff7b1510 | 395 | } |
53b28675 | 396 | |
789d0a3d | 397 | bool wxNotebook::InsertPage( size_t position, |
07b8d7ec VZ |
398 | wxNotebookPage* win, |
399 | const wxString& text, | |
400 | bool select, | |
401 | int imageId ) | |
53b28675 | 402 | { |
de6185e2 | 403 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid notebook") ); |
a81258be | 404 | |
de6185e2 | 405 | wxCHECK_MSG( win->GetParent() == this, false, |
223d09f6 | 406 | wxT("Can't add a page whose parent is not the notebook!") ); |
8aadf227 | 407 | |
de6185e2 | 408 | wxCHECK_MSG( position <= GetPageCount(), false, |
9a83f860 | 409 | wxT("invalid page index in wxNotebookPage::InsertPage()") ); |
07b8d7ec | 410 | |
48200154 | 411 | // Hack Alert! (Part II): See above in wxNotebook::AddChildGTK |
9ff9d30c PC |
412 | // why this has to be done. |
413 | gtk_widget_unparent(win->m_widget); | |
d7f1759a | 414 | |
a2d93e73 | 415 | if (m_themeEnabled) |
de6185e2 | 416 | win->SetThemeEnabled(true); |
a2d93e73 | 417 | |
587ce561 | 418 | GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); |
53b28675 | 419 | |
c58d2238 | 420 | wxGtkNotebookPage* pageData = new wxGtkNotebookPage; |
a6aa9b1e | 421 | |
07b8d7ec | 422 | m_pages.Insert(win, position); |
c58d2238 | 423 | m_pagesData.Insert(position, pageData); |
8aadf227 | 424 | |
f986fe76 VZ |
425 | // set the label image and text |
426 | // this must be done before adding the page, as GetPageText | |
427 | // and GetPageImage will otherwise return wrong values in | |
428 | // the page-changed event that results from inserting the | |
429 | // first page. | |
c58d2238 | 430 | pageData->m_imageIndex = imageId; |
f986fe76 | 431 | |
c58d2238 PC |
432 | pageData->m_box = gtk_hbox_new(false, 1); |
433 | gtk_container_set_border_width(GTK_CONTAINER(pageData->m_box), 2); | |
a6aa9b1e | 434 | |
c58d2238 | 435 | pageData->m_image = NULL; |
3eb78d7e | 436 | if (imageId != -1) |
e4a81a2e | 437 | { |
abfdefed | 438 | if (HasImageList()) |
c58d2238 | 439 | { |
abfdefed | 440 | const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(imageId); |
c58d2238 PC |
441 | pageData->m_image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf()); |
442 | gtk_box_pack_start(GTK_BOX(pageData->m_box), | |
443 | pageData->m_image, false, false, m_padding); | |
444 | } | |
445 | else | |
4c2ea599 | 446 | { |
c58d2238 | 447 | wxFAIL_MSG("invalid notebook imagelist"); |
4c2ea599 | 448 | } |
3eb78d7e | 449 | } |
24d20a8f | 450 | |
587ce561 | 451 | /* set the label text */ |
c58d2238 PC |
452 | pageData->m_label = gtk_label_new(wxGTK_CONV(wxStripMenuCodes(text))); |
453 | gtk_box_pack_end(GTK_BOX(pageData->m_box), | |
454 | pageData->m_label, false, false, m_padding); | |
455 | ||
456 | gtk_widget_show_all(pageData->m_box); | |
457 | gtk_notebook_insert_page(notebook, win->m_widget, pageData->m_box, position); | |
279b5e2e | 458 | |
97357eec | 459 | /* apply current style */ |
9dc44eff PC |
460 | #ifdef __WXGTK3__ |
461 | GTKApplyStyle(pageData->m_label, NULL); | |
462 | #else | |
496e7ec6 | 463 | GtkRcStyle *style = GTKCreateWidgetStyle(); |
97357eec VS |
464 | if ( style ) |
465 | { | |
c58d2238 | 466 | gtk_widget_modify_style(pageData->m_label, style); |
385e8575 | 467 | g_object_unref(style); |
88d19775 | 468 | } |
9dc44eff | 469 | #endif |
88d19775 | 470 | |
c58d2238 | 471 | if (select && GetPageCount() > 1) |
587ce561 | 472 | { |
c9882624 | 473 | SetSelection( position ); |
587ce561 | 474 | } |
741fd203 | 475 | |
37144cf0 | 476 | InvalidateBestSize(); |
de6185e2 | 477 | return true; |
ff7b1510 | 478 | } |
53b28675 | 479 | |
279b5e2e VZ |
480 | // helper for HitTest(): check if the point lies inside the given widget which |
481 | // is the child of the notebook whose position and border size are passed as | |
482 | // parameters | |
483 | static bool | |
484 | IsPointInsideWidget(const wxPoint& pt, GtkWidget *w, | |
485 | gint x, gint y, gint border = 0) | |
486 | { | |
385e8575 PC |
487 | GtkAllocation a; |
488 | gtk_widget_get_allocation(w, &a); | |
279b5e2e | 489 | return |
385e8575 PC |
490 | (pt.x >= a.x - x - border) && |
491 | (pt.x <= a.x - x + border + a.width) && | |
492 | (pt.y >= a.y - y - border) && | |
493 | (pt.y <= a.y - y + border + a.height); | |
279b5e2e VZ |
494 | } |
495 | ||
496 | int wxNotebook::HitTest(const wxPoint& pt, long *flags) const | |
497 | { | |
385e8575 PC |
498 | GtkAllocation a; |
499 | gtk_widget_get_allocation(m_widget, &a); | |
500 | const int x = a.x; | |
501 | const int y = a.y; | |
279b5e2e VZ |
502 | |
503 | const size_t count = GetPageCount(); | |
f660b206 MR |
504 | size_t i = 0; |
505 | ||
385e8575 | 506 | #if !GTK_CHECK_VERSION(3,0,0) && !defined(GSEAL_ENABLE) |
f660b206 | 507 | GtkNotebook * notebook = GTK_NOTEBOOK(m_widget); |
a5bb4f82 | 508 | if (gtk_notebook_get_scrollable(notebook)) |
f660b206 | 509 | i = g_list_position( notebook->children, notebook->first_tab ); |
385e8575 | 510 | #endif |
f660b206 MR |
511 | |
512 | for ( ; i < count; i++ ) | |
279b5e2e | 513 | { |
c58d2238 PC |
514 | wxGtkNotebookPage* pageData = GetNotebookPage(i); |
515 | GtkWidget* box = pageData->m_box; | |
279b5e2e | 516 | |
279b5e2e | 517 | const gint border = gtk_container_get_border_width(GTK_CONTAINER(box)); |
68567a96 | 518 | |
279b5e2e VZ |
519 | if ( IsPointInsideWidget(pt, box, x, y, border) ) |
520 | { | |
521 | // ok, we're inside this tab -- now find out where, if needed | |
522 | if ( flags ) | |
523 | { | |
c58d2238 | 524 | if (pageData->m_image && IsPointInsideWidget(pt, pageData->m_image, x, y)) |
279b5e2e | 525 | { |
9804d540 | 526 | *flags = wxBK_HITTEST_ONICON; |
279b5e2e | 527 | } |
c58d2238 | 528 | else if (IsPointInsideWidget(pt, pageData->m_label, x, y)) |
279b5e2e | 529 | { |
9804d540 | 530 | *flags = wxBK_HITTEST_ONLABEL; |
279b5e2e VZ |
531 | } |
532 | else | |
533 | { | |
9804d540 | 534 | *flags = wxBK_HITTEST_ONITEM; |
279b5e2e VZ |
535 | } |
536 | } | |
537 | ||
538 | return i; | |
539 | } | |
540 | } | |
541 | ||
542 | if ( flags ) | |
d0a84b63 | 543 | { |
9804d540 | 544 | *flags = wxBK_HITTEST_NOWHERE; |
d0a84b63 VZ |
545 | wxWindowBase * page = GetCurrentPage(); |
546 | if ( page ) | |
547 | { | |
548 | // rect origin is in notebook's parent coordinates | |
549 | wxRect rect = page->GetRect(); | |
550 | ||
551 | // adjust it to the notebook's coordinates | |
552 | wxPoint pos = GetPosition(); | |
553 | rect.x -= pos.x; | |
554 | rect.y -= pos.y; | |
22a35096 | 555 | if ( rect.Contains( pt ) ) |
9804d540 | 556 | *flags |= wxBK_HITTEST_ONPAGE; |
d0a84b63 VZ |
557 | } |
558 | } | |
279b5e2e VZ |
559 | |
560 | return wxNOT_FOUND; | |
561 | } | |
562 | ||
b98d804b RR |
563 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) |
564 | { | |
f861258f | 565 | if (event.IsWindowChange()) |
b98d804b | 566 | AdvanceSelection( event.GetDirection() ); |
f861258f | 567 | else |
b98d804b RR |
568 | event.Skip(); |
569 | } | |
570 | ||
93d38175 VS |
571 | #if wxUSE_CONSTRAINTS |
572 | ||
5a8c929e | 573 | // override these 2 functions to do nothing: everything is done in OnSize |
e3e65dac | 574 | void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) |
5a8c929e | 575 | { |
b292e2f5 | 576 | // don't set the sizes of the pages - their correct size is not yet known |
de6185e2 | 577 | wxControl::SetConstraintSizes(false); |
5a8c929e VZ |
578 | } |
579 | ||
e3e65dac | 580 | bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) |
5a8c929e | 581 | { |
de6185e2 | 582 | return true; |
5a8c929e VZ |
583 | } |
584 | ||
93d38175 VS |
585 | #endif |
586 | ||
f40fdaa3 | 587 | void wxNotebook::DoApplyWidgetStyle(GtkRcStyle *style) |
a81258be | 588 | { |
9dc44eff | 589 | GTKApplyStyle(m_widget, style); |
c58d2238 | 590 | for (size_t i = GetPageCount(); i--;) |
9dc44eff | 591 | GTKApplyStyle(GetNotebookPage(i)->m_label, style); |
a81258be RR |
592 | } |
593 | ||
ef5c70f9 | 594 | GdkWindow *wxNotebook::GTKGetWindow(wxArrayGdkWindows& windows) const |
58d1c1ae | 595 | { |
385e8575 | 596 | windows.push_back(gtk_widget_get_window(m_widget)); |
9dc44eff PC |
597 | #ifdef __WXGTK3__ |
598 | // no access to internal GdkWindows | |
599 | #else | |
ef5c70f9 | 600 | windows.push_back(GTK_NOTEBOOK(m_widget)->event_window); |
9dc44eff | 601 | #endif |
ef5c70f9 VZ |
602 | |
603 | return NULL; | |
58d1c1ae RR |
604 | } |
605 | ||
9d522606 RD |
606 | // static |
607 | wxVisualAttributes | |
608 | wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
609 | { | |
610 | return GetDefaultAttributesFromGTKWidget(gtk_notebook_new); | |
611 | } | |
612 | ||
a3a7f879 | 613 | #endif |