| 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/setup.h" |
| 33 | #include "wx/frame.h" |
| 34 | #include "wx/menu.h" |
| 35 | #include "wx/app.h" |
| 36 | #include "wx/utils.h" |
| 37 | #include "wx/dialog.h" |
| 38 | #include "wx/settings.h" |
| 39 | #include "wx/dcclient.h" |
| 40 | #endif // WX_PRECOMP |
| 41 | |
| 42 | #include "wx/msw/private.h" |
| 43 | |
| 44 | #if wxUSE_STATUSBAR |
| 45 | #include "wx/statusbr.h" |
| 46 | |
| 47 | #if wxUSE_NATIVE_STATUSBAR |
| 48 | #include "wx/msw/statbr95.h" |
| 49 | #endif |
| 50 | #endif // wxUSE_STATUSBAR |
| 51 | |
| 52 | #if wxUSE_TOOLBAR |
| 53 | #include "wx/toolbar.h" |
| 54 | #endif // wxUSE_TOOLBAR |
| 55 | |
| 56 | #include "wx/menuitem.h" |
| 57 | #include "wx/log.h" |
| 58 | |
| 59 | // ---------------------------------------------------------------------------- |
| 60 | // globals |
| 61 | // ---------------------------------------------------------------------------- |
| 62 | |
| 63 | extern wxWindowList wxModelessWindows; |
| 64 | extern wxList WXDLLEXPORT wxPendingDelete; |
| 65 | extern wxChar wxFrameClassName[]; |
| 66 | extern wxMenu *wxCurrentPopupMenu; |
| 67 | |
| 68 | // ---------------------------------------------------------------------------- |
| 69 | // event tables |
| 70 | // ---------------------------------------------------------------------------- |
| 71 | |
| 72 | #if !USE_SHARED_LIBRARY |
| 73 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
| 74 | EVT_ACTIVATE(wxFrame::OnActivate) |
| 75 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) |
| 76 | END_EVENT_TABLE() |
| 77 | |
| 78 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) |
| 79 | #endif |
| 80 | |
| 81 | // ============================================================================ |
| 82 | // implementation |
| 83 | // ============================================================================ |
| 84 | |
| 85 | // ---------------------------------------------------------------------------- |
| 86 | // static class members |
| 87 | // ---------------------------------------------------------------------------- |
| 88 | |
| 89 | #if wxUSE_NATIVE_STATUSBAR |
| 90 | bool wxFrame::m_useNativeStatusBar = TRUE; |
| 91 | #else |
| 92 | bool wxFrame::m_useNativeStatusBar = FALSE; |
| 93 | #endif |
| 94 | |
| 95 | // ---------------------------------------------------------------------------- |
| 96 | // creation/destruction |
| 97 | // ---------------------------------------------------------------------------- |
| 98 | |
| 99 | void wxFrame::Init() |
| 100 | { |
| 101 | m_iconized = FALSE; |
| 102 | |
| 103 | #if wxUSE_TOOLTIPS |
| 104 | m_hwndToolTip = 0; |
| 105 | #endif |
| 106 | } |
| 107 | |
| 108 | bool wxFrame::Create(wxWindow *parent, |
| 109 | wxWindowID id, |
| 110 | const wxString& title, |
| 111 | const wxPoint& pos, |
| 112 | const wxSize& size, |
| 113 | long style, |
| 114 | const wxString& name) |
| 115 | { |
| 116 | SetName(name); |
| 117 | m_windowStyle = style; |
| 118 | m_frameMenuBar = NULL; |
| 119 | m_frameToolBar = NULL; |
| 120 | m_frameStatusBar = NULL; |
| 121 | |
| 122 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
| 123 | |
| 124 | if ( id > -1 ) |
| 125 | m_windowId = id; |
| 126 | else |
| 127 | m_windowId = (int)NewControlId(); |
| 128 | |
| 129 | if (parent) parent->AddChild(this); |
| 130 | |
| 131 | int x = pos.x; |
| 132 | int y = pos.y; |
| 133 | int width = size.x; |
| 134 | int height = size.y; |
| 135 | |
| 136 | m_iconized = FALSE; |
| 137 | |
| 138 | // we pass NULL as parent to MSWCreate because frames with parents behave |
| 139 | // very strangely under Win95 shell |
| 140 | // Alteration by JACS: keep normal Windows behaviour (float on top of parent) |
| 141 | // with this style. |
| 142 | if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0) |
| 143 | parent = NULL; |
| 144 | |
| 145 | if (!parent) |
| 146 | wxTopLevelWindows.Append(this); |
| 147 | |
| 148 | MSWCreate(m_windowId, parent, wxFrameClassName, this, title, |
| 149 | x, y, width, height, style); |
| 150 | |
| 151 | wxModelessWindows.Append(this); |
| 152 | return TRUE; |
| 153 | } |
| 154 | |
| 155 | wxFrame::~wxFrame() |
| 156 | { |
| 157 | m_isBeingDeleted = TRUE; |
| 158 | wxTopLevelWindows.DeleteObject(this); |
| 159 | |
| 160 | DeleteAllBars(); |
| 161 | |
| 162 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) |
| 163 | { |
| 164 | wxTheApp->SetTopWindow(NULL); |
| 165 | |
| 166 | if (wxTheApp->GetExitOnFrameDelete()) |
| 167 | { |
| 168 | PostQuitMessage(0); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | wxModelessWindows.DeleteObject(this); |
| 173 | |
| 174 | // For some reason, wxWindows can activate another task altogether |
| 175 | // when a frame is destroyed after a modal dialog has been invoked. |
| 176 | // Try to bring the parent to the top. |
| 177 | // MT:Only do this if this frame is currently the active window, else weird |
| 178 | // things start to happen |
| 179 | if ( wxGetActiveWindow() == this ) |
| 180 | if (GetParent() && GetParent()->GetHWND()) |
| 181 | ::BringWindowToTop((HWND) GetParent()->GetHWND()); |
| 182 | } |
| 183 | |
| 184 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
| 185 | void wxFrame::DoGetClientSize(int *x, int *y) const |
| 186 | { |
| 187 | RECT rect; |
| 188 | ::GetClientRect(GetHwnd(), &rect); |
| 189 | |
| 190 | #if wxUSE_STATUSBAR |
| 191 | if ( GetStatusBar() ) |
| 192 | { |
| 193 | int statusX, statusY; |
| 194 | GetStatusBar()->GetClientSize(&statusX, &statusY); |
| 195 | rect.bottom -= statusY; |
| 196 | } |
| 197 | #endif // wxUSE_STATUSBAR |
| 198 | |
| 199 | wxPoint pt(GetClientAreaOrigin()); |
| 200 | rect.bottom -= pt.y; |
| 201 | rect.right -= pt.x; |
| 202 | |
| 203 | if ( x ) |
| 204 | *x = rect.right; |
| 205 | if ( y ) |
| 206 | *y = rect.bottom; |
| 207 | } |
| 208 | |
| 209 | // Set the client size (i.e. leave the calculation of borders etc. |
| 210 | // to wxWindows) |
| 211 | void wxFrame::DoSetClientSize(int width, int height) |
| 212 | { |
| 213 | HWND hWnd = GetHwnd(); |
| 214 | |
| 215 | RECT rect; |
| 216 | ::GetClientRect(hWnd, &rect); |
| 217 | |
| 218 | RECT rect2; |
| 219 | GetWindowRect(hWnd, &rect2); |
| 220 | |
| 221 | // Find the difference between the entire window (title bar and all) |
| 222 | // and the client area; add this to the new client size to move the |
| 223 | // window |
| 224 | int actual_width = rect2.right - rect2.left - rect.right + width; |
| 225 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; |
| 226 | |
| 227 | #if wxUSE_STATUSBAR |
| 228 | if ( GetStatusBar() ) |
| 229 | { |
| 230 | int statusX, statusY; |
| 231 | GetStatusBar()->GetClientSize(&statusX, &statusY); |
| 232 | actual_height += statusY; |
| 233 | } |
| 234 | #endif // wxUSE_STATUSBAR |
| 235 | |
| 236 | wxPoint pt(GetClientAreaOrigin()); |
| 237 | actual_width += pt.y; |
| 238 | actual_height += pt.x; |
| 239 | |
| 240 | POINT point; |
| 241 | point.x = rect2.left; |
| 242 | point.y = rect2.top; |
| 243 | |
| 244 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE); |
| 245 | |
| 246 | wxSizeEvent event(wxSize(width, height), m_windowId); |
| 247 | event.SetEventObject( this ); |
| 248 | GetEventHandler()->ProcessEvent(event); |
| 249 | } |
| 250 | |
| 251 | void wxFrame::DoGetSize(int *width, int *height) const |
| 252 | { |
| 253 | RECT rect; |
| 254 | GetWindowRect(GetHwnd(), &rect); |
| 255 | *width = rect.right - rect.left; |
| 256 | *height = rect.bottom - rect.top; |
| 257 | } |
| 258 | |
| 259 | void wxFrame::DoGetPosition(int *x, int *y) const |
| 260 | { |
| 261 | RECT rect; |
| 262 | GetWindowRect(GetHwnd(), &rect); |
| 263 | POINT point; |
| 264 | point.x = rect.left; |
| 265 | point.y = rect.top; |
| 266 | |
| 267 | *x = point.x; |
| 268 | *y = point.y; |
| 269 | } |
| 270 | |
| 271 | // ---------------------------------------------------------------------------- |
| 272 | // variations around ::ShowWindow() |
| 273 | // ---------------------------------------------------------------------------- |
| 274 | |
| 275 | void wxFrame::DoShowWindow(int nShowCmd) |
| 276 | { |
| 277 | ::ShowWindow(GetHwnd(), nShowCmd); |
| 278 | |
| 279 | m_iconized = nShowCmd == SW_MINIMIZE; |
| 280 | } |
| 281 | |
| 282 | bool wxFrame::Show(bool show) |
| 283 | { |
| 284 | DoShowWindow(show ? SW_SHOW : SW_HIDE); |
| 285 | |
| 286 | if ( show ) |
| 287 | { |
| 288 | ::BringWindowToTop(GetHwnd()); |
| 289 | |
| 290 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); |
| 291 | event.SetEventObject( this ); |
| 292 | GetEventHandler()->ProcessEvent(event); |
| 293 | } |
| 294 | else |
| 295 | { |
| 296 | // Try to highlight the correct window (the parent) |
| 297 | if ( GetParent() ) |
| 298 | { |
| 299 | HWND hWndParent = GetHwndOf(GetParent()); |
| 300 | if (hWndParent) |
| 301 | ::BringWindowToTop(hWndParent); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return TRUE; |
| 306 | } |
| 307 | |
| 308 | void wxFrame::Iconize(bool iconize) |
| 309 | { |
| 310 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); |
| 311 | } |
| 312 | |
| 313 | void wxFrame::Maximize(bool maximize) |
| 314 | { |
| 315 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); |
| 316 | } |
| 317 | |
| 318 | void wxFrame::Restore() |
| 319 | { |
| 320 | DoShowWindow(SW_RESTORE); |
| 321 | } |
| 322 | |
| 323 | bool wxFrame::IsIconized() const |
| 324 | { |
| 325 | ((wxFrame *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0); |
| 326 | return m_iconized; |
| 327 | } |
| 328 | |
| 329 | // Is it maximized? |
| 330 | bool wxFrame::IsMaximized() const |
| 331 | { |
| 332 | return (::IsZoomed(GetHwnd()) != 0); |
| 333 | } |
| 334 | |
| 335 | void wxFrame::SetIcon(const wxIcon& icon) |
| 336 | { |
| 337 | wxFrameBase::SetIcon(icon); |
| 338 | |
| 339 | #if defined(__WIN95__) |
| 340 | if ( m_icon.Ok() ) |
| 341 | { |
| 342 | SendMessage(GetHwnd(), WM_SETICON, |
| 343 | (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON()); |
| 344 | } |
| 345 | #endif // __WIN95__ |
| 346 | } |
| 347 | |
| 348 | #if wxUSE_STATUSBAR |
| 349 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
| 350 | long style, |
| 351 | wxWindowID id, |
| 352 | const wxString& name) |
| 353 | { |
| 354 | wxStatusBar *statusBar = NULL; |
| 355 | |
| 356 | #if wxUSE_NATIVE_STATUSBAR |
| 357 | if ( UsesNativeStatusBar() ) |
| 358 | { |
| 359 | statusBar = new wxStatusBar95(this, id, style); |
| 360 | |
| 361 | statusBar->SetFieldsCount(number); |
| 362 | } |
| 363 | else |
| 364 | #endif |
| 365 | { |
| 366 | statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name); |
| 367 | } |
| 368 | |
| 369 | return statusBar; |
| 370 | } |
| 371 | |
| 372 | void wxFrame::PositionStatusBar() |
| 373 | { |
| 374 | // native status bar positions itself |
| 375 | if ( m_frameStatusBar |
| 376 | #if wxUSE_NATIVE_STATUSBAR |
| 377 | && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)) |
| 378 | #endif |
| 379 | ) |
| 380 | { |
| 381 | int w, h; |
| 382 | GetClientSize(&w, &h); |
| 383 | int sw, sh; |
| 384 | m_frameStatusBar->GetSize(&sw, &sh); |
| 385 | |
| 386 | // Since we wish the status bar to be directly under the client area, |
| 387 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. |
| 388 | m_frameStatusBar->SetSize(0, h, w, sh); |
| 389 | } |
| 390 | } |
| 391 | #endif // wxUSE_STATUSBAR |
| 392 | |
| 393 | void wxFrame::DetachMenuBar() |
| 394 | { |
| 395 | if (m_frameMenuBar) |
| 396 | { |
| 397 | m_frameMenuBar->Detach(); |
| 398 | m_frameMenuBar = NULL; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | void wxFrame::SetMenuBar(wxMenuBar *menu_bar) |
| 403 | { |
| 404 | if (!menu_bar) |
| 405 | { |
| 406 | DetachMenuBar(); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") ); |
| 411 | |
| 412 | if (m_frameMenuBar) |
| 413 | delete m_frameMenuBar; |
| 414 | |
| 415 | m_hMenu = menu_bar->Create(); |
| 416 | |
| 417 | if ( !m_hMenu ) |
| 418 | return; |
| 419 | |
| 420 | InternalSetMenuBar(); |
| 421 | |
| 422 | m_frameMenuBar = menu_bar; |
| 423 | menu_bar->Attach(this); |
| 424 | } |
| 425 | |
| 426 | void wxFrame::InternalSetMenuBar() |
| 427 | { |
| 428 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
| 429 | { |
| 430 | wxLogLastError("SetMenu"); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | // Responds to colour changes, and passes event on to children. |
| 435 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
| 436 | { |
| 437 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
| 438 | Refresh(); |
| 439 | |
| 440 | if ( m_frameStatusBar ) |
| 441 | { |
| 442 | wxSysColourChangedEvent event2; |
| 443 | event2.SetEventObject( m_frameStatusBar ); |
| 444 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
| 445 | } |
| 446 | |
| 447 | // Propagate the event to the non-top-level children |
| 448 | wxWindow::OnSysColourChanged(event); |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * Frame window |
| 453 | * |
| 454 | */ |
| 455 | |
| 456 | bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title, |
| 457 | int x, int y, int width, int height, long style) |
| 458 | |
| 459 | { |
| 460 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); |
| 461 | |
| 462 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN |
| 463 | // could be the culprit. But without it, you can get a lot of flicker. |
| 464 | |
| 465 | DWORD msflags = 0; |
| 466 | if ((style & wxCAPTION) == wxCAPTION) |
| 467 | msflags = WS_OVERLAPPED; |
| 468 | else |
| 469 | msflags = WS_POPUP; |
| 470 | |
| 471 | if (style & wxMINIMIZE_BOX) |
| 472 | msflags |= WS_MINIMIZEBOX; |
| 473 | if (style & wxMAXIMIZE_BOX) |
| 474 | msflags |= WS_MAXIMIZEBOX; |
| 475 | if (style & wxTHICK_FRAME) |
| 476 | msflags |= WS_THICKFRAME; |
| 477 | if (style & wxSYSTEM_MENU) |
| 478 | msflags |= WS_SYSMENU; |
| 479 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) |
| 480 | msflags |= WS_MINIMIZE; |
| 481 | if (style & wxMAXIMIZE) |
| 482 | msflags |= WS_MAXIMIZE; |
| 483 | if (style & wxCAPTION) |
| 484 | msflags |= WS_CAPTION; |
| 485 | if (style & wxCLIP_CHILDREN) |
| 486 | msflags |= WS_CLIPCHILDREN; |
| 487 | |
| 488 | // Keep this in wxFrame because it saves recoding this function |
| 489 | // in wxTinyFrame |
| 490 | #if wxUSE_ITSY_BITSY |
| 491 | if (style & wxTINY_CAPTION_VERT) |
| 492 | msflags |= IBS_VERTCAPTION; |
| 493 | if (style & wxTINY_CAPTION_HORIZ) |
| 494 | msflags |= IBS_HORZCAPTION; |
| 495 | #else |
| 496 | if (style & wxTINY_CAPTION_VERT) |
| 497 | msflags |= WS_CAPTION; |
| 498 | if (style & wxTINY_CAPTION_HORIZ) |
| 499 | msflags |= WS_CAPTION; |
| 500 | #endif |
| 501 | if ((style & wxTHICK_FRAME) == 0) |
| 502 | msflags |= WS_BORDER; |
| 503 | |
| 504 | WXDWORD extendedStyle = MakeExtendedStyle(style); |
| 505 | |
| 506 | #if !defined(__WIN16__) && !defined(__SC__) |
| 507 | if (style & wxFRAME_TOOL_WINDOW) |
| 508 | extendedStyle |= WS_EX_TOOLWINDOW; |
| 509 | #endif |
| 510 | |
| 511 | if (style & wxSTAY_ON_TOP) |
| 512 | extendedStyle |= WS_EX_TOPMOST; |
| 513 | |
| 514 | m_iconized = FALSE; |
| 515 | if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, |
| 516 | msflags, NULL, extendedStyle) ) |
| 517 | return FALSE; |
| 518 | |
| 519 | // Seems to be necessary if we use WS_POPUP |
| 520 | // style instead of WS_OVERLAPPED |
| 521 | if (width > -1 && height > -1) |
| 522 | ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); |
| 523 | |
| 524 | return TRUE; |
| 525 | } |
| 526 | |
| 527 | // Default activation behaviour - set the focus for the first child |
| 528 | // subwindow found. |
| 529 | void wxFrame::OnActivate(wxActivateEvent& event) |
| 530 | { |
| 531 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
| 532 | node; |
| 533 | node = node->GetNext() ) |
| 534 | { |
| 535 | // FIXME all this is totally bogus - we need to do the same as wxPanel, |
| 536 | // but how to do it without duplicating the code? |
| 537 | |
| 538 | // restore focus |
| 539 | wxWindow *child = node->GetData(); |
| 540 | |
| 541 | if ( !child->IsTopLevel() |
| 542 | #if wxUSE_TOOLBAR |
| 543 | && !wxDynamicCast(child, wxToolBar) |
| 544 | #endif // wxUSE_TOOLBAR |
| 545 | #if wxUSE_STATUSBAR |
| 546 | && !wxDynamicCast(child, wxStatusBar) |
| 547 | #endif // wxUSE_STATUSBAR |
| 548 | ) |
| 549 | { |
| 550 | child->SetFocus(); |
| 551 | return; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | // ---------------------------------------------------------------------------- |
| 557 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars |
| 558 | // from the client area, so the client area is what's really available for the |
| 559 | // frame contents |
| 560 | // ---------------------------------------------------------------------------- |
| 561 | |
| 562 | // Checks if there is a toolbar, and returns the first free client position |
| 563 | wxPoint wxFrame::GetClientAreaOrigin() const |
| 564 | { |
| 565 | wxPoint pt(0, 0); |
| 566 | if (GetToolBar()) |
| 567 | { |
| 568 | int w, h; |
| 569 | GetToolBar()->GetSize(& w, & h); |
| 570 | |
| 571 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) |
| 572 | { |
| 573 | pt.x += w; |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | pt.y += h; |
| 578 | } |
| 579 | } |
| 580 | return pt; |
| 581 | } |
| 582 | |
| 583 | void wxFrame::DoScreenToClient(int *x, int *y) const |
| 584 | { |
| 585 | wxWindow::DoScreenToClient(x, y); |
| 586 | |
| 587 | // We may be faking the client origin. |
| 588 | // So a window that's really at (0, 30) may appear |
| 589 | // (to wxWin apps) to be at (0, 0). |
| 590 | wxPoint pt(GetClientAreaOrigin()); |
| 591 | *x -= pt.x; |
| 592 | *y -= pt.y; |
| 593 | } |
| 594 | |
| 595 | void wxFrame::DoClientToScreen(int *x, int *y) const |
| 596 | { |
| 597 | // We may be faking the client origin. |
| 598 | // So a window that's really at (0, 30) may appear |
| 599 | // (to wxWin apps) to be at (0, 0). |
| 600 | wxPoint pt1(GetClientAreaOrigin()); |
| 601 | *x += pt1.x; |
| 602 | *y += pt1.y; |
| 603 | |
| 604 | wxWindow::DoClientToScreen(x, y); |
| 605 | } |
| 606 | |
| 607 | // ---------------------------------------------------------------------------- |
| 608 | // tool/status bar stuff |
| 609 | // ---------------------------------------------------------------------------- |
| 610 | |
| 611 | #if wxUSE_TOOLBAR |
| 612 | |
| 613 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
| 614 | { |
| 615 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
| 616 | { |
| 617 | PositionToolBar(); |
| 618 | } |
| 619 | |
| 620 | return m_frameToolBar; |
| 621 | } |
| 622 | |
| 623 | void wxFrame::PositionToolBar() |
| 624 | { |
| 625 | RECT rect; |
| 626 | ::GetClientRect(GetHwnd(), &rect); |
| 627 | |
| 628 | #if wxUSE_STATUSBAR |
| 629 | if ( GetStatusBar() ) |
| 630 | { |
| 631 | int statusX, statusY; |
| 632 | GetStatusBar()->GetClientSize(&statusX, &statusY); |
| 633 | rect.bottom -= statusY; |
| 634 | } |
| 635 | #endif // wxUSE_STATUSBAR |
| 636 | |
| 637 | if ( GetToolBar() ) |
| 638 | { |
| 639 | int tw, th; |
| 640 | GetToolBar()->GetSize(&tw, &th); |
| 641 | |
| 642 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) |
| 643 | { |
| 644 | th = rect.bottom; |
| 645 | } |
| 646 | else |
| 647 | { |
| 648 | tw = rect.right; |
| 649 | } |
| 650 | |
| 651 | // Use the 'real' MSW position here |
| 652 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); |
| 653 | } |
| 654 | } |
| 655 | #endif // wxUSE_TOOLBAR |
| 656 | |
| 657 | // ---------------------------------------------------------------------------- |
| 658 | // frame state (iconized/maximized/...) |
| 659 | // ---------------------------------------------------------------------------- |
| 660 | |
| 661 | // propagate our state change to all child frames: this allows us to emulate X |
| 662 | // Windows behaviour where child frames float independently of the parent one |
| 663 | // on the desktop, but are iconized/restored with it |
| 664 | void wxFrame::IconizeChildFrames(bool bIconize) |
| 665 | { |
| 666 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
| 667 | node; |
| 668 | node = node->GetNext() ) |
| 669 | { |
| 670 | wxWindow *win = node->GetData(); |
| 671 | |
| 672 | if ( win->IsKindOf(CLASSINFO(wxFrame)) ) |
| 673 | { |
| 674 | ((wxFrame *)win)->Iconize(bIconize); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | // =========================================================================== |
| 680 | // message processing |
| 681 | // =========================================================================== |
| 682 | |
| 683 | // --------------------------------------------------------------------------- |
| 684 | // preprocessing |
| 685 | // --------------------------------------------------------------------------- |
| 686 | |
| 687 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) |
| 688 | { |
| 689 | if ( wxWindow::MSWTranslateMessage(pMsg) ) |
| 690 | return TRUE; |
| 691 | |
| 692 | // try the menu bar accels |
| 693 | wxMenuBar *menuBar = GetMenuBar(); |
| 694 | if ( !menuBar ) |
| 695 | return FALSE; |
| 696 | |
| 697 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); |
| 698 | return acceleratorTable.Translate(this, pMsg); |
| 699 | } |
| 700 | |
| 701 | // --------------------------------------------------------------------------- |
| 702 | // our private (non virtual) message handlers |
| 703 | // --------------------------------------------------------------------------- |
| 704 | |
| 705 | bool wxFrame::HandlePaint() |
| 706 | { |
| 707 | RECT rect; |
| 708 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) |
| 709 | { |
| 710 | if ( m_iconized ) |
| 711 | { |
| 712 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
| 713 | : (HICON)m_defaultIcon; |
| 714 | |
| 715 | // Hold a pointer to the dc so long as the OnPaint() message |
| 716 | // is being processed |
| 717 | PAINTSTRUCT ps; |
| 718 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); |
| 719 | |
| 720 | // Erase background before painting or we get white background |
| 721 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); |
| 722 | |
| 723 | if ( hIcon ) |
| 724 | { |
| 725 | RECT rect; |
| 726 | ::GetClientRect(GetHwnd(), &rect); |
| 727 | |
| 728 | // FIXME: why hardcoded? |
| 729 | static const int icon_width = 32; |
| 730 | static const int icon_height = 32; |
| 731 | |
| 732 | int icon_x = (int)((rect.right - icon_width)/2); |
| 733 | int icon_y = (int)((rect.bottom - icon_height)/2); |
| 734 | |
| 735 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); |
| 736 | } |
| 737 | |
| 738 | ::EndPaint(GetHwnd(), &ps); |
| 739 | |
| 740 | return TRUE; |
| 741 | } |
| 742 | else |
| 743 | { |
| 744 | return wxWindow::HandlePaint(); |
| 745 | } |
| 746 | } |
| 747 | else |
| 748 | { |
| 749 | // nothing to paint - processed |
| 750 | return TRUE; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | bool wxFrame::HandleSize(int x, int y, WXUINT id) |
| 755 | { |
| 756 | bool processed = FALSE; |
| 757 | |
| 758 | switch ( id ) |
| 759 | { |
| 760 | case SIZENORMAL: |
| 761 | // only do it it if we were iconized before, otherwise resizing the |
| 762 | // parent frame has a curious side effect of bringing it under it's |
| 763 | // children |
| 764 | if ( !m_iconized ) |
| 765 | break; |
| 766 | |
| 767 | // restore all child frames too |
| 768 | IconizeChildFrames(FALSE); |
| 769 | |
| 770 | // fall through |
| 771 | |
| 772 | case SIZEFULLSCREEN: |
| 773 | m_iconized = FALSE; |
| 774 | break; |
| 775 | |
| 776 | case SIZEICONIC: |
| 777 | // iconize all child frames too |
| 778 | IconizeChildFrames(TRUE); |
| 779 | |
| 780 | m_iconized = TRUE; |
| 781 | break; |
| 782 | } |
| 783 | |
| 784 | if ( !m_iconized ) |
| 785 | { |
| 786 | // forward WM_SIZE to status bar control |
| 787 | #if wxUSE_NATIVE_STATUSBAR |
| 788 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) |
| 789 | { |
| 790 | wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); |
| 791 | event.SetEventObject( m_frameStatusBar ); |
| 792 | |
| 793 | ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); |
| 794 | } |
| 795 | #endif // wxUSE_NATIVE_STATUSBAR |
| 796 | |
| 797 | PositionStatusBar(); |
| 798 | PositionToolBar(); |
| 799 | |
| 800 | wxSizeEvent event(wxSize(x, y), m_windowId); |
| 801 | event.SetEventObject( this ); |
| 802 | processed = GetEventHandler()->ProcessEvent(event); |
| 803 | } |
| 804 | |
| 805 | return processed; |
| 806 | } |
| 807 | |
| 808 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
| 809 | { |
| 810 | if ( control ) |
| 811 | { |
| 812 | // In case it's e.g. a toolbar. |
| 813 | wxWindow *win = wxFindWinFromHandle(control); |
| 814 | if ( win ) |
| 815 | return win->MSWCommand(cmd, id); |
| 816 | } |
| 817 | |
| 818 | // handle here commands from menus and accelerators |
| 819 | if ( cmd == 0 || cmd == 1 ) |
| 820 | { |
| 821 | if ( wxCurrentPopupMenu ) |
| 822 | { |
| 823 | wxMenu *popupMenu = wxCurrentPopupMenu; |
| 824 | wxCurrentPopupMenu = NULL; |
| 825 | |
| 826 | return popupMenu->MSWCommand(cmd, id); |
| 827 | } |
| 828 | |
| 829 | if ( ProcessCommand(id) ) |
| 830 | { |
| 831 | return TRUE; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | return FALSE; |
| 836 | } |
| 837 | |
| 838 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
| 839 | { |
| 840 | int item; |
| 841 | if ( flags == 0xFFFF && hMenu == 0 ) |
| 842 | { |
| 843 | // menu was removed from screen |
| 844 | item = -1; |
| 845 | } |
| 846 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
| 847 | { |
| 848 | item = nItem; |
| 849 | } |
| 850 | else |
| 851 | { |
| 852 | // don't give hints for separators (doesn't make sense) nor for the |
| 853 | // items opening popup menus (they don't have them anyhow) |
| 854 | return FALSE; |
| 855 | } |
| 856 | |
| 857 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); |
| 858 | event.SetEventObject( this ); |
| 859 | |
| 860 | return GetEventHandler()->ProcessEvent(event); |
| 861 | } |
| 862 | |
| 863 | // --------------------------------------------------------------------------- |
| 864 | // the window proc for wxFrame |
| 865 | // --------------------------------------------------------------------------- |
| 866 | |
| 867 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
| 868 | { |
| 869 | long rc = 0; |
| 870 | bool processed = FALSE; |
| 871 | |
| 872 | switch ( message ) |
| 873 | { |
| 874 | case WM_CLOSE: |
| 875 | // if we can't close, tell the system that we processed the |
| 876 | // message - otherwise it would close us |
| 877 | processed = !Close(); |
| 878 | break; |
| 879 | |
| 880 | case WM_COMMAND: |
| 881 | { |
| 882 | WORD id, cmd; |
| 883 | WXHWND hwnd; |
| 884 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, |
| 885 | &id, &hwnd, &cmd); |
| 886 | |
| 887 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); |
| 888 | } |
| 889 | break; |
| 890 | |
| 891 | case WM_MENUSELECT: |
| 892 | { |
| 893 | WXWORD item, flags; |
| 894 | WXHMENU hmenu; |
| 895 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); |
| 896 | |
| 897 | processed = HandleMenuSelect(item, flags, hmenu); |
| 898 | } |
| 899 | break; |
| 900 | |
| 901 | case WM_PAINT: |
| 902 | processed = HandlePaint(); |
| 903 | break; |
| 904 | |
| 905 | case WM_QUERYDRAGICON: |
| 906 | { |
| 907 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
| 908 | : (HICON)(m_defaultIcon); |
| 909 | rc = (long)hIcon; |
| 910 | processed = rc != 0; |
| 911 | } |
| 912 | break; |
| 913 | |
| 914 | case WM_SIZE: |
| 915 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); |
| 916 | break; |
| 917 | } |
| 918 | |
| 919 | if ( !processed ) |
| 920 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); |
| 921 | |
| 922 | return rc; |
| 923 | } |
| 924 | |