Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / unx / x11 / x11sys.cxx
blobe3eb453fcb375c3ffc80ab6db14996c63bda1c4b
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 <unx/salunx.h>
21 #include <unx/saldata.hxx>
22 #include <unx/salinst.h>
23 #include <unx/saldisp.hxx>
24 #include <unx/x11/x11sys.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <vcl/button.hxx>
29 #include <svdata.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <osl/thread.h>
34 SalSystem* X11SalInstance::CreateSalSystem()
36 return new X11SalSystem();
39 X11SalSystem::~X11SalSystem()
43 // for the moment only handle xinerama case
44 unsigned int X11SalSystem::GetDisplayScreenCount()
46 SalDisplay* pSalDisp = vcl_sal::getSalDisplay(GetGenericData());
47 return pSalDisp->IsXinerama() ? pSalDisp->GetXineramaScreens().size() :
48 pSalDisp->GetXScreenCount();
51 bool X11SalSystem::IsUnifiedDisplay()
53 SalDisplay* pSalDisp = vcl_sal::getSalDisplay(GetGenericData());
54 unsigned int nScreenCount = pSalDisp->GetXScreenCount();
55 return pSalDisp->IsXinerama() || (nScreenCount == 1);
58 unsigned int X11SalSystem::GetDisplayBuiltInScreen()
60 SalDisplay* pSalDisp = vcl_sal::getSalDisplay(GetGenericData());
61 return pSalDisp->GetDefaultXScreen().getXScreen();
64 Rectangle X11SalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen )
66 Rectangle aRet;
67 SalDisplay* pSalDisp = vcl_sal::getSalDisplay(GetGenericData());
68 if( pSalDisp->IsXinerama() )
70 const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
72 // we shouldn't be able to pick a screen > number of screens available
73 assert(nScreen < rScreens.size() );
75 if( nScreen < rScreens.size() )
76 aRet = rScreens[nScreen];
78 else
80 const SalDisplay::ScreenData& rScreen =
81 pSalDisp->getDataForScreen( SalX11Screen( nScreen ) );
82 aRet = Rectangle( Point( 0, 0 ), rScreen.m_aSize );
85 return aRet;
88 OUString X11SalSystem::GetDisplayScreenName( unsigned int nScreen )
90 OUString aScreenName;
91 SalDisplay* pSalDisp = vcl_sal::getSalDisplay(GetGenericData());
92 if( pSalDisp->IsXinerama() )
94 const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
95 if( nScreen >= rScreens.size() )
96 nScreen = 0;
97 OUStringBuffer aBuf( 256 );
98 aBuf.append( OStringToOUString( OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
99 aBuf.appendAscii( " [" );
100 aBuf.append( static_cast<sal_Int32>(nScreen) );
101 aBuf.append( ']' );
102 aScreenName = aBuf.makeStringAndClear();
104 else
106 if( nScreen >= static_cast<unsigned int>(pSalDisp->GetXScreenCount()) )
107 nScreen = 0;
108 OUStringBuffer aBuf( 256 );
109 aBuf.append( OStringToOUString( OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
110 // search backwards for ':'
111 int nPos = aBuf.getLength();
112 if( nPos > 0 )
113 nPos--;
114 while( nPos > 0 && aBuf[nPos] != ':' )
115 nPos--;
116 // search forward to '.'
117 while( nPos < aBuf.getLength() && aBuf[nPos] != '.' )
118 nPos++;
119 if( nPos < aBuf.getLength() )
120 aBuf.setLength( nPos+1 );
121 else
122 aBuf.append( '.' );
123 aBuf.append( static_cast<sal_Int32>(nScreen) );
124 aScreenName = aBuf.makeStringAndClear();
126 return aScreenName;
129 int X11SalSystem::ShowNativeDialog( const OUString& rTitle, const OUString& rMessage, const std::list< OUString >& rButtons, int nDefButton )
131 int nRet = -1;
133 ImplSVData* pSVData = ImplGetSVData();
134 if( pSVData->mpIntroWindow )
135 pSVData->mpIntroWindow->Hide();
137 ScopedVclPtrInstance<WarningBox> aWarn(nullptr, WB_STDWORK, rMessage);
138 aWarn->SetText( rTitle );
139 aWarn->Clear();
141 sal_uInt16 nButton = 0;
142 for( std::list< OUString >::const_iterator it = rButtons.begin(); it != rButtons.end(); ++it )
144 aWarn->AddButton( *it, nButton+1, nButton == (sal_uInt16)nDefButton ? ButtonDialogFlags::Default : ButtonDialogFlags::NONE );
145 nButton++;
147 aWarn->SetFocusButton( (sal_uInt16)nDefButton+1 );
149 nRet = ((int)aWarn->Execute()) - 1;
151 // normalize behaviour, actually this should never happen
152 if( nRet < -1 || nRet >= int(rButtons.size()) )
153 nRet = -1;
155 return nRet;
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */