home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / OWLINC.ZIP / WINDOBJ.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  7.8 KB  |  236 lines

  1. // ObjectWindows - (C) Copyright 1991 by Borland International
  2.  
  3. #ifndef __WINDOBJ_H
  4. #define __WINDOBJ_H
  5.  
  6. #ifndef __WINDOWS_H
  7. #undef NULL
  8. #include <windows.h>
  9. #endif
  10.  
  11. #ifndef __OBJECT_H
  12. #include <object.h>
  13. #endif
  14.  
  15. #ifndef __APPLICAT_H
  16. #include <applicat.h>
  17. #endif
  18.  
  19. #ifndef __OWLDEFS_H
  20. #include <owldefs.h>
  21. #endif
  22.  
  23. #ifndef __OBJSTRM_H
  24. #include <objstrm.h>
  25. #endif
  26.  
  27. struct TMessage {
  28.   HWND Receiver;
  29.   WORD Message;
  30.   union {
  31.     WORD WParam;
  32.         struct tagWP {
  33.           BYTE Lo;
  34.           BYTE Hi;
  35.         } WP;
  36.   };
  37.   union {
  38.         DWORD LParam;
  39.         struct tagLP {
  40.           WORD Lo;
  41.           WORD Hi;
  42.         } LP;
  43.   };
  44.   long Result;
  45. };
  46.  
  47. _CLASSDEF(TMDIClient)
  48. _CLASSDEF(TApplication)
  49. _CLASSDEF(TModule)
  50. _CLASSDEF(TWindowsObject)
  51.  
  52. typedef TMessage _FAR &RTMessage;
  53.  
  54. typedef void ( _FAR *TActionFunc )(Pvoid Child, Pvoid ParamList);
  55. typedef BOOL ( _FAR *TCondFunc )(Pvoid Child, Pvoid ParamList);
  56.  
  57. /* TWindowsObject */
  58. class _EXPORT TWindowsObject : public Object, public TStreamable 
  59. {
  60. public:
  61.     int Status;
  62.     HWND HWindow;    // handle to associated MS-Windows window 
  63.     LPSTR Title;
  64.     PTWindowsObject Parent;
  65.  
  66.     TWindowsObject(PTWindowsObject AParent, PTModule AModule = NULL);
  67.     virtual ~TWindowsObject();
  68.     void SetFlags(WORD Mask, BOOL OnOff);
  69.  
  70.     /* Determines whether the flag whose mask is passed has been set,
  71.        returning a BOOL indicator --  True = On, False = Off. */
  72.     BOOL IsFlagSet(WORD Mask)
  73.         { return( (Flags & Mask) == Mask); }
  74.  
  75.     PTWindowsObject FirstThat(TCondFunc Test, Pvoid PParamList);
  76.     void ForEach(TActionFunc Action, Pvoid PParamList);
  77.     PTWindowsObject FirstThat(
  78.         BOOL (TWindowsObject::* _FAR Test)(Pvoid, Pvoid), Pvoid PParamList);
  79.     void ForEach(
  80.         void (TWindowsObject::* _FAR Action)(Pvoid, Pvoid), Pvoid PParamList);
  81.  
  82.     PTWindowsObject Next();
  83.     PTWindowsObject GetFirstChild()
  84.         { return ChildList->SiblingList; }    
  85.     PTWindowsObject GetLastChild()
  86.         { return ChildList; }    
  87.     PTWindowsObject Previous();
  88.     void EnableKBHandler();
  89.     void EnableAutoCreate();
  90.     void DisableAutoCreate();
  91.     void EnableTransfer();
  92.     void DisableTransfer();
  93.  
  94.     PTModule GetModule()
  95.         { return Module; }
  96.     PTApplication GetApplication()
  97.         { return Application; }
  98.     FARPROC GetInstance()
  99.         { return Instance; }
  100.     virtual BOOL Register();
  101.  
  102. /* Pure virtual function, placeholder for derived classes to redefine to 
  103.    create an MS_Windows element to be associated with an OWL window 
  104.    object */
  105.     virtual BOOL Create() = 0;
  106.  
  107.     virtual void Destroy();
  108.  
  109.     virtual int GetId();
  110.     PTWindowsObject ChildWithId(int Id);
  111.     virtual PTMDIClient GetClient();
  112.     virtual void SetParent(PTWindowsObject NewParent);
  113.     void Show(int ShowCmd);
  114.     void SetCaption(LPSTR ATitle);
  115.     virtual BOOL CanClose();
  116.     void SetTransferBuffer(Pvoid ATransferBuffer)
  117.         { TransferBuffer = ATransferBuffer; }
  118.     virtual WORD Transfer(Pvoid DataPtr, WORD TransferFlag);
  119.     virtual void TransferData(WORD Direction);
  120.     virtual void DefWndProc(RTMessage Msg);
  121.     virtual void BeforeDispatchHandler() {}
  122.     virtual void AfterDispatchHandler() {}
  123.     virtual void DispatchAMessage(WORD AMsg, RTMessage AMessage,
  124.         void (TWindowsObject::* _FAR)(RTMessage ));
  125.     void CloseWindow();
  126.     void GetChildren(Ripstream is);
  127.     void PutChildren(Ropstream os);
  128.     BOOL CreateChildren();
  129.     virtual void ShutDownWindow();
  130.     virtual void DrawItem(DRAWITEMSTRUCT _FAR & DrawInfo);
  131.     virtual void ActivationResponse(WORD Activated, BOOL IsIconified);
  132.  
  133.     // define pure virtual functions derived from Object class
  134.     virtual classType      isA() const = 0;
  135.     virtual Pchar nameOf() const = 0;
  136.     virtual hashValueType  hashValue() const
  137.         { return hashValueType(HWindow); }
  138.     virtual int              isEqual(RCObject testwin)  const
  139.         { return this ==  &(RTWindowsObject)testwin; }
  140.     virtual void             printOn(Rostream outputStream) const
  141.         { outputStream << nameOf() << "{ HWindow = " << HWindow << " }\n"; }
  142.  
  143.     static PTStreamable build();
  144.  
  145. protected:
  146.     FARPROC DefaultProc;
  147.     Pvoid TransferBuffer;
  148.     virtual void GetWindowClass(WNDCLASS _FAR & AWndClass);
  149.     virtual LPSTR GetClassName() = 0;
  150.     void RemoveClient()
  151.         { RemoveChild((PTWindowsObject)GetClient()); }
  152.     void GetChildPtr(Ripstream is, RPTWindowsObject P);
  153.     void PutChildPtr(Ropstream os, PTWindowsObject P);
  154.     void GetSiblingPtr(Ripstream is, RPTWindowsObject P);
  155.     void PutSiblingPtr(Ropstream os, PTWindowsObject P);
  156.     virtual void DefCommandProc(RTMessage Msg);
  157.     virtual void DefChildProc(RTMessage Msg);
  158.     virtual void DefNotificationProc(RTMessage Msg);
  159.     virtual void SetupWindow();
  160.     virtual void WMVScroll(RTMessage Msg) = 
  161.                  [WM_FIRST + WM_VSCROLL];
  162.     virtual void WMHScroll(RTMessage Msg) = 
  163.                  [WM_FIRST + WM_HSCROLL];
  164.     void DispatchScroll(RTMessage Msg);
  165.     virtual void WMCommand(RTMessage Msg) = 
  166.                  [WM_FIRST + WM_COMMAND];
  167.     virtual void WMDrawItem(RTMessage Msg) = 
  168.                  [WM_FIRST + WM_DRAWITEM];
  169.     virtual void WMClose(RTMessage Msg) = 
  170.                  [WM_FIRST + WM_CLOSE];
  171.     virtual void WMDestroy(RTMessage Msg) = 
  172.                  [WM_FIRST + WM_DESTROY];
  173.     virtual void WMNCDestroy(RTMessage Msg) = 
  174.                  [WM_FIRST + WM_NCDESTROY];
  175.     virtual void WMActivate(RTMessage Msg) = 
  176.                  [WM_FIRST + WM_ACTIVATE];
  177.     virtual void WMQueryEndSession(RTMessage Msg) = 
  178.                  [WM_FIRST + WM_QUERYENDSESSION];
  179.     virtual void CMExit(RTMessage Msg) = 
  180.                  [CM_FIRST + CM_EXIT];
  181.  
  182.     TWindowsObject(StreamableInit) {};
  183.     virtual void write (Ropstream os);
  184.     virtual Pvoid read (Ripstream is);
  185.  
  186. private:
  187.     FARPROC Instance;
  188.     PTApplication Application;
  189.     PTModule Module;
  190.     WORD Flags;
  191.     WORD CreateOrder;
  192.     BOOL OrderIsI(Pvoid P, Pvoid I);
  193.     BOOL CreateZeroChild(Pvoid P, Pvoid I);
  194.     void AssignCreateOrder();
  195.     PTWindowsObject ChildList, SiblingList;
  196.     void AddChild(PTWindowsObject AChild);
  197.     void RemoveChild(PTWindowsObject AChild);
  198.     int IndexOf(PTWindowsObject P);
  199.     PTWindowsObject At(int APosition);
  200.  
  201.     virtual const Pchar streamableName() const
  202.         { return "TWindowsObject"; }
  203.  
  204. };    // end of WindowsObject class
  205.  
  206. /* Returns the Id of the TWindowsObject, used to identify the window
  207.    in a specified parent's ChildList.  Redefined by TControl
  208.    descendants to return their identifier from their attributes 
  209.    structure.  0 is returned here as the default identifier. This 
  210.    precludes any window with a 0 Id from being easily found. If you
  211.    need to address individual windows, redefine GetId to return
  212.    something other than 0.*/
  213. inline int TWindowsObject::GetId()
  214.         { return 0; }
  215.  
  216. /* Returns a pointer to the TWindowsObject's next sibling (the next 
  217.    window in its parent's child window list.  If this was the last child
  218.    added to the list, returns a pointer to the first child added.*/
  219. inline PTWindowsObject TWindowsObject::Next()
  220.         { return SiblingList; }
  221.  
  222. typedef void ( TWindowsObject::* _FAR TActionMemFunc )(Pvoid Child, Pvoid ParamList);
  223. typedef BOOL ( TWindowsObject::* _FAR TCondMemFunc )(Pvoid Child, Pvoid ParamList);
  224.  
  225. inline Ripstream operator >> ( Ripstream is, RTWindowsObject cl )
  226.     { return is >> (RTStreamable)cl; }
  227. inline Ripstream operator >> ( Ripstream is, RPTWindowsObject cl )
  228.     { return is >> (RPvoid)cl; }
  229.  
  230. inline Ropstream operator << ( Ropstream os, RTWindowsObject cl )
  231.     { return os << (RTStreamable )cl; }
  232. inline Ropstream operator << ( Ropstream os, PTWindowsObject cl )
  233.     { return os << (PTStreamable )cl; }
  234.  
  235. #endif  // ifndef _WINDOBJ_H
  236.