Example #1
0
// following doesn't work correctly yet
void OcViewGlyph::viewmenu(Glyph* m) {
	printf("OcViewGlyph::viewmenu()\n");
	if (!g_) {
		g_ = body();
		Resource::ref(g_);
		LayoutKit& lk = *LayoutKit::instance();
		WidgetKit& wk = *WidgetKit::instance();
		PolyGlyph* hbox = lk.hbox(2);
		hbox->append(lk.center(m, 0, 1));
		hbox->append(lk.center(view(), 0, 1));
		body(hbox);
		printf("add menu\n");
	}else{
		printf("delete menu\n");
		body(g_);
		Resource::unref(g_);
		g_ = NULL;
	}
}
Example #2
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);

}
Example #3
0
void Text31::init () {
    LayoutKit* layout = LayoutKit::instance();
    PolyGlyph* col = layout->vbox();
    PolyGlyph* line = layout->hbox();
    FontBoundingBox bbox;
    _font->font_bbox(bbox);
    Coord lineheight = bbox.ascent() + bbox.descent();
    char ch;
    
    for (int i = 0; (*_text)[i] != '\0'; i++) {
        ch = (*_text)[i];

        if (ch == '\n') {
            line->append(layout->strut(_font));
            col->append(layout->fixed_dimension(line, Dimension_Y,lineheight));
            line = layout->hbox();
        } else if (ch == ' ') {
            line->append(new Character(' ', _font, _stroke));
        } else if (ch != ')' && ch != '(') {
            if (ch == '\\') {
                ch = (*_text)[++i];
                if (isdigit(ch)) {
                    ch -= '0';
                    ch *= 8;
                    char digit;
                    digit = (*_text)[i++];
                    ch = (ch * 8) + digit - '0';
                    digit = (*_text)[i++];
                    ch = (ch * 8) + digit - '0';
                }
            }
            line->append(new Character(ch, _font, _stroke));
        }
    }

    Transformer fixtext;
    fixtext.translate(0, bbox.descent());
    _t->premultiply(fixtext);
    _body->append(col);
}
Example #4
0
Glyph* read_idraw_graphic (
    FILE* file, const Brush* pb, const Color* pfg, const Color* pbg,
    const Font* pf, Stipple* ps
) {
    skip(file);
    Transformer tx;
    Glyph* glyph = nil;
    const LayoutKit& layout = *LayoutKit::instance();
    if (fscanf(file, "%s", buffer) != EOF) {
        figure& fig = figures[which(figures, buffer)];

        if (strcmp(fig.name, "Idraw") == 0) {
            fscanf(file, "%d", &drawing_version);
            figures = versions[drawing_version];
        }
        const Brush* b = (fig.brush) ? read_brush(file) : nil;
        const Color* fg = (fig.foreground) ? read_color(file) : nil;
        const Color* bg = (fig.background) ? read_color(file) : nil;
        const Font* f = (fig.font) ? read_font(file) : nil;
        Stipple* s = (fig.pattern) ? read_stipple(file) : nil;
        if (fig.transformer) {
            read_transformer(file, tx);
        }

        if (pb) b = pb;
        if (pfg) fg = pfg;
        if (pbg) bg = pbg;
        if (pf) f = pf;
        if (ps) s = ps;

        if (fig.name == nil) {
            ; // error
        } else if (
            strcmp(fig.name, "Idraw") == 0 || strcmp(fig.name, "Pict") == 0
        ) {
            Glyph* pic = layout.overlay();
            Glyph* g;
            do {
                g = read_idraw_graphic(file, b, fg, bg, f, s);
                if (g != nil) {
                    pic->append(g);
                }
            } while (g != nil);
            glyph = pic;
        } else if (strcmp(fig.name, "eop") == 0) {
            glyph = nil;
        } else if (strcmp(fig.name, "Text") == 0) {
            skip(file);
            fscanf(file, "%s", buffer);
            getc(file);
            PolyGlyph* col = layout.vbox_first_aligned();
            PolyGlyph* line = layout.hbox_first_aligned();
	    FontBoundingBox bbox;
	    f->font_bbox(bbox);
            Coord lineheight = bbox.font_ascent() + bbox.font_descent();
            if (_idraw_font_metrics) {
                lineheight /= fixtextscale;
            }
            int c;
            while ((c = getc(file)) != ']') {
                if (c == '\n') {
                    line->append(layout.strut(f));
                    col->append(
			layout.v_fixed_span(line, lineheight)
		    );
                    line = layout.hbox();
                } else if (c == ' ') {
                    if (_idraw_font_metrics) {
                        line->append(
			    layout.shape_of(new Character(' ', f, fg))
			);
                    } else {
                        line->append(new Character(' ', f, fg));
                    }
                } else if (c != ')' && c != '(') {
                    if (c == '\\') {
                        c = getc(file);
			if (isdigit(c)) {
			    c -= '0';
			    c = (c * 8) + getc(file) - '0';
			    c = (c * 8) + getc(file) - '0';
			}
                    }
                    line->append(new Character(c, f, fg));
                }
            }
            Transformer fixtext;
            if (_idraw_font_metrics) {
                fixtext.scale(fixtextscale, fixtextscale);
            }
            fixtext.translate(0, bbox.font_descent() - lineheight);
            glyph = new TransformSetter(col, fixtext);
        } else {
            skip(file);
            int c = fig.coords;
            if (c == -1) { 
                fscanf(file, "%d", &c);
            }
            Coord xx, yy;
            Coord* x = new Coord[c];
            Coord* y = new Coord[c];
            for (int i = 0; i < c; ++i) {
                fscanf(file, "%g %g", &xx, &yy);
                x[i] = xx;
                y[i] = yy;
            }

            const Brush* brush = (b != no_brush) ? b : nil;
            const Color* stroke = fg;
            const Color* fill = (
                (s != no_stipple) ? dither_color(fg, bg, s->_dither) : nil
            );
            if (strcmp(fig.name, "Line") == 0) {
                glyph = new Line(brush, stroke, fill, x[0], y[0], x[1], y[1]);
            } else if (strcmp(fig.name, "BSpl") == 0) {
                glyph = new Open_BSpline(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "CBSpl") == 0) {
                glyph = new Closed_BSpline(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "MLine") == 0) {
                glyph = new Polyline(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "Poly") == 0) {
                glyph = new Polygon(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "Rect") == 0) {
                glyph = new Rectangle(brush, stroke, fill,x[0],y[0],x[1],y[1]);
            } else if (strcmp(fig.name, "Circ") == 0) {
                fscanf(file, "%f", &xx);
                glyph = new Circle(brush, stroke, fill, x[0], y[0], xx);
            } else if (strcmp(fig.name, "Elli") == 0) {
                fscanf(file, "%f %f", &xx, &yy);
                glyph = new Ellipse(brush, stroke, fill, x[0], y[0], xx, yy);
            } else {
                glyph = nil;
            }
            delete x;
            delete y;
        }
        for (int extra = fig.skip; extra > 0; --extra) {
            skip(file);
        }
    }
    if (glyph != nil && !tx.identity()) {
        glyph = new TransformSetter(glyph, tx);
    }
    return glyph;
}
Example #5
0
void FrameKit::InitLayout(OverlayKit* kit, const char* name) {
    FrameEditor* ed = (FrameEditor*) kit->GetEditor();
    Catalog* catalog = unidraw->GetCatalog();
    const char* stripped_string = catalog->GetAttribute("stripped");
    boolean stripped_flag = stripped_string ? strcmp(stripped_string, "true")==0 : false;
    if (ed->GetWindow() == nil) {
        TextObserver* mousedoc_observer = new TextObserver(ed->MouseDocObservable(), "");
	WidgetKit& wk = *WidgetKit::instance();
	const LayoutKit& layout = *LayoutKit::instance();
	PolyGlyph* topbox = layout.vbox();

	Glyph* menus = kit->MakeMenus();
	Glyph* states = kit->MakeStates();
	Glyph* toolbar = kit->MakeToolbar();

	if (stripped_flag) {

	  Target* viewer = 
	    new Target(new Frame(ed->Interior()), TargetPrimitiveHit);
	  ed->body(viewer);
	  topbox->append(ed);

	} else {
	  if (states)
	    menus->append(states);
	  Target* viewer = 
	    new Target(new Frame(kit->Interior()), TargetPrimitiveHit);
	  Catalog* catalog = unidraw->GetCatalog();
	  if (const char* toolbarloca = catalog->GetAttribute("toolbarloc")) {
	    if (strcmp(toolbarloca, "r") == 0) 
	      toolbar->prepend(layout.vcenter(viewer));
	    else /* if (strcmp(toolbarloca, "l") == 0) */
	      toolbar->append(layout.vcenter(viewer));
	  } else 
	    toolbar->append(layout.vcenter(viewer));
	  menus->append(toolbar);
	  
	  
	  Style* style = Session::instance()->style();
	  boolean bookgeom = style->value_is_on("bookgeom");
	  
	  ed->body(menus);
	  ed->GetKeyMap()->Execute(CODE_SELECT);
	  topbox->append(ed);
	  if (!bookgeom) {
	    boolean set_flag = kit->set_button_flag();
	    boolean clr_flag = kit->clr_button_flag();
	    EivTextEditor* texteditor = nil;
	    if(!set_flag && !clr_flag) {
	      texteditor = new ComTextEditor(wk.style(), ed->comterp());
	    }
	    else
	      texteditor = new EivTextEditor(wk.style());
	    ((FrameEditor*)ed)->_texteditor = texteditor;
	    Button* set = set_flag ? 
	      wk.push_button("Set", new ActionCallback(FrameEditor)
			     ((FrameEditor*)ed, &FrameEditor::SetText)) : 
	      nil;
	    Button* clear = clr_flag ? 
	      wk.push_button("Clear", new ActionCallback(FrameEditor)
			     ((FrameEditor*)ed, &FrameEditor::ClearText)) : 
	      nil;
	    Glyph* buttonbox = nil;
	    if (set && !clear) {
	      buttonbox = 
		layout.vbox(layout.hcenter(set));
	    } else if (!set && clear) { 
	      buttonbox = 
		layout.vbox(layout.hcenter(clear));
	    } else if (set && clear) {
	      buttonbox = 
		layout.vbox(
			    layout.hcenter(set),
			    layout.vspace(10),
			    layout.hcenter(clear)
			    );
	    }
	    if (buttonbox) {
	      topbox->append(
		wk.outset_frame(
		  layout.hbox(
		    layout.vcenter(
		      layout.margin(
			buttonbox,
			10
		      )
		    ),
   		    layout.vcenter(texteditor)
		  )
   	        )
	      );
	    } else {
	      topbox->append(
   	        wk.outset_frame(
		  layout.hbox(
		    layout.vcenter(
		      layout.margin(
			layout.vbox(
#if 0
			  wk.label("type help"),
			  layout.vspace(10),
			  wk.label("to print"),
			  layout.vspace(10),
		          wk.label("info to stdout")
#else
			  kit->appicon()
#endif
		        ),
			10
		      )
   		    ),
  		    layout.vcenter(texteditor)
		  )
   	        )
	      );
	    }
	  }
	}
	  
	ManagedWindow* w = new ApplicationWindow(topbox);
	ed->SetWindow(w);
	Style* s = new Style(Session::instance()->style());
	s->alias(name);
	w->style(s);
    }
}
Example #6
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);
}
Example #7
0
void SymChooserImpl::build() {
    WidgetKit& kit = *kit_;
    const LayoutKit& layout = *LayoutKit::instance();
    Style* s = style_;
    kit.push_style();
    kit.style(s);
    String caption("");
    s->find_attribute("caption", caption);
    String subcaption("Enter  Symbol name:");
    s->find_attribute("subcaption", subcaption);
    String open("Accept");
    s->find_attribute("open", open);
    String close("Cancel");
    s->find_attribute("cancel", close);
    long rows = 10;
    s->find_attribute("rows", rows);
    const Font* f = kit.font();
    FontBoundingBox bbox;
    f->font_bbox(bbox);
    Coord height = rows * (bbox.ascent() + bbox.descent()) + 1.0;
    Coord width;
    if (!s->find_attribute("width", width)) {
	width = 16 * f->width('m') + 3.0;
    }

    int i;
    Action* accept = new ActionCallback(SymChooserImpl)(
	this, &SymChooserImpl::accept_browser
    );
    Action* cancel = new ActionCallback(SymChooserImpl)(
	this, &SymChooserImpl::cancel_browser
    );
    editor_ = DialogKit::instance()->field_editor(
	"", s,
	new FieldEditorCallback(SymChooserImpl)(
	    this, &SymChooserImpl::editor_accept, nil
	)
    );
    browser_index_ = 0;
    for (i=0; i < nbrowser_; ++i) {
	fbrowser_[i] = new FileBrowser(kit_,
		new SymBrowserAccept(this, i),
		nil);
    }
    fchooser_->remove_all_input_handlers();
    fchooser_->append_input_handler(editor_);
	for (i=0; i < nbrowser_; ++i) {
	    fchooser_->append_input_handler(fbrowser_[i]);
	}
    fchooser_->next_focus();

    Glyph* g = layout.vbox();
    if (caption.length() > 0) {
	g->append(layout.r_margin(kit.fancy_label(caption), 5.0, fil, 0.0));
    }
    if (subcaption.length() > 0) {
	g->append(layout.r_margin(kit.fancy_label(subcaption), 5.0, fil, 0.0));
    }
    g->append(layout.vglue(5.0, 0.0, 2.0));
    g->append(editor_);
    g->append(layout.vglue(5.0, 0.0, 2.0));
    g->append(makeshowmenu());
    g->append(layout.vglue(15.0, 0.0, 12.0));
    PolyGlyph* h = layout.hbox(nbrowser_);
    Glyph* b;
    for (i=0; i < nbrowser_; ++i) {
     b = layout.hbox(
	    layout.vcenter(
		kit.inset_frame(
		    layout.margin(
			layout.natural_span(fbrowser_[i], width, height), 1.0
		    )
		),
		1.0
	    ),
	    layout.hspace(4.0),
	    kit.vscroll_bar(fbrowser_[i]->adjustable())
	);
      h->append(b);
    }
    g->append(h);
    g->append(layout.vspace(15.0));
    if (s->value_is_on("filter")) {
	FieldEditorAction* action = new FieldEditorCallback(SymChooserImpl)(
	    this, &SymChooserImpl::filter_accept, nil
	);
	filter_ = add_filter(
	    s, "filterPattern", "", "filterCaption", "Filter:", g, action
	);
	if (s->value_is_on("directoryFilter")) {
	    directory_filter_ = add_filter(
		s, "directoryFilterPattern", "",
		"directoryFilterCaption", "Name Filter:", g, action
	    );
	} else {
	    directory_filter_ = nil;
	}
    } else {
	filter_ = nil;
	directory_filter_ = nil;
    }
    g->append(
	layout.hbox(
	    layout.hglue(10.0),
	    layout.vcenter(kit.default_button(open, accept)),
	    layout.hglue(10.0, 0.0, 5.0),
	    layout.vcenter(kit.push_button(close, cancel)),
	    layout.hglue(10.0)
	)
    );

    fchooser_->body(
	layout.vcenter(kit.outset_frame(layout.margin(g, 5.0)), 1.0)
    );
    kit.pop_style();
    load(0);
}
Example #8
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);
}