码迷,mamicode.com
首页 > 其他好文 > 详细

PopupMenus

时间:2014-12-18 13:13:39      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   io   color   sp   for   on   div   

 1 //PopupMenus.cpp
 2 
 3 
 4 #include "vcf/ApplicationKit/ApplicationKit.h"
 5 #include "vcf/ApplicationKit/CommandButton.h"
 6 #include "vcf/ApplicationKit/DefaultMenuItem.h"
 7 
 8 using namespace VCF;
 9 
10 
11 class PopupMenusWindow : public Window {
12 public:
13     PopupMenusWindow() {
14         setCaption( "PopupMenus" );        
15 
16         CommandButton* cb = new CommandButton();
17         cb->setBounds( 20, 20, 100, 30 );
18         add( cb );
19 
20         cb->ButtonClicked += new ClassProcedure1<Event*,PopupMenusWindow>(this, &PopupMenusWindow::btnClick, "btnClick" );
21 
22         EventHandler* eh = new ClassProcedure1<Event*,PopupMenusWindow>(this, &PopupMenusWindow::onMenuItemClicked, "onMenuItemClicked" );
23 
24 
25         PopupMenu* popupMenu = new PopupMenu( this );
26         MenuItem* root = popupMenu->getRootMenuItem();
27 
28         setPopupMenu( popupMenu );
29 
30         for (int i=1;i<=10;i++ ) {
31             MenuItem* item = 
32                 new DefaultMenuItem( Format("Context Menu Item %d") % i, root,popupMenu );
33             item->MenuItemClicked +=  getCallback( "onMenuItemClicked" );
34         }
35 
36     }
37 
38     virtual ~PopupMenusWindow(){};
39 
40     void btnClick( Event* e ) {
41         PopupMenu* popupMenu = new PopupMenu( this );
42 
43         MenuItem* root = popupMenu->getRootMenuItem();
44 
45         
46         for (int i=1;i<=10;i++ ) {
47             MenuItem* item = 
48                 new DefaultMenuItem( Format("Menu Item %d") % i, root,popupMenu );
49             item->MenuItemClicked += getCallback( "onMenuItemClicked" );
50         }
51 
52         Point pt(20, 50);
53         popupMenu->popup( &pt );
54 
55         removeComponent( popupMenu );
56         popupMenu->free();
57     }
58     
59     void onMenuItemClicked( Event* e ) {
60         MenuItem* item = (MenuItem*)e->getSource();
61         Dialog::showMessage( Format("Menu item \"%s\" clicked!") % item->getCaption() );
62     }
63 };
64 
65 
66 
67 
68 class PopupMenusApplication : public Application {
69 public:
70 
71     PopupMenusApplication( int argc, char** argv ) : Application(argc, argv) {
72 
73     }
74 
75     virtual bool initRunningApplication(){
76         bool result = Application::initRunningApplication();
77         
78         Window* mainWindow = new PopupMenusWindow();
79         setMainWindow(mainWindow);
80         mainWindow->setBounds( 100.0, 100.0, 500.0, 500.0 );
81         mainWindow->show();
82         
83         return result;
84     }
85 
86 };
87 
88 
89 int main(int argc, char *argv[])
90 {
91     Application* app = new PopupMenusApplication( argc, argv );
92 
93     Application::main();
94     
95     return 0;
96 }

 

PopupMenus

标签:style   blog   ar   io   color   sp   for   on   div   

原文地址:http://www.cnblogs.com/elitiwin/p/4171393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!