本文整理汇总了C++中MenuItem::action方法的典型用法代码示例。如果您正苦于以下问题:C++ MenuItem::action方法的具体用法?C++ MenuItem::action怎么用?C++ MenuItem::action使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItem
的用法示例。
在下文中一共展示了MenuItem::action方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_menu
Menu* TE_View::make_menu(Menu* m, CommandInfo* info)
{
WidgetKit& kit = *WidgetKit::instance();
TelltaleGroup* group = nil;
// loop for command array info
for (CommandInfo* i = info; i->str != nil; i++) {
if (i->str[0] == '\0') {
// string is empty (""), add separator
m->append_item(kit.menu_item_separator());
}
else {
// create menu item
MenuItem* item;
if (i->submenu == nil) {
// not a sub-menu, just add callback
item = kit.menu_item(i->str);
item->action(
new ActionCallback(TE_View)(this, i->func)
);
}
else {
// sub-menu, create recursively
item = kit.menu_item(i->str);
item->menu(make_menu(kit.pullright(), i->submenu));
}
// appen created item
m->append_item(item);
}
}
return m;
}
示例2: buildmenu
Glyph* MenuEnumEditor::buildmenu() {
WidgetKit& wk = *WidgetKit::instance();
const LayoutKit& lk = *LayoutKit::instance();
int i;
Coord maxwidth = 0;
Coord tempwid;
for (i = 0; i < _obs->maxvalue(); i++) {
if ((tempwid = wk.font()->width(_obs->labelvalue(i).string(),
_obs->labelvalue(i).length()))
> maxwidth)
maxwidth = tempwid;
}
_enumobs = new EnumObserver(_obs, "", maxwidth);
_menu = wk.menubar();
MenuItem* mbi = wk.menubar_item(_enumobs);
mbi->menu(wk.pullright());
Action* action1;
Action* action2;
for (i = 0; i < _obs->maxvalue(); i++) {
action1 = new EnumActionCallback(MenuEnumEditor)(
this, &MenuEnumEditor::edit, _obs->labelvalue(i)
);
action2 = _macro ? _macro->action(i) : nil;
MenuItem* mi = wk.menu_item(lk.overlay(
lk.vcenter(lk.hspace(maxwidth)),
lk.vcenter(wk.label(_obs->labelvalue(i)))));
mbi->menu()->append_item(mi);
mi->action(new Macro(action1, action2));
}
_menu->append_item(mbi);
return lk.hfixed(_menu, maxwidth+20);
}
示例3: makeshowmenu
Menu* SymChooserImpl::makeshowmenu() {
WidgetKit& k = *WidgetKit::instance();
Menu* mb = k.menubar();
MenuItem* mi = k.menubar_item("Show");
mb->append_item(mi);
Menu* mp = k.pulldown();
mi->menu(mp);
TelltaleGroup* ttg = new TelltaleGroup();
mi = K::radio_menu_item(ttg, "All");
mi->action(new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_all
));
mp->append_item(mi);
mi->state()->set(TelltaleState::is_chosen, true);
mi = K::radio_menu_item(ttg, "Variables");
mi->action(new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_var
));
mp->append_item(mi);
mi = K::radio_menu_item(ttg, "Object refs");
mi->action(new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_objref
));
mp->append_item(mi);
mi = K::radio_menu_item(ttg, "Objects");
mi->action(new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_objid
));
mp->append_item(mi);
mi = K::radio_menu_item(ttg, "Sections");
mi->action(new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_sec
));
mp->append_item(mi);
#if SHOW_SECTION
mi->state()->set(TelltaleState::is_chosen, true);
#endif
return mb;
}
示例4: Background
main(int argc, char *argv[]) {
Session * session = new Session("strchooser", argc, argv, options, properties);
LayoutKit & lk = *LayoutKit::instance();
WidgetKit * wk = MFKit::instance();
PolyGlyph * mainglyph = lk.vbox();
ApplicationWindow * mainwin = new ApplicationWindow(mainglyph);
App * tryme = new App(mainwin);
Menu * top_menu = wk->menubar();
MenuItem *quit = wk->menubar_item("Quit");
quit->action(new ActionCallback(Session)(Session::instance(),
&Session::quit));
top_menu->append_item(quit);
MenuItem *post = wk->menubar_item("Post");
post->action(new ActionCallback(App)(tryme, &App::post_the_file_chooser));
top_menu->append_item(post);
mainglyph->append(
new Background(
lk.vcenter(
lk.vbox(
top_menu,
lk.fixed(nil, 200, 200)
)
),
wk->background()
)
);
return session->run_window(mainwin);
}
示例5: open
void Menu::open() {
MenuImpl& i = *impl_;
GlyphIndex index = i.item_;
if (index >= 0) {
MenuItem* mi = item(index);
TelltaleState* t = mi->state();
if (t != nil && t->test(TelltaleState::is_enabled)) {
t->set(TelltaleState::is_active, true);
if (mi->menu() != nil) {
mi->menu()->unselect();
Action* a = mi->action();
if (a != nil) {
a->execute();
}
}
if ((mi->window() != nil) && (mi->patch_->canvas() != nil)) {
const Window& rel = *mi->patch_->canvas()->window();
const Allocation& a = mi->patch_->allocation();
Window& w = *mi->window();
w.display(rel.display());
#if defined(WIN32) || defined(MAC)
if (!w.bound()) { // got to get it sized before align
w.place(-10000, 10000); // will work
w.map();
w.unmap();
}
#endif
w.place(
rel.left() + (1 - i.x1_) * a.left() + i.x1_ * a.right(),
rel.bottom() + (1 - i.y1_) * a.bottom() + i.y1_ * a.top()
);
w.align(i.x2_, i.y2_);
#ifdef WIN32
// force onto screen. Well, almost, there is a problem if menu items overlay
// previous menus. so only check if bottom is negative.
if (w.bottom() < 0) {
w.place(w.left(), 0);
}
#endif
w.map();
#if carbon
++iv_carbon_in_menu_;
#endif
}
}
}
}
示例6: pulldown
Menu* App::pulldown(
CmdInfo* info, int opt, WidgetKit& k, const LayoutKit& layout
) {
Menu* m = k.pulldown();
TelltaleGroup* group = nil;
for (CmdInfo* i = info; i->str != nil; i++) {
if (i->str[0] == '\0') {
m->append_item(k.menu_item_separator());
} else {
Glyph* g = layout.r_margin(
k.fancy_label(i->str), 0.0, fil, 0.0
);
MenuItem* mi;
switch (opt) {
case 1:
mi = k.check_menu_item(g);
break;
case 2:
if (group == nil) {
group = new TelltaleGroup;
}
mi = k.radio_menu_item(group, g);
break;
default:
mi = k.menu_item(g);
break;
}
if (i->func == nil && i->submenu != nil) {
mi->menu(pulldown(i->submenu, i->options, k, layout));
} else {
mi->action(new ActionCallback(App)(this, i->func));
}
m->append_item(mi);
}
}
return m;
}
示例7: add_radio_menu
MenuItem* ScenePicker::add_radio_menu(const char* name, Action* a, Menu* m) {
MenuItem* mi = K::radio_menu_item(spi_->tg_, name);
mi->action(new RadioSelect(name, a, spi_->scene_));
return add_menu(name, mi, m);
}
示例8: add_menu
MenuItem* ScenePicker::add_menu(const char* name, Action* a, Menu* m) {
MenuItem* mi = K::menu_item(name);
mi->action(a);
return add_menu(name, mi, m);
}
示例9: main
int main(int argc, char** argv) {
Session* session = new Session("meter demo", argc, argv, options, properties);
WidgetKit& wk = *WidgetKit::instance();
LayoutKit& lk = *LayoutKit::instance();
PolyGlyph * mainglyph = lk.vbox();
ApplicationWindow * mainwin = new ApplicationWindow(mainglyph);
BoundedValue* bdv1 = new BoundedValue(0.0, 1000.0, 5.0, 10.0, 747, "%6.0f");
BoundedValue* bdv2 = new BoundedValue(0.0, 1000.0, 5.0, 10.0, 512, "%6.0f");
BoundedValue* bdv3 = new BoundedValue(0.0, 1000.0, 5.0, 10.0, 66, "%6.0f");
App * tryme = new App(mainwin, bdv1, bdv2, bdv3);
BoundedValueObserver* bdview1 = new BoundedValueObserver(bdv1,
"Bounded Float Value: ");
BoundedValueObserver* bdview2 = new BoundedValueObserver(bdv2,
"Bounded Float Value: ");
BoundedValueObserver* bdview3 = new BoundedValueObserver(bdv3,
"Bounded Float Value: ");
Menu * top_menu = wk.menubar();
MenuItem *quit = wk.menubar_item("Quit");
quit->action(new ActionCallback(Session)(Session::instance(), &Session::quit));
top_menu->append_item(quit);
MenuItem *meter = wk.menubar_item("Meter");
meter->action(new ActionCallback(App)(tryme, &App::meter_it));
top_menu->append_item(meter);
MenuItem *multimeter = wk.menubar_item("MultiMeter");
multimeter->action(new ActionCallback(App)(tryme, &App::multimeter_it));
top_menu->append_item(multimeter);
mainglyph->append(
new Background(
lk.vbox(
top_menu,
lk.natural(
lk.tmargin(
lk.lmargin(
lk.vbox(
bdview1,
lk.vspace(10),
bdview2,
lk.vspace(10),
bdview3
),
10
),
10
),
200, 200
)
),
wk.background()
)
);
return session->run_window(mainwin);
}
示例10: release
void Menu::release(const Event& e) {
#if carbon
extern bool session_deactivating_;
if (session_deactivating_) {
unselect();
return;
}
#endif
Menu* m = this;
GlyphIndex index;
for (;;) {
index = m->selected();
if (index < 0) {
break;
}
Menu* submenu = m->item(index)->menu();
if (submenu == nil) {
break;
}
m = submenu;
}
if (index >= 0) {
GlyphIndex top_index = selected();
TelltaleState* top_t = item(top_index)->state();
Resource::ref(top_t);
top_t->set(TelltaleState::is_running, true);
impl_->ungrab(this, e);
Canvas* c = canvas();
if (c != nil) {
impl_->restore_cursor(c);
}
unselect();
MenuItem* mi = m->item(index);
TelltaleState* t = mi->state();
Action* a = mi->action();
if (t != nil && t->test(TelltaleState::is_enabled)) {
bool act = !t->test(TelltaleState::is_chosen);
if (t->test(TelltaleState::is_toggle)) {
t->set(TelltaleState::is_chosen, act);
act = true;
} else if (t->test(TelltaleState::is_choosable)) {
t->set(TelltaleState::is_chosen, true);
}
if (act && a != nil) {
a->execute();
}
}
top_t->set(TelltaleState::is_running, false);
Resource::unref(top_t);
} else {
/*
* If we hit an item with a submenu, then we leave
* the submenu open (with item 0 selected), grab, and return.
*/
Canvas* c;
Menu* submenu;
for (m = this, c = canvas(); c != nil; m = submenu, c = m->canvas()) {
Window* w = c->window();
Hit hit(
e.pointer_root_x() - w->left(),
e.pointer_root_y() - w->bottom()
);
m->pick(c, m->allocation(), 0, hit);
if (hit.any()) {
m = m->item(hit.index(0))->menu();
if (m != nil) {
m->select(0);
#if 0 && defined(WIN32)
//twice clicking on a menu that opens a submenu gets it into a state
//where it is hard to close except by clicking on a submenu item and
//dragging the mouse off the subment and releasing.
// or clicking on any neuron window. Unfortunately, this fix broke the
// ability to click on an item with submenus and have the submenu persist.
// Therefore we are backing out of it.
impl_->ungrab(this, e);
#endif
impl_->grab(this, e);
return;
}
break;
}
submenu = m->impl_->selected_menu();
if (submenu == nil) {
break;
}
}
impl_->ungrab(this, e);
c = canvas();
if (c != nil) {
impl_->restore_cursor(c);
}
unselect();
}
}