Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / osx / salsys.cxx
bloba60f26078316b99ba07208fd4e689e7d69720117
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 .
20 #include "rtl/ustrbuf.hxx"
22 #include "vcl/button.hxx"
24 #include "osx/salsys.h"
25 #include "osx/saldata.hxx"
26 #include "osx/salinst.h"
27 #include "quartz/utils.h"
29 #include "svids.hrc"
31 AquaSalSystem::~AquaSalSystem()
35 unsigned int AquaSalSystem::GetDisplayScreenCount()
37 NSArray* pScreens = [NSScreen screens];
38 return pScreens ? [pScreens count] : 1;
41 Rectangle AquaSalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen )
43 NSArray* pScreens = [NSScreen screens];
44 Rectangle aRet;
45 NSScreen* pScreen = nil;
46 if( pScreens && nScreen < [pScreens count] )
47 pScreen = [pScreens objectAtIndex: nScreen];
48 else
49 pScreen = [NSScreen mainScreen];
51 if( pScreen )
53 NSRect aFrame = [pScreen frame];
54 aRet = Rectangle( Point( static_cast<long int>(aFrame.origin.x), static_cast<long int>(aFrame.origin.y) ),
55 Size( static_cast<long int>(aFrame.size.width), static_cast<long int>(aFrame.size.height) ) );
57 return aRet;
60 OUString AquaSalSystem::GetDisplayScreenName( unsigned int nScreen )
62 NSArray* pScreens = [NSScreen screens];
63 OUString aRet;
64 if( nScreen < [pScreens count] )
66 ResMgr* pMgr = ImplGetResMgr();
67 if( pMgr )
69 OUString aScreenName(ResId(SV_MAC_SCREENNNAME, *pMgr).toString());
70 aRet = aScreenName.replaceAll("%d", OUString::number(nScreen));
73 return aRet;
76 static NSString* getStandardString( StandardButtonType nButtonId, bool bUseResources )
78 OUString aText;
79 if( bUseResources )
81 aText = Button::GetStandardText( nButtonId );
83 if( aText.isEmpty() ) // this is for bad cases, we might be missing the vcl resource
85 switch( nButtonId )
87 case StandardButtonType::OK: aText = "OK";break;
88 case StandardButtonType::Abort: aText = "Abort";break;
89 case StandardButtonType::Cancel: aText = "Cancel";break;
90 case StandardButtonType::Retry: aText = "Retry";break;
91 case StandardButtonType::Yes: aText = "Yes";break;
92 case StandardButtonType::No: aText = "No";break;
93 default: break;
96 return aText.isEmpty() ? nil : CreateNSString( aText);
99 #define NO_BUTTON static_cast<StandardButtonType>(-1)
101 int AquaSalSystem::ShowNativeMessageBox( const OUString& rTitle,
102 const OUString& rMessage,
103 int nButtonCombination,
104 int nDefaultButton, bool bUseResources)
106 NSString* pTitle = CreateNSString( rTitle );
107 NSString* pMessage = CreateNSString( rMessage );
109 struct id_entry
111 int nCombination;
112 int nDefaultButton;
113 StandardButtonType nTextIds[3];
114 } aButtonIds[] =
116 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK, { StandardButtonType::OK, NO_BUTTON, NO_BUTTON } },
117 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK, { StandardButtonType::OK, StandardButtonType::Cancel, NO_BUTTON } },
118 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, { StandardButtonType::Cancel, StandardButtonType::OK, NO_BUTTON } },
119 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT, { StandardButtonType::Abort, StandardButtonType::Ignore, StandardButtonType::Retry } },
120 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY, { StandardButtonType::Retry, StandardButtonType::Ignore, StandardButtonType::Abort } },
121 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE, { StandardButtonType::Ignore, StandardButtonType::Ignore, StandardButtonType::Abort } },
122 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES, { StandardButtonType::Yes, StandardButtonType::No, StandardButtonType::Cancel } },
123 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO, { StandardButtonType::No, StandardButtonType::Yes, StandardButtonType::Cancel } },
124 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, { StandardButtonType::Cancel, StandardButtonType::Yes, StandardButtonType::No } },
125 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES, { StandardButtonType::Yes, StandardButtonType::No, NO_BUTTON } },
126 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO, { StandardButtonType::No, StandardButtonType::Yes, NO_BUTTON } },
127 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY, { StandardButtonType::Retry, StandardButtonType::Cancel, NO_BUTTON } },
128 { SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL, SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL, { StandardButtonType::Cancel, StandardButtonType::Retry, NO_BUTTON } }
131 NSString* pDefText = nil;
132 NSString* pAltText = nil;
133 NSString* pOthText = nil;
135 unsigned int nC;
136 for( nC = 0; nC < sizeof(aButtonIds)/sizeof(aButtonIds[0]); nC++ )
138 if( aButtonIds[nC].nCombination == nButtonCombination )
140 if( aButtonIds[nC].nDefaultButton == nDefaultButton )
142 if( aButtonIds[nC].nTextIds[0] != NO_BUTTON )
143 pDefText = getStandardString(
144 aButtonIds[nC].nTextIds[0], bUseResources );
145 if( aButtonIds[nC].nTextIds[1] != NO_BUTTON )
146 pAltText = getStandardString(
147 aButtonIds[nC].nTextIds[1], bUseResources );
148 if( aButtonIds[nC].nTextIds[2] != NO_BUTTON )
149 pOthText = getStandardString(
150 aButtonIds[nC].nTextIds[2], bUseResources );
151 break;
156 SAL_WNODEPRECATED_DECLARATIONS_PUSH //TODO: 10.10 NSRunAlertPanel
157 int nResult = NSRunAlertPanel( pTitle, @"%@", pDefText, pAltText, pOthText, pMessage );
158 SAL_WNODEPRECATED_DECLARATIONS_POP
160 if( pTitle )
161 [pTitle release];
162 if( pMessage )
163 [pMessage release];
164 if( pDefText )
165 [pDefText release];
166 if( pAltText )
167 [pAltText release];
168 if( pOthText )
169 [pOthText release];
171 int nRet = 0;
172 if( nC < sizeof(aButtonIds)/sizeof(aButtonIds[0]) && nResult >= 1 && nResult <= 3 )
174 StandardButtonType nPressed = aButtonIds[nC].nTextIds[nResult-1];
175 switch( nPressed )
177 case StandardButtonType::No: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO; break;
178 case StandardButtonType::Yes: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES; break;
179 case StandardButtonType::OK: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK; break;
180 case StandardButtonType::Cancel: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL; break;
181 case StandardButtonType::Abort: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT; break;
182 case StandardButtonType::Retry: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY; break;
183 case StandardButtonType::Ignore: nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE; break;
184 default: break;
188 return nRet;
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */