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