Imported from antiword-0.36.tar.gz.
[antiword.git] / icons.c
blob402fc7d8595a26c46cb6a0d9644ffb83d3de4639
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 "wimpt.h"
11 #include "antiword.h"
13 void
14 vUpdateIcon(wimp_w tWindow, wimp_icon *pIcon)
16 wimp_redrawstr r;
17 BOOL bMore;
19 r.w = tWindow;
20 r.box = pIcon->box;
21 wimpt_noerr(wimp_update_wind(&r, &bMore));
22 while (bMore) {
23 (void)wimp_ploticon(pIcon);
24 wimpt_noerr(wimp_get_rectangle(&r, &bMore));
26 } /* end of vUpdateIcon */
28 void
29 vUpdateRadioButton(wimp_w tWindow, wimp_i tIconNumber, BOOL bSelected)
31 wimp_icon tIcon;
33 wimpt_noerr(wimp_get_icon_info(tWindow, tIconNumber, &tIcon));
34 DBG_DEC(tIconNumber);
35 DBG_HEX(tIcon.flags);
36 if (bSelected ==
37 ((tIcon.flags & wimp_ISELECTED) == wimp_ISELECTED)) {
38 /* No update needed */
39 return;
41 wimpt_noerr(wimp_set_icon_state(tWindow, tIconNumber,
42 bSelected ? wimp_ISELECTED : 0, wimp_ISELECTED));
43 vUpdateIcon(tWindow, &tIcon);
44 } /* end of vUpdateRadioButton */
47 * vUpdateWriteable - update a writeable icon with a string
49 void
50 vUpdateWriteable(wimp_w tWindow, wimp_i tIconNumber, char *szString)
52 wimp_icon tIcon;
53 wimp_caretstr tCaret;
54 int iLen;
56 fail(szString == NULL);
58 NO_DBG_DEC(tIconNumber);
59 NO_DBG_MSG(szString);
61 wimpt_noerr(wimp_get_icon_info(tWindow, tIconNumber, &tIcon));
62 NO_DBG_HEX(tIcon.flags);
63 if ((tIcon.flags & (wimp_ITEXT|wimp_INDIRECT)) !=
64 (wimp_ITEXT|wimp_INDIRECT)) {
65 werr(1, "Icon %d must be indirected text", (int)tIconNumber);
66 return;
68 strncpy(tIcon.data.indirecttext.buffer,
69 szString,
70 tIcon.data.indirecttext.bufflen - 1);
71 /* Ensure the caret is behind the last character of the text */
72 wimpt_noerr(wimp_get_caret_pos(&tCaret));
73 if (tCaret.w == tWindow && tCaret.i == tIconNumber) {
74 iLen = strlen(tIcon.data.indirecttext.buffer);
75 if (tCaret.index != iLen) {
76 tCaret.index = iLen;
77 wimpt_noerr(wimp_set_caret_pos(&tCaret));
80 wimpt_noerr(wimp_set_icon_state(tWindow, tIconNumber, 0,0));
81 vUpdateIcon(tWindow, &tIcon);
82 } /* end of vUpdateWriteable */
85 * vUpdateWriteableNumber - update a writeable icon with a number
87 void
88 vUpdateWriteableNumber(wimp_w tWindow, wimp_i tIconNumber, int iNumber)
90 char szTmp[12];
92 (void)sprintf(szTmp, "%d", iNumber);
93 vUpdateWriteable(tWindow, tIconNumber, szTmp);
94 } /* end of vUpdateWriteableNumber */