Merge branch 'msw-tlw-state'

Fix showing TLWs under MSW when restoring their geometry.

See https://github.com/wxWidgets/wxWidgets/pull/842
This commit is contained in:
Vadim Zeitlin
2018-06-22 19:46:44 +02:00
6 changed files with 101 additions and 64 deletions

View File

@@ -77,12 +77,20 @@ public:
wxCopyRectToRECT(r, m_placement.rcNormalPosition);
// Maximized/minimized state.
//
// Note the special case of SW_MINIMIZE: while GetWindowPlacement()
// returns SW_SHOWMINIMIZED when the window is iconized, we restore it
// as SW_MINIMIZE as this is what the code in wxTLW checks to determine
// whether the window is supposed to be iconized or not.
//
// Just to confuse matters further, note that SW_MAXIMIZE is exactly
// the same thing as SW_SHOWMAXIMIZED.
int tmp;
UINT& show = m_placement.showCmd;
if ( ser.RestoreField(wxPERSIST_TLW_MAXIMIZED, &tmp) && tmp )
show = SW_SHOWMAXIMIZED;
show = SW_MAXIMIZE;
else if ( ser.RestoreField(wxPERSIST_TLW_ICONIZED, &tmp) && tmp )
show = SW_SHOWMINIMIZED;
show = SW_MINIMIZE;
else
show = SW_SHOWNORMAL;
@@ -110,6 +118,18 @@ public:
virtual bool ApplyTo(wxTopLevelWindow* tlw) wxOVERRIDE
{
// There is a subtlety here: if the window is currently hidden,
// restoring its geometry shouldn't show it, so we must use SW_HIDE as
// show command, but showing it later should restore it to the correct
// state, so we need to remember it in wxTLW itself. And even if it's
// currently shown, we still need to update its show command, so that
// it matches the real window state after SetWindowPlacement() call.
tlw->MSWSetShowCommand(m_placement.showCmd);
if ( !tlw->IsShown() )
{
m_placement.showCmd = SW_HIDE;
}
if ( !::SetWindowPlacement(GetHwndOf(tlw), &m_placement) )
{
wxLogLastError(wxS("SetWindowPlacement"));

View File

@@ -116,6 +116,9 @@ public:
// returns true if the platform should explicitly apply a theme border
virtual bool CanApplyThemeBorder() const wxOVERRIDE { return false; }
// This function is only for internal use.
void MSWSetShowCommand(WXUINT showCmd) { m_showCmd = showCmd; }
protected:
// common part of all ctors
void Init();
@@ -132,9 +135,12 @@ protected:
const wxPoint& pos,
const wxSize& size);
// common part of Iconize(), Maximize() and Restore()
// Just a wrapper around MSW ShowWindow().
void DoShowWindow(int nShowCmd);
// Return true if the window is iconized at MSW level, ignoring m_showCmd.
bool MSWIsIconized() const;
// override those to return the normal window coordinates even when the
// window is minimized
virtual void DoGetPosition(int *x, int *y) const wxOVERRIDE;
@@ -156,13 +162,11 @@ protected:
int& x, int& y,
int& w, int& h) const wxOVERRIDE;
// is the window 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;
// This field contains the show command to use when showing the window the
// next time and also indicates whether the window should be considered
// being iconized or maximized (which may be different from whether it's
// actually iconized or maximized at MSW level).
WXUINT m_showCmd;
// Data to save/restore when calling ShowFullScreen
long m_fsStyle; // Passed to ShowFullScreen