home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xgraphbt.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  6KB  |  232 lines

  1. #include "xgraphbt.h"
  2.  
  3. #include "string.h"
  4. #include "stdlib.h"
  5. #include "XColor.h"
  6.  
  7. #ifdef OOL_FOR_OS2_X86
  8. #define INCL_OS2MM
  9. #define INCL_MMIOOS2
  10. #define INCL_MMIO_CODEC
  11. #define INCL_MCIOS2
  12. #define INCL_MACHDR
  13.  
  14. #include "os2me.h"
  15. #endif
  16.  
  17. #ifndef WC_GRAPHICBUTTON
  18.  
  19. #define GB_ERROR           -1
  20. #define GB_UP               1
  21. #define GB_DOWN             2
  22. #define GB_DISABLE          3
  23. #define GB_HILITE           4
  24. #define GB_OUTOFHILITE      5
  25. #define GB_TOGGLE          10
  26. #define GB_CURRENTSTATE    11
  27. #define GB_ANIMATIONBEGIN  12
  28. #define GB_ANIMATIONEND    13
  29. #define GB_MAXINDEX        14
  30. #define GB_TEXTBELOW        1
  31. #define GB_TEXTABOVE        2
  32. #define GB_INDEX_FORWARD   -1
  33. #define GB_INDEX_BACKWARD  -2
  34. #define GB_INDEX_FIRST     -3
  35. #define GB_INDEX_LAST      -4
  36. #define GB_RESOURCE         1
  37. #define GB_STRUCTURE        0
  38.  
  39. #define GBM_SETGRAPHICDATA        0x052A
  40. #define GBM_ANIMATE               0x052B
  41. #define GBM_SETANIMATIONRATE      0x052C
  42. #define GBM_QUERYANIMATIONACTIVE  0x052D
  43. #define GBM_QUERYANIMATIONRATE    0x052E
  44. #define GBM_SETBITMAPINDEX        0x052F
  45. #define GBM_QUERYBITMAPINDEX      0x0530
  46. #define GBM_SETSTATE              0x0531
  47. #define GBM_QUERYSTATE            0x0532
  48. #define GBM_SETTEXTPOSITION       0x0533
  49. #define GBM_QUERYTEXTPOSITION     0x0534
  50.  
  51. #define GBN_BUTTONUP      0x0524
  52. #define GBN_BUTTONDOWN    0x0525
  53. #define GBN_BUTTONHILITE  0x0526
  54.  
  55. #define GBS_TWOSTATE         0x1000
  56. #define GBS_AUTOTWOSTATE     0X2000
  57. #define GBS_ANIMATION        0x4000
  58. #define GBS_AUTOANIMATION    0x8000
  59. #define GBS_DISABLEBITMAP    0x0010
  60. #define GBS_HILITEBITMAP     0x0020
  61. #define GBS_3D_TEXTRECESSED  0x0040
  62. #define GBS_3D_TEXTRAISED    0x0080
  63.  
  64. #define WC_GRAPHICBUTTON ((PSZ)0xffff0040L)
  65.  
  66.  /* use 8-bit alignment */
  67. #pragma pack(1)
  68.  
  69. typedef struct _GBTNCDATA
  70. {
  71.     USHORT usReserved;
  72.     PSZ pszText;
  73.     HMODULE hmod;
  74.     USHORT cBitmaps;
  75.     USHORT aidBitmap[1];
  76. }   GBTNCDATA;
  77.  
  78. typedef GBTNCDATA *PGBTNCDATA;
  79.  
  80.  /* use 32-bit alignment again */
  81. #pragma pack(4)
  82.  
  83. BOOL WinRegisterGraphicButton(VOID);
  84.  
  85. #endif
  86.  
  87.  
  88. /*@ XGraphicButton::Select(BOOL select)
  89. @group misc
  90. @remarks Select/deselect the button
  91. @parameters BOOL select    TRUE=select, FALSE=deselect
  92. */
  93. void XGraphicButton::Select(BOOL select)
  94. {
  95.     SHORT sel = select ? 2 : 1;
  96.  
  97.     WinSendMsg(winhandle, GBM_SETSTATE, MPFROMSHORT(sel), 0);
  98. }
  99.  
  100.  
  101. /*@ XGraphicButton::IsSelected(void)
  102. @group misc
  103. @remarks Query if the button is selected
  104. @returns BOOL result
  105. */
  106. BOOL XGraphicButton::IsSelected(void) const
  107. {
  108.     if (SHORT1FROMMR(WinSendMsg(winhandle, GBM_QUERYSTATE, 0, 0)) == 2)
  109.         return TRUE;
  110.     else
  111.         return FALSE;
  112. }
  113.  
  114.  
  115. /*@ XGraphicButton::Toggle(void)
  116. @group misc
  117. @remarks Toggles the button
  118. */
  119. void XGraphicButton::Toggle(void)
  120. {
  121.     WinSendMsg(winhandle, GBM_SETSTATE, MPFROMSHORT(10), 0);
  122. }
  123.  
  124.  
  125. XGraphicButton :: XGraphicButton(HWND hwnd):XSettingButton(hwnd)
  126. {
  127. }
  128.  
  129.  
  130. /*@ 
  131. @class XGraphicButton
  132. @parent XSettingButton
  133. @type overview
  134. @symbol _
  135. */
  136.  
  137. /*@ XGraphicButton :: XGraphicButton(XWindow * owner, XRect * rec, USHORT id, ULONG style, const char *s, SHORT bitmapIdCount, SHORT * bitmapIdList)
  138. @group constructors/destructors
  139. @remarks Construct a graphic-button. To use this control you must invoke the multimedia-library!
  140. @parameters <t '°' c=2>
  141.                 °XWindow * owner      °owner of the button
  142.             °XRect * rectangle    °rectangle for position/size
  143.             °USHORT id            °id of the window
  144.             °ULONG style          °style of the button:
  145.                                             <t '°' c=1>
  146.                                     °GB_TWOSTATE
  147.                                     °GB_AUTOTWOSTATE
  148.                                     °GB_ANIMATION
  149.                                     °GB_AUTOANIMATION
  150.                                     °GB_DISABLEBITMAP
  151.                                     °GB_HILITEBITMAP
  152.                                     °GB_3D_TEXTRECESSED
  153.                                     °GB_3D_TEXTRAISED
  154.                                             </t>
  155.             °const char * title   °text to display
  156.             °SHORT bitmapCount    °number of bitmap-ids in parameter bitmapList
  157.             °SHORT * bitmapList   °array of bitmap-ids to use for an animation. Bitmaps
  158.                                  with this ids must be in the programs resources (not in DLLs).
  159.                 </t>
  160. */
  161. XGraphicButton :: XGraphicButton(XWindow * owner, XRect * rec, USHORT id, ULONG style, const char *s, SHORT bitmapIdCount, SHORT * bitmapIdList):XSettingButton(owner, rec, id, style, "", (unsigned char *) WC_GRAPHICBUTTON)
  162. {
  163.     PGBTNCDATA pgbtn;
  164.     LONG lSize;
  165.     SHORT i;
  166.  
  167.     lSize = sizeof(GBTNCDATA) + sizeof(USHORT) * (bitmapIdCount - 1);
  168.     pgbtn = (PGBTNCDATA) malloc(lSize);
  169.  
  170.     memset(pgbtn, 0, lSize);
  171.  
  172.     pgbtn->pszText = (PSZ) s;
  173.     pgbtn->cBitmaps = bitmapIdCount;
  174.     for (i = 0; i < bitmapIdCount; i++)
  175.         pgbtn->aidBitmap[i] = bitmapIdList[i];
  176.  
  177.     WinSendMsg(winhandle, GBM_SETGRAPHICDATA, MPFROMP(pgbtn), 0);
  178.  
  179.     XColor color;
  180.  
  181.     owner->GetBackgroundColor(&color);
  182.     SetBackgroundColor(&color);
  183. }
  184.  
  185.  
  186. /*@ XGraphicButton::Animate(BOOL start, BOOL fromBeginning)
  187. @group animation
  188. @remarks Start/stop to display the animation (if GB_ANIMATION is set)
  189. @parameters BOOL start        TRUE=start, FALSE=stop<BR>
  190.             BOOL fromBegining TRUE=display from beginning,
  191.                               FALSE=display from current position
  192. @returns    BOOL success
  193. */
  194. BOOL XGraphicButton::Animate(BOOL start, BOOL fromBeginning)
  195. {
  196.     return (BOOL) WinSendMsg(winhandle, GBM_ANIMATE, MPFROMSHORT(start), MPFROMSHORT(fromBeginning));
  197. }
  198.  
  199.  
  200. /*@ XGraphicButton::IsAnimationActive(void)
  201. @group animation
  202. @remarks Query if the animation is active
  203. @returns BOOL result
  204. */
  205. BOOL XGraphicButton::IsAnimationActive(void)
  206. {
  207.     return (BOOL) WinSendMsg(winhandle, GBM_QUERYANIMATIONACTIVE, 0, 0);
  208. }
  209.  
  210.  
  211. /*@ XGraphicButton::GetAnimationRate(void)
  212. @group animation
  213. @remarks Query the speed of the animation
  214. @returns LONG  speed
  215. */
  216. LONG XGraphicButton::GetAnimationRate(void)
  217. {
  218.     return (LONG) WinSendMsg(winhandle, GBM_QUERYANIMATIONRATE, 0, 0);
  219. }
  220.  
  221.  
  222. /*@ XGraphicButton::SetAnimationRate(LONG rate)
  223. @group animation
  224. @remarks Set the speed of animation
  225. @parameters LONG rate   speed
  226. @returns    BOOL result
  227. */
  228. BOOL XGraphicButton::SetAnimationRate(LONG rate)
  229. {
  230.     return (BOOL) WinSendMsg(winhandle, GBM_SETANIMATIONRATE, (MPARAM) rate, 0);
  231. }
  232.