progress.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1996-2000 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * File: Progress.h
  8. *
  9. * Release: Palm OS SDK 4.0 (63220)
  10. *
  11. * Description:
  12. * This header file defines a generic progress dialog interface
  13. *
  14. * History:
  15. * 6/4/97 from Ron Marianetti's net dialog stuff Created by Gavin Peacock
  16. *
  17. *****************************************************************************)
  18. unit progress;
  19. interface
  20. uses palmos, coretraps, control;
  21. const
  22. progressMaxMessage = 128;
  23. progressMaxTitle = 31; // max size for title of progress dialog
  24. progressMaxButtonText = 7; // max size of text in OK/Cancel button
  25. // Progress callback function
  26. // The progress dialog will call this function to get the text to display for the
  27. // current status.
  28. // stage - the current stage of progess as defined by your app
  29. // message - text that can be sent from the protocol
  30. // cancel - true if the dialog is in cancel mode
  31. // error - current error (func should return an error message in this case...
  32. type
  33. PrgCallbackData = record
  34. stage: UInt16; // <= current stage
  35. textP: PChar; // => buffer to hold text to display
  36. textLen: UInt16; // <= length of text buffer
  37. message: PChar; // <= additional text for display
  38. error: Err; // <= current error
  39. bitmapId: UInt16; // => resource ID of bitmap to display
  40. Bits: UInt16;
  41. {
  42. UInt16 canceled:1; // <= true if user has pressed the cancel button
  43. UInt16 showDetails:1; // <= true if user pressed down arrow for more details
  44. UInt16 textChanged:1; // => if true then update text (defaults to true)
  45. UInt16 timedOut:1; // <= true if update caused by a timeout
  46. }
  47. timeout: UInt32; // <> timeout in ticks to force next update (for animation)
  48. //progress bar info (Not Implemented)
  49. barMaxValue: UInt32; // the maximum value for the progress bar, if = 0 then the bar is
  50. // not visible
  51. barCurValue: UInt32; // the current value of the progress bar, the bar will be drawn
  52. // filled the percentage of maxValue \ value
  53. barMessage: PChar; // additional text for display below the progress bar.
  54. barFlags: UInt16; // reserved for future use.
  55. //
  56. // *** The following fields were added in PalmOS 3.2 ***
  57. //
  58. delay_bits: UInt16;
  59. {
  60. UInt16 delay:1; // => if true delay 1 second after updating form icon/msg
  61. }
  62. userDataP: Pointer; // <= context pointer that caller passed to PrgStartDialog
  63. end;
  64. PrgCallbackDataPtr = ^PrgCallbackData;
  65. //typedef Boolean (*PrgCallbackFunc) (UInt16 stage,Boolean showDetails,Char *message,Boolean cancel,UInt16 error,Char *textP, UInt16 maxtextLen,UInt16 *bitmapID);
  66. PrgCallbackFunc = function(cbP: PrgCallbackDataPtr): Boolean;
  67. //---------------------------------------------------------------------------
  68. // Structure of the Progress Info structure. This structure should be stored
  69. // in the interface's globals. Each of the routines in SerNetIFCommon.c
  70. // take a pointer to this structure.
  71. //---------------------------------------------------------------------------
  72. ProgressType = record
  73. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_PROGRESS}
  74. // This field contains a pointer to the open progress dialog
  75. frmP: FormPtr; // Our progress dialog ptr
  76. // This field is set a maximum time for the action to take place. A cancel
  77. // will be generated if this timeout is reached
  78. timeout: UInt32; // max time to wait in ticks
  79. Bits: UInt16;
  80. {
  81. // This boolean is set by either the protocol (through PrgUpdateDialog()) or UI
  82. // task to inform the UI that it needs to update it's progress dialog with new
  83. // information as stored in the error, stage, and message fields.
  84. UInt16 needUpdate:1; // true if UI update required.
  85. // The following boolean is set by the UI task when the user hits the cancel button.
  86. // When the user cancels, the UI changes to display "Cancelling..." and then waits
  87. // for the protocol task to notice the user cancel and set the error field to
  88. // netErrUserCancel before disposing the dialog. The SerIFUserCancel() which is
  89. // called from the protocol task checks this boolean.
  90. UInt16 cancel:1; // true if cancelling
  91. // This boolean is set by PrvCheckEvents() after we've displayed an error message
  92. // in the progress dialog and changed the "cancel" button to an "OK" button.
  93. // This tells the dialog event handling code in PrvCheckEvents() that it should
  94. // dispose of the dialog on the next hit of the cancel/OK button.
  95. UInt16 waitingForOK:1; // true if waiting for OK button hit.
  96. // This boolean gets set if the user hits the down button while the UI is up. It
  97. // causes more detailed progress to be shown
  98. UInt16 showDetails:1; // show progress details.
  99. // This is set to true whenever the message text is changed. This allows the
  100. // display to be more efficient by not redrawing when not needed
  101. UInt16 messageChanged: 1;
  102. }
  103. //-----------------------------------------------------------------------
  104. // The following fields are set by PrgUpdateDialog() and used by PrgHandleEvent()
  105. // to figure out what to display in the progress dialog
  106. //-----------------------------------------------------------------------
  107. // This word is set by the protocol task (through PrgUpdateDialog()) when an
  108. // error occurs during connection establishment. If this error is non-nil
  109. // and not equal to netErrUserCancel, the UI task will display the appropriate
  110. // error message and change the cancel button to an OK button, set the waitingForOK
  111. // boolean and wait for the user to hit the OK button before disposing
  112. // the dialog.
  113. error: UInt16; // error set by interface
  114. // This enum is set by the protocol task (through PrgUpdateDialog()) as it
  115. // progresses through the connection establishment and is checked by
  116. // PrgHandleEvent() when needUpate is true. It is used to determine what
  117. // string to display in the progress dialog.
  118. stage: UInt16; // which stage of the connection we're in
  119. // This is an additional string that is displayed in the progress dialog for
  120. // certain stages. The netConStageSending stage for example uses this string
  121. // for holding the text string that it is sending. It is set by
  122. // PrgUpdateDialog().
  123. message: array [0..progressMaxMessage] of Char; // connection stage message.
  124. reserved1: UInt8;
  125. // Used to cache current icon number so we don't unnecessarily redraw it
  126. lastBitmapID: UInt16;
  127. // Text array used to hold control title for the OK/Cancel button. This
  128. // must be kept around while the control is present in case of updates.
  129. ctlLabel: array [0..progressMaxButtonText] of Char;
  130. serviceNameP: PChar;
  131. //progress bar stuff (Not implemented)
  132. lastBarMaxValue: UInt32;
  133. lastBarCurValue: UInt32;
  134. // stuff for saving old window state
  135. oldDrawWinH: WinHandle;
  136. oldActiveWinH: WinHandle;
  137. oldFrmP: FormPtr;
  138. oldInsPtState: Boolean;
  139. reserved2: UInt8;
  140. oldInsPtPos: PointType;
  141. textCallback: PrgCallbackFunc;
  142. title: array [0..progressMaxTitle] of Char;
  143. //
  144. // *** The following field was added in PalmOS 3.2 ***
  145. //
  146. userDataP: Pointer;
  147. {$else}
  148. opaque1: UInt32;
  149. opaque2: UInt32;
  150. Bits: UInt16;
  151. {!!!
  152. UInt16 opaque3:1;
  153. // The following boolean is set by the UI task when the user hits the cancel button.
  154. // When the user cancels, the UI changes to display "Cancelling..." and then waits
  155. // for the protocol task to notice the user cancel and set the error field to
  156. // netErrUserCancel before disposing the dialog. The SerIFUserCancel() which is
  157. // called from the protocol task checks this boolean.
  158. UInt16 cancel:1; // true if cancelling
  159. UInt16 opaque4:14;
  160. !!!}
  161. // This word is set by the protocol task (through PrgUpdateDialog()) when an
  162. // error occurs during connection establishment. If this error is non-nil
  163. // and not equal to netErrUserCancel, the UI task will display the appropriate
  164. // error message and change the cancel button to an OK button, set the waitingForOK
  165. // boolean and wait for the user to hit the OK button before disposing
  166. // the dialog.
  167. error: UInt16; // error set by interface
  168. // This enum is set by the protocol task (through PrgUpdateDialog()) as it
  169. // progresses through the connection establishment and is checked by
  170. // PrgHandleEvent() when needUpate is true. It is used to determine what
  171. // string to display in the progress dialog.
  172. stage: UInt16; // which stage of the connection we're in
  173. {$endif}
  174. end;
  175. ProgressPtr = ^ProgressType;
  176. // Warning: In the future, the ProgressType will be opaque. So, please don't
  177. // write code that depends on its internals; you'll just pass it around as a
  178. // "cookie," and that's how you should be treating it now.
  179. // macro to test if the user has canceled
  180. function PrgUserCancel(prgP: ProgressPtr): Boolean;
  181. //-----------------------------------------------------------------------
  182. // Prototypes
  183. //-----------------------------------------------------------------------
  184. function PrgStartDialogV31(const title: PChar; textCallback: PrgCallbackFunc): ProgressPtr; syscall sysTrapPrgStartDialogV31;
  185. function PrgStartDialog(const title: PChar; textCallback: PrgCallbackFunc; userDataP: Pointer): ProgressPtr; syscall sysTrapPrgStartDialog;
  186. procedure PrgStopDialog(prgP: ProgressPtr; force: Boolean); syscall sysTrapPrgStopDialog;
  187. procedure PrgUpdateDialog(prgGP: ProgressPtr; err, stage: UInt16; const messageP: PChar; updateNow: Boolean); syscall sysTrapPrgUpdateDialog;
  188. function PrgHandleEvent(prgGP: ProgressPtr; eventP: EventPtr): Boolean; syscall sysTrapPrgHandleEvent;
  189. implementation
  190. function PrgUserCancel(prgP: ProgressPtr): Boolean;
  191. begin
  192. PrgUserCancel := (prgP^.Bits and $4000) <> 0; // cancel
  193. end;
  194. end.