bump product version to 4.2.0.1
[LibreOffice.git] / vcl / aqua / source / window / salobj.cxx
blobabf085cdd5d107e44648b732bb234e128a970bb3
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 .
21 #include <string.h>
23 #include "aqua/saldata.hxx"
24 #include "aqua/salobj.h"
25 #include "aqua/salframe.h"
27 // =======================================================================
29 AquaSalObject::AquaSalObject( AquaSalFrame* pFrame ) :
30 mpFrame( pFrame ),
31 mnClipX( -1 ),
32 mnClipY( -1 ),
33 mnClipWidth( -1 ),
34 mnClipHeight( -1 ),
35 mbClip( false ),
36 mnX( 0 ),
37 mnY( 0 ),
38 mnWidth( 20 ),
39 mnHeight( 20 )
41 maSysData.nSize = sizeof( maSysData );
42 maSysData.pView = NULL;
44 NSRect aInitFrame = { { 0, 0 }, { 20, 20 } };
45 mpClipView = [[NSClipView alloc] initWithFrame: aInitFrame ];
46 if( mpClipView )
48 [mpFrame->getView() addSubview: mpClipView];
49 [mpClipView setHidden: YES];
51 maSysData.pView = [[NSView alloc] initWithFrame: aInitFrame];
52 if( maSysData.pView )
54 if( mpClipView )
55 [mpClipView setDocumentView: maSysData.pView];
59 // -----------------------------------------------------------------------
61 AquaSalObject::~AquaSalObject()
63 if( maSysData.pView )
65 NSView *pView = maSysData.pView;
66 [pView removeFromSuperview];
67 [pView release];
69 if( mpClipView )
71 [mpClipView removeFromSuperview];
72 [mpClipView release];
77 sadly there seems to be no way to impose clipping on a child view,
78 especially a QTMovieView which seems to ignore the current context
79 completely. Also there is no real way to shape a window; on Aqua a
80 similar effect to non-rectangular windows is achieved by using a
81 non-opaque window and not painting where one wants the background
82 to shine through.
84 With respect to SalObject this leaves us to having an NSClipView
85 containing the child view. Even a QTMovieView respects the boundaries of
86 that, which gives us a clip "region" consisting of one rectangle.
87 This is gives us an 80% solution only, though.
90 // -----------------------------------------------------------------------
92 void AquaSalObject::ResetClipRegion()
94 mbClip = false;
95 setClippedPosSize();
98 // -----------------------------------------------------------------------
100 sal_uInt16 AquaSalObject::GetClipRegionType()
102 return SAL_OBJECT_CLIP_INCLUDERECTS;
105 // -----------------------------------------------------------------------
107 void AquaSalObject::BeginSetClipRegion( sal_uLong )
109 mbClip = false;
112 // -----------------------------------------------------------------------
114 void AquaSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
116 if( mbClip )
118 if( nX < mnClipX )
120 mnClipWidth += mnClipX - nX;
121 mnClipX = nX;
123 if( nX + nWidth > mnClipX + mnClipWidth )
124 mnClipWidth = nX + nWidth - mnClipX;
125 if( nY < mnClipY )
127 mnClipHeight += mnClipY - nY;
128 mnClipY = nY;
130 if( nY + nHeight > mnClipY + mnClipHeight )
131 mnClipHeight = nY + nHeight - mnClipY;
133 else
135 mnClipX = nX;
136 mnClipY = nY;
137 mnClipWidth = nWidth;
138 mnClipHeight = nHeight;
139 mbClip = true;
143 // -----------------------------------------------------------------------
145 void AquaSalObject::EndSetClipRegion()
147 setClippedPosSize();
150 // -----------------------------------------------------------------------
152 void AquaSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
154 mnX = nX;
155 mnY = nY;
156 mnWidth = nWidth;
157 mnHeight = nHeight;
158 setClippedPosSize();
161 // -----------------------------------------------------------------------
163 void AquaSalObject::setClippedPosSize()
165 NSRect aViewRect = { { 0, 0 }, { static_cast<CGFloat>(mnWidth), static_cast<CGFloat>(mnHeight) } };
166 if( maSysData.pView )
168 NSView *pView = maSysData.pView;
169 [pView setFrame: aViewRect];
172 NSRect aClipViewRect = { { static_cast<CGFloat>(mnX), static_cast<CGFloat>(mnY) }, { static_cast<CGFloat>(mnWidth), static_cast<CGFloat>(mnHeight) } };
173 NSPoint aClipPt = { 0, 0 };
174 if( mbClip )
176 aClipViewRect.origin.x += mnClipX;
177 aClipViewRect.origin.y += mnClipY;
178 aClipViewRect.size.width = mnClipWidth;
179 aClipViewRect.size.height = mnClipHeight;
180 aClipPt.x = mnClipX;
181 if( mnClipY == 0 )
182 aClipPt.y = mnHeight - mnClipHeight;
185 mpFrame->VCLToCocoa( aClipViewRect, false );
186 [mpClipView setFrame: aClipViewRect];
188 [mpClipView scrollToPoint: aClipPt];
191 // -----------------------------------------------------------------------
193 void AquaSalObject::Show( sal_Bool bVisible )
195 if( mpClipView )
196 [mpClipView setHidden: (bVisible ? NO : YES)];
199 // -----------------------------------------------------------------------
201 const SystemEnvData* AquaSalObject::GetSystemData() const
203 return &maSysData;
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */