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 <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>
31 #include <rtl/ustrbuf.hxx>
32 #include <osl/thread.h>
35 SalSystem
* X11SalInstance::CreateSalSystem()
37 return new X11SalSystem();
40 // -----------------------------------------------------------------------
42 X11SalSystem::~X11SalSystem()
46 // for the moment only handle xinerama case
47 unsigned int X11SalSystem::GetDisplayScreenCount()
49 SalDisplay
* pSalDisp
= GetGenericData()->GetSalDisplay();
50 return pSalDisp
->IsXinerama() ? pSalDisp
->GetXineramaScreens().size() :
51 pSalDisp
->GetXScreenCount();
54 bool X11SalSystem::IsUnifiedDisplay()
56 SalDisplay
* pSalDisp
= GetGenericData()->GetSalDisplay();
57 unsigned int nScreenCount
= pSalDisp
->GetXScreenCount();
58 return pSalDisp
->IsXinerama() ? true : (nScreenCount
== 1);
61 unsigned int X11SalSystem::GetDisplayBuiltInScreen()
63 SalDisplay
* pSalDisp
= GetGenericData()->GetSalDisplay();
64 return pSalDisp
->GetDefaultXScreen().getXScreen();
67 Rectangle
X11SalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen
)
70 SalDisplay
* pSalDisp
= GetGenericData()->GetSalDisplay();
71 if( pSalDisp
->IsXinerama() )
73 const std::vector
< Rectangle
>& rScreens
= pSalDisp
->GetXineramaScreens();
74 if( nScreen
< rScreens
.size() )
75 aRet
= rScreens
[nScreen
];
79 const SalDisplay::ScreenData
& rScreen
=
80 pSalDisp
->getDataForScreen( SalX11Screen( nScreen
) );
81 aRet
= Rectangle( Point( 0, 0 ), rScreen
.m_aSize
);
87 OUString
X11SalSystem::GetDisplayScreenName( unsigned int nScreen
)
90 SalDisplay
* pSalDisp
= GetGenericData()->GetSalDisplay();
91 if( pSalDisp
->IsXinerama() )
93 const std::vector
< Rectangle
>& rScreens
= pSalDisp
->GetXineramaScreens();
94 if( nScreen
>= rScreens
.size() )
96 OUStringBuffer
aBuf( 256 );
97 aBuf
.append( OStringToOUString( OString( DisplayString( pSalDisp
->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
98 aBuf
.appendAscii( " [" );
99 aBuf
.append( static_cast<sal_Int32
>(nScreen
) );
101 aScreenName
= aBuf
.makeStringAndClear();
105 if( nScreen
>= static_cast<unsigned int>(pSalDisp
->GetXScreenCount()) )
107 OUStringBuffer
aBuf( 256 );
108 aBuf
.append( OStringToOUString( OString( DisplayString( pSalDisp
->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
109 // search backwards for ':'
110 int nPos
= aBuf
.getLength();
113 while( nPos
> 0 && aBuf
[nPos
] != ':' )
115 // search forward to '.'
116 while( nPos
< aBuf
.getLength() && aBuf
[nPos
] != '.' )
118 if( nPos
< aBuf
.getLength() )
119 aBuf
.setLength( nPos
+1 );
122 aBuf
.append( static_cast<sal_Int32
>(nScreen
) );
123 aScreenName
= aBuf
.makeStringAndClear();
128 int X11SalSystem::ShowNativeDialog( const OUString
& rTitle
, const OUString
& rMessage
, const std::list
< OUString
>& rButtons
, int nDefButton
)
132 ImplSVData
* pSVData
= ImplGetSVData();
133 if( pSVData
->mpIntroWindow
)
134 pSVData
->mpIntroWindow
->Hide();
136 WarningBox
aWarn( NULL
, WB_STDWORK
, rMessage
);
137 aWarn
.SetText( rTitle
);
140 sal_uInt16 nButton
= 0;
141 for( std::list
< OUString
>::const_iterator it
= rButtons
.begin(); it
!= rButtons
.end(); ++it
)
143 aWarn
.AddButton( *it
, nButton
+1, nButton
== (sal_uInt16
)nDefButton
? BUTTONDIALOG_DEFBUTTON
: 0 );
146 aWarn
.SetFocusButton( (sal_uInt16
)nDefButton
+1 );
148 nRet
= ((int)aWarn
.Execute()) - 1;
150 // normalize behaviour, actually this should never happen
151 if( nRet
< -1 || nRet
>= int(rButtons
.size()) )
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */