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