Advertisement
Dediggefedde

owl Class TWindow

Apr 24th, 2013
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 42.08 KB | None | 0 0
  1.  
  2. //
  3. /// \class TWindow
  4. // ~~~~~ ~~~~~~~
  5. /// TWindow, derived from TEventHandler and TStreamableBase, provides
  6. /// window-specific behavior and encapsulates many functions that control window
  7. /// behavior and specify window creation and registration attributes.
  8. ///
  9. /// TWindow is a generic window that can be resized and moved. You can construct an
  10. /// instance of TWindow, though normally you use TWindow as a base for your
  11. /// specialized window classes. In general, to associate and disassociate a TWindow
  12. /// object with a window element, you need to follow these steps:
  13. /// - 1.    Construct an instance of a TWindow.
  14. /// - 2.    Call Create or Execute, which creates the interface element (HWND) and then
  15. /// calls SetupWindow, which calls the base SetupWindow for normal processing, which
  16. /// in turn involves
  17. /// - Creating the HWindow and any child HWindows.
  18. /// - Calling TransferData to setup the transfer of data between the
  19. /// parent and child windows.
  20. /// - 3.    To destroy the interface element, choose one of the following actions,
  21. /// depending on your application:
  22. /// - Call Destroy to destroy the interface element unconditionally.
  23. /// - Call CloseWindow, which calls CanClose to test if it is OK to
  24. /// destroy the interface element.
  25. /// - 4.    There are two ways to destroy the interface object:
  26. /// - If the object has been new'd, use delete.
  27. /// - If the object has not been new'd, the compiler automatically
  28. /// destructs the object.
  29. ///
  30. /// The ObjectWindows destroy process consists of two parts: (1) call Destroy to
  31. /// destroy the interface element and (2) then delete the C++ object. However, it is
  32. /// perfectly valid to call Destroy on the interface element without deleting the
  33. /// C++ object and then to call Create at a later time to re-create the window.
  34. /// Because it is also valid to construct a C++ window object on the stack or as an
  35. /// aggregated member, the Destroy function cannot assume it should delete the C++
  36. /// object.
  37. ///
  38. /// The user-generated WM_CLOSE event handler, EvClose, also causes a C++ object to
  39. /// be deleted by passing the this pointer to the application. The C++ object is
  40. /// deleted automatically because the EvClose event frequently occurs in response to
  41. /// a user action, and this is the most convenient place for the deletion to take
  42. /// place. Later, when it's safe to do so, the application then deletes the window
  43. /// pointer. Because the stack often contains selectors that refer to the addresses
  44. /// of objects that may become invalid during the delete process, it is not safe to
  45. /// delete the this pointer while events are still being processed. If the addresses
  46. /// become invalid, they could cause trouble when they are reloaded from the stack.
  47. ///
  48. /// TWindow is the base class for all window classes, including TFrameWindow,
  49. /// TControl, TDialog, and TMDIChild. The ObjectWindows hierarchy diagram shows the
  50. /// many classes that are derived from TWindow.
  51. //
  52. class _OWLCLASS TWindow : virtual public TEventHandler,
  53.                           virtual public TStreamableBase {
  54.   public:
  55.     // Class scoped types
  56.     //
  57.     typedef HWND THandle;  ///< TWindow encapsulates an HWND
  58.  
  59.         /// \todo Make protected or private
  60.     void TraceWindowPlacement(); //DLN debug
  61.    
  62.     // Constructors and destructor for TWindow
  63.     //
  64.     TWindow(TWindow* parent, LPCTSTR title = 0, TModule* module = 0);
  65.     TWindow(TWindow* parent, const tstring& title, TModule* module = 0);
  66.     TWindow(HWND handle, TModule* module = 0);
  67.  
  68.     virtual ~TWindow();
  69.  
  70.     /// \name Two iterators that take function pointers
  71.     /// @{
  72.     TWindow*          FirstThat(TCondFunc test, void* paramList = 0) const;
  73.     void              ForEach(TActionFunc action, void* paramList = 0);
  74.     /// @}
  75.  
  76.     /// \name Two iterators that take pointers to member functions
  77.     /// @{
  78.     TWindow*          FirstThat(TCondMemFunc test, void* paramList = 0);
  79.     void              ForEach(TActionMemFunc action, void* paramList = 0);
  80.     /// @}
  81.  
  82.     /// \name Other functions for iteration
  83.     /// @{
  84.     TWindow*          Next();
  85.     void              SetNext(TWindow* next);
  86.     TWindow*          GetFirstChild();
  87.     TWindow*          GetLastChild();
  88.     TWindow*          Previous();
  89.     uint              NumChildren() const;   // Number of child windows
  90.     /// @}
  91.  
  92.     /// \name Query and set the Owl window flags.
  93.     /// Accepts TWindowFlag args, possibly or'd together.
  94.     /// @{
  95.     void              SetFlag(uint mask);
  96.     void              ClearFlag(uint mask);
  97.     bool              IsFlagSet(uint mask);
  98.     /// @}
  99.  
  100.     /// \name Sets/clears auto-create flag
  101.     /// It indicates that the TWindow should be
  102.     /// created if a create is sent while in the parent's child list
  103.     /// @{
  104.     void              EnableAutoCreate();
  105.     void              DisableAutoCreate();
  106.     /// @}
  107.  
  108.     /// \name Retrieves/assigns tooltip of/to window
  109.     /// @{
  110.     virtual TTooltip* GetTooltip() const;
  111.     virtual void       EnableTooltip(bool enable=true);
  112.     void              SetTooltip(TTooltip* tooltip);
  113.     /// @}
  114.  
  115.     /// \name Sets/clears transfer flag  
  116.     /// It indicates that the TWindow can/will transfer data via the transfer mechanism
  117.     /// @{
  118.     void              EnableTransfer();
  119.     void              DisableTransfer();
  120.     /// @}
  121.  
  122.     /// \name Window's default module access functions
  123.     // !CQ SetModule() should be protected!
  124.     /// @{
  125.     TModule*          GetModule() const;
  126.     void              SetModule(TModule* module);
  127.     /// @}
  128.  
  129.     /// Convenience functions - forwards the call to the module associated with this window.
  130.     /// @{
  131.     tstring LoadString(uint id) const {PRECONDITION(Module); return Module->LoadString(id);}
  132.     HBITMAP LoadBitmap(TResId id) const {PRECONDITION(Module); return Module->LoadBitmap(id);}
  133.     HACCEL LoadAccelerators(TResId id) const {PRECONDITION(Module); return Module->LoadAccelerators(id);}
  134.     HMENU LoadMenu(TResId id) const {PRECONDITION(Module); return Module->LoadMenu(id);}
  135.     HCURSOR LoadCursor(TResId id) const {PRECONDITION(Module); return Module->LoadCursor(id);}
  136.     HICON LoadIcon(LPCTSTR name) const {PRECONDITION(Module); return Module->LoadIcon(name);}
  137.     /// @}
  138.  
  139.     TApplication*     GetApplication() const;
  140.     virtual bool      Register();
  141.  
  142.     TScroller*        GetScroller();
  143.     void              SetScroller(TScroller* scroller);
  144.  
  145.     /// \name Create/destroy an native window to be associated with this window
  146.     /// @{
  147.     virtual bool      Create();
  148.     bool              CreateChildren();
  149.     virtual void      Destroy(int retVal = 0);
  150.     /// @}
  151.  
  152.     /// \name Create a modal window, and perform actual modal execute call
  153.     /// @{
  154.     virtual int       Execute();
  155.     virtual int       DoExecute();
  156.     /// @}
  157.  
  158.     // Request this window to close itself
  159.     //
  160.     virtual void      CloseWindow(int retVal = 0);
  161.  
  162.     /// \name Unconditionally shut down a given window.
  163.     /// Destroy() is called to
  164.     /// destroy the Handle, & then the window is deleted. Non-static version
  165.     /// is safe as long as it is inline and not called on itself
  166.     /// @{
  167.     static void       ShutDownWindow(TWindow* win, int retVal = 0);
  168.     void              ShutDownWindow(int retVal = 0);
  169.     /// @}
  170.  
  171.     /// \name Attach or detach a window handle to a TWindow object.  
  172.     /// Used when a child re-creates itself.
  173.     /// @{
  174.     void              AttachHandle(HWND handle);
  175.     void              DetachHandle();
  176.     /// @}
  177.  
  178. #if defined(BI_MULTI_THREAD_RTL)
  179.     //Override TEventHandler::Dispatch() to handle multi-thread
  180.     //synchronization
  181.     //
  182.     virtual TResult  Dispatch(TEventInfo& info, TParam1 wp, TParam2 lp = 0);
  183. #endif
  184.  
  185.     /// \name Message preprocessing
  186.     /// Called from TApplication::ProcessAppMsg() to give the window an
  187.     /// opportunity to perform preprocessing of the Windows message
  188.     /// @{
  189.     virtual bool      PreProcessMsg(MSG& msg);
  190.     virtual bool      IdleAction(long idleCount);
  191.     virtual bool      HoldFocusHWnd(HWND hLose, HWND hGain);
  192.     /// @}
  193.  
  194.     TWindowAttr&      GetWindowAttr();
  195.     const TWindowAttr& GetWindowAttr() const;
  196.  
  197.     LPCTSTR           GetCaption() const;
  198.  
  199.  
  200.     /// \name Child and parenting
  201.     /// @{
  202.     int               GetId() const;
  203.     TWindow*          ChildWithId(int id) const;
  204.     /// @}
  205.  
  206.     /// \name Get this window's parent.
  207.     /// Either the handle of native window, or a
  208.     /// pointer to the OWL object. May return different objects in some cases.
  209.     /// Use H & O varieties to avoid change across version
  210.     /// @{
  211.     HWND               GetParentH() const; // Native handle version
  212.     TWindow*          GetParentO() const; // OWL object version
  213.     TWindow*          GetParent() const;        // New version -- returns object
  214.  
  215.     /// @}
  216.  
  217.     virtual void      SetParent(TWindow* newParent);
  218.  
  219.     /// \name Other attributes
  220.     /// @{
  221.     virtual bool      SetDocTitle(LPCTSTR docname, int index);
  222.     bool              SetDocTitle(const tstring& docname, int index) {return SetDocTitle(docname.c_str(), index);}
  223.     void              SetCaption(LPCTSTR title);
  224.     void              SetCaption(const tstring& title) {SetCaption(title.c_str());}
  225.     void              SetCaption(uint resourceStringId);
  226.     bool              SetCursor(TModule* module, TResId resId);
  227.     void              SetBkgndColor(const TColor& color);
  228.     void              SetAcceleratorTable(TResId resId);
  229.     /// @}
  230.  
  231.     //Can close virtual tests whether all children and this window are ready
  232.     //and able to close
  233.     //
  234.     virtual bool      CanClose();
  235.  
  236.     /// \name Message forwarding
  237.     /// Forward the current event to "handle" using either PostMessage() or
  238.     /// SendMessage(). Owl window version calls directly to window proc on send.
  239.     /// @{
  240.     TResult           ForwardMessage(HWND handle, bool send = true);
  241.     TResult           ForwardMessage(bool send = true);
  242.     /// @}
  243.  
  244.     // Send message to all children
  245.     //
  246.     void              ChildBroadcastMessage(uint msg, TParam1 wParam=0, TParam2 lParam=0);
  247.  
  248.     /// \name Notify a window (parent usually) of a child action.
  249.     /// @{
  250.     void              SendNotification(int id, int notifyCode, HWND hCtl,
  251.                                        uint msg = WM_COMMAND);
  252.     void              SendNotification(HWND receiver, int id,
  253.                                        int notifyCode, HWND hCtl,
  254.                                        uint msg = WM_COMMAND);
  255.     TResult           SendNotification(int id, NMHDR& nmhdr,
  256.                                        uint msg = WM_NOTIFY);
  257.     TResult           SendNotification(HWND receiver, uint id,
  258.                                        NMHDR& nmhdr, uint msg = WM_NOTIFY);
  259.     /// @}
  260.  
  261. #if defined(OWL5_COMPAT)
  262.  
  263.     // Obsolete. Forwards the call to message handler.
  264.     //
  265.     TResult ReceiveMessage(uint msg, TParam1 p1 = 0, TParam2 p2 = 0)
  266.     {return ReceiveMessage(Handle, msg, p1, p2);}
  267.  
  268. #endif
  269.  
  270.     // Call a Window's window proc to handle a message. Similar to SendMessage
  271.     // but goes directly to the OWL window, bypassing the Windows message queue.
  272.     //
  273.     TResult HandleMessage(uint msg, TParam1 p1 = 0, TParam2 p2 = 0)
  274.     {return ReceiveMessage(Handle, msg, p1, p2);}
  275.  
  276.     /// \name Windows message handlers
  277.     /// Virtual functions called to handle a message, and to deal with an
  278.     /// unhandled message in a default way.
  279.     /// @{
  280.     virtual TResult   WindowProc(uint msg, TParam1 p1, TParam2 p2);
  281.     virtual TResult   DefWindowProc(uint msg, TParam1 p1, TParam2 p2);
  282.     /// @}
  283.  
  284.     // Called by WindowProc() to handle WM_COMMANDs
  285.     //
  286.     virtual TResult   EvCommand(uint id, HWND hWndCtl, uint notifyCode);
  287.  
  288.     // Called by WindowProc() to handle WM_NOTIFYs
  289.     //
  290.     virtual TResult   EvNotify(uint id, TNotify & notifyInfo);
  291.  
  292.     /// \name Called by WindowProc() to handle WM_COMMAND_ENABLE, & helper function
  293.     /// @{
  294.     virtual void      EvCommandEnable(TCommandEnabler& ce);
  295.     void              RouteCommandEnable(HWND hInitCmdTarget, TCommandEnabler& ce);
  296.     /// @}
  297.  
  298.     // Default processing, deals with special cases or calls DefWindowProc
  299.     //
  300.     TResult           DefaultProcessing();
  301.  
  302.     // Paint function called by base classes when responding to WM_PAINT
  303.     //
  304.     virtual void      Paint(TDC& dc, bool erase, TRect& rect);
  305.  
  306.     /// \name Transfer buffer functionality
  307.     /// @{
  308. #if defined(OWL5_COMPAT)
  309.     void              SetTransferBuffer(void* transferBuffer);
  310. #endif
  311.  
  312.     void              SetTransferBuffer(void* transferBuffer, uint size);
  313.    
  314.     template <class TBuffer>
  315.     void              SetTransferBuffer(TBuffer* transferBuffer);
  316.  
  317.     template <class TElement, uint Count>
  318.     void              SetTransferBuffer(TElement (&transferBuffer)[Count]);
  319.  
  320.     void*             GetTransferBuffer() const {return TransferBuffer;}
  321.     uint              GetTransferBufferSize() const {return TransferBufferSize;}
  322.  
  323.     virtual uint      Transfer(void* buffer, TTransferDirection direction);
  324.     virtual void      TransferData(TTransferDirection direction);
  325.     /// @}
  326.  
  327.     // Installs the instance window procedure and saves the previous window
  328.     // procedure in "DefaultProc"
  329.     //
  330.     void              SubclassWindowFunction();
  331.  
  332.     //-----------------------------------
  333.     // Encapsulated native HWND functions inline
  334.     //
  335.  
  336.     /// \name Allow a TWindow& to be used as an HWND in Windows API calls
  337.     /// @{
  338.     HWND               GetHandle() const;
  339.     operator          HWND() const;
  340.     bool              IsWindow() const;
  341.     /// @}
  342.  
  343.     /// \name Messages
  344.     /// @{
  345.     TResult           SendMessage(uint msg, TParam1 p1 = 0, TParam2 p2 = 0) const;
  346.     TResult           SendDlgItemMessage(int childId, uint msg, TParam1 p1 = 0,
  347.                                          TParam2 p2 = 0);
  348.     bool              PostMessage(uint msg, TParam1 p1 = 0, TParam2 p2 = 0);
  349.     static HWND        GetCapture();
  350.     HWND               SetCapture();
  351.     static void       ReleaseCapture();
  352.     static HWND        GetFocus();
  353.     HWND               SetFocus();
  354.     bool              IsWindowEnabled() const;
  355.     virtual bool      EnableWindow(bool enable);
  356.     void              SetRedraw(bool redraw);
  357.     /// @}
  358.  
  359.     /// \name Window coordinates, dimensions...
  360.     /// @{
  361.     void              ScreenToClient(TPoint& point) const;
  362.     void              MapWindowPoints(HWND hWndTo, TPoint* pts, int count) const;
  363.     void              GetClientRect(TRect& rect) const;
  364.     TRect             GetClientRect() const;
  365.     static HWND        WindowFromPoint(const TPoint& point);
  366.     HWND              ChildWindowFromPoint(const TPoint& point) const;
  367.     void              ClientToScreen(TPoint& point) const;
  368.     void              GetWindowRect(TRect& rect) const;
  369.     TRect             GetWindowRect() const;
  370.     static void       AdjustWindowRect(TRect& rect, uint32 style, bool menu);
  371.     static void       AdjustWindowRectEx(TRect& rect, uint32 style,
  372.                                          bool  menu,  uint32 exStyle);
  373.     /// @}
  374.  
  375.     /// \name Window and class Words and Longs, window properties
  376.     /// @{
  377.     long              GetClassName(LPTSTR className, int maxCount) const;
  378.     long              GetClassLong(int index) const;
  379.     long              SetClassLong(int index, long newLong);
  380.     uint16            GetClassWord(int index) const;
  381.     uint16            SetClassWord(int index, uint16 newWord);
  382.     LONG_PTR          GetWindowLongPtr(int index) const;
  383.     LONG_PTR          SetWindowLongPtr(int index, LONG_PTR newLong);
  384.     long              GetWindowLong(int index) const;
  385.     long              SetWindowLong(int index, long newLong);
  386.     uint16            GetWindowWord(int index) const;
  387.     uint16            SetWindowWord(int index, uint16 newWord);
  388.     WNDPROC           GetWindowProc() const;
  389.     WNDPROC           SetWindowProc(WNDPROC wndProc);
  390.     int               EnumProps(PROPENUMPROC proc);
  391.     HANDLE            GetProp(uint16 atom) const;
  392.     HANDLE            RemoveProp(uint16 atom) const;
  393.     bool              SetProp(uint16 atom, HANDLE data) const;
  394.     HANDLE            GetProp(LPCTSTR str) const;
  395.     HANDLE            GetProp(const tstring& str) const {return GetProp(str.c_str());}
  396.     HANDLE            RemoveProp(LPCTSTR str) const;
  397.     HANDLE            RemoveProp(const tstring& str) const {return RemoveProp(str.c_str());}
  398.     bool              SetProp(LPCTSTR str, HANDLE data) const;
  399.     bool              SetProp(const tstring& str, HANDLE data) const {return SetProp(str.c_str(), data);}
  400.     /// @}
  401.  
  402.     /// \name Dual mode accessors.
  403.     /// Work with Attr and other members as well as the underlying window information
  404.     /// @{
  405.     uint32            GetStyle() const;
  406.     uint32            SetStyle(uint32 style);
  407.     uint32            GetExStyle() const;
  408.     uint32            SetExStyle(uint32 style);
  409.     bool              ModifyStyle(uint32 offBits, uint32 onBits,
  410.                                   uint swpFlags = 0);
  411.     bool              ModifyExStyle(uint32 offBits, uint32 onBits,
  412.                                     uint swpFlags = 0);
  413.     /// @}
  414.  
  415.     /// \name Window placement(X,Y) and display
  416.     /// @{
  417.     bool              MoveWindow(int x, int y, int w, int h, bool repaint = false);
  418.     bool              MoveWindow(const TRect& rect, bool repaint = false);
  419.     virtual bool      ShowWindow(int cmdShow);
  420.     void              ShowOwnedPopups(bool show);
  421.     bool              IsWindowVisible() const;
  422.     bool              IsZoomed() const;
  423.     bool              IsIconic() const;
  424.     int               GetWindowTextLength() const;
  425.     int               GetWindowText(LPTSTR str, int maxCount) const;
  426.     tstring        GetWindowText() const;
  427.     void              SetWindowText(LPCTSTR str);
  428.     void              SetWindowText(const tstring& str) {SetWindowText(str.c_str());}
  429.     void              SetWindowText(uint resourceStringId);
  430.     bool              GetWindowPlacement(WINDOWPLACEMENT* place) const;
  431.     bool              SetWindowPlacement(const WINDOWPLACEMENT* place);
  432.     /// @}
  433.  
  434.     /// \name Window positioning(Z), sibling relationships
  435.     /// @{
  436.     void              BringWindowToTop();
  437.     static HWND        GetActiveWindow();
  438.     HWND               SetActiveWindow();
  439.     static HWND        GetDesktopWindow();
  440.     HWND               GetLastActivePopup() const;
  441.     HWND               GetNextWindow(uint dirFlag) const;
  442.     HWND              GetTopWindow() const;
  443.     HWND               GetWindow(uint cmd) const;
  444.     bool              SetWindowPos(HWND      hWndInsertAfter,
  445.                                    const TRect& rect,
  446.                                    uint         flags);
  447.     bool              SetWindowPos(HWND      hWndInsertAfter,
  448.                                    int x, int y, int w, int h,
  449.                                    uint         flags);
  450.     /// @}
  451.  
  452.     /// \name Window painting: invalidating, validating & updating
  453.     /// @{
  454.     virtual void      Invalidate(bool erase = true);
  455.     virtual void      InvalidateRect(const TRect& rect, bool erase = true);
  456.     void              InvalidateRgn(HRGN hRgn, bool erase = true);
  457.     void              Validate();
  458.     void              ValidateRect(const TRect& rect);
  459.     void              ValidateRgn(HRGN hRgn);
  460.     void              UpdateWindow();
  461.     bool              FlashWindow(bool invert);
  462.     bool              GetUpdateRect(TRect& rect, bool erase = true) const;
  463.     int               GetUpdateRgn(TRegion& rgn, bool erase = true) const;
  464.     bool              LockWindowUpdate(bool lock=true);
  465.     bool              RedrawWindow(TRect* update,
  466.                                    HRGN   hUpdateRgn,
  467.                                    uint   redrawFlags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
  468.     /// @}
  469.  
  470.     /// \name Scrolling and scrollbars
  471.     /// @{
  472.     int               GetScrollPos(int bar) const;
  473.     int               SetScrollPos(int bar, int pos, bool redraw = true);
  474.     void              GetScrollRange(int bar, int& minPos, int& maxPos) const;
  475.     void              SetScrollRange(int  bar,
  476.                                      int  minPos,
  477.                                      int  maxPos,
  478.                                      bool redraw = true);
  479.     void              SetScrollPage(int bar, int page, bool redraw = true);
  480.     int               GetScrollPage(int bar) const;
  481.     bool              EnableScrollBar(uint sbFlags=SB_BOTH,
  482.                                       uint arrowFlags=ESB_ENABLE_BOTH);
  483.     void              ShowScrollBar(int bar, bool show = true);
  484.     void              ScrollWindow(int              dx,
  485.                                    int              dy,
  486.                                    const TRect * scroll = 0,
  487.                                    const TRect * clip = 0);
  488.     void              ScrollWindowEx(int              dx,
  489.                                      int              dy,
  490.                                      const TRect * scroll = 0,
  491.                                      const TRect * clip = 0,
  492.                                      HRGN             hUpdateRgn = 0,
  493.                                      TRect *       update = 0,
  494.                                      uint             flags = 0);
  495.     void              SetScrollInfo(int bar, SCROLLINFO* scrollInfo,
  496.                                     bool redraw = true);
  497.     void              GetScrollInfo(int bar, SCROLLINFO* scrollInfo) const;
  498.     /// @}
  499.  
  500.     /// \name Parent/child with Ids
  501.     /// @{
  502.     int               GetDlgCtrlID() const;
  503.     HWND               GetDlgItem(int childId) const;
  504.     uint              GetDlgItemInt(int   childId,
  505.                                     bool* translated = 0,
  506.                                     bool  isSigned = true) const;
  507.     void              SetDlgItemInt(int  childId,
  508.                                     uint value,
  509.                                     bool isSigned = true) const;
  510.     int               GetDlgItemText(int childId, LPTSTR text, int max) const;
  511.     tstring        GetDlgItemText(int childId) const;
  512.     void              SetDlgItemText(int childId, LPCTSTR text) const;
  513.     void              SetDlgItemText(int childId, const tstring& text) const {SetDlgItemText(childId, text.c_str());}
  514.     void              SetDlgItemText(int childId, uint resourceStringId) const {SetDlgItemText(childId, LoadString(resourceStringId));}
  515.     uint              IsDlgButtonChecked(int buttonId) const;
  516.     bool              IsChild(HWND hWnd) const;
  517.     HWND              GetNextDlgGroupItem(HWND hWndCtrl,
  518.                                           bool previous = false) const;
  519.     HWND              GetNextDlgTabItem(HWND hWndCtrl,
  520.                                         bool previous = false) const;
  521.     void              CheckDlgButton(int buttonId, uint check);
  522.     void              CheckRadioButton(int firstButtonId,
  523.                                        int lastButtonId,
  524.                                        int checkButtonId);
  525.     /// @}
  526.  
  527.     /// \name Menus and menubar
  528.     /// @{
  529.     HMENU             GetMenu() const;
  530.     HMENU             GetSystemMenu(bool revert = false) const;
  531.     bool              SetMenu(HMENU hMenu);
  532.     bool              HiliteMenuItem(HMENU hMenu, uint idItem, uint hilite);
  533.     void              DrawMenuBar();
  534.     /// @}
  535.  
  536.     /// \name Timer
  537.     /// @{
  538.     bool              KillTimer(UINT_PTR timerId);
  539.     UINT_PTR          SetTimer(UINT_PTR timerId, uint timeout, TIMERPROC proc = 0);
  540.     /// @}
  541.  
  542.     /// \name Caret, cursor, font
  543.     /// @{
  544.     void              CreateCaret(HBITMAP hBitmap);
  545.     void              CreateCaret(bool isGray, int width, int height);
  546.     static uint       GetCaretBlinkTime();
  547.     static void       GetCaretPos(TPoint& point);
  548.     void              HideCaret();
  549.     static void       SetCaretBlinkTime(uint16 milliSecs);
  550.     static void       SetCaretPos(int x, int y);
  551.     static void       SetCaretPos(const TPoint& pos);
  552.     void              ShowCaret();
  553.     static void       DestroyCaret();
  554.     static void       GetCursorPos(TPoint& pos);
  555.     void              SetWindowFont(HFONT font, bool redraw);
  556.     HFONT             GetWindowFont();
  557.     /// @}
  558.    
  559.  
  560.     /// \name Hot keys
  561.     /// @{
  562.     bool              RegisterHotKey(int idHotKey, uint modifiers, uint virtKey);
  563.     bool              UnregisterHotKey(int idHotKey);
  564.     /// @}
  565.  
  566.     /// \name Misc
  567.     /// @{
  568.     bool              WinHelp(LPCTSTR helpFile, uint command, uint32 data);
  569.     bool              WinHelp(const tstring& helpFile, uint command, uint32 data) {return WinHelp(helpFile.c_str(), command, data);}
  570.     void              AssignContextMenu(TPopupMenu* menu);
  571.     TPopupMenu*       GetContextMenu() const;
  572.     int               MessageBox(LPCTSTR text, LPCTSTR caption = 0, uint flags = MB_OK);
  573.     int               MessageBox(const tstring& text, const tstring& caption = tstring(), uint flags = MB_OK);
  574.     int               MessageBox(uint resId, LPCTSTR caption = 0, uint flags = MB_OK);
  575.     int               MessageBox(uint resId, const tstring& caption, uint flags = MB_OK);
  576.     int               FormatMessageBox(LPCTSTR text, LPCTSTR caption, uint flags, va_list argp);
  577.     int               FormatMessageBox(LPCTSTR text, LPCTSTR caption, uint flags, ...);
  578.     int               FormatMessageBox(const tstring& text, const tstring& caption, uint flags, va_list argp);
  579.     int               FormatMessageBox(const tstring& text, const tstring& caption, uint flags, ...);
  580.     int               FormatMessageBox(uint resId, LPCTSTR caption, uint flags, va_list argp);
  581.     int               FormatMessageBox(uint resId, LPCTSTR caption = 0, uint flags = MB_OK, ...);
  582.     int               FormatMessageBox(uint resId, const tstring& caption, uint flags, va_list argp);
  583.     int               FormatMessageBox(uint resId, const tstring& caption, uint flags = MB_OK, ...);
  584.     HTASK             GetWindowTask() const;
  585.     void              DragAcceptFiles(bool accept);
  586.  
  587.     TCurrentEvent&    GetCurrentEvent();
  588.     void              SethAccel(HACCEL);
  589.     /// @}
  590.  
  591.   protected:
  592.     /// \name These events are processed by TWindow
  593.     /// @{
  594.     void              EvClose();
  595.     int               EvCreate(CREATESTRUCT & createStruct);
  596.     void              EvDestroy();
  597.     TResult           EvCompareItem(uint ctrlId, COMPAREITEMSTRUCT & compareInfo);
  598.     void              EvDeleteItem(uint ctrlId, DELETEITEMSTRUCT & deleteInfo);
  599.     void              EvDrawItem(uint ctrlId, DRAWITEMSTRUCT & drawInfo);
  600.     void              EvMeasureItem(uint ctrlId, MEASUREITEMSTRUCT & measureInfo);
  601.     void              EvHScroll(uint scrollCode, uint thumbPos, HWND hWndCtl);
  602.     void              EvVScroll(uint scrollCode, uint thumbPos, HWND hWndCtl);
  603.     void              EvMove(TPoint& clientOrigin);
  604.     void              EvNCDestroy();
  605.     bool              EvQueryEndSession();
  606.     void              EvSize(uint sizeType, TSize& size);
  607.     void              EvLButtonDown(uint modKeys, TPoint& point);
  608.     bool              EvEraseBkgnd(HDC);
  609.     void              EvPaint();
  610.     void              EvSysColorChange();
  611.     TResult           EvWin32CtlColor(TParam1, TParam2);
  612.     /// @}
  613.  
  614.     /// \name Input validation message handler
  615.     /// @{
  616.     void              EvChildInvalid(HWND hWnd);
  617.     /// @}
  618.  
  619.     /// \name System messages
  620.     /// @{
  621.     void              EvCommNotify(uint commId, uint status);
  622.     void              EvCompacting(uint compactRatio);
  623.     void              EvDevModeChange(LPTSTR devName);
  624.     void              EvEnable(bool enabled);
  625.     void              EvEndSession(bool endSession, bool logOff /* used only by Win95 */);
  626.     void              EvFontChange();
  627.     int               EvPower(uint powerEvent);
  628.     void              EvSysCommand(uint cmdType, TPoint& point);
  629.     void              EvSystemError(uint error);
  630.     void              EvTimeChange();
  631.     void              EvTimer(uint timerId);
  632.     void              EvWinIniChange(LPTSTR section);
  633.     /// @}
  634.  
  635.     /// \name Window manager messages
  636.     /// @{
  637.     void              EvActivate(uint active,
  638.                                  bool minimized,
  639.                                  HWND hWndOther /* may be 0 */);
  640.     void              EvActivateApp(bool active, HTASK hTask);
  641.     void              EvCancelMode();
  642.     void              EvGetMinMaxInfo(MINMAXINFO & minmaxinfo);
  643.     void              EvGetText(uint buffSize, LPTSTR buff);
  644.     uint              EvGetTextLength();
  645.     void              EvIconEraseBkgnd(HDC hDC);
  646.     void              EvKillFocus(HWND hWndGetFocus /* may be 0 */);
  647.     uint              EvMouseActivate(HWND hTopLevel, uint hitCode, uint msg);
  648.     /// @}
  649.  
  650.     /// \name The following are called under Win32 only
  651.     /// @{
  652.     void              EvInputFocus(bool gainingFocus);
  653.     void              EvOtherWindowCreated(HWND hWndOther);
  654.     void              EvOtherWindowDestroyed(HWND hWndOther);
  655.     void              EvPaintIcon();
  656.     void              EvHotKey(int idHotKey);
  657.     TResult           EvCopyData(HWND hwnd, COPYDATASTRUCT* dataStruct);
  658.  
  659.     void              EvNextDlgCtl(uint hctlOrDir, uint isHCtl);
  660.     void              EvParentNotify(uint event,
  661.                                      uint childHandleOrX,
  662.                                      uint childIDOrY);
  663.     HANDLE            EvQueryDragIcon();
  664.     bool              EvQueryOpen();
  665.     void              EvQueueSync();
  666.     bool              EvSetCursor(HWND hWndCursor,
  667.                                   uint hitTest,
  668.                                   uint mouseMsg);
  669.     void              EvSetFocus(HWND hWndLostFocus /* may be 0 */);
  670.     HFONT             EvGetFont();
  671.     void              EvSetFont(HFONT hFont, bool redraw);
  672.     void              EvSetRedraw(bool redraw);
  673.     void              EvSetText(LPCTSTR text);
  674.     void              EvShowWindow(bool show, uint status);
  675.     void              EvWindowPosChanged(WINDOWPOS & windowPos);
  676.     void              EvWindowPosChanging(WINDOWPOS & windowPos);
  677.     /// @}
  678.  
  679.     /// \name Controls
  680.     /// @{
  681.     HBRUSH            EvCtlColor(HDC hDC, HWND hWndChild, uint ctlType);
  682.     /// @}
  683.  
  684.     /// \name Keyboard input
  685.     /// @{
  686.     void              EvChar(uint key, uint repeatCount, uint flags);
  687.     void              EvDeadChar(uint deadKey, uint repeatCount, uint flags);
  688.     void              EvKeyDown(uint key, uint repeatCount, uint flags);
  689.     void              EvKeyUp(uint key, uint repeatCount, uint flags);
  690.     void              EvSysChar(uint key, uint repeatCount, uint flags);
  691.     void              EvSysDeadChar(uint key, uint repeatCount, uint flags);
  692.     void              EvSysKeyDown(uint key, uint repeatCount, uint flags);
  693.     void              EvSysKeyUp(uint key, uint repeatCount, uint flags);
  694.     /// @}
  695.  
  696.     /// \name Mouse input
  697.     /// @{
  698.     void              EvLButtonDblClk(uint modKeys, TPoint& point);
  699.     void              EvLButtonUp(uint modKeys, TPoint& point);
  700.     void              EvMButtonDblClk(uint modKeys, TPoint& point);
  701.     void              EvMButtonDown(uint modKeys, TPoint& point);
  702.     void              EvMButtonUp(uint modKeys, TPoint& point);
  703.     void              EvMouseMove(uint modKeys, TPoint& point);
  704.     bool              EvMouseWheel(uint modKeys, int zDelta, TPoint& point);
  705.     void              EvRButtonDblClk(uint modKeys, TPoint& point);
  706.     void              EvRButtonDown(uint modKeys, TPoint& point);
  707.     void              EvRButtonUp(uint modKeys, TPoint& point);
  708.     TResult            EvRegisteredMouseWheel(TParam1, TParam2);
  709.     /// @}
  710.  
  711.  
  712.     /// \name Menu related messages
  713.     /// @{
  714.     void              EvInitMenu(HMENU hMenu);
  715.     void              EvInitMenuPopup(HMENU hPopupMenu,
  716.                                       uint  index,
  717.                                       bool  sysMenu);
  718.     int32             EvMenuChar(uint nChar, uint menuType, HMENU hMenu);
  719.     void              EvMenuSelect(uint menuItemId, uint flags, HMENU hMenu);
  720.     void              EvContextMenu(HWND childHwnd, int x, int y);
  721.     /// @}
  722.  
  723.     /// \name Dialog [Menu] messages
  724.     /// @{
  725.     uint              EvGetDlgCode(MSG * msg);
  726.     void              EvEnterIdle(uint source, HWND hWndDlg);
  727.     /// @}
  728.  
  729.     /// \name Print manager messages
  730.     /// @{
  731.     void              EvSpoolerStatus(uint jobStatus, uint jobsLeft);
  732.     /// @}
  733.  
  734.     /// \name Clipboard messages
  735.     /// @{
  736.     void              EvAskCBFormatName(uint bufLen, LPTSTR buffer);
  737.     void              EvChangeCBChain(HWND hWndRemoved, HWND hWndNext);
  738.     void              EvDrawClipboard();
  739.     void              EvDestroyClipboard();
  740.     void              EvHScrollClipboard(HWND hCBViewer, uint scrollCode, uint pos);
  741.     void              EvPaintClipboard(HWND hWnd, HANDLE hPaintStruct);
  742.     void              EvRenderAllFormats();
  743.     void              EvRenderFormat(uint dataFormat);
  744.     void              EvSizeClipboard(HWND hWndViewer, HANDLE hRect);
  745.     void              EvVScrollClipboard(HWND hCBViewer, uint scrollCode, uint pos);
  746.     /// @}
  747.  
  748.     /// \name Palette manager messages
  749.     /// @{
  750.     void              EvPaletteChanged(HWND hWndPalChg);
  751.     void              EvPaletteIsChanging(HWND hWndPalChg);
  752.     bool              EvQueryNewPalette();
  753.     /// @}
  754.  
  755.     /// \name Drag-n-drop messages
  756.     /// @{
  757.     void              EvDropFiles(TDropInfo dropInfo);
  758.     /// @}
  759.  
  760.     /// \name List box messages
  761.     /// @{
  762.     int               EvCharToItem(uint key, HWND hWndListBox, uint caretPos);
  763.     int               EvVKeyToItem(uint key, HWND hWndListBox, uint caretPos);
  764.     /// @}
  765.  
  766.     /// \name Non-client messages
  767.     /// @{
  768.     bool              EvNCActivate(bool active);
  769.     uint              EvNCCalcSize(bool calcValidRects, NCCALCSIZE_PARAMS & params);
  770.     bool              EvNCCreate(CREATESTRUCT & createStruct);
  771.     uint              EvNCHitTest(TPoint& point);
  772.     void              EvNCLButtonDblClk(uint hitTest, TPoint& point);
  773.     void              EvNCLButtonDown(uint hitTest, TPoint& point);
  774.     void              EvNCLButtonUp(uint hitTest, TPoint& point);
  775.     void              EvNCMButtonDblClk(uint hitTest, TPoint& point);
  776.     void              EvNCMButtonDown(uint hitTest, TPoint& point);
  777.     void              EvNCMButtonUp(uint hitTest, TPoint& point);
  778.     void              EvNCMouseMove(uint hitTest, TPoint& point);
  779.  
  780.     // WM_NCPAINT now passes an HRGN under Win32.
  781.     //
  782.     void              EvNCPaint(HRGN);
  783.  
  784.     void              EvNCRButtonDblClk(uint hitTest, TPoint& point);
  785.     void              EvNCRButtonDown(uint hitTest, TPoint& point);
  786.     void              EvNCRButtonUp(uint hitTest, TPoint& point);
  787.     /// @}
  788.  
  789.     /// \name Icon messages
  790.     /// \todo There is no implementation for these functions
  791.     /// @{
  792.     HICON             EvGetIcon(bool largeIcon);
  793.     HICON             EvSetIcon(bool largeIcon, HICON icon);
  794.     /// @}
  795.  
  796.     /// \name Callback procs for hooking TWindow to native window
  797.     /// @{
  798.     static TResult CALLBACK InitWndProc(HWND, uint, TParam1, TParam2);
  799.     /// @}
  800.  
  801.   protected:
  802.     // Constructor & subsequent initializer for use with virtual derivations
  803.     // Immediate derivitives must call Init() before constructions are done.
  804.     //
  805.     TWindow();
  806.     void              Init(TWindow* parent, LPCTSTR title, TModule* module);
  807.     void              Init(TWindow* parent, const tstring& title, TModule* module) {Init(parent, title.c_str(), module);}
  808.     void              Init(HWND hWnd, TModule* module);
  809.  
  810.     //
  811.     /// For code safety and 64-bit compatibility the old parameter to PerformCreate
  812.     /// has been deprecated. In the strict build mode, the parameter is no longer
  813.     /// used, and the signature of PerformCreate has been changed to force a
  814.     /// compilation error for legacy code. This is achieved by changing the return
  815.     /// type but leaving the old parameter in place, although now unused.
  816.     //
  817. #if OWL_STRICT
  818.     typedef THandle TPerformCreateReturnType;
  819. #else
  820.     typedef void TPerformCreateReturnType;
  821. #endif
  822.  
  823.     virtual TPerformCreateReturnType PerformCreate(int deprecated_argument = 0);
  824.    
  825.     void SetHandle(THandle);
  826.     TPerformCreateReturnType SetOrReturnHandle(THandle);
  827.  
  828.     // Resynching state
  829.     //
  830.     void              GetHWndState(bool forceStyleSync = false);
  831.     void              GetWindowTextTitle();
  832.  
  833.     virtual void      GetWindowClass(WNDCLASS& wndClass);
  834.  
  835. #if defined(OWL5_COMPAT)
  836.     typedef LPTSTR TGetClassNameReturnType;
  837. #else
  838.     typedef LPCTSTR TGetClassNameReturnType;
  839. #endif
  840.     virtual TGetClassNameReturnType GetClassName();
  841.  
  842.     void              PerformSetupAndTransfer();
  843.     virtual void      SetupWindow();
  844.     virtual void      CleanupWindow();
  845.  
  846.     void              DispatchScroll(uint scrollCode, uint thumbPos, HWND hWndCtrl);
  847.  
  848.     void              LoadAcceleratorTable();
  849.     virtual void      RemoveChild(TWindow* child);
  850.  
  851.     TWindow*          GetWindowPtr(HWND hWnd) const;
  852.  
  853.     // Member data  // !CQ need to add accessors for many of these
  854.     //
  855.   public_data:
  856.  
  857.     /// Holds the handle to the associated MS-Windows window, which you'll need to
  858.     /// access if you make calls directly to Windows API functions.
  859.     //
  860.     HWND         Handle;  
  861.  
  862. /// Points to the window's caption. When there is a valid HWindow, Title will yield
  863. /// the same information as ::GetWindowText if you use TWindow::SetCaption to set
  864. /// it.
  865.     LPTSTR             Title;    // Logical title. Usually the same as window text
  866.    
  867. /// Points to the interface object that serves as the parent window for this interface object.
  868.     TWindow*          Parent;   // Owl parent, use GetParentO(), SetParent()
  869.  
  870. /// Holds a TWindowAttr structure, which contains the window's creation attributes.
  871. /// These attributes, which  include the window's style, extended style, position,
  872. /// size, menu ID, child window ID, and menu accelerator table ID, are passed to the
  873. /// function that creates the window.
  874.     TWindowAttr       Attr;    
  875.  
  876. /// Holds the address of the default window procedure. DefWindowProc calls
  877. /// DefaultProc to process Windows messages that are not handled by the window.
  878.     WNDPROC           DefaultProc;
  879.  
  880. /// Points to the scroller object that supports either the horizontal or vertical
  881. /// scrolling for this window.
  882.     TScroller*        Scroller; // Scrolling helper object
  883.  
  884.   protected_data:
  885.  
  886.     /// Holds the handle to the current Windows accelerator table associated with this window.
  887.     //
  888.     HACCEL          HAccel;
  889.    
  890. /// Holds the module ID for the specified cursor. A value of 0 indicates a standard system cursor.
  891.     TModule*          CursorModule;
  892.    
  893. /// Holds the cursor resource ID for the window's cursor. If the data member
  894. /// CursorModule is 0, CursorResId can be one of the following IDC_Xxxx constants
  895. /// that represent different kinds of cursors:
  896. /// - \c \b IDC_ARROW   Customary arrow cursor
  897. /// - \c \b IDC_CROSS   Crosshair cursor
  898. /// - \c \b IDC_IBEAM   I-beam cursor
  899. /// - \c \b IDC_ICON    Unfilled icon cursor
  900. /// - \c \b IDC_SIZE    A smaller square in the right inside corner of a larger square
  901. /// - \c \b IDC_SIZENESW    Dual-pointing cursor with arrows pointing southwest and northeast
  902. /// - \c \b IDC_SIZENS  Dual-pointing cursor with arrows pointing south and north
  903. /// - \c \b IDC_SIZENWSE    Dual-pointing cursor with arrows pointing southeast and northwest
  904. /// - \c \b IDC_SIZEWE  Dual-pointing cursor with arrows pointing east and west
  905. /// - \c \b IDC_UPARROW Vertical arrow cursor
  906. /// - \c \b IDC_WAIT    Hourglass cursor
  907.     TResId            CursorResId;
  908.    
  909. /// Holds a handle to the window's cursor. The cursor is retrieved using
  910. /// CursorModule and CursorResId and set using SetCursor.
  911.     HCURSOR           HCursor;
  912.  
  913. /// Stores the current background color set by TWindow::SetBkgndColor.
  914.     TColor            BkgndColor;
  915.  
  916.     TPopupMenu*       ContextPopupMenu;   ///< Popup menu used for right click
  917.     TTooltip*          Tooltip;            // Tooltip
  918.  
  919. #if defined(OWL5_COMPAT)
  920.   protected_data: // TransferBuffer is proteced or maybe even public.
  921. #else
  922.   private: // TransferBuffer is always private.
  923. #endif
  924.  
  925. /// Points to a buffer to be used in transferring data in and out of the TWindow
  926. /// object. A TWindow object assumes that the buffer contains data used by the
  927. /// windows in its child list. If TransferBuffer is 0, no data is to be transferred.
  928.     void*             TransferBuffer;
  929.  
  930. /// Specifies the size of the transfer buffer pointed to by TransferBuffer.
  931.     uint              TransferBufferSize;
  932.    
  933.   private:
  934.     WNDPROC           InstanceProc; ///< The window proc for this window instance
  935.     TApplication*     Application;  ///< Application that this window belongs to
  936.     TModule*          Module;       ///< Default module used for getting resources
  937.     uint32            Flags;
  938.     uint16            ZOrder;
  939.     TWindow*          ChildList;
  940.     TWindow*          SiblingList;
  941.     uint32            UniqueId;
  942.  
  943.     static uint32     LastUniqueId;
  944.  
  945.     // Instance window proc interface
  946.     //
  947.     WNDPROC           CreateInstanceProc();
  948.     WNDPROC           GetInstanceProc() const;
  949.     void              InitInstanceProc();
  950.     void              FreeInstanceProc();
  951.  
  952.     // Internal functions
  953.     //
  954.     HMENU MakeMenuOrId();
  955.     void              PerformInit(TWindow* parent, TModule* module);
  956.     bool              OrderIsI(TWindow* win, void* position);
  957.     void              AssignZOrder();
  958.     void              AddChild(TWindow* child);
  959.     int               IndexOf(TWindow* child) const;
  960.     TWindow*          At(int position);
  961.     void              SetUniqueId();
  962.  
  963.     TResult ReceiveMessage(HWND hwnd, uint msg, TParam1 p1 = 0, TParam2 p2 = 0);
  964.     friend void* GetMessageReceiverMemberFunctionAddress();
  965.  
  966.     // Hidden to prevent accidental copying or assignment
  967.     //
  968.     TWindow(const TWindow&);
  969.     TWindow& operator =(const TWindow&);
  970.  
  971.   DECLARE_RESPONSE_TABLE(TWindow);
  972. //  DECLARE_STREAMABLE(_OWLCLASS, owl::TWindow, 3);
  973.   DECLARE_STREAMABLE_OWL(owl::TWindow, 3);
  974. };  // class TWindow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement