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