Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / osx / salobj.cxx
blob58e2c6436b1a53342ca552c58fe023c6c5c74c81
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 .
20 #include <string.h>
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 ) :
28 mpFrame( pFrame ),
29 mnClipX( -1 ),
30 mnClipY( -1 ),
31 mnClipWidth( -1 ),
32 mnClipHeight( -1 ),
33 mbClip( false ),
34 mnX( 0 ),
35 mnY( 0 ),
36 mnWidth( 20 ),
37 mnHeight( 20 )
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 ];
45 if( mpClipView )
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];
69 else
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];
87 else
89 maSysData.mpNSView = [[NSView alloc] initWithFrame: aInitFrame];
92 if( maSysData.mpNSView )
94 if( mpClipView )
95 [mpClipView setDocumentView: maSysData.mpNSView];
99 AquaSalObject::~AquaSalObject()
101 if( maSysData.mpNSView )
103 NSView *pView = maSysData.mpNSView;
104 [pView removeFromSuperview];
105 [pView release];
107 if( mpClipView )
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
118 // is unclear.
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
126 to shine through.
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()
136 mbClip = false;
137 setClippedPosSize();
140 sal_uInt16 AquaSalObject::GetClipRegionType()
142 return SAL_OBJECT_CLIP_INCLUDERECTS;
145 void AquaSalObject::BeginSetClipRegion( sal_uLong )
147 mbClip = false;
150 void AquaSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
152 if( mbClip )
154 if( nX < mnClipX )
156 mnClipWidth += mnClipX - nX;
157 mnClipX = nX;
159 if( nX + nWidth > mnClipX + mnClipWidth )
160 mnClipWidth = nX + nWidth - mnClipX;
161 if( nY < mnClipY )
163 mnClipHeight += mnClipY - nY;
164 mnClipY = nY;
166 if( nY + nHeight > mnClipY + mnClipHeight )
167 mnClipHeight = nY + nHeight - mnClipY;
169 else
171 mnClipX = nX;
172 mnClipY = nY;
173 mnClipWidth = nWidth;
174 mnClipHeight = nHeight;
175 mbClip = true;
179 void AquaSalObject::EndSetClipRegion()
181 setClippedPosSize();
184 void AquaSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
186 mnX = nX;
187 mnY = nY;
188 mnWidth = nWidth;
189 mnHeight = nHeight;
190 setClippedPosSize();
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;
204 if( mbClip )
206 aClipViewRect.origin.x += mnClipX;
207 aClipViewRect.origin.y += mnClipY;
208 aClipViewRect.size.width = mnClipWidth;
209 aClipViewRect.size.height = mnClipHeight;
210 aClipPt.x = mnClipX;
211 if( mnClipY == 0 )
212 aClipPt.y = mnHeight - mnClipHeight;
215 mpFrame->VCLToCocoa( aClipViewRect, false );
216 [mpClipView setFrame: aClipViewRect];
218 [mpClipView scrollToPoint: aClipPt];
221 void AquaSalObject::Show( bool bVisible )
223 if( mpClipView )
224 [mpClipView setHidden: (bVisible ? NO : YES)];
227 const SystemEnvData* AquaSalObject::GetSystemData() const
229 return &maSysData;
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */