#include #include #include #include #include #include #include "menudialogs.h" FileDialog::FileDialog(RSLBrowser* browser) { this->browser = browser; lastfile = null; choice = null; } bool FileDialog::Accept(const char* startfile, const char* msg) { FileChooser* fc = new FileChooser("Select a file:", msg ? msg : "\0", startfile); World* w = browser->GetWorld(); bool a; w->InsertTransient(fc, browser, 500, 500); a = fc->Accept(); if (choice) delete choice; choice = newstr(fc->Choice()); w->Remove(fc); delete fc; return a; } const char* FileDialog::ChooseFile(const char* prevfile, const char* msg) { /* * Entry point from File.Open and File.SaveAs menu items. */ if (Accept(prevfile ? prevfile : "\0")) return choice; else return null; } FileListDialog::FileListDialog(RSLBrowser* browser) { this->browser = browser; } bool FileListDialog::Accept() { return true; } const char* FileListDialog::ChooseFile() { /* * Entry point from File.Close and File.Expose menu items. */ if (Accept()) return choice; else return null; } SearchDialog::SearchDialog(RSLBrowser* browser, char* msg) { lastsearch = null; this->msg = msg; choice = null; this->browser = browser; } bool SearchDialog::Accept() { if (lastsearch == nil) { lastsearch = new StringDialog(msg, round(3*inches)); } World* w = browser->GetWorld(); bool a; w->InsertTransient(lastsearch, browser, 500, 500); a = lastsearch->Accept(); choice = lastsearch->String(); w->Remove(lastsearch); return a; } const char* SearchDialog::ChooseSearchString() { /* * Entry point from Search.Open menu item. */ if (Accept()) return choice; else return null; } /*****************************************************************************/ static const float fspace = .375; // space in cm /*****************************************************************************/ BasicDialog::BasicDialog () : Dialog(new ButtonState, nil) { input = new Sensor; input->Catch(KeyEvent); input->Reference(); } bool BasicDialog::Accept () { Event e; int v = 0; state->SetValue(0); do { Read(e); if (!KeyEquiv(e)) { Forward(e); } state->GetValue(v); } while (v == 0); return v == '\r'; } void BasicDialog::Forward (Event& e) { Coord x = e.x, y = e.y; e.target->GetRelative(x, y, this); if (x >= 0 && y >= 0 && x <= xmax && y <= ymax) { e.target->Handle(e); } } bool BasicDialog::KeyEquiv (Event& e) { bool keyEquiv = false; if (e.eventType == KeyEvent && e.len > 0) { char c = e.keystring[0]; if (c == '\r' || c == '\007' || c == '\033') { state->SetValue(c); keyEquiv = true; } } return keyEquiv; } /*****************************************************************************/ AcknowledgeDialog::AcknowledgeDialog (const char* msg, const char* btnLbl) { int space = round(fspace*cm); Insert( new MarginFrame( new VBox( new Message(msg), new VGlue(space, space, 0), new HBox( new HGlue, new PushButton(btnLbl, state, '\r'), new HGlue ) ), space, space, 0 ) ); } void AcknowledgeDialog::Acknowledge () { Event e; int v = 0; state->SetValue(v); do { Read(e); if (!KeyEquiv(e)) { Forward(e); } state->GetValue(v); } while (v == 0); } /*****************************************************************************/ ConfirmDialog::ConfirmDialog (const char* msg, const char* confirmLbl) { int space = round(fspace*cm); Insert( new MarginFrame( new VBox( new Message(msg), new VGlue(space, space, 0), new HBox( new HGlue, new PushButton(confirmLbl, state, '\r'), new HGlue(space, space, 0), new PushButton(" Cancel ", state, '\007'), new HGlue ) ), space, space, 0 ) ); } /*****************************************************************************/ StringDialog::StringDialog ( const char* msg, const char* sample, const char* confirmLbl ) { Init(msg, confirmLbl); _sedit->Message(sample); } StringDialog::StringDialog ( const char* msg, int width, const char* confirmLbl ) { Init(msg, confirmLbl, width); } void StringDialog::Select () { _sedit->Select(0, strlen(_sedit->Text())); } void StringDialog::Select (int pos) { _sedit->Select(pos); } void StringDialog::Select (int left, int right) { _sedit->Select(left, right);} void StringDialog::Init (const char* msg, const char* confirmLbl, int width) { int space = round(fspace*cm); _sedit = new StringEditor(state, ""); HBox* framedSedit = new HBox; if (width == 0) { framedSedit->Insert(_sedit); } else { framedSedit->Insert(new HGlue); framedSedit->Insert( new VBox( new Frame(new MarginFrame(_sedit, 2)), new HGlue(width, 0, 0) ) ); framedSedit->Insert(new HGlue); } Insert( new MarginFrame( new VBox( new Message(msg), new VGlue(space, space, 0), framedSedit, new VGlue(space, space, 0), new HBox( new HGlue, new PushButton(confirmLbl, state, '\r'), new HGlue(space, space, 0), new PushButton(" Cancel ", state, '\007') ) ), space, space, 0 ) ); } const char* StringDialog::String () { return _sedit->Text(); } bool StringDialog::Accept () { Event e; int v = 0; state->SetValue(0); Select(); _sedit->Edit(); for (;;) { state->GetValue(v); if (v != 0) { break; } Read(e); if (!KeyEquiv(e)) { Forward(e); } } return v == '\r'; }