xref: /aoo42x/main/vcl/unx/generic/app/salsys.cxx (revision c82f2877)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <unx/salunx.h>
28 #include <unx/dtint.hxx>
29 #include <unx/saldata.hxx>
30 #include <unx/salinst.h>
31 #include <unx/saldisp.hxx>
32 #include <unx/salsys.h>
33 
34 #include <vcl/msgbox.hxx>
35 #include <vcl/button.hxx>
36 
37 #include <svdata.hxx>
38 
39 #include <rtl/ustrbuf.hxx>
40 #include <osl/thread.h>
41 
42 
CreateSalSystem()43 SalSystem* X11SalInstance::CreateSalSystem()
44 {
45     return new X11SalSystem();
46 }
47 
48 // -----------------------------------------------------------------------
49 
~X11SalSystem()50 X11SalSystem::~X11SalSystem()
51 {
52 }
53 
54 // for the moment only handle xinerama case
GetDisplayScreenCount()55 unsigned int X11SalSystem::GetDisplayScreenCount()
56 {
57     SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
58     return pSalDisp->IsXinerama() ? pSalDisp->GetXineramaScreens().size() : pSalDisp->GetScreenCount();
59 }
60 
IsMultiDisplay()61 bool X11SalSystem::IsMultiDisplay()
62 {
63     SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
64     unsigned int nScreenCount = pSalDisp->GetScreenCount();
65     return pSalDisp->IsXinerama() ? false : (nScreenCount > 1);
66 }
67 
GetDefaultDisplayNumber()68 unsigned int X11SalSystem::GetDefaultDisplayNumber()
69 {
70     SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
71     return pSalDisp->IsXinerama() ? pSalDisp->GetDefaultMonitorNumber() : pSalDisp->GetDefaultScreenNumber();
72 }
73 
GetDisplayScreenPosSizePixel(unsigned int nScreen)74 Rectangle X11SalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen )
75 {
76     Rectangle aRet;
77     SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
78     if( pSalDisp->IsXinerama() )
79     {
80         const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
81         if( nScreen < rScreens.size() )
82             aRet = rScreens[nScreen];
83     }
84     else
85     {
86         const SalDisplay::ScreenData& rScreen = pSalDisp->getDataForScreen( nScreen );
87         aRet = Rectangle( Point( 0, 0 ), rScreen.m_aSize );
88     }
89 
90     return aRet;
91 }
92 
GetDisplayWorkAreaPosSizePixel(unsigned int nScreen)93 Rectangle X11SalSystem::GetDisplayWorkAreaPosSizePixel( unsigned int nScreen )
94 {
95     // FIXME: workareas
96     return GetDisplayScreenPosSizePixel( nScreen );
97 }
98 
GetScreenName(unsigned int nScreen)99 rtl::OUString X11SalSystem::GetScreenName( unsigned int nScreen )
100 {
101     rtl::OUString aScreenName;
102     SalDisplay* pSalDisp = GetX11SalData()->GetDisplay();
103     if( pSalDisp->IsXinerama() )
104     {
105         const std::vector< Rectangle >& rScreens = pSalDisp->GetXineramaScreens();
106         if( nScreen >= rScreens.size() )
107             nScreen = 0;
108         rtl::OUStringBuffer aBuf( 256 );
109         aBuf.append( rtl::OStringToOUString( rtl::OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
110         aBuf.appendAscii( " [" );
111         aBuf.append( static_cast<sal_Int32>(nScreen) );
112         aBuf.append( sal_Unicode(']') );
113         aScreenName = aBuf.makeStringAndClear();
114     }
115     else
116     {
117         if( nScreen >= static_cast<unsigned int>(pSalDisp->GetScreenCount()) )
118             nScreen = 0;
119         rtl::OUStringBuffer aBuf( 256 );
120         aBuf.append( rtl::OStringToOUString( rtl::OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) );
121         // search backwards for ':'
122         int nPos = aBuf.getLength();
123         if( nPos > 0 )
124             nPos--;
125         while( nPos > 0 && aBuf.charAt( nPos ) != ':' )
126             nPos--;
127         // search forward to '.'
128         while( nPos < aBuf.getLength() && aBuf.charAt( nPos ) != '.' )
129             nPos++;
130         if( nPos < aBuf.getLength() )
131             aBuf.setLength( nPos+1 );
132         else
133             aBuf.append( sal_Unicode('.') );
134         aBuf.append( static_cast<sal_Int32>(nScreen) );
135         aScreenName = aBuf.makeStringAndClear();
136     }
137     return aScreenName;
138 }
139 
ShowNativeDialog(const String & rTitle,const String & rMessage,const std::list<String> & rButtons,int nDefButton)140 int X11SalSystem::ShowNativeDialog( const String& rTitle, const String& rMessage, const std::list< String >& rButtons, int nDefButton )
141 {
142     int nRet = -1;
143 
144     ImplSVData* pSVData = ImplGetSVData();
145     if( pSVData->mpIntroWindow )
146         pSVData->mpIntroWindow->Hide();
147 
148 	WarningBox aWarn( NULL, WB_STDWORK, rMessage );
149 	aWarn.SetText( rTitle );
150 	aWarn.Clear();
151 
152 	sal_uInt16 nButton = 0;
153 	for( std::list< String >::const_iterator it = rButtons.begin(); it != rButtons.end(); ++it )
154 	{
155             aWarn.AddButton( *it, nButton+1, nButton == (sal_uInt16)nDefButton ? BUTTONDIALOG_DEFBUTTON : 0 );
156             nButton++;
157 	}
158 	aWarn.SetFocusButton( (sal_uInt16)nDefButton+1 );
159 
160 	nRet = ((int)aWarn.Execute()) - 1;
161 
162     // normalize behaviour, actually this should never happen
163     if( nRet < -1 || nRet >= int(rButtons.size()) )
164         nRet = -1;
165 
166     return nRet;
167 }
168 
ShowNativeMessageBox(const String & rTitle,const String & rMessage,int nButtonCombination,int nDefaultButton)169 int X11SalSystem::ShowNativeMessageBox(const String& rTitle, const String& rMessage, int nButtonCombination, int nDefaultButton)
170 {
171     int nDefButton = 0;
172     std::list< String > aButtons;
173     int nButtonIds[5], nBut = 0;
174 
175     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK ||
176         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL )
177     {
178         aButtons.push_back( Button::GetStandardText( BUTTON_OK ) );
179         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK;
180     }
181     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
182         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO )
183     {
184         aButtons.push_back( Button::GetStandardText( BUTTON_YES ) );
185         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES;
186         aButtons.push_back( Button::GetStandardText( BUTTON_NO ) );
187         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO;
188         if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO )
189             nDefButton = 1;
190     }
191     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL ||
192         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
193         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
194     {
195         if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
196         {
197             aButtons.push_back( Button::GetStandardText( BUTTON_RETRY ) );
198             nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
199         }
200         aButtons.push_back( Button::GetStandardText( BUTTON_CANCEL ) );
201         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL;
202         if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL )
203             nDefButton = aButtons.size()-1;
204     }
205     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE )
206     {
207         aButtons.push_back( Button::GetStandardText( BUTTON_ABORT ) );
208         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT;
209         aButtons.push_back( Button::GetStandardText( BUTTON_RETRY ) );
210         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
211         aButtons.push_back( Button::GetStandardText( BUTTON_IGNORE ) );
212         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE;
213         switch( nDefaultButton )
214         {
215             case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY: nDefButton = 1;break;
216             case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE: nDefButton = 2;break;
217         }
218     }
219     int nResult = ShowNativeDialog( rTitle, rMessage, aButtons, nDefButton );
220 
221     return nResult != -1 ? nButtonIds[ nResult ] : 0;
222 }
223