home *** CD-ROM | disk | FTP | other *** search
- #include <IV-look/kit.h>
- #include <IV-look/menu.h>
- #include <InterViews/action.h>
- #include <InterViews/background.h>
- #include <InterViews/box.h>
- #include <InterViews/place.h>
- #include <InterViews/session.h>
- #include <InterViews/style.h>
- #include <InterViews/window.h>
- #include <stdio.h>
-
- struct CmdInfo;
-
- class App {
- public:
- void open(), save(), quit();
-
- void cut();
- void copy();
- void paste();
-
- void black();
- void red();
- void green();
- void blue();
-
- Menu* menubar(CmdInfo*, Kit*, Style*);
- private:
- Menu* pulldown(CmdInfo*, int, Kit*, Style*);
- };
-
- declare(ActionCallback,App);
- implement(ActionCallback,App);
-
- struct CmdInfo {
- const char* str;
- ActionMemberFunction(App)* func;
- CmdInfo* submenu;
- int options;
- };
-
- CmdInfo filemenu[] = {
- { "Open", &App::open },
- { "Save", &App::save },
- { "", nil },
- { "Quit", &App::quit },
- { nil }
- };
-
- CmdInfo editmenu[] = {
- { "Cut", &App::cut },
- { "Copy", &App::copy },
- { "Paste", &App::paste },
- { nil }
- };
-
- CmdInfo colormenu[] = {
- { "Black", &App::black },
- { "Red", &App::red },
- { "Green", &App::green },
- { "Blue", &App::blue },
- { nil }
- };
-
- CmdInfo bar[] = {
- { "File", nil, filemenu, 0 },
- { "Edit", nil, editmenu, 1 },
- { "Color", nil, colormenu, 2 },
- { nil }
- };
-
- void App::open() { printf("open\n"); }
- void App::save() { printf("save\n"); }
- void App::quit() { Session::instance()->quit(); }
-
- void App::cut() { printf("cut\n"); }
- void App::copy() { printf("copy\n"); }
- void App::paste() { printf("paste\n"); }
-
- void App::black() { printf("black\n"); }
- void App::red() { printf("red\n"); }
- void App::green() { printf("green\n"); }
- void App::blue() { printf("blue\n"); }
-
- Menu* App::menubar(CmdInfo* info, Kit* kit, Style* style) {
- Menu* m = kit->menubar(style);
- for (CmdInfo* i = info; i->str != nil; i++) {
- m->add_item(
- kit->menubar_item(
- kit->fancy_label(i->str, style),
- style
- ),
- pulldown(i->submenu, i->options, kit, style)
- );
- }
- m->menu(0)->telltale(1)->set(Telltale::is_enabled, false);
-
- return m;
- }
-
- Menu* App::pulldown(CmdInfo* info, int opt, Kit* k, Style* s) {
- Menu* m = k->pulldown(s);
- TelltaleGroup* group = nil;
- for (CmdInfo* i = info; i->str != nil; i++) {
- if (i->str[0] == '\0') {
- m->add_item(k->menu_item_separator(s));
- } else {
- Glyph* g = new RMargin(
- k->fancy_label(i->str, s), 0.0, fil, 0.0
- );
- Telltale* t;
- switch (opt) {
- case 1:
- t = k->toggle_menu_item(g, s);
- break;
- case 2:
- if (group == nil) {
- group = new TelltaleGroup;
- }
- t = k->radio_menu_item(group, g, s);
- break;
- default:
- t = k->menu_item(g, s);
- break;
- }
- if (i->func == nil && i->submenu != nil) {
- m->add_item(t, pulldown(i->submenu, i->options, k, s));
- } else {
- m->add_item(t, new ActionCallback(App)(this, i->func));
- }
- }
- }
- return m;
- }
-
- int main(int argc, char** argv) {
- Session* session = new Session("Himom", argc, argv);
- Style* style = session->style();
- Kit* kit = Kit::instance();
- App* a = new App;
- return session->run_window(
- new ApplicationWindow(
- new Background(
- new Margin(a->menubar(bar, kit, style), 10.0),
- style->flat()
- )
- )
- );
- }
-