dlgutil.c
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:3k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. /*
  2. COW : Character Oriented Windows
  3. dlgutil.c : dialog utility routines
  4. */
  5. #define COW
  6. #include <cow.h>
  7. #define DIALOG
  8. #include <udialog.h>
  9. #include <uevent.h>
  10. #include <uwindow.h>
  11. #include <uedit.h>
  12. #include "dialog.h"
  13. #include "window.h"
  14. #include "util.h"
  15. PRIVATE VOID FARPRIVATE
  16. SetDlgItemText(pwnd, szText, fDisplay)
  17. /*
  18.   -- set the text for a given item
  19.   -- allow tilde characters for non-edit items
  20. */
  21. REGISTER PWND pwnd; /* the actual item */
  22. char *szText;
  23. BOOL fDisplay;
  24. {
  25. REGISTER char *pchSrc = szText;
  26. Assert(pwnd != NULL);
  27. if ((pwnd->style & WS_TYPE) == WS_EDIT)
  28. SetEditText(pwnd, pchSrc, fDisplay);
  29. else
  30. {
  31. WORD cch; /* max # of chars */
  32. REGISTER char * pchDest;
  33. BOOL fNoAccel;
  34. fNoAccel = (pwnd->style & WS_TYPE) == WS_STATIC_NOACCEL;
  35. cch = pwnd->cchDialog;
  36. Assert(cch > 0);
  37. pchDest = (char *) pwnd->szDialog;
  38. Assert(pchDest != NULL);
  39. pwnd->aclDialog = aclNil;
  40. while (1)
  41. {
  42. switch (*pchSrc)
  43. {
  44. default:
  45. default_char:
  46. *pchDest++ = *pchSrc++;
  47. #ifndef KANJI
  48. add_char:
  49. #endif
  50. if (--cch != 0)
  51. break; /* continue */
  52. /* else fall through to terminate */
  53. case '':
  54. /* terminate & we are done */
  55. *pchDest = '';
  56. goto done_scan;
  57. case chPrefix1:
  58. if (fNoAccel)
  59. goto default_char;
  60. /* set accelerator, show character */
  61. AssertSz(pwnd->aclDialog == aclNil &&
  62.     *(pchSrc+1) != '',
  63.     "Bogus ~ name");
  64. #ifndef KANJI
  65. Assert(pchSrc - szText < 256);
  66. if (*(pchSrc+1) == chPrefix1)
  67. {
  68. /* two accelerators => use one */
  69. pchSrc++;
  70. goto default_char;
  71. }
  72. pwnd->aclDialog = (((BYTE)
  73.     (pchSrc - szText)) << 8) +
  74.     *((unsigned char *)pchSrc+1);
  75. pchSrc++;
  76. #else
  77. /* two choices for R/K accelerators */
  78. AssertSz(pchSrc == szText,
  79.    "Kana accelerators must be at start of string");
  80. /* Roman in lobyte, Kana in high */
  81. pchSrc++; /* skip prefix */
  82. pwnd->aclDialog = *(WORD *)pchSrc;
  83. /* show proper dialog accelerator */
  84. *pchDest++ = *(fKanaAccel ? pchSrc+1 : pchSrc);
  85. pchSrc += 2;
  86. #endif /*KANJI*/
  87. break;
  88. #ifndef KANJI
  89. case chPrefix2:
  90. if (fNoAccel)
  91. goto default_char;
  92. /* set accelerator, show blank */
  93. AssertSz(pwnd->aclDialog == aclNil &&
  94.     *(pchSrc+1) != '',
  95.     "Bogus double~ name");
  96. Assert(pchSrc - szText < 256);
  97. pwnd->aclDialog = (((BYTE)
  98.     (pchSrc - szText)) << 8) +
  99.     *((unsigned char *)pchSrc+1);
  100. pchSrc += 2; /* skip prefix & accel character */
  101. *pchDest++ = ' ';
  102. goto add_char;
  103. /*break;*/
  104. #endif
  105. }
  106. }
  107. }
  108. done_scan:
  109. if (fDisplay)
  110. DrawWindow(pwnd);
  111. }
  112. PRIVATE WORD FARPRIVATE
  113. GetDlgItemText(pwnd, sz, cchMax)
  114. /*
  115.   -- get the text associated with a listbox, edit or static text item;
  116. copies up to cchsz characters into the buffer sz; returns the number
  117. of characters copied into the buffer
  118. */
  119. REGISTER PWND pwnd; /* the actual item */
  120. WORD cchMax;
  121. REGISTER char *sz;
  122. {
  123. WORD cch;
  124. Assert(pwnd != NULL);
  125. switch(pwnd->style & WS_TYPE)
  126. {
  127. case WS_LISTBOX:
  128. return(GetListText(pwnd, sz, cchMax));
  129. break;
  130. case WS_EDIT:
  131. return(GetEditText(pwnd, sz, cchMax));
  132. break;
  133. default:
  134. {
  135. REGISTER char *szDlg = (char *) pwnd->szDialog;
  136. for (cch = 0; *szDlg != '' && cch < cchMax; cch++)
  137. *sz++ = *szDlg++;
  138. *sz = '';
  139. return(cch);
  140. break;
  141. }
  142. }
  143. }