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")
44 #define SendCommand(hWnd, wID, wCode, hControl) \
45 SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(wID, wCode) \
49 typedef CHatchWin
*PCHatchWin
;
52 void DrawShading(LPRECT prc
, HDC hDC
, UINT cWidth
);
56 winwrap::CWindow::CWindow(HINSTANCE hInst
)
63 winwrap::CWindow::~CWindow(void)
66 DestroyWindow(m_hWnd
);
77 * Returns the window handle associated with this object.
80 * HWND Window handle for this object
83 HWND
winwrap::CWindow::Window(void)
94 * Returns the instance handle associated with this object.
97 * HINSTANCE Instance handle of the module stored here.
100 HINSTANCE
winwrap::CWindow::Instance(void)
109 //Hatch pattern brush bits
110 static WORD g_wHatchBmp
[]={0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};
112 // void DrawShading(LPRECT, HDC, UINT);
116 * HatchWindowRegister
119 * Registers the hatch window class for use with CHatchWin.
122 * hInst HINSTANCE under which to register.
125 * BOOL TRUE if successful, FALSE otherwise.
128 BOOL
winwrap::HatchWindowRegister(HINSTANCE hInst
)
132 //Must have CS_DBLCLKS for border!
133 wc
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
134 wc
.hInstance
= hInst
;
136 wc
.lpfnWndProc
= HatchWndProc
;
137 wc
.cbWndExtra
= CBHATCHWNDEXTRA
;
139 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
140 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
141 wc
.lpszMenuName
= NULL
;
142 wc
.lpszClassName
= SZCLASSHATCHWIN
;
144 return RegisterClass(&wc
);
151 * CHatchWin:CHatchWin
152 * CHatchWin::~CHatchWin
154 * Constructor Parameters:
155 * hInst HINSTANCE of the application we're in.
158 CHatchWin::CHatchWin(HINSTANCE hInst
,const DocumentHolder
* pDocHolder
)
164 m_hWndAssociate
=NULL
;
167 m_dBorderOrg
=GetProfileInt(TEXT("windows")
168 , TEXT("OleInPlaceBorderWidth")
169 , HATCHWIN_BORDERWIDTHDEFAULT
);
171 m_dBorder
=m_dBorderOrg
;
172 SetRect(&m_rcPos
, 0, 0, 0, 0);
173 SetRect(&m_rcClip
, 0, 0, 0, 0);
175 m_pDocHolder
= pDocHolder
;
180 CHatchWin::~CHatchWin(void)
183 * Chances are this was already destroyed when a document
186 if (NULL
!=m_hWnd
&& IsWindow(m_hWnd
))
187 DestroyWindow(m_hWnd
);
198 * Instantiates a hatch window within a given parent with a
199 * default rectangle. This is not initially visible.
202 * hWndParent HWND of the parent of this window
203 * uID UINT identifier for this window (send in
204 * notifications to associate window).
205 * hWndAssoc HWND of the initial associate.
208 * BOOL TRUE if the function succeeded, FALSE otherwise.
211 BOOL
CHatchWin::Init(HWND hWndParent
, UINT uID
, HWND hWndAssoc
)
213 m_hWndParent
= hWndParent
;
214 m_hWnd
=CreateWindowEx(
215 WS_EX_NOPARENTNOTIFY
, SZCLASSHATCHWIN
216 , SZCLASSHATCHWIN
, WS_CHILD
| WS_CLIPSIBLINGS
217 | WS_CLIPCHILDREN
, 0, 0, 100, 100, hWndParent
, (HMENU
)uID
221 m_hWndAssociate
=hWndAssoc
;
223 return (NULL
!=m_hWnd
);
227 void CHatchWin::SetTrans()
229 HRGN hrgn
= CreateRectRgn(0,0,0,0);
230 SetWindowRgn(m_hWnd
,hrgn
,true);
234 * CHatchWin::HwndAssociateSet
235 * CHatchWin::HwndAssociateGet
238 * Sets (Set) or retrieves (Get) the associate window of the
241 * Parameters: (Set only)
242 * hWndAssoc HWND to set as the associate.
245 * HWND Previous (Set) or current (Get) associate
249 HWND
CHatchWin::HwndAssociateSet(HWND hWndAssoc
)
251 HWND hWndT
=m_hWndAssociate
;
253 m_hWndAssociate
=hWndAssoc
;
258 HWND
CHatchWin::HwndAssociateGet(void)
260 return m_hWndAssociate
;
265 * CHatchWin::RectsSet
268 * Changes the size and position of the hatch window and the child
269 * window within it using a position rectangle for the child and
270 * a clipping rectangle for the hatch window and child. The hatch
271 * window occupies prcPos expanded by the hatch border and clipped
272 * by prcClip. The child window is fit to prcPos to give the
273 * proper scaling, but it clipped to the hatch window which
274 * therefore clips it to prcClip without affecting the scaling.
277 * prcPos LPRECT providing the position rectangle.
278 * prcClip LPRECT providing the clipping rectangle.
284 void CHatchWin::RectsSet(LPRECT prcPos
, LPRECT prcClip
)
292 //Calculate the rectangle for the hatch window, then clip it.
294 InflateRect(&rcPos
, m_dBorder
, m_dBorder
);
295 IntersectRect(&rc
, &rcPos
, prcClip
);
297 SetWindowPos(m_hWnd
, NULL
, rc
.left
, rc
.top
, rc
.right
-rc
.left
298 , rc
.bottom
-rc
.top
, SWP_NOZORDER
| SWP_NOACTIVATE
);
301 * Set the rectangle of the child window to be at m_dBorder
302 * from the top and left but with the same size as prcPos
303 * contains. The hatch window will clip it.
305 // SetWindowPos(m_hWndKid, NULL, rcPos.left-rc.left+m_dBorder
306 // , rcPos.top-rc.top+m_dBorder, prcPos->right-prcPos->left
307 // , prcPos->bottom-prcPos->top, SWP_NOZORDER | SWP_NOACTIVATE);
310 GetClientRect(m_hWnd
,&newRC
);
311 m_aTracker
= Tracker(
313 Tracker::hatchInside
|
314 Tracker::hatchedBorder
|
315 Tracker::resizeInside
324 * CHatchWin::ChildSet
327 * Assigns a child window to this hatch window.
330 * hWndKid HWND of the child window.
336 void CHatchWin::ChildSet(HWND hWndKid
)
342 SetParent(hWndKid
, m_hWnd
);
344 //Insure this is visible when the hatch window becomes visible.
345 ShowWindow(hWndKid
, SW_SHOW
);
354 * CHatchWin::ShowHatch
357 * Turns hatching on and off; turning the hatching off changes
358 * the size of the window to be exactly that of the child, leaving
359 * everything else the same. The result is that we don't have
360 * to turn off drawing because our own WM_PAINT will never be
364 * fHatch BOOL indicating to show (TRUE) or hide (FALSE)
371 void CHatchWin::ShowHatch(BOOL fHatch
)
374 * All we have to do is set the border to zero and
375 * call SetRects again with the last rectangles the
378 m_dBorder
=fHatch
? m_dBorderOrg
: 0;
379 RectsSet(&m_rcPos
, &m_rcClip
);
389 * Standard window procedure for the Hatch Window
392 LRESULT APIENTRY
winwrap::HatchWndProc(
394 , WPARAM wParam
, LPARAM lParam
)
400 phw
=(PCHatchWin
)GetWindowLong(hWnd
, HWWL_STRUCTURE
);
406 phw
=(PCHatchWin
)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
407 SetWindowLong(hWnd
, HWWL_STRUCTURE
, (LONG
)phw
);
410 hDC
=BeginPaint(hWnd
,&ps
);
411 //Always draw the hatching.
412 phw
->m_aTracker
.Draw(hDC
);
416 GetCursorPos(&ptMouse
);
417 ScreenToClient(hWnd
,&ptMouse
);
419 // track in case we have to
420 if(phw
->m_aTracker
.Track(hWnd
,ptMouse
,FALSE
,GetParent(hWnd
)))
422 RECT aRect
= phw
->m_aTracker
.m_rect
;
423 TransformRect(&aRect
,hWnd
,GetParent(hWnd
));
424 phw
->m_pDocHolder
->OnPosRectChanged(&aRect
);
429 GetCursorPos(&ptMouse
);
430 ScreenToClient(hWnd
,&ptMouse
);
431 phw
->m_aTracker
.SetCursor(hWnd
,HTCLIENT
);
434 //We need this since the container will SetFocus to us.
435 if (NULL
!=phw
->m_hWndKid
)
436 SetFocus(phw
->m_hWndKid
);
439 case WM_LBUTTONDBLCLK
:
441 * If the double click was within m_dBorder of an
442 * edge, send the HWN_BORDERDOUBLECLICKED notification.
444 * Because we're always sized just larger than our child
445 * window by the border width, we can only *get* this
446 * message when the mouse is on the border. So we can
447 * just send the notification.
449 if (NULL
!=phw
->m_hWndAssociate
)
451 SendCommand(phw
->m_hWndAssociate
, phw
->m_uID
452 , HWN_BORDERDOUBLECLICKED
, hWnd
);
457 return DefWindowProc(hWnd
, iMsg
, wParam
, lParam
);
463 // Fix strange warnings about some
464 // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions.
465 // warning C4505: 'xxx' : unreferenced local function has been removed
466 #if defined(_MSC_VER)
467 #pragma warning(disable: 4505)
470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */