Menu

[r1967]: / trunk / src / sdk / menuitemsmanager.cpp  Maximize  Restore  History

Download this file

82 lines (73 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* This file is part of Code::Blocks Studio, an open-source cross-platform IDE
* Copyright (C) 2003 Yiannis An. Mandravellos
*
* This program is distributed under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include "menuitemsmanager.h"
#endif
MenuItemsManager::MenuItemsManager()
: m_Menu(0L)
{
//ctor
}
MenuItemsManager::~MenuItemsManager()
{
//dtor
Clear(m_Menu);
m_MenuItems.Clear();
}
/** @brief Add a menu item
*
* @param parent The menu to append the menu item to
* @param id The menu item ID (use wxID_SEPARATOR for adding a separator)
* @param caption The caption for the new menu item
* @param helptext The help text for the new menu item
*/
void MenuItemsManager::Add(wxMenu* parent, int id, const wxString& caption, const wxString& helptext)
{
if (!parent)
return;
m_Menu = parent;
wxMenuItem* ni = new wxMenuItem(parent, id, caption, helptext);
m_MenuItems.Add(ni);
parent->Append(ni);
}
/** @brief Insert a menu item
*
* @param parent The menu to insert the menu item to
* @param index The index where to insert the menu item
* @param id The menu item ID (use wxID_SEPARATOR for adding a separator)
* @param caption The caption for the new menu item
* @param helptext The help text for the new menu item
*/
void MenuItemsManager::Insert(wxMenu* parent, int index, int id, const wxString& caption, const wxString& helptext)
{
if (!parent)
return;
m_Menu = parent;
wxMenuItem* ni = new wxMenuItem(0L, id, caption, helptext);
m_MenuItems.Add(ni);
parent->Insert(index, ni);
}
/** @brief Clear all managed menu items
* @param menu The menu that holds the menu items
*/
void MenuItemsManager::Clear(wxMenu* menu)
{
if (!menu)
return;
for (unsigned int i = 0; i < m_MenuItems.Count(); ++i)
{
wxMenuItem* ni = m_MenuItems[i];
menu->Delete(ni);
}
m_MenuItems.Clear();
}