Fixed issue #3212: With Detached Head, Push Dialog has Local Branch filled with HEAD...
[TortoiseGit.git] / ext / ResizableLib / ResizableWndState.cpp
blob8ec58dda0067dd69aaddacdbba4a4a50f929d0f3
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // This file is part of ResizableLib
4 // http://sourceforge.net/projects/resizablelib
5 //
6 // Copyright (C) 2000-2004,2008 by Paolo Messina
7 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com
8 //
9 // The contents of this file are subject to the Artistic License (the "License").
10 // You may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at:
12 // http://www.opensource.org/licenses/artistic-license.html
14 // If you find this code useful, credits would be nice!
16 /////////////////////////////////////////////////////////////////////////////
18 /*!
19 * @file
20 * @brief Implementation of the CResizableWndState class.
23 #include "stdafx.h"
24 #include "ResizableWndState.h"
26 //////////////////////////////////////////////////////////////////////
27 // Construction/Destruction
28 //////////////////////////////////////////////////////////////////////
30 CResizableWndState::CResizableWndState()
35 CResizableWndState::~CResizableWndState()
40 // used to save/restore window's size and position
41 // either in the registry or a private .INI file
42 // depending on your application settings
44 #define PLACEMENT_ENT _T("WindowPlacement")
45 #define PLACEMENT_FMT _T("%d,%d,%d,%d,%d,%d,%d,%d")
47 /*!
48 * This function saves the current window position and size using the base
49 * class persist method. Minimized and maximized state is also optionally
50 * preserved.
51 * @sa CResizableState::WriteState
52 * @note Window coordinates are in the form used by the system functions
53 * GetWindowPlacement and SetWindowPlacement.
55 * @param pszName String that identifies stored settings
56 * @param bRectOnly Flag that specifies wether to ignore min/max state
58 * @return Returns @a TRUE if successful, @a FALSE otherwise
60 BOOL CResizableWndState::SaveWindowRect(LPCTSTR pszName, BOOL bRectOnly)
62 CString data, id;
63 WINDOWPLACEMENT wp;
65 SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
66 wp.length = sizeof(WINDOWPLACEMENT);
67 if (!GetResizableWnd()->GetWindowPlacement(&wp))
68 return FALSE;
70 // use workspace coordinates
71 RECT& rc = wp.rcNormalPosition;
73 if (bRectOnly) // save size/pos only (normal state)
75 data.Format(PLACEMENT_FMT, rc.left, rc.top,
76 rc.right, rc.bottom, SW_SHOWNORMAL, 0, 0, 0);
78 else // save also min/max state
80 data.Format(PLACEMENT_FMT, rc.left, rc.top,
81 rc.right, rc.bottom, wp.showCmd, wp.flags,
82 wp.ptMinPosition.x, wp.ptMinPosition.y);
85 id = CString(pszName) + PLACEMENT_ENT;
86 return WriteState(id, data);
89 /*!
90 * This function loads and set the current window position and size using
91 * the base class persist method. Minimized and maximized state is also
92 * optionally preserved.
93 * @sa CResizableState::WriteState
94 * @note Window coordinates are in the form used by the system functions
95 * GetWindowPlacement and SetWindowPlacement.
97 * @param pszName String that identifies stored settings
98 * @param bRectOnly Flag that specifies wether to ignore min/max state
100 * @return Returns @a TRUE if successful, @a FALSE otherwise
102 BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly, BOOL bHorzResize, BOOL bVertResize)
104 CString data, id;
105 WINDOWPLACEMENT wp;
107 id = CString(pszName) + PLACEMENT_ENT;
108 if (!ReadState(id, data)) // never saved before
109 return FALSE;
111 SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
112 wp.length = sizeof(WINDOWPLACEMENT);
113 if (!GetResizableWnd()->GetWindowPlacement(&wp))
114 return FALSE;
116 // use workspace coordinates
117 RECT& rc = wp.rcNormalPosition;
119 long min_width = rc.right - rc.left;
120 long min_height = rc.bottom - rc.top;
122 if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top,
123 &rc.right, &rc.bottom, &wp.showCmd, &wp.flags,
124 &wp.ptMinPosition.x, &wp.ptMinPosition.y) == 8)
126 if ((!bVertResize) || (rc.bottom - rc.top < min_height))
127 rc.bottom = rc.top + min_height;
128 if ((!bHorzResize) || (rc.right - rc.left < min_width))
129 rc.right = rc.left + min_width;
130 if (bRectOnly) // restore size/pos only
132 wp.showCmd = SW_SHOWNORMAL;
133 wp.flags = 0;
134 return GetResizableWnd()->SetWindowPlacement(&wp);
136 else // restore minimized window to normal or maximized state
138 if (wp.showCmd == SW_SHOWMINIMIZED && wp.flags == 0)
139 wp.showCmd = SW_SHOWNORMAL;
140 else if (wp.showCmd == SW_SHOWMINIMIZED && wp.flags == WPF_RESTORETOMAXIMIZED)
141 wp.showCmd = SW_SHOWMAXIMIZED;
142 return GetResizableWnd()->SetWindowPlacement(&wp);
145 return FALSE;