home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / DIALOG.PEL < prev    next >
Text File  |  1995-04-07  |  62KB  |  1,931 lines

  1. # $Header:   P:\source\wmacros\dialog.pev   1.144   07 Apr 1995 16:35:42   PFHDWM0  $
  2. ## $Tabs:4 7$
  3.  
  4. ##############################################################################
  5. #
  6. #       Compuware Corporation
  7. #         31440 Northwestern Highway
  8. #           Farmington Hills, Michigan 48334-2564
  9. #
  10. #   This source code listing contains information that is
  11. #   proprietary to Compuware Corporation and may not be copied
  12. #   duplicated, translated, transmitted, stored, retrieved
  13. #   or in any manner or by any method conveyed or disclosed
  14. #   to a third party or parties without express written
  15. #   permission from Compuware Corporation.
  16. #
  17. #  
  18. ##############################################################################
  19.  
  20. #### $Workfile:   dialog.pel  $: dialog window interface
  21.  
  22. ## dialog manager functions and variables available to the user
  23. #
  24. # hDlg  create_dialog_template( callback_function_id, parent, label_str, x0, y0, width, height )
  25. # void  delete_dialog_template( dlghand )
  26. # void  begin_dialog( dlghand )
  27. # bool  add_dialog_control( dlghand, index, dctrl, label_str, x0, y0, width, height )
  28. # long  set_dialog_item( dlghand, index, dac, opt value, opt value2, opt value3, opt value4, opt value5, opt value6, opt value7 )
  29. # any   query_dialog_item( dlghand, index, dac )
  30. # void  set_dialog_focus( dlghand, index )
  31. # hDlg  callback_dlg_hand
  32. # int   callback_index
  33. # int   callback_message
  34.  
  35. ## Dialog control styles:
  36. #
  37. global  DCTRL_DEFAULT_PUSH_BUTTON = 1
  38. global  DCTRL_PUSH_BUTTON         = 2
  39. global  DCTRL_RADIO_BUTTON        = 3
  40. global  DCTRL_CHECK_BOX           = 4
  41. global  DCTRL_TRISTATE            = 5
  42. global  DCTRL_EDIT                = 6
  43. global  DCTRL_EDIT_KEY            = 7
  44. global  DCTRL_STATIC_TEXT         = 8
  45. global  DCTRL_GROUP_BOX           = 9
  46. global  DCTRL_LIST_BOX            = 10
  47. global  DCTRL_COMBO_BOX           = 11
  48. global  DCTRL_NOTEBOOK            = 12
  49. global  DCTRL_MULTI_LIST_BOX      = 13
  50. global  DCTRL_MLE                 = 14
  51. global  DCTRL_MLE_KEY             = 15
  52. global  DCTRL_VALUESET            = 16
  53. global  DCTRL_SPINBUTTON          = 17
  54.  
  55. # Editor Window Codes 
  56. global  EWC_TO_TOP                = 1
  57. global  EWC_MINIMIZE              = 2
  58. global  EWC_MAXIMIZE              = 3
  59. global  EWC_NORMAL                = 4
  60. global  EWC_X_POS                 = 5
  61. global  EWC_Y_POS                 = 6
  62. global  EWC_WIDTH                 = 7
  63. global  EWC_HEIGHT                = 8
  64. global  EWC_RESTORE_X_POS         = 9
  65. global  EWC_RESTORE_Y_POS         = 10
  66. global  EWC_RESTORE_WIDTH         = 11
  67. global  EWC_RESTORE_HEIGHT        = 12
  68. global  EWC_CLIENT_WIDTH          = 13
  69. global  EWC_CLIENT_HEIGHT         = 14
  70. global  EWC_ENABLE                = 15
  71. global  EWC_DISABLE               = 16
  72. global  EWC_HANDLE                = 17
  73.  
  74. # Dialog Window Codes 
  75. global  DWC_TITLE                 = 1
  76. global  DWC_POSITION              = 2
  77. global  DWC_SIZE                  = 3
  78. global  DWC_HIDE                  = 4
  79. global  DWC_SHOW                  = 5
  80. global  DWC_TO_TOP                = 6
  81. global  DWC_SYS_MENU              = 7
  82. global  DWC_SIZEBORDER            = 8
  83. global  DWC_NORMALBORDER          = 9
  84. global  DWC_STATUSBAR             = 10
  85. global  DWC_STATUSBARTEXT         = 11
  86. global  DWC_STATUSBARSIZE         = 12
  87. global  DWC_NORMALSIZE            = 13
  88. global  DWC_ICONIZED              = 14
  89. global  DWC_ZOOMED                = 15
  90. global  DWC_STICKONTOP            = 16
  91.  
  92. ## Dialog action codes:
  93. #
  94. global  DAC_TEXT                    = 1
  95.  
  96. global  DAC_ENABLE                  = 2
  97. global  DAC_DISABLE                 = 3
  98.                                     
  99. global  DAC_HIDE                    = 4
  100. global  DAC_SHOW                    = 5
  101.                                     
  102. global  DAC_UNCHECK                 = 6
  103. global  DAC_CHECK                   = 7
  104. global  DAC_GRAY_CHECK              = 8
  105.                                     
  106. global  DAC_ADD_ITEM                = 9
  107. global  DAC_COUNT_ITEMS             = DAC_ADD_ITEM
  108. global  DAC_DELETE_ITEM             = 10
  109. global  DAC_SELECT_ITEM             = 11
  110.                                     
  111. global  DAC_SET_MAJOR_TAB_SIZE      = 12
  112. global  DAC_SET_MINOR_TAB_SIZE      = 13
  113. global  DAC_SET_BUTTON_SIZE         = 14
  114. global  DAC_SET_BINDER_TYPE         = 15
  115. global  DAC_SET_TAB_TYPE            = 16
  116. global  DAC_SET_TAB_LOCATION        = 17
  117. global  DAC_SET_TAB_ALIGN           = 18
  118. global  DAC_SET_STATUS_ALIGN        = 19
  119. global  DAC_SET_BACKPAGES           = 20
  120. global  DAC_APPEND_PAGE             = 21
  121. global  DAC_INSERT_PAGE_AT_TOP      = 22
  122. global  DAC_INSERT_PAGE_BEFORE      = 23
  123. global  DAC_INSERT_PAGE_AFTER       = 24
  124.                                     
  125. global  DAC_SETFOCUS                = 25
  126.                                     
  127. global  DAC_FIRST_ITEM              = 26
  128. global  DAC_NEXT_ITEM               = 27
  129. global  DAC_DESELECT_ITEM           = 28
  130. global  DAC_UNSELECT_ITEM           = DAC_DESELECT_ITEM
  131. global  DAC_COUNT_SELECTED          = 29
  132. global  DAC_SELECT_INDEX            = 30
  133. global  DAC_FIRST_INDEX             = 31
  134. global  DAC_NEXT_INDEX              = 32
  135. global  DAC_GET_INDEX_ITEM          = 33
  136. global  DAC_ADD_INDEX               = 34
  137. global  DAC_DELETE_INDEX            = 35
  138. global  DAC_DESELECT_INDEX          = 36
  139. global  DAC_DESELECT_INDEX_RANGE    = 37
  140. global  DAC_SELECT_INDEX_RANGE      = 38
  141. global  DAC_SIZE                    = 39
  142. global  DAC_POSITION                = 40
  143.                                        
  144. global  DAC_SET_TEXT_LEN            = 41
  145.                                     
  146. global  DAC_SORT_ASCENDING          = 42
  147. global  DAC_SORT_DESCENDING         = 43
  148. global  DAC_NO_SORT                 = 44
  149.                                     
  150. global  DAC_EDIT_TEXT               = 45
  151. global  DAC_EDIT_KEY_TEXT           = 46
  152. global  DAC_CLEAR_LIST              = 47
  153. global  DAC_FIND                    = 48
  154. global  DAC_FONT                    = 49
  155.  
  156. global  DAC_SELECTED_RANGE          = 50
  157. global  DAC_SELECTION               = DAC_SELECTED_RANGE
  158. global  DAC_SELECTED_TEXT           = 51
  159. global  DAC_PASTE                   = DAC_SELECTED_TEXT
  160. global  DAC_COPY                    = 52
  161. global  DAC_CUT                     = 53
  162. global  DAC_CLEAR                   = 54
  163. global  DAC_UNDO                    = 55
  164. global  DAC_MODIFIED                = 56
  165.  
  166. global  DAC_LINEUP                  = 57
  167. global  DAC_LINEDOWN                = 58
  168. global  DAC_PAGEUP                  = 59
  169. global  DAC_PAGEDOWN                = 60
  170. global  DAC_SCROLL_VERT             = 61
  171. global  DAC_SCROLL_HORIZ            = 62
  172. global  DAC_COUNT_LINES             = 63
  173. global  DAC_GET_LINE                = 64
  174.  
  175. global DAC_VS_QUERY_ITEM            = 65
  176. global DAC_VS_QUERY_METRICS         = 66
  177. global DAC_VS_QUERY_SELECTED        = 67
  178. global DAC_VS_SET_ITEM              = 68
  179. global DAC_VS_SET_METRICS           = 69
  180. global DAC_VS_SELECT_ITEM           = 70
  181.  
  182. global DAC_FG_COLOR                 = 71
  183. global DAC_BG_COLOR                 = 72
  184.  
  185. global DAC_SPIN_OVERRIDELIMITS      = 73
  186. global DAC_SPIN_LIMITS              = 74
  187. global DAC_SPIN_VALUE               = 75
  188. global DAC_SPIN_MASTER              = 76
  189. global DAC_SPIN_TEXTLIMIT           = 77
  190. global DAC_SPIN_DOWN                = 78
  191. global DAC_SPIN_UP                  = 79
  192.  
  193. global DAC_VS_COLORS                = 80
  194.  
  195. # Dialog Styles
  196. # Only the border styles work dynamically
  197. #global DS_SYSMENU                  = 41
  198. #global DS_MINBUTTON                = 42
  199. #global DS_MAXBUTTON                = 43
  200.                                     
  201. global DS_BORDER                    = 44
  202. global DS_SIZEBORDER                = 45
  203. global DS_NOBORDER                  = 46
  204.                                
  205. ## Messages passed to the callback function in callback_msg:
  206. #
  207. global  DM_INIT                     = 1
  208. global  DM_CLICK                    = 2
  209. global  DM_SELECT                   = 3
  210. global  DM_DOUBLE_CLICK             = 4
  211. global  DM_SET_FOCUS                = 5
  212. global  DM_KILL_FOCUS               = 6
  213. global  DM_CHANGE                   = 7
  214. global  DM_DROP_DOWN                = 8
  215. global  DM_OK                       = 9
  216. global  DM_CANCEL                   = 10
  217. global  DM_KEY                      = 11
  218. global  DM_HELPREQUESTED            = 12
  219. global  DM_PAGECHANGED              = 13
  220. global  DM_CLOSE                    = 14
  221. global  DM_INVALID_PCHAR            = 15
  222. global  DM_ACTIVATE                 = 16
  223. global  DM_DEACTIVATE               = 17
  224. global  DM_RESIZE                   = 18
  225. global  DM_MENUSELECT               = 19
  226. global  DM_MENUCOMMAND              = 20
  227. global  DM_AFTER_ACTIVATE           = 21
  228. global  DM_VS_ENTER                 = 22
  229. global  DM_VS_HELP                  = 23
  230. global  DM_VS_SELECT                = 24
  231. global  DM_SPIN_UP                  = 25
  232. global  DM_SPIN_DOWN                = 26
  233. global  DM_SPIN_END                 = 27
  234. global  DM_SPIN_CHANGE              = 28
  235.  
  236. ## dialog manager callback function return values:
  237. #
  238. global  DRC_EXIT                    = 0
  239. global  DRC_CONTINUE                = 1
  240. global  DRC_MSG_PROCESSED           = 2
  241.  
  242. ## value returned by dialog callback function to caller
  243. #
  244. local   dialog_return_value
  245.  
  246. # Handle of the Dialog List dialog
  247. local DialogList
  248.  
  249.  
  250. ## dialog handles
  251. #
  252. global  dhBufferList
  253.  
  254. ## dialog item indices
  255. #
  256. global  DI_CANCEL       = 2
  257. global  DI_OK           = 1
  258. global IDB_SCL_SAVE_AS  = 1383
  259. global IDD_LIST         = 1512
  260.  
  261. local IDD_CMD_DLG       = 1570
  262. local IDL_CMD_HISTORY   = 1571
  263. local IDE_COMMAND       = 1572
  264.                              
  265.                                 
  266. local CommandDlg = 0
  267. # !!?? ------------------------------------------------------------------
  268. # !!?? for debugging callback functions
  269. # !!??
  270. # !!?? returns a string identifying the callback message and the
  271. # !!??  currently active control
  272. global function identMsg()
  273. {
  274.    local   msg
  275.    if ( callback_msg == DM_INIT )
  276.       msg = "DM_INIT"
  277.    else if ( callback_msg == DM_SELECT )
  278.       msg = "DM_SELECT"
  279.    else if ( callback_msg == DM_CLICK )
  280.       msg = "DM_CLICK"
  281.    else if ( callback_msg == DM_DOUBLE_CLICK )
  282.       msg = "DM_DOUBLE_CLICK"
  283.    else if ( callback_msg == DM_SET_FOCUS )
  284.       msg = "DM_SET_FOCUS"
  285.    else if ( callback_msg == DM_KILL_FOCUS )
  286.       msg = "DM_KILL_FOCUS"
  287.    else if ( callback_msg == DM_CHANGE )
  288.       msg = "DM_CHANGE"
  289.    else if ( callback_msg == DM_DROP_DOWN )
  290.       msg = "DM_DROP_DOWN"
  291.    else if ( callback_msg == DM_OK )
  292.       msg = "DM_OK"
  293.    else if ( callback_msg == DM_CANCEL )
  294.       msg = "DM_CANCEL"
  295.    else if ( callback_msg == DM_KEY )
  296.       msg = "DM_KEY"
  297.    else if ( callback_msg == DM_HELPREQUESTED)
  298.       msg = "DM_HELPREQUESTED"
  299.    else if ( callback_msg == DM_CLOSE)
  300.       msg = "DM_CLOSE"
  301.    else if ( callback_msg == DM_INVALID_PCHAR)
  302.       msg = "DM_INVALID_PCHAR"
  303.    else if ( callback_msg == DM_RESIZE )
  304.       msg = "DM_RESIZE"
  305.    else if ( callback_msg == DM_ACTIVATE )
  306.       msg = "DM_ACTIVATE"
  307.    else if ( callback_msg == DM_DEACTIVATE )
  308.       msg = "DM_DEACTIVATE"
  309.    else if ( callback_msg == DM_MENUSELECT )
  310.       msg = "DM_MENUSELECT"
  311.    else if ( callback_msg == DM_MENUCOMMAND )
  312.       msg = "DM_MENUCOMMAND"
  313.    else if ( callback_msg == DM_AFTER_ACTIVATE )
  314.       msg = "DM_AFTER_ACTIVATE"
  315.    else
  316.       msg = "?unknown(" callback_msg ")"
  317.  
  318.    return "msg=(" msg ") "
  319. }
  320.  
  321. #local function identIdx()
  322. #{
  323. #   local indx
  324. #
  325. #   if ( callback_index == IDL_LIST ){
  326. #      indx = "IDL_LIST"
  327. #   } else if ( callback_index == IDB_SAVE_FILE ){
  328. #      indx = "IDB_SAVE_FILE"
  329. #   } else if ( callback_index == IDB_DELETE_FILE ){
  330. #      indx = "IDB_DELETE_FILE"
  331. #   } else if ( callback_index == IDB_READONLY ){
  332. #      indx = "IDB_READONLY"
  333. #   } else if ( callback_index == DI_OK ){
  334. #      indx = "DI_OK"
  335. #   } else if ( callback_index == DI_CANCEL ){
  336. #      indx = "DI_CANCEL"
  337. #   } else if ( callback_index == DI_HELP ){
  338. #      indx = "DI_HELP"
  339. #   } else if ( callback_msg == DM_CLOSE ){
  340. #      indx = "DM_CLOSE"
  341. #   } else {
  342. #      if ( callback_msg != DM_INIT || callback_index != 0 ){
  343. #              indx = "?unknown(" callback_index ")"
  344. #      }
  345. #   }
  346. #
  347. #   return "idx=(" indx ")"
  348. #}
  349.  
  350. # !!?? end of debugging code
  351. # !!?? ------------------------------------------------------------------
  352.  
  353. ############################################################################
  354.  
  355. ## Buffer list dialog
  356. #
  357. global function buffer_list_dialog(old_list)
  358. {
  359.    local   w, h
  360.  
  361.    if ( mdi_mode == 2 && old_list != 1 )
  362.    {
  363.       if ( query_editwin_property( EWC_MINIMIZE ) )
  364.          set_editwin_property( EWC_NORMAL )
  365.  
  366.       set_editwin_property( EWC_TO_TOP )
  367.  
  368.       set_container_item( current_buffer )
  369.       return
  370.    }  
  371.    else if ( !dhBufferList )
  372.    {
  373.       #
  374.       # build the dialog
  375.       #
  376.       w = 400
  377.       h = 240
  378.  
  379.       dhBufferList = create_dialog( function_id( "buffer_list_callback" ),
  380.                                     0, IDD_BUFFERLIST, resource_dll );
  381.  
  382.       attach_help(editor_helpfile, dhBufferList)
  383.  
  384.       add_dialog_item( dhBufferList, IDL_LIST,        DCTRL_MULTI_LIST_BOX )
  385.       add_dialog_item( dhBufferList, IDB_SAVE_FILE,   DCTRL_PUSH_BUTTON )
  386.       add_dialog_item( dhBufferList, IDB_DELETE_FILE, DCTRL_PUSH_BUTTON )
  387.       add_dialog_item( dhBufferList, IDB_READONLY,    DCTRL_PUSH_BUTTON )
  388.    }
  389.  
  390.    if ( save_changes_list )
  391.    {
  392.       set_dialog_window( dhBufferList, DWC_TITLE, "Exit" )
  393.       
  394.       set_dialog_item( dhBufferList, IDB_READONLY,     DAC_HIDE, 1)
  395.       set_dialog_item( dhBufferList, IDB_DELETE_FILE,  DAC_HIDE, 1)
  396.       set_dialog_item( dhBufferList, DI_OK,            DAC_HIDE, 1)   
  397.       set_dialog_item( dhBufferList, IDB_LOCK_FILE,    DAC_HIDE, 1)
  398.  
  399.       set_dialog_item( dhBufferList, IDB_SCL_SAVE_ALL, DAC_SHOW, 1)
  400.       set_dialog_item( dhBufferList, IDB_SCL_SAVE_AS,  DAC_SHOW, 1)
  401.       set_dialog_item( dhBufferList, IDB_SCL_QUIT,     DAC_SHOW, 1)
  402.       set_dialog_item( dhBufferList, IDB_SAVE_FILE,    DAC_ENABLE )
  403.    }                                                           
  404.    else
  405.    {
  406.       set_dialog_window( dhBufferList, DWC_TITLE, "Buffer List" )
  407.  
  408.       set_dialog_item( dhBufferList, IDB_LOCK_FILE,    DAC_SHOW, 1)
  409.       set_dialog_item( dhBufferList, IDB_READONLY,     DAC_SHOW, 1)
  410.       set_dialog_item( dhBufferList, IDB_DELETE_FILE,  DAC_SHOW, 1)
  411.       set_dialog_item( dhBufferList, DI_OK,            DAC_SHOW, 1)   
  412.  
  413.       set_dialog_item( dhBufferList, IDB_SCL_SAVE_ALL, DAC_HIDE, 1)
  414.       set_dialog_item( dhBufferList, IDB_SCL_SAVE_AS,  DAC_HIDE, 1)
  415.       set_dialog_item( dhBufferList, IDB_SCL_QUIT,     DAC_HIDE, 1)
  416.    }
  417.  
  418.    set_dialog_window( dhBufferList, DWC_POSITION, 100, 100)
  419.    dialog_return_value = ""
  420.    begin_dialog( dhBufferList )
  421.    # WGN 3/31/95 - Added call to delete_dialog so that the modal Buffer List doesn't show
  422.    # up in the Dialog List after it's cancelled.
  423.    delete_dialog( dhBufferList )
  424.    dhBufferList = 0
  425.    
  426.    update_current_view()
  427.  
  428.    return dialog_return_value
  429. }
  430.  
  431.  
  432. function buffer_list_callback()
  433. {
  434. #  local dbgmsg = identMsg()     # !!??
  435.    local sel
  436.    local temp
  437.  
  438.    if ( ( callback_msg == DM_CLICK && callback_index == DI_HELP ) ||
  439.         ( callback_msg == DM_HELPREQUESTED ) )
  440.    {
  441.       if(isWindows())
  442.          display_help("Buffer List", callback_dialog_handle);
  443.       else
  444.          display_help("bufferlist", callback_dialog_handle)
  445.       return DRC_MSG_PROCESSED 
  446.    }
  447.    else if ( callback_msg == DM_INIT )
  448.    {
  449.       # fill the list box
  450.       bufferListUpdate()
  451.  
  452.       # Initially disable all of the buttons
  453.       bufferListActivateButtons()
  454.  
  455.       set_dialog_item(dhBufferList, IDL_LIST, DAC_SETFOCUS)
  456.    }
  457.    else if ( callback_msg == DM_SELECT )
  458.    {
  459.       if ( callback_index == IDL_LIST )
  460.          bufferListActivateButtons()
  461.       else
  462.       {
  463. #        notify( dbgmsg )
  464.          beep()  # !!??
  465.       }
  466.       return DRC_MSG_PROCESSED 
  467.    }
  468.    else if (callback_msg == DM_CLICK && (callback_index == IDB_SAVE_FILE   ||
  469.                                          callback_index == IDB_DELETE_FILE ||
  470.                                          callback_index == IDB_READONLY    ||
  471.                                          callback_index == IDB_LOCK_FILE   ||
  472.                                          callback_index == IDB_SCL_SAVE_AS ))
  473.    {
  474.       # add selected command to the list of pending commands
  475.       bufferListRegisterCommand( callback_index )
  476.       set_dialog_item(dhBufferList, IDL_LIST, DAC_DESELECT_INDEX)
  477.       set_dialog_item(dhBufferList, IDL_LIST, DAC_SETFOCUS)
  478.       return DRC_MSG_PROCESSED 
  479.    }
  480.    else if (!save_changes_list && (callback_msg == DM_OK            ||
  481.                                    callback_msg == DM_DOUBLE_CLICK  ||
  482.                                    (callback_msg == DM_CLICK &&
  483.                                     callback_index == DI_OK)))
  484.    {
  485.       # processing all pending commands
  486. #      bufferListProcessCommands()
  487.  
  488.       # return selected buffer name, if any
  489.       sel = bufferListSelected()
  490.       if ( sel >= 0 )
  491.          dialog_return_value = bufferListText(sel)
  492.       else
  493.          dialog_return_value = ""
  494.  
  495.       return DRC_EXIT
  496.    }
  497.    else if ( ((callback_msg == DM_CLICK) && (callback_index == IDB_SCL_QUIT)) ||
  498.              ((callback_msg == DM_OK) && save_changes_list) )
  499.    {      
  500.       dialog_return_value = ""
  501.       return DRC_EXIT
  502.    }
  503.    else if ( (callback_msg == DM_CLICK) && (callback_index == IDB_SCL_SAVE_ALL) )
  504.    {
  505.       temp = query_dialog_item(dhBufferList, IDL_LIST, DAC_FIRST_INDEX)
  506.  
  507.       set_dialog_item(dhBufferList, IDL_LIST, DAC_SELECT_INDEX_RANGE, 0, buffer_list_index)
  508.  
  509.       bufferListRegisterCommand( IDB_SAVE_FILE )
  510.  
  511.       set_dialog_item(dhBufferList, IDL_LIST, DAC_DESELECT_INDEX_RANGE, 0, buffer_list_index)
  512.       set_dialog_item(dhBufferList, IDL_LIST, DAC_SELECT_INDEX, temp)
  513.  
  514.       set_dialog_item(dhBufferList, IDL_LIST, DAC_SETFOCUS)
  515.       return DRC_MSG_PROCESSED 
  516.    }
  517.    else if (( callback_msg == DM_CANCEL ) || 
  518.             ( callback_msg == DM_CLICK    && callback_index == DI_CANCEL ))
  519.    {
  520.       process_ok = 0
  521.       dialog_return_value = ""
  522.       return DRC_EXIT
  523.    }
  524.    else if ( callback_msg == DM_SET_FOCUS )
  525.    {
  526.       if ( callback_index == IDB_DELETE_FILE )
  527.          set_dialog_item(dhBufferList, IDL_LIST, DAC_SETFOCUS)
  528.    }
  529. #  else if ( callback_msg == DM_KILL_FOCUS )
  530. #  {
  531. #     # And this Message  !!??.
  532. #  }
  533.  
  534.    return DRC_CONTINUE
  535. }
  536.  
  537. #=======================================================================
  538. # create_list_dialog
  539. #   creates a dialog box containing a list box that is used for 
  540. #   displaying information similar to error information.  Where you
  541. #   have some text and a location in a file to goto when that text
  542. #   is selected.  Also used in grep and routines.
  543. #
  544. #  paramters:
  545. #   title     - title of dialog box
  546. #   help_file - Help file for dialog box
  547. #=======================================================================
  548. global   DLG_LIST_DIALOG   =  1511
  549. global   DLG_LIST_DIALOG2  =  1514
  550. local    DLG_HEIGHT_DIFF   =  35
  551. local    DLG_HEIGHT_DIFF2  =  170
  552. local    DLG_WIDTH_DIFF    =  30
  553.  
  554. # used in errorfix.pel
  555. local  dialog_data_list[] 
  556. local  dialog_title_list[]
  557. local  dialog_delete_list[]
  558. local  dialog_item_count_list[]
  559. local  bookmark_delete_list[]
  560. local  last_dialog_selected = 0
  561.  
  562. global function create_list_dialog(title, help_file, sub_callback, needs_input)
  563. {
  564.    local dlgid
  565.    local newtitle
  566.    local id         = 1
  567.    local callbackid = 0
  568.  
  569.    if ( argcount() < 3 )
  570.       callbackid = function_id( "dlg_list_callback" )
  571.    else
  572.    {
  573.       callbackid = function_id( sub_callback )
  574.       if ( !callbackid )
  575.          callbackid = function_id( "dlg_list_callback" )
  576.    }
  577.  
  578.    check_for_deleted_dialogs()
  579.  
  580.    newtitle = title
  581.  
  582.    while ( newtitle in dialog_title_list )
  583.    {
  584.       # append an identifer to end of title and try again
  585.       newtitle = sprintf("%s-%d", title, id)
  586.       id++
  587.    }
  588.  
  589.    # WGN 3/16 - replaced prompt_display_handle with 0 so that the search
  590.    # results dialog will not be a child of the Find Dialog.
  591.    dlgid = create_mdialog( callbackid, 
  592.                            (mdi_mode == 2)              \
  593.                               ? -1                      \
  594.                               : 0,
  595.                            needs_input                  \
  596.                               ? DLG_LIST_DIALOG2        \
  597.                               : DLG_LIST_DIALOG, 
  598.                            resource_dll )
  599.  
  600.    # add items for the buttons. Since the buttons are disabled the assumed type
  601.    # is incorrect so we must explicitly tell the dialog manager what type these
  602.    # controls are.
  603.    add_dialog_item( dlgid, DI_GOTO_BUTTON,   DCTRL_DEFAULT_PUSH_BUTTON )
  604.    add_dialog_item( dlgid, DI_NEXT_BUTTON,   DCTRL_PUSH_BUTTON )
  605.    add_dialog_item( dlgid, DI_PREV_BUTTON,   DCTRL_PUSH_BUTTON ) 
  606.    add_dialog_item( dlgid, IDB_CLOSE_BTN,    DCTRL_PUSH_BUTTON )
  607.    add_dialog_item( dlgid, DI_HELP,          DCTRL_PUSH_BUTTON )
  608.  
  609.    add_dialog_item( dlgid, DI_STOP_BUTTON,   DCTRL_PUSH_BUTTON )
  610.    add_dialog_item( dlgid, DI_DELETE_BUTTON, DCTRL_PUSH_BUTTON )
  611.    add_dialog_item( dlgid, IDL_LIST,         DCTRL_LIST_BOX )
  612.    
  613.    if (needs_input)
  614.    {
  615.       add_dialog_item( dlgid, DI_ENTER_BUTTON, DCTRL_PUSH_BUTTON )
  616.       add_dialog_item( dlgid, DI_INPUT,        DCTRL_EDIT )
  617.    }
  618.  
  619.    set_dialog_window( dlgid, DWC_TITLE, newtitle )
  620.    attach_help(help_file, dlgid)
  621.  
  622.    dialog_item_count_list[dlgid] = 0
  623.    dialog_title_list[newtitle]   = dlgid
  624.  
  625.    reinitialize_dialog_list()
  626.  
  627.    return dlgid
  628. }
  629.  
  630. #=======================================================================
  631. #  begin_list_dialog(dlgid)
  632. #  displays the dialog list box specified by dlgid parameter
  633. #=======================================================================
  634. global function begin_list_dialog(dlgid)
  635. {
  636.    begin_dialog(dlgid)
  637. }
  638.  
  639. #=======================================================================
  640. #  delete_list_dialog(dlgid)
  641. #  deletes the dialog list box from memory
  642. #=======================================================================
  643. global function delete_list_dialog(dlgid)
  644. {
  645.    local count
  646.    local dlg_title
  647.  
  648.    if ( dlgid in dialog_item_count_list )
  649.    {
  650.       count = dialog_item_count_list[dlgid]
  651.    
  652.       while ( count > 0 )
  653.       {
  654.          delete dialog_data_list[dlgid,count]
  655.          count--
  656.       }
  657.    
  658.       delete dialog_item_count_list[dlgid]
  659.       dlg_title = query_dialog_window(dlgid, DWC_TITLE)
  660.       delete dialog_title_list[dlg_title]
  661.    
  662.       delete_dialog(dlgid)
  663.       reinitialize_dialog_list()
  664.    }
  665.    else
  666.       warning( "delete_list_dialog:  invalid dialog handle(%d)", dlgid )
  667. }
  668.  
  669. #=======================================================================
  670. # add_item_to_list
  671. #    adds an item to a list box dialog.
  672. #
  673. #  parameters:
  674. #    dlgid    - dialog box to add item to
  675. #    data     - data to put in the list box
  676. #    filename - filename to load when item is selected
  677. #    line     - line in file to goto when item is selected
  678. #    col      - column in file to goto when item is selected
  679. #    hlen     - highlight length.  If zero no text is highlighted,
  680. #               if -1 the whole line is highlighted, -2 all characters
  681. #               from col to the end-of-line are selected, otherwise
  682. #               hlen characters are highlighted starting at col.
  683. #=======================================================================
  684. global function add_item_to_list(dlgid, data, filename, line, col, hlen)
  685. {
  686.    local index
  687.    local text = 1;
  688.  
  689.    index = set_dialog_item( dlgid, IDL_LIST, DAC_ADD_ITEM, data )
  690.  
  691.    if ( index != -1 )
  692.    {
  693.       dialog_data_list[dlgid,index]      = filename FS line FS col FS hlen
  694.       dialog_data_list[dlgid,index,text] = data;
  695.       dialog_item_count_list[dlgid]      = dialog_item_count_list[dlgid] + 1
  696.    }
  697.    else
  698.       warning("Could not add item to list.")
  699.  
  700.    return index
  701. }
  702.  
  703. local function remove_item(dlgid, index)
  704. {
  705.    local i, count = dialog_item_count_list[dlgid] - 1;
  706.    local text = 1, newtext;
  707.    
  708.    if (bookmark_delete_list[dlgid, index])
  709.    {
  710.       newtext = dialog_data_list[dlgid, index, text];
  711.       bookmark_delete_list[dlgid, index] = FALSE;
  712.    }
  713.    else
  714.    {
  715.       newtext = "(DEL) " dialog_data_list[dlgid, index, text];
  716.       bookmark_delete_list[dlgid, index] = TRUE;
  717.    }
  718.  
  719.    set_dialog_item(dlgid, IDL_LIST, DAC_DELETE_INDEX, index );
  720.    set_dialog_item(dlgid, IDL_LIST, DAC_ADD_INDEX, newtext, index );
  721.  
  722. }
  723.  
  724. local dlg_initialized[]
  725.  
  726. global function dlg_is_initialized( handle )
  727. {
  728.    if ( argcount() < 1 )
  729.       handle = callback_dialog_handle
  730.  
  731.    return( handle in dlg_initialized )
  732. }
  733.  
  734. global function set_dlg_initialized( handle )
  735. {
  736.    if ( argcount() < 1 )
  737.       handle = callback_dialog_handle
  738.  
  739.    dlg_initialized[ handle ] = TRUE
  740. }
  741.  
  742. global function unset_dlg_initialized( handle )
  743. {
  744.    if ( argcount() < 1 )
  745.       handle = callback_dialog_handle
  746.  
  747.    delete dlg_initialized[ handle ]
  748. }
  749.  
  750. global function valid_list_dialog( handle )
  751. {
  752.    return( handle in dialog_item_count_list )
  753. }
  754.  
  755. #=======================================================================
  756. #    dlg_list_callback()
  757. #  callback function for the dialog boxes that takes care
  758. #  of getting the next, prev, and goto buttons.
  759. #=======================================================================
  760. global function dlg_list_callback()
  761. {
  762.    local size
  763.    local sbar_size
  764.    local index
  765.    local ret     = DRC_CONTINUE
  766.  
  767.    # set the current dialog box. This is used in next/prev item because we
  768.    # really don't know what dialog box the user wants to use.
  769.    # DWM--DM_DEACTIVATE can get sent after DM_CLOSE, so check for that case
  770.    if ( callback_msg != DM_DEACTIVATE )
  771.       last_dialog_selected = callback_dialog_handle
  772.  
  773.    if ( callback_msg == DM_INIT )
  774.    {
  775.       set_dialog_item(callback_dialog_handle, IDL_LIST, DAC_SETFOCUS)
  776.       set_dialog_item(callback_dialog_handle, IDL_LIST, DAC_SELECT_INDEX, 0)
  777.  
  778.       if ( !dlg_is_initialized() )
  779.       {
  780. #         list_size = query_dialog_item(callback_dialog_handle, IDL_LIST, DAC_SIZE)
  781. #         font = query_dialog_item(callback_dialog_handle, IDL_LIST, DAC_FONT)
  782. #         warning("Initial ListBox height is: %d, Font is %x", list_size % 65536, font)
  783.          
  784.          fix_stop_button( callback_dialog_handle, FALSE )
  785. #         size = query_dialog_window(callback_dialog_handle, DWC_SIZE)
  786. #         sbar_size = query_dialog_window(callback_dialog_handle, DWC_STATUSBARSIZE)
  787. #         move_buttons(callback_dialog_handle, sbar_size)
  788. #         change_dialog_size( callback_dialog_handle, size, FALSE )
  789.          set_dlg_initialized()
  790.       }
  791.    } 
  792.    else if (callback_msg == DM_CLOSE || callback_msg == DM_CANCEL ||
  793.             ( callback_msg == DM_CLICK && callback_index == IDB_CLOSE_BTN ) )
  794.    {
  795.       close_dialog_box( callback_dialog_handle )
  796.       ret = DRC_EXIT;
  797.    }
  798.    else if (callback_msg == DM_HELPREQUESTED)
  799.    {
  800.       if(isWindows())
  801.          display_help("Dialog List", callback_dialog_handle);
  802.       else
  803.          display_help("dlglist", callback_dialog_handle);
  804.       ret = DRC_MSG_PROCESSED 
  805.    }
  806.    else if (callback_msg == DM_CLICK )
  807.    {
  808.       # goto button pressed
  809.       if ( callback_index == DI_GOTO_BUTTON )
  810.       {
  811.          process_selection()
  812.  
  813.          ret = DRC_MSG_PROCESSED
  814.       }
  815.       # next button pressed
  816.       else if ( callback_index == DI_NEXT_BUTTON )
  817.       {
  818.          goto_next_item(callback_dialog_handle)
  819.          ret = DRC_MSG_PROCESSED
  820.       }
  821.       # previous button pressed
  822.       else if ( callback_index == DI_PREV_BUTTON )
  823.       {
  824.          goto_prev_item(callback_dialog_handle)
  825.          ret = DRC_MSG_PROCESSED
  826.       }
  827.       else if ( callback_index == DI_HELP )
  828.       {
  829.          display_help("HelpOnHelp", callback_dialog_handle)
  830.          ret = DRC_MSG_PROCESSED 
  831.       }
  832.    }
  833.    # if list box is double clicked get the error text and goto error 
  834.    else if (callback_msg == DM_DOUBLE_CLICK && callback_index == IDL_LIST)
  835.    {
  836.       process_selection()
  837.  
  838.       ret = DRC_MSG_PROCESSED 
  839.    }
  840.    else if ( callback_msg == DM_SELECT && callback_index == IDL_LIST)
  841.    {
  842.       if (selection_ok(callback_dialog_handle))
  843.          set_dialog_item(callback_dialog_handle, DI_GOTO_BUTTON, DAC_ENABLE )
  844.       else
  845.          set_dialog_item(callback_dialog_handle, DI_GOTO_BUTTON, DAC_DISABLE )
  846.  
  847.       ret = DRC_MSG_PROCESSED 
  848.    }
  849.    # The list box should always have the focus
  850.    else if ( callback_msg == DM_SET_FOCUS )
  851.    {
  852.       if ( callback_index != IDL_LIST )
  853.          set_dialog_item(callback_dialog_handle, IDL_LIST, DAC_SETFOCUS)
  854.    }
  855.    else if ( callback_msg == DM_AFTER_ACTIVATE )
  856.    {
  857.       set_dialog_item(callback_dialog_handle, IDL_LIST, DAC_SETFOCUS)
  858.    }
  859.    else if ( callback_msg == DM_RESIZE )
  860.    {
  861.       resize_dialog( callback_dialog_handle, FALSE )
  862.       ret = DRC_MSG_PROCESSED 
  863.    }
  864.    return ret
  865. }
  866.  
  867. global function compile_list_callback()
  868. {
  869.    local index, data
  870.    local call_hand   = callback_dialog_handle
  871.    local call_msg    = callback_msg
  872.    local call_idx    = callback_index
  873.    local ret         = DRC_CONTINUE;
  874.    local size, sbar_size
  875.  
  876.    if ( call_msg == DM_INIT )
  877.    {
  878.       if ( !dlg_is_initialized( call_hand ) )
  879.       {
  880.          set_dialog_window( call_hand, DWC_STATUSBAR, 1)
  881.          fix_stop_button( call_hand, 1 )
  882.  
  883.          if (optional_function("compile_has_input", callback_dialog_handle) && \
  884.              query_dialog_item(callback_dialog_handle, DI_INPUT, DAC_ENABLE))
  885.          {
  886.             set_dialog_item(callback_dialog_handle, DI_INPUT, DAC_SETFOCUS)
  887.          }
  888.          else
  889.          {
  890.             size = query_dialog_window(callback_dialog_handle, DWC_SIZE)
  891.             sbar_size = query_dialog_window(callback_dialog_handle, DWC_STATUSBARSIZE)
  892.             move_buttons(callback_dialog_handle, sbar_size)
  893.             change_dialog_size( callback_dialog_handle, size, 1 )
  894.          }
  895.  
  896.          set_dlg_initialized()
  897.       }
  898.    }
  899.    else if ( call_msg == DM_CLICK || call_msg == DM_DOUBLE_CLICK )
  900.    {
  901.       if ( call_idx == DI_STOP_BUTTON )
  902.       {
  903.          optional_function( "stop_button_pressed", call_hand )
  904.          ret = DRC_MSG_PROCESSED
  905.       }
  906.       else if ( call_idx == DI_DELETE_BUTTON )
  907.       {
  908.          index = query_dialog_item( call_hand, IDL_LIST, DAC_SELECT_INDEX );
  909.          close_dialog_box( call_hand );
  910.          ret = DRC_MSG_PROCESSED
  911.       }
  912.       else if ( call_idx == DI_ENTER_BUTTON )
  913.       {
  914.          data = query_dialog_item(call_hand, DI_INPUT, DAC_EDIT_TEXT)
  915.          optional_function( "send_compile_data", call_hand, data )
  916.          set_dialog_item(call_hand, DI_INPUT, DAC_EDIT_TEXT, "")
  917.          ret = DRC_MSG_PROCESSED
  918.       }
  919.    }
  920.    else if ( callback_msg == DM_SET_FOCUS )
  921.    {
  922.       if (optional_function("compile_has_input", callback_dialog_handle)  && \
  923.           query_dialog_item(callback_dialog_handle, DI_INPUT, DAC_ENABLE) && \
  924.           callback_index != DI_INPUT)
  925.       {
  926.          set_dialog_item(callback_dialog_handle, DI_INPUT, DAC_SETFOCUS)
  927.       }
  928.    }
  929.    else if ( callback_msg == DM_RESIZE )
  930.    {
  931.       resize_dialog( callback_dialog_handle, 1 )
  932.       ret = DRC_MSG_PROCESSED
  933.    }
  934.  
  935.    if ( ret != DRC_MSG_PROCESSED )
  936.       return dlg_list_callback()
  937.    else
  938.       return ret
  939. }
  940.  
  941. global function bookmark_list_callback()
  942. {
  943.    local index;
  944.    local ret         = DRC_CONTINUE;
  945.    local call_hand   = callback_dialog_handle
  946.    local call_msg    = callback_msg
  947.    local call_idx    = callback_index
  948.    local text = 1;
  949.    local size, sbar_size
  950.  
  951.    if ( call_msg == DM_INIT )
  952.    {
  953.       if ( !dlg_is_initialized() )
  954.       {
  955.          fix_stop_button( call_hand, 2 )
  956. #         sbar_size = query_dialog_window(callback_dialog_handle, DWC_STATUSBARSIZE)
  957. #         move_buttons(callback_dialog_handle, sbar_size)
  958. #         size = query_dialog_window(callback_dialog_handle, DWC_SIZE)
  959. #         change_dialog_size( callback_dialog_handle, size, FALSE )
  960.          set_dlg_initialized()
  961.       }
  962.    }
  963.    else if ( call_msg == DM_CLICK || call_msg == DM_DOUBLE_CLICK )
  964.    {
  965.       if ( call_idx == DI_DELETE_BUTTON )
  966.       {
  967.          index = query_dialog_item( call_hand, IDL_LIST, DAC_SELECT_INDEX );
  968.          bookmark_delete_pressed( dialog_data_list[call_hand, index, text], dialog_data_list[call_hand, index] );
  969.          remove_item(call_hand, index);
  970.          set_dialog_item(callback_dialog_handle, DI_DELETE_BUTTON, DAC_DISABLE )
  971. #        close_dialog_box( call_hand );
  972.          ret = DRC_MSG_PROCESSED
  973.       }
  974.       else
  975.          set_dialog_item(callback_dialog_handle, DI_DELETE_BUTTON, DAC_ENABLE )
  976.    }
  977.    else if(call_msg == DM_SELECT)
  978.          set_dialog_item(callback_dialog_handle, DI_DELETE_BUTTON, DAC_ENABLE )
  979.  
  980.    else if ( callback_msg == DM_RESIZE )
  981.    {
  982.       resize_dialog( callback_dialog_handle, 2 )
  983.       ret = DRC_MSG_PROCESSED
  984.    }
  985.  
  986.    if ( ret != DRC_MSG_PROCESSED )
  987.       return dlg_list_callback()
  988.    else
  989.       return ret
  990. }
  991.  
  992. global function grep_list_callback()
  993. {
  994.    local ret         = DRC_EXIT
  995.    local call_hand   = callback_dialog_handle
  996.    local call_msg    = callback_msg
  997.    local call_idx    = callback_index
  998.    local size, sbar_size
  999.    local start_line, start_col, start_buffer
  1000.  
  1001.    if ( !process_background(IN_BACKGROUND) )
  1002.    {
  1003.       start_line = current_line
  1004.       start_col = current_column
  1005.       start_buffer = current_buffer
  1006.    }
  1007.  
  1008.    if ( call_msg == DM_INIT )
  1009.    {
  1010.       if ( !dlg_is_initialized( call_hand ) )
  1011.       {
  1012.          set_dialog_window( call_hand, DWC_STATUSBAR, 1)
  1013.          fix_stop_button( call_hand, 1 )
  1014.          size = query_dialog_window(callback_dialog_handle, DWC_SIZE)
  1015.          sbar_size = query_dialog_window(callback_dialog_handle, DWC_STATUSBARSIZE)
  1016.          move_buttons(callback_dialog_handle, sbar_size)
  1017.          change_dialog_size( callback_dialog_handle, size, 1 )
  1018.          set_dlg_initialized()
  1019.       }
  1020.    }
  1021.    else if ( call_msg == DM_CLICK || call_msg == DM_DOUBLE_CLICK )
  1022.    {
  1023.       if ( call_idx == DI_STOP_BUTTON )
  1024.       {
  1025.          set_dialog_item( call_hand, DI_STOP_BUTTON, DAC_DISABLE )
  1026.          process_background( STOP_BACKGROUND )
  1027.          ret = DRC_MSG_PROCESSED
  1028.       }
  1029.    }
  1030.    else if ( ( call_msg == DM_CLOSE || call_msg == DM_CANCEL ) ||
  1031.             ( callback_msg == DM_CLICK && callback_index == IDB_CLOSE_BTN ) )
  1032.    {
  1033.       current_window = current_window
  1034.       if ( query_dialog_item(call_hand, DI_STOP_BUTTON, DAC_ENABLE) )
  1035.       {
  1036.          set_dialog_item( call_hand, DI_STOP_BUTTON, DAC_DISABLE )
  1037.          process_background( STOP_BACKGROUND )
  1038.       }
  1039.  
  1040.       ret = DRC_EXIT
  1041.    }
  1042.    else if ( callback_msg == DM_RESIZE )
  1043.    {
  1044.       resize_dialog( callback_dialog_handle, 1 )
  1045.       ret = DRC_MSG_PROCESSED
  1046.    }
  1047.  
  1048.    if ( ret == DRC_EXIT )
  1049.       ret = dlg_list_callback()
  1050.  
  1051.    if ( !process_background(IN_BACKGROUND) )
  1052.    {
  1053.       # If the current message caused a buffer position change
  1054.       # while processing in the foreground, then save that pos.
  1055.       if (  start_line != current_line    || 
  1056.             start_col != current_column   ||
  1057.             start_buffer != current_buffer )
  1058.          save_foreground_context()
  1059.    }
  1060.  
  1061.    return ret
  1062. }
  1063.  
  1064. local function close_dialog_box( dlghand )
  1065. {
  1066.    local count
  1067.    local dlg_title
  1068.  
  1069.    if ( argcount() < 1 )
  1070.       dlghand = callback_dialog_handle
  1071.  
  1072.    count = dialog_item_count_list[ dlghand ]
  1073.  
  1074.    while ( count >= 0 )
  1075.    {
  1076.       delete dialog_data_list[ dlghand, count ]
  1077.       count--
  1078.    }
  1079.  
  1080.    last_dialog_selected = 0
  1081.  
  1082.    delete dialog_item_count_list[ dlghand ]
  1083.    dlg_title = query_dialog_window( dlghand, DWC_TITLE )
  1084.    delete dialog_title_list[ dlg_title ]
  1085.    dialog_delete_list[ dlghand ] = 0
  1086.    reinitialize_dialog_list()
  1087.  
  1088.    unset_dlg_initialized( dlghand )
  1089.  
  1090.    # errorfix uses this to stop a compile if the dialog box is closed
  1091.    # while the compile is going on.
  1092.    optional_function( "close_dialog_box", dlghand )                              
  1093. }
  1094.  
  1095. local function process_selection(dlghandle, behindwin)
  1096. {
  1097.    local index
  1098.    local arr[]
  1099.    local filename
  1100.    local line
  1101.    local column
  1102.    local hlen
  1103.    local text
  1104.    local title
  1105.  
  1106.    if ( !dlghandle )
  1107.       dlghandle = callback_dialog_handle
  1108.  
  1109.    # get current text from list box
  1110.    index = query_dialog_item(dlghandle, IDL_LIST, DAC_SELECT_INDEX)
  1111.  
  1112.    if ( index >= 0 )
  1113.    {
  1114.       if ( split( dialog_data_list[dlghandle,index], arr ) )
  1115.       {
  1116.          filename = arr[1]
  1117.          line     = arr[2]
  1118.          column   = arr[3]
  1119.          hlen     = arr[4]
  1120.  
  1121.          # delete any temporary selection that may have been installed
  1122.          unhilight_temp_selection();
  1123.  
  1124.          if (line && length(filename))
  1125.          {
  1126.             create_buf_and_win(filename, behindwin)
  1127.  
  1128.             # if this is a compile dialog box then go to the old line
  1129.             # otherwise use goto_line.  This allows the user to make
  1130.             # changes to the file after compiling and then use next error
  1131.             # to position to the correct place.  If the user saves the file
  1132.             # then old line is reset and will then function just like goto_line
  1133.             title = query_dialog_window(dlghandle, DWC_TITLE)
  1134.             if ( substr(title, 1, 7) == "Compile" )
  1135.                goto_old_line(line)
  1136.             else
  1137.                goto_line(line)
  1138.  
  1139.             line=current_line
  1140.             goto_pos(line, column)
  1141.  
  1142.             # highlight to error line
  1143.             if ( hlen > 0 )
  1144.             {
  1145.                create_linecol_selection(NORMAL_SELECTION, line, column+hlen,
  1146.                                         line, column)
  1147.             }
  1148.             else if ( hlen == -1 ) # Hilight Line
  1149.             {
  1150.                create_linecol_selection(LINE_SELECTION, line, column, line,
  1151.                                         column+hlen)
  1152.             }
  1153.             else if ( hlen == -2 ) # Hilight to End-of-Line
  1154.             {
  1155.                goto_eol()
  1156.                hlen = current_column - column
  1157.                if (hlen < 1)
  1158.                    hlen = 1
  1159.  
  1160.                create_linecol_selection(NORMAL_SELECTION, line, column+hlen,
  1161.                                         line, column)
  1162.             }
  1163.  
  1164.             text = query_dialog_item( dlghandle,  IDL_LIST, DAC_GET_INDEX_ITEM, index ) 
  1165.  
  1166.             if ( and(status_bar_flags, STB_MESSAGES) )
  1167.                message(text "")
  1168.  
  1169.             update_current_view()
  1170.          }
  1171.          else
  1172.             beep() # No Error Information for this item.
  1173.       }
  1174.       else
  1175.       {
  1176.          warning("Cannot retrieve information from list box.")
  1177.       }
  1178.    }
  1179. }
  1180.  
  1181. local function selection_ok(dlghand, index)
  1182. {
  1183.    local arr[]
  1184.  
  1185.    if (argcount() < 2 || index < 0)
  1186.       index = query_dialog_item(dlghand, IDL_LIST, DAC_SELECT_INDEX)
  1187.  
  1188.    if ( index >= 0 )
  1189.    {
  1190.       if ( split( dialog_data_list[dlghand,index], arr ) )
  1191.       {
  1192.          if (arr[2] && length(arr[1]))
  1193.             return TRUE
  1194.       }
  1195.    }
  1196.    return FALSE
  1197. }
  1198.  
  1199. global function goto_next_item(dlg_handle, listbox)
  1200. {
  1201.    local numitems
  1202.    local numleft
  1203.    local selecteditem
  1204.    local behindwin = dlg_handle
  1205.  
  1206.    if ( argcount() <= 0 )
  1207.    {
  1208.       dlg_handle = last_dialog_selected
  1209.       listbox = IDL_LIST
  1210.    }
  1211.    else if ( argcount() <= 1 )
  1212.       listbox = IDL_LIST
  1213.  
  1214.    if ( dlg_handle == 0 )
  1215.    {
  1216.       message("No list dialog selected")
  1217.       return
  1218.    }
  1219.  
  1220.    numitems     = query_dialog_item(dlg_handle, listbox, DAC_COUNT_ITEMS) 
  1221.    selecteditem = query_dialog_item(dlg_handle, listbox, DAC_SELECT_INDEX)
  1222.  
  1223. # DWM 4/19/94
  1224. # I don't know why this was here, but it was causing an unsightly "jumping"
  1225. # during next and prev items
  1226. #   if (selecteditem >= 0 )
  1227. #      set_dialog_item(dlg_handle, listbox, DAC_DESELECT_INDEX, selecteditem)
  1228.  
  1229.    numleft = numitems
  1230.    do
  1231.    {
  1232.       selecteditem++
  1233.       numleft--
  1234.    
  1235.       # go back to top of list
  1236.       if ( selecteditem >= numitems )
  1237.          selecteditem = 0
  1238.    }
  1239.    while ( numleft > 0 && !selection_ok(dlg_handle, selecteditem) )
  1240.  
  1241.    if ( numitems > 0 && selecteditem != -1 )
  1242.    {
  1243.       set_dialog_item(dlg_handle, listbox, DAC_SELECT_INDEX, selecteditem)
  1244.    
  1245.       process_selection(dlg_handle, behindwin)
  1246.    }
  1247.    else
  1248.       message("No items in current listbox: %s", query_dialog_window(dlg_handle, DWC_TITLE))
  1249. }
  1250.  
  1251. local function select_next_item(dlghandle, listbox)
  1252. {
  1253.    local numitems
  1254.    local selecteditem
  1255.  
  1256.    numitems     = query_dialog_item(dlghandle, listbox, DAC_COUNT_ITEMS) 
  1257.    selecteditem = query_dialog_item(dlghandle, listbox, DAC_SELECT_INDEX)
  1258.  
  1259.    if (selecteditem >= 0 )
  1260.       set_dialog_item(dlghandle, listbox, DAC_DESELECT_INDEX, selecteditem)
  1261.  
  1262.    selecteditem++
  1263.  
  1264.    # go back to top of list
  1265.    if (selecteditem >= numitems)
  1266.       selecteditem = 0
  1267.  
  1268.    set_dialog_item(dlghandle, listbox, DAC_SELECT_INDEX, selecteditem)
  1269. }
  1270.  
  1271. global function goto_prev_item(dlg_handle, listbox)
  1272. {
  1273.    local numitems
  1274.    local numleft
  1275.    local selecteditem
  1276.    local behindwin = dlg_handle
  1277.  
  1278.    if ( argcount() <= 0 )
  1279.    {
  1280.       dlg_handle = last_dialog_selected
  1281.       listbox = IDL_LIST
  1282.    }   
  1283.    else if ( argcount() <= 1 )
  1284.       listbox = IDL_LIST
  1285.  
  1286.    if ( dlg_handle == 0 )
  1287.    {
  1288.       message("No list dialog selected")
  1289.       return
  1290.    }
  1291.  
  1292.    numitems     = query_dialog_item(dlg_handle, listbox, DAC_COUNT_ITEMS) 
  1293.    selecteditem = query_dialog_item(dlg_handle, listbox, DAC_SELECT_INDEX)
  1294.  
  1295. # DWM 4/19/94
  1296. # I don't know why this was here, but it was causing an unsightly "jumping"
  1297. # during next and prev items
  1298. #   if ( selecteditem >= 0 )
  1299. #      set_dialog_item(dlg_handle, listbox, DAC_DESELECT_INDEX, selecteditem)
  1300.  
  1301.    numleft = numitems
  1302.    do
  1303.    {
  1304.       numleft--
  1305.       selecteditem--
  1306.    
  1307.       # go back to top of list
  1308.       if ( selecteditem < 0 )
  1309.          selecteditem = numitems-1
  1310.    }
  1311.    while ( numleft > 0 && !selection_ok(dlg_handle, selecteditem) )
  1312.  
  1313.    if ( numitems > 0 && selecteditem != -1 )
  1314.    {
  1315.       set_dialog_item(dlg_handle, listbox, DAC_SELECT_INDEX, selecteditem)
  1316.       process_selection(dlg_handle, behindwin)
  1317.    }
  1318.    else
  1319.       message("No items in current listbox: %s", query_dialog_window(dlg_handle, DWC_TITLE))
  1320. }
  1321.  
  1322. local function select_prev_item(dlghandle, listbox)
  1323. {
  1324.    local numitems
  1325.    local selecteditem
  1326.  
  1327.    numitems     = query_dialog_item(dlghandle, listbox, DAC_COUNT_ITEMS) 
  1328.    selecteditem = query_dialog_item(dlghandle, listbox, DAC_SELECT_INDEX)
  1329.  
  1330.    if (selecteditem >= 0 )
  1331.       set_dialog_item(dlghandle, listbox, DAC_DESELECT_INDEX, selecteditem)
  1332.  
  1333.    selecteditem--
  1334.  
  1335.    # go back to top of list
  1336.    if (selecteditem < 0)
  1337.       selecteditem = numitems-1
  1338.  
  1339.    set_dialog_item(dlghandle, listbox, DAC_SELECT_INDEX, selecteditem)
  1340. }
  1341.  
  1342. global function dialog_list()
  1343. {
  1344.    local i
  1345.    local callbackid
  1346.  
  1347.    if ( !DialogList )
  1348.    {
  1349.       callbackid = function_id( "dialog_list_callback" )
  1350.       DialogList = create_mdialog(callbackid, mdi_mode == 2 ? -1 : 0, DLG_LIST_DIALOG, resource_dll)
  1351.  
  1352.       fix_stop_button( DialogList )
  1353.       add_dialog_item( DialogList, IDL_LIST, DCTRL_LIST_BOX )
  1354.       set_dialog_window( DialogList, DWC_TITLE, "Dialog List" )
  1355.       attach_help(editor_helpfile, DialogList)
  1356.       begin_dialog( DialogList )
  1357.    }
  1358.    else
  1359.    {
  1360.       set_dialog_window(DialogList, DWC_SHOW )
  1361.       set_dialog_window(DialogList, DWC_TO_TOP )
  1362.    }
  1363.    
  1364.    reinitialize_dialog_list();
  1365.       
  1366. }
  1367.  
  1368. global function dialog_list_callback()
  1369. {
  1370.    local call_hand   = callback_dialog_handle
  1371.    local call_msg    = callback_msg
  1372.    local call_idx    = callback_index
  1373.  
  1374.    local ret         = DRC_CONTINUE
  1375.    local count
  1376.    local size, sbar_size
  1377.  
  1378.    if ( call_msg == DM_INIT )
  1379.    {
  1380.       set_dialog_item(call_hand, IDL_LIST, DAC_SETFOCUS)
  1381.       set_dialog_item(call_hand, IDL_LIST, DAC_SELECT_INDEX, 0)
  1382.       if ( !dlg_is_initialized() )
  1383.       {
  1384. #         size = query_dialog_window(callback_dialog_handle, DWC_SIZE)
  1385. #         sbar_size = query_dialog_window(callback_dialog_handle, DWC_STATUSBARSIZE)
  1386. #         move_buttons(callback_dialog_handle, sbar_size)
  1387. #         change_dialog_size( callback_dialog_handle, size, FALSE )
  1388.          set_dlg_initialized()
  1389.       }
  1390.    }
  1391.    else if (call_msg == DM_ACTIVATE)
  1392.    {
  1393.       reinitialize_dialog_list()
  1394.    }
  1395.    else if (call_msg == DM_HELPREQUESTED)
  1396.    {
  1397.       display_help("dialoglist", call_hand)
  1398.       ret = DRC_MSG_PROCESSED 
  1399.    }
  1400.    else if (call_msg == DM_CLOSE || call_msg == DM_CANCEL )
  1401.    {
  1402. #     DialogList = 0  
  1403. #     delete_dialog(call_hand)
  1404.       current_window = current_window
  1405.    }
  1406.    else if (call_msg == DM_CLICK )
  1407.    {
  1408.       # goto button pressed
  1409.       if ( call_idx == DI_GOTO_BUTTON )
  1410.       {
  1411.          if (goto_dialog_box())
  1412.             set_dialog_window(call_hand, DWC_HIDE)
  1413.          ret = DRC_MSG_PROCESSED
  1414.       }
  1415.       # next button pressed
  1416.       else if ( call_idx == DI_NEXT_BUTTON )
  1417.       {
  1418.          select_next_item(call_hand, IDL_LIST)
  1419.          if (goto_dialog_box())
  1420.             set_dialog_window(call_hand, DWC_HIDE)
  1421.          ret = DRC_MSG_PROCESSED
  1422.       }
  1423.       # previous button pressed
  1424.       else if ( call_idx == DI_PREV_BUTTON )
  1425.       {
  1426.          select_prev_item(call_hand, IDL_LIST)
  1427.          if (goto_dialog_box())
  1428.             set_dialog_window(call_hand, DWC_HIDE)
  1429.          ret = DRC_MSG_PROCESSED
  1430.       }
  1431.       else if ( call_idx == DI_HELP )
  1432.       {
  1433.          display_help("HelpOnHelp", call_hand)
  1434.          ret = DRC_MSG_PROCESSED 
  1435.       }
  1436.       else if (call_idx == IDB_CLOSE_BTN )
  1437.       {
  1438.          ret = DRC_EXIT
  1439.       }
  1440.    }
  1441.    # if list box is double clicked get the error text and goto error 
  1442.    else if (call_msg == DM_DOUBLE_CLICK && call_idx == IDL_LIST)
  1443.    {
  1444.       if (goto_dialog_box())
  1445.          set_dialog_window(call_hand, DWC_HIDE)
  1446.       ret = DRC_MSG_PROCESSED
  1447.    }
  1448.    # The list box should always have the focus
  1449.    else if ((call_msg == DM_SET_FOCUS) && (call_idx != IDL_LIST))
  1450.    {
  1451.       set_dialog_item(call_hand, IDL_LIST, DAC_SETFOCUS)
  1452.    }
  1453.    else if ( call_msg == DM_RESIZE )
  1454.    {
  1455.       resize_dialog( call_hand )
  1456.    }
  1457.    return ret
  1458. }
  1459.  
  1460. #local button
  1461. local function fix_stop_button( handle, compile )
  1462. {
  1463.    local help, new, close, stop, button
  1464.  
  1465.    # hide the stop button and shift the other two when we 
  1466.    # aren't compiling
  1467.    #
  1468.    if ( !compile )
  1469.    {
  1470.       # hide button since we won't need it
  1471.       #
  1472.       set_dialog_item( handle, DI_STOP_BUTTON,   DAC_HIDE )
  1473.       set_dialog_item( handle, DI_DELETE_BUTTON, DAC_HIDE )
  1474.       
  1475.       # get position of stop and close button
  1476.       #
  1477.       close.pos = query_dialog_item( handle, IDB_CLOSE_BTN,  DAC_POSITION)
  1478.       stop.pos  = query_dialog_item( handle, DI_STOP_BUTTON, DAC_POSITION)
  1479.       
  1480.       # use x and y of stop button and move cancel to it
  1481.       #
  1482.       new.x = stop.pos / 65536
  1483.       new.y = stop.pos % 65536
  1484.       set_dialog_item( handle, IDB_CLOSE_BTN, DAC_POSITION, new.x, new.y)
  1485.       
  1486.       # use x and y of old cancel position, and move help to it
  1487.       #
  1488.       new.x = close.pos / 65536
  1489.       new.y = close.pos % 65536
  1490.       set_dialog_item( handle, DI_HELP, DAC_POSITION, new.x, new.y)
  1491.    }
  1492.    else if (compile == 1)
  1493.       set_dialog_item( handle, DI_DELETE_BUTTON, DAC_HIDE )
  1494.    else if (compile == 2)
  1495.       set_dialog_item( handle, DI_STOP_BUTTON, DAC_HIDE )
  1496.  
  1497.    # get size and position of help button and determine the distance
  1498.    # before we hide the buttons 
  1499.    #
  1500.    help.size = query_dialog_item( handle, DI_HELP, DAC_SIZE)
  1501.    help.pos = query_dialog_item( handle, DI_HELP, DAC_POSITION)
  1502.    new.width  = help.size / 65536
  1503.    new.height = help.size % 65536
  1504.    new.x  = help.pos / 65536
  1505.    new.y = help.pos % 65536
  1506.    button.top = new.y + new.height + 40
  1507.    button.width = new.x + new.width + 15
  1508.  
  1509.    save_button_positions( handle, compile )
  1510. }
  1511.  
  1512. local button_pos[]
  1513. local function save_button_positions(handle, compile)
  1514. {
  1515.    local i
  1516.    for (i in button_pos)
  1517.       delete button_pos[i]
  1518.       
  1519. #   if (isWindows())
  1520.    {
  1521.       button_pos[DI_GOTO_BUTTON] = query_dialog_item( handle, DI_GOTO_BUTTON, DAC_POSITION)
  1522.       button_pos[DI_NEXT_BUTTON] = query_dialog_item( handle, DI_NEXT_BUTTON, DAC_POSITION)
  1523.       button_pos[DI_PREV_BUTTON] = query_dialog_item( handle, DI_PREV_BUTTON, DAC_POSITION)
  1524.       button_pos[IDB_CLOSE_BTN]  = query_dialog_item( handle, IDB_CLOSE_BTN,  DAC_POSITION)
  1525.       button_pos[DI_HELP]        = query_dialog_item( handle, DI_HELP,        DAC_POSITION)
  1526.  
  1527.       if (compile == 1)
  1528.          button_pos[DI_STOP_BUTTON]   = query_dialog_item( handle, DI_STOP_BUTTON, DAC_POSITION)
  1529.       else if (compile == 2)
  1530.          button_pos[DI_DELETE_BUTTON] = query_dialog_item( handle, DI_DELETE_BUTTON, DAC_POSITION)
  1531.    }
  1532. }
  1533.  
  1534. local function set_button_positions(handle)
  1535. {
  1536.    local i
  1537.    for (i in button_pos)
  1538.    {
  1539.       set_dialog_item(handle, i, DAC_POSITION,
  1540.                         button_pos[i] / 65536,
  1541.                         button_pos[i] % 65536)
  1542.    }
  1543. }
  1544.  
  1545.  
  1546. local function move_buttons(handle, dist)
  1547. {
  1548.    local i
  1549.    local newY, oldX
  1550.    local oldPos
  1551.    
  1552.    if (!button_pos)
  1553.       save_button_positions(handle, 0)
  1554.       
  1555.    for (i in button_pos)
  1556.    {
  1557.       #oldPos = button_pos[i]
  1558.       #oldX = button_pos[i] / 65536
  1559.       newY = and((button_pos[ i ] % 65536) + dist, 0x0000FFFF)
  1560.       #button_pos[i] = shiftl(oldX, 16) + newY
  1561.       button_pos[i] = and(button_pos[i],0xFFFF0000) 
  1562.       #warning("old = %x, new = %x", oldPos, button_pos[i])
  1563.       button_pos[i] += newY
  1564.       #warning("old = %x, new = %x", oldPos, button_pos[i])
  1565.       #warning("Old = %x, New = %x, Oldx = %d, %s", oldPos, button_pos[i], oldX, i)
  1566.    }
  1567.    
  1568.    set_button_positions(handle)
  1569.    
  1570.    oldX = query_dialog_item(handle, IDL_LIST, DAC_POSITION) / 65536
  1571.    newY = (query_dialog_item(handle, IDL_LIST, DAC_POSITION) % 65536) + dist
  1572.    set_dialog_item(handle, IDL_LIST, DAC_POSITION, oldX, newY )
  1573. }
  1574.  
  1575. local function resize_dialog( handle, compile )
  1576. {
  1577.    if (query_dialog_window(handle, DWC_ICONIZED))
  1578.       set_dialog_window(handle, DWC_HIDE)
  1579.    else
  1580.    {
  1581.       change_dialog_size(handle, callback_data, compile)
  1582.       # Make sure the dialog is shown Normal Sized if it is not zoomed..
  1583.       if (!query_dialog_window(handle, DWC_ZOOMED))
  1584.          set_dialog_window(handle, DWC_SHOW)
  1585.    }
  1586. }
  1587.  
  1588. local function change_dialog_size(handle, newsize, compile)
  1589. {
  1590.    local new               # new size of the dialog
  1591.    local edit_field_size   # height of the edit field
  1592.    local list_height # height of the listbox
  1593.    local sbar_height # height of the status bar
  1594.    local item_height # height of an item in the listbox !! Should be queried !!
  1595.    local rem         # difference between the current list_height and a multiple of item_height
  1596.    
  1597.    sbar_height = query_dialog_window(handle, DWC_STATUSBARSIZE) % 65536
  1598.    
  1599.    # new size is stored in a long as (short width)(short height)
  1600.    new.width  = newsize / 65536
  1601.    new.height = newsize % 65536
  1602.    
  1603.    if ( new.width && new.height )
  1604.    {
  1605.       save_button_positions(handle, compile)
  1606.       # resize edit control to match new dialog size (if it's there)
  1607.       if (optional_function("compile_has_input", handle))
  1608.       {
  1609.          list_height = new.height - DLG_HEIGHT_DIFF2
  1610.          edit_field_size = query_dialog_item(handle, DI_INPUT, DAC_SIZE)
  1611.          set_dialog_item(handle, DI_INPUT, DAC_SIZE,
  1612.                          new.width - DLG_WIDTH_DIFF + 5,  edit_field_size % 65536)
  1613.       }
  1614.       else
  1615.          list_height = new.height - 
  1616.             query_dialog_item( handle, IDL_LIST, DAC_POSITION) % 65536 -
  1617.             DLG_HEIGHT_DIFF
  1618.          
  1619.       # NOTE: The purpose of this code is to keep the size of the listbox = to a
  1620.       # multiple of the height of the items in it.  This code should be replaced
  1621.       # with code to get the height of items in the listbox.
  1622. #      if (screen_width > 800)
  1623. #         item_height = 20
  1624. #      else if (screen_width < 700)
  1625. #         item_height = 16
  1626. #      else
  1627. #         item_height = 18
  1628. #      
  1629. #      if ( list_height > item_height && (rem = list_height % item_height))
  1630. #         list_height -= rem
  1631.    
  1632. #      message("sbar = %d, list = %d, total = %d", sbar_height, list_height, new.height)
  1633.    
  1634.       # resize list box to match new dialog size
  1635.       set_dialog_item(handle, IDL_LIST, DAC_SIZE,
  1636.                         new.width - DLG_WIDTH_DIFF, list_height )
  1637.    
  1638.       # Move the buttons for Windows.
  1639.       if (isWindows())
  1640.       {
  1641.          set_button_positions(handle)
  1642. #         set_dialog_item(handle, DI_GOTO_BUTTON, DAC_POSITION,
  1643. #                           button_pos[DI_GOTO_BUTTON] / 65536,
  1644. #                           button_pos[DI_GOTO_BUTTON] % 65536)
  1645. #   
  1646. #         set_dialog_item(handle, DI_NEXT_BUTTON, DAC_POSITION,
  1647. #                           button_pos[DI_NEXT_BUTTON] / 65536,
  1648. #                           button_pos[DI_NEXT_BUTTON] % 65536)
  1649. #   
  1650. #         set_dialog_item(handle, DI_PREV_BUTTON, DAC_POSITION,
  1651. #                           button_pos[DI_PREV_BUTTON] / 65536,
  1652. #                           button_pos[DI_PREV_BUTTON] % 65536)
  1653. #   
  1654. #         set_dialog_item(handle, IDB_CLOSE_BTN, DAC_POSITION,
  1655. #                           button_pos[IDB_CLOSE_BTN] / 65536,
  1656. #                           button_pos[IDB_CLOSE_BTN] % 65536)
  1657. #   
  1658. #         set_dialog_item(handle, DI_HELP, DAC_POSITION,
  1659. #                           button_pos[DI_HELP] / 65536,
  1660. #                           button_pos[DI_HELP] % 65536)
  1661. ##   
  1662. #         if (compile == 1)
  1663. #         {
  1664. #            set_dialog_item(handle, DI_STOP_BUTTON, DAC_POSITION,
  1665. #                              button_pos[DI_STOP_BUTTON] / 65536,
  1666. #                              button_pos[DI_STOP_BUTTON] % 65536)
  1667. #         }
  1668. #         else if (compile == 2)
  1669. #         {
  1670. #            set_dialog_item(handle, DI_DELETE_BUTTON, DAC_POSITION,
  1671. #                              button_pos[DI_DELETE_BUTTON] / 65536,
  1672. #                              button_pos[DI_DELETE_BUTTON] % 65536)
  1673. #         }
  1674.       }
  1675.    }
  1676.    
  1677.    # show/hide the group of buttons if new dimensions are smaller
  1678.    # than the group of buttons
  1679.    #
  1680.    if ( compile == 1)
  1681.       show_button( handle, DI_STOP_BUTTON, new )
  1682.    else if(compile == 2)
  1683.       show_button( handle, DI_DELETE_BUTTON, new )
  1684.    
  1685.    if (query_dialog_item( callback_dialog_handle, DI_ENTER_BUTTON, DAC_SHOW))
  1686.       show_button( handle, DI_ENTER_BUTTON, new )
  1687.  
  1688.    show_button( handle, DI_GOTO_BUTTON, new )
  1689.    show_button( handle, DI_NEXT_BUTTON, new )
  1690.    show_button( handle, DI_PREV_BUTTON, new )
  1691.    show_button( handle, IDB_CLOSE_BTN,  new )
  1692.    show_button( handle, DI_HELP,        new )
  1693. }
  1694.  
  1695. global function show_button(dlgid, btnid, new)
  1696. {
  1697.    local button, show
  1698.  
  1699.    button.size   = query_dialog_item( dlgid, btnid, DAC_SIZE)
  1700.    button.pos    = query_dialog_item( dlgid, btnid, DAC_POSITION)
  1701.  
  1702.    button.width  = button.size / 65536
  1703.    button.height = button.size % 65536
  1704.  
  1705.    button.x      = button.pos  / 65536
  1706.    button.y      = button.pos  % 65536
  1707.  
  1708.    button.top    = button.y + button.height + 40
  1709.    button.width  = button.x + button.width  + 15
  1710.  
  1711.    show = ( new.height < button.top || new.width < button.width ) \
  1712.           ? DAC_HIDE : DAC_SHOW
  1713.  
  1714.    set_dialog_item( dlgid, btnid,   show )
  1715. }
  1716.  
  1717. local function goto_dialog_box()
  1718. {
  1719.    local dlg_title
  1720.    local dlg_handle
  1721.    local ret = FALSE
  1722.  
  1723.    if ( query_dialog_item( callback_dialog_handle, IDL_LIST, DAC_COUNT_ITEMS) )
  1724.    {
  1725.       dlg_title = query_dialog_item( callback_dialog_handle, IDL_LIST, DAC_SELECT_ITEM)
  1726.       
  1727.       if ( dlg_title )
  1728.       {
  1729.          dlg_handle = first_dialog()
  1730.          while (dlg_handle)
  1731.          {
  1732.             if (!(dlg_handle in dialog_delete_list) && 
  1733.                dlg_title == query_dialog_window(dlg_handle, DWC_TITLE) )
  1734.             {
  1735.                set_dialog_window(dlg_handle, DWC_SHOW )
  1736.                set_dialog_window(dlg_handle, DWC_TO_TOP )
  1737. #               last_dialog_selected = dlg_handle
  1738.                ret = TRUE
  1739.                break
  1740.             }
  1741.             dlg_handle = next_dialog()
  1742.          }
  1743. #         set_dialog_window(dialog_title_list[dlg_title], DWC_SHOW )
  1744. #         set_dialog_window(dialog_title_list[dlg_title], DWC_TO_TOP )
  1745. #         last_dialog_selected = dialog_title_list[dlg_title]
  1746.       }
  1747.    }
  1748.    
  1749.    if (!ret)
  1750.    {
  1751.       warning("Selected dialog has been deleted")
  1752.       reinitialize_dialog_list()
  1753.    }
  1754.    
  1755.    return ret
  1756. }
  1757.  
  1758. global function reinitialize_dialog_list()
  1759. {
  1760.    local i
  1761.    local cnt = 0
  1762.    local compile, enable
  1763.    local dlg_handle
  1764.    local title
  1765.  
  1766.    if ( DialogList )
  1767.    {
  1768.        # clear listbox
  1769.       set_dialog_item(DialogList, IDL_LIST, DAC_CLEAR_LIST )
  1770.       
  1771.       dlg_handle = first_dialog()
  1772.       while (dlg_handle)
  1773.       {
  1774.          if (dlg_handle != DialogList && !(dlg_handle in dialog_delete_list) )
  1775.          {
  1776.             cnt++
  1777.             title = query_dialog_window(dlg_handle, DWC_TITLE)
  1778.             set_dialog_item(DialogList, IDL_LIST, DAC_ADD_ITEM, title)
  1779.          }
  1780.          dlg_handle = next_dialog()
  1781.       }
  1782.       
  1783. #      for ( i in dialog_title_list )
  1784. #      {
  1785. #         cnt++
  1786. #         set_dialog_item(DialogList, IDL_LIST, DAC_ADD_ITEM, i )           
  1787. #      }
  1788.  
  1789.       enable = ( cnt > 0 ) ? DAC_ENABLE : DAC_DISABLE
  1790.       
  1791.       # if the STOP button is visible, enable/disable it
  1792.       #
  1793.       if ( query_dialog_item( DialogList, DI_STOP_BUTTON, DAC_SHOW) )
  1794.          set_dialog_item( DialogList, DI_STOP_BUTTON, enable )
  1795.       if ( query_dialog_item( DialogList, DI_DELETE_BUTTON, DAC_SHOW) )
  1796.          set_dialog_item( DialogList, DI_DELETE_BUTTON, enable )
  1797.  
  1798.       set_dialog_item( DialogList, DI_GOTO_BUTTON, enable )
  1799.       set_dialog_item( DialogList, DI_NEXT_BUTTON, enable )
  1800.       set_dialog_item( DialogList, DI_PREV_BUTTON, enable )
  1801.    }
  1802. }
  1803.  
  1804. local function check_for_deleted_dialogs()
  1805. {
  1806.    local index
  1807.  
  1808.    for ( index in dialog_delete_list )
  1809.    {
  1810.       delete dialog_delete_list[index]
  1811.       delete_dialog(index)
  1812.    }
  1813. }
  1814.  
  1815. ################################ COMMAND ##################
  1816.  
  1817. function gui_command()
  1818. {
  1819.    CommandDlg = create_dialog(function_id("command_dlg_callback"), 0, 
  1820.                         IDD_CMD_DLG, resource_dll )
  1821.    add_dialog_item( CommandDlg, IDE_COMMAND, DCTRL_EDIT_KEY )
  1822.    attach_help(editor_helpfile, CommandDlg)
  1823.       
  1824.    setup_prompt_history("XMACRO")
  1825.  
  1826.    initialize_command_dlg()
  1827.    begin_dialog( CommandDlg )
  1828.    delete_dialog( CommandDlg )
  1829.  
  1830.    if ( dialog_return_value != "" )
  1831.       invoke_function( dialog_return_value )
  1832. }
  1833.  
  1834. function initialize_command_dlg()
  1835. {
  1836.    local cmd_array
  1837.    local i
  1838.  
  1839.    cmd_array = get_history( "XMACRO" )
  1840.    for (i in cmd_array )
  1841.    {
  1842.       set_dialog_item(CommandDlg, IDL_CMD_HISTORY, DAC_ADD_ITEM, cmd_array[i])
  1843.    }
  1844.    set_dialog_item( CommandDlg, IDE_COMMAND, DAC_SET_TEXT_LEN, 256 )
  1845.    set_dialog_item( CommandDlg, IDE_COMMAND, DAC_SETFOCUS )
  1846.    dialog_return_value = ""
  1847. }
  1848.  
  1849. function command_dlg_callback()
  1850. {
  1851.    local call_hand   = callback_dialog_handle
  1852.    local call_msg    = callback_msg
  1853.    local call_idx    = callback_index
  1854.  
  1855.    local retval
  1856.  
  1857.    if ( ( call_msg == DM_CLICK && call_idx == DI_HELP ) ||
  1858.       ( call_msg == DM_HELPREQUESTED ) ) 
  1859.    {
  1860.       if(isWindows())
  1861.          display_help("Command dialog", CommandDlg );
  1862.       else
  1863.          display_help("command", CommandDlg );
  1864.       return DRC_MSG_PROCESSED
  1865.    } # end DI_HELP
  1866.  
  1867.    else if ( call_msg == DM_OK )
  1868.    {
  1869.       cleanup_prompt_history("XMACRO")
  1870.       dialog_return_value = query_dialog_item(call_hand, IDE_COMMAND, DAC_EDIT_KEY_TEXT)
  1871.    } # end DM_OK
  1872.    
  1873.    else if ( call_msg == DM_CLOSE || call_idx == DI_CANCEL)
  1874.    {
  1875.       cleanup_prompt_history("XMACRO")
  1876.       dialog_return_value = ""
  1877.       return DRC_EXIT
  1878.    } # end DM_CANCEL
  1879.  
  1880.    else if ( (call_msg == DM_CLICK) || (call_msg == DM_DOUBLE_CLICK) )
  1881.    {
  1882.       return DRC_MSG_PROCESSED
  1883.    } # end DM_DOUBLE_CLICK && DM_CLICK
  1884.  
  1885.    else if ( call_msg == DM_KILL_FOCUS ) 
  1886.    {
  1887.       if ( call_idx == IDE_COMMAND )
  1888.          {
  1889.             retval = query_dialog_item(call_hand, call_idx, DAC_EDIT_KEY_TEXT)
  1890.             set_dialog_item(call_hand, call_idx, DAC_EDIT_KEY_TEXT, 
  1891.                            retval "") 
  1892.          }
  1893.       
  1894.       return DRC_MSG_PROCESSED
  1895.    } # end DM_KILL_FOCUS
  1896.  
  1897.    else if ( call_msg == DM_SELECT )
  1898.    {
  1899.       if ( call_idx == IDL_CMD_HISTORY )
  1900.       {
  1901.          retval = query_dialog_item(call_hand, call_idx, DAC_SELECT_ITEM)
  1902.          set_dialog_item(call_hand, IDE_COMMAND, DAC_EDIT_KEY_TEXT, 
  1903.                               retval, 1 )
  1904.  
  1905.       }
  1906.       return DRC_MSG_PROCESSED
  1907.    } # end DM_SELECT
  1908.  
  1909.    else if (call_msg == DM_INVALID_PCHAR)
  1910.    {
  1911.       if ( callback_index == IDE_COMMAND )
  1912.       {
  1913.          dialog_history( call_hand, call_idx, "XMACRO")
  1914.          set_dialog_item(call_hand, IDL_CMD_HISTORY, 
  1915.                          DAC_SELECT_ITEM, prompt_response)
  1916.       }
  1917.  
  1918.       return DRC_MSG_PROCESSED
  1919.    }
  1920.    return DRC_CONTINUE
  1921.  
  1922. }
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.