OSDN Git Service

Fix open second file log list error
[tortoisegit/TortoiseGitJp.git] / ext / ResizableLib / ResizableWndState.cpp
1 /////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 // This file is part of ResizableLib\r
4 // http://sourceforge.net/projects/resizablelib\r
5 //\r
6 // Copyright (C) 2000-2004,2008 by Paolo Messina\r
7 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com\r
8 //\r
9 // The contents of this file are subject to the Artistic License (the "License").\r
10 // You may not use this file except in compliance with the License. \r
11 // You may obtain a copy of the License at:\r
12 // http://www.opensource.org/licenses/artistic-license.html\r
13 //\r
14 // If you find this code useful, credits would be nice!\r
15 //\r
16 /////////////////////////////////////////////////////////////////////////////\r
17 \r
18 /*!\r
19  *  @file\r
20  *  @brief Implementation of the CResizableWndState class.\r
21  */\r
22 \r
23 #include "stdafx.h"\r
24 #include "ResizableWndState.h"\r
25 \r
26 //////////////////////////////////////////////////////////////////////\r
27 // Construction/Destruction\r
28 //////////////////////////////////////////////////////////////////////\r
29 \r
30 CResizableWndState::CResizableWndState()\r
31 {\r
32 \r
33 }\r
34 \r
35 CResizableWndState::~CResizableWndState()\r
36 {\r
37 \r
38 }\r
39 \r
40 // used to save/restore window's size and position\r
41 // either in the registry or a private .INI file\r
42 // depending on your application settings\r
43 \r
44 #define PLACEMENT_ENT   _T("WindowPlacement")\r
45 #define PLACEMENT_FMT   _T("%d,%d,%d,%d,%d,%d,%d,%d")\r
46 \r
47 /*!\r
48  *  This function saves the current window position and size using the base\r
49  *  class persist method. Minimized and maximized state is also optionally\r
50  *  preserved.\r
51  *  @sa CResizableState::WriteState\r
52  *  @note Window coordinates are in the form used by the system functions\r
53  *  GetWindowPlacement and SetWindowPlacement.\r
54  *  \r
55  *  @param pszName String that identifies stored settings\r
56  *  @param bRectOnly Flag that specifies wether to ignore min/max state\r
57  *  \r
58  *  @return Returns @a TRUE if successful, @a FALSE otherwise\r
59  */\r
60 BOOL CResizableWndState::SaveWindowRect(LPCTSTR pszName, BOOL bRectOnly)\r
61 {\r
62         CString data, id;\r
63         WINDOWPLACEMENT wp;\r
64 \r
65         SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT));\r
66         wp.length = sizeof(WINDOWPLACEMENT);\r
67         if (!GetResizableWnd()->GetWindowPlacement(&wp))\r
68                 return FALSE;\r
69         \r
70         // use workspace coordinates\r
71         RECT& rc = wp.rcNormalPosition;\r
72 \r
73         if (bRectOnly)  // save size/pos only (normal state)\r
74         {\r
75                 data.Format(PLACEMENT_FMT, rc.left, rc.top,\r
76                         rc.right, rc.bottom, SW_SHOWNORMAL, 0, 0, 0);\r
77         }\r
78         else    // save also min/max state\r
79         {\r
80                 data.Format(PLACEMENT_FMT, rc.left, rc.top,\r
81                         rc.right, rc.bottom, wp.showCmd, wp.flags,\r
82                         wp.ptMinPosition.x, wp.ptMinPosition.y);\r
83         }\r
84 \r
85         id = CString(pszName) + PLACEMENT_ENT;\r
86         return WriteState(id, data);\r
87 }\r
88 \r
89 /*!\r
90  *  This function loads and set the current window position and size using\r
91  *  the base class persist method. Minimized and maximized state is also\r
92  *  optionally preserved.\r
93  *  @sa CResizableState::WriteState\r
94  *  @note Window coordinates are in the form used by the system functions\r
95  *  GetWindowPlacement and SetWindowPlacement.\r
96  *  \r
97  *  @param pszName String that identifies stored settings\r
98  *  @param bRectOnly Flag that specifies wether to ignore min/max state\r
99  *  \r
100  *  @return Returns @a TRUE if successful, @a FALSE otherwise\r
101  */\r
102 BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly)\r
103 {\r
104         CString data, id;\r
105         WINDOWPLACEMENT wp;\r
106 \r
107         id = CString(pszName) + PLACEMENT_ENT;\r
108         if (!ReadState(id, data))       // never saved before\r
109                 return FALSE;\r
110         \r
111         SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT));\r
112         wp.length = sizeof(WINDOWPLACEMENT);\r
113         if (!GetResizableWnd()->GetWindowPlacement(&wp))\r
114                 return FALSE;\r
115 \r
116         // use workspace coordinates\r
117         RECT& rc = wp.rcNormalPosition;\r
118 \r
119         if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top,\r
120                 &rc.right, &rc.bottom, &wp.showCmd, &wp.flags,\r
121                 &wp.ptMinPosition.x, &wp.ptMinPosition.y) == 8)\r
122         {\r
123                 if (bRectOnly)  // restore size/pos only\r
124                 {\r
125                         wp.showCmd = SW_SHOWNORMAL;\r
126                         wp.flags = 0;\r
127                         return GetResizableWnd()->SetWindowPlacement(&wp);\r
128                 }\r
129                 else    // restore also max state\r
130                 {\r
131                         if (wp.showCmd == SW_SHOWMINIMIZED)\r
132                                 wp.showCmd = SW_SHOWNORMAL;\r
133                         return GetResizableWnd()->SetWindowPlacement(&wp);\r
134                 }\r
135         }\r
136         return FALSE;\r
137 }\r