home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / anwor032.zip / antiword.0.32 / icons.c < prev    next >
C/C++ Source or Header  |  2001-04-22  |  2KB  |  95 lines

  1. /*
  2.  * icons.c
  3.  * Copyright (C) 1998-2001 A.J. van Os; Released under GPL
  4.  *
  5.  * Description:
  6.  * Update window icons
  7.  */
  8.  
  9. #include <string.h>
  10. #include "wimpt.h"
  11. #include "antiword.h"
  12.  
  13. void
  14. vUpdateIcon(wimp_w tWindow, wimp_icon *pIcon)
  15. {
  16.     wimp_redrawstr    r;
  17.     BOOL        bMore;
  18.  
  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));
  25.     }
  26. } /* end of vUpdateIcon */
  27.  
  28. void
  29. vUpdateRadioButton(wimp_w tWindow, wimp_i tIconNumber, BOOL bSelected)
  30. {
  31.     wimp_icon    tIcon;
  32.  
  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;
  40.     }
  41.     wimpt_noerr(wimp_set_icon_state(tWindow, tIconNumber,
  42.             bSelected ? wimp_ISELECTED : 0, wimp_ISELECTED));
  43.     vUpdateIcon(tWindow, &tIcon);
  44. } /* end of vUpdateRadioButton */
  45.  
  46. /*
  47.  * vUpdateWriteable - update a writeable icon with a string
  48.  */
  49. void
  50. vUpdateWriteable(wimp_w tWindow, wimp_i tIconNumber, char *szString)
  51. {
  52.     wimp_icon    tIcon;
  53.     wimp_caretstr    tCaret;
  54.     int        iLen;
  55.  
  56.     fail(szString == NULL);
  57.  
  58.     NO_DBG_DEC(tIconNumber);
  59.     NO_DBG_MSG(szString);
  60.  
  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;
  67.     }
  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));
  78.         }
  79.     }
  80.     wimpt_noerr(wimp_set_icon_state(tWindow, tIconNumber, 0,0));
  81.     vUpdateIcon(tWindow, &tIcon);
  82. } /* end of vUpdateWriteable */
  83.  
  84. /*
  85.  * vUpdateWriteableNumber - update a writeable icon with a number
  86.  */
  87. void
  88. vUpdateWriteableNumber(wimp_w tWindow, wimp_i tIconNumber, int iNumber)
  89. {
  90.     char    szTmp[12];
  91.  
  92.     (void)sprintf(szTmp, "%d", iNumber);
  93.     vUpdateWriteable(tWindow, tIconNumber, szTmp);
  94. } /* end of vUpdateWriteableNumber */
  95.