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 "tools/rc.hxx" 32 33 #include "rtl/ustrbuf.hxx" 34 35 #include "vcl/button.hxx" 36 37 #include "aqua/salsys.h" 38 #include "aqua/saldata.hxx" 39 #include "aqua/salinst.h" 40 41 #include "svids.hrc" 42 43 using namespace rtl; 44 45 // ======================================================================= 46 47 AquaSalSystem::~AquaSalSystem() 48 { 49 } 50 51 unsigned int AquaSalSystem::GetDisplayScreenCount() 52 { 53 NSArray* pScreens = [NSScreen screens]; 54 return pScreens ? [pScreens count] : 1; 55 } 56 57 bool AquaSalSystem::IsMultiDisplay() 58 { 59 return false; 60 } 61 62 unsigned int AquaSalSystem::GetDefaultDisplayNumber() 63 { 64 return 0; 65 } 66 67 Rectangle AquaSalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen ) 68 { 69 NSArray* pScreens = [NSScreen screens]; 70 Rectangle aRet; 71 NSScreen* pScreen = nil; 72 if( pScreens && nScreen < [pScreens count] ) 73 pScreen = [pScreens objectAtIndex: nScreen]; 74 else 75 pScreen = [NSScreen mainScreen]; 76 77 if( pScreen ) 78 { 79 NSRect aFrame = [pScreen frame]; 80 aRet = Rectangle( Point( static_cast<long int>(aFrame.origin.x), static_cast<long int>(aFrame.origin.y) ), 81 Size( static_cast<long int>(aFrame.size.width), static_cast<long int>(aFrame.size.height) ) ); 82 } 83 return aRet; 84 } 85 86 Rectangle AquaSalSystem::GetDisplayWorkAreaPosSizePixel( unsigned int nScreen ) 87 { 88 NSArray* pScreens = [NSScreen screens]; 89 Rectangle aRet; 90 NSScreen* pScreen = nil; 91 if( pScreens && nScreen < [pScreens count] ) 92 pScreen = [pScreens objectAtIndex: nScreen]; 93 else 94 pScreen = [NSScreen mainScreen]; 95 96 if( pScreen ) 97 { 98 NSRect aFrame = [pScreen visibleFrame]; 99 aRet = Rectangle( Point( static_cast<long int>(aFrame.origin.x), static_cast<long int>(aFrame.origin.y) ), 100 Size( static_cast<long int>(aFrame.size.width), static_cast<long int>(aFrame.size.height) ) ); 101 } 102 return aRet; 103 } 104 105 rtl::OUString AquaSalSystem::GetScreenName( unsigned int nScreen ) 106 { 107 NSArray* pScreens = [NSScreen screens]; 108 OUString aRet; 109 if( nScreen < [pScreens count] ) 110 { 111 ResMgr* pMgr = ImplGetResMgr(); 112 if( pMgr ) 113 { 114 String aScreenName( ResId( SV_MAC_SCREENNNAME, *pMgr ) ); 115 aScreenName.SearchAndReplaceAllAscii( "%d", String::CreateFromInt32( nScreen ) ); 116 aRet = aScreenName; 117 } 118 } 119 return aRet; 120 } 121 122 static NSString* getStandardString( int nButtonId ) 123 { 124 rtl::OUString aText( Button::GetStandardText( nButtonId ) ); 125 if( ! aText.getLength() ) // this is for bad cases, we might be missing the vcl resource 126 { 127 switch( nButtonId ) 128 { 129 case BUTTON_OK: aText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OK" ) );break; 130 case BUTTON_ABORT: aText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Abort" ) );break; 131 case BUTTON_CANCEL: aText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cancel" ) );break; 132 case BUTTON_RETRY: aText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Retry" ) );break; 133 case BUTTON_YES: aText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Yes" ) );break; 134 case BUTTON_NO : aText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No" ) );break; 135 } 136 } 137 return aText.getLength() ? CreateNSString( aText) : nil; 138 } 139 140 int AquaSalSystem::ShowNativeMessageBox( const String& rTitle, 141 const String& rMessage, 142 int nButtonCombination, 143 int nDefaultButton) 144 { 145 NSString* pTitle = CreateNSString( rTitle ); 146 NSString* pMessage = CreateNSString( rMessage ); 147 148 struct id_entry 149 { 150 int nCombination; 151 int nDefaultButton; 152 int nTextIds[3]; 153 } aButtonIds[] = 154 { 155 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK, { BUTTON_OK, -1, -1 } }, 156 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK, { BUTTON_OK, BUTTON_CANCEL, -1 } }, 157 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, { BUTTON_CANCEL, BUTTON_OK, -1 } }, 158 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT, { BUTTON_ABORT, BUTTON_IGNORE, BUTTON_RETRY } }, 159 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY, { BUTTON_RETRY, BUTTON_IGNORE, BUTTON_ABORT } }, 160 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE, { BUTTON_IGNORE, BUTTON_IGNORE, BUTTON_ABORT } }, 161 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES, { BUTTON_YES, BUTTON_NO, BUTTON_CANCEL } }, 162 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO, { BUTTON_NO, BUTTON_YES, BUTTON_CANCEL } }, 163 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, { BUTTON_CANCEL, BUTTON_YES, BUTTON_NO } }, 164 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES, { BUTTON_YES, BUTTON_NO, -1 } }, 165 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO, { BUTTON_NO, BUTTON_YES, -1 } }, 166 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY, { BUTTON_RETRY, BUTTON_CANCEL, -1 } }, 167 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, { BUTTON_CANCEL, BUTTON_RETRY, -1 } } 168 }; 169 170 NSString* pDefText = nil; 171 NSString* pAltText = nil; 172 NSString* pOthText = nil; 173 174 unsigned int nC; 175 for( nC = 0; nC < sizeof(aButtonIds)/sizeof(aButtonIds[0]); nC++ ) 176 { 177 if( aButtonIds[nC].nCombination == nButtonCombination ) 178 { 179 if( aButtonIds[nC].nDefaultButton == nDefaultButton ) 180 { 181 if( aButtonIds[nC].nTextIds[0] != -1 ) 182 pDefText = getStandardString( aButtonIds[nC].nTextIds[0] ); 183 if( aButtonIds[nC].nTextIds[1] != -1 ) 184 pAltText = getStandardString( aButtonIds[nC].nTextIds[1] ); 185 if( aButtonIds[nC].nTextIds[2] != -1 ) 186 pOthText = getStandardString( aButtonIds[nC].nTextIds[2] ); 187 break; 188 } 189 } 190 } 191 192 193 int nResult = NSRunAlertPanel( pTitle, pMessage, pDefText, pAltText, pOthText ); 194 195 if( pTitle ) 196 [pTitle release]; 197 if( pMessage ) 198 [pMessage release]; 199 if( pDefText ) 200 [pDefText release]; 201 if( pAltText ) 202 [pAltText release]; 203 if( pOthText ) 204 [pOthText release]; 205 206 int nRet = 0; 207 if( nC < sizeof(aButtonIds)/sizeof(aButtonIds[0]) && nResult >= 1 && nResult <= 3 ) 208 { 209 int nPressed = aButtonIds[nC].nTextIds[nResult-1]; 210 switch( nPressed ) 211 { 212 case BUTTON_NO: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO; break; 213 case BUTTON_YES: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES; break; 214 case BUTTON_OK: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK; break; 215 case BUTTON_CANCEL: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL; break; 216 case BUTTON_ABORT: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT; break; 217 case BUTTON_RETRY: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY; break; 218 case BUTTON_IGNORE: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE; break; 219 } 220 } 221 222 return nRet; 223 } 224