OSDN Git Service

Merge remove x86 build
[tortoisegit/TortoiseGitJp.git] / src / 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 #include "git.h"\r
40 class CHistoryCombo : public CComboBoxEx\r
41 {\r
42 // Construction\r
43 public:\r
44         CHistoryCombo(BOOL bAllowSortStyle = FALSE);\r
45         virtual ~CHistoryCombo();\r
46 \r
47 // Operations\r
48 public:\r
49         /**\r
50          * Adds the string \a str to both the combobox and the history.\r
51          * If \a pos is specified, insert the string at the specified\r
52          * position, otherwise add it to the end of the list.\r
53          */\r
54         int AddString(CString str, INT_PTR pos = -1);\r
55         void DisableTooltip(){m_bDyn = FALSE;} //because rebase need disable combox tooltip to show version info\r
56 protected:\r
57         DECLARE_MESSAGE_MAP()\r
58         virtual BOOL PreCreateWindow(CREATESTRUCT& cs);\r
59         virtual BOOL PreTranslateMessage(MSG* pMsg);\r
60         virtual void PreSubclassWindow();\r
61 \r
62         afx_msg void OnMouseMove(UINT nFlags, CPoint point);\r
63         afx_msg void OnTimer(UINT_PTR nIDEvent);\r
64         afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);\r
65 \r
66         void CreateToolTip();\r
67 \r
68 // Implementation\r
69 public:\r
70         /**\r
71          * Clears the history in the registry/inifile and the ComboBox.\r
72          * \param bDeleteRegistryEntries if this value is true then the registry key\r
73          * itself is deleted.\r
74          */\r
75         void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);\r
76         /**\r
77          * When \a bURLHistory is TRUE, treat the combo box entries\r
78          * as URLs. This activates Shell URL auto completion and\r
79          * the display of special icons in front of the combobox\r
80          * entries. Default is FALSE.\r
81          */\r
82         void SetURLHistory(BOOL bURLHistory);\r
83         /**\r
84          * When \a bPathHistory is TRUE, treat the combo box entries\r
85          * as Paths. This activates Shell Path auto completion and\r
86          * the display of special icons in front of the combobox\r
87          * entries. Default is FALSE.\r
88          */\r
89         void SetPathHistory(BOOL bPathHistory);\r
90         /**\r
91          * Sets the maximum numbers of entries in the history list.\r
92          * If the history is larger as \em nMaxItems then the last\r
93          * items in the history are deleted.\r
94          */\r
95         void SetMaxHistoryItems(int nMaxItems);\r
96         /**\r
97          * Saves the history to the registry/inifile.\r
98          * \remark if you haven't called LoadHistory() before this method\r
99          * does nothing!\r
100          */\r
101         void SaveHistory();\r
102         /**\r
103          * Loads the history from the registry/inifile and fills in the\r
104          * ComboBox.\r
105          * \param lpszSection a section name where to put the entries, e.g. "lastloadedfiles"\r
106          * \param lpszKeyPrefix a prefix to use for the history entries in registry/inifiles. E.g. "file" or "entry"\r
107          */\r
108         CString LoadHistory(LPCTSTR lpszSection, LPCTSTR lpszKeyPrefix);\r
109 \r
110         /**\r
111          * Returns the string in the combobox which is either selected or the user has entered.\r
112          */\r
113         CString GetString() const;\r
114 \r
115         void AddString(STRING_VECTOR &list);\r
116 \r
117 protected:\r
118         /**\r
119          * Will be called whenever the return key is pressed while the\r
120          * history combo has the input focus. A derived class may implement\r
121          * a special behavior for the return key by overriding this method.\r
122          * It must return true to prevent the default processing for the\r
123          * return key. The default implementation returns false.\r
124          */\r
125         virtual bool OnReturnKeyPressed() { return false; }\r
126 \r
127         /**\r
128          * Removes the selected item from the combo box and updates\r
129          * the registry settings. Returns TRUE if successful.\r
130          */\r
131         BOOL RemoveSelectedItem();\r
132 \r
133 protected:\r
134         CStringArray    m_arEntries;\r
135         CString                 m_sSection;\r
136         CString                 m_sKeyPrefix;\r
137         int                             m_nMaxHistoryItems;\r
138         BOOL                    m_bAllowSortStyle;\r
139         BOOL                    m_bURLHistory;\r
140         BOOL                    m_bPathHistory;\r
141         HWND                    m_hWndToolTip;\r
142         TOOLINFO                m_ToolInfo;\r
143         BOOL                    m_ttShown;\r
144         BOOL                    m_bDyn;\r
145 };\r
146 \r
147 \r
148 \r