GUI.H 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. #ifndef __GUI_H
  2. #define __GUI_H
  3. #include <stdlib.h>
  4. #include "typedefs.h"
  5. #include "resource.h"
  6. // modal result codes
  7. enum MODAL_RESULT {
  8. mrNone = 0,
  9. mrOk,
  10. mrCancel,
  11. mrAbort,
  12. mrRetry,
  13. mrIgnore,
  14. mrYes,
  15. mrNo,
  16. mrUser,
  17. };
  18. enum GEVENT_TYPE {
  19. evNone = 0x00,
  20. evMouseDown = 0x01,
  21. evMouseUp = 0x02,
  22. evMouseRepeat = 0x04,
  23. evMouseDrag = 0x08,
  24. evMouse = 0xFF,
  25. evKeyDown = 0x100,
  26. evKeyUp = 0x200,
  27. evKey = 0xF00,
  28. evCommand = 0x1000,
  29. evBroadcast = 0x2000,
  30. evMessage = 0xF000,
  31. };
  32. struct MOUSE_GEVENT
  33. {
  34. int time;
  35. int button;
  36. int x, y;
  37. int dx, dy;
  38. BOOL doubleClick;
  39. };
  40. struct KEY_GEVENT
  41. {
  42. BYTE ascii;
  43. BYTE make;
  44. union
  45. {
  46. int shiftFlags;
  47. struct
  48. {
  49. unsigned shift : 1;
  50. unsigned control : 1;
  51. unsigned alt : 1;
  52. unsigned lshift : 1;
  53. unsigned rshift : 1;
  54. unsigned lcontrol : 1;
  55. unsigned rcontrol : 1;
  56. unsigned lalt : 1;
  57. unsigned ralt : 1;
  58. };
  59. };
  60. };
  61. struct MESSAGE
  62. {
  63. int command;
  64. };
  65. struct GEVENT
  66. {
  67. GEVENT_TYPE type;
  68. int time;
  69. union
  70. {
  71. MOUSE_GEVENT mouse;
  72. KEY_GEVENT key;
  73. MESSAGE message;
  74. };
  75. void Clear( void ) { type = evNone; }
  76. };
  77. extern Resource gGuiRes;
  78. void SetBlinkOn( void );
  79. void SetBlinkOff( void );
  80. BOOL IsBlinkOn( void );
  81. void UpdateBlinkClock( int ticks );
  82. void CenterString(int x, int y, char *s, int foreColor);
  83. void DrawBevel( int x0, int y0, int x1, int y1, int color1, int color2 );
  84. void DrawRect( int x0, int y0, int x1, int y1, int color );
  85. int GetStringBox( char *title, char *s );
  86. int GetNumberBox( char *title, int n, int nDefault );
  87. class Widget
  88. {
  89. public:
  90. int left, top, width, height;
  91. BOOL Contains(int x, int y)
  92. { return x >= left && y >= top && x < left + width && y < top + height; }
  93. Widget *prev, *next, *owner;
  94. BOOL canFocus;
  95. BOOL canDefault;
  96. BOOL isContainer;
  97. Widget( int left, int top, int width, int height ) :
  98. left(left), top(top), width(width), height(height), canFocus(FALSE), canDefault(FALSE),
  99. isContainer(FALSE) {};
  100. virtual ~Widget() {};
  101. virtual void Paint( int x, int y, BOOL hasFocus ) = 0;
  102. virtual void HandleEvent( GEVENT *event ) = 0;
  103. virtual void EndModal( MODAL_RESULT result ) { owner->EndModal(result); }
  104. };
  105. typedef void (*CLICK_PROC)( Widget * );
  106. class HeadWidget : public Widget
  107. {
  108. public:
  109. HeadWidget() : Widget(0, 0, 0, 0) {};
  110. virtual void Paint( int, int, BOOL ) {};
  111. virtual void HandleEvent( GEVENT * ) {}
  112. };
  113. class Container : public Widget
  114. {
  115. public:
  116. BOOL isModal;
  117. MODAL_RESULT endState;
  118. Widget *focus;
  119. Widget *drag; // receives drag and up events
  120. HeadWidget head;
  121. void Insert( Widget *widget );
  122. void Remove( Widget *widget );
  123. Container( int left, int top, int width, int height);
  124. virtual ~Container();
  125. virtual BOOL SetFocus( int dir );
  126. virtual void Paint( int x, int y, BOOL hasFocus );
  127. virtual void HandleEvent( GEVENT *event );
  128. virtual void EndModal( MODAL_RESULT result );
  129. };
  130. class Panel : public Container
  131. {
  132. public:
  133. int size1, size2, size3;
  134. Panel( int left, int top, int width, int height, int size1, int size2, int size3) :
  135. Container(left, top, width, height), size1(size1), size2(size2), size3(size3)
  136. { canFocus = FALSE; };
  137. virtual void Paint( int x, int y, BOOL hasFocus );
  138. };
  139. class TitleBar : public Widget
  140. {
  141. public:
  142. char string[256];
  143. int len;
  144. TitleBar( int left, int top, int width, int height, char *s );
  145. virtual void Paint( int x, int y, BOOL hasFocus );
  146. virtual void HandleEvent( GEVENT * );
  147. };
  148. class Window : public Panel
  149. {
  150. Container *client;
  151. TitleBar *titleBar;
  152. public:
  153. void Insert( Widget *widget ) { client->Insert(widget); }
  154. Window( int left, int top, int width, int height, char *title);
  155. };
  156. class Button : public Widget
  157. {
  158. protected:
  159. MODAL_RESULT result;
  160. CLICK_PROC clickProc;
  161. BOOL pressed;
  162. public:
  163. Button( int left, int top, int width, int height, MODAL_RESULT result ) :
  164. Widget(left, top, width, height), result(result), pressed(FALSE), clickProc(NULL)
  165. {}
  166. Button( int left, int top, int width, int height, CLICK_PROC clickProc ) :
  167. Widget(left, top, width, height), result(mrNone), pressed(FALSE), clickProc(clickProc)
  168. {}
  169. virtual void Paint( int x, int y, BOOL hasFocus );
  170. virtual void HandleEvent( GEVENT *event );
  171. };
  172. class TextButton : public Button
  173. {
  174. char *text;
  175. public:
  176. TextButton( int left, int top, int width, int height, char *text, MODAL_RESULT result ) :
  177. Button(left, top, width, height, result), text(text)
  178. { canFocus = TRUE; }
  179. virtual void Paint( int x, int y, BOOL hasFocus );
  180. virtual void HandleEvent( GEVENT *event );
  181. };
  182. class BitButton : public Button
  183. {
  184. RESHANDLE hBitmap;
  185. public:
  186. BitButton( int left, int top, int width, int height, RESHANDLE hBitmap, CLICK_PROC clickProc) :
  187. Button( left, top, width, height, clickProc), hBitmap(hBitmap) {};
  188. virtual void Paint( int x, int y, BOOL hasFocus );
  189. };
  190. class EditText : public Widget
  191. {
  192. public:
  193. char string[256];
  194. int len;
  195. int pos;
  196. int maxlen;
  197. EditText( int left, int top, int width, int height, char *s );
  198. virtual void Paint( int x, int y, BOOL hasFocus );
  199. virtual void HandleEvent( GEVENT *event );
  200. };
  201. class EditNumber : public EditText
  202. {
  203. public:
  204. int value;
  205. EditNumber( int left, int top, int width, int height, int n );
  206. virtual void HandleEvent( GEVENT *event );
  207. };
  208. #define kSBWidth 11
  209. #define kSBHeight 10
  210. class ThumbButton : public Button
  211. {
  212. public:
  213. ThumbButton( int left, int top, int height ) :
  214. Button( left, top, kSBWidth, height, mrNone) {};
  215. virtual void HandleEvent( GEVENT *event );
  216. };
  217. class ScrollButton : public BitButton
  218. {
  219. public:
  220. ScrollButton( int left, int top, RESHANDLE hBitmap, CLICK_PROC clickProc ) :
  221. BitButton( left, top, kSBWidth, kSBHeight, hBitmap, clickProc) {};
  222. virtual void HandleEvent( GEVENT *event );
  223. };
  224. class ScrollBar : public Container
  225. {
  226. private:
  227. int min;
  228. int max;
  229. int size;
  230. ScrollButton *pbUp, *pbDown;
  231. Container *pcThumbBar;
  232. ThumbButton *pbThumb;
  233. public:
  234. int value;
  235. ScrollBar( int left, int top, int height, int min, int max, int value);
  236. virtual void Paint( int x, int y, BOOL hasFocus );
  237. void ScrollRelative( int offset );
  238. void SetValue( int value, int size = 0 );
  239. void SetRange( int min, int max );
  240. };
  241. MODAL_RESULT ShowModal( Container *dialog );
  242. #endif