Remembering a wxWindow's position and state Re: GetScreenPosition
and iconize
Volker Bartheld
dr_versaeg at freenet.de
Mon Apr 2 06:26:48 PDT 2007
Hi Vadim!
>> VB> Unfortunately, with wxMSW 2.8.0 the window's context menu still shows
>> VB> the options related to a restored window even if it came up minimized
>> VB> to the taskbar.
>> I don't see with the minimal sample: when it's minimized, the window menu
>> shows only "Restore" and "Maximize", the other items are disabled as
>> expected.
> I'll take a look at the differences to my app and then report back. THX &
> have a nice evening!
The culprit was, that I capture EVT_MOVE in my child windows and forward
the event to the parent with
void PassphrasePopup::OnMove(wxMoveEvent& e)
{
GetParent()->AddPendingEvent(e);
}
This parent then remembers all enabled/maximized/iconized/shown state
variabled, no matter whether the child window was minimized or not. When
restoring those states for new windows, the position held an invalid value
that wxWindow::GetPosition() returned. I fixed it so that a position is
only stored when the window is in "normal" state.
This is the code which works for me quite well (it doesn't use the
Win32-native ::GetWindowPlacement()-function that was mentioned in the
thread starting with Message-ID:
<1170665503.811775.234390 at a75g2000cwd.googlegroups.com>):
class PopupWindowState
{
public:
PopupWindowState() : m_bEmpty(true), m_Position(wxDefaultPosition),
m_bShown(true), m_bEnabled(true), m_bIconized(false), m_bMaximized(false)
{}
PopupWindowState(const wxWindow* pWin) { Read(pWin); }
PopupWindowState(const wxTopLevelWindow* pWin) { Read(pWin); }
bool Empty() { return m_bEmpty; }
wxPoint Position() { return m_Position; }
void Read(const wxWindow* pWin)
{
m_Position=pWin->GetPosition();
m_bShown=pWin->IsShown();
m_bEnabled=pWin->IsEnabled();
m_bEmpty=false;
}
void Read(const wxTopLevelWindow* pWin)
{
m_bShown=pWin->IsShown();
m_bEnabled=pWin->IsEnabled();
m_bIconized=pWin->IsIconized();
m_bMaximized=pWin->IsMaximized();
if(!m_bIconized && !m_bMaximized && m_bEnabled && m_bShown)
m_Position=pWin->GetPosition();
m_bEmpty=false;
}
const void Write(wxWindow* pWin) const
{
pWin->Enable(m_bEnabled);
if(m_bShown) pWin->SetPosition(m_Position);
pWin->Show(m_bShown);
}
const void Write(wxTopLevelWindow* pWin) const
{
pWin->Enable(m_bEnabled);
if(m_bIconized) pWin->Iconize(m_bIconized);
else if(m_bMaximized) pWin->Maximize(m_bMaximized);
else if(m_bShown) pWin->SetPosition(m_Position);
pWin->Show(m_bShown);
}
const void Save(wxFileConfig* pCfg) const
{
pCfg->Write(wxT("PX"), m_Position.x);
pCfg->Write(wxT("PY"), m_Position.y);
pCfg->Write(wxT("IsShown"), m_bShown);
pCfg->Write(wxT("IsEnabled"), m_bEnabled);
pCfg->Write(wxT("IsIconized"), m_bIconized);
pCfg->Write(wxT("IsMaximized"), m_bMaximized);
}
void Load(wxFileConfig* pCfg)
{
pCfg->Read(wxT("PX"), &m_Position.x);
pCfg->Read(wxT("PY"), &m_Position.y);
pCfg->Read(wxT("IsShown"), &m_bShown, true);
pCfg->Read(wxT("IsEnabled"), &m_bEnabled, true);
pCfg->Read(wxT("IsIconized"), &m_bIconized, false);
pCfg->Read(wxT("IsMaximized"), &m_bMaximized, false);
}
protected:
bool m_bEmpty;
wxPoint m_Position;
bool m_bShown, m_bEnabled, m_bIconized, m_bMaximized;
};
Cheers & HTH,
Volker
--
mailto: V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list