home *** CD-ROM | disk | FTP | other *** search
- _PROGRAMMER TOOLS FOR ACTOR 3.0_
- by Marty Franz
-
- [LISTING ONE]
-
- /* ROLO.H */
-
- /* Menu Constants */
- #define SEARCH 2000
-
- #define PRIMARY 2011 /* Index popup */
- #define ALTERNATE 2012
-
- #define NEXT 2020
- #define PREV 2030
- #define INSERT 2040
- #define UPDATE 2050
- #define DELETE 2060
- !!
-
- /* Dialog Constants */
- #define PHONE 101
- #define PERSON 102
- #define COMPANY 103
- !!
-
-
- [LISTING TWO]
-
- /* Additional methods required by WinTrieve Rolodex Browser sample app. */
-
- now(String);!!
-
- /* Returns a copy of the receiver from
- which a blank characters have been removed. */
- Def removeBlanks(self | str)
- { str := "";
- do(self,
- {using(c) if c <> ' ' then str := str + asString(c) endif;
- });
- ^str;
- }
- !!
- now(class(CType))!!
-
- /* Return a CType object by looking up it's name in type dictionaries. Same as
- findType method except does no error checking. */
- Def getType(self, tName)
- { ^$CTypes[tName] cor $UserTypes[tName];
- }
- !!
-
-
- [LISTING THREE]
-
- /* Rolodex browser. */!!
-
- inherit(Application, #RoloApp, nil, 2, nil)!!
-
- now(class(RoloApp))!!
-
- /* Remove unnecessary classes. */
- Def removeExtra(self)
- { do(#(EditWindow WinEllipse WinPolygon StopWatch
- Control FileDialog ReplaceDialog RelFile),
- {using(g) removeGlobal(self, g);
- });
- }
- !!
-
- now(RoloApp)!!
-
- /* Startup the Rolodex browser. */
- Def init(self, cmdStr)
- { init(self:ancestor, cmdStr);
- mainWindow := newMain(RoloWindow, nil, "Rolodex Browser", nil);
- show(mainWindow, CmdShow);
- if not(createDB(mainWindow))
- then close(mainWindow);
- endif;
- }
- !!
-
- /* Class Initialization */
-
-
- [LISTING FOUR]
-
- /* A Rolodex file. */!!
-
- inherit(IsamFile, #RoloFile, nil, 2, nil)!!
-
- now(RoloFileClass)!!
-
- now(RoloFile)!!
-
- /* Init Rolodex file record type and key defs. */
- Def init(self)
- { init(self:ancestor);
- def(UserType, #rolo, #(
- char phone 30
- char person 30
- char company 30
- ));
- setRecType(self, #rolo);
- addKeyDef(self, #primary, #NODUPS, #phone);
- addKeyDef(self, #person, #DUPS, #person);
- }!!
-
-
- [LISTING FIVE]
-
- /* Main window of Rolodex ISAM file browser. */!!
-
- inherit(TextWindow, #RoloWindow, #(keysDict /* Dictionary of keys */
- roloDB /* ISAM manager */
- roloTable /* ISAM rolodex file */), 2, nil)!!
-
- now(class(RoloWindow))!!
-
- now(RoloWindow)!!
-
- /* Initiate a session with the ISAM manager. Create the ISAM file. */
- Def createDB(self)
- { roloDB := new(IsamManager);
- openManager(roloDB);
- if checkError(roloDB)
- then destroy(roloDB);
- ^roloDB := nil;
- endif;
- roloTable := new(RoloFile);
- setFilename(roloTable, "rolo");
- setManager(roloTable, roloDB);
- create(roloTable, ISINOUT + ISMANULOCK);
- if checkError(roloTable)
- then destroy(roloTable);
- ^roloTable := nil;
- endif;
- }
- !!
- /* Handles input dialog processing for obtaining search title. Returns title
- or nil if user cancels. */
- Def getPerson(self | id title)
- { id := new(InputDialog, "Person Key", "Person:", "");
- loop
- while runModal(id, INPUT_BOX, self) = IDOK
- title := leftJustify(getText(id));
- if size(title) > 0
- then ^title;
- endif;
- endLoop;
- ^nil;
- }
- !!
- /* Handles input dialog processing for obtaining phone number. Returns phone
- number or nil if user cancels. */
- Def getPhone(self | id str val)
- { id := new(InputDialog, "Primary Key", "Phone:", "");
- loop
- while runModal(id, INPUT_BOX, self) = IDOK
- str := removeBlanks(getText(id));
- if size(str) > 0 cand (val := asInt(str, 10))
- then ^val;
- endif;
- endLoop;
- ^nil;
- }
- !!
- /* Validate record dialog input. If ok, returns dictionary of input field
- values. If error input field, displays error box and returns nil. */
- Def validateInput(self, cVals | input)
- { input := new(Dictionary, 10); /* Validate input. */
- input[#phone] := leftJustify(removeBlanks(cVals[PHONE]));
- if size(input[#phone]) = 0
- then errorBox(caption, "Invalid Phone field.");
- else input[#person] := leftJustify(cVals[PERSON]);
- if size(input[#person]) = 0
- then errorBox(caption, "Invalid Person field.");
- else input[#company] := leftJustify(cVals[COMPANY]);
- if size(input[#company]) = 0
- then errorBox(caption, "Invalid Company field.");
- else ^input
- endif;
- endif;
- endif;
- ^nil;
- } !!
- /* Close the database. */
- Def closeDB(self)
- { if roloTable
- then close(roloTable);
- destroy(roloTable);
- roloTable := nil;
- endif;
- if roloDB
- then closeManager(roloDB);
- destroy(roloDB);
- roloDB := nil;
- endif;
- }
- !!
- /* Closing the window so close the database. */
- Def shouldClose(self)
- { closeDB(self);
- }
- !!
- /* Initiate a session with the ISAM manager. */
- Def openDB(self)
- { roloDB := new(IsamManager);
- openManager(roloDB);
- if checkError(roloDB)
- then destroy(roloDB);
- ^roloDB := nil;
- endif;
- roloTable := new(RoloFile);
- setFilename(roloTable, "rolo");
- setManager(roloTable, roloDB);
- open(roloTable, ISINOUT + ISMANULOCK);
- if checkError(roloTable)
- then destroy(roloTable);
- ^roloTable := nil;
- endif;
- }
- !!
- /* Display the current record in the window. */
- Def printRecord(self)
- { cls(self);
- printString(self, "Phone: ");
- printString(self, asString(getField(roloTable, #phone)));
- eol(self);
- printString(self, "Person: ");
- printString(self, asString(getField(roloTable, #person)));
- eol(self);
- printString(self, "Company: ");
- printString(self, asString(getField(roloTable, #company)));
- eol(self);
- }
- !!
- /* Build a record dialog. */
- Def recDlg(self, dPhone, dPerson, dCompany | D)
- { D := new(DialogDesign);
- setSize(D, 8@8, 185@120);
- /*
- addItem(D, newStatic(DlgItem, "Phone:", 100, 5@10, 40@10, 0));
- addItem(D, newEdit(DlgItem, dPhone, PHONE, 50@10, 35@12, 0));
- addItem(D, newStatic(DlgItem, "Person:", 100, 5@25, 40@10, 0));
- addItem(D, newEdit(DlgItem, dPerson, PERSON, 50@25, 125@12, 0));
- addItem(D, newStatic(DlgItem, "Company:", 100, 5@40, 40@10, 0));
- addItem(D, newEdit(DlgItem, dCompany, COMPANY, 50@40, 35@12, 0));
- */
- addItem(D, newStatic(DlgItem, "Phone:", 100, 5@10, 40@10, 0));
- addItem(D, newEdit(DlgItem, dPhone, PHONE, 50@10, 125@12, 0));
- addItem(D, newStatic(DlgItem, "Person:", 100, 5@25, 40@10, 0));
- addItem(D, newEdit(DlgItem, dPerson, PERSON, 50@25, 125@12, 0));
- addItem(D, newStatic(DlgItem, "Company:", 100, 5@40, 40@10, 0));
- addItem(D, newEdit(DlgItem, dCompany, COMPANY, 50@40, 125@12, 0));
- addItem(D, newButton(DlgItem, "Cancel", IDCANCEL, 115@95, 40@14, 0));
- ^D;
- }
- !!
- /* Search for a record based on current index order. */
- Def searchRec(self, wp | val)
- { select
- case currentIndex(roloTable) = #primary
- is val := getPhone(self);
- if not(val)
- then ^nil;
- endif;
- putField(roloTable, val, #phone);
- endCase
- case currentIndex(roloTable) = #person
- is val := getPerson(self);
- if not(val)
- then ^nil;
- endif;
- putField(roloTable, val, #person);
- endCase
- endSelect;
- if not(read(roloTable, ISEQUAL))
- then checkError(roloTable);
- ^nil;
- endif;
- printRecord(self);
- }
- !!
- /* Read the previous record and display it. */
- Def prevRec(self, wp)
- { if read(roloTable, ISPREV)
- then printRecord(self);
- else checkError(roloTable);
- cls(self);
- endif;
- }
- !!
- /* Read the next record and display it. */
- Def nextRec(self, wp)
- { if read(roloTable, ISNEXT)
- then printRecord(self);
- else checkError(roloTable);
- cls(self);
- endif;
- }
- !!
- /* Insert a record. */
- Def insertRec(self, wp | rDlg cVals iVals)
- { rDlg := recDlg(self, "", "", "");
- loop
- while runModal(rDlg, nil, self) <> 0
- cVals := controlValues(rDlg);
- if iVals := validateInput(self, cVals)
- then putField(roloTable, iVals[#phone], #phone);
- putField(roloTable, iVals[#person], #person);
- putField(roloTable, iVals[#company], #company);
- if not(insertCurrent(roloTable))
- then checkError(roloTable);
- else printRecord(self);
- endif;
- ^self;
- endif;
- rDlg := recDlg(self, cVals[PHONE], cVals[PERSON], cVals[COMPANY]);
- endLoop;
- }!!
- /* Change to selected index and display first record in new index ordering. */
- Def changeIndex(self, wp | key oldKey)
- { key := keyAt(keysDict, wp);
- oldKey := currentIndex(roloTable);
- if key = oldKey
- then ^self;
- endif;
- if selectRecord(roloTable, key, 0, ISFIRST)
- then read(roloTable, ISNEXT);
- unCheckMenuItem(menu, keysDict[oldKey]);
- checkMenuItem(menu, wp);
- endif;
- if not(checkError(roloTable))
- then printRecord(self);
- endif;
- }
- !!
- /* Delete the current record. */
- Def deleteRec(self, wp)
- { if not(deleteCurrent(roloTable))
- then checkError(roloTable);
- else cls(self);
- endif;
- }
- !!
- /* Update a record. */
- Def updateRec(self, wp | rDlg cVals iVals)
- { if not(read(roloTable, ISCURR))
- then checkError(roloTable);
- ^self;
- endif;
- rDlg := recDlg(self,
- asString(getField(roloTable, #phone)),
- getField(roloTable, #person),
- asString(getField(roloTable, #company)));
- loop
- while runModal(rDlg, nil, self) <> 0
- cVals := controlValues(rDlg);
- if iVals := validateInput(self, cVals)
- then putField(roloTable, iVals[#phone], #phone);
- putField(roloTable, iVals[#person], #person);
- putField(roloTable, iVals[#company], #company);
- if not(updateCurrent(roloTable))
- then checkError(roloTable);
- else printRecord(self);
- endif;
- ^self;
- endif;
- rDlg := recDlg(self, cVals[PHONE], cVals[PERSON], cVals[COMPANY]);
- endLoop;
- }!!
- /* Respond to the menu events.
- The wp argument gives the selected menu ID.
- Get a message symbol from the menu object. */
- Def command(self, wp, lp | msg)
- { if msg := action(menu, wp)
- then ^perform(self, wp, msg)
- endif;
- }!!
- /* Setup the menu bar. */
- Def createMenu(self)
- { createMenu(self:ancestor);
- menu := init(new(Menu));
- setHandle(menu, hMenu);
- topMenu(menu, "&Search!", SEARCH, #searchRec);
- keysDict := new(OrderedDictionary, 4);
- keysDict[#primary] := PRIMARY;
- keysDict[#person] := ALTERNATE;
- popupMenu(menu, "&Index",
- tuple("phone", "person"),
- tuple(PRIMARY, ALTERNATE), #changeIndex);
- checkMenuItem(menu, PRIMARY);
- topMenu(menu, "&Next!", NEXT, #nextRec);
- topMenu(menu, "&Prev!", PREV, #prevRec);
- topMenu(menu, "&Insert!", INSERT, #insertRec);
- topMenu(menu, "&Update!", UPDATE, #updateRec);
- topMenu(menu, "&Delete!", DELETE, #deleteRec);
- drawMenu(self);
- }
- !!
- /* Initialize the window. Create menu and About to control menu. */
- Def init(self)
- { init(self:ancestor);
- createMenu(self);
- addAbout(self);
- }
- !!
-
- /* Class Initialization */
-
-
- [ROLO.LOD]
-
- /* Load file for WinTrieve Rolodex Browser. You must load
- ISAM.LOD file before loading these files. */
-
- LoadFiles := tuple(
- "classes\menu.cls", /* dynamic menu support */
-
- "res\control.h", /* dynamic dialog support */
- "classes\dlgitem.cls",
- "classes\dialogde.cls",
-
- "res\rolo.h", /* rolo Browser support */
- "classes\rolofile.cls",
- "classes\rolowind.cls",
- "classes\roloapp.cls",
- "act\rolo.act"
- )!!
-
- printLine("");!!
- printLine("Use load() to load WinTrieve Rolodex Browser");!!
-
-
- [EXAMPLE 1]
-
- /* Build a record dialog. */
- Def recDlg(self, dPhone, dPerson, dCompany | D)
- { D := new(DialogDesign);
- setSize(D, 8@8, 185@120);
- addItem(D, newStatic(DlgItem, "Phone:", 100, 5@10, 40@10, 0));
- addItem(D, newEdit(DlgItem, dPhone, PHONE, 50@10, 35@12, 0));
- addItem(D, newStatic(DlgItem, "Person:", 100, 5@25, 40@10, 0));
- addItem(D, newEdit(DlgItem, dPerson, PERSON, 50@25, 125@12, 0));
- addItem(D, newStatic(DlgItem, "Company:", 100, 5@40, 40@10, 0));
- addItem(D, newEdit(DlgItem, dCompany, dCompany, 50@40, 35@12, 0));
- addItem(D, newButton(DlgItem, "Cancel", IDCANCEL, 115@95, 40@14, 0));
- ^D;
- }
-
-
-