1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma warning(disable : 4917 4555)
23 #include "docholder.hxx"
24 #include "syswinwrapper.hxx"
30 * Constructor Parameters:
31 * hInst HINSTANCE of the task owning us.
35 using namespace winwrap
;
38 #define HWWL_STRUCTURE 0
40 //Notification codes for WM_COMMAND messages
41 #define HWN_BORDERDOUBLECLICKED 1
42 #define CBHATCHWNDEXTRA (sizeof(LONG))
43 #define SZCLASSHATCHWIN TEXT("hatchwin")
45 typedef CHatchWin
*PCHatchWin
;
48 void DrawShading(LPRECT prc
, HDC hDC
, UINT cWidth
);
51 winwrap::CWindow::CWindow(HINSTANCE hInst
)
58 winwrap::CWindow::~CWindow()
61 DestroyWindow(m_hWnd
);
71 * Returns the window handle associated with this object.
74 * HWND Window handle for this object
77 HWND
winwrap::CWindow::Window()
87 * Returns the instance handle associated with this object.
90 * HINSTANCE Instance handle of the module stored here.
93 HINSTANCE
winwrap::CWindow::Instance()
102 * Registers the hatch window class for use with CHatchWin.
105 * hInst HINSTANCE under which to register.
108 * BOOL TRUE if successful, FALSE otherwise.
111 BOOL
winwrap::HatchWindowRegister(HINSTANCE hInst
)
115 //Must have CS_DBLCLKS for border!
116 wc
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
117 wc
.hInstance
= hInst
;
119 wc
.lpfnWndProc
= HatchWndProc
;
120 wc
.cbWndExtra
= CBHATCHWNDEXTRA
;
122 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
123 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
124 wc
.lpszMenuName
= NULL
;
125 wc
.lpszClassName
= SZCLASSHATCHWIN
;
127 return RegisterClass(&wc
);
132 * CHatchWin:CHatchWin
133 * CHatchWin::~CHatchWin
135 * Constructor Parameters:
136 * hInst HINSTANCE of the application we're in.
139 CHatchWin::CHatchWin(HINSTANCE hInst
,const DocumentHolder
* pDocHolder
)
145 m_hWndAssociate
=NULL
;
148 m_dBorderOrg
=GetProfileInt(TEXT("windows")
149 , TEXT("OleInPlaceBorderWidth")
150 , HATCHWIN_BORDERWIDTHDEFAULT
);
152 m_dBorder
=m_dBorderOrg
;
153 SetRect(&m_rcPos
, 0, 0, 0, 0);
154 SetRect(&m_rcClip
, 0, 0, 0, 0);
156 m_pDocHolder
= pDocHolder
;
161 CHatchWin::~CHatchWin()
164 * Chances are this was already destroyed when a document
167 if (NULL
!=m_hWnd
&& IsWindow(m_hWnd
))
168 DestroyWindow(m_hWnd
);
178 * Instantiates a hatch window within a given parent with a
179 * default rectangle. This is not initially visible.
182 * hWndParent HWND of the parent of this window
183 * uID WORD identifier for this window (send in
184 * notifications to associate window).
185 * hWndAssoc HWND of the initial associate.
188 * BOOL TRUE if the function succeeded, FALSE otherwise.
191 BOOL
CHatchWin::Init(HWND hWndParent
, WORD uID
, HWND hWndAssoc
)
193 m_hWndParent
= hWndParent
;
194 m_hWnd
=CreateWindowEx(
195 WS_EX_NOPARENTNOTIFY
, SZCLASSHATCHWIN
196 , SZCLASSHATCHWIN
, WS_CHILD
| WS_CLIPSIBLINGS
197 | WS_CLIPCHILDREN
, 0, 0, 100, 100, hWndParent
198 , reinterpret_cast<HMENU
>(UINT_PTR(uID
)), m_hInst
, this);
201 m_hWndAssociate
=hWndAssoc
;
203 return (NULL
!=m_hWnd
);
207 void CHatchWin::SetTrans()
209 HRGN hrgn
= CreateRectRgn(0,0,0,0);
210 SetWindowRgn(m_hWnd
,hrgn
,true);
214 * CHatchWin::HwndAssociateSet
215 * CHatchWin::HwndAssociateGet
218 * Sets (Set) or retrieves (Get) the associate window of the
221 * Parameters: (Set only)
222 * hWndAssoc HWND to set as the associate.
225 * HWND Previous (Set) or current (Get) associate
229 HWND
CHatchWin::HwndAssociateSet(HWND hWndAssoc
)
231 HWND hWndT
=m_hWndAssociate
;
233 m_hWndAssociate
=hWndAssoc
;
238 HWND
CHatchWin::HwndAssociateGet()
240 return m_hWndAssociate
;
245 * CHatchWin::RectsSet
248 * Changes the size and position of the hatch window and the child
249 * window within it using a position rectangle for the child and
250 * a clipping rectangle for the hatch window and child. The hatch
251 * window occupies prcPos expanded by the hatch border and clipped
252 * by prcClip. The child window is fit to prcPos to give the
253 * proper scaling, but it clipped to the hatch window which
254 * therefore clips it to prcClip without affecting the scaling.
257 * prcPos LPRECT providing the position rectangle.
258 * prcClip LPRECT providing the clipping rectangle.
264 void CHatchWin::RectsSet(LPRECT prcPos
, LPRECT prcClip
)
272 //Calculate the rectangle for the hatch window, then clip it.
274 InflateRect(&rcPos
, m_dBorder
, m_dBorder
);
275 IntersectRect(&rc
, &rcPos
, prcClip
);
277 SetWindowPos(m_hWnd
, NULL
, rc
.left
, rc
.top
, rc
.right
-rc
.left
278 , rc
.bottom
-rc
.top
, SWP_NOZORDER
| SWP_NOACTIVATE
);
281 * Set the rectangle of the child window to be at m_dBorder
282 * from the top and left but with the same size as prcPos
283 * contains. The hatch window will clip it.
285 // SetWindowPos(m_hWndKid, NULL, rcPos.left-rc.left+m_dBorder
286 // , rcPos.top-rc.top+m_dBorder, prcPos->right-prcPos->left
287 // , prcPos->bottom-prcPos->top, SWP_NOZORDER | SWP_NOACTIVATE);
290 GetClientRect(m_hWnd
,&newRC
);
291 m_aTracker
= Tracker(
293 Tracker::hatchInside
|
294 Tracker::hatchedBorder
|
295 Tracker::resizeInside
303 * CHatchWin::ChildSet
306 * Assigns a child window to this hatch window.
309 * hWndKid HWND of the child window.
315 void CHatchWin::ChildSet(HWND hWndKid
)
321 SetParent(hWndKid
, m_hWnd
);
323 //Insure this is visible when the hatch window becomes visible.
324 ShowWindow(hWndKid
, SW_SHOW
);
332 * CHatchWin::ShowHatch
335 * Turns hatching on and off; turning the hatching off changes
336 * the size of the window to be exactly that of the child, leaving
337 * everything else the same. The result is that we don't have
338 * to turn off drawing because our own WM_PAINT will never be
342 * fHatch BOOL indicating to show (TRUE) or hide (FALSE)
349 void CHatchWin::ShowHatch(BOOL fHatch
)
352 * All we have to do is set the border to zero and
353 * call SetRects again with the last rectangles the
356 m_dBorder
=fHatch
? m_dBorderOrg
: 0;
357 RectsSet(&m_rcPos
, &m_rcClip
);
366 * Standard window procedure for the Hatch Window
369 LRESULT APIENTRY
winwrap::HatchWndProc(
371 , WPARAM wParam
, LPARAM lParam
)
377 phw
=(PCHatchWin
)GetWindowLongPtr(hWnd
, HWWL_STRUCTURE
);
383 phw
=(PCHatchWin
)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
384 SetWindowLongPtr(hWnd
, HWWL_STRUCTURE
, (LONG_PTR
)phw
);
387 hDC
=BeginPaint(hWnd
,&ps
);
388 //Always draw the hatching.
389 phw
->m_aTracker
.Draw(hDC
);
393 GetCursorPos(&ptMouse
);
394 ScreenToClient(hWnd
,&ptMouse
);
396 // track in case we have to
397 if(phw
->m_aTracker
.Track(hWnd
,ptMouse
,FALSE
,GetParent(hWnd
)))
399 RECT aRect
= phw
->m_aTracker
.m_rect
;
400 TransformRect(&aRect
,hWnd
,GetParent(hWnd
));
401 phw
->m_pDocHolder
->OnPosRectChanged(&aRect
);
406 GetCursorPos(&ptMouse
);
407 ScreenToClient(hWnd
,&ptMouse
);
408 phw
->m_aTracker
.SetCursor(hWnd
,HTCLIENT
);
411 //We need this since the container will SetFocus to us.
412 if (NULL
!=phw
->m_hWndKid
)
413 SetFocus(phw
->m_hWndKid
);
416 case WM_LBUTTONDBLCLK
:
418 * If the double click was within m_dBorder of an
419 * edge, send the HWN_BORDERDOUBLECLICKED notification.
421 * Because we're always sized just larger than our child
422 * window by the border width, we can only *get* this
423 * message when the mouse is on the border. So we can
424 * just send the notification.
426 if (NULL
!=phw
->m_hWndAssociate
)
429 phw
->m_hWndAssociate
, WM_COMMAND
,
430 MAKEWPARAM(phw
->m_uID
, HWN_BORDERDOUBLECLICKED
),
436 return DefWindowProc(hWnd
, iMsg
, wParam
, lParam
);
442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */