1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <rtl/ustrbuf.hxx>
21 
22 #include <vcl/stdtext.hxx>
23 
24 #include <osx/salsys.h>
25 #include <osx/saldata.hxx>
26 #include <osx/salinst.h>
27 #include <quartz/utils.h>
28 
29 #include <strings.hrc>
30 
~AquaSalSystem()31 AquaSalSystem::~AquaSalSystem()
32 {
33 }
34 
GetDisplayScreenCount()35 unsigned int AquaSalSystem::GetDisplayScreenCount()
36 {
37     NSArray* pScreens = [NSScreen screens];
38     return pScreens ? [pScreens count] : 1;
39 }
40 
GetDisplayScreenPosSizePixel(unsigned int nScreen)41 tools::Rectangle AquaSalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen )
42 {
43     if (Application::IsBitmapRendering())
44     {
45         tools::Rectangle aRect;
46         if (nScreen == 0)
47             aRect = tools::Rectangle(Point(0,0), Size(1024, 768));
48         return aRect;
49     }
50 
51     NSArray* pScreens = [NSScreen screens];
52     tools::Rectangle aRet;
53     NSScreen* pScreen = nil;
54     if( pScreens && nScreen < [pScreens count] )
55         pScreen = [pScreens objectAtIndex: nScreen];
56     else
57         pScreen = [NSScreen mainScreen];
58 
59     if( pScreen )
60     {
61         NSRect aFrame = [pScreen frame];
62         aRet = tools::Rectangle( Point( static_cast<long int>(aFrame.origin.x), static_cast<long int>(aFrame.origin.y) ),
63                           Size( static_cast<long int>(aFrame.size.width), static_cast<long int>(aFrame.size.height) ) );
64     }
65     return aRet;
66 }
67 
getStandardString(StandardButtonType nButtonId,bool bUseResources)68 static NSString* getStandardString( StandardButtonType nButtonId, bool bUseResources )
69 {
70     OUString aText;
71     if( bUseResources )
72     {
73         aText = GetStandardText( nButtonId );
74     }
75     if( aText.isEmpty() ) // this is for bad cases, we might be missing the vcl resource
76     {
77         switch( nButtonId )
78         {
79         case StandardButtonType::OK:         aText = "OK";break;
80         case StandardButtonType::Abort:      aText = "Abort";break;
81         case StandardButtonType::Cancel:     aText = "Cancel";break;
82         case StandardButtonType::Retry:      aText = "Retry";break;
83         case StandardButtonType::Yes:        aText = "Yes";break;
84         case StandardButtonType::No:         aText = "No";break;
85         default: break;
86         }
87     }
88     return aText.isEmpty() ? nil : CreateNSString( aText);
89 }
90 
ShowNativeMessageBox(const OUString & rTitle,const OUString & rMessage)91 int AquaSalSystem::ShowNativeMessageBox( const OUString& rTitle,
92                                         const OUString& rMessage )
93 {
94     NSString* pTitle = CreateNSString( rTitle );
95     NSString* pMessage = CreateNSString( rMessage );
96 
97     NSString* pDefText = getStandardString( StandardButtonType::OK, false/*bUseResources*/ );
98 
99     SAL_WNODEPRECATED_DECLARATIONS_PUSH //TODO: 10.10 NSRunAlertPanel
100     int nResult = NSRunAlertPanel( pTitle, @"%@", pDefText, nil, nil, pMessage );
101     SAL_WNODEPRECATED_DECLARATIONS_POP
102 
103     if( pTitle )
104         [pTitle release];
105     if( pMessage )
106         [pMessage release];
107     if( pDefText )
108         [pDefText release];
109 
110     int nRet = 0;
111     if( nResult == 1 )
112         nRet = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK;
113 
114     return nRet;
115 }
116 
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
118