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