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 #ifndef _SALGTKFPICKER_HXX_
29 #define _SALGTKFPICKER_HXX_
30 
31 //_____________________________________________________________________________
32 //	includes of other projects
33 //_____________________________________________________________________________
34 
35 #include <osl/mutex.hxx>
36 #include <cppuhelper/compbase1.hxx>
37 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
38 #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
39 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/util/XCancellable.hpp>
42 
43 #include <com/sun/star/awt/XTopWindowListener.hpp>
44 #include <com/sun/star/awt/XExtendedToolkit.hpp>
45 
46 #include <gtk/gtk.h>
47 #include <gdk/gdkkeysyms.h>
48 
49 //----------------------------------------------------------
50 // class declaration
51 //----------------------------------------------------------
52 
53 class SalGtkPicker
54 {
55 	public:
56 		SalGtkPicker(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory>& xServiceMgr);
57 		virtual ~SalGtkPicker();
58 	protected:
59 		osl::Mutex m_rbHelperMtx;
60 		GtkWidget  *m_pDialog;
61 	protected:
62 		virtual void SAL_CALL implsetTitle( const ::rtl::OUString& aTitle )
63 			throw( ::com::sun::star::uno::RuntimeException );
64 
65 		virtual void SAL_CALL implsetDisplayDirectory( const rtl::OUString& rDirectory )
66 			throw( com::sun::star::lang::IllegalArgumentException, com::sun::star::uno::RuntimeException );
67 
68 		virtual rtl::OUString SAL_CALL implgetDisplayDirectory(  )
69 			throw( com::sun::star::uno::RuntimeException );
70 		static rtl::OUString uritounicode(const gchar *pIn);
71 		static rtl::OString unicodetouri(const rtl::OUString &rURL);
72 };
73 
74 class GdkThreadLock
75 {
76 public:
77     GdkThreadLock() { gdk_threads_enter(); }
78     ~GdkThreadLock() { gdk_threads_leave(); }
79 };
80 
81 //Run the Gtk Dialog. Watch for any "new windows" created while we're
82 //executing and consider that a CANCEL event to avoid e.g. "file cannot be opened"
83 //modal dialogs and this one getting locked if some other API call causes this
84 //to happen while we're opened waiting for user input, e.g.
85 //https://bugzilla.redhat.com/show_bug.cgi?id=441108
86 class RunDialog :
87     public cppu::WeakComponentImplHelper1< ::com::sun::star::awt::XTopWindowListener >
88 {
89 private:
90     osl::Mutex maLock;
91     GtkWidget *mpDialog;
92     GdkWindow *mpCreatedParent;
93     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XExtendedToolkit>  mxToolkit;
94 public:
95 
96     // XTopWindowListener
97     using cppu::WeakComponentImplHelperBase::disposing;
98     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& )
99         throw(::com::sun::star::uno::RuntimeException) {}
100     virtual void SAL_CALL windowOpened( const ::com::sun::star::lang::EventObject& e )
101         throw (::com::sun::star::uno::RuntimeException);
102     virtual void SAL_CALL windowClosing( const ::com::sun::star::lang::EventObject& )
103         throw (::com::sun::star::uno::RuntimeException) {}
104     virtual void SAL_CALL windowClosed( const ::com::sun::star::lang::EventObject& )
105         throw (::com::sun::star::uno::RuntimeException) {}
106     virtual void SAL_CALL windowMinimized( const ::com::sun::star::lang::EventObject& )
107         throw (::com::sun::star::uno::RuntimeException) {}
108     virtual void SAL_CALL windowNormalized( const ::com::sun::star::lang::EventObject& )
109         throw (::com::sun::star::uno::RuntimeException) {}
110     virtual void SAL_CALL windowActivated( const ::com::sun::star::lang::EventObject& )
111         throw (::com::sun::star::uno::RuntimeException) {}
112     virtual void SAL_CALL windowDeactivated( const ::com::sun::star::lang::EventObject& )
113         throw (::com::sun::star::uno::RuntimeException) {}
114 public:
115     RunDialog(GtkWidget *pDialog, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XExtendedToolkit > &rToolkit);
116     gint run();
117     void cancel();
118     ~RunDialog();
119 };
120 
121 #endif
122