-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopUpMenu.cpp
More file actions
65 lines (52 loc) · 1.61 KB
/
PopUpMenu.cpp
File metadata and controls
65 lines (52 loc) · 1.61 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
/*
Open source not for commercial deployment
*/
//---------------------------------------------------------------------------
#pragma hdrstop
#include "PopUpMenu.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
void PopUpMenu::init(TComponent * pParent)
{
parent = pParent;
}
void __fastcall PopUpMenu::MenuItemClick(TObject *Sender)
{
MainForm->recurcingDepth =0;
MainForm->ProcessCommands( ((TMenuItem*)Sender)->Hint );
}
void PopUpMenu::CleanUpMenu()
{
delete PopUpMenu; //this will also automicily delete all menuItems.
PopUpMenu = new TPopupMenu(parent);
String t = parent->ClassName();
if (t == "Picture") ((Picture *)parent)->PopupMenu = PopUpMenu;
if (t == "TPanel") ((TPanel *)parent)->PopupMenu = PopUpMenu;
MenuItemCount = 0;
}
void PopUpMenu::addMenuItem(String s) // label_command|command
{
if (s=="ClearAll")
{
CleanUpMenu();
return;
}
else if (PopUpMenu == NULL)
{
CleanUpMenu();
}
if (MenuItemCount == MAX_MENU_ITEMS)
{
MessageDlg("Maximum number of menu items reached.", mtInformation, TMsgDlgButtons()<<mbOK , 0);
return;
}
String Commands = getAfter(s,"_");
Commands = replace(Commands, "|", ",");
MenuItems[MenuItemCount] = new TMenuItem(PopUpMenu);
MenuItems[MenuItemCount]->Caption = getUntil(s,"_");
MenuItems[MenuItemCount]->OnClick = &MenuItemClick;
MenuItems[MenuItemCount]->Hint = Commands;
PopUpMenu->Items->Add(MenuItems[MenuItemCount]);
MenuItemCount++;
}
#pragma package(smart_init)