bump product version to 4.1.6.2
[LibreOffice.git] / vcl / generic / app / gensys.cxx
blob68d2192f00b5b564670a88254ff9c5a0a85625a1
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 <generic/gensys.h>
22 #include <vcl/msgbox.hxx>
23 #include <vcl/button.hxx>
25 #include <svdata.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <rtl/strbuf.hxx>
29 #include <rtl/bootstrap.hxx>
30 #include <osl/process.h>
31 #include <osl/thread.h>
33 #include "vcl/unohelp.hxx"
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 using namespace com::sun::star;
40 namespace {
42 OUString GetNativeMessageBoxButtonText( int nButtonId, bool bUseResources )
44 OUString aText;
45 if( bUseResources )
47 aText = Button::GetStandardText( nButtonId );
49 if( aText.isEmpty() )
51 switch( nButtonId )
53 case BUTTON_OK:
54 aText = "OK";
55 break;
56 case BUTTON_CANCEL:
57 aText = "Cancel";
58 break;
59 case BUTTON_ABORT:
60 aText = "Abort";
61 break;
62 case BUTTON_RETRY:
63 aText = "Retry";
64 break;
65 case BUTTON_IGNORE:
66 aText = "Ignore";
67 break;
68 case BUTTON_YES:
69 aText = "Yes";
70 break;
71 case BUTTON_NO:
72 aText = "No";
73 break;
76 return aText;
81 SalGenericSystem::SalGenericSystem()
85 SalGenericSystem::~SalGenericSystem()
89 int SalGenericSystem::ShowNativeMessageBox( const OUString& rTitle, const OUString& rMessage,
90 int nButtonCombination, int nDefaultButton,
91 bool bUseResources )
93 int nDefButton = 0;
94 std::list< OUString > aButtons;
95 int nButtonIds[5], nBut = 0;
97 ImplHideSplash();
99 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK ||
100 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL )
102 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_OK, bUseResources ) );
103 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK;
105 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
106 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO )
108 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_YES, bUseResources ) );
109 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES;
110 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_NO, bUseResources ) );
111 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO;
112 if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO )
113 nDefButton = 1;
115 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL ||
116 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
117 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
119 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
121 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_RETRY, bUseResources ) );
122 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
124 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_CANCEL, bUseResources ) );
125 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL;
126 if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL )
127 nDefButton = aButtons.size()-1;
129 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE )
131 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_ABORT, bUseResources ) );
132 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT;
133 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_RETRY, bUseResources ) );
134 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
135 aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_IGNORE, bUseResources ) );
136 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE;
137 switch( nDefaultButton )
139 case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY: nDefButton = 1;break;
140 case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE: nDefButton = 2;break;
144 int nResult = ShowNativeDialog( rTitle, rMessage, aButtons, nDefButton );
146 return nResult != -1 ? nButtonIds[ nResult ] : 0;
149 #if !defined(ANDROID) && !defined(IOS)
151 // X11-specific
153 const char* SalGenericSystem::getFrameResName()
155 /* according to ICCCM:
156 * first search command line for -name parameter
157 * then try RESOURCE_NAME environment variable
158 * then use argv[0] stripped by directories
160 static OStringBuffer aResName;
161 if( !aResName.getLength() )
163 int nArgs = osl_getCommandArgCount();
164 for( int n = 0; n < nArgs-1; n++ )
166 OUString aArg;
167 if( ! osl_getCommandArg( n, &aArg.pData ) &&
168 aArg.equalsIgnoreAsciiCase("-name") &&
169 ! osl_getCommandArg( n+1, &aArg.pData ) )
171 aResName.append( OUStringToOString( aArg, osl_getThreadTextEncoding() ) );
172 break;
175 if( !aResName.getLength() )
177 const char* pEnv = getenv( "RESOURCE_NAME" );
178 if( pEnv && *pEnv )
179 aResName.append( pEnv );
181 if( !aResName.getLength() )
182 aResName.append( "VCLSalFrame" );
184 return aResName.getStr();
187 const char* SalGenericSystem::getFrameClassName()
189 static OStringBuffer aClassName;
190 if( !aClassName.getLength() )
192 OUString aIni, aProduct;
193 rtl::Bootstrap::get( "BRAND_BASE_DIR", aIni );
194 aIni += "/program/" SAL_CONFIGFILE( "bootstrap" );
195 rtl::Bootstrap aBootstrap( aIni );
196 aBootstrap.getFrom( "ProductKey", aProduct );
198 if( !aProduct.isEmpty() )
199 aClassName.append( OUStringToOString( aProduct, osl_getThreadTextEncoding() ) );
200 else
201 aClassName.append( "VCLSalFrame" );
203 return aClassName.getStr();
206 OString SalGenericSystem::getFrameResName( SalExtStyle nStyle )
208 OStringBuffer aBuf( 64 );
209 aBuf.append( getFrameResName() );
210 if( (nStyle & SAL_FRAME_EXT_STYLE_DOCUMENT) )
211 aBuf.append( ".DocumentWindow" );
213 return aBuf.makeStringAndClear();
216 #endif
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */