xref: /aoo41x/main/vcl/unx/gtk/app/gtksys.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <unx/svunx.h>
28cdf0e10cSrcweir #include <svdata.hxx>
29cdf0e10cSrcweir #include <vcl/window.hxx>
30cdf0e10cSrcweir #include <unx/gtk/gtkinst.hxx>
31cdf0e10cSrcweir #include <cstdio>
32cdf0e10cSrcweir #include <gdk/gdk.h>
33cdf0e10cSrcweir #include <gtk/gtk.h>
34cdf0e10cSrcweir #include <X11/Xlib.h>
35cdf0e10cSrcweir 
CreateSalSystem()36cdf0e10cSrcweir SalSystem *GtkInstance::CreateSalSystem()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 		return new GtkSalSystem();
39cdf0e10cSrcweir }
40cdf0e10cSrcweir 
~GtkSalSystem()41cdf0e10cSrcweir GtkSalSystem::~GtkSalSystem()
42cdf0e10cSrcweir {
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
ShowNativeDialog(const String & rTitle,const String & rMessage,const std::list<String> & rButtons,int nDefButton)45cdf0e10cSrcweir int GtkSalSystem::ShowNativeDialog( const String& rTitle,
46cdf0e10cSrcweir 									const String& rMessage,
47cdf0e10cSrcweir 									const std::list< String >& rButtons,
48cdf0e10cSrcweir 									int nDefButton )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	ImplSVData* pSVData = ImplGetSVData();
52cdf0e10cSrcweir 	if( pSVData->mpIntroWindow )
53cdf0e10cSrcweir 			pSVData->mpIntroWindow->Hide();
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
56cdf0e10cSrcweir     std::fprintf( stderr, "GtkSalSystem::ShowNativeDialog\n");
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	ByteString aTitle( rTitle, RTL_TEXTENCODING_UTF8 );
60cdf0e10cSrcweir 	ByteString aMessage( rMessage, RTL_TEXTENCODING_UTF8 );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /* Create the dialogue */
63cdf0e10cSrcweir     GtkWidget* mainwin = gtk_message_dialog_new
64cdf0e10cSrcweir 			( NULL, (GtkDialogFlags)0, GTK_MESSAGE_WARNING,
65cdf0e10cSrcweir 			  GTK_BUTTONS_NONE, aMessage.GetBuffer(), NULL );
66cdf0e10cSrcweir     gtk_window_set_title( GTK_WINDOW( mainwin ), aTitle.GetBuffer() );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     gint nButtons = 0, nResponse;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	int nButton = 0;
71cdf0e10cSrcweir 	for( std::list< String >::const_iterator it = rButtons.begin(); it != rButtons.end(); ++it )
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir         ByteString aLabel( *it, RTL_TEXTENCODING_UTF8 );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 		if( nButton == nDefButton )
76cdf0e10cSrcweir 		{
77cdf0e10cSrcweir             gtk_dialog_add_button( GTK_DIALOG( mainwin ), aLabel.GetBuffer(), nButtons );
78cdf0e10cSrcweir             gtk_dialog_set_default_response( GTK_DIALOG( mainwin ), nButtons );
79cdf0e10cSrcweir 		}
80cdf0e10cSrcweir 		else
81cdf0e10cSrcweir 			gtk_dialog_add_button( GTK_DIALOG( mainwin ), aLabel.GetBuffer(), nButtons );
82cdf0e10cSrcweir 		nButtons++;
83cdf0e10cSrcweir 	}
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     nResponse = gtk_dialog_run( GTK_DIALOG(mainwin) );
86cdf0e10cSrcweir     if( nResponse == GTK_RESPONSE_NONE || nResponse == GTK_RESPONSE_DELETE_EVENT )
87cdf0e10cSrcweir         nResponse = -1;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     gtk_widget_destroy( GTK_WIDGET(mainwin) );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	return nResponse;
92cdf0e10cSrcweir }
93