OSDN Git Service

Linked with static version of CRT/MFC.
[tortoisegit/TortoiseGitJp.git] / ext / ResizableLib / ResizableState.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 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 CResizableState class.\r
21  */\r
22 \r
23 #include "stdafx.h"\r
24 #include "ResizableState.h"\r
25 \r
26 #ifdef _DEBUG\r
27 #undef THIS_FILE\r
28 static char THIS_FILE[]=__FILE__;\r
29 #define new DEBUG_NEW\r
30 #endif\r
31 \r
32 //////////////////////////////////////////////////////////////////////\r
33 // Construction/Destruction\r
34 //////////////////////////////////////////////////////////////////////\r
35 \r
36 CResizableState::CResizableState()\r
37 {\r
38         m_sStorePath = m_sDefaultStorePath;\r
39 }\r
40 \r
41 CResizableState::~CResizableState()\r
42 {\r
43 \r
44 }\r
45 \r
46 // static intializer must be called before user code\r
47 #pragma warning(disable:4073)\r
48 #pragma init_seg(lib)\r
49 CString CResizableState::m_sDefaultStorePath(_T("ResizableState"));\r
50 \r
51 /*!\r
52  *  Static function to set the default path used to store state information.\r
53  *  This path is used to initialize all the instances of this class.\r
54  *  @sa GetDefaultStateStore GetStateStore SetStateStore\r
55  *  \r
56  *  @param szPath String that specifies the new path to be set\r
57  */\r
58 void CResizableState::SetDefaultStateStore(LPCTSTR szPath)\r
59 {\r
60         m_sDefaultStorePath = szPath;\r
61 }\r
62 \r
63 /*!\r
64  *  Static function to retrieve the default path used to store state\r
65  *  information.\r
66  *  This path is used to initialize all the instances of this class.\r
67  *  @sa SetDefaultStateStore GetStateStore SetStateStore\r
68  *  \r
69  *  @return The return value is a string that specifies the current path\r
70  */\r
71 LPCTSTR CResizableState::GetDefaultStateStore()\r
72 {\r
73         return m_sDefaultStorePath;\r
74 }\r
75 \r
76 /*!\r
77  *  This function sets the path used to store state information by\r
78  *  the current instance of the class.\r
79  *  @sa GetStateStore GetDefaultStateStore SetDefaultStateStore\r
80  *  \r
81  *  @param szPath String that specifies the new path to be set\r
82  */\r
83 void CResizableState::SetStateStore(LPCTSTR szPath)\r
84 {\r
85         m_sStorePath = szPath;\r
86 }\r
87 \r
88 /*!\r
89  *  This function retrieves the path used to store state information by\r
90  *  the current instance of the class.\r
91  *  @sa SetStateStore GetDefaultStateStore SetDefaultStateStore\r
92  *  \r
93  *  @return The return value is a string that specifies the current path\r
94  */\r
95 LPCTSTR CResizableState::GetStateStore()\r
96 {\r
97         return m_sStorePath;\r
98 }\r
99 \r
100 /*!\r
101  *  This function writes state information and associates it with some\r
102  *  identification text for later retrieval.\r
103  *  The base implementation uses the application profile to persist state\r
104  *  information, but this function can be overridden to implement\r
105  *  different methods.\r
106  *  \r
107  *  @param szId String that identifies the stored settings\r
108  *  @param szState String that represents the state information to store\r
109  *  \r
110  *  @return The return value is @a TRUE if settings have been successfully\r
111  *          stored, @a FALSE otherwise.\r
112  */\r
113 BOOL CResizableState::WriteState(LPCTSTR szId, LPCTSTR szState)\r
114 {\r
115         return AfxGetApp()->WriteProfileString(GetStateStore(), szId, szState);\r
116 }\r
117 \r
118 /*!\r
119  *  This function reads state information previously associated with some\r
120  *  identification text.\r
121  *  The base implementation uses the application profile to persist state\r
122  *  information, but this function can be overridden to implement\r
123  *  different methods.\r
124  *  \r
125  *  @param szId String that identifies the stored settings\r
126  *  @param rsState String to be filled with the retrieved state information\r
127  *  \r
128  *  @return The return value is @a TRUE if settings have been successfully\r
129  *          retrieved, @a FALSE otherwise.\r
130  */\r
131 BOOL CResizableState::ReadState(LPCTSTR szId, CString &rsState)\r
132 {\r
133         rsState = AfxGetApp()->GetProfileString(GetStateStore(), szId);\r
134         return !rsState.IsEmpty();\r
135 }\r