merge the formfield patch from ooo-build
[ooovba.git] / embedserv / source / embed / syswinwrapper.cxx
blobb80be70df67c0cbb942063ff979719660fc6066b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: syswinwrapper.cxx,v $
10 * $Revision: 1.6 $
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)
32 #endif
34 #include "docholder.hxx"
35 #include "syswinwrapper.hxx"
38 * CWindow::CWindow
39 * CWindow::~CWindow
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) \
57 , (LPARAM)hControl)
60 typedef CHatchWin *PCHatchWin;
63 void DrawShading(LPRECT prc, HDC hDC, UINT cWidth);
67 winwrap::CWindow::CWindow(HINSTANCE hInst)
69 m_hInst=hInst;
70 m_hWnd=NULL;
71 return;
74 winwrap::CWindow::~CWindow(void)
76 if (IsWindow(m_hWnd))
77 DestroyWindow(m_hWnd);
79 return;
85 * CWindow::Window
87 * Purpose:
88 * Returns the window handle associated with this object.
90 * Return Value:
91 * HWND Window handle for this object
94 HWND winwrap::CWindow::Window(void)
96 return m_hWnd;
102 * CWindow::Instance
104 * Purpose:
105 * Returns the instance handle associated with this object.
107 * Return Value:
108 * HINSTANCE Instance handle of the module stored here.
111 HINSTANCE winwrap::CWindow::Instance(void)
113 return m_hInst;
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
129 * Purpose:
130 * Registers the hatch window class for use with CHatchWin.
132 * Parameters:
133 * hInst HINSTANCE under which to register.
135 * Return Value:
136 * BOOL TRUE if successful, FALSE otherwise.
139 BOOL winwrap::HatchWindowRegister(HINSTANCE hInst)
141 WNDCLASS wc;
143 //Must have CS_DBLCLKS for border!
144 wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
145 wc.hInstance = hInst;
146 wc.cbClsExtra = 0;
147 wc.lpfnWndProc = HatchWndProc;
148 wc.cbWndExtra = CBHATCHWNDEXTRA;
149 wc.hIcon = NULL;
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);
156 return FALSE;
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)
171 : CWindow(hInst),
172 m_aTracker()
174 m_hWnd=NULL;
175 m_hWndKid=NULL;
176 m_hWndAssociate=NULL;
177 m_uID=0;
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;
188 return;
192 CHatchWin::~CHatchWin(void)
195 * Chances are this was already destroyed when a document
196 * was destroyed.
198 if (NULL!=m_hWnd && IsWindow(m_hWnd))
199 DestroyWindow(m_hWnd);
201 return;
207 * CHatchWin::Init
209 * Purpose:
210 * Instantiates a hatch window within a given parent with a
211 * default rectangle. This is not initially visible.
213 * Parameters:
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.
219 * Return Value:
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
230 , m_hInst, this);
232 m_uID=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
249 * Purpose:
250 * Sets (Set) or retrieves (Get) the associate window of the
251 * hatch window.
253 * Parameters: (Set only)
254 * hWndAssoc HWND to set as the associate.
256 * Return Value:
257 * HWND Previous (Set) or current (Get) associate
258 * window.
261 HWND CHatchWin::HwndAssociateSet(HWND hWndAssoc)
263 HWND hWndT=m_hWndAssociate;
265 m_hWndAssociate=hWndAssoc;
266 return hWndT;
270 HWND CHatchWin::HwndAssociateGet(void)
272 return m_hWndAssociate;
277 * CHatchWin::RectsSet
279 * Purpose:
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.
288 * Parameters:
289 * prcPos LPRECT providing the position rectangle.
290 * prcClip LPRECT providing the clipping rectangle.
292 * Return Value:
293 * None
296 void CHatchWin::RectsSet(LPRECT prcPos, LPRECT prcClip)
298 RECT rc;
299 RECT rcPos;
301 m_rcPos=*prcPos;
302 m_rcClip=*prcClip;
304 //Calculate the rectangle for the hatch window, then clip it.
305 rcPos=*prcPos;
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);
321 RECT newRC;
322 GetClientRect(m_hWnd,&newRC);
323 m_aTracker = Tracker(
324 &newRC,
325 Tracker::hatchInside |
326 Tracker::hatchedBorder |
327 Tracker::resizeInside
330 return;
336 * CHatchWin::ChildSet
338 * Purpose:
339 * Assigns a child window to this hatch window.
341 * Parameters:
342 * hWndKid HWND of the child window.
344 * Return Value:
345 * None
348 void CHatchWin::ChildSet(HWND hWndKid)
350 m_hWndKid=hWndKid;
352 if (NULL!=hWndKid)
354 SetParent(hWndKid, m_hWnd);
356 //Insure this is visible when the hatch window becomes visible.
357 ShowWindow(hWndKid, SW_SHOW);
360 return;
366 * CHatchWin::ShowHatch
368 * Purpose:
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
373 * called.
375 * Parameters:
376 * fHatch BOOL indicating to show (TRUE) or hide (FALSE)
377 the hatching.
379 * Return Value:
380 * None
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
388 * child sent to us.
390 m_dBorder=fHatch ? m_dBorderOrg : 0;
391 RectsSet(&m_rcPos, &m_rcClip);
392 return;
398 * HatchWndProc
400 * Purpose:
401 * Standard window procedure for the Hatch Window
404 LRESULT APIENTRY winwrap::HatchWndProc(
405 HWND hWnd, UINT iMsg
406 , WPARAM wParam, LPARAM lParam)
408 PCHatchWin phw;
409 HDC hDC;
410 PAINTSTRUCT ps;
412 phw=(PCHatchWin)GetWindowLong(hWnd, HWWL_STRUCTURE);
413 POINT ptMouse;
415 switch (iMsg)
417 case WM_CREATE:
418 phw=(PCHatchWin)((LPCREATESTRUCT)lParam)->lpCreateParams;
419 SetWindowLong(hWnd, HWWL_STRUCTURE, (LONG)phw);
420 break;
421 case WM_PAINT:
422 hDC=BeginPaint(hWnd,&ps);
423 //Always draw the hatching.
424 phw->m_aTracker.Draw(hDC);
425 EndPaint(hWnd,&ps);
426 break;
427 case WM_LBUTTONDOWN:
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);
438 break;
439 case WM_LBUTTONUP:
440 case WM_MOUSEMOVE:
441 GetCursorPos(&ptMouse);
442 ScreenToClient(hWnd,&ptMouse);
443 phw->m_aTracker.SetCursor(hWnd,HTCLIENT);
444 break;
445 case WM_SETFOCUS:
446 //We need this since the container will SetFocus to us.
447 if (NULL!=phw->m_hWndKid)
448 SetFocus(phw->m_hWndKid);
450 break;
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);
467 break;
468 default:
469 return DefWindowProc(hWnd, iMsg, wParam, lParam);
472 return 0L;
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)
480 #endif