Пример #1
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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();
    }
}
Пример #11
0
int main(int argc, char** argv) {
    Session* session = new Session("Forms demo", argc, argv, options, properties);
    WidgetKit& wk = *WidgetKit::instance();
    LayoutKit& lk = *LayoutKit::instance();

    PolyGlyph * mainglyph = lk.vbox();
    ApplicationWindow * mainwin = new ApplicationWindow(mainglyph);

    ObservableBoolean* obsb = new ObservableBoolean();
    StringList* list = new StringList;
    String* str_i;
    str_i = new String("Athos   ");
    list->append(*str_i);
    str_i = new String("Porthos ");
    list->append(*str_i);
    str_i = new String("Aramis  ");
    list->append(*str_i);
    ObservableEnum* obse = new ObservableEnum(list);
    BoundedValue* bdv = new BoundedValue(0.0, 100.0, 5.0, 10.0, 50.0);
    ObservableText* obst = new ObservableText("any text");

    App * tryme = new App(mainwin, obsb, obse, bdv, obst);

    BooleanObserver* bview = new BooleanObserver(obsb,"Boolean Value: ");
    EnumObserver* eview = new EnumObserver(obse, "Enum Value: ");
    BoundedValueObserver* bdview = new BoundedValueObserver(bdv,
							    "Bounded Float Value: ");
    TextObserver* txtview = new TextObserver(obst, "Text 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 *post = wk.menubar_item("Edit");
    post->action(new ActionCallback(App)(tryme, &App::post_it));
    top_menu->append_item(post);

    mainglyph->append(
	new Background(
	    lk.vbox(
		top_menu,
		lk.natural(
		    lk.tmargin(
			lk.lmargin(
			    lk.vbox(
				bview,
				lk.vspace(10),
				eview,
				lk.vspace(10),
				bdview,
				lk.vspace(10),
				txtview
			    ),
			    10
			),
			10
		    ),
		    200, 200
		)
	    ),
	    wk.background()
	)
    );

    return session->run_window(mainwin);
}