1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "osx/saldata.hxx"
23 #include "osx/salobj.h"
24 #include "osx/salframe.h"
25 #include <AppKit/NSOpenGLView.h>
27 AquaSalObject::AquaSalObject( AquaSalFrame
* pFrame
, SystemWindowData
* pWindowData
) :
39 maSysData
.nSize
= sizeof( maSysData
);
40 maSysData
.mpNSView
= NULL
;
41 maSysData
.mbOpenGL
= false;
43 NSRect aInitFrame
= { NSZeroPoint
, { 20, 20 } };
44 mpClipView
= [[NSClipView alloc
] initWithFrame
: aInitFrame
];
47 [mpFrame
->getNSView() addSubview
: mpClipView
];
48 [mpClipView setHidden
: YES
];
50 if (pWindowData
&& pWindowData
->bOpenGL
)
52 maSysData
.mbOpenGL
= true;
53 NSOpenGLPixelFormat
* pixFormat
= NULL
;
55 if (pWindowData
->bLegacy
)
57 NSOpenGLPixelFormatAttribute aAttributes
[] =
59 NSOpenGLPFADoubleBuffer
,
60 NSOpenGLPFAAlphaSize
, 8,
61 NSOpenGLPFAColorSize
, 24,
62 NSOpenGLPFAMultisample
,
63 NSOpenGLPFASampleBuffers
, (NSOpenGLPixelFormatAttribute
)1,
64 NSOpenGLPFASamples
, (NSOpenGLPixelFormatAttribute
)4,
67 pixFormat
= [[NSOpenGLPixelFormat alloc
] initWithAttributes
:aAttributes
];
71 NSOpenGLPixelFormatAttribute aAttributes
[] =
73 NSOpenGLPFAOpenGLProfile
, NSOpenGLProfileVersion3_2Core
,
74 NSOpenGLPFADoubleBuffer
,
75 NSOpenGLPFAAlphaSize
, 8,
76 NSOpenGLPFAColorSize
, 24,
77 NSOpenGLPFAMultisample
,
78 NSOpenGLPFASampleBuffers
, (NSOpenGLPixelFormatAttribute
)1,
79 NSOpenGLPFASamples
, (NSOpenGLPixelFormatAttribute
)4,
82 pixFormat
= [[NSOpenGLPixelFormat alloc
] initWithAttributes
:aAttributes
];
85 maSysData
.mpNSView
= [[NSOpenGLView alloc
] initWithFrame
: aInitFrame pixelFormat
:pixFormat
];
89 maSysData
.mpNSView
= [[NSView alloc
] initWithFrame
: aInitFrame
];
92 if( maSysData
.mpNSView
)
95 [mpClipView setDocumentView
: maSysData
.mpNSView
];
99 AquaSalObject::~AquaSalObject()
101 if( maSysData
.mpNSView
)
103 NSView
*pView
= maSysData
.mpNSView
;
104 [pView removeFromSuperview
];
109 [mpClipView removeFromSuperview
];
110 [mpClipView release
];
114 // Please note that the talk about QTMovieView below presumably refers
115 // to stuff in the QuickTime avmedia thingie, and that QuickTime is
116 // deprecated, not available for 64-bit code, and won't thus be used
117 // in a "modern" build of LO anyway. So the relevance of the comment
121 sadly there seems to be no way to impose clipping on a child view,
122 especially a QTMovieView which seems to ignore the current context
123 completely. Also there is no real way to shape a window; on Aqua a
124 similar effect to non-rectangular windows is achieved by using a
125 non-opaque window and not painting where one wants the background
128 With respect to SalObject this leaves us to having an NSClipView
129 containing the child view. Even a QTMovieView respects the boundaries of
130 that, which gives us a clip "region" consisting of one rectangle.
131 This is gives us an 80% solution only, though.
134 void AquaSalObject::ResetClipRegion()
140 sal_uInt16
AquaSalObject::GetClipRegionType()
142 return SAL_OBJECT_CLIP_INCLUDERECTS
;
145 void AquaSalObject::BeginSetClipRegion( sal_uLong
)
150 void AquaSalObject::UnionClipRegion( long nX
, long nY
, long nWidth
, long nHeight
)
156 mnClipWidth
+= mnClipX
- nX
;
159 if( nX
+ nWidth
> mnClipX
+ mnClipWidth
)
160 mnClipWidth
= nX
+ nWidth
- mnClipX
;
163 mnClipHeight
+= mnClipY
- nY
;
166 if( nY
+ nHeight
> mnClipY
+ mnClipHeight
)
167 mnClipHeight
= nY
+ nHeight
- mnClipY
;
173 mnClipWidth
= nWidth
;
174 mnClipHeight
= nHeight
;
179 void AquaSalObject::EndSetClipRegion()
184 void AquaSalObject::SetPosSize( long nX
, long nY
, long nWidth
, long nHeight
)
193 void AquaSalObject::setClippedPosSize()
195 NSRect aViewRect
= { NSZeroPoint
, NSMakeSize( mnWidth
, mnHeight
) };
196 if( maSysData
.mpNSView
)
198 NSView
* pNSView
= maSysData
.mpNSView
;
199 [pNSView setFrame
: aViewRect
];
202 NSRect aClipViewRect
= NSMakeRect( mnX
, mnY
, mnWidth
, mnHeight
);
203 NSPoint aClipPt
= NSZeroPoint
;
206 aClipViewRect
.origin
.x
+= mnClipX
;
207 aClipViewRect
.origin
.y
+= mnClipY
;
208 aClipViewRect
.size
.width
= mnClipWidth
;
209 aClipViewRect
.size
.height
= mnClipHeight
;
212 aClipPt
.y
= mnHeight
- mnClipHeight
;
215 mpFrame
->VCLToCocoa( aClipViewRect
, false );
216 [mpClipView setFrame
: aClipViewRect
];
218 [mpClipView scrollToPoint
: aClipPt
];
221 void AquaSalObject::Show( bool bVisible
)
224 [mpClipView setHidden
: (bVisible
? NO
: YES
)];
227 const SystemEnvData
* AquaSalObject::GetSystemData() const
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */