1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <string.h>
#include <svsys.h>
#include <vcl/svapp.hxx>
#include <sal/log.hxx>
#include <win/wincomp.hxx>
#include <win/saldata.hxx>
#include <win/salinst.h>
#include <win/salframe.h>
#include <win/salobj.h>
#include <comphelper/windowserrorstring.hxx>
static bool ImplIsSysWindowOrChild( HWND hWndParent, HWND hWndChild )
{
if ( hWndParent == hWndChild )
return true;
HWND hTempWnd = ::GetParent( hWndChild );
while ( hTempWnd )
{
// stop searching if not a child window
if ( !(GetWindowStyle( hTempWnd ) & WS_CHILD) )
return false;
if ( hTempWnd == hWndParent )
return true;
hTempWnd = ::GetParent( hTempWnd );
}
return false;
}
WinSalObject* ImplFindSalObject( HWND hWndChild )
{
SalData* pSalData = GetSalData();
WinSalObject* pObject = pSalData->mpFirstObject;
while ( pObject )
{
if ( ImplIsSysWindowOrChild( pObject->mhWndChild, hWndChild ) )
return pObject;
pObject = pObject->mpNextObject;
}
return nullptr;
}
static WinSalFrame* ImplFindSalObjectFrame( HWND hWnd )
{
WinSalFrame* pFrame = nullptr;
WinSalObject* pObject = ImplFindSalObject( hWnd );
if ( pObject )
{
// find matching frame
HWND hWnd2 = ::GetParent( pObject->mhWnd );
pFrame = GetSalData()->mpFirstFrame;
while ( pFrame )
{
if ( pFrame->mhWnd == hWnd2 )
break;
pFrame = pFrame->mpNextFrame;
}
}
return pFrame;
}
static LRESULT CALLBACK SalSysMsgProc( int nCode, WPARAM wParam, LPARAM lParam )
{
// Used for Unicode and none Unicode
SalData* pSalData = GetSalData();
if ( (nCode >= 0) && lParam )
{
CWPSTRUCT* pData = reinterpret_cast<CWPSTRUCT*>(lParam);
if ( (pData->message != WM_KEYDOWN) &&
(pData->message != WM_KEYUP) )
pSalData->mnSalObjWantKeyEvt = 0;
// check if we need to process data for a SalObject-window
WinSalObject* pObject;
if ( pData->message == WM_SETFOCUS )
{
pObject = ImplFindSalObject( pData->hwnd );
if ( pObject )
{
pObject->mhLastFocusWnd = pData->hwnd;
if ( ImplSalYieldMutexTryToAcquire() )
{
pObject->CallCallback( SalObjEvent::GetFocus );
ImplSalYieldMutexRelease();
}
else
{
bool const ret = PostMessageW(pObject->mhWnd, SALOBJ_MSG_POSTFOCUS, 0, 0);
SAL_WARN_IF(!ret, "vcl", "ERROR: PostMessage() failed!");
}
}
}
else if ( pData->message == WM_KILLFOCUS )
{
pObject = ImplFindSalObject( pData->hwnd );
if ( pObject && !ImplFindSalObject( reinterpret_cast<HWND>(pData->wParam) ) )
{
// only call LoseFocus, if truly no child window gets the focus
if ( !pData->wParam || !ImplFindSalObject( reinterpret_cast<HWND>(pData->wParam) ) )
{
if ( ImplSalYieldMutexTryToAcquire() )
{
pObject->CallCallback( SalObjEvent::LoseFocus );
ImplSalYieldMutexRelease();
}
else
{
bool const ret = PostMessageW(pObject->mhWnd, SALOBJ_MSG_POSTFOCUS, 0, 0);
SAL_WARN_IF(!ret, "vcl", "ERROR: PostMessage() failed!");
}
}
else
pObject->mhLastFocusWnd = reinterpret_cast<HWND>(pData->wParam);
}
}
}
return CallNextHookEx( pSalData->mhSalObjMsgHook, nCode, wParam, lParam );
}
bool ImplSalPreDispatchMsg( const MSG* pMsg )
{
// Used for Unicode and none Unicode
SalData* pSalData = GetSalData();
WinSalObject* pObject;
if ( (pMsg->message == WM_LBUTTONDOWN) ||
(pMsg->message == WM_RBUTTONDOWN) ||
(pMsg->message == WM_MBUTTONDOWN) )
{
ImplSalYieldMutexAcquireWithWait();
pObject = ImplFindSalObject( pMsg->hwnd );
if ( pObject && !pObject->IsMouseTransparent() )
{
bool const ret = PostMessageW(pObject->mhWnd, SALOBJ_MSG_TOTOP, 0, 0);
SAL_WARN_IF(!ret, "vcl", "ERROR: PostMessage() failed!");
}
ImplSalYieldMutexRelease();
}
if ( (pMsg->message == WM_KEYDOWN) ||
(pMsg->message == WM_KEYUP) )
{
// process KeyEvents even if the control does not process them itself
// SysKeys are processed as WM_SYSCOMMAND
// Char-Events are not processed, as they are not accelerator-relevant
bool bWantedKeyCode = false;
// A-Z, 0-9 only when combined with the Control-key
if ( ((pMsg->wParam >= 65) && (pMsg->wParam <= 90)) ||
((pMsg->wParam >= 48) && (pMsg->wParam <= 57)) )
{
if ( GetKeyState( VK_CONTROL ) & 0x8000 )
bWantedKeyCode = true;
}
else if ( ((pMsg->wParam >= VK_F1) && (pMsg->wParam <= VK_F24)) ||
((pMsg->wParam >= VK_SPACE) && (pMsg->wParam <= VK_HELP)) ||
(pMsg->wParam == VK_BACK) || (pMsg->wParam == VK_TAB) ||
(pMsg->wParam == VK_CLEAR) || (pMsg->wParam == VK_RETURN) ||
(pMsg->wParam == VK_ESCAPE) )
bWantedKeyCode = true;
if ( bWantedKeyCode )
{
ImplSalYieldMutexAcquireWithWait();
pObject = ImplFindSalObject( pMsg->hwnd );
if ( pObject )
pSalData->mnSalObjWantKeyEvt = pMsg->wParam;
ImplSalYieldMutexRelease();
}
}
// check WM_SYSCHAR, to activate menu with Alt key
else if ( pMsg->message == WM_SYSCHAR )
{
pSalData->mnSalObjWantKeyEvt = 0;
sal_uInt16 nKeyCode = LOWORD( pMsg->wParam );
// only 0-9 and A-Z
if ( ((nKeyCode >= 48) && (nKeyCode <= 57)) ||
((nKeyCode >= 65) && (nKeyCode <= 90)) ||
((nKeyCode >= 97) && (nKeyCode <= 122)) )
{
bool bRet = false;
ImplSalYieldMutexAcquireWithWait();
pObject = ImplFindSalObject( pMsg->hwnd );
if ( pObject )
{
if ( pMsg->hwnd == ::GetFocus() )
{
WinSalFrame* pFrame = ImplFindSalObjectFrame( pMsg->hwnd );
if ( pFrame )
{
if ( ImplHandleSalObjSysCharMsg( pFrame->mhWnd, pMsg->wParam, pMsg->lParam ) )
bRet = true;
}
}
}
ImplSalYieldMutexRelease();
if ( bRet )
return true;
}
}
else
pSalData->mnSalObjWantKeyEvt = 0;
return false;
}
void ImplSalPostDispatchMsg( const MSG* pMsg )
{
// Used for Unicode and none Unicode
SalData *pSalData = GetSalData();
if ( (pMsg->message == WM_KEYDOWN) || (pMsg->message == WM_KEYUP) )
{
if ( pSalData->mnSalObjWantKeyEvt == pMsg->wParam )
{
pSalData->mnSalObjWantKeyEvt = 0;
if ( pMsg->hwnd == ::GetFocus() )
{
ImplSalYieldMutexAcquireWithWait();
WinSalFrame* pFrame = ImplFindSalObjectFrame( pMsg->hwnd );
if ( pFrame )
ImplHandleSalObjKeyMsg( pFrame->mhWnd, pMsg->message, pMsg->wParam, pMsg->lParam );
ImplSalYieldMutexRelease();
}
}
}
pSalData->mnSalObjWantKeyEvt = 0;
}
static LRESULT CALLBACK SalSysObjWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef )
{
WinSalObject* pSysObj;
LRESULT nRet = 0;
switch( nMsg )
{
case WM_ERASEBKGND:
nRet = 1;
rDef = FALSE;
break;
case WM_PAINT:
{
PAINTSTRUCT aPs;
BeginPaint( hWnd, &aPs );
EndPaint( hWnd, &aPs );
rDef = FALSE;
}
break;
case WM_PARENTNOTIFY:
{
UINT nNotifyMsg = LOWORD( wParam );
if ( (nNotifyMsg == WM_LBUTTONDOWN) ||
(nNotifyMsg == WM_RBUTTONDOWN) ||
(nNotifyMsg == WM_MBUTTONDOWN) )
{
ImplSalYieldMutexAcquireWithWait();
pSysObj = GetSalObjWindowPtr( hWnd );
if ( pSysObj && !pSysObj->IsMouseTransparent() )
pSysObj->CallCallback( SalObjEvent::ToTop );
ImplSalYieldMutexRelease();
}
}
break;
case WM_MOUSEACTIVATE:
{
ImplSalYieldMutexAcquireWithWait();
pSysObj = GetSalObjWindowPtr( hWnd );
if ( pSysObj && !pSysObj->IsMouseTransparent() )
{
bool const ret = PostMessageW( hWnd, SALOBJ_MSG_TOTOP, 0, 0 );
SAL_WARN_IF(!ret, "vcl", "ERROR: PostMessage() failed!");
}
ImplSalYieldMutexRelease();
}
break;
case SALOBJ_MSG_TOTOP:
if ( ImplSalYieldMutexTryToAcquire() )
{
pSysObj = GetSalObjWindowPtr( hWnd );
pSysObj->CallCallback( SalObjEvent::ToTop );
ImplSalYieldMutexRelease();
rDef = FALSE;
}
else
{
bool const ret = PostMessageW( hWnd, SALOBJ_MSG_TOTOP, 0, 0 );
SAL_WARN_IF(!ret, "vcl", "ERROR: PostMessage() failed!");
}
break;
case SALOBJ_MSG_POSTFOCUS:
if ( ImplSalYieldMutexTryToAcquire() )
{
pSysObj = GetSalObjWindowPtr( hWnd );
HWND hFocusWnd = ::GetFocus();
SalObjEvent nEvent;
if ( hFocusWnd && ImplIsSysWindowOrChild( hWnd, hFocusWnd ) )
nEvent = SalObjEvent::GetFocus;
else
nEvent = SalObjEvent::LoseFocus;
pSysObj->CallCallback( nEvent );
ImplSalYieldMutexRelease();
}
else
{
bool const ret = PostMessageW(hWnd, SALOBJ_MSG_POSTFOCUS, 0, 0);
SAL_WARN_IF(!ret, "vcl", "ERROR: PostMessage() failed!");
}
rDef = FALSE;
break;
case WM_SIZE:
{
HWND hWndChild = GetWindow( hWnd, GW_CHILD );
if ( hWndChild )
{
SetWindowPos( hWndChild,
nullptr, 0, 0, static_cast<int>(LOWORD( lParam )), static_cast<int>(HIWORD( lParam )),
SWP_NOZORDER | SWP_NOACTIVATE );
}
}
rDef = FALSE;
break;
case WM_CREATE:
{
// Save the window instance at the window handle.
// Can also be used for the A-Version, because the struct
// to access lpCreateParams is the same structure
CREATESTRUCTW* pStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
pSysObj = static_cast<WinSalObject*>(pStruct->lpCreateParams);
SetSalObjWindowPtr( hWnd, pSysObj );
// set HWND already here,
// as instance data might be used during CreateWindow() events
pSysObj->mhWnd = hWnd;
rDef = FALSE;
}
break;
}
return nRet;
}
static LRESULT CALLBACK SalSysObjWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
int bDef = TRUE;
LRESULT nRet = SalSysObjWndProc( hWnd, nMsg, wParam, lParam, bDef );
if ( bDef )
nRet = DefWindowProcW( hWnd, nMsg, wParam, lParam );
return nRet;
}
static LRESULT CALLBACK SalSysObjChildWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef )
{
LRESULT nRet = 0;
switch( nMsg )
{
// clear background for plugins
case WM_ERASEBKGND:
{
WinSalObject* pSysObj = GetSalObjWindowPtr( ::GetParent( hWnd ) );
if( pSysObj && !pSysObj->IsEraseBackgroundEnabled() )
{
// do not erase background
nRet = 1;
rDef = FALSE;
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT aPs;
BeginPaint( hWnd, &aPs );
EndPaint( hWnd, &aPs );
rDef = FALSE;
}
break;
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
{
WinSalObject* pSysObj;
pSysObj = GetSalObjWindowPtr( ::GetParent( hWnd ) );
if( pSysObj && pSysObj->IsMouseTransparent() )
{
// forward mouse events to parent frame
HWND hWndParent = ::GetParent( pSysObj->mhWnd );
// transform coordinates
POINT pt;
pt.x = static_cast<tools::Long>(LOWORD( lParam ));
pt.y = static_cast<tools::Long>(HIWORD( lParam ));
MapWindowPoints( hWnd, hWndParent, &pt, 1 );
lParam = MAKELPARAM( static_cast<WORD>(pt.x), static_cast<WORD>(pt.y) );
nRet = SendMessageW( hWndParent, nMsg, wParam, lParam );
rDef = FALSE;
}
}
break;
}
return nRet;
}
static LRESULT CALLBACK SalSysObjChildWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
int bDef = TRUE;
LRESULT nRet = SalSysObjChildWndProc( hWnd, nMsg, wParam, lParam, bDef );
if ( bDef )
nRet = DefWindowProcW( hWnd, nMsg, wParam, lParam );
return nRet;
}
SalObject* ImplSalCreateObject( WinSalInstance* pInst, WinSalFrame* pParent )
{
SalData* pSalData = GetSalData();
// install hook, if it is the first SalObject
if ( !pSalData->mpFirstObject )
{
pSalData->mhSalObjMsgHook = SetWindowsHookExW( WH_CALLWNDPROC,
SalSysMsgProc,
pSalData->mhInst,
pSalData->mnAppThreadId );
}
if ( !pSalData->mbObjClassInit )
{
WNDCLASSEXW aWndClassEx;
aWndClassEx.cbSize = sizeof( aWndClassEx );
aWndClassEx.style = 0;
aWndClassEx.lpfnWndProc = SalSysObjWndProcW;
aWndClassEx.cbClsExtra = 0;
aWndClassEx.cbWndExtra = SAL_OBJECT_WNDEXTRA;
aWndClassEx.hInstance = pSalData->mhInst;
aWndClassEx.hIcon = nullptr;
aWndClassEx.hIconSm = nullptr;
aWndClassEx.hCursor = LoadCursor( nullptr, IDC_ARROW );
aWndClassEx.hbrBackground = nullptr;
aWndClassEx.lpszMenuName = nullptr;
aWndClassEx.lpszClassName = SAL_OBJECT_CLASSNAMEW;
if ( RegisterClassExW( &aWndClassEx ) )
{
// Clean background first because of plugins.
aWndClassEx.cbWndExtra = 0;
aWndClassEx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
aWndClassEx.lpfnWndProc = SalSysObjChildWndProcW;
aWndClassEx.lpszClassName = SAL_OBJECT_CHILDCLASSNAMEW;
if ( RegisterClassExW( &aWndClassEx ) )
pSalData->mbObjClassInit = true;
}
}
if ( pSalData->mbObjClassInit )
{
WinSalObject* pObject = new WinSalObject;
// #135235# Clip siblings of this
// SystemChildWindow. Otherwise, DXCanvas (using a hidden
// SystemChildWindow) clobbers applets/plugins during
// animations .
HWND hWnd = CreateWindowExW( 0, SAL_OBJECT_CLASSNAMEW, L"",
WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 0, 0,
pParent->mhWnd, nullptr,
pInst->mhInst, pObject );
HWND hWndChild = nullptr;
if ( hWnd )
{
// #135235# Explicitly stack SystemChildWindows in
// the order they're created - since there's no notion
// of zorder.
SetWindowPos(hWnd,HWND_TOP,0,0,0,0,
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOSIZE);
hWndChild = CreateWindowExW( 0, SAL_OBJECT_CHILDCLASSNAMEW, L"",
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE,
0, 0, 0, 0,
hWnd, nullptr,
pInst->mhInst, nullptr );
}
if ( !hWndChild )
{
SAL_WARN("vcl", "CreateWindowExW failed: " << WindowsErrorString(GetLastError()));
delete pObject;
return nullptr;
}
if ( hWnd )
{
pObject->mhWnd = hWnd;
pObject->mhWndChild = hWndChild;
pObject->maSysData.hWnd = hWndChild;
return pObject;
}
}
return nullptr;
}
WinSalObject::WinSalObject()
{
SalData* pSalData = GetSalData();
mhWnd = nullptr;
mhWndChild = nullptr;
mhLastFocusWnd = nullptr;
mpStdClipRgnData = nullptr;
// Insert object in objectlist
mpNextObject = pSalData->mpFirstObject;
pSalData->mpFirstObject = this;
}
WinSalObject::~WinSalObject()
{
SalData* pSalData = GetSalData();
// remove frame from framelist
if ( this == pSalData->mpFirstObject )
{
pSalData->mpFirstObject = mpNextObject;
// remove hook, if it is the last SalObject
if ( !pSalData->mpFirstObject )
UnhookWindowsHookEx( pSalData->mhSalObjMsgHook );
}
else
{
WinSalObject* pTempObject = pSalData->mpFirstObject;
while ( pTempObject->mpNextObject != this )
pTempObject = pTempObject->mpNextObject;
pTempObject->mpNextObject = mpNextObject;
}
// destroy cache data
delete [] reinterpret_cast<BYTE*>(mpStdClipRgnData);
HWND hWndParent = ::GetParent( mhWnd );
if ( mhWndChild )
DestroyWindow( mhWndChild );
if ( mhWnd )
DestroyWindow( mhWnd );
// reset palette, if no external child window is left,
// as they might have overwritten our palette
if ( hWndParent &&
::GetActiveWindow() == hWndParent &&
!GetWindow( hWndParent, GW_CHILD ) )
SendMessageW( hWndParent, SAL_MSG_FORCEPALETTE, 0, 0 );
}
void WinSalObject::ResetClipRegion()
{
SetWindowRgn( mhWnd, nullptr, TRUE );
}
void WinSalObject::BeginSetClipRegion( sal_uInt32 nRectCount )
{
sal_uLong nRectBufSize = sizeof(RECT)*nRectCount;
if ( nRectCount < SAL_CLIPRECT_COUNT )
{
if ( !mpStdClipRgnData )
mpStdClipRgnData = reinterpret_cast<RGNDATA*>(new BYTE[sizeof(RGNDATA)-1+(SAL_CLIPRECT_COUNT*sizeof(RECT))]);
mpClipRgnData = mpStdClipRgnData;
}
else
mpClipRgnData = reinterpret_cast<RGNDATA*>(new BYTE[sizeof(RGNDATA)-1+nRectBufSize]);
mpClipRgnData->rdh.dwSize = sizeof( RGNDATAHEADER );
mpClipRgnData->rdh.iType = RDH_RECTANGLES;
mpClipRgnData->rdh.nCount = nRectCount;
mpClipRgnData->rdh.nRgnSize = nRectBufSize;
SetRectEmpty( &(mpClipRgnData->rdh.rcBound) );
mpNextClipRect = reinterpret_cast<RECT*>(&(mpClipRgnData->Buffer));
mbFirstClipRect = true;
}
void WinSalObject::UnionClipRegion( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight )
{
RECT* pRect = mpNextClipRect;
RECT* pBoundRect = &(mpClipRgnData->rdh.rcBound);
tools::Long nRight = nX + nWidth;
tools::Long nBottom = nY + nHeight;
if ( mbFirstClipRect )
{
pBoundRect->left = nX;
pBoundRect->top = nY;
pBoundRect->right = nRight;
pBoundRect->bottom = nBottom;
mbFirstClipRect = false;
}
else
{
if ( nX < pBoundRect->left )
pBoundRect->left = static_cast<int>(nX);
if ( nY < pBoundRect->top )
pBoundRect->top = static_cast<int>(nY);
if ( nRight > pBoundRect->right )
pBoundRect->right = static_cast<int>(nRight);
if ( nBottom > pBoundRect->bottom )
pBoundRect->bottom = static_cast<int>(nBottom);
}
pRect->left = static_cast<int>(nX);
pRect->top = static_cast<int>(nY);
pRect->right = static_cast<int>(nRight);
pRect->bottom = static_cast<int>(nBottom);
mpNextClipRect++;
}
void WinSalObject::EndSetClipRegion()
{
HRGN hRegion;
// create a ClipRegion from the vcl::Region data
if ( mpClipRgnData->rdh.nCount == 1 )
{
RECT* pRect = &(mpClipRgnData->rdh.rcBound);
hRegion = CreateRectRgn( pRect->left, pRect->top,
pRect->right, pRect->bottom );
}
else
{
sal_uLong nSize = mpClipRgnData->rdh.nRgnSize+sizeof(RGNDATAHEADER);
hRegion = ExtCreateRegion( nullptr, nSize, mpClipRgnData );
if ( mpClipRgnData != mpStdClipRgnData )
delete [] reinterpret_cast<BYTE*>(mpClipRgnData);
}
SAL_WARN_IF( !hRegion, "vcl", "SalObject::EndSetClipRegion() - Can't create ClipRegion" );
SetWindowRgn( mhWnd, hRegion, TRUE );
}
void WinSalObject::SetPosSize( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight )
{
sal_uLong nStyle = 0;
bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
if ( bVisible )
{
ShowWindow( mhWnd, SW_HIDE );
nStyle |= SWP_SHOWWINDOW;
}
SetWindowPos( mhWnd, nullptr,
static_cast<int>(nX), static_cast<int>(nY), static_cast<int>(nWidth), static_cast<int>(nHeight),
SWP_NOZORDER | SWP_NOACTIVATE | nStyle );
}
void WinSalObject::Show( bool bVisible )
{
if ( bVisible )
ShowWindow( mhWnd, SW_SHOWNORMAL );
else
ShowWindow( mhWnd, SW_HIDE );
}
void WinSalObject::Enable( bool bEnable )
{
EnableWindow( mhWnd, bEnable );
}
void WinSalObject::GrabFocus()
{
if ( mhLastFocusWnd &&
IsWindow( mhLastFocusWnd ) &&
ImplIsSysWindowOrChild( mhWndChild, mhLastFocusWnd ) )
::SetFocus( mhLastFocusWnd );
else
::SetFocus( mhWndChild );
}
const SystemEnvData* WinSalObject::GetSystemData() const
{
return &maSysData;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|