update credits
[LibreOffice.git] / embedserv / source / embed / syswinwrapper.cxx
blob0621eb54ebb4f85487292db3f21da1cd228b54b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifdef _MSC_VER
20 #pragma warning(disable : 4917 4555)
21 #endif
23 #include "docholder.hxx"
24 #include "syswinwrapper.hxx"
27 * CWindow::CWindow
28 * CWindow::~CWindow
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) \
46 , (LPARAM)hControl)
49 typedef CHatchWin *PCHatchWin;
52 void DrawShading(LPRECT prc, HDC hDC, UINT cWidth);
56 winwrap::CWindow::CWindow(HINSTANCE hInst)
58 m_hInst=hInst;
59 m_hWnd=NULL;
60 return;
63 winwrap::CWindow::~CWindow(void)
65 if (IsWindow(m_hWnd))
66 DestroyWindow(m_hWnd);
68 return;
74 * CWindow::Window
76 * Purpose:
77 * Returns the window handle associated with this object.
79 * Return Value:
80 * HWND Window handle for this object
83 HWND winwrap::CWindow::Window(void)
85 return m_hWnd;
91 * CWindow::Instance
93 * Purpose:
94 * Returns the instance handle associated with this object.
96 * Return Value:
97 * HINSTANCE Instance handle of the module stored here.
100 HINSTANCE winwrap::CWindow::Instance(void)
102 return m_hInst;
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
118 * Purpose:
119 * Registers the hatch window class for use with CHatchWin.
121 * Parameters:
122 * hInst HINSTANCE under which to register.
124 * Return Value:
125 * BOOL TRUE if successful, FALSE otherwise.
128 BOOL winwrap::HatchWindowRegister(HINSTANCE hInst)
130 WNDCLASS wc;
132 //Must have CS_DBLCLKS for border!
133 wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
134 wc.hInstance = hInst;
135 wc.cbClsExtra = 0;
136 wc.lpfnWndProc = HatchWndProc;
137 wc.cbWndExtra = CBHATCHWNDEXTRA;
138 wc.hIcon = NULL;
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)
159 : CWindow(hInst),
160 m_aTracker()
162 m_hWnd=NULL;
163 m_hWndKid=NULL;
164 m_hWndAssociate=NULL;
165 m_uID=0;
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;
176 return;
180 CHatchWin::~CHatchWin(void)
183 * Chances are this was already destroyed when a document
184 * was destroyed.
186 if (NULL!=m_hWnd && IsWindow(m_hWnd))
187 DestroyWindow(m_hWnd);
189 return;
195 * CHatchWin::Init
197 * Purpose:
198 * Instantiates a hatch window within a given parent with a
199 * default rectangle. This is not initially visible.
201 * Parameters:
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.
207 * Return Value:
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
218 , m_hInst, this);
220 m_uID=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
237 * Purpose:
238 * Sets (Set) or retrieves (Get) the associate window of the
239 * hatch window.
241 * Parameters: (Set only)
242 * hWndAssoc HWND to set as the associate.
244 * Return Value:
245 * HWND Previous (Set) or current (Get) associate
246 * window.
249 HWND CHatchWin::HwndAssociateSet(HWND hWndAssoc)
251 HWND hWndT=m_hWndAssociate;
253 m_hWndAssociate=hWndAssoc;
254 return hWndT;
258 HWND CHatchWin::HwndAssociateGet(void)
260 return m_hWndAssociate;
265 * CHatchWin::RectsSet
267 * Purpose:
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.
276 * Parameters:
277 * prcPos LPRECT providing the position rectangle.
278 * prcClip LPRECT providing the clipping rectangle.
280 * Return Value:
281 * None
284 void CHatchWin::RectsSet(LPRECT prcPos, LPRECT prcClip)
286 RECT rc;
287 RECT rcPos;
289 m_rcPos=*prcPos;
290 m_rcClip=*prcClip;
292 //Calculate the rectangle for the hatch window, then clip it.
293 rcPos=*prcPos;
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);
309 RECT newRC;
310 GetClientRect(m_hWnd,&newRC);
311 m_aTracker = Tracker(
312 &newRC,
313 Tracker::hatchInside |
314 Tracker::hatchedBorder |
315 Tracker::resizeInside
318 return;
324 * CHatchWin::ChildSet
326 * Purpose:
327 * Assigns a child window to this hatch window.
329 * Parameters:
330 * hWndKid HWND of the child window.
332 * Return Value:
333 * None
336 void CHatchWin::ChildSet(HWND hWndKid)
338 m_hWndKid=hWndKid;
340 if (NULL!=hWndKid)
342 SetParent(hWndKid, m_hWnd);
344 //Insure this is visible when the hatch window becomes visible.
345 ShowWindow(hWndKid, SW_SHOW);
348 return;
354 * CHatchWin::ShowHatch
356 * Purpose:
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
361 * called.
363 * Parameters:
364 * fHatch BOOL indicating to show (TRUE) or hide (FALSE)
365 the hatching.
367 * Return Value:
368 * None
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
376 * child sent to us.
378 m_dBorder=fHatch ? m_dBorderOrg : 0;
379 RectsSet(&m_rcPos, &m_rcClip);
380 return;
386 * HatchWndProc
388 * Purpose:
389 * Standard window procedure for the Hatch Window
392 LRESULT APIENTRY winwrap::HatchWndProc(
393 HWND hWnd, UINT iMsg
394 , WPARAM wParam, LPARAM lParam)
396 PCHatchWin phw;
397 HDC hDC;
398 PAINTSTRUCT ps;
400 phw=(PCHatchWin)GetWindowLong(hWnd, HWWL_STRUCTURE);
401 POINT ptMouse;
403 switch (iMsg)
405 case WM_CREATE:
406 phw=(PCHatchWin)((LPCREATESTRUCT)lParam)->lpCreateParams;
407 SetWindowLong(hWnd, HWWL_STRUCTURE, (LONG)phw);
408 break;
409 case WM_PAINT:
410 hDC=BeginPaint(hWnd,&ps);
411 //Always draw the hatching.
412 phw->m_aTracker.Draw(hDC);
413 EndPaint(hWnd,&ps);
414 break;
415 case WM_LBUTTONDOWN:
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);
426 break;
427 case WM_LBUTTONUP:
428 case WM_MOUSEMOVE:
429 GetCursorPos(&ptMouse);
430 ScreenToClient(hWnd,&ptMouse);
431 phw->m_aTracker.SetCursor(hWnd,HTCLIENT);
432 break;
433 case WM_SETFOCUS:
434 //We need this since the container will SetFocus to us.
435 if (NULL!=phw->m_hWndKid)
436 SetFocus(phw->m_hWndKid);
438 break;
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);
455 break;
456 default:
457 return DefWindowProc(hWnd, iMsg, wParam, lParam);
460 return 0L;
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)
468 #endif
470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */