1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <config_folders.h>
22 #include <generic/gensys.h>
24 #include <vcl/msgbox.hxx>
25 #include <vcl/button.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <rtl/strbuf.hxx>
31 #include <rtl/bootstrap.hxx>
32 #include <osl/process.h>
33 #include <osl/thread.h>
34 #include <unotools/configmgr.hxx>
36 #include "vcl/unohelp.hxx"
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 using namespace com::sun::star
;
45 OUString
GetNativeMessageBoxButtonText( StandardButtonType nButtonId
, bool bUseResources
)
50 aText
= Button::GetStandardText( nButtonId
);
56 case StandardButtonType::OK
:
59 case StandardButtonType::Cancel
:
62 case StandardButtonType::Abort
:
65 case StandardButtonType::Retry
:
68 case StandardButtonType::Ignore
:
71 case StandardButtonType::Yes
:
74 case StandardButtonType::No
:
85 SalGenericSystem::SalGenericSystem()
89 SalGenericSystem::~SalGenericSystem()
93 int SalGenericSystem::ShowNativeMessageBox( const OUString
& rTitle
, const OUString
& rMessage
,
94 int nButtonCombination
, int nDefaultButton
,
98 std::list
< OUString
> aButtons
;
99 int nButtonIds
[5] = {0}, nBut
= 0;
103 if( nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK
||
104 nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL
)
106 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::OK
, bUseResources
) );
107 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK
;
109 if( nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL
||
110 nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO
)
112 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Yes
, bUseResources
) );
113 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES
;
114 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::No
, bUseResources
) );
115 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO
;
116 if( nDefaultButton
== SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO
)
119 if( nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL
||
120 nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL
||
121 nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL
)
123 if( nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL
)
125 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Retry
, bUseResources
) );
126 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY
;
128 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Cancel
, bUseResources
) );
129 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
;
130 if( nDefaultButton
== SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL
)
131 nDefButton
= aButtons
.size()-1;
133 if( nButtonCombination
== SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE
)
135 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Abort
, bUseResources
) );
136 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT
;
137 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Retry
, bUseResources
) );
138 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY
;
139 aButtons
.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Ignore
, bUseResources
) );
140 nButtonIds
[nBut
++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE
;
141 switch( nDefaultButton
)
143 case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY
: nDefButton
= 1;break;
144 case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE
: nDefButton
= 2;break;
148 int nResult
= ShowNativeDialog( rTitle
, rMessage
, aButtons
, nDefButton
);
150 return nResult
!= -1 ? nButtonIds
[ nResult
] : 0;
153 #if !defined(ANDROID) && !defined(IOS)
157 const char* SalGenericSystem::getFrameResName()
159 /* according to ICCCM:
160 * first search command line for -name parameter
161 * then try RESOURCE_NAME environment variable
162 * then use argv[0] stripped by directories
164 static OStringBuffer aResName
;
165 if( aResName
.isEmpty() )
167 int nArgs
= osl_getCommandArgCount();
168 for( int n
= 0; n
< nArgs
-1; n
++ )
171 osl_getCommandArg( n
, &aArg
.pData
);
172 if( aArg
.equalsIgnoreAsciiCase("-name") )
174 osl_getCommandArg( n
+1, &aArg
.pData
);
175 aResName
.append( OUStringToOString( aArg
, osl_getThreadTextEncoding() ) );
179 if( aResName
.isEmpty() )
181 const char* pEnv
= getenv( "RESOURCE_NAME" );
183 aResName
.append( pEnv
);
185 if( aResName
.isEmpty() )
186 aResName
.append( OUStringToOString( utl::ConfigManager::getProductName().toAsciiLowerCase(),
187 osl_getThreadTextEncoding()));
189 return aResName
.getStr();
192 const char* SalGenericSystem::getFrameClassName()
194 static OStringBuffer aClassName
;
195 if( aClassName
.isEmpty() )
197 OUString aIni
, aProduct
;
198 rtl::Bootstrap::get( "BRAND_BASE_DIR", aIni
);
199 aIni
+= "/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE( "bootstrap" );
200 rtl::Bootstrap
aBootstrap( aIni
);
201 aBootstrap
.getFrom( "ProductKey", aProduct
);
203 if( !aProduct
.isEmpty() )
204 aClassName
.append( OUStringToOString( aProduct
, osl_getThreadTextEncoding() ) );
206 aClassName
.append( OUStringToOString( utl::ConfigManager::getProductName(), osl_getThreadTextEncoding()));
208 return aClassName
.getStr();
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */