xref: /AOO41X/main/vcl/aqua/source/window/salobj.cxx (revision 9f62ea84a806e17e6f2bbff75724a7257a0eb5d9)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "aqua/saldata.hxx"
30cdf0e10cSrcweir #include "aqua/salobj.h"
31cdf0e10cSrcweir #include "aqua/salframe.h"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // =======================================================================
34cdf0e10cSrcweir 
35cdf0e10cSrcweir AquaSalObject::AquaSalObject( AquaSalFrame* pFrame ) :
36cdf0e10cSrcweir     mpFrame( pFrame ),
37cdf0e10cSrcweir     mnClipX( -1 ),
38cdf0e10cSrcweir     mnClipY( -1 ),
39cdf0e10cSrcweir     mnClipWidth( -1 ),
40cdf0e10cSrcweir     mnClipHeight( -1 ),
41cdf0e10cSrcweir     mbClip( false ),
42cdf0e10cSrcweir     mnX( 0 ),
43cdf0e10cSrcweir     mnY( 0 ),
44cdf0e10cSrcweir     mnWidth( 20 ),
45cdf0e10cSrcweir     mnHeight( 20 )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     maSysData.nSize = sizeof( maSysData );
48cdf0e10cSrcweir     maSysData.pView = NULL;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     NSRect aInitFrame = { { 0, 0 }, { 20, 20 } };
51cdf0e10cSrcweir     mpClipView = [[NSClipView alloc] initWithFrame: aInitFrame ];
52cdf0e10cSrcweir     if( mpClipView )
53cdf0e10cSrcweir     {
54cdf0e10cSrcweir         [mpFrame->getView() addSubview: mpClipView];
55cdf0e10cSrcweir         [mpClipView setHidden: YES];
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir     maSysData.pView = [[NSView alloc] initWithFrame: aInitFrame];
58cdf0e10cSrcweir     if( maSysData.pView )
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir         if( mpClipView )
61cdf0e10cSrcweir             [mpClipView setDocumentView: maSysData.pView];
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir // -----------------------------------------------------------------------
66cdf0e10cSrcweir 
67cdf0e10cSrcweir AquaSalObject::~AquaSalObject()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     if( maSysData.pView )
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         NSView *pView = maSysData.pView;
72cdf0e10cSrcweir         [pView removeFromSuperview];
73cdf0e10cSrcweir         [pView release];
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir     if( mpClipView )
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         [mpClipView removeFromSuperview];
78cdf0e10cSrcweir         [mpClipView release];
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir /*
83cdf0e10cSrcweir    sadly there seems to be no way to impose clipping on a child view,
84cdf0e10cSrcweir    especially a QTMovieView which seems to ignore the current context
85cdf0e10cSrcweir    completely. Also there is no real way to shape a window; on Aqua a
86cdf0e10cSrcweir    similar effect to non-rectangular windows is achieved by using a
87cdf0e10cSrcweir    non-opaque window and not painting where one wants the background
88cdf0e10cSrcweir    to shine through.
89cdf0e10cSrcweir 
90cdf0e10cSrcweir    With respect to SalObject this leaves us to having an NSClipView
91cdf0e10cSrcweir    containing the child view. Even a QTMovieView respects the boundaries of
92cdf0e10cSrcweir    that, which gives us a clip "region" consisting of one rectangle.
93cdf0e10cSrcweir    This is gives us an 80% solution only, though.
94cdf0e10cSrcweir */
95cdf0e10cSrcweir 
96cdf0e10cSrcweir // -----------------------------------------------------------------------
97cdf0e10cSrcweir 
98cdf0e10cSrcweir void AquaSalObject::ResetClipRegion()
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     mbClip = false;
101cdf0e10cSrcweir     setClippedPosSize();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir // -----------------------------------------------------------------------
105cdf0e10cSrcweir 
106cdf0e10cSrcweir sal_uInt16 AquaSalObject::GetClipRegionType()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	return SAL_OBJECT_CLIP_INCLUDERECTS;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir // -----------------------------------------------------------------------
112cdf0e10cSrcweir 
113cdf0e10cSrcweir void AquaSalObject::BeginSetClipRegion( sal_uLong )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     mbClip = false;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir // -----------------------------------------------------------------------
119cdf0e10cSrcweir 
120cdf0e10cSrcweir void AquaSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     if( mbClip )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         if( nX < mnClipX )
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             mnClipWidth += mnClipX - nX;
127cdf0e10cSrcweir             mnClipX = nX;
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir         if( nX + nWidth > mnClipX + mnClipWidth )
130cdf0e10cSrcweir             mnClipWidth = nX + nWidth - mnClipX;
131cdf0e10cSrcweir         if( nY < mnClipY )
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             mnClipHeight += mnClipY - nY;
134cdf0e10cSrcweir             mnClipY = nY;
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir         if( nY + nHeight > mnClipY + mnClipHeight )
137cdf0e10cSrcweir             mnClipHeight = nY + nHeight - mnClipY;
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir     else
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         mnClipX = nX;
142cdf0e10cSrcweir         mnClipY = nY;
143cdf0e10cSrcweir         mnClipWidth = nWidth;
144cdf0e10cSrcweir         mnClipHeight = nHeight;
145cdf0e10cSrcweir         mbClip = true;
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir // -----------------------------------------------------------------------
150cdf0e10cSrcweir 
151cdf0e10cSrcweir void AquaSalObject::EndSetClipRegion()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     setClippedPosSize();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // -----------------------------------------------------------------------
157cdf0e10cSrcweir 
158cdf0e10cSrcweir void AquaSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     mnX = nX;
161cdf0e10cSrcweir     mnY = nY;
162cdf0e10cSrcweir     mnWidth = nWidth;
163cdf0e10cSrcweir     mnHeight = nHeight;
164cdf0e10cSrcweir     setClippedPosSize();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // -----------------------------------------------------------------------
168cdf0e10cSrcweir 
169cdf0e10cSrcweir void AquaSalObject::setClippedPosSize()
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     NSRect aViewRect = { { 0, 0 }, { mnWidth, mnHeight } };
172cdf0e10cSrcweir     if( maSysData.pView )
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         NSView *pView = maSysData.pView;
175cdf0e10cSrcweir         [pView setFrame: aViewRect];
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     NSRect aClipViewRect = { { mnX, mnY }, { mnWidth, mnHeight } };
179cdf0e10cSrcweir     NSPoint aClipPt = { 0, 0 };
180cdf0e10cSrcweir     if( mbClip )
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         aClipViewRect.origin.x += mnClipX;
183cdf0e10cSrcweir         aClipViewRect.origin.y += mnClipY;
184cdf0e10cSrcweir         aClipViewRect.size.width = mnClipWidth;
185cdf0e10cSrcweir         aClipViewRect.size.height = mnClipHeight;
186cdf0e10cSrcweir         aClipPt.x = mnClipX;
187cdf0e10cSrcweir         if( mnClipY == 0 )
188cdf0e10cSrcweir             aClipPt.y = mnHeight - mnClipHeight;;
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     mpFrame->VCLToCocoa( aClipViewRect, false );
192cdf0e10cSrcweir     [mpClipView setFrame: aClipViewRect];
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     [mpClipView scrollToPoint: aClipPt];
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir // -----------------------------------------------------------------------
198cdf0e10cSrcweir 
199cdf0e10cSrcweir void AquaSalObject::Show( sal_Bool bVisible )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     if( mpClipView )
202cdf0e10cSrcweir         [mpClipView setHidden: (bVisible ? NO : YES)];
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir // -----------------------------------------------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir void AquaSalObject::Enable( sal_Bool )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir // -----------------------------------------------------------------------
212cdf0e10cSrcweir 
213cdf0e10cSrcweir void AquaSalObject::GrabFocus()
214cdf0e10cSrcweir {
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir // -----------------------------------------------------------------------
218cdf0e10cSrcweir 
219cdf0e10cSrcweir void AquaSalObject::SetBackground()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // -----------------------------------------------------------------------
224cdf0e10cSrcweir 
225cdf0e10cSrcweir void AquaSalObject::SetBackground( SalColor )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir // -----------------------------------------------------------------------
230cdf0e10cSrcweir 
231cdf0e10cSrcweir const SystemEnvData* AquaSalObject::GetSystemData() const
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	return &maSysData;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir // -----------------------------------------------------------------------
237cdf0e10cSrcweir 
238cdf0e10cSrcweir void AquaSalObject::InterceptChildWindowKeyDown( sal_Bool /*bIntercept*/ )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242