Actions.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: Actions.c /main/8 1996/10/30 10:03:40 pascale $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: Actions.c
  28. **
  29. ** Project: Display Area Library
  30. **
  31. ** Description: This body of code handles the actions for the
  32. ** Display Area.
  33. **
  34. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  35. **
  36. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  37. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  38. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  39. ** (c) Copyright 1993, 1994 Novell, Inc.
  40. **
  41. **
  42. ****************************************************************************
  43. ************************************<+>*************************************/
  44. /*
  45. * system includes
  46. */
  47. #include <stdlib.h>
  48. #include <Xm/Xm.h>
  49. /*
  50. * CanvasEngine
  51. */
  52. #include "CanvasP.h"
  53. /*
  54. * private includes
  55. */
  56. #include "DisplayAreaP.h"
  57. #include "DisplayAreaI.h"
  58. #include "ActionsI.h"
  59. #include "CallbacksI.h"
  60. #ifdef NLS16
  61. #endif
  62. /******** Private Function Declarations ********/
  63. /******** End Private Function Declarations ********/
  64. /******** End Private Defines ********/
  65. /******** Private Variable Declarations ********/
  66. /******** End Private Variable Declarations ********/
  67. /******************************************************************************
  68. * Private Functions
  69. ******************************************************************************/
  70. /******************************************************************************
  71. * Semi Public Functions
  72. *****************************************************************************/
  73. /*****************************************************************************
  74. * Function: _DtHelpCopyAction
  75. *
  76. * _DtHelpCopyAction - Copy the current info to the clipboard
  77. *
  78. *****************************************************************************/
  79. void
  80. _DtHelpCopyAction (
  81. Widget widget,
  82. XEvent *event,
  83. String *params,
  84. Cardinal *num_params)
  85. {
  86. Arg args[2];
  87. XtPointer userData;
  88. XtSetArg(args[0], XmNuserData, &userData);
  89. XtGetValues(widget, args, 1);
  90. _DtHelpInitiateClipboard(userData);;
  91. } /* End _DtHelpCopyAction */
  92. /*****************************************************************************
  93. * Function: _DtHelpDeSelectAll
  94. *
  95. * _DtHelpDeSelectAll - Deselects the information in the widget.
  96. *
  97. *****************************************************************************/
  98. void
  99. _DtHelpDeSelectAll (
  100. Widget widget,
  101. XEvent *event,
  102. String *params,
  103. Cardinal *num_params)
  104. {
  105. Arg args[2];
  106. XtPointer userData;
  107. XtSetArg(args[0], XmNuserData, &userData);
  108. XtGetValues(widget, args, 1);
  109. if (userData != NULL)
  110. _DtHelpClearSelection (userData);
  111. } /* End _DtHelpDeSelectAll */
  112. /*****************************************************************************
  113. * Function: _DtHelpSelectAll
  114. *
  115. * _DtHelpSelectAll - Selects all the information in the widget.
  116. *
  117. *****************************************************************************/
  118. void
  119. _DtHelpSelectAll (
  120. Widget widget,
  121. XEvent *event,
  122. String *params,
  123. Cardinal *num_params)
  124. {
  125. Arg args[2];
  126. XtPointer userData;
  127. XtSetArg(args[0], XmNuserData, &userData);
  128. XtGetValues(widget, args, 1);
  129. if (userData != NULL)
  130. {
  131. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
  132. _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_OFF, False, True,
  133. NULL, NULL, NULL, NULL, NULL);
  134. _DtHelpGetClearSelection (widget, userData);
  135. _DtCanvasProcessSelection(pDAS->canvas, 0, 0, _DtCvSELECTION_START);
  136. _DtCanvasProcessSelection(pDAS->canvas, pDAS->dispUseWidth,
  137. pDAS->maxYpos, _DtCvSELECTION_END);
  138. _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_ON, False, True,
  139. NULL, NULL, NULL, NULL, NULL);
  140. pDAS->text_selected = True;
  141. }
  142. } /* End _DtHelpSelectAll */
  143. /*****************************************************************************
  144. * Function: _DtHelpActivateLink
  145. *
  146. * _DtHelpSelectAll - Selects all the information in the widget.
  147. *
  148. *****************************************************************************/
  149. void
  150. _DtHelpActivateLink (
  151. Widget widget,
  152. XEvent *event,
  153. String *params,
  154. Cardinal *num_params)
  155. {
  156. Arg args[2];
  157. DtHelpDispAreaStruct *pDAS;
  158. _DtCvLinkInfo ceHyper;
  159. DtHelpHyperTextStruct callData;
  160. XtSetArg(args[0], XmNuserData, &pDAS);
  161. XtGetValues(widget, args, 1);
  162. if (pDAS == NULL)
  163. return;
  164. if (! pDAS->dtinfo)
  165. {
  166. if (_DtCvSTATUS_OK == _DtCanvasGetCurLink(pDAS->canvas, &ceHyper))
  167. {
  168. callData.reason = XmCR_ACTIVATE;
  169. callData.event = event;
  170. callData.window = XtWindow (pDAS->dispWid);
  171. callData.specification = ceHyper.specification;
  172. callData.hyper_type = ceHyper.hyper_type;
  173. callData.window_hint = ceHyper.win_hint;
  174. (*(pDAS->hyperCall)) (pDAS, pDAS->clientData, &callData);
  175. }
  176. }
  177. else /* dtinfo context */
  178. {
  179. _DtCvPointer mark_enclosure = NULL;
  180. _DtCvStatus status;
  181. status = _DtCanvasGetCurTraversal(pDAS->canvas, &ceHyper,
  182. &mark_enclosure);
  183. if (status == _DtCvSTATUS_LINK)
  184. {
  185. callData.reason = XmCR_ACTIVATE;
  186. callData.event = event;
  187. callData.window = XtWindow (pDAS->dispWid);
  188. callData.specification = ceHyper.specification;
  189. callData.hyper_type = ceHyper.hyper_type;
  190. callData.window_hint = ceHyper.win_hint;
  191. (*(pDAS->hyperCall)) (pDAS, pDAS->clientData, &callData);
  192. }
  193. else if (status == _DtCvSTATUS_MARK)
  194. {
  195. callData.reason = XmCR_ACTIVATE;
  196. callData.event = event;
  197. callData.window = XtWindow (pDAS->dispWid);
  198. callData.specification = mark_enclosure;
  199. callData.hyper_type = -1; /* signifies it's a mark */
  200. callData.window_hint = 0;
  201. (*(pDAS->hyperCall)) (pDAS, pDAS->clientData, &callData);
  202. }
  203. /* otherwise do nothing */
  204. }
  205. } /* End _DtHelpActivateLink */
  206. /*****************************************************************************
  207. * Function: _DtHelpPageUpOrDown
  208. *
  209. * _DtHelpPageUpOrDown - Selects all the information in the widget.
  210. *
  211. *****************************************************************************/
  212. void
  213. _DtHelpPageUpOrDown (
  214. Widget widget,
  215. XEvent *event,
  216. String *params,
  217. Cardinal *num_params)
  218. {
  219. int keyPressed;
  220. _DtCvUnit newY;
  221. _DtCvUnit diff;
  222. Arg args[2];
  223. XtPointer userData;
  224. XtSetArg(args[0], XmNuserData, &userData);
  225. XtGetValues(widget, args, 1);
  226. if (userData != NULL)
  227. {
  228. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
  229. diff = pDAS->dispUseHeight - pDAS->lineHeight;
  230. keyPressed = atoi(*params);
  231. if (keyPressed == 0)
  232. diff = -diff;
  233. newY = pDAS->firstVisible + diff;
  234. /*
  235. * Is the new Y position too large?
  236. * If so, adjust.
  237. */
  238. if (newY + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
  239. newY = pDAS->maxYpos - pDAS->dispUseHeight;
  240. /*
  241. * Is the new Y before the begining?
  242. * If so, zero it.
  243. */
  244. if (newY < 0)
  245. newY = 0;
  246. if (newY != pDAS->firstVisible)
  247. {
  248. pDAS->firstVisible = newY;
  249. XtSetArg(args[0], XmNvalue, newY);
  250. XtSetValues (pDAS->vertScrollWid, args, 1);
  251. if (pDAS->vScrollNotify)
  252. (pDAS->vScrollNotify)(pDAS->clientData, pDAS->firstVisible);
  253. _DtHelpCleanAndDrawWholeCanvas (userData);
  254. }
  255. }
  256. } /* End _DtHelpPageUpOrDown */
  257. /*****************************************************************************
  258. * Function: _DtHelpPageLeftOrRight
  259. *
  260. * _DtHelpPageLeftOrRight - Selects all the information in the widget.
  261. *
  262. *****************************************************************************/
  263. void
  264. _DtHelpPageLeftOrRight (
  265. Widget widget,
  266. XEvent *event,
  267. String *params,
  268. Cardinal *num_params)
  269. {
  270. int keyPressed;
  271. _DtCvUnit newX;
  272. _DtCvUnit diff;
  273. Arg args[2];
  274. XtPointer userData;
  275. XtSetArg(args[0], XmNuserData, &userData);
  276. XtGetValues(widget, args, 1);
  277. if (userData != NULL)
  278. {
  279. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
  280. diff = pDAS->dispUseWidth - ((int) pDAS->charWidth / 10);
  281. keyPressed = atoi(*params);
  282. if (keyPressed == 0)
  283. diff = -diff;
  284. newX = pDAS->virtualX + diff;
  285. /*
  286. * Is the new X position too large?
  287. * If so, adjust.
  288. */
  289. if (newX + ((int)pDAS->dispUseWidth) > pDAS->maxX)
  290. newX = pDAS->maxX - pDAS->dispUseWidth;
  291. /*
  292. * Is the new X before the begining?
  293. * If so, zero it.
  294. */
  295. if (newX < 0)
  296. newX = 0;
  297. if (newX != pDAS->virtualX)
  298. {
  299. pDAS->virtualX = newX;
  300. XtSetArg(args[0], XmNvalue, newX);
  301. XtSetValues (pDAS->horzScrollWid, args, 1);
  302. _DtHelpCleanAndDrawWholeCanvas (userData);
  303. }
  304. }
  305. } /* End _DtHelpPageLeftOrRight */
  306. /*****************************************************************************
  307. * Function: _DtHelpNextLink
  308. *
  309. * _DtHelpNextLink - Moves the traversal to the requested hypertext link.
  310. *
  311. *****************************************************************************/
  312. void
  313. _DtHelpNextLink (
  314. Widget widget,
  315. XEvent *event,
  316. String *params,
  317. Cardinal *num_params)
  318. {
  319. _DtCvTraversalCmd cmd = _DtCvTRAVERSAL_NEXT;
  320. _DtCvUnit diff;
  321. _DtCvUnit newY;
  322. _DtCvUnit newX;
  323. _DtCvUnit height;
  324. _DtCvUnit top;
  325. Arg args[2];
  326. XtPointer userData;
  327. XtSetArg(args[0], XmNuserData, &userData);
  328. XtGetValues(widget, args, 1);
  329. if (userData != NULL)
  330. {
  331. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
  332. switch(atoi(*params))
  333. {
  334. case 0: cmd = _DtCvTRAVERSAL_PREV;
  335. break;
  336. case 2: cmd = _DtCvTRAVERSAL_TOP;
  337. break;
  338. case 3: cmd = _DtCvTRAVERSAL_BOTTOM;
  339. break;
  340. }
  341. if (_DtCvSTATUS_OK == _DtCanvasMoveTraversal(pDAS->canvas, cmd, False,
  342. (XtIsRealized(pDAS->dispWid) ? True : False),
  343. NULL, &newX, &newY, NULL, &height))
  344. {
  345. /*
  346. * take into account our traversal indicator
  347. */
  348. newY -= pDAS->lineThickness;
  349. height += (2 * pDAS->lineThickness);
  350. top = pDAS->firstVisible;
  351. diff = ((int) pDAS->dispUseHeight) * 2 / 3;
  352. if (newY < top)
  353. {
  354. top = newY;
  355. if (cmd == _DtCvTRAVERSAL_TOP && newY <= diff)
  356. top = 0;
  357. }
  358. else if (newY + height > top + ((int) pDAS->dispUseHeight))
  359. {
  360. top = newY + height - ((int) pDAS->dispUseHeight);
  361. if (cmd == _DtCvTRAVERSAL_BOTTOM &&
  362. newY >= (pDAS->maxYpos - diff))
  363. top = pDAS->maxYpos - pDAS->dispUseHeight;
  364. }
  365. if (top != pDAS->firstVisible)
  366. {
  367. pDAS->firstVisible = top;
  368. if (top + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
  369. {
  370. pDAS->firstVisible = pDAS->maxYpos - pDAS->dispUseHeight;
  371. if (pDAS->firstVisible < 0)
  372. pDAS->firstVisible = 0;
  373. }
  374. XtSetArg (args[0], XmNvalue, pDAS->firstVisible);
  375. XtSetValues (pDAS->vertScrollWid, args, 1);
  376. if (pDAS->vScrollNotify)
  377. (pDAS->vScrollNotify)(pDAS->clientData, pDAS->firstVisible);
  378. /*
  379. * re-draw the information
  380. */
  381. _DtHelpCleanAndDrawWholeCanvas (userData);
  382. }
  383. }
  384. }
  385. } /* End _DtHelpNextLink */