home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / MAGAZINE / MSJOURNA / MSJV4_2B.ZIP / PROJECT.ZOO / act / proj.act < prev    next >
Text File  |  1988-11-30  |  5KB  |  169 lines

  1. /* proj.act       --miscelaneous methods, initializations
  2. */
  3.  
  4.  
  5. /* globals for conditional compilation during debugging etc */
  6.  
  7. Actor[#Debug] := false;     /* debugging enable/disable */
  8. Actor[#Trace] := false;     /* trace recalc calls */      
  9. Actor[#CurPos] := 0;        /* text dump of network uses this */ 
  10. !!
  11.  
  12. /* methods for system classes */
  13.  
  14. now(Window)!!
  15.  
  16. /* Set the current cursor position in client coords.
  17.    This is useful when implementing a keyboard interface. */
  18. Def  setCursorPos(self, pos | scrnPos)
  19.   scrnPos := clientToScreen(self, pos);
  20.   Call SetCursorPos(scrnPos.x, scrnPos.y);
  21. }!!
  22.  
  23. /* Return a point of the current cursor position in client coords.
  24.    This is useful when implementing a keyboard interface. */
  25. Def  getCursorPos(self | struct, scrnPos, lpr)
  26.   struct := new(Struct,4);          /* to store the point */
  27.   lpr := lP(struct);                /* long pointer */
  28.   Call GetCursorPos(lpr);           /* device coords */
  29.   scrnPos := pointAt(lpr);          /* get the data */
  30.   freeHandle(struct);               /* free up memory */
  31.   ^screenToClient(self, scrnPos);   /* screen coords */
  32. }!!
  33.  
  34. /* Return a point giving the text width and height
  35.    in the given display context. 
  36.    e.g. for system font the return value might be 
  37.    8@15 for 8 pixels wide, 15 high, depending on the
  38.    Windows drivers. */
  39. Def  textSize(self, hDC | tm1, tm2)
  40.   tm1 := new(Struct, 31);            /* to hold the info */
  41.   Call GetTextMetrics(hDC, lP(tm1)); /* call Windows fn */
  42.   tm2 := getData(tm1);               /* get the data back */
  43.   freeHandle(tm1);                   /* free up memory */
  44.   ^point(low(tm2[10]), low(tm2[0])); /* width@height */
  45. }!!
  46.  
  47. now(Dialog);!!
  48.  
  49. /* Run the dialog with the appropriate resource
  50.    and parent.  Display a warning if it fails. */
  51. Def  checkRunModal(self, res, parent | retValue)
  52. {
  53.   retValue := runModal(self, res, parent);
  54.   if retValue == NOMEM
  55.     beep();
  56.     errorBox(loadString(PW_WARNING),
  57.              loadString(PW_ERRMEM1) + CR_LF +
  58.              loadString(PW_ERRMEM2));
  59.   endif;
  60.   ^retValue;
  61. }!!
  62.  
  63. now(String);!!
  64.  
  65. /* Return the string in a field of fieldSize.
  66.    Truncate or pad with blanks as necessary.
  67. */
  68. Def  field(self, fieldSize | size)
  69. {
  70.   if fieldSize < size := size(self)
  71.     ^subString(self, 0, fieldSize)            /* truncate */
  72.   else
  73.     ^self + stringOf(' ', fieldSize - size);  /* pad */
  74.   endif;
  75. }!!
  76.  
  77. /* Convert to decimal.  Safe if length = 0. */
  78. Def  asDec(self)
  79. {
  80.   if size(self) = 0
  81.     ^ 0;
  82.   else
  83.     ^asInt(self,10);
  84.   endif;
  85. }!!
  86.  
  87. /* Show a yesNoBox with self as the caption, str as message.  
  88.    Return value of 6 = Yes, 7 = No. */
  89. Def yesNoBox(self, str)
  90. {  ^new(ErrorBox, ThePort, str, self, 4);
  91. }!!
  92.  
  93.  
  94. /* Report an error if the date string is invalid,
  95.    otherwise return the Date object.  Ignore empty strings.
  96.    Report the error according to international date format. */
  97. Def  checkDate(self | retValue, iDate, format)
  98.   if self <> ""
  99.   cand not(retValue := asDate(self))
  100.     beep();
  101.     iDate := getProfileString("intl", "iDate");
  102.     select
  103.       case iDate = "2"
  104.         format := loadString(PW_YYMMDD);
  105.       endCase
  106.       case iDate = "1"
  107.         format := loadString(PW_DDMMYY);
  108.       endCase
  109.       default                               /* "0" or unspecified */
  110.         format := loadString(PW_MMDDYY);
  111.     endSelect;
  112.     errorBox(loadString(PW_ERRDATE1),
  113.              asString(self) + loadString(PW_ERRDATE2) + format +
  114.              loadString(PW_ERRDATE3));
  115.   endif;
  116.   ^retValue;
  117. }!!
  118.  
  119. now(NilClass)!!
  120.  
  121. /* Return an empty string.  For compatibility
  122.    with the Date class so you can checkString(nil)
  123.    or checkString(aDate) and get a string. */
  124. Def  checkString(self)
  125.   ^"";
  126. }!!
  127.  
  128. now(Collection)!!
  129.  
  130. /* Returns true (the position) if the elem is in the collection.
  131.    Uses a sequential search.  Descendent classes redefine this
  132.    using more efficient means where possible. */
  133. Def  in(self, elem)
  134. {
  135.   do(size(self),
  136.     {using(i) 
  137.      if self[i] = elem ^i; endif;   /* found */
  138.   });
  139.   ^false;    /* not found */
  140. }!!
  141.  
  142. now(Dictionary)!!
  143.  
  144. /* Returns the value (true) if the key is in the Dictionary. */
  145. Def  in(self, key | assoc)
  146. {
  147.   assoc := assocAt(self, key);
  148.   if assoc
  149.     ^assoc.value;
  150.   else
  151.     ^false;
  152.   endif;
  153. }!!
  154.  
  155. now(Date)!!
  156.  
  157. /* Convert a date to a string.  NilClass:checkString
  158.    returns an empty string. */
  159. Def  checkString(self)
  160.   ^asString(self);
  161. }!!
  162.  
  163.