[dasher: 193/217] Use the same set of options to remember window position and size bor linux and win
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 193/217] Use the same set of options to remember window position and size bor linux and win
- Date: Sat, 27 Feb 2016 12:16:33 +0000 (UTC)
commit f35b471480d9e7e30cbe7f32b3b8a2bf5a71a3e0
Author: Ada Majorek <amajorek google com>
Date: Sun Jan 24 21:33:02 2016 -0800
Use the same set of options to remember window position and size bor linux and win
fixes https://github.com/ipomoena/dasher/issues/67
Src/Common/AppSettingsData.h | 2 +-
Src/Common/AppSettingsHeader.h | 3 +-
Src/Win32/AppSettings.cpp | 36 -----------------
Src/Win32/AppSettings.h | 3 -
Src/Win32/DasherWindow.cpp | 86 +++++++++++++++++++++++----------------
Src/Win32/DasherWindow.h | 9 ++--
6 files changed, 57 insertions(+), 82 deletions(-)
---
diff --git a/Src/Common/AppSettingsData.h b/Src/Common/AppSettingsData.h
index bc15cfa..5beddc2 100644
--- a/Src/Common/AppSettingsData.h
+++ b/Src/Common/AppSettingsData.h
@@ -33,6 +33,7 @@ Dasher::Settings::bp_table app_boolparamtable[] = {
{ APP_BP_SHOW_STATUSBAR, "ViewStatusbar", Persistence::PERSISTENT, true, "ViewStatusbar" },
#endif
{ APP_BP_MIRROR_LAYOUT, "MirrorLayout", Persistence::PERSISTENT, false, "MirrorLayout" },
+{ APP_BP_FULL_SCREEN, "FullScreen", Persistence::PERSISTENT, false, "FullScreen" },
};
Dasher::Settings::lp_table app_longparamtable[] = {
@@ -56,5 +57,4 @@ Dasher::Settings::sp_table app_stringparamtable[] = {
{APP_SP_EDIT_FONT, "EditFont", Persistence::PERSISTENT, "Sans 10", "EditFont"},
#endif
{ APP_SP_TOOLBAR_ID, "ToolbarID", Persistence::PERSISTENT, "", "ToolbarID" },
-{APP_SP_WINDOW_STATE, "WindowState", Persistence::PERSISTENT, "", "WindowState"},
};
diff --git a/Src/Common/AppSettingsHeader.h b/Src/Common/AppSettingsHeader.h
index e416465..bde7e7e 100644
--- a/Src/Common/AppSettingsHeader.h
+++ b/Src/Common/AppSettingsHeader.h
@@ -8,7 +8,7 @@
enum {
APP_BP_TIME_STAMP = END_OF_SPS, APP_BP_CONFIRM_UNSAVED, APP_BP_SHOW_TOOLBAR,
- APP_BP_SHOW_STATUSBAR, APP_BP_MIRROR_LAYOUT, END_OF_APP_BPS
+ APP_BP_SHOW_STATUSBAR, APP_BP_MIRROR_LAYOUT, APP_BP_FULL_SCREEN, END_OF_APP_BPS
};
enum {
@@ -25,7 +25,6 @@ enum {
enum {
APP_SP_EDIT_FONT = END_OF_APP_LPS,
APP_SP_TOOLBAR_ID,
- APP_SP_WINDOW_STATE, // TODO Use the same settings as linux.
END_OF_APP_SPS
};
diff --git a/Src/Win32/AppSettings.cpp b/Src/Win32/AppSettings.cpp
index 2c1fdbd..9fbc6d2 100644
--- a/Src/Win32/AppSettings.cpp
+++ b/Src/Win32/AppSettings.cpp
@@ -61,39 +61,3 @@ void CAppSettings::GetPermittedValues(int iParameter, vector<string> &vList) {
DASHER_ASSERT(m_pDasher != NULL);
m_pDasher->GetPermittedValues(iParameter,vList);
}
-
-static const char FormatWindowPlacement[] = "%u,%u,%d,%d,%d,%d,%d,%d,%d,%d";
-
-/////////////////////////////////////////////////////////////////////////////
-
-void CAppSettings::SaveWindowPlacement(int iParameter, const LPWINDOWPLACEMENT pwp) {
- DASHER_ASSERT(pwp != NULL);
-
- char t[200];
- sprintf_s(t, sizeof(t), FormatWindowPlacement, pwp->flags, pwp->showCmd, pwp->ptMinPosition.x,
pwp->ptMinPosition.y, pwp->ptMaxPosition.x, pwp->ptMaxPosition.y, pwp->rcNormalPosition.left,
pwp->rcNormalPosition.top, pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
- SetStringParameter(iParameter, t);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-
-bool CAppSettings::LoadWindowPlacement(int iParameter, LPWINDOWPLACEMENT pwp) {
- DASHER_ASSERT(pwp != NULL);
-
- auto str = GetStringParameter(iParameter);
- if (str.empty())
- return false;
-
- WINDOWPLACEMENT wp;
- int nRead = sscanf_s(str.c_str(), FormatWindowPlacement,
- &wp.flags, &wp.showCmd,
- &wp.ptMinPosition.x, &wp.ptMinPosition.y,
- &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
- &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
- &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
-
- if(nRead < 10)
- return false;
- wp.length = sizeof(wp);
- *pwp = wp;
- return true;
-}
diff --git a/Src/Win32/AppSettings.h b/Src/Win32/AppSettings.h
index d35c9a5..6f7a7e9 100644
--- a/Src/Win32/AppSettings.h
+++ b/Src/Win32/AppSettings.h
@@ -49,9 +49,6 @@ public:
void ResetParamater(int iParameter);
void GetPermittedValues(int iParameter, std::vector<std::string> &vList);
- bool LoadWindowPlacement(int iParameter, LPWINDOWPLACEMENT pwp);
- void SaveWindowPlacement(int iParameter, const LPWINDOWPLACEMENT pwp);
-
void SetHwnd(HWND hWnd) {
m_hWnd = hWnd;
diff --git a/Src/Win32/DasherWindow.cpp b/Src/Win32/DasherWindow.cpp
index 969c9e7..1c54c35 100644
--- a/Src/Win32/DasherWindow.cpp
+++ b/Src/Win32/DasherWindow.cpp
@@ -145,27 +145,20 @@ CDasherWindow::~CDasherWindow() {
}
void CDasherWindow::Show(int nCmdShow) {
- if (!LoadWindowState())
- ShowWindow(nCmdShow);
-}
-
-void CDasherWindow::SaveWindowState() const {
- WINDOWPLACEMENT wp;
- wp.length = sizeof(WINDOWPLACEMENT);
-
- if (GetWindowPlacement(&wp)) {//function call succeeds
- m_pAppSettings->SaveWindowPlacement(APP_SP_WINDOW_STATE, &wp);
- }
-}
-bool CDasherWindow::LoadWindowState() {
- WINDOWPLACEMENT wp;
+ RECT r = {
+ m_pAppSettings->GetLongParameter(APP_LP_X),
+ m_pAppSettings->GetLongParameter(APP_LP_Y),
+ m_pAppSettings->GetLongParameter(APP_LP_SCREEN_WIDTH),
+ m_pAppSettings->GetLongParameter(APP_LP_SCREEN_HEIGHT),
+ };
+ r.bottom += r.top;
+ r.right += r.left;
+ MoveWindow(&r, false);
m_bSizeRestored = true;
- if (m_pAppSettings->LoadWindowPlacement(APP_SP_WINDOW_STATE, &wp)) {
- if (SetWindowPlacement(&wp))
- return true;
- }
- return false;
+ if (m_pAppSettings->GetBoolParameter(APP_BP_FULL_SCREEN))
+ nCmdShow = SW_MAXIMIZE;
+ ShowWindow(nCmdShow);
}
void CDasherWindow::HandleParameterChange(int iParameter) {
@@ -344,7 +337,6 @@ LRESULT CDasherWindow::OnInitMenuPopup(UINT message, WPARAM wParam, LPARAM lPara
LRESULT CDasherWindow::OnClose(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
if (m_pEdit->ConfirmAndSaveIfNeeded()) {
- SaveWindowState();
DestroyWindow();
}
return 0;
@@ -444,10 +436,10 @@ void CDasherWindow::Layout() {
default:
int SplitterHeight = m_pSplitter->GetHeight();
int EditHeight = m_pAppSettings->GetLongParameter(APP_LP_EDIT_SIZE);
-
+
if (mirrorLayout)
{
- if (m_pSplitter->IsSizing())
+ if (m_pSplitter->IsSizing())
EditHeight = CanvasY + CanvasHeight - SplitterHeight - m_pSplitter->GetPos();
int SplitterY = CanvasY + CanvasHeight - SplitterHeight - EditHeight;
SplitterY = min(SplitterY, CanvasY + CanvasHeight - GetMinEditHeight() - SplitterHeight);
@@ -455,25 +447,49 @@ void CDasherWindow::Layout() {
EditHeight = CanvasY + CanvasHeight - SplitterY - SplitterHeight;
m_pDasher->Move(0, CanvasY, Width, SplitterY - CanvasY);
m_pSplitter->Move(SplitterY, Width);
- m_pEdit->Move(0,SplitterY + SplitterHeight, Width, EditHeight);
- } else {
- if (m_pSplitter->IsSizing())
- EditHeight = m_pSplitter->GetPos() - CanvasY;
- int SplitterY = CanvasY + EditHeight;
- SplitterY = min(SplitterY, CanvasY + CanvasHeight - GetMinCanvasHeight() - SplitterHeight);
- SplitterY = max(CanvasY + GetMinEditHeight(), SplitterY);
- EditHeight = SplitterY - CanvasY;
- m_pDasher->Move(0, SplitterY + SplitterHeight, Width, CanvasHeight - SplitterY - SplitterHeight);
- m_pEdit->Move(0, CanvasY, Width, EditHeight);
- m_pSplitter->Move(SplitterY, Width);
- }
- m_pEdit->ShowWindow(SW_SHOW);
+ m_pEdit->Move(0, SplitterY + SplitterHeight, Width, EditHeight);
+ }
+ else {
+ if (m_pSplitter->IsSizing())
+ EditHeight = m_pSplitter->GetPos() - CanvasY;
+ int SplitterY = CanvasY + EditHeight;
+ SplitterY = min(SplitterY, CanvasY + CanvasHeight - GetMinCanvasHeight() - SplitterHeight);
+ SplitterY = max(CanvasY + GetMinEditHeight(), SplitterY);
+ EditHeight = SplitterY - CanvasY;
+ m_pDasher->Move(0, SplitterY + SplitterHeight, Width, CanvasHeight - SplitterY - SplitterHeight);
+ m_pEdit->Move(0, CanvasY, Width, EditHeight);
+ m_pSplitter->Move(SplitterY, Width);
+ }
+ m_pEdit->ShowWindow(SW_SHOW);
m_pSplitter->ShowWindow(SW_SHOW);
if (m_bSizeRestored)
m_pAppSettings->SetLongParameter(APP_LP_EDIT_SIZE, EditHeight);
}
}
+LRESULT CDasherWindow::OnWindowPosChanged(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+ if (m_bSizeRestored) {
+ // Save window state
+ WINDOWPLACEMENT wp;
+ wp.length = sizeof(wp);
+ if (GetWindowPlacement(&wp)) {
+ bool normal = wp.showCmd != SW_SHOWMAXIMIZED && wp.showCmd != SW_SHOWMINIMIZED;
+ if (normal)
+ {
+ LPWINDOWPOS pwp = (LPWINDOWPOS)lParam;
+ m_pAppSettings->SetLongParameter(APP_LP_X, pwp->x);
+ m_pAppSettings->SetLongParameter(APP_LP_Y,pwp->y);
+ m_pAppSettings->SetLongParameter(APP_LP_SCREEN_WIDTH, pwp->cx);
+ m_pAppSettings->SetLongParameter(APP_LP_SCREEN_HEIGHT, pwp->cy);
+ }
+ m_pAppSettings->SetBoolParameter(APP_BP_FULL_SCREEN, wp.showCmd == SW_SHOWMAXIMIZED);
+ }
+ }
+ bHandled = false;
+ return 1;
+}
+
void CDasherWindow::HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG
idChild, DWORD dwEventThread, DWORD dwmsEventTime) {
if (!m_bFullyCreated)
return;
diff --git a/Src/Win32/DasherWindow.h b/Src/Win32/DasherWindow.h
index d6411a8..d7ec449 100644
--- a/Src/Win32/DasherWindow.h
+++ b/Src/Win32/DasherWindow.h
@@ -37,11 +37,13 @@ public:
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_GETMINMAXINFO,OnGetMinMaxInfo)
MESSAGE_HANDLER(WM_INITMENUPOPUP,OnInitMenuPopup)
- MESSAGE_HANDLER(WM_SETFOCUS,OnSetFocus)
+ MESSAGE_HANDLER(WM_SETFOCUS,OnSetFocus)
+ MESSAGE_HANDLER(WM_WINDOWPOSCHANGED,OnWindowPosChanged)
MESSAGE_RANGE_HANDLER(0xC000,0xFFFF,OnOther)
END_MSG_MAP()
- LRESULT OnSetFocus(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+ LRESULT OnWindowPosChanged(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+ LRESULT OnSetFocus(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnInitMenuPopup(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnGetMinMaxInfo(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnOther(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -66,9 +68,6 @@ public:
void HandleParameterChange(int iParameter);
private:
-
- void SaveWindowState() const;
- bool LoadWindowState();
int GetMinCanvasWidth() const { return 100; }
int GetMinCanvasHeight() const { return 100; }
int GetMinEditHeight() const { return 50; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]