home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xcontrol.cpp < prev    next >
C/C++ Source or Header  |  1998-04-13  |  6KB  |  229 lines

  1. #include "XControl.h"
  2. #include "XRect.h"
  3. #include "XPushBtn.h"
  4. #include "XDragHdl.h"
  5. #include "XDragEvn.h"
  6. #include "XMousHdl.h"
  7. #include "XMousEvn.h"
  8. #include "XFrame.h"
  9. #include "XNoteBk.h"
  10. #include "xcolor.h"
  11. #include "xmsgbox.h"
  12. #include "xexcept.h"
  13. #include "XFrmWnd.h"
  14. #include "XObjWnd.h"
  15. #include "xrect.h"
  16. #include "XColor.h"
  17. #include "xsize.h"
  18. #include "xcolcont.h"
  19. #include "xdefhdl.h"
  20.  
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24.  
  25.  
  26. MRESULT HandleDefault(XWindow * w, ULONG msg, MPARAM mp1, MPARAM mp2, BOOL & handled);
  27.  
  28.  
  29. MRESULT EXPENTRY ControlProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  30. {
  31.    XControl *w = (XControl *) WinQueryWindowULong(hwnd, QWL_USER);
  32.    if(msg == WM_CLOSE)
  33.       return 0;
  34.  
  35.    if (msg == WM_QUERYFRAMECTLCOUNT || msg == WM_FORMATFRAME || msg == WM_SYSCOMMAND)
  36.       return ((XFrame *) w)->HandleMessage(msg, mp1, mp2);
  37.  
  38.    if (w)
  39.    {
  40.       if ( msg == WM_FOCUSCHANGE )
  41.       {
  42.          MRESULT res = w->oldfunc(hwnd, msg, mp1, mp2);
  43.          w->FocusChanged( SHORT1FROMMP(mp2));
  44.          return res;
  45.       }
  46.       BOOL handled = FALSE;
  47. /*****************
  48.       if( msg == WM_SIZE )
  49.       {
  50.          MRESULT r = w->oldfunc(hwnd, msg, mp1, mp2);
  51.            XSize s(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  52.          w->DoSize( &s);
  53.          return r;
  54.       }
  55. ********************/
  56.       MRESULT mr = HandleDefault(w, msg, mp1, mp2, handled);
  57.  
  58.       if (handled)
  59.          return mr;
  60.  
  61.       return w->oldfunc(hwnd, msg, mp1, mp2);
  62.    }
  63.    else
  64.       return WinDefWindowProc(hwnd, msg, mp1, mp2);
  65. }
  66.  
  67.  
  68. /*@
  69. @class XControl
  70. @parent XWindow
  71. @type overview
  72. @symbol _
  73. @remarks XControl is the basic class for user input/output windows. You cannot create
  74. a XControl directly.
  75. */
  76.  
  77.  
  78. XControl :: XControl(const HWND hwnd)
  79. {
  80.    oldfunc = NULL;
  81.    winhandle = hwnd;
  82.    if (hwnd)
  83.    {
  84.       WinSetWindowULong(winhandle, QWL_USER, (ULONG) this);
  85.       oldfunc = WinSubclassWindow(winhandle, (PFNWP) ControlProc);
  86.    }
  87. }
  88.  
  89.  
  90. XControl :: XControl(const XRect * rec, const ULONG style, const XWindow * ow, const char *string, const PSZ cl, const USHORT id, const char *font)
  91. {
  92.    PRES pres;
  93.    HWND hwnd = 0;
  94.    char *s = (char *) string;
  95.  
  96.    if (ow)
  97.       hwnd = ow->GetHandle();
  98.    ULONG st = style;
  99.    void *p = NULL;
  100.  
  101.    if ((cl == WC_BUTTON && (style & BS_BITMAP || style & BS_ICON || style & BS_MINIICON)) || font)
  102.    {
  103.       pres.fcparam.id = PP_FOREGROUNDCOLORINDEX;
  104.       pres.fcparam.cb = sizeof(pres.fcparam.ulColor);
  105.       pres.fcparam.ulColor = 16;
  106.       pres.fntparam.id = PP_FONTNAMESIZE;
  107.       pres.fntparam.cb = 20;
  108.       pres.cb = sizeof(pres.fcparam) + sizeof(pres.fntparam);
  109.       p = (void *) &pres;
  110.  
  111.       if (!font)
  112.       {
  113.          strcpy(pres.fntparam.szFontNameSize, "7.Helv");
  114.          char ti[50];
  115.  
  116.          if (style & BS_TEXT)
  117.             sprintf(ti, "#%i\t%s", id, string);
  118.          else
  119.             sprintf(ti, "#%i", id);
  120.          s = ti;
  121.       }
  122.       else
  123.          strcpy(pres.fntparam.szFontNameSize, font);
  124.    }
  125.    if (cl == WC_BUTTON && st & BS_USERBUTTON && st & 0x8000)
  126.       st ^= 0x8000;
  127.  
  128.    if (rec == NULL)
  129.       rec = new XRect();
  130.    winhandle = WinCreateWindow(hwnd, cl, (PSZ) s, st, rec->x, rec->y, rec->cx, rec->cy, hwnd, HWND_TOP, id, NULL, p);
  131.  
  132.    if (winhandle == 0)
  133.       OOLThrow("error creating control", -10);
  134.  
  135.    WinSetWindowULong(winhandle, QWL_USER, (ULONG) this);
  136.    oldfunc = WinSubclassWindow(winhandle, (PFNWP) ControlProc);
  137.    if (ow && cl != WC_SCROLLBAR)
  138.       WinPostMsg(hwnd, OOL_ADDCLIENT, (MPARAM) winhandle, 0);
  139. }
  140.  
  141.  
  142. XObjectWindow :: XObjectWindow(const XFrameWindow * win)
  143. {
  144.    owner = (XFrameWindow *) win;
  145.  
  146.    if (WinRegisterClass( WinQueryAnchorBlock(win->frame), (PSZ) "OOL_OBJECTWND", (PFNWP) WindowProc, 0, 4) == FALSE)
  147.       OOLThrow("error registering objectwindow-class", -10);
  148.  
  149.    winhandle = WinCreateWindow(HWND_OBJECT, (PSZ) "OOL_OBJECTWND", (PSZ) "", 0, 0, 0, 0, 0, HWND_OBJECT, HWND_BOTTOM, 0, this, 0);
  150. }
  151.  
  152.  
  153. /*@
  154. @class XColorControl
  155. @parent XControl
  156. @type overview
  157. @symbol _
  158. @remarks XColorControl is a color selection control. Only use one control of this type
  159. in a window. The height of the control should be aprox. 60% of its width.
  160. */
  161.  
  162. class ColorDefaultHandler: public XDefaultHandler
  163. {
  164.    public:
  165.       ColorDefaultHandler(XWindow * w): XDefaultHandler(w) {;}
  166.       BOOL HandleEvent( ULONG msg, void * mp1, void *, LONG * retVal);
  167. };
  168.  
  169.  
  170. /*@ XColorControl :: GetColor( XColor* color)
  171. @group set/get the color
  172. @remarks Get the color
  173. @parameters XColor* buffer for the data
  174. */
  175.  
  176.  
  177.  
  178. /*@ XColorControl :: ColorSelected( const XColor& newColor)
  179. @group set/get the color
  180. @remarks Override this method if you need information when the user selected a new color
  181. @parameters XColor& the new color
  182. */
  183.  
  184.  
  185. /*@ XColorControl :: SetColor( XColor& color)
  186. @group set/get the color
  187. @remarks Set the color
  188. @parameters XColor& the pre-selected color
  189. */
  190. void XColorControl :: SetColor( const XColor& color) const
  191. {
  192.    WinSendMsg( winhandle, 0x0602, (MPARAM) color.GetColor(), 0);
  193. }
  194.  
  195.  
  196. MRESULT EXPENTRY ColorControlProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  197. {
  198.    XControl *w = (XControl *) WinQueryWindowULong(hwnd, QWL_USER+4);
  199.    if(msg == WM_CLOSE)
  200.       return 0;
  201.    if (w)
  202.    {
  203.       return w->oldfunc(hwnd, msg, mp1, mp2);
  204.    }
  205.    else
  206.       return WinDefWindowProc(hwnd, msg, mp1, mp2);
  207. }
  208.  
  209.  
  210. /*@ XColorControl :: XColorControl( XWindow * owner, XRect& rect)
  211. @group constructor
  212. @remarks Create the control
  213. @parameters
  214. <t '°' c=2>
  215. °XWindow*   °owner window
  216. °XRect&     °position/size
  217. </t>
  218. */
  219. XColorControl :: XColorControl( const XWindow * owner, const XRect& rect):lib("WPCONFIG.DLL"), XControl(0)
  220. {
  221.    winhandle = WinCreateWindow( owner->GetHandle(), "ColorSelectClass", "", WIN_VISIBLE, rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight(), owner->GetHandle(), HWND_TOP, 0, NULL, NULL);
  222.    if(winhandle == 0)
  223.    {
  224.       OOLThrow( "error creating XColorControl", -1);
  225.    }
  226.    WinSetWindowULong(winhandle, QWL_USER+4, (ULONG) this);
  227.    oldfunc = WinSubclassWindow(winhandle, (PFNWP) ColorControlProc);
  228. }
  229.