Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
4.2 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxWidget.cpp
  5. // implementation: Win32 API
  6. // last modified: Mar 19 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #include "mxtk/mxWidget.h"
  15. #include <windows.h>
  16. #include <commctrl.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. void mxTab_resizeChild (HWND hwnd);
  21. void mx_addWidget (mxWidget *widget);
  22. void mx_removeWidget (mxWidget *widget);
  23. class mxWidget_i
  24. {
  25. public:
  26. mxWindow *d_parent_p;
  27. HWND d_hwnd;
  28. void *d_userData;
  29. int d_type;
  30. };
  31. mxWidget::mxWidget (mxWindow *parent, int x, int y, int w, int h, const char *label)
  32. {
  33. d_this = new mxWidget_i;
  34. setHandle (0);
  35. setType (-1);
  36. setParent (parent);
  37. setBounds (x, y, w, h);
  38. setVisible (true);
  39. setEnabled (true);
  40. setId (0);
  41. setUserData (0);
  42. setLabel (label);
  43. mx_addWidget (this);
  44. }
  45. mxWidget::~mxWidget ()
  46. {
  47. mx_removeWidget (this);
  48. if (d_this->d_type == MX_MENU ||
  49. d_this->d_type == MX_MENUBAR ||
  50. d_this->d_type == MX_POPUPMENU)
  51. DestroyMenu ((HMENU) d_this->d_hwnd);
  52. else
  53. DestroyWindow (d_this->d_hwnd);
  54. delete d_this;
  55. }
  56. bool mxWidget::CanClose()
  57. {
  58. // Assume yes
  59. return true;
  60. }
  61. void mxWidget::OnDelete()
  62. {
  63. // Nothing
  64. }
  65. void
  66. mxWidget::setHandle (void *handle)
  67. {
  68. d_this->d_hwnd = (HWND) handle;
  69. }
  70. void
  71. mxWidget::setType (int type)
  72. {
  73. d_this->d_type = type;
  74. }
  75. void
  76. mxWidget::setParent (mxWindow *parentWindow)
  77. {
  78. d_this->d_parent_p = parentWindow;
  79. }
  80. void
  81. mxWidget::setBounds (int x, int y, int w, int h)
  82. {
  83. char str[128];
  84. GetClassName (d_this->d_hwnd, str, 128);
  85. if (!strcmp (str, "COMBOBOX"))
  86. MoveWindow (d_this->d_hwnd, x, y, w, h + 100, TRUE);
  87. else
  88. MoveWindow (d_this->d_hwnd, x, y, w, h, TRUE);
  89. if (!strcmp (str, WC_TABCONTROL))
  90. mxTab_resizeChild (d_this->d_hwnd);
  91. }
  92. void
  93. mxWidget::setLabel (const char *format, ... )
  94. {
  95. if (format == NULL)
  96. {
  97. if (d_this->d_hwnd)
  98. {
  99. SetWindowText (d_this->d_hwnd, NULL);
  100. }
  101. return;
  102. }
  103. va_list argptr;
  104. static char string[1024];
  105. va_start (argptr, format);
  106. vsprintf (string, format,argptr);
  107. va_end (argptr);
  108. if (d_this->d_hwnd)
  109. {
  110. SetWindowText (d_this->d_hwnd, string);
  111. }
  112. }
  113. void
  114. mxWidget::setVisible (bool b)
  115. {
  116. if (b)
  117. SetWindowPos (d_this->d_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
  118. else
  119. ShowWindow (d_this->d_hwnd, SW_HIDE);
  120. }
  121. void
  122. mxWidget::setEnabled (bool b)
  123. {
  124. EnableWindow (d_this->d_hwnd, b);
  125. }
  126. void
  127. mxWidget::setId (int id)
  128. {
  129. SetWindowLong (d_this->d_hwnd, GWL_ID, (LONG) id);
  130. }
  131. void
  132. mxWidget::setUserData (void *userData)
  133. {
  134. d_this->d_userData = userData;
  135. }
  136. void*
  137. mxWidget:: getHandle () const
  138. {
  139. return (void *) d_this->d_hwnd;
  140. }
  141. int
  142. mxWidget::getType () const
  143. {
  144. return d_this->d_type;
  145. }
  146. mxWindow*
  147. mxWidget::getParent () const
  148. {
  149. return d_this->d_parent_p;
  150. }
  151. int
  152. mxWidget::x () const
  153. {
  154. RECT rc;
  155. GetWindowRect (d_this->d_hwnd, &rc);
  156. return (int) rc.left;
  157. }
  158. int
  159. mxWidget::y () const
  160. {
  161. RECT rc;
  162. GetWindowRect (d_this->d_hwnd, &rc);
  163. return (int) rc.top;
  164. }
  165. int
  166. mxWidget::w () const
  167. {
  168. RECT rc;
  169. GetWindowRect (d_this->d_hwnd, &rc);
  170. return (int) (rc.right - rc.left);
  171. }
  172. int
  173. mxWidget::h () const
  174. {
  175. RECT rc;
  176. GetWindowRect (d_this->d_hwnd, &rc);
  177. return (int) (rc.bottom - rc.top);
  178. }
  179. int
  180. mxWidget::w2 () const
  181. {
  182. RECT rc;
  183. GetClientRect (d_this->d_hwnd, &rc);
  184. return (int) (rc.right - rc.left);
  185. }
  186. int
  187. mxWidget::h2 () const
  188. {
  189. RECT rc;
  190. GetClientRect (d_this->d_hwnd, &rc);
  191. return (int) (rc.bottom - rc.top);
  192. }
  193. const char*
  194. mxWidget::getLabel () const
  195. {
  196. static char label[256];
  197. GetWindowText (d_this->d_hwnd, label, 256);
  198. return label;
  199. }
  200. bool
  201. mxWidget::isVisible () const
  202. {
  203. return ( IsWindowVisible (d_this->d_hwnd) ? true : false );
  204. }
  205. bool
  206. mxWidget::isEnabled () const
  207. {
  208. return ( IsWindowEnabled (d_this->d_hwnd) ? true : false );
  209. }
  210. int
  211. mxWidget::getId () const
  212. {
  213. return (int) GetWindowLong (d_this->d_hwnd, GWL_ID);
  214. }
  215. void*
  216. mxWidget::getUserData () const
  217. {
  218. return d_this->d_userData;
  219. }