1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: syswinwrapper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #if defined(_MSC_VER) && (_MSC_VER > 1310)
31 #pragma warning(disable : 4917 4555)
34 #include "docholder.hxx"
35 #include "syswinwrapper.hxx"
41 * Constructor Parameters:
42 * hInst HINSTANCE of the task owning us.
46 using namespace winwrap
;
49 #define HWWL_STRUCTURE 0
51 //Notification codes for WM_COMMAND messages
52 #define HWN_BORDERDOUBLECLICKED 1
53 #define CBHATCHWNDEXTRA (sizeof(LONG))
54 #define SZCLASSHATCHWIN TEXT("hatchwin")
55 #define SendCommand(hWnd, wID, wCode, hControl) \
56 SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(wID, wCode) \
60 typedef CHatchWin
*PCHatchWin
;
63 void DrawShading(LPRECT prc
, HDC hDC
, UINT cWidth
);
67 winwrap::CWindow::CWindow(HINSTANCE hInst
)
74 winwrap::CWindow::~CWindow(void)
77 DestroyWindow(m_hWnd
);
88 * Returns the window handle associated with this object.
91 * HWND Window handle for this object
94 HWND
winwrap::CWindow::Window(void)
105 * Returns the instance handle associated with this object.
108 * HINSTANCE Instance handle of the module stored here.
111 HINSTANCE
winwrap::CWindow::Instance(void)
120 //Hatch pattern brush bits
121 static WORD g_wHatchBmp
[]={0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};
123 // void DrawShading(LPRECT, HDC, UINT);
127 * HatchWindowRegister
130 * Registers the hatch window class for use with CHatchWin.
133 * hInst HINSTANCE under which to register.
136 * BOOL TRUE if successful, FALSE otherwise.
139 BOOL
winwrap::HatchWindowRegister(HINSTANCE hInst
)
143 //Must have CS_DBLCLKS for border!
144 wc
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
145 wc
.hInstance
= hInst
;
147 wc
.lpfnWndProc
= HatchWndProc
;
148 wc
.cbWndExtra
= CBHATCHWNDEXTRA
;
150 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
151 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
152 wc
.lpszMenuName
= NULL
;
153 wc
.lpszClassName
= SZCLASSHATCHWIN
;
155 return RegisterClass(&wc
);
163 * CHatchWin:CHatchWin
164 * CHatchWin::~CHatchWin
166 * Constructor Parameters:
167 * hInst HINSTANCE of the application we're in.
170 CHatchWin::CHatchWin(HINSTANCE hInst
,const DocumentHolder
* pDocHolder
)
176 m_hWndAssociate
=NULL
;
179 m_dBorderOrg
=GetProfileInt(TEXT("windows")
180 , TEXT("OleInPlaceBorderWidth")
181 , HATCHWIN_BORDERWIDTHDEFAULT
);
183 m_dBorder
=m_dBorderOrg
;
184 SetRect(&m_rcPos
, 0, 0, 0, 0);
185 SetRect(&m_rcClip
, 0, 0, 0, 0);
187 m_pDocHolder
= pDocHolder
;
192 CHatchWin::~CHatchWin(void)
195 * Chances are this was already destroyed when a document
198 if (NULL
!=m_hWnd
&& IsWindow(m_hWnd
))
199 DestroyWindow(m_hWnd
);
210 * Instantiates a hatch window within a given parent with a
211 * default rectangle. This is not initially visible.
214 * hWndParent HWND of the parent of this window
215 * uID UINT identifier for this window (send in
216 * notifications to associate window).
217 * hWndAssoc HWND of the initial associate.
220 * BOOL TRUE if the function succeeded, FALSE otherwise.
223 BOOL
CHatchWin::Init(HWND hWndParent
, UINT uID
, HWND hWndAssoc
)
225 m_hWndParent
= hWndParent
;
226 m_hWnd
=CreateWindowEx(
227 WS_EX_NOPARENTNOTIFY
, SZCLASSHATCHWIN
228 , SZCLASSHATCHWIN
, WS_CHILD
| WS_CLIPSIBLINGS
229 | WS_CLIPCHILDREN
, 0, 0, 100, 100, hWndParent
, (HMENU
)uID
233 m_hWndAssociate
=hWndAssoc
;
235 return (NULL
!=m_hWnd
);
239 void CHatchWin::SetTrans()
241 HRGN hrgn
= CreateRectRgn(0,0,0,0);
242 SetWindowRgn(m_hWnd
,hrgn
,true);
246 * CHatchWin::HwndAssociateSet
247 * CHatchWin::HwndAssociateGet
250 * Sets (Set) or retrieves (Get) the associate window of the
253 * Parameters: (Set only)
254 * hWndAssoc HWND to set as the associate.
257 * HWND Previous (Set) or current (Get) associate
261 HWND
CHatchWin::HwndAssociateSet(HWND hWndAssoc
)
263 HWND hWndT
=m_hWndAssociate
;
265 m_hWndAssociate
=hWndAssoc
;
270 HWND
CHatchWin::HwndAssociateGet(void)
272 return m_hWndAssociate
;
277 * CHatchWin::RectsSet
280 * Changes the size and position of the hatch window and the child
281 * window within it using a position rectangle for the child and
282 * a clipping rectangle for the hatch window and child. The hatch
283 * window occupies prcPos expanded by the hatch border and clipped
284 * by prcClip. The child window is fit to prcPos to give the
285 * proper scaling, but it clipped to the hatch window which
286 * therefore clips it to prcClip without affecting the scaling.
289 * prcPos LPRECT providing the position rectangle.
290 * prcClip LPRECT providing the clipping rectangle.
296 void CHatchWin::RectsSet(LPRECT prcPos
, LPRECT prcClip
)
304 //Calculate the rectangle for the hatch window, then clip it.
306 InflateRect(&rcPos
, m_dBorder
, m_dBorder
);
307 IntersectRect(&rc
, &rcPos
, prcClip
);
309 SetWindowPos(m_hWnd
, NULL
, rc
.left
, rc
.top
, rc
.right
-rc
.left
310 , rc
.bottom
-rc
.top
, SWP_NOZORDER
| SWP_NOACTIVATE
);
313 * Set the rectangle of the child window to be at m_dBorder
314 * from the top and left but with the same size as prcPos
315 * contains. The hatch window will clip it.
317 // SetWindowPos(m_hWndKid, NULL, rcPos.left-rc.left+m_dBorder
318 // , rcPos.top-rc.top+m_dBorder, prcPos->right-prcPos->left
319 // , prcPos->bottom-prcPos->top, SWP_NOZORDER | SWP_NOACTIVATE);
322 GetClientRect(m_hWnd
,&newRC
);
323 m_aTracker
= Tracker(
325 Tracker::hatchInside
|
326 Tracker::hatchedBorder
|
327 Tracker::resizeInside
336 * CHatchWin::ChildSet
339 * Assigns a child window to this hatch window.
342 * hWndKid HWND of the child window.
348 void CHatchWin::ChildSet(HWND hWndKid
)
354 SetParent(hWndKid
, m_hWnd
);
356 //Insure this is visible when the hatch window becomes visible.
357 ShowWindow(hWndKid
, SW_SHOW
);
366 * CHatchWin::ShowHatch
369 * Turns hatching on and off; turning the hatching off changes
370 * the size of the window to be exactly that of the child, leaving
371 * everything else the same. The result is that we don't have
372 * to turn off drawing because our own WM_PAINT will never be
376 * fHatch BOOL indicating to show (TRUE) or hide (FALSE)
383 void CHatchWin::ShowHatch(BOOL fHatch
)
386 * All we have to do is set the border to zero and
387 * call SetRects again with the last rectangles the
390 m_dBorder
=fHatch
? m_dBorderOrg
: 0;
391 RectsSet(&m_rcPos
, &m_rcClip
);
401 * Standard window procedure for the Hatch Window
404 LRESULT APIENTRY
winwrap::HatchWndProc(
406 , WPARAM wParam
, LPARAM lParam
)
412 phw
=(PCHatchWin
)GetWindowLong(hWnd
, HWWL_STRUCTURE
);
418 phw
=(PCHatchWin
)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
419 SetWindowLong(hWnd
, HWWL_STRUCTURE
, (LONG
)phw
);
422 hDC
=BeginPaint(hWnd
,&ps
);
423 //Always draw the hatching.
424 phw
->m_aTracker
.Draw(hDC
);
428 GetCursorPos(&ptMouse
);
429 ScreenToClient(hWnd
,&ptMouse
);
431 // track in case we have to
432 if(phw
->m_aTracker
.Track(hWnd
,ptMouse
,FALSE
,GetParent(hWnd
)))
434 RECT aRect
= phw
->m_aTracker
.m_rect
;
435 TransformRect(&aRect
,hWnd
,GetParent(hWnd
));
436 phw
->m_pDocHolder
->OnPosRectChanged(&aRect
);
441 GetCursorPos(&ptMouse
);
442 ScreenToClient(hWnd
,&ptMouse
);
443 phw
->m_aTracker
.SetCursor(hWnd
,HTCLIENT
);
446 //We need this since the container will SetFocus to us.
447 if (NULL
!=phw
->m_hWndKid
)
448 SetFocus(phw
->m_hWndKid
);
451 case WM_LBUTTONDBLCLK
:
453 * If the double click was within m_dBorder of an
454 * edge, send the HWN_BORDERDOUBLECLICKED notification.
456 * Because we're always sized just larger than our child
457 * window by the border width, we can only *get* this
458 * message when the mouse is on the border. So we can
459 * just send the notification.
461 if (NULL
!=phw
->m_hWndAssociate
)
463 SendCommand(phw
->m_hWndAssociate
, phw
->m_uID
464 , HWN_BORDERDOUBLECLICKED
, hWnd
);
469 return DefWindowProc(hWnd
, iMsg
, wParam
, lParam
);
475 // Fix strange warnings about some
476 // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions.
477 // warning C4505: 'xxx' : unreferenced local function has been removed
478 #if defined(_MSC_VER)
479 #pragma warning(disable: 4505)