Update ooo320-m1
[ooovba.git] / vcl / unx / source / app / salsys.cxx
blob2bdef264960096ed9406266dd6e8a8b81083694b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salsys.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include <salunx.h>
35 #include <vcl/salsys.hxx>
36 #include <dtint.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <vcl/button.hxx>
39 #include <vcl/svdata.hxx>
40 #include <saldata.hxx>
41 #include <salinst.h>
42 #include <saldisp.hxx>
43 #include <salsys.h>
45 #include <rtl/ustrbuf.hxx>
46 #include <osl/thread.h>
49 SalSystem* X11SalInstance::CreateSalSystem()
51 return new X11SalSystem();
54 // -----------------------------------------------------------------------
56 X11SalSystem::~X11SalSystem()
60 // for the moment only handle xinerama case
61 unsigned int X11SalSystem::GetDisplayScreenCount()
63 SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
64 return pSalDisp->IsXinerama() ? pSalDisp->GetXineramaScreens().size() : pSalDisp->GetScreenCount();
67 bool X11SalSystem::IsMultiDisplay()
69 SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
70 unsigned int nScreenCount = pSalDisp->GetScreenCount();
71 return pSalDisp->IsXinerama() ? false : (nScreenCount > 1);
74 unsigned int X11SalSystem::GetDefaultDisplayNumber()
76 SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
77 return pSalDisp->GetDefaultScreenNumber();
80 Rectangle X11SalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen )
82 Rectangle aRet;
83 SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
84 if( pSalDisp->IsXinerama() )
86 const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
87 if( nScreen < rScreens.size() )
88 aRet = rScreens[nScreen];
90 else
92 const SalDisplay::ScreenData& rScreen = pSalDisp->getDataForScreen( nScreen );
93 aRet = Rectangle( Point( 0, 0 ), rScreen.m_aSize );
96 return aRet;
99 Rectangle X11SalSystem::GetDisplayWorkAreaPosSizePixel( unsigned int nScreen )
101 // FIXME: workareas
102 return GetDisplayScreenPosSizePixel( nScreen );
105 rtl::OUString X11SalSystem::GetScreenName( unsigned int nScreen )
107 rtl::OUString aScreenName;
108 SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
109 if( pSalDisp->IsXinerama() )
111 const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
112 if( nScreen >= rScreens.size() )
113 nScreen = 0;
114 rtl::OUStringBuffer aBuf( 256 );
115 aBuf.append( rtl::OStringToOUString( rtl::OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
116 aBuf.appendAscii( " [" );
117 aBuf.append( static_cast<sal_Int32>(nScreen) );
118 aBuf.append( sal_Unicode(']') );
119 aScreenName = aBuf.makeStringAndClear();
121 else
123 if( nScreen >= static_cast<unsigned int>(pSalDisp->GetScreenCount()) )
124 nScreen = 0;
125 rtl::OUStringBuffer aBuf( 256 );
126 aBuf.append( rtl::OStringToOUString( rtl::OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
127 // search backwards for ':'
128 int nPos = aBuf.getLength();
129 if( nPos > 0 )
130 nPos--;
131 while( nPos > 0 && aBuf.charAt( nPos ) != ':' )
132 nPos--;
133 // search forward to '.'
134 while( nPos < aBuf.getLength() && aBuf.charAt( nPos ) != '.' )
135 nPos++;
136 if( nPos < aBuf.getLength() )
137 aBuf.setLength( nPos+1 );
138 else
139 aBuf.append( sal_Unicode('.') );
140 aBuf.append( static_cast<sal_Int32>(nScreen) );
141 aScreenName = aBuf.makeStringAndClear();
143 return aScreenName;
146 int X11SalSystem::ShowNativeDialog( const String& rTitle, const String& rMessage, const std::list< String >& rButtons, int nDefButton )
148 int nRet = -1;
150 ImplSVData* pSVData = ImplGetSVData();
151 if( pSVData->mpIntroWindow )
152 pSVData->mpIntroWindow->Hide();
154 WarningBox aWarn( NULL, WB_STDWORK, rMessage );
155 aWarn.SetText( rTitle );
156 aWarn.Clear();
158 USHORT nButton = 0;
159 for( std::list< String >::const_iterator it = rButtons.begin(); it != rButtons.end(); ++it )
161 aWarn.AddButton( *it, nButton+1, nButton == (USHORT)nDefButton ? BUTTONDIALOG_DEFBUTTON : 0 );
162 nButton++;
164 aWarn.SetFocusButton( (USHORT)nDefButton+1 );
166 nRet = ((int)aWarn.Execute()) - 1;
168 // normalize behaviour, actually this should never happen
169 if( nRet < -1 || nRet >= int(rButtons.size()) )
170 nRet = -1;
172 return nRet;
175 int X11SalSystem::ShowNativeMessageBox(const String& rTitle, const String& rMessage, int nButtonCombination, int nDefaultButton)
177 int nDefButton = 0;
178 std::list< String > aButtons;
179 int nButtonIds[5], nBut = 0;
181 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK ||
182 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL )
184 aButtons.push_back( Button::GetStandardText( BUTTON_OK ) );
185 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK;
187 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
188 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO )
190 aButtons.push_back( Button::GetStandardText( BUTTON_YES ) );
191 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES;
192 aButtons.push_back( Button::GetStandardText( BUTTON_NO ) );
193 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO;
194 if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO )
195 nDefButton = 1;
197 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL ||
198 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
199 nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
201 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
203 aButtons.push_back( Button::GetStandardText( BUTTON_RETRY ) );
204 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
206 aButtons.push_back( Button::GetStandardText( BUTTON_CANCEL ) );
207 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL;
208 if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL )
209 nDefButton = aButtons.size()-1;
211 if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE )
213 aButtons.push_back( Button::GetStandardText( BUTTON_ABORT ) );
214 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT;
215 aButtons.push_back( Button::GetStandardText( BUTTON_RETRY ) );
216 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
217 aButtons.push_back( Button::GetStandardText( BUTTON_IGNORE ) );
218 nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE;
219 switch( nDefaultButton )
221 case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY: nDefButton = 1;break;
222 case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE: nDefButton = 2;break;
225 int nResult = ShowNativeDialog( rTitle, rMessage, aButtons, nDefButton );
227 return nResult != -1 ? nButtonIds[ nResult ] : 0;