1*a20fd023SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a20fd023SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a20fd023SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a20fd023SAndrew Rist  * distributed with this work for additional information
6*a20fd023SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a20fd023SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a20fd023SAndrew Rist  * "License"); you may not use this file except in compliance
9*a20fd023SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a20fd023SAndrew Rist  *
11*a20fd023SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a20fd023SAndrew Rist  *
13*a20fd023SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a20fd023SAndrew Rist  * software distributed under the License is distributed on an
15*a20fd023SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a20fd023SAndrew Rist  * KIND, either express or implied.  See the License for the
17*a20fd023SAndrew Rist  * specific language governing permissions and limitations
18*a20fd023SAndrew Rist  * under the License.
19*a20fd023SAndrew Rist  *
20*a20fd023SAndrew Rist  *************************************************************/
21*a20fd023SAndrew Rist 
22*a20fd023SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <windows.h>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**
28cdf0e10cSrcweir  ** CWindow:  Our basic window class.
29cdf0e10cSrcweir  **/
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir class DocumentHolder;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace winwrap {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir     void TransformRect(LPRECT rect,HWND pWnd,HWND pWndClipTo);
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 	LRESULT APIENTRY HatchWndProc(
42cdf0e10cSrcweir 		HWND hWnd, UINT iMsg
43cdf0e10cSrcweir 		, WPARAM wParam, LPARAM lParam);
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	BOOL HatchWindowRegister(HINSTANCE hInst);
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     class CWindow
49cdf0e10cSrcweir     {
50cdf0e10cSrcweir     protected:
51cdf0e10cSrcweir         HINSTANCE   m_hInst;            //Task instance
52cdf0e10cSrcweir         HWND        m_hWnd;             //Window handle of the window
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     public:
55cdf0e10cSrcweir         //Standard Class Functions
56cdf0e10cSrcweir         CWindow(HINSTANCE);
57cdf0e10cSrcweir         ~CWindow(void);
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         //Just returns members.  No need to modify
60cdf0e10cSrcweir         HWND        Window(void);
61cdf0e10cSrcweir         HINSTANCE   Instance(void);
62cdf0e10cSrcweir     };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     class Tracker {
67cdf0e10cSrcweir     public:
68cdf0e10cSrcweir         // Constructors
69cdf0e10cSrcweir         Tracker();
70cdf0e10cSrcweir         Tracker(LPCRECT lpSrcRect, UINT nStyle);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         // Style Flags
73cdf0e10cSrcweir         enum StyleFlags
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir             solidLine = 1, dottedLine = 2, hatchedBorder = 4,
76cdf0e10cSrcweir             resizeInside = 8, resizeOutside = 16, hatchInside = 32,
77cdf0e10cSrcweir         };
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         // Hit-Test codes
80cdf0e10cSrcweir         enum TrackerHit
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir             hitNothing = -1,
83cdf0e10cSrcweir             hitTopLeft = 0, hitTopRight = 1,
84cdf0e10cSrcweir             hitBottomRight = 2, hitBottomLeft = 3,
85cdf0e10cSrcweir             hitTop = 4, hitRight = 5, hitBottom = 6,
86cdf0e10cSrcweir             hitLeft = 7, hitMiddle = 8
87cdf0e10cSrcweir         };
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         // Attributes
90cdf0e10cSrcweir         UINT m_nStyle;      // current state
91cdf0e10cSrcweir         RECT m_rect;       // current position (always in pixels)
92cdf0e10cSrcweir         SIZE m_sizeMin;    // minimum X and Y size during track operation
93cdf0e10cSrcweir         int m_nHandleSize;  // size of resize handles (default from WIN.INI)
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         // Operations
96cdf0e10cSrcweir         void Draw(HDC hDC) const;
97cdf0e10cSrcweir         void GetTrueRect(LPRECT lpTrueRect) const;
98cdf0e10cSrcweir         BOOL SetCursor(HWND hWnd,UINT nHitTest) const;
99cdf0e10cSrcweir         BOOL Track(HWND hWnd,POINT point,BOOL bAllowInvert = FALSE,
100cdf0e10cSrcweir                    HWND hWndClipTo = NULL);
101cdf0e10cSrcweir //         BOOL TrackRubberBand(HWND hWnd,POINT point,BOOL bAllowInvert = TRUE);
102cdf0e10cSrcweir         int HitTest(POINT point) const;
103cdf0e10cSrcweir         int NormalizeHit(int nHandle) const;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         // Overridables
106cdf0e10cSrcweir         virtual void DrawTrackerRect(
107cdf0e10cSrcweir             LPRECT lpRect, HWND hWndClipTo,
108cdf0e10cSrcweir             HDC hDC, HWND hWnd);
109cdf0e10cSrcweir         virtual void AdjustRect(int nHandle, LPRECT lpRect);
110cdf0e10cSrcweir         virtual void OnChangedRect(const RECT& rectOld);
111cdf0e10cSrcweir         virtual UINT GetHandleMask() const;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // Implementation
114cdf0e10cSrcweir     public:
115cdf0e10cSrcweir         virtual ~Tracker();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir protected:
118cdf0e10cSrcweir         BOOL m_bAllowInvert; // flag passed to Track or TrackRubberBand
119cdf0e10cSrcweir         RECT m_rectLast;
120cdf0e10cSrcweir         SIZE m_sizeLast;
121cdf0e10cSrcweir         BOOL m_bErase;       // TRUE if DrawTrackerRect is called for erasing
122cdf0e10cSrcweir         BOOL m_bFinalErase;  // TRUE if DragTrackerRect called for final erase
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         // implementation helpers
125cdf0e10cSrcweir         int HitTestHandles(POINT point) const;
126cdf0e10cSrcweir         void GetHandleRect(int nHandle,RECT* pHandleRect) const;
127cdf0e10cSrcweir         void GetModifyPointers(
128cdf0e10cSrcweir             int nHandle,int**ppx, int**ppy, int* px, int*py);
129cdf0e10cSrcweir         virtual int GetHandleSize(LPRECT lpRect = NULL) const;
130cdf0e10cSrcweir         BOOL TrackHandle(int nHandle,HWND hWnd,POINT point,HWND hWndClipTo);
131cdf0e10cSrcweir         void Construct();
132cdf0e10cSrcweir     };
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //Width of the border
137cdf0e10cSrcweir #define HATCHWIN_BORDERWIDTHDEFAULT     4
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     class CHatchWin : public CWindow
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         friend LRESULT APIENTRY HatchWndProc(HWND, UINT, WPARAM, LPARAM);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     public:
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         const DocumentHolder* m_pDocHolder;
147cdf0e10cSrcweir         Tracker               m_aTracker;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         int         m_dBorder;
150cdf0e10cSrcweir         int         m_dBorderOrg;
151cdf0e10cSrcweir         UINT        m_uID;
152cdf0e10cSrcweir         HWND        m_hWndParent;
153cdf0e10cSrcweir         HWND        m_hWndKid;
154cdf0e10cSrcweir         HWND        m_hWndAssociate;
155cdf0e10cSrcweir         RECT        m_rcPos;
156cdf0e10cSrcweir         RECT        m_rcClip;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     public:
159cdf0e10cSrcweir         CHatchWin(HINSTANCE,const DocumentHolder*);
160cdf0e10cSrcweir         ~CHatchWin(void);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         BOOL        Init(HWND, UINT, HWND);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         HWND        HwndAssociateSet(HWND);
165cdf0e10cSrcweir         HWND        HwndAssociateGet(void);
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         void        RectsSet(LPRECT, LPRECT);
168cdf0e10cSrcweir         void        ChildSet(HWND);
169cdf0e10cSrcweir         void        ShowHatch(BOOL);
170cdf0e10cSrcweir         void        SetTrans();
171cdf0e10cSrcweir     };
172cdf0e10cSrcweir 
173cdf0e10cSrcweir }
174