Merge branch 'bare-repo'
[TortoiseGit.git] / src / Utils / MiscUI / MenuButton.h
blobdb79ab678325cce088ed52149b15ac29cffdf963
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011 - Sven Strickroth <email@cs-ware.de>
5 //based on:
6 // Copyright (C) 2003-2007 - TortoiseSVN
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software Foundation,
20 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #pragma once
24 /**
25 * \ingroup Utils
26 * A button control with a menu to choose from different
27 * actions. Clicking on the left "button" part is the same
28 * as with a normal button, clicking on the right "arrow"
29 * part will bring up a menu where the user can choose what
30 * action the button should do.
32 class CMenuButton : public CMFCMenuButton
34 public:
35 DECLARE_DYNCREATE(CMenuButton);
37 CMenuButton(void);
38 virtual ~CMenuButton(void);
40 /**
41 * Inserts a text to be shown in the button menu.
42 * The text is inserted at the end of the menu string list.
43 * \return the index of the inserted item. This index is
44 * returned in GetCurrentEntry().
46 INT_PTR AddEntry(const CString& sEntry);
48 /**
49 * Inserts an array of strings to be shown in the
50 * button menu. The strings are inserted at the end
51 * of the menu string list.
52 * \return the index of the first inserted item. This index
53 * is returned in GetCurrentEntry().
55 INT_PTR AddEntries(const CStringArray& sEntries);
57 /**
58 * Returns the currently shown entry index of the button.
60 INT_PTR GetCurrentEntry() const { return (m_nMenuResult == 0) ? m_nDefault - 1 : m_nMenuResult - 1; }
62 /**
63 * Sets which of the menu strings should be shown in the
64 * button and be active.
65 * \return true if successful
67 bool SetCurrentEntry(INT_PTR entry);
69 /**
70 * Determines if the button control is drawn with the XP
71 * themes or without. The default is \a true, which means
72 * the control is drawn with theming support if the underlying
73 * OS has it enabled and supports it.
75 void RemoveAll();
77 bool m_bMarkDefault;
79 protected:
80 virtual BOOL PreTranslateMessage(MSG* pMsg);
82 bool m_bRealMenuIsActive;
83 virtual void OnShowMenu();
84 afx_msg void OnDraw(CDC* pDC, const CRect& rect, UINT uiState);
86 afx_msg BOOL OnClicked();
87 afx_msg void OnDestroy();
89 CMenu m_btnMenu;
90 INT_PTR m_nDefault;
92 DECLARE_MESSAGE_MAP()
94 CStringArray m_sEntries;