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 Rectangle
X11SalSystem::GetDisplayScreenWorkAreaPosSizePixel( unsigned int nScreen
)
90 return GetDisplayScreenPosSizePixel( nScreen
);
93 OUString
X11SalSystem::GetDisplayScreenName( unsigned int nScreen
)
96 SalDisplay
* pSalDisp
= GetGenericData()->GetSalDisplay();
97 if( pSalDisp
->IsXinerama() )
99 const std::vector
< Rectangle
>& rScreens
= pSalDisp
->GetXineramaScreens();
100 if( nScreen
>= rScreens
.size() )
102 OUStringBuffer
aBuf( 256 );
103 aBuf
.append( OStringToOUString( OString( DisplayString( pSalDisp
->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
104 aBuf
.appendAscii( " [" );
105 aBuf
.append( static_cast<sal_Int32
>(nScreen
) );
106 aBuf
.append( sal_Unicode(']') );
107 aScreenName
= aBuf
.makeStringAndClear();
111 if( nScreen
>= static_cast<unsigned int>(pSalDisp
->GetXScreenCount()) )
113 OUStringBuffer
aBuf( 256 );
114 aBuf
.append( OStringToOUString( OString( DisplayString( pSalDisp
->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
115 // search backwards for ':'
116 int nPos
= aBuf
.getLength();
119 while( nPos
> 0 && aBuf
[nPos
] != ':' )
121 // search forward to '.'
122 while( nPos
< aBuf
.getLength() && aBuf
[nPos
] != '.' )
124 if( nPos
< aBuf
.getLength() )
125 aBuf
.setLength( nPos
+1 );
127 aBuf
.append( sal_Unicode('.') );
128 aBuf
.append( static_cast<sal_Int32
>(nScreen
) );
129 aScreenName
= aBuf
.makeStringAndClear();
134 int X11SalSystem::ShowNativeDialog( const OUString
& rTitle
, const OUString
& rMessage
, const std::list
< OUString
>& rButtons
, int nDefButton
)
138 ImplSVData
* pSVData
= ImplGetSVData();
139 if( pSVData
->mpIntroWindow
)
140 pSVData
->mpIntroWindow
->Hide();
142 WarningBox
aWarn( NULL
, WB_STDWORK
, rMessage
);
143 aWarn
.SetText( rTitle
);
146 sal_uInt16 nButton
= 0;
147 for( std::list
< OUString
>::const_iterator it
= rButtons
.begin(); it
!= rButtons
.end(); ++it
)
149 aWarn
.AddButton( *it
, nButton
+1, nButton
== (sal_uInt16
)nDefButton
? BUTTONDIALOG_DEFBUTTON
: 0 );
152 aWarn
.SetFocusButton( (sal_uInt16
)nDefButton
+1 );
154 nRet
= ((int)aWarn
.Execute()) - 1;
156 // normalize behaviour, actually this should never happen
157 if( nRet
< -1 || nRet
>= int(rButtons
.size()) )
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */