home *** CD-ROM | disk | FTP | other *** search
/ ftp.alaska-software.com / 2014.06.ftp.alaska-software.com.tar / ftp.alaska-software.com / acsn / ClickDate_v1-70.txt < prev    next >
Text File  |  2003-07-15  |  12KB  |  310 lines

  1. ***********************************************************************
  2. *
  3. *  Application Notes
  4. *  ==================
  5. *
  6. *  Module:     ClickDate.prg       Rev 1.70  10.Jul.2003
  7. *  Category:   Program, Popup Calendar
  8. *
  9. *  Purpose:    To provide a date selection solution satisfying the
  10. *              return requirements for a date Get or Sle field, or a
  11. *              date variable.
  12. *
  13. *  Author:     Greg Doran, Dublin Ireland
  14. *
  15. ***********************************************************************
  16. *
  17. *  Copyright (c) Greg J Doran. 2001-2003   e-mail: GDO@eircom.net
  18. *
  19. *  This code is released under the GNU General Public Licence
  20. *  and is governed by the conditions and protocols setout therein.
  21. *
  22. *  The code is provided "as is", without warranty of any kind,
  23. *  either expressed, or implied, including, but not limited to,
  24. *  the implied warranties of merchantability and fitness for a
  25. *  particular purpose. The entire risk as to the quality of this
  26. *  software, its use or misuse, modified or otherwise, lies with
  27. *  you, the recipient.
  28. *
  29. *
  30. ***********************************************************************
  31. *
  32. *  You are free to use this code as you wish but please retain
  33. *  the copyright and the above text in all program code used.
  34. *
  35. ***********************************************************************
  36. *
  37. *  Syntax:  ClickDate(xDate, oOwner, oDateField, lTopDown)
  38. *
  39. *           xDate can either be Text as in CtoD(date()) or a
  40. *           dDate value or may be omitted altogether.
  41. *
  42. *           TopDown users should set lTopDown true if using TopDown code
  43. *           for the date field.
  44. *
  45. *  Usage:
  46. *
  47. *           Return a date to a Date Variable;
  48. *           ---------------------------------
  49. *           dDate:= ClickDate([<xDate>],oOwner)
  50. *
  51. *           Return a date to a date get field;
  52. *           ------------------------------------
  53. *           oGet:lbDblClick := {| MP1, uNIL, o| clickdate(o:editbuffer(),oDlg,@o)}
  54. *
  55. *           Return a date to a date Sle field;
  56. *           ------------------------------------
  57. *           oSle:lbDblClick := {| MP1, uNIL, o| clickdate(o:editbuffer(),oDlg,@o)}
  58. *
  59. *           Top-Down user's Note:
  60. *           =====================
  61. *           You may use Clickdate in a bWhen codeblock in a tdDEget().
  62. *           It sets o:editbuffer() and returns the logic value .T.
  63. *           bWhen:= {|o| clickdate(o:editbuffer(), oDlg, @o, .T.)}
  64. *           If the get is the only active edit field on the form you
  65. *           can only activate the calendar once using a bWhen.
  66. *           (You can't re-trigger the bWhen without exiting the get
  67. *            and re-entering.)
  68. *
  69. *  Date:    ClickDate will accept invalid data from an Sle edit buffer
  70. *           and ignore the input.  It will return a valid date if one
  71. *           is selected, otherwise on Escape or Close [X] it will
  72. *           set the Sle edit buffer to "  /  /  ".
  73. *
  74. *           If the input is Character, clickDate performs a validation check
  75. *           on the data input and uses "  /  /  " if it is invalid.
  76. *
  77. *           Both the Sle and Get are treated identically even though the
  78. *           editbuffer content is cText in one case and a dDate in the other.
  79. *           The ClickDate code accepts either, and sets the o:editbuffer()
  80. *           with the appropriate VarType on selection.
  81. *
  82. *           The date (or empty buffer content) is sent to Clickdate when the
  83. *           Sle or Get is DoubleClicked. this means you can edit the field
  84. *           locally without the Calendar activating.
  85. *
  86. *  Owner:   Because Clickdate() is using a Modal dialog it is desireable that
  87. *           you nominate the calling dialog (oDlg) as the Owner of the ClickDate
  88. *           modal dialog, particularily if it is itself a Modal.
  89. *
  90. *           Do not use a Groupbox or Static or DrawingArea as the owner, it must
  91. *           be the Dialog.  Sure, it will work if you don't nominate the calling
  92. *           oDlg, but you risk a problem arising and unpredictability.
  93. *           Anything from the user being able to click the Get/Sle field a
  94. *           second time while the calendar is active to a total system freeze.
  95. *           This is not a problem with ClickDate, if you don't handle Modal's
  96. *           properly you invite trouble.
  97. *
  98. * oDateField:
  99. *           For a Get or Sle the Get or Sle object must be passed by
  100. *           reference.  There is minimal checking in this regard so if
  101. *           you pass a non-Get/Sle oVar you will definitely get an error.
  102. *
  103. *
  104. * lTopDown:
  105. *           The TopDown Date field shows [01 02 2003] instead of [01/02/2003]
  106. *           if this is not set True, and, if there is error trapping looking
  107. *           for a space in o:editbuffer you get an error; otherwise it is ok.
  108. *
  109. *           This is because the TopDown o:editbuffer field looks like a string
  110. *           buffer but, because it is a date field, it expects a Date Var.
  111. *           Without lTopDown = .T. a character string is returned.
  112. *
  113. *           For Top-Down users there is a section at the end of this file
  114. *           that describes how you can modify Top-Down Code to enable the
  115. *           use of a Down-Arrow Button (Alt+DownArrow) in conjunction with
  116. *           a Get to invoke the calculator.
  117. *
  118. ***********************************************************************
  119. *
  120. *  Picture Keys:
  121. *  =============
  122. *  [-]  Minimise, just drops to Icon on bottom left of screen.
  123. *  [x]  Close without section
  124. *  [8]  Little calendar -  returns/moves to Todays date.
  125. *  [/]  Tick mark - Select this date and exit.
  126. *  [C]  Open circular arrow - 'undo' return to orginal date on entry
  127. *  [?]  Help key, when activated has a / through it (toggle).
  128. *
  129. *
  130. ************************************************************************
  131. *
  132. *
  133. *  Configuration:
  134. *  ==============
  135. *
  136. *  The Calendar is fully configurable to use multiple languages and or
  137. *  background colours / bitmaps.  See important note below.
  138. *
  139. *  The current default is English.  The only difference between English
  140. *  and US-English is the date formatting.   The routine operates using
  141. *  the Set Date British format and switches the returned value to the
  142. *  locale set in ClickDate.ch. Do not change the British format in the
  143. *  routine, unless of course you want to give yourself unnecessary
  144. *  work going through the entire routine making changes where appropriate.
  145. *
  146. *  Not being an expert in languages, not even my native language!,
  147. *  the addition of other languages is entirely up to you.  The
  148. *  ClickDate.ch file has a template for you to customise the calendar
  149. *  to the language of your choice.
  150. *
  151. **********************************************************************
  152. *
  153. *  IMPORTANT
  154. *  =========
  155. *  ENTER YOUR LANGUAGE DEFINITIONS IN ClickDate.ch and...
  156. *  IN ClickDate.PRG make changes as follows:
  157. *
  158. *  AFTER:
  159. *  ------
  160. *  #include "xbp.ch"
  161. *  #include "Appevent.ch"
  162. *  #include "Gra.ch"
  163. *  #include "common.ch"
  164. *  #include "dll.ch"
  165. *
  166. *  AND BEFORE #INCLUDE CLICKDATE.CH
  167. *  --------------------------------
  168. *  ACTIVATE YOUR LANGUAGE DEFINITION DEFINED IN CLICKDATE.CH
  169. *  ----------------------------------------------------------
  170. *  // #define USENGLISH  // USEnglish
  171. *  #define ENGLISH
  172. *  //#define GERMAN
  173. *  // define LANGUAGE:  SPANISH, ITALIAN, PORTUGUESE etc.
  174. *
  175. * ================================================================
  176. *  NOTE:  ClickDate.CH MUST _FOLLOW_ YOUR LANGUAGE DEFINITION
  177. * ================================================================
  178. *  #include "ClickDate.ch"
  179. *
  180. *
  181. *
  182. * Special Character Sets
  183. * =======================
  184. * If you need to display apserated or special characters such as
  185. * the umlaut, grav or sina fada you may need to uncomment the
  186. * line "SET CHARSET TO ansi"
  187. *
  188. * Also, some character sets require the use of the
  189. * #pragma Library( "XppUi2.lib" ) which needs to be uncommented.
  190. *
  191. *
  192. *
  193. *************************  END
  194.  
  195.  
  196. * TopDown Users only.......
  197. **********************************************************************
  198. *
  199. *  Top-Down:  Use of Alt+DownArrow Button on Get.
  200. *
  201. *  Code Modification and Implementation
  202. *
  203. **********************************************************************
  204. *
  205. *  Normally Alt+DownArrow is used in Top-Down to access a Dropdown
  206. *  ListBox attached to a Get.   This method makes use of the existing
  207. *  Alt+DownArrow feature in TopDown code to enable the calendar.
  208. *
  209. *
  210. * In your program code to include a DnArrow button you use code as
  211. * follows:
  212. *
  213. *     ***** tdDEget_03
  214. *     oDlg:oGetDate := tdDEget(4.0,46.5,fieldWblock("Dated","Datafile"),;
  215. *         oDlg, oDa,10,cPeriod,bValidDate,bWhenDate,,,,.T.,             ;
  216. *         "9.Courier New",.T., 8, , , , ,.F.,6)
  217. *
  218. *     oDlg:oGetDate:setData()
  219. *     aadd(oDlg:aAllGets,oDlg:oGetDate)
  220. *     aadd(oDlg:aEditGets,oDlg:oGetDate)
  221. *
  222. *     ***** Create button and send activity to the Get key handler
  223. *     ***** The Get keyhandler will do what it has to and pass the
  224. *     ***** nkey back to the local keyhandler here as it is not a ListBox.
  225. *     oVBttn := tdPshBtn(4.0+0.1,46.5+8,1.6,oDa,chr(54),;
  226. *               {|| oDlg:oGetDate:Keyboard(xbeK_ALT_DOWN) },,.F.,;
  227. *               '10.Marlett',,,17)
  228. *
  229. *     ***** If the user clicks on the button while another Get has focus,
  230. *     ***** the calendar will be shown and receive focus.  So we must
  231. *     ***** notify the DE window that this Get is now the active one.
  232. *     oVBttn:SetInputFocus  := ;
  233. *     {|| iif(oDlg:oGetDate:editable,oDlg:oActvGet := oDlg:oGetDate,nil)}
  234. *
  235. *
  236. *  The 0.1 added to the 4.0 and the 8 added to the 46.5 positions the
  237. *  DnArrow button centrally at the right side of the get which in this
  238. *  case is at 4.0,46.5
  239. *
  240. *=========================================================================
  241. *
  242. *
  243. *  In your Keyhandler code, e.g. DEKeys() add the following:
  244. *
  245. *
  246. *  ELSEIF nKey == xbeK_ALT_DOWN  // Invoke Calendar
  247. *
  248. *         ClickDate(oDlg:oGetDate:EditBuffer(), oDlg, @oDlg:oGetDate, .T.)
  249. *         oDlg:oActvGet := oDlg:oGetDate
  250. *         SetAppFocus(oDlg:oGetDate)
  251. *
  252. * Obviously if you have more than one date get on a dialog you will need
  253. * to set a flag to determine which get is to be activated.
  254. *
  255. * This will not interfere with a Listbox attached to a Get as the key
  256. * xbeK_ALT_DOWN will be trapped by tdcDEGet:keyboard() code and will
  257. * never appear in your local Keyhandler.
  258. *
  259. * ========================================================================
  260. *
  261. * For the calendar Get to receive the xbeK_ALT_DOWN key you need to make a
  262. * small modification to tdcDEget:Keyboard() in tdcDEget.prg
  263. *
  264. *
  265. * These notes have been taken directly from the revision change block
  266. * of a modified tdcDEget.prg
  267. *
  268. *  IN METHOD tdcDEget:Keyboard()
  269. *
  270. *  PLACED THE FOLLOWING CODE BETWEEN
  271. *
  272. *    ENDIF  // keys
  273. *  AND...
  274. *   ENDIF  // useList
  275. *
  276. *  EFFECTIVELY:
  277. *
  278. *   IF ::lUseList
  279. *
  280. *      IF nKey == xbeK_ALT_DOWN
  281. *         ...
  282. *      ENDIF  // keys
  283. *
  284. *   ****** Begin Addition
  285. *   ELSE
  286. *
  287. *      ***** Its not a Listbox
  288. *      IF nKey == xbeK_ALT_DOWN
  289. *
  290. *         ******* Pass this keystroke to the parent dialog key handler
  291. *         postAppEvent(xbeP_Keyboard,nKey,,::oParentDlg)
  292. *
  293. *      ENDIF
  294. *
  295. *   ***** End Addition
  296. *
  297. *   ENDIF     // useList
  298. *
  299. **************************************
  300. * REASON FOR CHANGE:
  301. **************************************
  302. *
  303. *   In conjuction with Active Get program code, this enables
  304. *   the use of a DownArrow button bound to a Get which responds
  305. *   to Alt+DnArrow when a listbox is not the object activated.
  306. *   In this instance it is a popup calendar on a date get.
  307. *
  308. ****************************************************************************
  309. *
  310.