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