Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
25 :
26 : #include <vcl/msgbox.hxx>
27 : #include <vcl/button.hxx>
28 :
29 : #include <svdata.hxx>
30 :
31 : #include <rtl/ustrbuf.hxx>
32 : #include <osl/thread.h>
33 :
34 0 : SalSystem* X11SalInstance::CreateSalSystem()
35 : {
36 0 : return new X11SalSystem();
37 : }
38 :
39 0 : X11SalSystem::~X11SalSystem()
40 : {
41 0 : }
42 :
43 : // for the moment only handle xinerama case
44 0 : unsigned int X11SalSystem::GetDisplayScreenCount()
45 : {
46 0 : SalDisplay* pSalDisp = GetGenericData()->GetSalDisplay();
47 0 : return pSalDisp->IsXinerama() ? pSalDisp->GetXineramaScreens().size() :
48 0 : pSalDisp->GetXScreenCount();
49 : }
50 :
51 0 : bool X11SalSystem::IsUnifiedDisplay()
52 : {
53 0 : SalDisplay* pSalDisp = GetGenericData()->GetSalDisplay();
54 0 : unsigned int nScreenCount = pSalDisp->GetXScreenCount();
55 0 : return pSalDisp->IsXinerama() || (nScreenCount == 1);
56 : }
57 :
58 0 : unsigned int X11SalSystem::GetDisplayBuiltInScreen()
59 : {
60 0 : SalDisplay* pSalDisp = GetGenericData()->GetSalDisplay();
61 0 : return pSalDisp->GetDefaultXScreen().getXScreen();
62 : }
63 :
64 0 : Rectangle X11SalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen )
65 : {
66 0 : Rectangle aRet;
67 0 : SalDisplay* pSalDisp = GetGenericData()->GetSalDisplay();
68 0 : if( pSalDisp->IsXinerama() )
69 : {
70 0 : const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
71 :
72 : // we shouldn't be able to pick a screen > number of screens available
73 : assert(nScreen < rScreens.size() );
74 :
75 0 : if( nScreen < rScreens.size() )
76 0 : aRet = rScreens[nScreen];
77 : }
78 : else
79 : {
80 : const SalDisplay::ScreenData& rScreen =
81 0 : pSalDisp->getDataForScreen( SalX11Screen( nScreen ) );
82 0 : aRet = Rectangle( Point( 0, 0 ), rScreen.m_aSize );
83 : }
84 :
85 0 : return aRet;
86 : }
87 :
88 0 : OUString X11SalSystem::GetDisplayScreenName( unsigned int nScreen )
89 : {
90 0 : OUString aScreenName;
91 0 : SalDisplay* pSalDisp = GetGenericData()->GetSalDisplay();
92 0 : if( pSalDisp->IsXinerama() )
93 : {
94 0 : const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
95 0 : if( nScreen >= rScreens.size() )
96 0 : nScreen = 0;
97 0 : OUStringBuffer aBuf( 256 );
98 0 : aBuf.append( OStringToOUString( OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
99 0 : aBuf.appendAscii( " [" );
100 0 : aBuf.append( static_cast<sal_Int32>(nScreen) );
101 0 : aBuf.append( ']' );
102 0 : aScreenName = aBuf.makeStringAndClear();
103 : }
104 : else
105 : {
106 0 : if( nScreen >= static_cast<unsigned int>(pSalDisp->GetXScreenCount()) )
107 0 : nScreen = 0;
108 0 : OUStringBuffer aBuf( 256 );
109 0 : aBuf.append( OStringToOUString( OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
110 : // search backwards for ':'
111 0 : int nPos = aBuf.getLength();
112 0 : if( nPos > 0 )
113 0 : nPos--;
114 0 : while( nPos > 0 && aBuf[nPos] != ':' )
115 0 : nPos--;
116 : // search forward to '.'
117 0 : while( nPos < aBuf.getLength() && aBuf[nPos] != '.' )
118 0 : nPos++;
119 0 : if( nPos < aBuf.getLength() )
120 0 : aBuf.setLength( nPos+1 );
121 : else
122 0 : aBuf.append( '.' );
123 0 : aBuf.append( static_cast<sal_Int32>(nScreen) );
124 0 : aScreenName = aBuf.makeStringAndClear();
125 : }
126 0 : return aScreenName;
127 : }
128 :
129 0 : int X11SalSystem::ShowNativeDialog( const OUString& rTitle, const OUString& rMessage, const std::list< OUString >& rButtons, int nDefButton )
130 : {
131 0 : int nRet = -1;
132 :
133 0 : ImplSVData* pSVData = ImplGetSVData();
134 0 : if( pSVData->mpIntroWindow )
135 0 : pSVData->mpIntroWindow->Hide();
136 :
137 0 : WarningBox aWarn( NULL, WB_STDWORK, rMessage );
138 0 : aWarn.SetText( rTitle );
139 0 : aWarn.Clear();
140 :
141 0 : sal_uInt16 nButton = 0;
142 0 : for( std::list< OUString >::const_iterator it = rButtons.begin(); it != rButtons.end(); ++it )
143 : {
144 0 : aWarn.AddButton( *it, nButton+1, nButton == (sal_uInt16)nDefButton ? BUTTONDIALOG_DEFBUTTON : 0 );
145 0 : nButton++;
146 : }
147 0 : aWarn.SetFocusButton( (sal_uInt16)nDefButton+1 );
148 :
149 0 : nRet = ((int)aWarn.Execute()) - 1;
150 :
151 : // normalize behaviour, actually this should never happen
152 0 : if( nRet < -1 || nRet >= int(rButtons.size()) )
153 0 : nRet = -1;
154 :
155 0 : return nRet;
156 0 : }
157 :
158 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|