Line data Source code
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 <config_folders.h>
21 :
22 : #include <generic/gensys.h>
23 :
24 : #include <vcl/msgbox.hxx>
25 : #include <vcl/button.hxx>
26 :
27 : #include <svdata.hxx>
28 :
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>
35 :
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>
40 :
41 : using namespace com::sun::star;
42 :
43 : namespace {
44 :
45 0 : OUString GetNativeMessageBoxButtonText( int nButtonId, bool bUseResources )
46 : {
47 0 : OUString aText;
48 0 : if( bUseResources )
49 : {
50 0 : aText = Button::GetStandardText( nButtonId );
51 : }
52 0 : if( aText.isEmpty() )
53 : {
54 0 : switch( nButtonId )
55 : {
56 : case BUTTON_OK:
57 0 : aText = "OK";
58 0 : break;
59 : case BUTTON_CANCEL:
60 0 : aText = "Cancel";
61 0 : break;
62 : case BUTTON_ABORT:
63 0 : aText = "Abort";
64 0 : break;
65 : case BUTTON_RETRY:
66 0 : aText = "Retry";
67 0 : break;
68 : case BUTTON_IGNORE:
69 0 : aText = "Ignore";
70 0 : break;
71 : case BUTTON_YES:
72 0 : aText = "Yes";
73 0 : break;
74 : case BUTTON_NO:
75 0 : aText = "No";
76 0 : break;
77 : }
78 : }
79 0 : return aText;
80 : }
81 :
82 : }
83 :
84 0 : SalGenericSystem::SalGenericSystem()
85 : {
86 0 : }
87 :
88 0 : SalGenericSystem::~SalGenericSystem()
89 : {
90 0 : }
91 :
92 0 : int SalGenericSystem::ShowNativeMessageBox( const OUString& rTitle, const OUString& rMessage,
93 : int nButtonCombination, int nDefaultButton,
94 : bool bUseResources )
95 : {
96 0 : int nDefButton = 0;
97 0 : std::list< OUString > aButtons;
98 0 : int nButtonIds[5] = {0}, nBut = 0;
99 :
100 0 : ImplHideSplash();
101 :
102 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK ||
103 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL )
104 : {
105 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_OK, bUseResources ) );
106 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK;
107 : }
108 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
109 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO )
110 : {
111 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_YES, bUseResources ) );
112 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES;
113 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_NO, bUseResources ) );
114 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO;
115 0 : if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO )
116 0 : nDefButton = 1;
117 : }
118 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL ||
119 0 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
120 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
121 : {
122 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
123 : {
124 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_RETRY, bUseResources ) );
125 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
126 : }
127 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_CANCEL, bUseResources ) );
128 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL;
129 0 : if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL )
130 0 : nDefButton = aButtons.size()-1;
131 : }
132 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE )
133 : {
134 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_ABORT, bUseResources ) );
135 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT;
136 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_RETRY, bUseResources ) );
137 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
138 0 : aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_IGNORE, bUseResources ) );
139 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE;
140 0 : switch( nDefaultButton )
141 : {
142 0 : case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY: nDefButton = 1;break;
143 0 : case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE: nDefButton = 2;break;
144 : }
145 : }
146 :
147 0 : int nResult = ShowNativeDialog( rTitle, rMessage, aButtons, nDefButton );
148 :
149 0 : return nResult != -1 ? nButtonIds[ nResult ] : 0;
150 : }
151 :
152 : #if !defined(ANDROID) && !defined(IOS)
153 :
154 : // X11-specific
155 :
156 0 : const char* SalGenericSystem::getFrameResName()
157 : {
158 : /* according to ICCCM:
159 : * first search command line for -name parameter
160 : * then try RESOURCE_NAME environment variable
161 : * then use argv[0] stripped by directories
162 : */
163 0 : static OStringBuffer aResName;
164 0 : if( aResName.isEmpty() )
165 : {
166 0 : int nArgs = osl_getCommandArgCount();
167 0 : for( int n = 0; n < nArgs-1; n++ )
168 : {
169 0 : OUString aArg;
170 0 : if( ! osl_getCommandArg( n, &aArg.pData ) &&
171 0 : aArg.equalsIgnoreAsciiCase("-name") &&
172 0 : ! osl_getCommandArg( n+1, &aArg.pData ) )
173 : {
174 0 : aResName.append( OUStringToOString( aArg, osl_getThreadTextEncoding() ) );
175 0 : break;
176 : }
177 0 : }
178 0 : if( aResName.isEmpty() )
179 : {
180 0 : const char* pEnv = getenv( "RESOURCE_NAME" );
181 0 : if( pEnv && *pEnv )
182 0 : aResName.append( pEnv );
183 : }
184 0 : if( aResName.isEmpty() )
185 : aResName.append( OUStringToOString( utl::ConfigManager::getProductName().toAsciiLowerCase(),
186 0 : osl_getThreadTextEncoding()));
187 : }
188 0 : return aResName.getStr();
189 : }
190 :
191 0 : const char* SalGenericSystem::getFrameClassName()
192 : {
193 0 : static OStringBuffer aClassName;
194 0 : if( aClassName.isEmpty() )
195 : {
196 0 : OUString aIni, aProduct;
197 0 : rtl::Bootstrap::get( "BRAND_BASE_DIR", aIni );
198 0 : aIni += "/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" );
199 0 : rtl::Bootstrap aBootstrap( aIni );
200 0 : aBootstrap.getFrom( "ProductKey", aProduct );
201 :
202 0 : if( !aProduct.isEmpty() )
203 0 : aClassName.append( OUStringToOString( aProduct, osl_getThreadTextEncoding() ) );
204 : else
205 0 : aClassName.append( OUStringToOString( utl::ConfigManager::getProductName(), osl_getThreadTextEncoding()));
206 : }
207 0 : return aClassName.getStr();
208 : }
209 :
210 : #endif
211 :
212 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|