| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: msw/frame.cpp |
| 3 | // Purpose: wxFrame |
| 4 | // Author: Julian Smart |
| 5 | // Modified by: |
| 6 | // Created: 01/02/97 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Julian Smart and Markus Holzem |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // ============================================================================ |
| 13 | // declarations |
| 14 | // ============================================================================ |
| 15 | |
| 16 | // ---------------------------------------------------------------------------- |
| 17 | // headers |
| 18 | // ---------------------------------------------------------------------------- |
| 19 | |
| 20 | #ifdef __GNUG__ |
| 21 | #pragma implementation "frame.h" |
| 22 | #endif |
| 23 | |
| 24 | // For compilers that support precompilation, includes "wx.h". |
| 25 | #include "wx/wxprec.h" |
| 26 | |
| 27 | #ifdef __BORLANDC__ |
| 28 | #pragma hdrstop |
| 29 | #endif |
| 30 | |
| 31 | #ifndef WX_PRECOMP |
| 32 | #include "wx/frame.h" |
| 33 | #include "wx/app.h" |
| 34 | #include "wx/menu.h" |
| 35 | #include "wx/utils.h" |
| 36 | #include "wx/dialog.h" |
| 37 | #include "wx/settings.h" |
| 38 | #include "wx/dcclient.h" |
| 39 | #include "wx/mdi.h" |
| 40 | #include "wx/panel.h" |
| 41 | #endif // WX_PRECOMP |
| 42 | |
| 43 | #include "wx/msw/private.h" |
| 44 | |
| 45 | #if wxUSE_STATUSBAR |
| 46 | #include "wx/statusbr.h" |
| 47 | #include "wx/generic/statusbr.h" |
| 48 | #endif // wxUSE_STATUSBAR |
| 49 | |
| 50 | #if wxUSE_TOOLBAR |
| 51 | #include "wx/toolbar.h" |
| 52 | #endif // wxUSE_TOOLBAR |
| 53 | |
| 54 | #include "wx/menuitem.h" |
| 55 | #include "wx/log.h" |
| 56 | |
| 57 | #ifdef __WXUNIVERSAL__ |
| 58 | #include "wx/univ/theme.h" |
| 59 | #include "wx/univ/colschem.h" |
| 60 | #endif // __WXUNIVERSAL__ |
| 61 | |
| 62 | // ---------------------------------------------------------------------------- |
| 63 | // globals |
| 64 | // ---------------------------------------------------------------------------- |
| 65 | |
| 66 | extern const wxChar *wxFrameClassName; |
| 67 | |
| 68 | #if wxUSE_MENUS_NATIVE |
| 69 | extern wxMenu *wxCurrentPopupMenu; |
| 70 | #endif // wxUSE_MENUS_NATIVE |
| 71 | |
| 72 | // ---------------------------------------------------------------------------- |
| 73 | // event tables |
| 74 | // ---------------------------------------------------------------------------- |
| 75 | |
| 76 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
| 77 | EVT_ACTIVATE(wxFrame::OnActivate) |
| 78 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) |
| 79 | END_EVENT_TABLE() |
| 80 | |
| 81 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) |
| 82 | |
| 83 | // ============================================================================ |
| 84 | // implementation |
| 85 | // ============================================================================ |
| 86 | |
| 87 | // ---------------------------------------------------------------------------- |
| 88 | // static class members |
| 89 | // ---------------------------------------------------------------------------- |
| 90 | |
| 91 | #if wxUSE_STATUSBAR |
| 92 | #if wxUSE_NATIVE_STATUSBAR |
| 93 | bool wxFrame::m_useNativeStatusBar = TRUE; |
| 94 | #else |
| 95 | bool wxFrame::m_useNativeStatusBar = FALSE; |
| 96 | #endif |
| 97 | #endif // wxUSE_NATIVE_STATUSBAR |
| 98 | |
| 99 | // ---------------------------------------------------------------------------- |
| 100 | // creation/destruction |
| 101 | // ---------------------------------------------------------------------------- |
| 102 | |
| 103 | void wxFrame::Init() |
| 104 | { |
| 105 | #if wxUSE_TOOLTIPS |
| 106 | m_hwndToolTip = 0; |
| 107 | #endif |
| 108 | |
| 109 | // Data to save/restore when calling ShowFullScreen |
| 110 | m_fsStatusBarFields = 0; |
| 111 | m_fsStatusBarHeight = 0; |
| 112 | m_fsToolBarHeight = 0; |
| 113 | // m_fsMenu = 0; |
| 114 | |
| 115 | m_wasMinimized = FALSE; |
| 116 | |
| 117 | m_winLastFocused = (wxWindow *)NULL; |
| 118 | } |
| 119 | |
| 120 | bool wxFrame::Create(wxWindow *parent, |
| 121 | wxWindowID id, |
| 122 | const wxString& title, |
| 123 | const wxPoint& pos, |
| 124 | const wxSize& size, |
| 125 | long style, |
| 126 | const wxString& name) |
| 127 | { |
| 128 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
| 129 | return FALSE; |
| 130 | |
| 131 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
| 132 | |
| 133 | wxModelessWindows.Append(this); |
| 134 | |
| 135 | return TRUE; |
| 136 | } |
| 137 | |
| 138 | wxFrame::~wxFrame() |
| 139 | { |
| 140 | m_isBeingDeleted = TRUE; |
| 141 | |
| 142 | DeleteAllBars(); |
| 143 | } |
| 144 | |
| 145 | // ---------------------------------------------------------------------------- |
| 146 | // wxFrame client size calculations |
| 147 | // ---------------------------------------------------------------------------- |
| 148 | |
| 149 | void wxFrame::DoSetClientSize(int width, int height) |
| 150 | { |
| 151 | // leave enough space for the status bar if we have (and show) it |
| 152 | #if wxUSE_STATUSBAR |
| 153 | wxStatusBar *statbar = GetStatusBar(); |
| 154 | if ( statbar && statbar->IsShown() ) |
| 155 | { |
| 156 | height += statbar->GetSize().y; |
| 157 | } |
| 158 | #endif // wxUSE_STATUSBAR |
| 159 | |
| 160 | wxTopLevelWindow::DoSetClientSize(width, height); |
| 161 | } |
| 162 | |
| 163 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
| 164 | void wxFrame::DoGetClientSize(int *x, int *y) const |
| 165 | { |
| 166 | wxTopLevelWindow::DoGetClientSize(x, y); |
| 167 | |
| 168 | #if wxUSE_STATUSBAR |
| 169 | // adjust client area height to take the status bar into account |
| 170 | if ( y ) |
| 171 | { |
| 172 | wxStatusBar *statbar = GetStatusBar(); |
| 173 | if ( statbar && statbar->IsShown() ) |
| 174 | { |
| 175 | *y -= statbar->GetClientSize().y; |
| 176 | } |
| 177 | } |
| 178 | #endif // wxUSE_STATUSBAR |
| 179 | } |
| 180 | |
| 181 | // ---------------------------------------------------------------------------- |
| 182 | // wxFrame: various geometry-related functions |
| 183 | // ---------------------------------------------------------------------------- |
| 184 | |
| 185 | void wxFrame::Raise() |
| 186 | { |
| 187 | #ifdef __WIN16__ |
| 188 | // no SetForegroundWindow() in Win16 |
| 189 | wxFrameBase::Raise(); |
| 190 | #else // Win32 |
| 191 | ::SetForegroundWindow(GetHwnd()); |
| 192 | #endif // Win16/32 |
| 193 | } |
| 194 | |
| 195 | // generate an artificial resize event |
| 196 | void wxFrame::SendSizeEvent() |
| 197 | { |
| 198 | if ( !m_iconized ) |
| 199 | { |
| 200 | RECT r = wxGetWindowRect(GetHwnd()); |
| 201 | |
| 202 | (void)::PostMessage(GetHwnd(), WM_SIZE, |
| 203 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, |
| 204 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | #if wxUSE_STATUSBAR |
| 209 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
| 210 | long style, |
| 211 | wxWindowID id, |
| 212 | const wxString& name) |
| 213 | { |
| 214 | wxStatusBar *statusBar = NULL; |
| 215 | |
| 216 | #if wxUSE_NATIVE_STATUSBAR |
| 217 | if ( !UsesNativeStatusBar() ) |
| 218 | { |
| 219 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
| 220 | } |
| 221 | else |
| 222 | #endif |
| 223 | { |
| 224 | statusBar = new wxStatusBar(this, id, style, name); |
| 225 | } |
| 226 | |
| 227 | statusBar->SetFieldsCount(number); |
| 228 | |
| 229 | return statusBar; |
| 230 | } |
| 231 | |
| 232 | void wxFrame::PositionStatusBar() |
| 233 | { |
| 234 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) |
| 235 | return; |
| 236 | |
| 237 | int w, h; |
| 238 | GetClientSize(&w, &h); |
| 239 | int sw, sh; |
| 240 | m_frameStatusBar->GetSize(&sw, &sh); |
| 241 | |
| 242 | // Since we wish the status bar to be directly under the client area, |
| 243 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. |
| 244 | m_frameStatusBar->SetSize(0, h, w, sh); |
| 245 | } |
| 246 | #endif // wxUSE_STATUSBAR |
| 247 | |
| 248 | #if wxUSE_MENUS_NATIVE |
| 249 | |
| 250 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) |
| 251 | { |
| 252 | wxFrameBase::AttachMenuBar(menubar); |
| 253 | |
| 254 | if ( !menubar ) |
| 255 | { |
| 256 | // actually remove the menu from the frame |
| 257 | m_hMenu = (WXHMENU)0; |
| 258 | InternalSetMenuBar(); |
| 259 | } |
| 260 | else // set new non NULL menu bar |
| 261 | { |
| 262 | // Can set a menubar several times. |
| 263 | if ( menubar->GetHMenu() ) |
| 264 | { |
| 265 | m_hMenu = menubar->GetHMenu(); |
| 266 | } |
| 267 | else // no HMENU yet |
| 268 | { |
| 269 | m_hMenu = menubar->Create(); |
| 270 | |
| 271 | if ( !m_hMenu ) |
| 272 | { |
| 273 | wxFAIL_MSG( _T("failed to create menu bar") ); |
| 274 | return; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | InternalSetMenuBar(); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | void wxFrame::InternalSetMenuBar() |
| 283 | { |
| 284 | #ifndef __WXMICROWIN__ |
| 285 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
| 286 | { |
| 287 | wxLogLastError(wxT("SetMenu")); |
| 288 | } |
| 289 | #endif |
| 290 | } |
| 291 | |
| 292 | #endif // wxUSE_MENUS_NATIVE |
| 293 | |
| 294 | // Responds to colour changes, and passes event on to children. |
| 295 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
| 296 | { |
| 297 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
| 298 | Refresh(); |
| 299 | |
| 300 | #if wxUSE_STATUSBAR |
| 301 | if ( m_frameStatusBar ) |
| 302 | { |
| 303 | wxSysColourChangedEvent event2; |
| 304 | event2.SetEventObject( m_frameStatusBar ); |
| 305 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
| 306 | } |
| 307 | #endif // wxUSE_STATUSBAR |
| 308 | |
| 309 | // Propagate the event to the non-top-level children |
| 310 | wxWindow::OnSysColourChanged(event); |
| 311 | } |
| 312 | |
| 313 | // Pass TRUE to show full screen, FALSE to restore. |
| 314 | bool wxFrame::ShowFullScreen(bool show, long style) |
| 315 | { |
| 316 | if ( IsFullScreen() == show ) |
| 317 | return FALSE; |
| 318 | |
| 319 | if (show) |
| 320 | { |
| 321 | #if wxUSE_TOOLBAR |
| 322 | wxToolBar *theToolBar = GetToolBar(); |
| 323 | if (theToolBar) |
| 324 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); |
| 325 | |
| 326 | // zap the toolbar, menubar, and statusbar |
| 327 | |
| 328 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) |
| 329 | { |
| 330 | theToolBar->SetSize(-1,0); |
| 331 | theToolBar->Show(FALSE); |
| 332 | } |
| 333 | #endif // wxUSE_TOOLBAR |
| 334 | |
| 335 | #ifndef __WXMICROWIN__ |
| 336 | if (style & wxFULLSCREEN_NOMENUBAR) |
| 337 | SetMenu((HWND)GetHWND(), (HMENU) NULL); |
| 338 | #endif |
| 339 | |
| 340 | #if wxUSE_STATUSBAR |
| 341 | wxStatusBar *theStatusBar = GetStatusBar(); |
| 342 | if (theStatusBar) |
| 343 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); |
| 344 | |
| 345 | // Save the number of fields in the statusbar |
| 346 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) |
| 347 | { |
| 348 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); |
| 349 | //SetStatusBar((wxStatusBar*) NULL); |
| 350 | //delete theStatusBar; |
| 351 | theStatusBar->Show(FALSE); |
| 352 | } |
| 353 | else |
| 354 | m_fsStatusBarFields = 0; |
| 355 | #endif // wxUSE_STATUSBAR |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | #if wxUSE_TOOLBAR |
| 360 | wxToolBar *theToolBar = GetToolBar(); |
| 361 | |
| 362 | // restore the toolbar, menubar, and statusbar |
| 363 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) |
| 364 | { |
| 365 | theToolBar->SetSize(-1, m_fsToolBarHeight); |
| 366 | theToolBar->Show(TRUE); |
| 367 | } |
| 368 | #endif // wxUSE_TOOLBAR |
| 369 | |
| 370 | #if wxUSE_STATUSBAR |
| 371 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) |
| 372 | { |
| 373 | //CreateStatusBar(m_fsStatusBarFields); |
| 374 | if (GetStatusBar()) |
| 375 | { |
| 376 | GetStatusBar()->Show(TRUE); |
| 377 | PositionStatusBar(); |
| 378 | } |
| 379 | } |
| 380 | #endif // wxUSE_STATUSBAR |
| 381 | |
| 382 | #ifndef __WXMICROWIN__ |
| 383 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) |
| 384 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); |
| 385 | #endif |
| 386 | } |
| 387 | |
| 388 | return wxFrameBase::ShowFullScreen(show, style); |
| 389 | } |
| 390 | |
| 391 | // Default activation behaviour - set the focus for the first child |
| 392 | // subwindow found. |
| 393 | void wxFrame::OnActivate(wxActivateEvent& event) |
| 394 | { |
| 395 | if ( event.GetActive() ) |
| 396 | { |
| 397 | // restore focus to the child which was last focused |
| 398 | wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); |
| 399 | |
| 400 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() |
| 401 | : NULL; |
| 402 | if ( !parent ) |
| 403 | { |
| 404 | parent = this; |
| 405 | } |
| 406 | |
| 407 | wxSetFocusToChild(parent, &m_winLastFocused); |
| 408 | } |
| 409 | else // deactivating |
| 410 | { |
| 411 | // remember the last focused child if it is our child |
| 412 | m_winLastFocused = FindFocus(); |
| 413 | |
| 414 | // so we NULL it out if it's a child from some other frame |
| 415 | wxWindow *win = m_winLastFocused; |
| 416 | while ( win ) |
| 417 | { |
| 418 | if ( win->IsTopLevel() ) |
| 419 | { |
| 420 | if ( win != this ) |
| 421 | { |
| 422 | m_winLastFocused = NULL; |
| 423 | } |
| 424 | |
| 425 | break; |
| 426 | } |
| 427 | |
| 428 | win = win->GetParent(); |
| 429 | } |
| 430 | |
| 431 | wxLogTrace(_T("focus"), |
| 432 | _T("wxFrame %08x deactivated, last focused: %08x."), |
| 433 | m_hWnd, |
| 434 | m_winLastFocused ? GetHwndOf(m_winLastFocused) |
| 435 | : NULL); |
| 436 | |
| 437 | event.Skip(); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | // ---------------------------------------------------------------------------- |
| 442 | // tool/status bar stuff |
| 443 | // ---------------------------------------------------------------------------- |
| 444 | |
| 445 | #if wxUSE_TOOLBAR |
| 446 | |
| 447 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
| 448 | { |
| 449 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
| 450 | { |
| 451 | PositionToolBar(); |
| 452 | } |
| 453 | |
| 454 | return m_frameToolBar; |
| 455 | } |
| 456 | |
| 457 | void wxFrame::PositionToolBar() |
| 458 | { |
| 459 | wxToolBar *toolbar = GetToolBar(); |
| 460 | if ( toolbar && toolbar->IsShown() ) |
| 461 | { |
| 462 | // don't call our (or even wxTopLevelWindow) version because we want |
| 463 | // the real (full) client area size, not excluding the tool/status bar |
| 464 | int width, height; |
| 465 | wxWindow::DoGetClientSize(&width, &height); |
| 466 | |
| 467 | #if wxUSE_STATUSBAR |
| 468 | wxStatusBar *statbar = GetStatusBar(); |
| 469 | if ( statbar && statbar->IsShown() ) |
| 470 | { |
| 471 | height -= statbar->GetClientSize().y; |
| 472 | } |
| 473 | #endif // wxUSE_STATUSBAR |
| 474 | |
| 475 | int tw, th; |
| 476 | toolbar->GetSize(&tw, &th); |
| 477 | |
| 478 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
| 479 | { |
| 480 | th = height; |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | tw = width; |
| 485 | } |
| 486 | |
| 487 | // use the 'real' MSW position here, don't offset relativly to the |
| 488 | // client area origin |
| 489 | toolbar->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | #endif // wxUSE_TOOLBAR |
| 494 | |
| 495 | // ---------------------------------------------------------------------------- |
| 496 | // frame state (iconized/maximized/...) |
| 497 | // ---------------------------------------------------------------------------- |
| 498 | |
| 499 | // propagate our state change to all child frames: this allows us to emulate X |
| 500 | // Windows behaviour where child frames float independently of the parent one |
| 501 | // on the desktop, but are iconized/restored with it |
| 502 | void wxFrame::IconizeChildFrames(bool bIconize) |
| 503 | { |
| 504 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
| 505 | node; |
| 506 | node = node->GetNext() ) |
| 507 | { |
| 508 | wxWindow *win = node->GetData(); |
| 509 | |
| 510 | // iconizing the frames with this style under Win95 shell puts them at |
| 511 | // the bottom of the screen (as the MDI children) instead of making |
| 512 | // them appear in the taskbar because they are, by virtue of this |
| 513 | // style, not managed by the taskbar - instead leave Windows take care |
| 514 | // of them |
| 515 | #ifdef __WIN95__ |
| 516 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) |
| 517 | continue; |
| 518 | #endif // Win95 |
| 519 | |
| 520 | // the child MDI frames are a special case and should not be touched by |
| 521 | // the parent frame - instead, they are managed by the user |
| 522 | wxFrame *frame = wxDynamicCast(win, wxFrame); |
| 523 | if ( frame |
| 524 | #if wxUSE_MDI_ARCHITECTURE |
| 525 | && !wxDynamicCast(frame, wxMDIChildFrame) |
| 526 | #endif // wxUSE_MDI_ARCHITECTURE |
| 527 | ) |
| 528 | { |
| 529 | // we don't want to restore the child frames which had been |
| 530 | // iconized even before we were iconized, so save the child frame |
| 531 | // status when iconizing the parent frame and check it when |
| 532 | // restoring it |
| 533 | if ( bIconize ) |
| 534 | { |
| 535 | // note that we shouldn't touch the hidden frames neither |
| 536 | // because iconizing/restoring them would show them as a side |
| 537 | // effect |
| 538 | frame->m_wasMinimized = frame->IsIconized() || !frame->IsShown(); |
| 539 | } |
| 540 | |
| 541 | // this test works for both iconizing and restoring |
| 542 | if ( !frame->m_wasMinimized ) |
| 543 | frame->Iconize(bIconize); |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | WXHICON wxFrame::GetDefaultIcon() const |
| 549 | { |
| 550 | return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON |
| 551 | : wxDEFAULT_FRAME_ICON); |
| 552 | } |
| 553 | |
| 554 | // =========================================================================== |
| 555 | // message processing |
| 556 | // =========================================================================== |
| 557 | |
| 558 | // --------------------------------------------------------------------------- |
| 559 | // preprocessing |
| 560 | // --------------------------------------------------------------------------- |
| 561 | |
| 562 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) |
| 563 | { |
| 564 | if ( wxWindow::MSWTranslateMessage(pMsg) ) |
| 565 | return TRUE; |
| 566 | |
| 567 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
| 568 | // try the menu bar accels |
| 569 | wxMenuBar *menuBar = GetMenuBar(); |
| 570 | if ( !menuBar ) |
| 571 | return FALSE; |
| 572 | |
| 573 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); |
| 574 | return acceleratorTable.Translate(this, pMsg); |
| 575 | #else |
| 576 | return FALSE; |
| 577 | #endif // wxUSE_MENUS && wxUSE_ACCEL |
| 578 | } |
| 579 | |
| 580 | // --------------------------------------------------------------------------- |
| 581 | // our private (non virtual) message handlers |
| 582 | // --------------------------------------------------------------------------- |
| 583 | |
| 584 | bool wxFrame::HandlePaint() |
| 585 | { |
| 586 | RECT rect; |
| 587 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) |
| 588 | { |
| 589 | #ifndef __WXMICROWIN__ |
| 590 | if ( m_iconized ) |
| 591 | { |
| 592 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
| 593 | : (HICON)GetDefaultIcon(); |
| 594 | |
| 595 | // Hold a pointer to the dc so long as the OnPaint() message |
| 596 | // is being processed |
| 597 | PAINTSTRUCT ps; |
| 598 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); |
| 599 | |
| 600 | // Erase background before painting or we get white background |
| 601 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); |
| 602 | |
| 603 | if ( hIcon ) |
| 604 | { |
| 605 | RECT rect; |
| 606 | ::GetClientRect(GetHwnd(), &rect); |
| 607 | |
| 608 | // FIXME: why hardcoded? |
| 609 | static const int icon_width = 32; |
| 610 | static const int icon_height = 32; |
| 611 | |
| 612 | int icon_x = (int)((rect.right - icon_width)/2); |
| 613 | int icon_y = (int)((rect.bottom - icon_height)/2); |
| 614 | |
| 615 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); |
| 616 | } |
| 617 | |
| 618 | ::EndPaint(GetHwnd(), &ps); |
| 619 | |
| 620 | return TRUE; |
| 621 | } |
| 622 | else |
| 623 | #endif |
| 624 | { |
| 625 | return wxWindow::HandlePaint(); |
| 626 | } |
| 627 | } |
| 628 | else |
| 629 | { |
| 630 | // nothing to paint - processed |
| 631 | return TRUE; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | bool wxFrame::HandleSize(int x, int y, WXUINT id) |
| 636 | { |
| 637 | bool processed = FALSE; |
| 638 | #ifndef __WXMICROWIN__ |
| 639 | |
| 640 | switch ( id ) |
| 641 | { |
| 642 | case SIZENORMAL: |
| 643 | // only do it it if we were iconized before, otherwise resizing the |
| 644 | // parent frame has a curious side effect of bringing it under it's |
| 645 | // children |
| 646 | if ( !m_iconized ) |
| 647 | break; |
| 648 | |
| 649 | // restore all child frames too |
| 650 | IconizeChildFrames(FALSE); |
| 651 | |
| 652 | (void)SendIconizeEvent(FALSE); |
| 653 | |
| 654 | // fall through |
| 655 | |
| 656 | case SIZEFULLSCREEN: |
| 657 | m_iconized = FALSE; |
| 658 | break; |
| 659 | |
| 660 | case SIZEICONIC: |
| 661 | // iconize all child frames too |
| 662 | IconizeChildFrames(TRUE); |
| 663 | |
| 664 | (void)SendIconizeEvent(); |
| 665 | |
| 666 | m_iconized = TRUE; |
| 667 | break; |
| 668 | } |
| 669 | #endif |
| 670 | |
| 671 | if ( !m_iconized ) |
| 672 | { |
| 673 | #if wxUSE_STATUSBAR |
| 674 | PositionStatusBar(); |
| 675 | #endif // wxUSE_STATUSBAR |
| 676 | |
| 677 | #if wxUSE_TOOLBAR |
| 678 | PositionToolBar(); |
| 679 | #endif // wxUSE_TOOLBAR |
| 680 | |
| 681 | wxSizeEvent event(wxSize(x, y), m_windowId); |
| 682 | event.SetEventObject( this ); |
| 683 | processed = GetEventHandler()->ProcessEvent(event); |
| 684 | } |
| 685 | |
| 686 | return processed; |
| 687 | } |
| 688 | |
| 689 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
| 690 | { |
| 691 | if ( control ) |
| 692 | { |
| 693 | // In case it's e.g. a toolbar. |
| 694 | wxWindow *win = wxFindWinFromHandle(control); |
| 695 | if ( win ) |
| 696 | return win->MSWCommand(cmd, id); |
| 697 | } |
| 698 | |
| 699 | // handle here commands from menus and accelerators |
| 700 | if ( cmd == 0 || cmd == 1 ) |
| 701 | { |
| 702 | #if wxUSE_MENUS_NATIVE |
| 703 | if ( wxCurrentPopupMenu ) |
| 704 | { |
| 705 | wxMenu *popupMenu = wxCurrentPopupMenu; |
| 706 | wxCurrentPopupMenu = NULL; |
| 707 | |
| 708 | return popupMenu->MSWCommand(cmd, id); |
| 709 | } |
| 710 | #endif // wxUSE_MENUS_NATIVE |
| 711 | |
| 712 | if ( ProcessCommand(id) ) |
| 713 | { |
| 714 | return TRUE; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | return FALSE; |
| 719 | } |
| 720 | |
| 721 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
| 722 | { |
| 723 | int item; |
| 724 | if ( flags == 0xFFFF && hMenu == 0 ) |
| 725 | { |
| 726 | // menu was removed from screen |
| 727 | item = -1; |
| 728 | } |
| 729 | #ifndef __WXMICROWIN__ |
| 730 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
| 731 | { |
| 732 | item = nItem; |
| 733 | } |
| 734 | #endif |
| 735 | else |
| 736 | { |
| 737 | #if wxUSE_STATUSBAR |
| 738 | // don't give hints for separators (doesn't make sense) nor for the |
| 739 | // items opening popup menus (they don't have them anyhow) but do clear |
| 740 | // the status line - otherwise, we would be left with the help message |
| 741 | // for the previous item which doesn't apply any more |
| 742 | wxStatusBar *statbar = GetStatusBar(); |
| 743 | if ( statbar ) |
| 744 | { |
| 745 | statbar->SetStatusText(wxEmptyString); |
| 746 | } |
| 747 | #endif // wxUSE_STATUSBAR |
| 748 | |
| 749 | return FALSE; |
| 750 | } |
| 751 | |
| 752 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); |
| 753 | event.SetEventObject( this ); |
| 754 | |
| 755 | return GetEventHandler()->ProcessEvent(event); |
| 756 | } |
| 757 | |
| 758 | // --------------------------------------------------------------------------- |
| 759 | // the window proc for wxFrame |
| 760 | // --------------------------------------------------------------------------- |
| 761 | |
| 762 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
| 763 | { |
| 764 | long rc = 0; |
| 765 | bool processed = FALSE; |
| 766 | |
| 767 | switch ( message ) |
| 768 | { |
| 769 | case WM_CLOSE: |
| 770 | // if we can't close, tell the system that we processed the |
| 771 | // message - otherwise it would close us |
| 772 | processed = !Close(); |
| 773 | break; |
| 774 | |
| 775 | case WM_COMMAND: |
| 776 | { |
| 777 | WORD id, cmd; |
| 778 | WXHWND hwnd; |
| 779 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, |
| 780 | &id, &hwnd, &cmd); |
| 781 | |
| 782 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); |
| 783 | } |
| 784 | break; |
| 785 | |
| 786 | #ifndef __WXMICROWIN__ |
| 787 | case WM_MENUSELECT: |
| 788 | { |
| 789 | WXWORD item, flags; |
| 790 | WXHMENU hmenu; |
| 791 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); |
| 792 | |
| 793 | processed = HandleMenuSelect(item, flags, hmenu); |
| 794 | } |
| 795 | break; |
| 796 | #endif |
| 797 | |
| 798 | case WM_PAINT: |
| 799 | processed = HandlePaint(); |
| 800 | break; |
| 801 | |
| 802 | #ifndef __WXMICROWIN__ |
| 803 | case WM_QUERYDRAGICON: |
| 804 | { |
| 805 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
| 806 | : (HICON)GetDefaultIcon(); |
| 807 | rc = (long)hIcon; |
| 808 | processed = rc != 0; |
| 809 | } |
| 810 | break; |
| 811 | #endif |
| 812 | |
| 813 | case WM_SIZE: |
| 814 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); |
| 815 | break; |
| 816 | } |
| 817 | |
| 818 | if ( !processed ) |
| 819 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); |
| 820 | |
| 821 | return rc; |
| 822 | } |
| 823 | |