Imported from antiword-0.37.tar.gz.
[antiword.git] / icons.c
blobdd88c00531612ac572f3a8c39f8cfedad305d5e8
1 /*
2 * icons.c
3 * Copyright (C) 1998-2001 A.J. van Os; Released under GPL
5 * Description:
6 * Update window icons
7 */
9 #include <string.h>
10 #include "DeskLib:Error.h"
11 #include "DeskLib:WimpSWIs.h"
12 #include "antiword.h"
14 void
15 vUpdateIcon(window_handle tWindow, icon_block *pIcon)
17 window_redrawblock tRedraw;
18 BOOL bMore;
20 tRedraw.window = tWindow;
21 tRedraw.rect = pIcon->workarearect;
22 Error_CheckFatal(Wimp_UpdateWindow(&tRedraw, &bMore));
23 while (bMore) {
24 Error_CheckFatal(Wimp_PlotIcon(pIcon));
25 Error_CheckFatal(Wimp_GetRectangle(&tRedraw, &bMore));
27 } /* end of vUpdateIcon */
29 void
30 vUpdateRadioButton(window_handle tWindow, icon_handle tIconNumber,
31 BOOL bSelected)
33 icon_block tIcon;
35 Error_CheckFatal(Wimp_GetIconState(tWindow, tIconNumber, &tIcon));
36 DBG_DEC(tIconNumber);
37 DBG_HEX(tIcon.flags.data.selected);
38 if (bSelected == (tIcon.flags.data.selected == 1)) {
39 /* No update needed */
40 return;
42 Error_CheckFatal(Wimp_SetIconState(tWindow, tIconNumber,
43 bSelected ? 0x00200000 : 0, 0x00200000));
44 vUpdateIcon(tWindow, &tIcon);
45 } /* end of vUpdateRadioButton */
48 * vUpdateWriteable - update a writeable icon with a string
50 void
51 vUpdateWriteable(window_handle tWindow, icon_handle tIconNumber,
52 const char *szString)
54 icon_block tIcon;
55 caret_block tCaret;
56 int iLen;
58 fail(szString == NULL);
60 NO_DBG_DEC(tIconNumber);
61 NO_DBG_MSG(szString);
63 Error_CheckFatal(Wimp_GetIconState(tWindow, tIconNumber, &tIcon));
64 NO_DBG_HEX(tIcon.flags);
65 if (!tIcon.flags.data.text || !tIcon.flags.data.indirected) {
66 werr(1, "Icon %d must be indirected text", (int)tIconNumber);
67 return;
69 strncpy(tIcon.data.indirecttext.buffer,
70 szString,
71 tIcon.data.indirecttext.bufflen - 1);
72 /* Ensure the caret is behind the last character of the text */
73 Error_CheckFatal(Wimp_GetCaretPosition(&tCaret));
74 if (tCaret.window == tWindow && tCaret.icon == tIconNumber) {
75 iLen = strlen(tIcon.data.indirecttext.buffer);
76 if (tCaret.index != iLen) {
77 tCaret.index = iLen;
78 Error_CheckFatal(Wimp_SetCaretPosition(&tCaret));
81 Error_CheckFatal(Wimp_SetIconState(tWindow, tIconNumber, 0, 0));
82 vUpdateIcon(tWindow, &tIcon);
83 } /* end of vUpdateWriteable */
86 * vUpdateWriteableNumber - update a writeable icon with a number
88 void
89 vUpdateWriteableNumber(window_handle tWindow, icon_handle tIconNumber,
90 int iNumber)
92 char szTmp[1+3*sizeof(int)+1];
94 (void)sprintf(szTmp, "%d", iNumber);
95 vUpdateWriteable(tWindow, tIconNumber, szTmp);
96 } /* end of vUpdateWriteableNumber */