added wxTLW for MSW

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-09-24 00:34:14 +00:00
parent c2fd78b10f
commit 82c9f85ce5
20 changed files with 592 additions and 509 deletions

View File

@@ -30,7 +30,7 @@ class WXDLLEXPORT wxDialogBase : public wxTopLevelWindow
{
public:
wxDialogBase() { Init(); }
~wxDialogBase() {}
virtual ~wxDialogBase() { }
void Init();
@@ -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
};

View File

@@ -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();

View File

@@ -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;

View File

@@ -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();

View File

@@ -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
// ---------------------------------------------------------------------------

87
include/wx/msw/toplevel.h Normal file
View File

@@ -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_

View File

@@ -52,9 +52,6 @@ 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__)

View File

@@ -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;
}
}

View File

@@ -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());
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);
}

View File

@@ -60,10 +60,7 @@ wxDialog::wxDialog( wxWindow *parent,
{
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) )

View File

@@ -50,10 +50,6 @@ extern int g_openDialogs;
// event tables
// ----------------------------------------------------------------------------
#ifndef __WXUNIVERSAL__
IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
#endif
// ----------------------------------------------------------------------------
// data
// ----------------------------------------------------------------------------

View File

@@ -60,10 +60,7 @@ wxDialog::wxDialog( wxWindow *parent,
{
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) )

View File

@@ -50,10 +50,6 @@ extern int g_openDialogs;
// event tables
// ----------------------------------------------------------------------------
#ifndef __WXUNIVERSAL__
IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
#endif
// ----------------------------------------------------------------------------
// data
// ----------------------------------------------------------------------------

View File

@@ -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,20 +111,13 @@ bool wxDialog::Create(wxWindow *parent,
{
Init();
SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
m_oldFocus = FindFocus();
SetName(name);
wxTopLevelWindows.Append(this);
if ( parent )
parent->AddChild(this);
if ( id == -1 )
m_windowId = (int)NewControlId();
else
m_windowId = id;
int x = pos.x;
int y = pos.y;
int width = size.x;
@@ -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)
@@ -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 )

View File

@@ -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,32 +132,17 @@ 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;
wxTopLevelWindows.Append(this);
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
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);
if ( !MSWCreate(m_windowId, NULL, wxFrameClassName, this, title,
pos.x, pos.y, size.x, size.y, style) )
return FALSE;
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
wxModelessWindows.Append(this);
@@ -171,33 +152,8 @@ bool wxFrameMSW::Create(wxWindow *parent,
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();
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());
}
// 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;
}

View File

@@ -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
// ---------------------------------------------------------------------------

View File

@@ -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()

270
src/msw/toplevel.cpp Normal file
View File

@@ -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__
}

View File

@@ -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;
}
// Get size *available for subwindows* i.e. excluding menu bar etc.
void wxWindowMSW::DoGetClientSize(int *x, int *y) const
{
RECT rect = wxGetClientRect(GetHwnd());
if ( x )
*x = rect.right;
if ( y )
*y = rect.bottom;
}
void wxWindowMSW::DoGetPosition(int *x, int *y) const
{
HWND hWnd = GetHwnd();
RECT rect;
GetWindowRect(hWnd, &rect);
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) )

View File

@@ -37,8 +37,6 @@
// event tables
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
BEGIN_EVENT_TABLE(wxTopLevelWindow, wxTopLevelWindowNative)
EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint)
END_EVENT_TABLE()