From 82c9f85ce5aceaa3aedac7e690070d5eff904e5b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Sep 2001 00:34:14 +0000 Subject: [PATCH] added wxTLW for MSW git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dialog.h | 12 +- include/wx/msw/dialog.h | 23 +-- include/wx/msw/frame.h | 27 +--- include/wx/msw/mdi.h | 7 +- include/wx/msw/private.h | 36 ++++- include/wx/msw/toplevel.h | 87 ++++++++++++ include/wx/toplevel.h | 14 +- samples/minimal/minimal.cpp | 48 ++++++- src/common/toplvcmn.cpp | 31 +++-- src/gtk/dialog.cpp | 11 +- src/gtk/toplevel.cpp | 18 +-- src/gtk1/dialog.cpp | 11 +- src/gtk1/toplevel.cpp | 18 +-- src/msw/dialog.cpp | 112 ++------------- src/msw/frame.cpp | 269 ++++------------------------------- src/msw/mdi.cpp | 19 ++- src/msw/tbar95.cpp | 29 ++-- src/msw/toplevel.cpp | 270 ++++++++++++++++++++++++++++++++++++ src/msw/window.cpp | 55 +++----- src/univ/topluniv.cpp | 2 - 20 files changed, 591 insertions(+), 508 deletions(-) create mode 100644 include/wx/msw/toplevel.h create mode 100644 src/msw/toplevel.cpp diff --git a/include/wx/dialog.h b/include/wx/dialog.h index b3d75ccfbb..cfab0663ad 100644 --- a/include/wx/dialog.h +++ b/include/wx/dialog.h @@ -30,10 +30,10 @@ class WXDLLEXPORT wxDialogBase : public wxTopLevelWindow { public: wxDialogBase() { Init(); } - ~wxDialogBase() {} - + virtual ~wxDialogBase() { } + void Init(); - + // the modal dialogs have a return code - usually the id of the last // pressed button void SetReturnCode(int returnCode) { m_returnCode = returnCode; } @@ -44,7 +44,7 @@ public: // lines into a vertical wxBoxSizer wxSizer *CreateTextSizer( const wxString &message ); #endif // wxUSE_STATTEXT && wxUSE_TEXTCTRL - + #if wxUSE_BUTTON // places buttons into a horizontal wxBoxSizer wxSizer *CreateButtonSizer( long flags ); @@ -55,10 +55,10 @@ protected: int m_returnCode; // FIXME - temporary hack in absence of wxTLW !! - #ifdef wxTopLevelWindowNative +#ifdef wxTopLevelWindowNative DECLARE_EVENT_TABLE() WX_DECLARE_CONTROL_CONTAINER(); - #endif +#endif }; diff --git a/include/wx/msw/dialog.h b/include/wx/msw/dialog.h index 5fb90d68c3..552f764fc8 100644 --- a/include/wx/msw/dialog.h +++ b/include/wx/msw/dialog.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: dialog.h +// Name: wx/msw/dialog.h // Purpose: wxDialog class // Author: Julian Smart // Modified by: @@ -56,15 +56,7 @@ public: long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = wxDialogNameStr); - ~wxDialog(); - - // override some base class virtuals - virtual bool Destroy(); - virtual bool Show(bool show); - virtual void Iconize(bool iconize); - virtual bool IsIconized() const; - - virtual bool IsTopLevel() const { return TRUE; } + virtual ~wxDialog(); void SetModal(bool flag); virtual bool IsModal() const; @@ -78,16 +70,15 @@ public: // returns TRUE if we're in a modal loop bool IsModalShowing() const; -#if WXWIN_COMPATIBILITY - bool Iconized() const { return IsIconized(); }; -#endif - // wxMSW only: remove the "Close" button from the dialog bool EnableCloseButton(bool enable = TRUE); // implementation only from now on // ------------------------------- + // override some base class virtuals + virtual bool Show(bool show); + // event handlers bool OnClose(); void OnCharHook(wxKeyEvent& event); @@ -110,10 +101,6 @@ public: #endif // wxUSE_CTL3D protected: - // override more base class virtuals - virtual void DoSetClientSize(int width, int height); - virtual void DoGetPosition(int *x, int *y) const; - // show modal dialog and enter modal loop void DoShowModal(); diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index abd5752e93..a6215ab037 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -45,22 +45,13 @@ public: virtual ~wxFrameMSW(); // implement base class pure virtuals - virtual void Raise(); - virtual void Maximize(bool maximize = TRUE); - virtual bool IsMaximized() const; - virtual void Iconize(bool iconize = TRUE); - virtual bool IsIconized() const; - virtual void Restore(); - virtual void SetIcon(const wxIcon& icon); virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL); virtual bool IsFullScreen() const { return m_fsIsShowing; }; + virtual void Raise(); // implementation only from now on // ------------------------------- - // override some more virtuals - virtual bool Show(bool show = TRUE); - // event handlers void OnActivate(wxActivateEvent& event); void OnSysColourChanged(wxSysColourChangedEvent& event); @@ -124,14 +115,8 @@ protected: // common part of all ctors void Init(); - // common part of Iconize(), Maximize() and Restore() - void DoShowWindow(int nShowCmd); - // override base class virtuals virtual void DoGetClientSize(int *width, int *height) const; - virtual void DoGetSize(int *width, int *height) const; - virtual void DoGetPosition(int *x, int *y) const; - virtual void DoSetClientSize(int width, int height); #if wxUSE_MENUS_NATIVE @@ -154,14 +139,8 @@ protected: virtual bool IsMDIChild() const { return FALSE; } - // is the frame currently iconized? - bool m_iconized; - - // should the frame be maximized when it will be shown? set by Maximize() - // when it is called while the frame is hidden - bool m_maximizeOnShow; - - WXHICON m_defaultIcon; + // get default (wxWindows) icon for the frame + virtual WXHICON GetDefaultIcon() const; #if wxUSE_STATUSBAR static bool m_useNativeStatusBar; diff --git a/include/wx/msw/mdi.h b/include/wx/msw/mdi.h index 129cd8b40d..b65c21f750 100644 --- a/include/wx/msw/mdi.h +++ b/include/wx/msw/mdi.h @@ -30,8 +30,6 @@ class WXDLLEXPORT wxMDIChildFrame; class WXDLLEXPORT wxMDIParentFrame : public wxFrame { - DECLARE_DYNAMIC_CLASS(wxMDIParentFrame) - public: wxMDIParentFrame(); wxMDIParentFrame(wxWindow *parent, @@ -102,6 +100,8 @@ protected: virtual void InternalSetMenuBar(); #endif // wxUSE_MENUS_NATIVE + virtual WXHICON GetDefaultIcon() const; + wxMDIClientWindow * m_clientWindow; wxMDIChildFrame * m_currentChild; wxMenu* m_windowMenu; @@ -113,6 +113,7 @@ private: friend class WXDLLEXPORT wxMDIChildFrame; DECLARE_EVENT_TABLE() + DECLARE_DYNAMIC_CLASS(wxMDIParentFrame) }; // --------------------------------------------------------------------------- @@ -178,6 +179,8 @@ protected: virtual void InternalSetMenuBar(); virtual bool IsMDIChild() const { return TRUE; } + virtual WXHICON GetDefaultIcon() const; + // common part of all ctors void Init(); diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 3a76dd883b..2f5c2e49df 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -248,6 +248,38 @@ inline bool wxIsCtrlDown() return (::GetKeyState(VK_CONTROL) & 0x100) != 0; } +// wrapper around GetWindowRect() and GetClientRect() APIs doing error checking +// for Win32 +inline RECT wxGetWindowRect(HWND hwnd) +{ + RECT rect; +#ifdef __WIN16__ + ::GetWindowRect(hwnd, &rect); +#else // Win32 + if ( !::GetWindowRect(hwnd, &rect) ) + { + wxLogLastError(_T("GetWindowRect")); + } +#endif // Win16/32 + + return rect; +} + +inline RECT wxGetClientRect(HWND hwnd) +{ + RECT rect; +#ifdef __WIN16__ + ::GetClientRect(hwnd, &rect); +#else // Win32 + if ( !::GetClientRect(hwnd, &rect) ) + { + wxLogLastError(_T("GetClientRect")); + } +#endif // Win16/32 + + return rect; +} + // --------------------------------------------------------------------------- // small helper classes // --------------------------------------------------------------------------- @@ -357,8 +389,8 @@ WXDLLEXPORT extern WXWORD wxGetWindowId(WXHWND hWnd); // Does this window style specify any border? inline bool wxStyleHasBorder(long style) { - return (style & (wxSIMPLE_BORDER | wxRAISED_BORDER | - wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0; + return (style & (wxSIMPLE_BORDER | wxRAISED_BORDER | + wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0; } // find the window for HWND which is part of some wxWindow, returns just the diff --git a/include/wx/msw/toplevel.h b/include/wx/msw/toplevel.h new file mode 100644 index 0000000000..7b9f97886b --- /dev/null +++ b/include/wx/msw/toplevel.h @@ -0,0 +1,87 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/msw/toplevel.h +// Purpose: wxTopLevelWindowMSW is the MSW implementation of wxTLW +// Author: Vadim Zeitlin +// Modified by: +// Created: 20.09.01 +// RCS-ID: $Id$ +// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MSW_TOPLEVEL_H_ +#define _WX_MSW_TOPLEVEL_H_ + +#ifdef __GNUG__ + #pragma interface "toplevel.h" +#endif + +// ---------------------------------------------------------------------------- +// wxTopLevelWindowMSW +// ---------------------------------------------------------------------------- + +class wxTopLevelWindowMSW : public wxTopLevelWindowBase +{ +public: + // constructors and such + wxTopLevelWindowMSW() { Init(); } + + wxTopLevelWindowMSW(wxWindow *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr) + { + Init(); + + (void)Create(parent, id, title, pos, size, style, name); + } + + bool Create(wxWindow *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr); + + virtual ~wxTopLevelWindowMSW(); + + // implement base class pure virtuals + virtual void Maximize(bool maximize = TRUE); + virtual bool IsMaximized() const; + virtual void Iconize(bool iconize = TRUE); + virtual bool IsIconized() const; + virtual void SetIcon(const wxIcon& icon); + virtual void Restore(); + + virtual bool Show(bool show = TRUE); + + // implementation from now on + // -------------------------- + +protected: + // common part of all ctors + void Init(); + + // common part of Iconize(), Maximize() and Restore() + void DoShowWindow(int nShowCmd); + + // implement the geometry-related methods for a top level window + virtual void DoSetClientSize(int width, int height); + + // is the frame currently iconized? + bool m_iconized; + + // should the frame be maximized when it will be shown? set by Maximize() + // when it is called while the frame is hidden + bool m_maximizeOnShow; +}; + +// list of all frames and modeless dialogs +extern WXDLLEXPORT_DATA(wxWindowList) wxModelessWindows; + +#endif // _WX_MSW_TOPLEVEL_H_ + diff --git a/include/wx/toplevel.h b/include/wx/toplevel.h index 157ff3f0f3..f4482a2850 100644 --- a/include/wx/toplevel.h +++ b/include/wx/toplevel.h @@ -52,10 +52,7 @@ class WXDLLEXPORT wxTopLevelWindowBase : public wxWindow public: // construction wxTopLevelWindowBase(); -#ifdef __DARWIN__ - virtual ~wxTopLevelWindowBase() {} -#endif - + // top level wnd state // -------------------- @@ -108,6 +105,10 @@ public: // so should be there for all platforms void OnActivate(wxActivateEvent &WXUNUSED(event)) { } +#ifdef __DARWIN__ + virtual ~wxTopLevelWindowBase() {} +#endif + protected: // the frame client to screen translation should take account of the // toolbar which may shift the origin of the client area @@ -129,7 +130,10 @@ protected: // include the real class declaration -#if defined(__WXGTK__) +#if defined(__WXMSW__) + #include "wx/msw/toplevel.h" + #define wxTopLevelWindowNative wxTopLevelWindowMSW +#elif defined(__WXGTK__) #include "wx/gtk/toplevel.h" #define wxTopLevelWindowNative wxTopLevelWindowGTK #elif defined(__WXMGL__) diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp index d51eb10f59..59e20e6ca9 100644 --- a/samples/minimal/minimal.cpp +++ b/samples/minimal/minimal.cpp @@ -35,6 +35,10 @@ #include "wx/wx.h" #endif +#include "wx/dynarray.h" + +WX_DEFINE_ARRAY(wxWindow *, wxArrayLboxes); + // ---------------------------------------------------------------------------- // resources // ---------------------------------------------------------------------------- @@ -70,8 +74,13 @@ public: // event handlers (these functions should _not_ be virtual) void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); + void OnCreateLbox(wxCommandEvent& event); + void OnDeleteLbox(wxCommandEvent& event); private: + wxArrayLboxes m_lboxes; + wxCoord m_pos; + // any class wishing to process wxWindows events must use this macro DECLARE_EVENT_TABLE() }; @@ -85,9 +94,14 @@ enum { // menu items Minimal_Quit = 1, - Minimal_About + Minimal_About, + Minimal_CreateLbox, + Minimal_DeleteLbox, }; +static const size_t NUM_LBOXES = 10; +static const wxCoord POS_STEP = 5; + // ---------------------------------------------------------------------------- // event tables and other macros for wxWindows // ---------------------------------------------------------------------------- @@ -98,6 +112,8 @@ enum BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Minimal_Quit, MyFrame::OnQuit) EVT_MENU(Minimal_About, MyFrame::OnAbout) + EVT_MENU(Minimal_CreateLbox, MyFrame::OnCreateLbox) + EVT_MENU(Minimal_DeleteLbox, MyFrame::OnDeleteLbox) END_EVENT_TABLE() // Create a new application object: this macro will allow wxWindows to create @@ -107,7 +123,6 @@ END_EVENT_TABLE() // not wxApp) IMPLEMENT_APP(MyApp) - // ============================================================================ // implementation // ============================================================================ @@ -141,6 +156,8 @@ bool MyApp::OnInit() MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, -1, title, pos, size) { + m_pos = 0; + #ifdef __WXMAC__ // we need this in order to allow the about menu relocation, since ABOUT is // not the default id of the about menu @@ -157,6 +174,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) // the "About" item should be in the help menu wxMenu *helpMenu = new wxMenu; helpMenu->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); + helpMenu->Append(Minimal_CreateLbox, "&Create 10 listboxes\tCtrl-C"); + helpMenu->Append(Minimal_DeleteLbox, "&Delete 10 listboxes\tCtrl-D"); menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program"); @@ -193,3 +212,28 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxMessageBox(msg, "About Minimal", wxOK | wxICON_INFORMATION, this); } + +void MyFrame::OnCreateLbox(wxCommandEvent& WXUNUSED(event)) +{ + for ( size_t n = 0; n < NUM_LBOXES; n++ ) + { + m_lboxes.Add(new wxListBox(this, -1, wxPoint(m_pos, m_pos))); + m_pos += POS_STEP; + } +} + +void MyFrame::OnDeleteLbox(wxCommandEvent& WXUNUSED(event)) +{ + size_t count = m_lboxes.GetCount(); + if ( count < NUM_LBOXES ) + return; + + for ( size_t n = 0; n < NUM_LBOXES; n++ ) + { + delete m_lboxes[--count]; + m_lboxes.RemoveAt(count); + + m_pos -= POS_STEP; + } +} + diff --git a/src/common/toplvcmn.cpp b/src/common/toplvcmn.cpp index 9cc07cc8d8..7a9101dbb2 100644 --- a/src/common/toplvcmn.cpp +++ b/src/common/toplvcmn.cpp @@ -45,6 +45,8 @@ END_EVENT_TABLE() // implementation // ============================================================================ +IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow) + // ---------------------------------------------------------------------------- // construction/destruction // ---------------------------------------------------------------------------- @@ -64,31 +66,32 @@ bool wxTopLevelWindowBase::Destroy() } // ---------------------------------------------------------------------------- -// wxTopLevelWindow size management: we exclude the areas taken by menu/status/toolbars -// from the client area, so the client area is what's really available for the -// frame contents +// wxTopLevelWindow size management: we exclude the areas taken by +// menu/status/toolbars from the client area, so the client area is what's +// really available for the frame contents // ---------------------------------------------------------------------------- void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const { wxWindow::DoScreenToClient(x, y); - // We may be faking the client origin. - // So a window that's really at (0, 30) may appear - // (to wxWin apps) to be at (0, 0). + // translate the wxWindow client coords to our client coords wxPoint pt(GetClientAreaOrigin()); - *x -= pt.x; - *y -= pt.y; + if ( x ) + *x -= pt.x; + if ( y ) + *y -= pt.y; } void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const { - // We may be faking the client origin. - // So a window that's really at (0, 30) may appear - // (to wxWin apps) to be at (0, 0). - wxPoint pt1(GetClientAreaOrigin()); - *x += pt1.x; - *y += pt1.y; + // our client area origin (0, 0) may be really something like (0, 30) for + // wxWindow if we have a toolbar, account for it before translating + wxPoint pt(GetClientAreaOrigin()); + if ( x ) + *x += pt.x; + if ( y ) + *y += pt.y; wxWindow::DoClientToScreen(x, y); } diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index 445afaf5ae..d1d13da9b3 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -59,11 +59,8 @@ wxDialog::wxDialog( wxWindow *parent, long style, const wxString &name ) { Init(); - - // all dialogs should have tab traversal enabled - style |= wxTAB_TRAVERSAL; - Create( parent, id, title, pos, size, style, name ); + (void)Create( parent, id, title, pos, size, style, name ); } bool wxDialog::Create( wxWindow *parent, @@ -73,12 +70,16 @@ bool wxDialog::Create( wxWindow *parent, { SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); + // all dialogs should have tab traversal enabled + style |= wxTAB_TRAVERSAL; + return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); } void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) { - if (Validate()) TransferDataFromWindow(); + if (Validate()) + TransferDataFromWindow(); } void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index 422f586a9d..483af5d4e4 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -50,10 +50,6 @@ extern int g_openDialogs; // event tables // ---------------------------------------------------------------------------- -#ifndef __WXUNIVERSAL__ - IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow) -#endif - // ---------------------------------------------------------------------------- // data // ---------------------------------------------------------------------------- @@ -190,9 +186,9 @@ gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget), wxTopLevelWindowGTK * /* All this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. Not tested. */ - gdk_window_set_decorations(win->m_widget->window, + gdk_window_set_decorations(win->m_widget->window, (GdkWMDecoration)win->m_gdkDecor); - gdk_window_set_functions(win->m_widget->window, + gdk_window_set_functions(win->m_widget->window, (GdkWMFunction)win->m_gdkFunc); /* GTK's shrinking/growing policy */ @@ -377,7 +373,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, if (style & wxFRAME_TOOL_WINDOW) win_type = GTK_WINDOW_POPUP; - + if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) win_type = GTK_WINDOW_DIALOG; @@ -474,9 +470,9 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, { m_gdkDecor = (long) GDK_DECOR_BORDER; m_gdkFunc = (long) GDK_FUNC_MOVE; - + // All this is for Motif Window Manager "hints" and is supposed to be - // recognized by other WM as well. Not tested. + // recognized by other WM as well. Not tested. if ((style & wxCAPTION) != 0) m_gdkDecor |= GDK_DECOR_TITLE; if ((style & wxSYSTEM_MENU) != 0) @@ -679,12 +675,12 @@ void wxTopLevelWindowGTK::DoSetClientSize( int width, int height ) { wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); - DoSetSize(-1, -1, + DoSetSize(-1, -1, width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0); } void wxTopLevelWindowGTK::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), - int width, int height ) + int width, int height ) { // due to a bug in gtk, x,y are always 0 // m_x = x; diff --git a/src/gtk1/dialog.cpp b/src/gtk1/dialog.cpp index 445afaf5ae..d1d13da9b3 100644 --- a/src/gtk1/dialog.cpp +++ b/src/gtk1/dialog.cpp @@ -59,11 +59,8 @@ wxDialog::wxDialog( wxWindow *parent, long style, const wxString &name ) { Init(); - - // all dialogs should have tab traversal enabled - style |= wxTAB_TRAVERSAL; - Create( parent, id, title, pos, size, style, name ); + (void)Create( parent, id, title, pos, size, style, name ); } bool wxDialog::Create( wxWindow *parent, @@ -73,12 +70,16 @@ bool wxDialog::Create( wxWindow *parent, { SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); + // all dialogs should have tab traversal enabled + style |= wxTAB_TRAVERSAL; + return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); } void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) { - if (Validate()) TransferDataFromWindow(); + if (Validate()) + TransferDataFromWindow(); } void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) diff --git a/src/gtk1/toplevel.cpp b/src/gtk1/toplevel.cpp index 422f586a9d..483af5d4e4 100644 --- a/src/gtk1/toplevel.cpp +++ b/src/gtk1/toplevel.cpp @@ -50,10 +50,6 @@ extern int g_openDialogs; // event tables // ---------------------------------------------------------------------------- -#ifndef __WXUNIVERSAL__ - IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow) -#endif - // ---------------------------------------------------------------------------- // data // ---------------------------------------------------------------------------- @@ -190,9 +186,9 @@ gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget), wxTopLevelWindowGTK * /* All this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. Not tested. */ - gdk_window_set_decorations(win->m_widget->window, + gdk_window_set_decorations(win->m_widget->window, (GdkWMDecoration)win->m_gdkDecor); - gdk_window_set_functions(win->m_widget->window, + gdk_window_set_functions(win->m_widget->window, (GdkWMFunction)win->m_gdkFunc); /* GTK's shrinking/growing policy */ @@ -377,7 +373,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, if (style & wxFRAME_TOOL_WINDOW) win_type = GTK_WINDOW_POPUP; - + if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) win_type = GTK_WINDOW_DIALOG; @@ -474,9 +470,9 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, { m_gdkDecor = (long) GDK_DECOR_BORDER; m_gdkFunc = (long) GDK_FUNC_MOVE; - + // All this is for Motif Window Manager "hints" and is supposed to be - // recognized by other WM as well. Not tested. + // recognized by other WM as well. Not tested. if ((style & wxCAPTION) != 0) m_gdkDecor |= GDK_DECOR_TITLE; if ((style & wxSYSTEM_MENU) != 0) @@ -679,12 +675,12 @@ void wxTopLevelWindowGTK::DoSetClientSize( int width, int height ) { wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); - DoSetSize(-1, -1, + DoSetSize(-1, -1, width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0); } void wxTopLevelWindowGTK::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), - int width, int height ) + int width, int height ) { // due to a bug in gtk, x,y are always 0 // m_x = x; diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index bc03783404..d612844e9c 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -61,12 +61,6 @@ // globals // ---------------------------------------------------------------------------- -// all objects to be deleted during next idle processing - from window.cpp -extern wxList WXDLLEXPORT wxPendingDelete; - -// all frames and modeless dialogs - not static, used in frame.cpp, mdi.cpp &c -wxWindowList wxModelessWindows; - // all modal dialogs currently shown static wxWindowList wxModalDialogs; @@ -74,9 +68,9 @@ static wxWindowList wxModalDialogs; // wxWin macros // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) +IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) -BEGIN_EVENT_TABLE(wxDialog, wxPanel) +BEGIN_EVENT_TABLE(wxDialog, wxTopLevelWindow) EVT_BUTTON(wxID_OK, wxDialog::OnOK) EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) @@ -117,19 +111,12 @@ bool wxDialog::Create(wxWindow *parent, { Init(); - m_oldFocus = FindFocus(); - - SetName(name); + SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); - wxTopLevelWindows.Append(this); - - if ( parent ) - parent->AddChild(this); + if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) + return FALSE; - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; + m_oldFocus = FindFocus(); int x = pos.x; int y = pos.y; @@ -141,8 +128,6 @@ bool wxDialog::Create(wxWindow *parent, if (y < 0) y = wxDIALOG_DEFAULT_Y; - m_windowStyle = style; - if (width < 0) width = wxDIALOG_DEFAULT_WIDTH; if (height < 0) @@ -173,7 +158,7 @@ bool wxDialog::Create(wxWindow *parent, #ifdef __WXMICROWIN__ extern const wxChar *wxFrameClassName; - + int msflags = WS_OVERLAPPED|WS_POPUP; if (style & wxCAPTION) msflags |= WS_CAPTION; @@ -206,7 +191,7 @@ bool wxDialog::Create(wxWindow *parent, #ifndef __WXMICROWIN__ SubclassWin(GetHWND()); #endif - + SetWindowText(hwnd, title); return TRUE; @@ -240,7 +225,7 @@ bool wxDialog::EnableCloseButton(bool enable) wxLogLastError(_T("DrawMenuBar")); } #endif - + return TRUE; } @@ -264,24 +249,8 @@ wxDialog::~wxDialog() { m_isBeingDeleted = TRUE; - wxTopLevelWindows.DeleteObject(this); - // this will also reenable all the other windows for a modal dialog Show(FALSE); - - if ( !IsModal() ) - wxModelessWindows.DeleteObject(this); - - // If this is the last top-level window, exit. - if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) - { - wxTheApp->SetTopWindow(NULL); - - if ( wxTheApp->GetExitOnFrameDelete() ) - { - ::PostQuitMessage(0); - } - } } // ---------------------------------------------------------------------------- @@ -313,56 +282,6 @@ void wxDialog::OnCharHook(wxKeyEvent& event) event.Skip(); } -// ---------------------------------------------------------------------------- -// Windows dialog boxes can't be iconized -// ---------------------------------------------------------------------------- - -void wxDialog::Iconize(bool WXUNUSED(iconize)) -{ -} - -bool wxDialog::IsIconized() const -{ - return FALSE; -} - -// ---------------------------------------------------------------------------- -// size/position handling -// ---------------------------------------------------------------------------- - -void wxDialog::DoSetClientSize(int width, int height) -{ - HWND hWnd = (HWND) GetHWND(); - RECT rect; - ::GetClientRect(hWnd, &rect); - - RECT rect2; - GetWindowRect(hWnd, &rect2); - - // Find the difference between the entire window (title bar and all) - // and the client area; add this to the new client size to move the - // window - int actual_width = rect2.right - rect2.left - rect.right + width; - int actual_height = rect2.bottom - rect2.top - rect.bottom + height; - - MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE); - - wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); -} - -void wxDialog::DoGetPosition(int *x, int *y) const -{ - RECT rect; - GetWindowRect(GetHwnd(), &rect); - - if ( x ) - *x = rect.left; - if ( y ) - *y = rect.top; -} - // ---------------------------------------------------------------------------- // showing the dialogs // ---------------------------------------------------------------------------- @@ -579,17 +498,6 @@ void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) closing.DeleteObject(this); } -// Destroy the window (delayed, if a managed window) -bool wxDialog::Destroy() -{ - wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE, - _T("wxDialog destroyed twice") ); - - wxPendingDelete.Append(this); - - return TRUE; -} - void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) { #if wxUSE_CTL3D @@ -672,7 +580,7 @@ long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) rc = FALSE; } break; -#endif +#endif // __WXMICROWIN__ } if ( !processed ) diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index d766cb0992..220c15ec48 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -63,7 +63,6 @@ // globals // ---------------------------------------------------------------------------- -extern wxWindowList wxModelessWindows; extern const wxChar *wxFrameClassName; #if wxUSE_MENUS_NATIVE @@ -105,9 +104,6 @@ END_EVENT_TABLE() void wxFrameMSW::Init() { - m_iconized = - m_maximizeOnShow = FALSE; - #if wxUSE_TOOLTIPS m_hwndToolTip = 0; #endif @@ -136,68 +132,28 @@ bool wxFrameMSW::Create(wxWindow *parent, long style, const wxString& name) { - SetName(name); - m_windowStyle = style; - - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); - - if ( id > -1 ) - m_windowId = id; - else - m_windowId = (int)NewControlId(); - - if (parent) parent->AddChild(this); - - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - - m_iconized = FALSE; + if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) + return FALSE; - wxTopLevelWindows.Append(this); + // the frame must have NULL parent HWND or it would be always on top of its + // parent which is not what we usually want (in fact, we only want it for + // frames with the special wxFRAME_TOOL_WINDOW style handled elsewhere) + if ( !MSWCreate(m_windowId, NULL, wxFrameClassName, this, title, + pos.x, pos.y, size.x, size.y, style) ) + return FALSE; - // the frame must have NULL parent HWND or it would be always on top of its - // parent which is not what we usually want (in fact, we only want it for - // frames with the special wxFRAME_TOOL_WINDOW style handled elsewhere) - MSWCreate(m_windowId, NULL, wxFrameClassName, this, title, - x, y, width, height, style); + SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); - wxModelessWindows.Append(this); + wxModelessWindows.Append(this); - return TRUE; + return TRUE; } wxFrameMSW::~wxFrameMSW() { - m_isBeingDeleted = TRUE; - wxTopLevelWindows.DeleteObject(this); - - // the ~wxToolBar() code relies on the previous line to be executed before - // this one, i.e. the frame should remove itself from wxTopLevelWindows - // before destorying its toolbar - DeleteAllBars(); + m_isBeingDeleted = TRUE; - if (wxTheApp && (wxTopLevelWindows.Number() == 0)) - { - wxTheApp->SetTopWindow(NULL); - - if (wxTheApp->GetExitOnFrameDelete()) - { - PostQuitMessage(0); - } - } - - wxModelessWindows.DeleteObject(this); - - // For some reason, wxWindows can activate another task altogether - // when a frame is destroyed after a modal dialog has been invoked. - // Try to bring the parent to the top. - // MT:Only do this if this frame is currently the active window, else weird - // things start to happen - if ( wxGetActiveWindow() == this ) - if (GetParent() && GetParent()->GetHWND()) - ::BringWindowToTop((HWND) GetParent()->GetHWND()); + DeleteAllBars(); } // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. @@ -225,128 +181,24 @@ void wxFrameMSW::DoGetClientSize(int *x, int *y) const *y = rect.bottom; } -// Set the client size (i.e. leave the calculation of borders etc. -// to wxWindows) void wxFrameMSW::DoSetClientSize(int width, int height) { - HWND hWnd = GetHwnd(); - - RECT rectClient; - ::GetClientRect(hWnd, &rectClient); - - RECT rectTotal; - ::GetWindowRect(hWnd, &rectTotal); - - // Find the difference between the entire window (title bar and all) - // and the client area; add this to the new client size to move the - // window - width += rectTotal.right - rectTotal.left - rectClient.right; - height += rectTotal.bottom - rectTotal.top - rectClient.bottom; - + // leave enough space for the status bar if we have (and show) it #if wxUSE_STATUSBAR wxStatusBar *statbar = GetStatusBar(); if ( statbar && statbar->IsShown() ) { - // leave enough space for the status bar height += statbar->GetSize().y; } #endif // wxUSE_STATUSBAR - // note that this takes the toolbar into account - wxPoint pt = GetClientAreaOrigin(); - width += pt.x; - height += pt.y; - - if ( !::MoveWindow(hWnd, rectTotal.left, rectTotal.top, - width, height, TRUE /* redraw */) ) - { - wxLogLastError(_T("MoveWindow")); - } - - wxSizeEvent event(wxSize(width, height), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); -} - -void wxFrameMSW::DoGetSize(int *width, int *height) const -{ - RECT rect; - ::GetWindowRect(GetHwnd(), &rect); - - *width = rect.right - rect.left; - *height = rect.bottom - rect.top; -} - -void wxFrameMSW::DoGetPosition(int *x, int *y) const -{ - RECT rect; - ::GetWindowRect(GetHwnd(), &rect); - - *x = rect.left; - *y = rect.top; + wxTopLevelWindow::DoSetClientSize(width, height); } // ---------------------------------------------------------------------------- -// variations around ::ShowWindow() +// wxFrameMSW: various geometry-related functions // ---------------------------------------------------------------------------- -void wxFrameMSW::DoShowWindow(int nShowCmd) -{ - ::ShowWindow(GetHwnd(), nShowCmd); - - m_iconized = nShowCmd == SW_MINIMIZE; -} - -bool wxFrameMSW::Show(bool show) -{ - // don't use wxWindow version as we want to call DoShowWindow() - if ( !wxWindowBase::Show(show) ) - return FALSE; - - int nShowCmd; - if ( show ) - { - if ( m_maximizeOnShow ) - { - // show and maximize - nShowCmd = SW_MAXIMIZE; - - m_maximizeOnShow = FALSE; - } - else // just show - { - nShowCmd = SW_SHOW; - } - } - else // hide - { - nShowCmd = SW_HIDE; - } - - DoShowWindow(nShowCmd); - - if ( show ) - { - ::BringWindowToTop(GetHwnd()); - - wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } - else // hide - { - // Try to highlight the correct window (the parent) - if ( GetParent() ) - { - HWND hWndParent = GetHwndOf(GetParent()); - if (hWndParent) - ::BringWindowToTop(hWndParent); - } - } - - return TRUE; -} - void wxFrameMSW::Raise() { #ifdef __WIN16__ @@ -357,81 +209,13 @@ void wxFrameMSW::Raise() #endif // Win16/32 } -void wxFrameMSW::Iconize(bool iconize) -{ - DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); -} - -void wxFrameMSW::Maximize(bool maximize) -{ - if ( IsShown() ) - { - // just maximize it directly - DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); - } - else // hidden - { - // we can't maximize the hidden frame because it shows it as well, so - // just remember that we should do it later in this case - m_maximizeOnShow = TRUE; - } -} - -void wxFrameMSW::Restore() -{ - DoShowWindow(SW_RESTORE); -} - -bool wxFrameMSW::IsIconized() const -{ -#ifdef __WXMICROWIN__ - // TODO - return FALSE; -#else - ((wxFrameMSW *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0); - return m_iconized; -#endif -} - -// Is it maximized? -bool wxFrameMSW::IsMaximized() const -{ -#ifdef __WXMICROWIN__ - // TODO - return FALSE; -#else - return (::IsZoomed(GetHwnd()) != 0); -#endif -} - -void wxFrameMSW::SetIcon(const wxIcon& icon) -{ - wxFrameBase::SetIcon(icon); - -#if defined(__WIN95__) && !defined(__WXMICROWIN__) - if ( m_icon.Ok() ) - { - SendMessage(GetHwnd(), WM_SETICON, - (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON()); - } -#endif // __WIN95__ -} - // generate an artificial resize event void wxFrameMSW::SendSizeEvent() { - RECT r; -#ifdef __WIN16__ - ::GetWindowRect(GetHwnd(), &r); -#else - if ( !::GetWindowRect(GetHwnd(), &r) ) - { - wxLogLastError(_T("GetWindowRect")); - } -#endif - if ( !m_iconized ) { + RECT r = wxGetWindowRect(GetHwnd()); + (void)::PostMessage(GetHwnd(), WM_SIZE, IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, MAKELPARAM(r.right - r.left, r.bottom - r.top)); @@ -622,13 +406,12 @@ bool wxFrameMSW::ShowFullScreen(bool show, long style) newStyle &= (~offFlags); // change our window style to be compatible with full-screen mode - SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); + ::SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); // resize to the size of the desktop int width, height; - RECT rect; - ::GetWindowRect(GetDesktopWindow(), &rect); + RECT rect = wxGetWindowRect(::GetDesktopWindow()); width = rect.right - rect.left; height = rect.bottom - rect.top; @@ -695,8 +478,6 @@ bool wxFrameMSW::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWin int x, int y, int width, int height, long style) { - m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); - // If child windows aren't properly drawn initially, WS_CLIPCHILDREN // could be the culprit. But without it, you can get a lot of flicker. @@ -919,6 +700,12 @@ void wxFrameMSW::IconizeChildFrames(bool bIconize) } } +WXHICON wxFrameMSW::GetDefaultIcon() const +{ + return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON + : wxDEFAULT_FRAME_ICON); +} + // =========================================================================== // message processing // =========================================================================== @@ -958,7 +745,7 @@ bool wxFrameMSW::HandlePaint() if ( m_iconized ) { HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) - : (HICON)m_defaultIcon; + : (HICON)GetDefaultIcon(); // Hold a pointer to the dc so long as the OnPaint() message // is being processed @@ -1171,7 +958,7 @@ long wxFrameMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) case WM_QUERYDRAGICON: { HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) - : (HICON)(m_defaultIcon); + : (HICON)GetDefaultIcon(); rc = (long)hIcon; processed = rc != 0; } diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index 5869306dda..c71a0a8d37 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -163,10 +163,6 @@ bool wxMDIParentFrame::Create(wxWindow *parent, long style, const wxString& name) { - m_defaultIcon = (WXHICON) (wxSTD_MDIPARENTFRAME_ICON - ? wxSTD_MDIPARENTFRAME_ICON - : wxDEFAULT_MDIPARENTFRAME_ICON); - m_clientWindow = NULL; m_currentChild = NULL; @@ -349,6 +345,12 @@ void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) event.Skip(); } +WXHICON wxMDIParentFrame::GetDefaultIcon() const +{ + return (WXHICON)(wxSTD_MDIPARENTFRAME_ICON ? wxSTD_MDIPARENTFRAME_ICON + : wxDEFAULT_MDIPARENTFRAME_ICON); +} + // --------------------------------------------------------------------------- // MDI operations // --------------------------------------------------------------------------- @@ -647,9 +649,6 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, long style, const wxString& name) { - m_defaultIcon = (WXHICON)(wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON - : wxDEFAULT_MDICHILDFRAME_ICON); - SetName(name); wxWindowBase::Show(TRUE); // MDI child frame starts off shown @@ -814,6 +813,12 @@ void wxMDIChildFrame::InternalSetMenuBar() parent->m_parentFrameActive = FALSE; } +WXHICON wxMDIChildFrame::GetDefaultIcon() const +{ + return (WXHICON)(wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON + : wxDEFAULT_MDICHILDFRAME_ICON); +} + // --------------------------------------------------------------------------- // MDI operations // --------------------------------------------------------------------------- diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 1464a65e84..9bbd2d4ce1 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -866,20 +866,24 @@ wxSize wxToolBar::GetToolSize() const } } -static wxToolBarToolBase *GetItemSkippingDummySpacers( const wxToolBarToolsList& tools, size_t index ) +static +wxToolBarToolBase *GetItemSkippingDummySpacers(const wxToolBarToolsList& tools, + size_t index ) { wxToolBarToolsList::Node* current = tools.GetFirst(); - for( ; current != 0; current = current->GetNext() ) + for ( ; current != 0; current = current->GetNext() ) { - if( index == 0 ) + if ( index == 0 ) return current->GetData(); - size_t separators = ((wxToolBarTool*)current->GetData())->GetSeparatorsCount(); - // if it is a normal button, sepcount == 0, so skip 1 - // item ( the button ) - // otherwise, skip as many items as the separator count, - // plus the control itself - index -= separators ? separators + 1: 1; + + wxToolBarTool *tool = (wxToolBarTool *)current->GetData(); + size_t separators = tool->GetSeparatorsCount(); + + // if it is a normal button, sepcount == 0, so skip 1 item (the button) + // otherwise, skip as many items as the separator count, plus the + // control itself + index -= separators ? separators + 1 : 1; } return 0; @@ -897,20 +901,17 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const return (wxToolBarToolBase *)NULL; } - // if comctl32 version < 4.71 - // wxToolBar95 adds dummy spacers + // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 ) if ( wxTheApp->GetComCtl32Version() >= 471 ) { return m_tools.Item((size_t)index)->GetData(); } else +#endif { return GetItemSkippingDummySpacers( m_tools, (size_t) index ); } -#else - return GetItemSkippingDummySpacers( m_tools, (size_t) index ); -#endif } void wxToolBar::UpdateSize() diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp new file mode 100644 index 0000000000..4af6483229 --- /dev/null +++ b/src/msw/toplevel.cpp @@ -0,0 +1,270 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: msw/toplevel.cpp +// Purpose: implements wxTopLevelWindow for MSW +// Author: Vadim Zeitlin +// Modified by: +// Created: 24.09.01 +// RCS-ID: $Id$ +// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) +// License: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "toplevel.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/log.h" + #include "wx/intl.h" +#endif //WX_PRECOMP + +#include "wx/msw/private.h" + +// ---------------------------------------------------------------------------- +// stubs for missing functions under MicroWindows +// ---------------------------------------------------------------------------- + +#ifdef __WXMICROWIN__ + +static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; } +static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; } + +#endif // __WXMICROWIN__ + +// ---------------------------------------------------------------------------- +// globals +// ---------------------------------------------------------------------------- + +// list of all frames and modeless dialogs +wxWindowList wxModelessWindows; + +// ============================================================================ +// wxTopLevelWindowMSW implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxTopLevelWindowMSW creation +// ---------------------------------------------------------------------------- + +void wxTopLevelWindowMSW::Init() +{ + m_iconized = + m_maximizeOnShow = FALSE; +} + +bool wxTopLevelWindowMSW::Create(wxWindow *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) +{ + // init our fields + Init(); + + m_windowStyle = style; + + SetName(name); + + m_windowId = id == -1 ? NewControlId() : id; + + wxTopLevelWindows.Append(this); + + if ( parent ) + parent->AddChild(this); + + return TRUE; +} + +wxTopLevelWindowMSW::~wxTopLevelWindowMSW() +{ + wxTopLevelWindows.DeleteObject(this); + + if ( wxModelessWindows.Find(this) ) + wxModelessWindows.DeleteObject(this); + + // If this is the last top-level window, exit. + if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) + { + wxTheApp->SetTopWindow(NULL); + + if ( wxTheApp->GetExitOnFrameDelete() ) + { + ::PostQuitMessage(0); + } + } +} + +// ---------------------------------------------------------------------------- +// wxTopLevelWindowMSW geometry +// ---------------------------------------------------------------------------- + +void wxTopLevelWindowMSW::DoSetClientSize(int width, int height) +{ + HWND hWnd = GetHwnd(); + + RECT rectClient; + ::GetClientRect(hWnd, &rectClient); + + RECT rectTotal; + ::GetWindowRect(hWnd, &rectTotal); + + // Find the difference between the entire window (title bar and all) + // and the client area; add this to the new client size to move the + // window + width += rectTotal.right - rectTotal.left - rectClient.right; + height += rectTotal.bottom - rectTotal.top - rectClient.bottom; + + // note that calling GetClientAreaOrigin() takes the toolbar into account + wxPoint pt = GetClientAreaOrigin(); + width += pt.x; + height += pt.y; + + if ( !::MoveWindow(hWnd, rectTotal.left, rectTotal.top, + width, height, TRUE /* redraw */) ) + { + wxLogLastError(_T("MoveWindow")); + } + + wxSizeEvent event(wxSize(width, height), m_windowId); + event.SetEventObject(this); + (void)GetEventHandler()->ProcessEvent(event); +} + +// ---------------------------------------------------------------------------- +// wxTopLevelWindowMSW showing +// ---------------------------------------------------------------------------- + +void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd) +{ + ::ShowWindow(GetHwnd(), nShowCmd); + + m_iconized = nShowCmd == SW_MINIMIZE; +} + +bool wxTopLevelWindowMSW::Show(bool show) +{ + // don't use wxWindow version as we want to call DoShowWindow() ourselves + if ( !wxWindowBase::Show(show) ) + return FALSE; + + int nShowCmd; + if ( show ) + { + if ( m_maximizeOnShow ) + { + // show and maximize + nShowCmd = SW_MAXIMIZE; + + m_maximizeOnShow = FALSE; + } + else // just show + { + nShowCmd = SW_SHOW; + } + } + else // hide + { + nShowCmd = SW_HIDE; + } + + DoShowWindow(nShowCmd); + + if ( show ) + { + ::BringWindowToTop(GetHwnd()); + + wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } + else // hide + { + // Try to highlight the correct window (the parent) + if ( GetParent() ) + { + HWND hWndParent = GetHwndOf(GetParent()); + if (hWndParent) + ::BringWindowToTop(hWndParent); + } + } + + return TRUE; +} + +// ---------------------------------------------------------------------------- +// wxTopLevelWindowMSW maximize/minimize +// ---------------------------------------------------------------------------- + +void wxTopLevelWindowMSW::Maximize(bool maximize) +{ + if ( IsShown() ) + { + // just maximize it directly + DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); + } + else // hidden + { + // we can't maximize the hidden frame because it shows it as well, so + // just remember that we should do it later in this case + m_maximizeOnShow = TRUE; + } +} + +bool wxTopLevelWindowMSW::IsMaximized() const +{ + return ::IsZoomed(GetHwnd()) != 0; +} + +void wxTopLevelWindowMSW::Iconize(bool iconize) +{ + DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); +} + +bool wxTopLevelWindowMSW::IsIconized() const +{ + // also update the current state + ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0; + + return m_iconized; +} + +void wxTopLevelWindowMSW::Restore() +{ + DoShowWindow(SW_RESTORE); +} + +// ---------------------------------------------------------------------------- +// wxTopLevelWindowMSW misc +// ---------------------------------------------------------------------------- + +void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon) +{ + // this sets m_icon + wxTopLevelWindowBase::SetIcon(icon); + +#if defined(__WIN95__) && !defined(__WXMICROWIN__) + if ( m_icon.Ok() ) + { + ::SendMessage(GetHwnd(), WM_SETICON, + (WPARAM)TRUE, (LPARAM)GetHiconOf(m_icon)); + } +#endif // __WIN95__ +} diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 59e4c2a5f1..5eb41c8715 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -608,8 +608,7 @@ bool wxWindowMSW::SetCursor(const wxCursor& cursor) POINT point; ::GetCursorPos(&point); - RECT rect; - ::GetWindowRect(hWnd, &rect); + RECT rect = wxGetWindowRect(hWnd); if ( ::PtInRect(&rect, point) && !wxIsBusy() ) ::SetCursor(GetHcursorOf(m_cursor)); @@ -1184,11 +1183,7 @@ void wxWindowMSW::OnIdle(wxIdleEvent& WXUNUSED(event)) // we need to have client coordinates here for symmetry with // wxEVT_ENTER_WINDOW - RECT rect; - if ( !::GetWindowRect(GetHwnd(), &rect) ) - { - wxLogLastError(_T("GetWindowRect")); - } + RECT rect = wxGetWindowRect(GetHwnd()); pt.x -= rect.left; pt.y -= rect.top; @@ -1329,28 +1324,28 @@ void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip) // Get total size void wxWindowMSW::DoGetSize(int *x, int *y) const { - HWND hWnd = GetHwnd(); - RECT rect; -#ifdef __WIN16__ - ::GetWindowRect(hWnd, &rect); -#else - if ( !::GetWindowRect(hWnd, &rect) ) - { - wxLogLastError(_T("GetWindowRect")); - } -#endif + RECT rect = wxGetWindowRect(GetHwnd()); + if ( x ) *x = rect.right - rect.left; if ( y ) *y = rect.bottom - rect.top; } -void wxWindowMSW::DoGetPosition(int *x, int *y) const +// Get size *available for subwindows* i.e. excluding menu bar etc. +void wxWindowMSW::DoGetClientSize(int *x, int *y) const { - HWND hWnd = GetHwnd(); + RECT rect = wxGetClientRect(GetHwnd()); - RECT rect; - GetWindowRect(hWnd, &rect); + if ( x ) + *x = rect.right; + if ( y ) + *y = rect.bottom; +} + +void wxWindowMSW::DoGetPosition(int *x, int *y) const +{ + RECT rect = wxGetWindowRect(GetHwnd()); POINT point; point.x = rect.left; @@ -1396,8 +1391,7 @@ void wxWindowMSW::DoScreenToClient(int *x, int *y) const if ( y ) pt.y = *y; - HWND hWnd = GetHwnd(); - ::ScreenToClient(hWnd, &pt); + ::ScreenToClient(GetHwnd(), &pt); if ( x ) *x = pt.x; @@ -1413,8 +1407,7 @@ void wxWindowMSW::DoClientToScreen(int *x, int *y) const if ( y ) pt.y = *y; - HWND hWnd = GetHwnd(); - ::ClientToScreen(hWnd, &pt); + ::ClientToScreen(GetHwnd(), &pt); if ( x ) *x = pt.x; @@ -1422,18 +1415,6 @@ void wxWindowMSW::DoClientToScreen(int *x, int *y) const *y = pt.y; } -// Get size *available for subwindows* i.e. excluding menu bar etc. -void wxWindowMSW::DoGetClientSize(int *x, int *y) const -{ - HWND hWnd = GetHwnd(); - RECT rect; - ::GetClientRect(hWnd, &rect); - if ( x ) - *x = rect.right; - if ( y ) - *y = rect.bottom; -} - void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) { if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) ) diff --git a/src/univ/topluniv.cpp b/src/univ/topluniv.cpp index b592cbf6ab..f0760588dc 100644 --- a/src/univ/topluniv.cpp +++ b/src/univ/topluniv.cpp @@ -37,8 +37,6 @@ // event tables // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow) - BEGIN_EVENT_TABLE(wxTopLevelWindow, wxTopLevelWindowNative) EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint) END_EVENT_TABLE() -- 2.45.2