/**** * * Implementation of add-dialog-card.h * */ #include "add-card-dialog.h" #include "card.h" #include "label.h" #include "rolodex.h" #include #include #include #include #include AddCardDialog::AddCardDialog(Rolodex* r, RolodexMenuUI* rmui) : View(NULL, r) { /* * Construct the add card buttons object. It contains the OK, Clear, and * Cancel buttons. */ acb = new AddCardButtons(r, this, rmui); /* * 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(); hblabeledseds = new HBox(); vbouter = new VBox(); /* * Construct a new string editor for each card field. */ ConstructEditors(); } void AddCardDialog::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 = vbouter; vbouter->Align(Center); /* * Stick some stretchable glue spacing above the prompting message. */ vbouter->Insert(new VGlue(round(0.20 * inch), 0, round(0.50 * inch))); /* * Insert the prompting message into the top of the vbox. The prompting * message itself is in an hbox with some glue on each side. This glue * will enable horizontal stretching of the message, which stretchability * will transfer out to the entire scene that the message is in. */ vbouter->Insert(new Label( "Enter Information for a Rolodex Card:", "times", "bold", "r", 18)); /* * Stick some stretchable glue spacing between the message and the field * editors below. */ vbouter->Insert(new VGlue(round(0.20 * inch), 0, round(0.50 * inch))); /* * Compose the parallel label and string editor vboxes and stick them in a * stretchable hbox. */ ComposeLabels(); ComposeEditors(); ComposeOuter(); /* * Insert the outer hbox into this' window. */ ((VBox*)w)->Insert(hblabeledseds); /* * Compose the dialog buttons and insert into the window. */ acb->Compose(); ((VBox*)w)->Insert(new VGlue(round(0.2 * inch), 0, vfil)); ((VBox*)w)->Insert(acb->GetWindow()); ((VBox*)w)->Insert(new VGlue(round(0.2 * inch), 0, vfil)); } String* AddCardDialog::GetName() { return new String(sename->Text()); } String* AddCardDialog::GetId() { return new String(seid->Text()); } String* AddCardDialog::GetAge() { return new String(seage->Text()); } String* AddCardDialog::GetSex() { return new String(sesex->Text()); } String* AddCardDialog::GetAddr() { return new String(seaddr->Text()); } void AddCardDialog::ConstructEditors() { /* * The constant-length string as the second arg to the StringEditor * constructor is a handy way to set the initial size of the edit box. The * subsequent call to Message("") clears the blank chars out after the * editor is built and sized. In this way, the editor properly sized and * initially empty when user frist types in it. */ sename = new StringEditor(bs, " "); seid = new StringEditor(bs, " "); seage = new StringEditor(bs, " "); sesex = new StringEditor(bs, " "); seaddr = new StringEditor(bs, " "); sename->Message(""); seid->Message(""); seage->Message(""); sesex->Message(""); seaddr->Message(""); } void AddCardDialog::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 AddCardDialog::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 AddCardDialog::ComposeOuter() { hblabeledseds->Insert(new HGlue, round(0.25 * inch), hfil, hfil); hblabeledseds->Insert(vblabels); hblabeledseds->Insert(vbseds); hblabeledseds->Insert(new HGlue, round(0.25 * inch), hfil, hfil); } void AddCardDialog::Clear() { sename->Message(""); seid->Message(""); seage->Message(""); sesex->Message(""); seaddr->Message(""); }