/**** * * Implementation of found-dialog.h. * */ #include "card-list.h" #include "font-by-name.h" #include "found-cards-dialog.h" #include "label.h" #include "read-only-str-editor.h" #include #include #include #include #include FoundCardsDialog::FoundCardsDialog(Rolodex* r, RolodexMenuUI* rmui) : View(NULL, r) { /* * Construct the found cards buttons object. It contains the Next, * Previous, and Done buttons. */ fcb = new FoundCardsButtons(r, this, rmui); } void FoundCardsDialog::Compose() { /* * Make the window of this a VBox, which is an InterViews composite * interactor box with vertical layout. Set the vbox alignment to center. */ w = new VBox(); ((VBox*) w)->Align(Center); /* * Stick some stretchable glue spacing above the prompting message. */ ((VBox*) w)->Insert(new VGlue(round(0.20 * inch), 0, round(0.50 * inch))); /* * Allocate the boxes and string editor for the two-line message at the top * of the dialog. */ hb1 = new HBox(); hb2 = new HBox(); sen = new ReadOnlyStringEditor(" ", new FontByName("times", "bold", "r", 14)); sei = new ReadOnlyStringEditor(" ", new FontByName("times", "bold", "r", 14)); /* * Compose and insert the two-line message. */ ComposeTopMessages(); ((VBox*) w)->Insert(hb1); ((VBox*) w)->Insert(hb2); /* * Stick some stretchable glue spacing between the message and the field * editors below. */ ((VBox*) w)->Insert(new VGlue(round(0.20 * inch), 0, round(0.50 * inch))); /* * Allocate the vboxes for the labels and string editors plus the hbox that * holds them both. The outer box forces proper alignment. */ vblabels = new VBox(); vbseds = new VBox(); hbouter = new HBox(); /* * Construct a new read-only string editor for each card field. */ ConstructEditors(); /* * Compose the message boxes and card field boxes and stick them in a * stretchable vbox. */ ComposeLabels(); ComposeEditors(); ComposeOuter(); /* * Insert the outer hbox into this' window. */ ((VBox*)w)->Insert(hbouter); /* * Compose the dialog buttons and insert into the window. */ fcb->Compose(); ((VBox*)w)->Insert(new VGlue(round(0.2 * inch), 0, vfil)); ((VBox*)w)->Insert(fcb->GetWindow()); ((VBox*)w)->Insert(new VGlue(round(0.2 * inch), 0, vfil)); } void FoundCardsDialog::ComposeTopMessages() { hb1->Align(Center); hb2->Align(Center); sen->GetShape()->Rigid(); sei->GetShape()->Rigid(); hb1->Insert(sen); hb1->Insert(new Label("card(s) of the given name found.", "times", "bold", "r", 14)); hb2->Insert(new Label("Here is card ", "times", "bold", "r", 14)); hb2->Insert(sei); hb2->Insert(new Label(":", "times", "bold", "r", 14)); } void FoundCardsDialog::ConstructEditors() { sename = new ReadOnlyStringEditor(" "); seid = new ReadOnlyStringEditor(" "); seage = new ReadOnlyStringEditor(" "); sesex = new ReadOnlyStringEditor(" "); seaddr = new ReadOnlyStringEditor(" "); } void FoundCardsDialog::ComposeLabels() { vblabels->Align(Right); vblabels->Insert(new VGlue(round(0.10*inch), 0, vfil)); vblabels->Insert(new Label("Name: ", "times", "bold", "r", 14)); vblabels->Insert(new VGlue(round(0.10*inch), 0, vfil)); vblabels->Insert(new Label("Id: ", "times", "bold", "r", 14)); vblabels->Insert(new VGlue(round(0.10*inch), 0, vfil)); vblabels->Insert(new Label("Age: ", "times", "bold", "r", 14)); vblabels->Insert(new VGlue(round(0.10*inch), 0, vfil)); vblabels->Insert(new Label("Sex: ", "times", "bold", "r", 14)); vblabels->Insert(new VGlue(round(0.10*inch), 0, vfil)); vblabels->Insert(new Label("Address: ", "times", "bold", "r", 14)); vblabels->Insert(new VGlue(round(0.10*inch), 0, vfil)); } void FoundCardsDialog::ComposeEditors() { /* * The shawdow frames provide the string editor border. By default a * string editor has no visible border. */ vbseds->Align(Right); vbseds->Insert(new VGlue(round(0.10*inch), 0, vfil)); vbseds->Insert(new ShadowFrame(sename)); vbseds->Insert(new VGlue(round(0.10*inch), 0, vfil)); vbseds->Insert(new ShadowFrame(seid)); vbseds->Insert(new VGlue(round(0.10*inch), 0, vfil)); vbseds->Insert(new ShadowFrame(seage)); vbseds->Insert(new VGlue(round(0.10*inch), 0, vfil)); vbseds->Insert(new ShadowFrame(sesex)); vbseds->Insert(new VGlue(round(0.10*inch), 0, vfil)); vbseds->Insert(new ShadowFrame(seaddr)); vbseds->Insert(new VGlue(round(0.10*inch), 0, vfil)); } void FoundCardsDialog::ComposeOuter() { hbouter->Insert(new HGlue, round(0.25 * inch), hfil, hfil); hbouter->Insert(vblabels); hbouter->Insert(vbseds); hbouter->Insert(new HGlue, round(0.25 * inch), hfil, hfil); } void FoundCardsDialog::ShowResults(CardList* cl) { /* * Clear transient model data in case it has been previously set. This is * possible given non-model behavior of the UI, wherein the user is not * required to press the Done button in the found cards dialog. */ if (this->cl) delete this->cl; /* * Temporarily store the transient model data for display purposes. */ this->cl = cl; /* * Initialize the current card index to 0. */ curindex = 0; /* * Set the value of N in the "N cards found ..." message. */ ShowNumberOfCards(this->cl->Len()); /* * Call Next (with a 0 current index) to display the first card. */ Next(); } void FoundCardsDialog::ShowNumberOfCards(int n) { String* s = new String(n); sen->Message(s->ConstConvert()); delete s; } void FoundCardsDialog::ShowWhichCard(int i) { String* s = new String(i); sei->Message(s->ConstConvert()); delete s; } void FoundCardsDialog::Next() { if (curindex < cl->Len()) { ShowWhichCard(++curindex); ShowCardData(cl->GetNth(curindex)); } } void FoundCardsDialog::Previous() { if (curindex > 1) { ShowWhichCard(--curindex); ShowCardData(cl->GetNth(curindex)); } } void FoundCardsDialog::ShowCardData(Card* c) { String* idstr = new String(c->GetId()); String* agestr = new String(c->GetAge()); String* sexstr = r->SexToString(c->GetSex()); sename->Message(c->GetName()->ConstConvert()); seid->Message(idstr->ConstConvert()); seage->Message(agestr->ConstConvert()); sesex->Message(sexstr->ConstConvert()); seaddr->Message(c->GetName()->ConstConvert()); delete idstr; delete agestr; delete sexstr; } void FoundCardsDialog::Done() { if (cl) { delete cl; cl = NULL; } }