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