| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: src/gtk/frame.cpp |
| 3 | // Purpose: |
| 4 | // Author: Robert Roebling |
| 5 | // Id: $Id$ |
| 6 | // Copyright: (c) 1998 Robert Roebling |
| 7 | // Licence: wxWindows licence |
| 8 | ///////////////////////////////////////////////////////////////////////////// |
| 9 | |
| 10 | // For compilers that support precompilation, includes "wx.h". |
| 11 | #include "wx/wxprec.h" |
| 12 | |
| 13 | #include "wx/frame.h" |
| 14 | |
| 15 | #ifndef WX_PRECOMP |
| 16 | #include "wx/menu.h" |
| 17 | #include "wx/toolbar.h" |
| 18 | #include "wx/statusbr.h" |
| 19 | #endif // WX_PRECOMP |
| 20 | |
| 21 | #include "wx/gtk/private.h" |
| 22 | #include "wx/gtk/win_gtk.h" |
| 23 | |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | // constants |
| 26 | // ---------------------------------------------------------------------------- |
| 27 | |
| 28 | static const int wxSTATUS_HEIGHT = 25; |
| 29 | static const int wxPLACE_HOLDER = 0; |
| 30 | |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | // event tables |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | |
| 35 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
| 36 | |
| 37 | // ============================================================================ |
| 38 | // implementation |
| 39 | // ============================================================================ |
| 40 | |
| 41 | // ---------------------------------------------------------------------------- |
| 42 | // GTK callbacks |
| 43 | // ---------------------------------------------------------------------------- |
| 44 | |
| 45 | #if wxUSE_MENUS_NATIVE |
| 46 | |
| 47 | //----------------------------------------------------------------------------- |
| 48 | // "child_attached" of menu bar |
| 49 | //----------------------------------------------------------------------------- |
| 50 | |
| 51 | extern "C" { |
| 52 | static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) |
| 53 | { |
| 54 | if (!win->m_hasVMT) return; |
| 55 | |
| 56 | win->m_menuBarDetached = false; |
| 57 | win->GtkUpdateSize(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | //----------------------------------------------------------------------------- |
| 62 | // "child_detached" of menu bar |
| 63 | //----------------------------------------------------------------------------- |
| 64 | |
| 65 | extern "C" { |
| 66 | static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) |
| 67 | { |
| 68 | if (g_isIdle) |
| 69 | wxapp_install_idle_handler(); |
| 70 | |
| 71 | if (!win->m_hasVMT) return; |
| 72 | |
| 73 | // Raise the client area area |
| 74 | gdk_window_raise( win->m_wxwindow->window ); |
| 75 | |
| 76 | win->m_menuBarDetached = true; |
| 77 | win->GtkUpdateSize(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | #endif // wxUSE_MENUS_NATIVE |
| 82 | |
| 83 | #if wxUSE_TOOLBAR |
| 84 | //----------------------------------------------------------------------------- |
| 85 | // "child_attached" of tool bar |
| 86 | //----------------------------------------------------------------------------- |
| 87 | |
| 88 | extern "C" { |
| 89 | static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) |
| 90 | { |
| 91 | if (!win->m_hasVMT) return; |
| 92 | |
| 93 | win->m_toolBarDetached = false; |
| 94 | win->GtkUpdateSize(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | //----------------------------------------------------------------------------- |
| 99 | // "child_detached" of tool bar |
| 100 | //----------------------------------------------------------------------------- |
| 101 | |
| 102 | extern "C" { |
| 103 | static void gtk_toolbar_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) |
| 104 | { |
| 105 | if (g_isIdle) |
| 106 | wxapp_install_idle_handler(); |
| 107 | |
| 108 | if (!win->m_hasVMT) return; |
| 109 | |
| 110 | // Raise the client area area |
| 111 | gdk_window_raise( win->m_wxwindow->window ); |
| 112 | |
| 113 | win->m_toolBarDetached = true; |
| 114 | win->GtkUpdateSize(); |
| 115 | } |
| 116 | } |
| 117 | #endif // wxUSE_TOOLBAR |
| 118 | |
| 119 | |
| 120 | // ---------------------------------------------------------------------------- |
| 121 | // wxFrame itself |
| 122 | // ---------------------------------------------------------------------------- |
| 123 | |
| 124 | //----------------------------------------------------------------------------- |
| 125 | // InsertChild for wxFrame |
| 126 | //----------------------------------------------------------------------------- |
| 127 | |
| 128 | /* Callback for wxFrame. This very strange beast has to be used because |
| 129 | * C++ has no virtual methods in a constructor. We have to emulate a |
| 130 | * virtual function here as wxWidgets requires different ways to insert |
| 131 | * a child in container classes. */ |
| 132 | |
| 133 | static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child ) |
| 134 | { |
| 135 | wxASSERT( GTK_IS_WIDGET(child->m_widget) ); |
| 136 | |
| 137 | if (!parent->m_insertInClientArea) |
| 138 | { |
| 139 | // These are outside the client area |
| 140 | wxFrame* frame = (wxFrame*) parent; |
| 141 | gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget), |
| 142 | GTK_WIDGET(child->m_widget), |
| 143 | child->m_x, |
| 144 | child->m_y, |
| 145 | child->m_width, |
| 146 | child->m_height ); |
| 147 | |
| 148 | #if wxUSE_TOOLBAR_NATIVE |
| 149 | // We connect to these events for recalculating the client area |
| 150 | // space when the toolbar is floating |
| 151 | if (wxIS_KIND_OF(child,wxToolBar)) |
| 152 | { |
| 153 | wxToolBar *toolBar = (wxToolBar*) child; |
| 154 | if (toolBar->GetWindowStyle() & wxTB_DOCKABLE) |
| 155 | { |
| 156 | g_signal_connect (toolBar->m_widget, "child_attached", |
| 157 | G_CALLBACK (gtk_toolbar_attached_callback), |
| 158 | parent); |
| 159 | g_signal_connect (toolBar->m_widget, "child_detached", |
| 160 | G_CALLBACK (gtk_toolbar_detached_callback), |
| 161 | parent); |
| 162 | } |
| 163 | } |
| 164 | #endif // wxUSE_TOOLBAR |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | // These are inside the client area |
| 169 | gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), |
| 170 | GTK_WIDGET(child->m_widget), |
| 171 | child->m_x, |
| 172 | child->m_y, |
| 173 | child->m_width, |
| 174 | child->m_height ); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | // ---------------------------------------------------------------------------- |
| 179 | // wxFrame creation |
| 180 | // ---------------------------------------------------------------------------- |
| 181 | |
| 182 | void wxFrame::Init() |
| 183 | { |
| 184 | m_menuBarDetached = false; |
| 185 | m_toolBarDetached = false; |
| 186 | m_menuBarHeight = 2; |
| 187 | } |
| 188 | |
| 189 | bool wxFrame::Create( wxWindow *parent, |
| 190 | wxWindowID id, |
| 191 | const wxString& title, |
| 192 | const wxPoint& pos, |
| 193 | const wxSize& sizeOrig, |
| 194 | long style, |
| 195 | const wxString &name ) |
| 196 | { |
| 197 | bool rt = wxTopLevelWindow::Create(parent, id, title, pos, sizeOrig, |
| 198 | style, name); |
| 199 | m_insertCallback = (wxInsertChildFunction) wxInsertChildInFrame; |
| 200 | |
| 201 | return rt; |
| 202 | } |
| 203 | |
| 204 | wxFrame::~wxFrame() |
| 205 | { |
| 206 | m_isBeingDeleted = true; |
| 207 | DeleteAllBars(); |
| 208 | } |
| 209 | |
| 210 | // ---------------------------------------------------------------------------- |
| 211 | // overridden wxWindow methods |
| 212 | // ---------------------------------------------------------------------------- |
| 213 | |
| 214 | void wxFrame::DoGetClientSize( int *width, int *height ) const |
| 215 | { |
| 216 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
| 217 | |
| 218 | wxTopLevelWindow::DoGetClientSize( width, height ); |
| 219 | |
| 220 | if (height) |
| 221 | { |
| 222 | #if wxUSE_MENUS_NATIVE |
| 223 | // menu bar |
| 224 | if (m_frameMenuBar && !(m_fsIsShowing && (m_fsSaveFlag & wxFULLSCREEN_NOMENUBAR != 0))) |
| 225 | { |
| 226 | if (!m_menuBarDetached) |
| 227 | (*height) -= m_menuBarHeight; |
| 228 | else |
| 229 | (*height) -= wxPLACE_HOLDER; |
| 230 | } |
| 231 | #endif // wxUSE_MENUS_NATIVE |
| 232 | |
| 233 | #if wxUSE_STATUSBAR |
| 234 | // status bar |
| 235 | if (m_frameStatusBar && m_frameStatusBar->IsShown() && |
| 236 | !(m_fsIsShowing && (m_fsSaveFlag & wxFULLSCREEN_NOSTATUSBAR != 0))) |
| 237 | (*height) -= wxSTATUS_HEIGHT; |
| 238 | #endif // wxUSE_STATUSBAR |
| 239 | } |
| 240 | |
| 241 | #if wxUSE_TOOLBAR |
| 242 | // tool bar |
| 243 | if (m_frameToolBar && m_frameToolBar->IsShown()) |
| 244 | { |
| 245 | if (m_toolBarDetached) |
| 246 | { |
| 247 | if (height != NULL) |
| 248 | *height -= wxPLACE_HOLDER; |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | int x, y; |
| 253 | m_frameToolBar->GetSize( &x, &y ); |
| 254 | if ( m_frameToolBar->IsVertical() ) |
| 255 | { |
| 256 | if (width != NULL) |
| 257 | *width -= x; |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | if (height != NULL) |
| 262 | *height -= y; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | #endif // wxUSE_TOOLBAR |
| 267 | |
| 268 | if (width != NULL && *width < 0) |
| 269 | *width = 0; |
| 270 | if (height != NULL && *height < 0) |
| 271 | *height = 0; |
| 272 | } |
| 273 | |
| 274 | void wxFrame::DoSetClientSize( int width, int height ) |
| 275 | { |
| 276 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
| 277 | |
| 278 | #if wxUSE_MENUS_NATIVE |
| 279 | // menu bar |
| 280 | if (m_frameMenuBar && !(m_fsIsShowing && (m_fsSaveFlag & wxFULLSCREEN_NOMENUBAR != 0))) |
| 281 | { |
| 282 | if (!m_menuBarDetached) |
| 283 | height += m_menuBarHeight; |
| 284 | else |
| 285 | height += wxPLACE_HOLDER; |
| 286 | } |
| 287 | #endif // wxUSE_MENUS_NATIVE |
| 288 | |
| 289 | #if wxUSE_STATUSBAR |
| 290 | // status bar |
| 291 | if (m_frameStatusBar && m_frameStatusBar->IsShown() && |
| 292 | !(m_fsIsShowing && (m_fsSaveFlag & wxFULLSCREEN_NOSTATUSBAR != 0))) |
| 293 | height += wxSTATUS_HEIGHT; |
| 294 | #endif |
| 295 | |
| 296 | #if wxUSE_TOOLBAR |
| 297 | // tool bar |
| 298 | if (m_frameToolBar && m_frameToolBar->IsShown()) |
| 299 | { |
| 300 | if (m_toolBarDetached) |
| 301 | { |
| 302 | height += wxPLACE_HOLDER; |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | int x, y; |
| 307 | m_frameToolBar->GetSize( &x, &y ); |
| 308 | if ( m_frameToolBar->IsVertical() ) |
| 309 | { |
| 310 | width += x; |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | height += y; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | #endif |
| 319 | |
| 320 | wxTopLevelWindow::DoSetClientSize( width, height ); |
| 321 | } |
| 322 | |
| 323 | void wxFrame::GtkOnSize() |
| 324 | { |
| 325 | // avoid recursions |
| 326 | if (m_resizing) return; |
| 327 | m_resizing = true; |
| 328 | |
| 329 | // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow |
| 330 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); |
| 331 | |
| 332 | // space occupied by m_frameToolBar and m_frameMenuBar |
| 333 | int client_area_x_offset = 0, |
| 334 | client_area_y_offset = 0; |
| 335 | |
| 336 | /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses |
| 337 | wxWindow::Create to create it's GTK equivalent. m_mainWidget is only |
| 338 | set in wxFrame::Create so it is used to check what kind of frame we |
| 339 | have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we |
| 340 | skip the part which handles m_frameMenuBar, m_frameToolBar and (most |
| 341 | importantly) m_mainWidget */ |
| 342 | |
| 343 | int minWidth = GetMinWidth(), |
| 344 | minHeight = GetMinHeight(), |
| 345 | maxWidth = GetMaxWidth(), |
| 346 | maxHeight = GetMaxHeight(); |
| 347 | |
| 348 | if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth; |
| 349 | if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight; |
| 350 | if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth; |
| 351 | if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight; |
| 352 | |
| 353 | if (m_mainWidget) |
| 354 | { |
| 355 | // TODO |
| 356 | // Rewrite this terrible code to using GtkVBox |
| 357 | |
| 358 | // m_mainWidget holds the menubar, the toolbar and the client |
| 359 | // area, which is represented by m_wxwindow. |
| 360 | |
| 361 | #if wxUSE_MENUS_NATIVE |
| 362 | if (m_frameMenuBar && !(m_fsIsShowing && (m_fsSaveFlag & wxFULLSCREEN_NOMENUBAR != 0))) |
| 363 | { |
| 364 | if (!GTK_WIDGET_VISIBLE(m_frameMenuBar->m_widget)) |
| 365 | gtk_widget_show( m_frameMenuBar->m_widget ); |
| 366 | int xx = m_miniEdge; |
| 367 | int yy = m_miniEdge + m_miniTitle; |
| 368 | int ww = m_width - 2*m_miniEdge; |
| 369 | if (ww < 0) |
| 370 | ww = 0; |
| 371 | int hh = m_menuBarHeight; |
| 372 | if (m_menuBarDetached) hh = wxPLACE_HOLDER; |
| 373 | m_frameMenuBar->m_x = xx; |
| 374 | m_frameMenuBar->m_y = yy; |
| 375 | m_frameMenuBar->m_width = ww; |
| 376 | m_frameMenuBar->m_height = hh; |
| 377 | gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), |
| 378 | m_frameMenuBar->m_widget, |
| 379 | xx, yy, ww, hh ); |
| 380 | client_area_y_offset += hh; |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | if (m_frameMenuBar) |
| 385 | { |
| 386 | if (GTK_WIDGET_VISIBLE(m_frameMenuBar->m_widget)) |
| 387 | gtk_widget_hide( m_frameMenuBar->m_widget ); |
| 388 | } |
| 389 | } |
| 390 | #endif // wxUSE_MENUS_NATIVE |
| 391 | |
| 392 | #if wxUSE_TOOLBAR |
| 393 | if ((m_frameToolBar) && m_frameToolBar->IsShown() && |
| 394 | (m_frameToolBar->m_widget->parent == m_mainWidget)) |
| 395 | { |
| 396 | int xx = m_miniEdge; |
| 397 | int yy = m_miniEdge + m_miniTitle; |
| 398 | #if wxUSE_MENUS_NATIVE |
| 399 | if (m_frameMenuBar) |
| 400 | { |
| 401 | if (!m_menuBarDetached) |
| 402 | yy += m_menuBarHeight; |
| 403 | else |
| 404 | yy += wxPLACE_HOLDER; |
| 405 | } |
| 406 | #endif // wxUSE_MENUS_NATIVE |
| 407 | |
| 408 | m_frameToolBar->m_x = xx; |
| 409 | m_frameToolBar->m_y = yy; |
| 410 | |
| 411 | // don't change the toolbar's reported height/width |
| 412 | int ww, hh; |
| 413 | if ( m_frameToolBar->GetWindowStyle() & wxTB_VERTICAL ) |
| 414 | { |
| 415 | ww = m_toolBarDetached ? wxPLACE_HOLDER |
| 416 | : m_frameToolBar->m_width; |
| 417 | hh = m_height - 2*m_miniEdge; |
| 418 | |
| 419 | client_area_x_offset += ww; |
| 420 | } |
| 421 | else if( m_frameToolBar->HasFlag(wxTB_RIGHT) ) |
| 422 | { |
| 423 | yy += 2; |
| 424 | ww = m_toolBarDetached ? wxPLACE_HOLDER |
| 425 | : m_frameToolBar->m_width; |
| 426 | xx = GetClientSize().x - 1; |
| 427 | hh = m_height - 2*m_miniEdge; |
| 428 | if( hh < 0 ) |
| 429 | hh = 0; |
| 430 | |
| 431 | } |
| 432 | else if( m_frameToolBar->GetWindowStyle() & wxTB_BOTTOM ) |
| 433 | { |
| 434 | xx = m_miniEdge; |
| 435 | yy = GetClientSize().y; |
| 436 | #if wxUSE_MENUS_NATIVE |
| 437 | yy += m_menuBarHeight; |
| 438 | #endif // wxUSE_MENU_NATIVE |
| 439 | m_frameToolBar->m_x = xx; |
| 440 | m_frameToolBar->m_y = yy; |
| 441 | ww = m_width - 2*m_miniEdge; |
| 442 | hh = m_toolBarDetached ? wxPLACE_HOLDER |
| 443 | : m_frameToolBar->m_height; |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | ww = m_width - 2*m_miniEdge; |
| 448 | hh = m_toolBarDetached ? wxPLACE_HOLDER |
| 449 | : m_frameToolBar->m_height; |
| 450 | |
| 451 | client_area_y_offset += hh; |
| 452 | } |
| 453 | |
| 454 | if (ww < 0) |
| 455 | ww = 0; |
| 456 | if (hh < 0) |
| 457 | hh = 0; |
| 458 | gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), |
| 459 | m_frameToolBar->m_widget, |
| 460 | xx, yy, ww, hh ); |
| 461 | } |
| 462 | #endif // wxUSE_TOOLBAR |
| 463 | |
| 464 | int client_x = client_area_x_offset + m_miniEdge; |
| 465 | int client_y = client_area_y_offset + m_miniEdge + m_miniTitle; |
| 466 | int client_w = m_width - client_area_x_offset - 2*m_miniEdge; |
| 467 | int client_h = m_height - client_area_y_offset- 2*m_miniEdge - m_miniTitle; |
| 468 | if (client_w < 0) |
| 469 | client_w = 0; |
| 470 | if (client_h < 0) |
| 471 | client_h = 0; |
| 472 | gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), |
| 473 | m_wxwindow, |
| 474 | client_x, client_y, client_w, client_h ); |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | // If there is no m_mainWidget between m_widget and m_wxwindow there |
| 479 | // is no need to set the size or position of m_wxwindow. |
| 480 | } |
| 481 | |
| 482 | #if wxUSE_STATUSBAR |
| 483 | if (m_frameStatusBar && m_frameStatusBar->IsShown() && |
| 484 | !(m_fsIsShowing && (m_fsSaveFlag & wxFULLSCREEN_NOSTATUSBAR != 0))) |
| 485 | { |
| 486 | if (!GTK_WIDGET_VISIBLE(m_frameStatusBar->m_widget)) |
| 487 | gtk_widget_show( m_frameStatusBar->m_widget ); |
| 488 | |
| 489 | int xx = 0 + m_miniEdge; |
| 490 | int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge - client_area_y_offset; |
| 491 | int ww = m_width - 2*m_miniEdge; |
| 492 | if (ww < 0) |
| 493 | ww = 0; |
| 494 | int hh = wxSTATUS_HEIGHT; |
| 495 | m_frameStatusBar->m_x = xx; |
| 496 | m_frameStatusBar->m_y = yy; |
| 497 | m_frameStatusBar->m_width = ww; |
| 498 | m_frameStatusBar->m_height = hh; |
| 499 | gtk_pizza_set_size( GTK_PIZZA(m_wxwindow), |
| 500 | m_frameStatusBar->m_widget, |
| 501 | xx, yy, ww, hh ); |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | if (m_frameStatusBar) |
| 506 | { |
| 507 | if (GTK_WIDGET_VISIBLE(m_frameStatusBar->m_widget)) |
| 508 | gtk_widget_hide( m_frameStatusBar->m_widget ); |
| 509 | } |
| 510 | } |
| 511 | #endif // wxUSE_STATUSBAR |
| 512 | |
| 513 | m_sizeSet = true; |
| 514 | |
| 515 | // send size event to frame |
| 516 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
| 517 | event.SetEventObject( this ); |
| 518 | GetEventHandler()->ProcessEvent( event ); |
| 519 | |
| 520 | #if wxUSE_STATUSBAR |
| 521 | // send size event to status bar |
| 522 | if (m_frameStatusBar) |
| 523 | { |
| 524 | wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() ); |
| 525 | event2.SetEventObject( m_frameStatusBar ); |
| 526 | m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 ); |
| 527 | } |
| 528 | #endif // wxUSE_STATUSBAR |
| 529 | |
| 530 | m_resizing = false; |
| 531 | } |
| 532 | |
| 533 | void wxFrame::OnInternalIdle() |
| 534 | { |
| 535 | wxFrameBase::OnInternalIdle(); |
| 536 | |
| 537 | #if wxUSE_MENUS_NATIVE |
| 538 | if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle(); |
| 539 | #endif // wxUSE_MENUS_NATIVE |
| 540 | #if wxUSE_TOOLBAR |
| 541 | if (m_frameToolBar) m_frameToolBar->OnInternalIdle(); |
| 542 | #endif |
| 543 | #if wxUSE_STATUSBAR |
| 544 | if (m_frameStatusBar) |
| 545 | { |
| 546 | m_frameStatusBar->OnInternalIdle(); |
| 547 | |
| 548 | // There may be controls in the status bar that |
| 549 | // need to be updated |
| 550 | for ( wxWindowList::compatibility_iterator node = m_frameStatusBar->GetChildren().GetFirst(); |
| 551 | node; |
| 552 | node = node->GetNext() ) |
| 553 | { |
| 554 | wxWindow *child = node->GetData(); |
| 555 | child->OnInternalIdle(); |
| 556 | } |
| 557 | } |
| 558 | #endif |
| 559 | } |
| 560 | |
| 561 | // ---------------------------------------------------------------------------- |
| 562 | // menu/tool/status bar stuff |
| 563 | // ---------------------------------------------------------------------------- |
| 564 | |
| 565 | #if wxUSE_MENUS_NATIVE |
| 566 | |
| 567 | void wxFrame::DetachMenuBar() |
| 568 | { |
| 569 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
| 570 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); |
| 571 | |
| 572 | if ( m_frameMenuBar ) |
| 573 | { |
| 574 | m_frameMenuBar->UnsetInvokingWindow( this ); |
| 575 | |
| 576 | if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE) |
| 577 | { |
| 578 | g_signal_handlers_disconnect_by_func (m_frameMenuBar->m_widget, |
| 579 | (gpointer) gtk_menu_attached_callback, |
| 580 | this); |
| 581 | |
| 582 | g_signal_handlers_disconnect_by_func (m_frameMenuBar->m_widget, |
| 583 | (gpointer) gtk_menu_detached_callback, |
| 584 | this); |
| 585 | } |
| 586 | |
| 587 | gtk_widget_ref( m_frameMenuBar->m_widget ); |
| 588 | |
| 589 | gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget ); |
| 590 | } |
| 591 | |
| 592 | wxFrameBase::DetachMenuBar(); |
| 593 | } |
| 594 | |
| 595 | void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) |
| 596 | { |
| 597 | wxFrameBase::AttachMenuBar(menuBar); |
| 598 | |
| 599 | if (m_frameMenuBar) |
| 600 | { |
| 601 | m_frameMenuBar->SetInvokingWindow( this ); |
| 602 | |
| 603 | m_frameMenuBar->SetParent(this); |
| 604 | gtk_pizza_put( GTK_PIZZA(m_mainWidget), |
| 605 | m_frameMenuBar->m_widget, |
| 606 | m_frameMenuBar->m_x, |
| 607 | m_frameMenuBar->m_y, |
| 608 | m_frameMenuBar->m_width, |
| 609 | m_frameMenuBar->m_height ); |
| 610 | |
| 611 | if (menuBar->GetWindowStyle() & wxMB_DOCKABLE) |
| 612 | { |
| 613 | g_signal_connect (menuBar->m_widget, "child_attached", |
| 614 | G_CALLBACK (gtk_menu_attached_callback), |
| 615 | this); |
| 616 | g_signal_connect (menuBar->m_widget, "child_detached", |
| 617 | G_CALLBACK (gtk_menu_detached_callback), |
| 618 | this); |
| 619 | } |
| 620 | |
| 621 | gtk_widget_show( m_frameMenuBar->m_widget ); |
| 622 | |
| 623 | UpdateMenuBarSize(); |
| 624 | } |
| 625 | else |
| 626 | { |
| 627 | m_menuBarHeight = 2; |
| 628 | GtkUpdateSize(); // resize window in OnInternalIdle |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | void wxFrame::UpdateMenuBarSize() |
| 633 | { |
| 634 | GtkRequisition req; |
| 635 | |
| 636 | req.width = 2; |
| 637 | req.height = 2; |
| 638 | |
| 639 | // this is called after Remove with a NULL m_frameMenuBar |
| 640 | if ( m_frameMenuBar ) |
| 641 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request ) |
| 642 | (m_frameMenuBar->m_widget, &req ); |
| 643 | |
| 644 | m_menuBarHeight = req.height; |
| 645 | |
| 646 | // resize window in OnInternalIdle |
| 647 | |
| 648 | GtkUpdateSize(); |
| 649 | } |
| 650 | |
| 651 | #endif // wxUSE_MENUS_NATIVE |
| 652 | |
| 653 | #if wxUSE_TOOLBAR |
| 654 | |
| 655 | wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name ) |
| 656 | { |
| 657 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
| 658 | |
| 659 | m_insertInClientArea = false; |
| 660 | |
| 661 | m_frameToolBar = wxFrameBase::CreateToolBar( style, id, name ); |
| 662 | |
| 663 | m_insertInClientArea = true; |
| 664 | |
| 665 | GtkUpdateSize(); |
| 666 | |
| 667 | return m_frameToolBar; |
| 668 | } |
| 669 | |
| 670 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
| 671 | { |
| 672 | bool hadTbar = m_frameToolBar != NULL; |
| 673 | |
| 674 | wxFrameBase::SetToolBar(toolbar); |
| 675 | |
| 676 | if ( m_frameToolBar ) |
| 677 | { |
| 678 | // insert into toolbar area if not already there |
| 679 | if ((m_frameToolBar->m_widget->parent) && |
| 680 | (m_frameToolBar->m_widget->parent != m_mainWidget)) |
| 681 | { |
| 682 | GetChildren().DeleteObject( m_frameToolBar ); |
| 683 | |
| 684 | gtk_widget_reparent( m_frameToolBar->m_widget, m_mainWidget ); |
| 685 | GtkUpdateSize(); |
| 686 | } |
| 687 | } |
| 688 | else // toolbar unset |
| 689 | { |
| 690 | // still need to update size if it had been there before |
| 691 | if ( hadTbar ) |
| 692 | { |
| 693 | GtkUpdateSize(); |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | #endif // wxUSE_TOOLBAR |
| 699 | |
| 700 | #if wxUSE_STATUSBAR |
| 701 | |
| 702 | wxStatusBar* wxFrame::CreateStatusBar(int number, |
| 703 | long style, |
| 704 | wxWindowID id, |
| 705 | const wxString& name) |
| 706 | { |
| 707 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
| 708 | |
| 709 | // because it will change when toolbar is added |
| 710 | GtkUpdateSize(); |
| 711 | |
| 712 | return wxFrameBase::CreateStatusBar( number, style, id, name ); |
| 713 | } |
| 714 | |
| 715 | void wxFrame::SetStatusBar(wxStatusBar *statbar) |
| 716 | { |
| 717 | bool hadStatBar = m_frameStatusBar != NULL; |
| 718 | |
| 719 | wxFrameBase::SetStatusBar(statbar); |
| 720 | |
| 721 | if (hadStatBar && !m_frameStatusBar) |
| 722 | GtkUpdateSize(); |
| 723 | } |
| 724 | |
| 725 | void wxFrame::PositionStatusBar() |
| 726 | { |
| 727 | if ( !m_frameStatusBar ) |
| 728 | return; |
| 729 | |
| 730 | GtkUpdateSize(); |
| 731 | } |
| 732 | #endif // wxUSE_STATUSBAR |