Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / embedserv / source / embed / syswinwrapper.cxx
blobe079d6c73344661b18f26814406af5f5c259f09b
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")
45 typedef CHatchWin *PCHatchWin;
48 void DrawShading(LPRECT prc, HDC hDC, UINT cWidth);
51 winwrap::CWindow::CWindow(HINSTANCE hInst)
53 m_hInst=hInst;
54 m_hWnd=NULL;
55 return;
58 winwrap::CWindow::~CWindow()
60 if (IsWindow(m_hWnd))
61 DestroyWindow(m_hWnd);
63 return;
68 * CWindow::Window
70 * Purpose:
71 * Returns the window handle associated with this object.
73 * Return Value:
74 * HWND Window handle for this object
77 HWND winwrap::CWindow::Window()
79 return m_hWnd;
84 * CWindow::Instance
86 * Purpose:
87 * Returns the instance handle associated with this object.
89 * Return Value:
90 * HINSTANCE Instance handle of the module stored here.
93 HINSTANCE winwrap::CWindow::Instance()
95 return m_hInst;
99 * HatchWindowRegister
101 * Purpose:
102 * Registers the hatch window class for use with CHatchWin.
104 * Parameters:
105 * hInst HINSTANCE under which to register.
107 * Return Value:
108 * BOOL TRUE if successful, FALSE otherwise.
111 BOOL winwrap::HatchWindowRegister(HINSTANCE hInst)
113 WNDCLASS wc;
115 //Must have CS_DBLCLKS for border!
116 wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
117 wc.hInstance = hInst;
118 wc.cbClsExtra = 0;
119 wc.lpfnWndProc = HatchWndProc;
120 wc.cbWndExtra = CBHATCHWNDEXTRA;
121 wc.hIcon = NULL;
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)
140 : CWindow(hInst),
141 m_aTracker()
143 m_hWnd=NULL;
144 m_hWndKid=NULL;
145 m_hWndAssociate=NULL;
146 m_uID=0;
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;
157 return;
161 CHatchWin::~CHatchWin()
164 * Chances are this was already destroyed when a document
165 * was destroyed.
167 if (NULL!=m_hWnd && IsWindow(m_hWnd))
168 DestroyWindow(m_hWnd);
170 return;
175 * CHatchWin::Init
177 * Purpose:
178 * Instantiates a hatch window within a given parent with a
179 * default rectangle. This is not initially visible.
181 * Parameters:
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.
187 * Return Value:
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);
200 m_uID=uID;
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
217 * Purpose:
218 * Sets (Set) or retrieves (Get) the associate window of the
219 * hatch window.
221 * Parameters: (Set only)
222 * hWndAssoc HWND to set as the associate.
224 * Return Value:
225 * HWND Previous (Set) or current (Get) associate
226 * window.
229 HWND CHatchWin::HwndAssociateSet(HWND hWndAssoc)
231 HWND hWndT=m_hWndAssociate;
233 m_hWndAssociate=hWndAssoc;
234 return hWndT;
238 HWND CHatchWin::HwndAssociateGet()
240 return m_hWndAssociate;
245 * CHatchWin::RectsSet
247 * Purpose:
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.
256 * Parameters:
257 * prcPos LPRECT providing the position rectangle.
258 * prcClip LPRECT providing the clipping rectangle.
260 * Return Value:
261 * None
264 void CHatchWin::RectsSet(LPRECT prcPos, LPRECT prcClip)
266 RECT rc;
267 RECT rcPos;
269 m_rcPos=*prcPos;
270 m_rcClip=*prcClip;
272 //Calculate the rectangle for the hatch window, then clip it.
273 rcPos=*prcPos;
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);
289 RECT newRC;
290 GetClientRect(m_hWnd,&newRC);
291 m_aTracker = Tracker(
292 &newRC,
293 Tracker::hatchInside |
294 Tracker::hatchedBorder |
295 Tracker::resizeInside
298 return;
303 * CHatchWin::ChildSet
305 * Purpose:
306 * Assigns a child window to this hatch window.
308 * Parameters:
309 * hWndKid HWND of the child window.
311 * Return Value:
312 * None
315 void CHatchWin::ChildSet(HWND hWndKid)
317 m_hWndKid=hWndKid;
319 if (NULL!=hWndKid)
321 SetParent(hWndKid, m_hWnd);
323 //Insure this is visible when the hatch window becomes visible.
324 ShowWindow(hWndKid, SW_SHOW);
327 return;
332 * CHatchWin::ShowHatch
334 * Purpose:
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
339 * called.
341 * Parameters:
342 * fHatch BOOL indicating to show (TRUE) or hide (FALSE)
343 the hatching.
345 * Return Value:
346 * None
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
354 * child sent to us.
356 m_dBorder=fHatch ? m_dBorderOrg : 0;
357 RectsSet(&m_rcPos, &m_rcClip);
358 return;
363 * HatchWndProc
365 * Purpose:
366 * Standard window procedure for the Hatch Window
369 LRESULT APIENTRY winwrap::HatchWndProc(
370 HWND hWnd, UINT iMsg
371 , WPARAM wParam, LPARAM lParam)
373 PCHatchWin phw;
374 HDC hDC;
375 PAINTSTRUCT ps;
377 phw=(PCHatchWin)GetWindowLongPtr(hWnd, HWWL_STRUCTURE);
378 POINT ptMouse;
380 switch (iMsg)
382 case WM_CREATE:
383 phw=(PCHatchWin)((LPCREATESTRUCT)lParam)->lpCreateParams;
384 SetWindowLongPtr(hWnd, HWWL_STRUCTURE, (LONG_PTR)phw);
385 break;
386 case WM_PAINT:
387 hDC=BeginPaint(hWnd,&ps);
388 //Always draw the hatching.
389 phw->m_aTracker.Draw(hDC);
390 EndPaint(hWnd,&ps);
391 break;
392 case WM_LBUTTONDOWN:
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);
403 break;
404 case WM_LBUTTONUP:
405 case WM_MOUSEMOVE:
406 GetCursorPos(&ptMouse);
407 ScreenToClient(hWnd,&ptMouse);
408 phw->m_aTracker.SetCursor(hWnd,HTCLIENT);
409 break;
410 case WM_SETFOCUS:
411 //We need this since the container will SetFocus to us.
412 if (NULL!=phw->m_hWndKid)
413 SetFocus(phw->m_hWndKid);
415 break;
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)
428 SendMessage(
429 phw->m_hWndAssociate, WM_COMMAND,
430 MAKEWPARAM(phw->m_uID, HWN_BORDERDOUBLECLICKED),
431 (LPARAM) hWnd);
434 break;
435 default:
436 return DefWindowProc(hWnd, iMsg, wParam, lParam);
439 return 0L;
442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */