xref: /aoo41x/main/vcl/os2/source/app/salinfo.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #define INCL_PM
29 #define INCL_DOS
30 #define INCL_GPI
31 #include <svpm.h>
32 
33 #include <tools/string.hxx>
34 #include <salsys.h>
35 #include <salframe.h>
36 #include <salinst.h>
37 #include "saldata.hxx"
38 #include <tools/debug.hxx>
39 #include <vcl/svdata.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include "vcl/window.hxx"
42 
43 #ifndef _SV_SALGTYPE_HXX
44 //#include <salgtype.hxx>
45 #endif
46 
47 #define CHAR_POINTER(THE_OUSTRING) ::rtl::OUStringToOString (THE_OUSTRING, RTL_TEXTENCODING_UTF8).pData->buffer
48 
49 class Os2SalSystem : public SalSystem
50 {
51 public:
52     Os2SalSystem() {}
53     virtual ~Os2SalSystem();
54 
55     virtual unsigned int GetDisplayScreenCount();
56     virtual Rectangle GetDisplayScreenPosSizePixel( unsigned int nScreen );
57     //virtual bool GetSalSystemDisplayInfo( DisplayInfo& rInfo );
58 
59     virtual bool IsMultiDisplay();
60     virtual unsigned int GetDefaultDisplayNumber();
61     virtual Rectangle GetDisplayWorkAreaPosSizePixel( unsigned int nScreen );
62     virtual rtl::OUString GetScreenName( unsigned int nScreen );
63 
64     virtual int ShowNativeMessageBox( const String& rTitle,
65                                       const String& rMessage,
66                                       int nButtonCombination,
67                                       int nDefaultButton);
68 };
69 
70 SalSystem* Os2SalInstance::CreateSalSystem()
71 {
72     return new Os2SalSystem();
73 }
74 
75 Os2SalSystem::~Os2SalSystem()
76 {
77 }
78 
79 // -----------------------------------------------------------------------
80 #if 0
81 bool Os2SalSystem::GetSalSystemDisplayInfo( DisplayInfo& rInfo )
82 {
83     HDC hDC;
84     if( hDC = WinQueryWindowDC(HWND_DESKTOP) )
85     {
86         LONG bitCount;
87         DevQueryCaps(hDC, CAPS_COLOR_BITCOUNT, CAPS_COLOR_BITCOUNT, &bitCount);
88         rInfo.nWidth    = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
89         rInfo.nHeight   = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
90         rInfo.nDepth    = bitCount;
91         return true;
92     }
93     else
94         return false;
95 }
96 #endif
97 
98 unsigned int Os2SalSystem::GetDisplayScreenCount()
99 {
100     return 1;
101 }
102 
103 Rectangle Os2SalSystem::GetDisplayScreenPosSizePixel( unsigned int nScreen )
104 {
105     Rectangle aRet;
106     aRet = Rectangle( Point(), Point( WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ),
107 	WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) ) );
108     return aRet;
109 }
110 
111 // -----------------------------------------------------------------------
112 /* We have to map the button identifier to the identifier used by the Os232
113    Platform SDK to specify the default button for the MessageBox API.
114    The first dimension is the button combination, the second dimension
115    is the button identifier.
116 */
117 static int DEFAULT_BTN_MAPPING_TABLE[][8] =
118 {
119     //  Undefined        OK             CANCEL         ABORT          RETRY          IGNORE         YES             NO
120     { MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1 }, //OK
121     { MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1 }, //OK_CANCEL
122     { MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON3, MB_DEFBUTTON1, MB_DEFBUTTON1 }, //ABORT_RETRY_IGNO
123     { MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON3, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON2 }, //YES_NO_CANCEL
124     { MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON2 }, //YES_NO
125     { MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1, MB_DEFBUTTON1 }  //RETRY_CANCEL
126 };
127 
128 static int COMBI_BTN_MAPPING_TABLE[] =
129 {
130     MB_OK, MB_OKCANCEL, MB_ABORTRETRYIGNORE, MB_YESNO, MB_YESNOCANCEL, MB_RETRYCANCEL
131 };
132 
133 int Os2SalSystem::ShowNativeMessageBox(const String& rTitle, const String& rMessage, int nButtonCombination, int nDefaultButton)
134 {
135     DBG_ASSERT( nButtonCombination >= SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK &&
136                 nButtonCombination <= SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL &&
137                 nDefaultButton >= SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK &&
138                 nDefaultButton <= SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO, "Invalid arguments!" );
139 
140     int nFlags = MB_APPLMODAL | MB_WARNING | COMBI_BTN_MAPPING_TABLE[nButtonCombination];
141 
142     if (nButtonCombination >= SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK &&
143         nButtonCombination <= SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL &&
144         nDefaultButton >= SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK &&
145         nDefaultButton <= SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO)
146         nFlags |= DEFAULT_BTN_MAPPING_TABLE[nButtonCombination][nDefaultButton];
147 
148     //#107209 hide the splash screen if active
149     ImplSVData* pSVData = ImplGetSVData();
150     if (pSVData->mpIntroWindow)
151         pSVData->mpIntroWindow->Hide();
152 
153     return WinMessageBox(
154         HWND_DESKTOP, HWND_DESKTOP,
155         (PSZ)CHAR_POINTER(rMessage),
156         (PSZ)CHAR_POINTER(rTitle),
157         0, nFlags);
158 }
159 
160 
161 unsigned int Os2SalSystem::GetDefaultDisplayNumber()
162 {
163 	return 0;
164 }
165 
166 bool Os2SalSystem::IsMultiDisplay()
167 {
168 	return false;
169 }
170 
171 Rectangle Os2SalSystem::GetDisplayWorkAreaPosSizePixel( unsigned int nScreen )
172 {
173 	return GetDisplayScreenPosSizePixel( nScreen );
174 }
175 
176 rtl::OUString Os2SalSystem::GetScreenName( unsigned int nScreen )
177 {
178    rtl::OUStringBuffer aBuf( 32 );
179    aBuf.appendAscii( "VirtualScreen " );
180    aBuf.append( sal_Int32(nScreen) );
181    return aBuf.makeStringAndClear();
182 }
183