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