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