/* * a Dialog for browsing fonts */ #include "fontbrowser.h" #include "fontsample.h" #include #include #include #include #include #include #include class ButtonChoice { public: const char* label; void* value; }; static ButtonChoice ModeChoices[] = { { "family", "family" }, { "name", "name" }, { nil } }; static ButtonChoice FamilyChoices[] = { { "helvetica", "helvetica" }, { "times", "times" }, { nil } }; static ButtonChoice WeightChoices[] = { { "medium", "medium" }, { "bold", "bold" }, { nil } }; static ButtonChoice SlantChoices[] = { { "roman", "r" }, { "oblique", "o" }, { "italic", "i" }, { nil } }; static ButtonChoice PointChoices[] = { { "24 point", "24" }, { "18 point", "18" }, { "14 point", "14" }, { "12 point", "12" }, { nil } }; static Interactor* ButtonBox ( const char* name, ButtonState* state, ButtonChoice* choices ) { HBox* box = new HBox(); box->Align(Center); for (int i = 0; choices[i].label != nil; ++i) { box->Insert( new RadioButton(name, choices[i].label, state, choices[i].value) ); box->Insert(new HGlue(round(0.05*inch), round(0.05*inch), 0)); } return box; } FontBrowser::FontBrowser (ButtonState* s, const char* samp) : (s, nil) { Init(samp); } FontBrowser::FontBrowser ( const char* name, ButtonState* s, const char* samp ) : (s, nil) { SetInstance(name); Init(samp); } FontBrowser::~FontBrowser () { delete family; delete weight; delete slant; delete point; delete fontname; } void FontBrowser::Init (const char* samp) { SetClassName("FontBrowser"); family = new ButtonState(FamilyChoices[0].value); weight = new ButtonState(WeightChoices[0].value); slant = new ButtonState(SlantChoices[0].value); point = new ButtonState(PointChoices[0].value); sample = new FontSample(samp); Insert( new HBox( new HGlue(round(0.5*inch), round(0.4*inch), round(2.0*inch)), new VBox( new VGlue(round(0.3*inch), round(0.2*inch), round(1.0*inch)), sample, new VGlue(round(0.3*inch), round(0.2*inch), 0), new HBox( new VBox( new HBox( new Message("label", "Family"), new HGlue(round(0.2*inch), round(0.1*inch)), ButtonBox("choice", family, FamilyChoices) ), new VGlue(round(0.05*inch), round(0.05*inch), 0), new HBox( new Message("label", "Weight"), new HGlue(round(0.2*inch), round(0.1*inch)), ButtonBox("choice", weight, WeightChoices) ), new VGlue(round(0.05*inch), round(0.05*inch), 0), new HBox( new Message("label", "Slant"), new HGlue(round(0.2*inch), round(0.1*inch)), ButtonBox("choice", slant, SlantChoices) ), new VGlue(round(0.05*inch), round(0.05*inch), 0), new HBox( new Message("label", "Size"), new HGlue(round(0.2*inch), round(0.1*inch)), ButtonBox("choice", point, PointChoices) ) ), new HGlue(round(0.3*inch), round(0.2*inch), hfil), new PushButton("Quit", state, true) ), new VGlue(round(0.3*inch), round(0.2*inch), round(1.0*inch)) ), new HGlue(round(0.5*inch), round(0.4*inch), round(2.0*inch)) ) ); fontname = new char[1000]; UpdateFontname(); } const char* FontBrowser::Fontname () { return fontname; } boolean FontBrowser::Accept () { Event e; int v; state->SetValue(0); do { Read(e); e.target->Handle(e); UpdateFontname(); state->GetValue(v); } while (v == 0 && e.target != nil); return v == 1 || e.target == nil; } void FontBrowser::UpdateFontname () { void* v; family->GetValue(v); const char* fam = (char*)v; weight->GetValue(v); const char* wgt = (char*)v; slant->GetValue(v); const char* sl = (char*)v; point->GetValue(v); const char* pnt = (char*)v; sprintf(fontname, "*-*-%s-%s-%s-normal-*-*-%s0-*-*-*-*-iso8859-1", fam, wgt, sl, pnt ); sample->ShowFont(Fontname()); }