home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xcontrol.cpp < prev    next >
C/C++ Source or Header  |  1997-04-04  |  3KB  |  135 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.  
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21.  
  22.  
  23. MRESULT HandleDefault(XWindow * w, ULONG msg, MPARAM mp1, MPARAM mp2, BOOL & handled);
  24.  
  25.  
  26. MRESULT EXPENTRY ControlProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  27. {
  28.     XControl *w = (XControl *) WinQueryWindowULong(hwnd, QWL_USER);
  29.  
  30.     if (msg == WM_QUERYFRAMECTLCOUNT || msg == WM_FORMATFRAME)
  31.         return ((XFrame *) w)->HandleMessage(msg, mp1, mp2);
  32.  
  33.     if (w)
  34.     {
  35.         BOOL handled = FALSE;
  36.         MRESULT mr = HandleDefault(w, msg, mp1, mp2, handled);
  37.  
  38.         if (handled)
  39.             return mr;
  40.  
  41.         return w->oldfunc(hwnd, msg, mp1, mp2);
  42.     }
  43.     else
  44.         return WinDefWindowProc(hwnd, msg, mp1, mp2);
  45. }
  46.  
  47.  
  48. /*@ 
  49. @class XControl
  50. @parent XWindow
  51. @type overview
  52. @symbol _
  53. @remarks XControl is the basic class for user input/output windows. You cannot create
  54. a XControl directly.
  55. */
  56.  
  57.  
  58. XControl :: XControl(const HWND hwnd)
  59. {
  60.     winhandle = hwnd;
  61.     if (hwnd)
  62.     {
  63.         WinSetWindowULong(winhandle, QWL_USER, (ULONG) this);
  64.         oldfunc = WinSubclassWindow(winhandle, (PFNWP) ControlProc);
  65.     }
  66. }
  67.  
  68.  
  69. XControl :: XControl(const XRect * rec, const ULONG style, const XWindow * ow, const char *string, const PSZ cl, const USHORT id, const char *font)
  70. {
  71.    PRES pres;
  72.     HWND hwnd = 0;
  73.     char *s = (char *) string;
  74.  
  75.     if (ow)
  76.         hwnd = ow->GetHandle();
  77.     ULONG st = style;
  78.     void *p = NULL;
  79.  
  80.     if ((cl == WC_BUTTON && (style & BS_BITMAP || style & BS_ICON || style & BS_MINIICON)) || font)
  81.     {
  82.         pres.fcparam.id = PP_FOREGROUNDCOLORINDEX;
  83.         pres.fcparam.cb = sizeof(pres.fcparam.ulColor);
  84.         pres.fcparam.ulColor = 16;
  85.         pres.fntparam.id = PP_FONTNAMESIZE;
  86.         pres.fntparam.cb = 20;
  87.         pres.cb = sizeof(pres.fcparam) + sizeof(pres.fntparam);
  88.         p = (void *) &pres;
  89.  
  90.         if (!font)
  91.         {
  92.             strcpy(pres.fntparam.szFontNameSize, "7.Helv");
  93.             char ti[50];
  94.  
  95.             if (style & BS_TEXT)
  96.                 sprintf(ti, "#%i\t%s", id, string);
  97.             else
  98.                 sprintf(ti, "#%i", id);
  99.             s = ti;
  100.         }
  101.         else
  102.             strcpy(pres.fntparam.szFontNameSize, font);
  103.     }
  104.     if (cl == WC_BUTTON && st & BS_USERBUTTON && st & 0x8000)
  105.         st ^= 0x8000;
  106.  
  107.     if (rec == NULL)
  108.         rec = new XRect();
  109.     winhandle = WinCreateWindow(hwnd, cl, (PSZ) s, st, rec->x, rec->y, rec->cx, rec->cy, hwnd, HWND_TOP, id, NULL, p);
  110.  
  111.     if (winhandle == 0)
  112.         OOLThrow("error creating control", -10);
  113.  
  114.     WinSetWindowULong(winhandle, QWL_USER, (ULONG) this);
  115.     oldfunc = WinSubclassWindow(winhandle, (PFNWP) ControlProc);
  116.     if (ow && cl != WC_SCROLLBAR)
  117.         WinPostMsg(hwnd, OOL_ADDCLIENT, (MPARAM) winhandle, 0);
  118. }
  119.  
  120.  
  121.  
  122.  
  123. XObjectWindow :: XObjectWindow(const XFrameWindow * id)
  124. {
  125.     owner = (XFrameWindow *) id;
  126.  
  127.     if (WinRegisterClass(WinQueryAnchorBlock(id->frame), (PSZ) "OOL_OBJECTWND", (PFNWP) WindowProc, 0, 4) == FALSE)
  128.         OOLThrow("error registering objectwindow-class", -10);
  129.  
  130.     winhandle = WinCreateWindow(HWND_OBJECT, (PSZ) "OOL_OBJECTWND", (PSZ) "", 0, 0, 0, 0, 0, HWND_OBJECT, HWND_BOTTOM, 0, this, 0);
  131. }
  132.  
  133.  
  134.  
  135.