home *** CD-ROM | disk | FTP | other *** search
- /* proj.act --miscelaneous methods, initializations
- */
-
-
- /* globals for conditional compilation during debugging etc */
-
- Actor[#Debug] := false; /* debugging enable/disable */
- Actor[#Trace] := false; /* trace recalc calls */
- Actor[#CurPos] := 0; /* text dump of network uses this */
- !!
-
- /* methods for system classes */
-
- now(Window)!!
-
- /* Set the current cursor position in client coords.
- This is useful when implementing a keyboard interface. */
- Def setCursorPos(self, pos | scrnPos)
- {
- scrnPos := clientToScreen(self, pos);
- Call SetCursorPos(scrnPos.x, scrnPos.y);
- }!!
-
- /* Return a point of the current cursor position in client coords.
- This is useful when implementing a keyboard interface. */
- Def getCursorPos(self | struct, scrnPos, lpr)
- {
- struct := new(Struct,4); /* to store the point */
- lpr := lP(struct); /* long pointer */
- Call GetCursorPos(lpr); /* device coords */
- scrnPos := pointAt(lpr); /* get the data */
- freeHandle(struct); /* free up memory */
- ^screenToClient(self, scrnPos); /* screen coords */
- }!!
-
- /* Return a point giving the text width and height
- in the given display context.
- e.g. for system font the return value might be
- 8@15 for 8 pixels wide, 15 high, depending on the
- Windows drivers. */
- Def textSize(self, hDC | tm1, tm2)
- {
- tm1 := new(Struct, 31); /* to hold the info */
- Call GetTextMetrics(hDC, lP(tm1)); /* call Windows fn */
- tm2 := getData(tm1); /* get the data back */
- freeHandle(tm1); /* free up memory */
- ^point(low(tm2[10]), low(tm2[0])); /* width@height */
- }!!
-
- now(Dialog);!!
-
- /* Run the dialog with the appropriate resource
- and parent. Display a warning if it fails. */
- Def checkRunModal(self, res, parent | retValue)
- {
- retValue := runModal(self, res, parent);
- if retValue == NOMEM
- beep();
- errorBox(loadString(PW_WARNING),
- loadString(PW_ERRMEM1) + CR_LF +
- loadString(PW_ERRMEM2));
- endif;
- ^retValue;
- }!!
-
- now(String);!!
-
- /* Return the string in a field of fieldSize.
- Truncate or pad with blanks as necessary.
- */
- Def field(self, fieldSize | size)
- {
- if fieldSize < size := size(self)
- ^subString(self, 0, fieldSize) /* truncate */
- else
- ^self + stringOf(' ', fieldSize - size); /* pad */
- endif;
- }!!
-
- /* Convert to decimal. Safe if length = 0. */
- Def asDec(self)
- {
- if size(self) = 0
- ^ 0;
- else
- ^asInt(self,10);
- endif;
- }!!
-
- /* Show a yesNoBox with self as the caption, str as message.
- Return value of 6 = Yes, 7 = No. */
- Def yesNoBox(self, str)
- { ^new(ErrorBox, ThePort, str, self, 4);
- }!!
-
-
- /* Report an error if the date string is invalid,
- otherwise return the Date object. Ignore empty strings.
- Report the error according to international date format. */
- Def checkDate(self | retValue, iDate, format)
- {
- if self <> ""
- cand not(retValue := asDate(self))
- beep();
- iDate := getProfileString("intl", "iDate");
- select
- case iDate = "2"
- format := loadString(PW_YYMMDD);
- endCase
- case iDate = "1"
- format := loadString(PW_DDMMYY);
- endCase
- default /* "0" or unspecified */
- format := loadString(PW_MMDDYY);
- endSelect;
- errorBox(loadString(PW_ERRDATE1),
- asString(self) + loadString(PW_ERRDATE2) + format +
- loadString(PW_ERRDATE3));
- endif;
- ^retValue;
- }!!
-
- now(NilClass)!!
-
- /* Return an empty string. For compatibility
- with the Date class so you can checkString(nil)
- or checkString(aDate) and get a string. */
- Def checkString(self)
- {
- ^"";
- }!!
-
- now(Collection)!!
-
- /* Returns true (the position) if the elem is in the collection.
- Uses a sequential search. Descendent classes redefine this
- using more efficient means where possible. */
- Def in(self, elem)
- {
- do(size(self),
- {using(i)
- if self[i] = elem ^i; endif; /* found */
- });
- ^false; /* not found */
- }!!
-
- now(Dictionary)!!
-
- /* Returns the value (true) if the key is in the Dictionary. */
- Def in(self, key | assoc)
- {
- assoc := assocAt(self, key);
- if assoc
- ^assoc.value;
- else
- ^false;
- endif;
- }!!
-
- now(Date)!!
-
- /* Convert a date to a string. NilClass:checkString
- returns an empty string. */
- Def checkString(self)
- {
- ^asString(self);
- }!!
-
-