OSDN Git Service

add Utils
[tortoisegit/TortoiseGitJp.git] / Utils / MiscUI / HistoryCombo.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoioseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 \r
21 /**\r
22  * \ingroup Utils\r
23  * Extends the CComboBoxEx class with a history of entered\r
24  * values. An example of such a combobox is the Start/Run\r
25  * dialog which lists the programs you used last in a combobox.\r
26  * To use this class do the following:\r
27  * -# add both files HistoryCombo.h and HistoryCombo.cpp to your project.\r
28  * -# add a ComboBoxEx to your dialog\r
29  * -# create a variable for the ComboBox of type control\r
30  * -# change the type of the created variable from CComboBoxEx to\r
31  *    CHistoryCombo\r
32  * -# in your OnInitDialog() call SetURLHistory(TRUE) if your ComboBox\r
33  *    contains URLs\r
34  * -# in your OnInitDialog() call the LoadHistory() method\r
35  * -# in your OnOK() or somewhere similar call the SaveHistory() method\r
36  * \r
37  * thats it. \r
38  */\r
39 class CHistoryCombo : public CComboBoxEx\r
40 {\r
41 // Construction\r
42 public:\r
43         CHistoryCombo(BOOL bAllowSortStyle = FALSE);\r
44         virtual ~CHistoryCombo();\r
45 \r
46 // Operations\r
47 public:\r
48         /**\r
49          * Adds the string \a str to both the combobox and the history.\r
50          * If \a pos is specified, insert the string at the specified\r
51          * position, otherwise add it to the end of the list.\r
52          */\r
53         int AddString(CString str, INT_PTR pos = -1);\r
54 \r
55 protected:\r
56         DECLARE_MESSAGE_MAP()\r
57         virtual BOOL PreCreateWindow(CREATESTRUCT& cs);\r
58         virtual BOOL PreTranslateMessage(MSG* pMsg);\r
59         virtual void PreSubclassWindow();\r
60 \r
61         afx_msg void OnMouseMove(UINT nFlags, CPoint point);\r
62         afx_msg void OnTimer(UINT_PTR nIDEvent);\r
63         afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);\r
64 \r
65         void CreateToolTip();\r
66 \r
67 // Implementation\r
68 public:\r
69         /**\r
70          * Clears the history in the registry/inifile and the ComboBox.\r
71          * \param bDeleteRegistryEntries if this value is true then the registry key\r
72          * itself is deleted.\r
73          */\r
74         void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);\r
75         /**\r
76          * When \a bURLHistory is TRUE, treat the combo box entries\r
77          * as URLs. This activates Shell URL auto completion and\r
78          * the display of special icons in front of the combobox\r
79          * entries. Default is FALSE.\r
80          */\r
81         void SetURLHistory(BOOL bURLHistory);\r
82         /**\r
83          * When \a bPathHistory is TRUE, treat the combo box entries\r
84          * as Paths. This activates Shell Path auto completion and\r
85          * the display of special icons in front of the combobox\r
86          * entries. Default is FALSE.\r
87          */\r
88         void SetPathHistory(BOOL bPathHistory);\r
89         /**\r
90          * Sets the maximum numbers of entries in the history list.\r
91          * If the history is larger as \em nMaxItems then the last\r
92          * items in the history are deleted.\r
93          */\r
94         void SetMaxHistoryItems(int nMaxItems);\r
95         /**\r
96          * Saves the history to the registry/inifile.\r
97          * \remark if you haven't called LoadHistory() before this method\r
98          * does nothing!\r
99          */\r
100         void SaveHistory();\r
101         /**\r
102          * Loads the history from the registry/inifile and fills in the\r
103          * ComboBox.\r
104          * \param lpszSection a section name where to put the entries, e.g. "lastloadedfiles"\r
105          * \param lpszKeyPrefix a prefix to use for the history entries in registry/inifiles. E.g. "file" or "entry"\r
106          */\r
107         CString LoadHistory(LPCTSTR lpszSection, LPCTSTR lpszKeyPrefix);\r
108 \r
109         /**\r
110          * Returns the string in the combobox which is either selected or the user has entered.\r
111          */\r
112         CString GetString() const;\r
113 \r
114 protected:\r
115         /**\r
116          * Will be called whenever the return key is pressed while the\r
117          * history combo has the input focus. A derived class may implement\r
118          * a special behavior for the return key by overriding this method.\r
119          * It must return true to prevent the default processing for the\r
120          * return key. The default implementation returns false.\r
121          */\r
122         virtual bool OnReturnKeyPressed() { return false; }\r
123 \r
124         /**\r
125          * Removes the selected item from the combo box and updates\r
126          * the registry settings. Returns TRUE if successful.\r
127          */\r
128         BOOL RemoveSelectedItem();\r
129 \r
130 protected:\r
131         CStringArray    m_arEntries;\r
132         CString                 m_sSection;\r
133         CString                 m_sKeyPrefix;\r
134         int                             m_nMaxHistoryItems;\r
135         BOOL                    m_bAllowSortStyle;\r
136         BOOL                    m_bURLHistory;\r
137         BOOL                    m_bPathHistory;\r
138         HWND                    m_hWndToolTip;\r
139         TOOLINFO                m_ToolInfo;\r
140         BOOL                    m_ttShown;\r
141         BOOL                    m_bDyn;\r
142 };\r
143 \r
144 \r
145 \r