-
Notifications
You must be signed in to change notification settings - Fork 0
/
RealShpe.cpp
975 lines (793 loc) · 23.2 KB
/
RealShpe.cpp
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
/* @(#)Z 1.19 com/src/imaging/realshps/RealShpe.cpp, odimaging, od96os2, odos29712d 97/03/21 17:18:24 (96/10/29 09:27:05) */
//====START_GENERATED_PROLOG======================================
//
//
// COMPONENT_NAME: odimaging
//
// CLASSES: none
//
// ORIGINS: 82,27
//
//
// (C) COPYRIGHT International Business Machines Corp. 1995,1996
// All Rights Reserved
// Licensed Materials - Property of IBM
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//
// IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
// USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
// OR PERFORMANCE OF THIS SOFTWARE.
//
//====END_GENERATED_PROLOG========================================
//
/********************************************************************/
/* Licensed Materials - Property of IBM */
/* */
/* */
/* Copyright (C) International Business Machines Corp., 1994. */
/* Copyright (C) Apple Computer, Inc., 1994 */
/* */
/* US Government Users Restricted Rights - */
/* Use, duplication, or disclosure restricted */
/* by GSA ADP Schedule Contract with IBM Corp. */
/********************************************************************/
/* IBM Change History (most recent first): */
/* 23332 6/24/96 chb Added SetDisplay/fDisplay for X Windows */
/* 3/19/96 jab Changes for cross platform support. */
/* 122017 5/11/95 aml Performance enhancements */
/* 120604 4/28/95 ced Merge with B1C16 Apple code. */
/* */
/********************************************************************/
/*
File: RealShpe.cpp
Contains: RealShape class, private to ODShape.
Owned by: Jens Alfke
Copyright: © 1993-1995 by Apple Computer, Inc., all rights reserved.
Change History (most recent first):
<10> 8/29/95 jpa Don't use kODErrInvalidValue. [1278284]
<9> 5/25/95 jpa Use new GX headers [1241078, 1253324]
<8> 2/24/95 jpa Removed private ODNewRgn. [1220810]
<7> 12/5/94 jpa Code review cleanup [1203923]
<6> 10/24/94 jpa Added NewGeometricShape [1195070]. Added
ODNewRgn: allocate rgns from temp-mem.
[1151710]
<5> 9/29/94 RA 1189812: Mods for 68K build.
<4> 8/2/94 jpa Added AsPolygonShape method.
<3> 7/26/94 jpa Initialize gGX to 99, not -1 [it's
unsigned]. Actually any value >1 will do.
<2> 6/18/94 MB Update memory includes
<1> 6/15/94 jpa first checked in
--------Moved to SOM project and rearranged-----
<9> 5/10/94 jpa Replaced 'inherited::' to appease %$#@
cfront.
<8> 5/9/94 MB #1162181: Changes necessary to install MMM.
<7> 5/9/94 jpa Enable polygon clipper and GX support
[1162090]
<6> 3/25/94 JA Use new XMPTransform API. (1153438)
<5> 3/15/94 MB Changes to support SCpp/ASLM builds,
#1150864.
<4> 2/17/94 JA Include new AltPoly.h.
<3> 2/16/94 JA Stop using pointers to member fns. Include
new AltPoint.h.
<2> 2/9/94 JA ShapePrv.h --> ShapePvM.h
<10> 2/7/94 JA Capitalized THROW.
<9> 2/7/94 JA Further tigerings.
<8> 2/3/94 JA Tiger Team Makeover!
<7> 1/31/94 JA Mucho fixes to polygon shapes & region
shapes. Other bugs squashed. Etc.
<6> 12/3/93 T‚ Stop including XMPError.h, it is included
as ErrorDef.h inside Except.h
<5> 11/29/93 JA Fixed XMPRectShape::Union.
<4> 11/24/93 JA cfront fixes.
<3> 11/24/93 VL Rolled back changes as ASLM build breaks
the THINK build.
<2> 11/23/93 VL Made this work with ASLM.
<1> 11/23/93 JA first checked in
In Progress:
*/
//#define _DO_POLYCLIP_
#ifdef _PLATFORM_OS2_
#define INCL_GPI
#define INCL_WIN
#endif
#ifdef _PLATFORM_WIN32_
#include <wtypes.h>
#include <wingdi.h>
#endif
#ifndef _ALTPOINT_
#include "AltPoint.h" /* Use C++ savvy XMPPoint and XMPRect*/
#endif
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
#ifndef _PAGETUNING_OFF_
#include <ODPagtun.h>
#endif
#endif // IBM Platforms
#ifndef _ALTPOLY_
#include "AltPoly.h"
#endif
#ifdef _PLATFORM_OS2_
#include <builtin.h>
#endif
#ifndef _REALSHPE_
#include "RealShpe.h"
#endif
#ifdef _PLATFORM_MACINTOSH_
#ifndef _GXSHPE_
#include "GXShpe.h"
#endif
#endif // _PLATFORM_MACINTOSH_
#ifndef _POLYSHPE_
#include "PolyShpe.h"
#endif
#ifndef _RECTSHPE_
#include "RectShpe.h"
#endif
#ifndef _RGNSHPE_
#include "RgnShpe.h"
#endif
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
#ifndef _COMPSHPE_
#include "CompShpe.h"
#endif
#endif
#ifndef _SHAPE_
#include "Shape.xh"
#endif
#ifndef _EXCEPT_
#include "Except.h"
#endif
#ifndef _ODMEMORY_
#include "ODMemory.h"
#endif
#ifdef _PLATFORM_MACINTOSH_
#ifndef __GXGRAPHICS__
#include <GXGraphics.h>
#endif
#endif // _PLATFORM_MACINTOSH_
#ifndef _ODDEBUG_
#include "ODDebug.h"
#endif
#ifdef _PLATFORM_UNIX_
#ifndef _SHAPE_H_
#include "X11/extensions/shape.h"
#endif
#endif
#ifdef _PLATFORM_UNIX_
static Display *fDisplay = (Display *)NULL;
static ODBoolean fShapeExtensionOK = kODFalse;
static ODBoolean fShapeExtensionOK_Known = kODFalse;
#endif // _PLATFORM_UNIX_
#ifdef RGNDEBUG
#include "qprintf.h"
#endif
#ifdef _PLATFORM_MACINTOSH_
//==============================================================================
// QuickDraw GX Utilities
//==============================================================================
ODBoolean gGX = 99; // Is GX installed? Initialized by ODShape constructor
#pragma segment QDGXShape
void
ClearGXError( )
{
GXGetGraphicsError(kODNULL);
// GX error status is cleared after asking for errors.
}
void
ThrowIfGXError( )
{
gxGraphicsError err = GXGetGraphicsError(kODNULL); // Get latest graphics error
if( err )
THROW(err,"QuickDraw GX error");
}
void
ThrowIfFirstGXError( )
{
gxGraphicsError err;
(void) GXGetGraphicsError(&err); // Get first error, not last
if( err )
THROW(err,"QuickDraw GX error");
}
#endif // _PLATFORM_MACINTOSH_
//==============================================================================
// RealShape
//==============================================================================
#ifdef _PLATFORM_MACINTOSH_
#pragma segment ODShape
#endif // _PLATFORM_MACINTOSH_
RealShape::RealShape( ODGeometryMode mode )
:fQDRegion(kODNULL),
fMode(mode)
{
}
RealShape::~RealShape( )
{
this->Purge(0);
}
ODSize
RealShape::Purge( ODSize )
{
if( fQDRegion ) {
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
ODSize size = 0;
fQDRegion.DisposeRgn();
#else
ODSize size = GetHandleSize( (Handle)fQDRegion );
DisposeRgn( fQDRegion );
#endif // IBM Platforms
fQDRegion = kODNULL;
return size;
} else
return 0;
}
RealShape*
RealShape::NewGeometricShape( ODGeometryMode mode ) //static method
{
#ifdef _PLATFORM_MACINTOSH_
if( gGX )
return new QDGXShape( mode );
else
#endif // _PLATFORM_MACINTOSH_
return new PolygonShape( mode );
}
void
RealShape::SetGeometryMode( ODGeometryMode mode )
{
if( mode==kODNeedsGeometry && !this->HasGeometry() )
THROW( kODErrNoShapeGeometry );
fMode = mode;
}
ODGeometryMode
RealShape::GetGeometryMode( )
{
return fMode;
}
RealShape*
RealShape::SetPolygon( const ODPolygon &poly )
{
ODRect r;
if( poly.AsRectangle( &r ) )
return this->SetRectangle( &r );
else {
RealShape *s;
s = RealShape::NewGeometricShape( fMode );
s = s->SetPolygon( poly );
delete this;
return s;
}
}
void
RealShape::Simplify( )
{
// Only PolygonShape does anything in this method.
}
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_MACINTOSH_)
ODPlatformShape
#ifdef _PLATFORM_OS2_ // CED
RealShape::GetPlatformShape( Environment* ev, ODGraphicsSystem system )
#else
RealShape::GetPlatformShape( ODGraphicsSystem system )
#endif // IBM Platforms
{
if( system==kODQuickDraw ) {
if( !fQDRegion ) {
#ifdef _PLATFORM_OS2_
fQDRegion.InitRegion( NewRgn() );
#else
fQDRegion = ODNewRgn();
#endif // _PLATFORM_OS2_
TRY{
#ifdef _PLATFORM_OS2_
this->InitQDRegion(ev);
#else
this->InitQDRegion();
#endif
}CATCH_ALL{
#ifdef _PLATFORM_OS2_
fQDRegion.DisposeRgn();
#else
DisposeRgn(fQDRegion);
#endif
fQDRegion = kODNULL;
RERAISE;
}ENDTRY
}
return fQDRegion;
#ifdef _PLATFORM_OS2_ // CED
}
#else
} else if( system==kODQuickDrawGX && gGX )
return this->CopyGXShape();
#endif // _PLATFORM_OS2_
else {
THROW(kODErrInvalidGraphicsSystem);
return kODNULL;
}
}
#endif // _PLATFORM_OS2 || _PLATFORM_MACINTOSH_
#ifdef _PLATFORM_WIN32_
ODPlatformShape
RealShape::GetPlatformShape( Environment* ev, ODGraphicsSystem system )
{
if( ( system == kODWin32 ) || ( system == kODWinNT ) || ( system == kODWin95 ) ) {
if( !fQDRegion ) {
fQDRegion.InitRegion( NewRgn() );
TRY{
this->InitQDRegion(ev);
}CATCH_ALL{
fQDRegion.DisposeRgn();
fQDRegion = kODNULL;
RERAISE;
}ENDTRY
}
return fQDRegion;
}
else {
THROW( kODErrInvalidGraphicsSystem );
return kODNULL;
}
}
#endif // _PLATFORM_WIN32_
#ifdef _PLATFORM_AIX_
ODPlatformShape
RealShape::GetPlatformShape( Environment* ev, ODGraphicsSystem system )
{
if( system == kODAIX ) {
if( !fQDRegion ) {
fQDRegion.InitRegion( NewRgn() );
TRY{
this->InitQDRegion(ev);
}CATCH_ALL{
fQDRegion.DisposeRgn();
fQDRegion = kODNULL;
RERAISE;
}ENDTRY
}
return fQDRegion;
}
else {
THROW( kODErrInvalidGraphicsSystem );
return kODNULL;
}
}
#endif // _PLATFORM_AIX_
void
RealShape::SetPlatformShape( ODGraphicsSystem, ODPlatformShape )
{
WARNMSG(WARN_INDEX(AMSG_550),"RealShape: A subclass should have been overridden this method!" );
THROW( kODErrInvalidGraphicsSystem );
}
ODBoolean
RealShape::HasGeometry( )
{
return kODTrue; // ODRgnShape overrides this to return false if non-rectangular
}
RealShape*
RealShape::Clear( )
{
// Delete me and return a new empty rect-shape:
ODRect empty( 0,0,0,0 );
RealShape *s = new RectShape( fMode,empty );
delete this;
return s;
}
RealShape*
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
RealShape::ReplaceWith( Environment* ev, RealShape *shape )
#else
RealShape::ReplaceWith( RealShape *shape )
#endif // IBM Platforms
{
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
RealShape *s = shape->Copy(ev);
#else
RealShape *s = shape->Copy();
#endif
delete this;
return s;
}
RealShape*
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
RealShape::Combine( Environment* ev, ODShapeOp op, RealShape *shape )
#else
RealShape::Combine( ODShapeOp op, RealShape *shape )
#endif // IBM Platforms
{
switch( op ) {
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
case kShapeIntersection:
return this->Intersect( ev, shape );
case kShapeUnion:
return this->Union( ev, shape );
case kShapeDifference:
return this->Subtract( ev, shape );
#else
case kShapeIntersection:
return this->Intersect( shape );
case kShapeUnion:
return this->Union( shape );
case kShapeDifference:
return this->Subtract( shape );
#endif // IBM Platforms
case kShapeNoOp:
return this;
default:
WARNMSG(WARN_INDEX(AMSG_590),"Illegal Shape Operation" );
THROW( kODErrInvalidParameter );
break;
}
return kODNULL;
}
RealShape*
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
RealShape::AsPolygonShape( Environment* ev )
#else
RealShape::AsPolygonShape( )
#endif // IBM Platforms
{
RealShape *s = kODNULL; ODVolatile( s );
ODPolygon poly; ODVolatile( poly );
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
this->CopyPolygon( ev, poly );
#else
this->CopyPolygon( poly );
#endif // IBM Platforms
TRY{
s = RealShape::NewGeometricShape( fMode );
s->SetPolygon( poly );
}CATCH_ALL{
delete s;
poly.Clear();
RERAISE;
}ENDTRY
poly.Clear();
return s;
}
RealShape*
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
RealShape::Promote( Environment* ev, ODShapeOp op, RealShape *shape )
{
// _DO_POLYCLIP_ is the magic which turns on and off the use of
// the CompositeShape class and the associated shape B-Tree.
// The CompositeShape class overrides all of the methods of RealShape
// and defers the calculation of the actual shape until much later.
#ifndef _DO_POLYCLIP_
if( fMode == kODNeedsGeometry )
THROW( kODErrNoShapeGeometry );
return new CompositeShape( this, shape->Copy(ev), op );
#else
// This section of the _DO_POLYCLIP_ implements the default
// method of dealing with shapes as implemented by Apple including
// the polygon clipping code. Note that the call to Combine is what
// the OS/2 shape B-tree algorithm defers until much later.
RealShape *s; ODVolatile(s);
if( fMode != kODLoseGeometry && ( shape == kODNULL || shape->HasGeometry() ) ) {
s = this->AsPolygonShape( ev );
TRY{
s = s->Combine( ev, op, shape );
}CATCH_ALL{
delete s;
RERAISE;
}ENDTRY
} else {
if( fMode == kODNeedsGeometry )
THROW( kODErrNoShapeGeometry );
#ifdef _PLATFORM_OS2_
RgnHandle rgn = (RgnHandle) ODCopyRgnHandle(
(RgnHandle)this->GetPlatformShape( ev, kODQuickDraw ) );
#endif
#ifdef _PLATFORM_WIN32_
RgnHandle rgn = (RgnHandle) ODCopyRgnHandle(
(RgnHandle)this->GetPlatformShape( ev, kODWin32 ) );
#endif
#ifdef _PLATFORM_AIX_
RgnHandle rgn = (RgnHandle) ODCopyRgnHandle(
(RgnHandle)this->GetPlatformShape( ev, kODAIX ) );
#endif
TRY{
s = new RgnShape( fMode );
}CATCH_ALL{
DisposeRgn( rgn );
RERAISE;
}ENDTRY
TRY{
#ifdef _PLATFORM_OS2_
s->SetPlatformShape( kODQuickDraw, rgn );
#endif
#ifdef _PLATFORM_WIN32_
s->SetPlatformShape( kODWin32, rgn );
#endif
#ifdef _PLATFORM_AIX_
s->SetPlatformShape( kODAIX, rgn );
#endif
s = s->Combine( ev, op, shape );
}CATCH_ALL{
delete s;
RERAISE;
}ENDTRY
}
delete this;
return s;
#endif // !_DO_POLYCLIP_
}
#else // defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
RealShape::Promote( ODShapeOp op, RealShape *shape )
{
// Delete me and return an equivalent region- or polygon-shape.
// Optionally perform a binary operation on the promoted shape.
RealShape *s; ODVolatile(s);
if( fMode!=kODLoseGeometry && ( shape==kODNULL || shape->HasGeometry() ) ) {
s = this->AsPolygonShape();
TRY{
s = s->Combine( op,shape );
}CATCH_ALL{
delete s;
RERAISE;
}ENDTRY
} else {
if( fMode == kODNeedsGeometry )
THROW( kODErrNoShapeGeometry );
RgnHandle rgn = (RgnHandle) ODCopyHandle(
(ODHandle)this->GetPlatformShape( kODQuickDraw ) );
TRY{
s = new RgnShape( fMode );
}CATCH_ALL{
DisposeRgn( rgn );
RERAISE;
}ENDTRY
TRY{
s->SetPlatformShape( kODQuickDraw, rgn );
s = s->Combine( op, shape );
}CATCH_ALL{
delete s;
RERAISE;
}ENDTRY
}
delete this;
return s;
}
#endif // defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
void RealShape::GetPesimisticBoundingBox( Environment* ev, ODRect *bounds )
{
GetBoundingBox( ev, bounds );
}
ODBoolean RealShape::IsObviousEmpty( Environment* ev )
{
return IsEmpty( ev );
}
ODBoolean RealShape::IsObviousRectangular( Environment* ev )
{
return IsRectangular( ev );
}
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
Region_rep::Region_rep( HRGN RegionHandle ) {
hrgn = RegionHandle;
refs = 1;
}
#endif
#if defined(_PLATFORM_UNIX_)
Region_rep::Region_rep( Region RegionHandle ) {
hrgn = RegionHandle;
refs = 1;
}
#endif
Region_rep::~Region_rep() {
if ( hrgn ) {
#ifdef _PLATFORM_OS2_
HPS hps = GetPresSpace();
BOOL success = GpiDestroyRegion( hps, hrgn );
#ifdef RGNDEBUG
if( !success )
qprintf("Region_rep::~Region_rep - DeleteObject( hrgn ) failed.");
#endif
ReleasePresSpace( hps );
#endif
#ifdef _PLATFORM_WIN32_
BOOL success = DeleteObject( hrgn );
#ifdef RGNDEBUG
if( !success )
qprintf("Region_rep::~Region_rep - DeleteObject( hrgn ) failed.");
#endif
#endif
#ifdef _PLATFORM_UNIX_
XDestroyRegion( hrgn );
#endif
}
}
RegionRef::RegionRef( RegionRef& ref ) {
rgn = ref.rgn;
if( rgn )
rgn->refs++;
}
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
RegionRef::RegionRef( HRGN RegionHandle ) {
if( RegionHandle )
rgn = new Region_rep( RegionHandle );
else
rgn = 0;
}
#endif
#if defined(_PLATFORM_UNIX_)
RegionRef::RegionRef( Region RegionHandle ) {
if( RegionHandle )
rgn = new Region_rep( RegionHandle );
else
rgn = 0;
}
#endif
void RegionRef::DisposeRgn()
{
if ( rgn && !--rgn->refs )
delete rgn;
rgn = 0;
}
RegionRef::~RegionRef() {
DisposeRgn();
}
RegionRef& RegionRef::operator =( const RegionRef& ref ) {
if ( rgn && !--rgn->refs )
delete rgn;
rgn = ref.rgn;
if( rgn )
rgn->refs++;
return *this;
}
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
RegionRef& RegionRef::operator =( HRGN RegionHandle ) {
if ( rgn && !--rgn->refs )
delete rgn;
if(RegionHandle)
rgn = new Region_rep( RegionHandle );
else
rgn = 0;
return *this;
}
#endif
#if defined(_PLATFORM_UNIX_)
RegionRef& RegionRef::operator =( Region RegionHandle ) {
if ( rgn && !--rgn->refs )
delete rgn;
if(RegionHandle)
rgn = new Region_rep( RegionHandle );
else
rgn = 0;
return *this;
}
#endif
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
RegionRef::operator HRGN() {
if( rgn )
return rgn->hrgn;
return(0);
}
#endif
#if defined(_PLATFORM_UNIX_)
RegionRef::operator Region() {
if( rgn )
return rgn->hrgn;
return(0);
}
#endif
void RegionRef::Unlink() {
if( !rgn ) return;
if ( rgn->refs > 1 ) {
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
HRGN newRgn = 0;
#endif
#if defined(_PLATFORM_UNIX_)
Region newRgn = 0;
#endif
if ( rgn->hrgn ) {
#ifdef _PLATFORM_OS2_
HPS hps = GetPresSpace();
newRgn = GpiCreateRegion( hps, 0, 0 );
GpiCombineRegion( hps, newRgn, rgn->hrgn, 0, CRGN_COPY );
ReleasePresSpace(hps);
#endif // _PLATFORM_OS2_
#ifdef _PLATFORM_WIN32_
newRgn = CreateRectRgn( 0, 0, 0, 0 );
CombineRgn( newRgn, rgn->hrgn, 0, RGN_COPY );
#endif // _PLATFORM_WIN32_
#ifdef _PLATFORM_UNIX_
newRgn = XCreateRegion();
Region newRgn2 = XCreateRegion();
XUnionRegion(newRgn2, rgn->hrgn, newRgn);
XDestroyRegion(newRgn2);
#endif // _PLATFORM_UNIX_
}
--rgn->refs;
rgn = new Region_rep( newRgn );
}
}
#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
void RegionRef::InitRegion( HRGN initRgn ) {
#if ODDebug
// jab 03/19/96 Not sure what _interrupt does...
// if (rgn && rgn->hrgn)
// _interrupt(3);
#endif
if( !rgn ) {
if( initRgn )
rgn = new Region_rep( initRgn );
else
rgn = 0;
}
else
rgn->hrgn = initRgn;
}
#endif
#if defined(_PLATFORM_UNIX_)
void RegionRef::InitRegion( Region initRgn ) {
#if ODDebug
// jab 03/19/96 Not sure what _interrupt does...
// if (rgn && rgn->hrgn)
// _interrupt(3);
#endif
if( !rgn ) {
if( initRgn )
rgn = new Region_rep( initRgn );
else
rgn = 0;
}
else
rgn->hrgn = initRgn;
}
#endif
#endif // defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
#if _PLATFORM_UNIX_
void RealShape::SetDisplay( Environment* ev, Display *display )
{
fDisplay = display;
}
int RealShape::GetRegionRects( ODRgnHandle rgn, XRectangle** rectangles )
{
// rectangles = (XRectangle **)NULL;
if (!fShapeExtensionOK_Known) {
int unused1, unused2;
fShapeExtensionOK = XShapeQueryExtension(fDisplay, &unused1, &unused2);
fShapeExtensionOK_Known = kODTrue;
}
if (!fShapeExtensionOK) {
WARNMSG(WARN_INDEX(AMSG_800),"GetRegionRects - X Server does not support the X11\n"
" Nonrectangular Window Shape Extension.\n");
return 0;
}
Window root_win = DefaultRootWindow(fDisplay);
int unused_x, unused_y;
unsigned int win_width, win_height, unused_bw, win_depth;
XWindowAttributes root_win_attr;
if (!XGetWindowAttributes(fDisplay, DefaultRootWindow(fDisplay), &root_win_attr)) {
WARNMSG(WARN_INDEX(AMSG_810),"GetRegionRects - can't read attributes\n"
" of root X window.\n");
return 0;
}
XSetWindowAttributes unused_attr;
Window temp_win = XCreateWindow(fDisplay,
root_win,
0, 0, 1024, 1024, 0,
root_win_attr.depth,
InputOutput, root_win_attr.visual,
(unsigned long) 0, &unused_attr);
if (!temp_win) {
WARNMSG(WARN_INDEX(AMSG_820),"GetRegionRects - can't create temporary X window!\n");
return 0;
}
// XGCValues unused_gc_vals;
// GC tmp_gc = XCreateGC(fDisplay, temp_win, (unsigned long) 0,
// &unused_gc_vals);
XShapeCombineRegion(fDisplay, temp_win, ShapeClip, 0, 0, rgn, ShapeIntersect);
// Now get a list of rectangles back from the shaped temp. X window
int rect_count = 0;
int rect_ordering;
*rectangles = XShapeGetRectangles(fDisplay, temp_win,
ShapeClip, &rect_count, &rect_ordering);
XDestroyWindow(fDisplay, temp_win);
// XFreeGC(fDisplay, tmp_gc);
return rect_count;
}
#endif // _PLATFORM_UNIX_