xref: /aoo42x/main/vcl/unx/gtk/app/gtksys.cxx (revision 9f62ea84)
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/svunx.h>
28 #include <svdata.hxx>
29 #include <vcl/window.hxx>
30 #include <unx/gtk/gtkinst.hxx>
31 #include <cstdio>
32 #include <gdk/gdk.h>
33 #include <gtk/gtk.h>
34 #include <X11/Xlib.h>
35 
CreateSalSystem()36 SalSystem *GtkInstance::CreateSalSystem()
37 {
38 		return new GtkSalSystem();
39 }
40 
~GtkSalSystem()41 GtkSalSystem::~GtkSalSystem()
42 {
43 }
44 
ShowNativeDialog(const String & rTitle,const String & rMessage,const std::list<String> & rButtons,int nDefButton)45 int GtkSalSystem::ShowNativeDialog( const String& rTitle,
46 									const String& rMessage,
47 									const std::list< String >& rButtons,
48 									int nDefButton )
49 {
50 
51 	ImplSVData* pSVData = ImplGetSVData();
52 	if( pSVData->mpIntroWindow )
53 			pSVData->mpIntroWindow->Hide();
54 
55 #if OSL_DEBUG_LEVEL > 1
56     std::fprintf( stderr, "GtkSalSystem::ShowNativeDialog\n");
57 #endif
58 
59 	ByteString aTitle( rTitle, RTL_TEXTENCODING_UTF8 );
60 	ByteString aMessage( rMessage, RTL_TEXTENCODING_UTF8 );
61 
62     /* Create the dialogue */
63     GtkWidget* mainwin = gtk_message_dialog_new
64 			( NULL, (GtkDialogFlags)0, GTK_MESSAGE_WARNING,
65 			  GTK_BUTTONS_NONE, aMessage.GetBuffer(), NULL );
66     gtk_window_set_title( GTK_WINDOW( mainwin ), aTitle.GetBuffer() );
67 
68     gint nButtons = 0, nResponse;
69 
70 	int nButton = 0;
71 	for( std::list< String >::const_iterator it = rButtons.begin(); it != rButtons.end(); ++it )
72 	{
73         ByteString aLabel( *it, RTL_TEXTENCODING_UTF8 );
74 
75 		if( nButton == nDefButton )
76 		{
77             gtk_dialog_add_button( GTK_DIALOG( mainwin ), aLabel.GetBuffer(), nButtons );
78             gtk_dialog_set_default_response( GTK_DIALOG( mainwin ), nButtons );
79 		}
80 		else
81 			gtk_dialog_add_button( GTK_DIALOG( mainwin ), aLabel.GetBuffer(), nButtons );
82 		nButtons++;
83 	}
84 
85     nResponse = gtk_dialog_run( GTK_DIALOG(mainwin) );
86     if( nResponse == GTK_RESPONSE_NONE || nResponse == GTK_RESPONSE_DELETE_EVENT )
87         nResponse = -1;
88 
89     gtk_widget_destroy( GTK_WIDGET(mainwin) );
90 
91 	return nResponse;
92 }
93