xref: /aoo42x/main/vcl/unx/gtk/app/gtkdata.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #define _SV_SALDATA_CXX
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <unistd.h>
36*cdf0e10cSrcweir #include <fcntl.h>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <stdio.h>
39*cdf0e10cSrcweir #include <string.h>
40*cdf0e10cSrcweir #include <stdlib.h>
41*cdf0e10cSrcweir #include <limits.h>
42*cdf0e10cSrcweir #include <errno.h>
43*cdf0e10cSrcweir #include <poll.h>
44*cdf0e10cSrcweir #ifdef FREEBSD
45*cdf0e10cSrcweir #include <sys/types.h>
46*cdf0e10cSrcweir #include <sys/time.h>
47*cdf0e10cSrcweir #include <unistd.h>
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #include <unx/gtk/gtkdata.hxx>
50*cdf0e10cSrcweir #include <unx/gtk/gtkinst.hxx>
51*cdf0e10cSrcweir #include <unx/gtk/gtkframe.hxx>
52*cdf0e10cSrcweir #include <unx/salobj.h>
53*cdf0e10cSrcweir #include <osl/thread.h>
54*cdf0e10cSrcweir #include <osl/process.h>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #include <tools/debug.hxx>
57*cdf0e10cSrcweir #include "unx/i18n_im.hxx"
58*cdf0e10cSrcweir #include "unx/i18n_xkb.hxx"
59*cdf0e10cSrcweir #include <unx/wmadaptor.hxx>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir #include "unx/x11_cursors/salcursors.h"
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <vcl/svapp.hxx>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir using namespace rtl;
66*cdf0e10cSrcweir using namespace vcl_sal;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir /***************************************************************************
69*cdf0e10cSrcweir  * class GtkDisplay                                                        *
70*cdf0e10cSrcweir  ***************************************************************************/
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir GtkSalDisplay::GtkSalDisplay( GdkDisplay* pDisplay )
73*cdf0e10cSrcweir             : SalDisplay( gdk_x11_display_get_xdisplay( pDisplay ) ),
74*cdf0e10cSrcweir               m_pGdkDisplay( pDisplay ),
75*cdf0e10cSrcweir               m_bStartupCompleted( false )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     m_bUseRandRWrapper = false; // use gdk signal instead
78*cdf0e10cSrcweir 	for(int i = 0; i < POINTER_COUNT; i++)
79*cdf0e10cSrcweir 		m_aCursors[ i ] = NULL;
80*cdf0e10cSrcweir 	Init ();
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir GtkSalDisplay::~GtkSalDisplay()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     if( !m_bStartupCompleted )
86*cdf0e10cSrcweir         gdk_notify_startup_complete();
87*cdf0e10cSrcweir     doDestruct();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	for(int i = 0; i < POINTER_COUNT; i++)
90*cdf0e10cSrcweir 		if( m_aCursors[ i ] )
91*cdf0e10cSrcweir 			gdk_cursor_unref( m_aCursors[ i ] );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     pDisp_ = NULL;
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir void GtkSalDisplay::deregisterFrame( SalFrame* pFrame )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir 	if( m_pCapture == pFrame )
99*cdf0e10cSrcweir 	{
100*cdf0e10cSrcweir 		static_cast<GtkSalFrame*>(m_pCapture)->grabPointer( FALSE );
101*cdf0e10cSrcweir 		m_pCapture = NULL;
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir     SalDisplay::deregisterFrame( pFrame );
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir extern "C" {
107*cdf0e10cSrcweir GdkFilterReturn call_filterGdkEvent( GdkXEvent* sys_event,
108*cdf0e10cSrcweir                                      GdkEvent* event,
109*cdf0e10cSrcweir                                      gpointer data )
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir     return GtkSalDisplay::filterGdkEvent( sys_event, event, data );
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void signalKeysChanged( GdkKeymap*, gpointer data )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     GtkSalDisplay* pDisp = (GtkSalDisplay*)data;
117*cdf0e10cSrcweir     pDisp->GetKeyboardName(TRUE);
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir void signalScreenSizeChanged( GdkScreen* pScreen, gpointer data )
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     GtkSalDisplay* pDisp = (GtkSalDisplay*)data;
123*cdf0e10cSrcweir     pDisp->screenSizeChanged( pScreen );
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir void signalMonitorsChanged( GdkScreen* pScreen, gpointer data )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     GtkSalDisplay* pDisp = (GtkSalDisplay*)data;
129*cdf0e10cSrcweir     pDisp->monitorsChanged( pScreen );
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir GdkFilterReturn GtkSalDisplay::filterGdkEvent( GdkXEvent* sys_event,
135*cdf0e10cSrcweir                                                GdkEvent*,
136*cdf0e10cSrcweir                                                gpointer data )
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir     GdkFilterReturn aFilterReturn = GDK_FILTER_CONTINUE;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	XEvent *pEvent = (XEvent *)sys_event;
141*cdf0e10cSrcweir 	GtkSalDisplay *pDisplay = (GtkSalDisplay *)data;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     // dispatch all XEvents to event callback
144*cdf0e10cSrcweir     if( GetSalData()->m_pInstance->
145*cdf0e10cSrcweir         CallEventCallback( pEvent, sizeof( XEvent ) ) )
146*cdf0e10cSrcweir         aFilterReturn = GDK_FILTER_REMOVE;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     GTK_YIELD_GRAB();
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     if (pDisplay->GetDisplay() == pEvent->xany.display )
151*cdf0e10cSrcweir     {
152*cdf0e10cSrcweir         // #i53471# gtk has no callback mechanism that lets us be notified
153*cdf0e10cSrcweir         // when settings (as in XSETTING and opposed to styles) are changed.
154*cdf0e10cSrcweir         // so we need to listen for corresponding property notifications here
155*cdf0e10cSrcweir         // these should be rare enough so that we can assume that the settings
156*cdf0e10cSrcweir         // actually change when a corresponding PropertyNotify occurs
157*cdf0e10cSrcweir         if( pEvent->type == PropertyNotify &&
158*cdf0e10cSrcweir             pEvent->xproperty.atom == pDisplay->getWMAdaptor()->getAtom( WMAdaptor::XSETTINGS ) &&
159*cdf0e10cSrcweir             ! pDisplay->m_aFrames.empty()
160*cdf0e10cSrcweir            )
161*cdf0e10cSrcweir         {
162*cdf0e10cSrcweir             pDisplay->SendInternalEvent( pDisplay->m_aFrames.front(), NULL, SALEVENT_SETTINGSCHANGED );
163*cdf0e10cSrcweir         }
164*cdf0e10cSrcweir         // let's see if one of our frames wants to swallow these events
165*cdf0e10cSrcweir         // get the frame
166*cdf0e10cSrcweir         for( std::list< SalFrame* >::const_iterator it = pDisplay->m_aFrames.begin();
167*cdf0e10cSrcweir                  it != pDisplay->m_aFrames.end(); ++it )
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             GtkSalFrame* pFrame = static_cast<GtkSalFrame*>(*it);
170*cdf0e10cSrcweir             if( (GdkNativeWindow)pFrame->GetSystemData()->aWindow == pEvent->xany.window ||
171*cdf0e10cSrcweir                 ( pFrame->getForeignParent() && pFrame->getForeignParentWindow() == pEvent->xany.window ) ||
172*cdf0e10cSrcweir                 ( pFrame->getForeignTopLevel() && pFrame->getForeignTopLevelWindow() == pEvent->xany.window )
173*cdf0e10cSrcweir                 )
174*cdf0e10cSrcweir             {
175*cdf0e10cSrcweir                 if( ! pFrame->Dispatch( pEvent ) )
176*cdf0e10cSrcweir                     aFilterReturn = GDK_FILTER_REMOVE;
177*cdf0e10cSrcweir                 break;
178*cdf0e10cSrcweir             }
179*cdf0e10cSrcweir         }
180*cdf0e10cSrcweir         X11SalObject::Dispatch( pEvent );
181*cdf0e10cSrcweir     }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     return aFilterReturn;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir void GtkSalDisplay::screenSizeChanged( GdkScreen* pScreen )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     if( pScreen )
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         int nScreen = gdk_screen_get_number( pScreen );
191*cdf0e10cSrcweir         if( nScreen < static_cast<int>(m_aScreens.size()) )
192*cdf0e10cSrcweir         {
193*cdf0e10cSrcweir             ScreenData& rSD = const_cast<ScreenData&>(m_aScreens[nScreen]);
194*cdf0e10cSrcweir             if( rSD.m_bInit )
195*cdf0e10cSrcweir             {
196*cdf0e10cSrcweir                 rSD.m_aSize = Size( gdk_screen_get_width( pScreen ),
197*cdf0e10cSrcweir                                     gdk_screen_get_height( pScreen ) );
198*cdf0e10cSrcweir                 if( ! m_aFrames.empty() )
199*cdf0e10cSrcweir                     m_aFrames.front()->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
200*cdf0e10cSrcweir             }
201*cdf0e10cSrcweir         }
202*cdf0e10cSrcweir         else
203*cdf0e10cSrcweir         {
204*cdf0e10cSrcweir             DBG_ERROR( "unknown screen changed size" );
205*cdf0e10cSrcweir         }
206*cdf0e10cSrcweir     }
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir void GtkSalDisplay::monitorsChanged( GdkScreen* pScreen )
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     /* Caution: since we support the _NET_WM_FULLSCREEN_MONITORS property now and
212*cdf0e10cSrcweir        the EWMH spec says, the index used for that needs to be that of the
213*cdf0e10cSrcweir        Xinerama extension, we need to ensure that the order of m_aXineramaScreens is actually intact.
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir        gdk_screen_get_monitor_geometry however has a different sort order that has a default monitor number
216*cdf0e10cSrcweir        Xinerama returns the default monitor as 0.
217*cdf0e10cSrcweir        That means if we fill in the multiple montors vector from gdk, we'll get the wrong order unless
218*cdf0e10cSrcweir        the default monitor is incidentally the same (number 0).
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir        Given that XRandR (which is what gdk_screen_get_monitor_geometry is based on) is
221*cdf0e10cSrcweir        supposed to replace Xinerama, this is bound to get a problem at some time again,
222*cdf0e10cSrcweir        unfortunately there does not currently seem to be a way to map the returns of xinerama to
223*cdf0e10cSrcweir        that of randr. Currently getting Xinerama values again works with updated values, given
224*cdf0e10cSrcweir        a new enough Xserver.
225*cdf0e10cSrcweir     */
226*cdf0e10cSrcweir     InitXinerama();
227*cdf0e10cSrcweir     (void)pScreen;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     #if 0
230*cdf0e10cSrcweir     if( pScreen )
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         if( gdk_display_get_n_screens(m_pGdkDisplay) == 1 )
233*cdf0e10cSrcweir         {
234*cdf0e10cSrcweir             int nScreen = gdk_screen_get_number( pScreen );
235*cdf0e10cSrcweir             if( nScreen == m_nDefaultScreen ) //To-Do, make m_aXineramaScreens a per-screen thing ?
236*cdf0e10cSrcweir             {
237*cdf0e10cSrcweir                 gint nMonitors = gdk_screen_get_n_monitors(pScreen);
238*cdf0e10cSrcweir                 m_aXineramaScreens = std::vector<Rectangle>();
239*cdf0e10cSrcweir                 m_aXineramaScreenIndexMap = std::vector<int>(nMonitors);
240*cdf0e10cSrcweir                 for (gint i = 0; i < nMonitors; ++i)
241*cdf0e10cSrcweir                 {
242*cdf0e10cSrcweir                     GdkRectangle dest;
243*cdf0e10cSrcweir                     gdk_screen_get_monitor_geometry(pScreen, i, &dest);
244*cdf0e10cSrcweir                     m_aXineramaScreenIndexMap[i] = addXineramaScreenUnique( dest.x, dest.y, dest.width, dest.height );
245*cdf0e10cSrcweir                 }
246*cdf0e10cSrcweir                 m_bXinerama = m_aXineramaScreens.size() > 1;
247*cdf0e10cSrcweir                 if( ! m_aFrames.empty() )
248*cdf0e10cSrcweir                     m_aFrames.front()->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
249*cdf0e10cSrcweir             }
250*cdf0e10cSrcweir             else
251*cdf0e10cSrcweir             {
252*cdf0e10cSrcweir                 DBG_ERROR( "monitors for non-default screen changed, extend-me" );
253*cdf0e10cSrcweir             }
254*cdf0e10cSrcweir         }
255*cdf0e10cSrcweir     }
256*cdf0e10cSrcweir     #endif
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir extern "C"
260*cdf0e10cSrcweir {
261*cdf0e10cSrcweir     typedef gint(* screen_get_primary_monitor)(GdkScreen *screen);
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir int GtkSalDisplay::GetDefaultMonitorNumber() const
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir     int n = 0;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     // currently disabled, see remarks in monitorsChanged
269*cdf0e10cSrcweir #if 0
270*cdf0e10cSrcweir     GdkScreen* pScreen = gdk_display_get_screen( m_pGdkDisplay, m_nDefaultScreen );
271*cdf0e10cSrcweir #if GTK_CHECK_VERSION(2,20,0)
272*cdf0e10cSrcweir     n = gdk_screen_get_primary_monitor(pScreen);
273*cdf0e10cSrcweir #else
274*cdf0e10cSrcweir     static screen_get_primary_monitor sym_gdk_screen_get_primary_monitor =
275*cdf0e10cSrcweir         (screen_get_primary_monitor)osl_getAsciiFunctionSymbol( GetSalData()->m_pPlugin, "gdk_screen_get_primary_monitor" );
276*cdf0e10cSrcweir     if (sym_gdk_screen_get_primary_monitor)
277*cdf0e10cSrcweir         n = sym_gdk_screen_get_primary_monitor( pScreen );
278*cdf0e10cSrcweir #endif
279*cdf0e10cSrcweir     if( n >= 0 && size_t(n) < m_aXineramaScreenIndexMap.size() )
280*cdf0e10cSrcweir         n = m_aXineramaScreenIndexMap[n];
281*cdf0e10cSrcweir #endif
282*cdf0e10cSrcweir     return n;
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir void GtkSalDisplay::initScreen( int nScreen ) const
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir     if( nScreen < 0 || nScreen >= static_cast<int>(m_aScreens.size()) )
288*cdf0e10cSrcweir         nScreen = m_nDefaultScreen;
289*cdf0e10cSrcweir     ScreenData& rSD = const_cast<ScreenData&>(m_aScreens[nScreen]);
290*cdf0e10cSrcweir     if( rSD.m_bInit )
291*cdf0e10cSrcweir         return;
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     // choose visual for screen
294*cdf0e10cSrcweir     SalDisplay::initScreen( nScreen );
295*cdf0e10cSrcweir     // now set a gdk default colormap matching the chosen visual to the screen
296*cdf0e10cSrcweir     GdkVisual* pVis = gdkx_visual_get( rSD.m_aVisual.visualid );
297*cdf0e10cSrcweir     GdkScreen* pScreen = gdk_display_get_screen( m_pGdkDisplay, nScreen );
298*cdf0e10cSrcweir     if( pVis )
299*cdf0e10cSrcweir     {
300*cdf0e10cSrcweir         GdkColormap* pDefCol = gdk_screen_get_default_colormap( pScreen );
301*cdf0e10cSrcweir         GdkVisual* pDefVis = gdk_colormap_get_visual( pDefCol );
302*cdf0e10cSrcweir         if( pDefVis != pVis )
303*cdf0e10cSrcweir         {
304*cdf0e10cSrcweir            pDefCol = gdk_x11_colormap_foreign_new( pVis, rSD.m_aColormap.GetXColormap() );
305*cdf0e10cSrcweir            gdk_screen_set_default_colormap( pScreen, pDefCol );
306*cdf0e10cSrcweir            #if OSL_DEBUG_LEVEL > 1
307*cdf0e10cSrcweir            fprintf( stderr, "set new gdk color map for screen %d\n", nScreen );
308*cdf0e10cSrcweir            #endif
309*cdf0e10cSrcweir         }
310*cdf0e10cSrcweir     }
311*cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 1
312*cdf0e10cSrcweir     else
313*cdf0e10cSrcweir         fprintf( stderr, "not GdkVisual for visual id %d\n", (int)rSD.m_aVisual.visualid );
314*cdf0e10cSrcweir     #endif
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir long GtkSalDisplay::Dispatch( XEvent* pEvent )
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir     if( GetDisplay() == pEvent->xany.display )
320*cdf0e10cSrcweir     {
321*cdf0e10cSrcweir         // let's see if one of our frames wants to swallow these events
322*cdf0e10cSrcweir         // get the child frame
323*cdf0e10cSrcweir         for( std::list< SalFrame* >::const_iterator it = m_aFrames.begin();
324*cdf0e10cSrcweir              it != m_aFrames.end(); ++it )
325*cdf0e10cSrcweir         {
326*cdf0e10cSrcweir             if( (GdkNativeWindow)(*it)->GetSystemData()->aWindow == pEvent->xany.window )
327*cdf0e10cSrcweir                 return static_cast<GtkSalFrame*>(*it)->Dispatch( pEvent );
328*cdf0e10cSrcweir         }
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     return GDK_FILTER_CONTINUE;
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir GdkCursor* GtkSalDisplay::getFromXPM( const char *pBitmap,
335*cdf0e10cSrcweir 									  const char *pMask,
336*cdf0e10cSrcweir 									  int nWidth, int nHeight,
337*cdf0e10cSrcweir 									  int nXHot, int nYHot )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir 	GdkScreen *pScreen = gdk_display_get_default_screen( m_pGdkDisplay );
340*cdf0e10cSrcweir 	GdkDrawable *pDrawable = GDK_DRAWABLE( gdk_screen_get_root_window (pScreen) );
341*cdf0e10cSrcweir 	GdkBitmap *pBitmapPix = gdk_bitmap_create_from_data
342*cdf0e10cSrcweir 			( pDrawable, pBitmap, nWidth, nHeight );
343*cdf0e10cSrcweir 	GdkBitmap *pMaskPix = gdk_bitmap_create_from_data
344*cdf0e10cSrcweir 			( pDrawable, pMask, nWidth, nHeight );
345*cdf0e10cSrcweir 	GdkColormap *pColormap = gdk_drawable_get_colormap( pDrawable );
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 	GdkColor aWhite = { 0, 0xffff, 0xffff, 0xffff };
348*cdf0e10cSrcweir 	GdkColor aBlack = { 0, 0, 0, 0 };
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 	gdk_colormap_alloc_color( pColormap, &aBlack, FALSE, TRUE);
351*cdf0e10cSrcweir 	gdk_colormap_alloc_color( pColormap, &aWhite, FALSE, TRUE);
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 	return gdk_cursor_new_from_pixmap
354*cdf0e10cSrcweir 			( pBitmapPix, pMaskPix,
355*cdf0e10cSrcweir 			  &aBlack, &aWhite, nXHot, nYHot);
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir #define MAKE_CURSOR( vcl_name, name ) \
359*cdf0e10cSrcweir 	case vcl_name: \
360*cdf0e10cSrcweir 		pCursor = getFromXPM( name##curs##_bits, name##mask##_bits, \
361*cdf0e10cSrcweir 							  name##curs_width, name##curs_height, \
362*cdf0e10cSrcweir 							  name##curs_x_hot, name##curs_y_hot ); \
363*cdf0e10cSrcweir 		break
364*cdf0e10cSrcweir #define MAP_BUILTIN( vcl_name, gdk_name ) \
365*cdf0e10cSrcweir 		case vcl_name: \
366*cdf0e10cSrcweir 			pCursor = gdk_cursor_new_for_display( m_pGdkDisplay, gdk_name ); \
367*cdf0e10cSrcweir 			break
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir GdkCursor *GtkSalDisplay::getCursor( PointerStyle ePointerStyle )
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir     if( ePointerStyle > POINTER_COUNT )
372*cdf0e10cSrcweir         return NULL;
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 	if ( !m_aCursors[ ePointerStyle ] )
375*cdf0e10cSrcweir 	{
376*cdf0e10cSrcweir 		GdkCursor *pCursor = NULL;
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 	    switch( ePointerStyle )
379*cdf0e10cSrcweir 	    {
380*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_ARROW, GDK_LEFT_PTR );
381*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_TEXT, GDK_XTERM );
382*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_HELP, GDK_QUESTION_ARROW );
383*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_CROSS, GDK_CROSSHAIR );
384*cdf0e10cSrcweir             MAP_BUILTIN( POINTER_WAIT, GDK_WATCH );
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_NSIZE, GDK_SB_V_DOUBLE_ARROW );
387*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_SSIZE, GDK_SB_V_DOUBLE_ARROW );
388*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WSIZE, GDK_SB_H_DOUBLE_ARROW );
389*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_ESIZE, GDK_SB_H_DOUBLE_ARROW );
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_NWSIZE, GDK_TOP_LEFT_CORNER );
392*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_NESIZE, GDK_TOP_RIGHT_CORNER );
393*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_SWSIZE, GDK_BOTTOM_LEFT_CORNER );
394*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_SESIZE, GDK_BOTTOM_RIGHT_CORNER );
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_NSIZE, GDK_TOP_SIDE );
397*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_SSIZE, GDK_BOTTOM_SIDE );
398*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_WSIZE, GDK_LEFT_SIDE );
399*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_ESIZE, GDK_RIGHT_SIDE );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_NWSIZE, GDK_TOP_LEFT_CORNER );
402*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_NESIZE, GDK_TOP_RIGHT_CORNER );
403*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_SWSIZE, GDK_BOTTOM_LEFT_CORNER );
404*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_WINDOW_SESIZE, GDK_BOTTOM_RIGHT_CORNER );
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_HSIZEBAR, GDK_SB_H_DOUBLE_ARROW );
407*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_VSIZEBAR, GDK_SB_V_DOUBLE_ARROW );
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_REFHAND, GDK_HAND1 );
410*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_HAND, GDK_HAND2 );
411*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_PEN, GDK_PENCIL );
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_HSPLIT, GDK_SB_H_DOUBLE_ARROW );
414*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_VSPLIT, GDK_SB_V_DOUBLE_ARROW );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 			MAP_BUILTIN( POINTER_MOVE, GDK_FLEUR );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_NULL, null );
419*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MAGNIFY, magnify_ );
420*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_FILL, fill_ );
421*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MOVEDATA, movedata_ );
422*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_COPYDATA, copydata_ );
423*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MOVEFILE, movefile_ );
424*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_COPYFILE, copyfile_ );
425*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MOVEFILES, movefiles_ );
426*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_COPYFILES, copyfiles_ );
427*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_NOTALLOWED, nodrop_ );
428*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_ROTATE, rotate_ );
429*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_HSHEAR, hshear_ );
430*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_VSHEAR, vshear_ );
431*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_LINE, drawline_ );
432*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_RECT, drawrect_ );
433*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_POLYGON, drawpolygon_ );
434*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_BEZIER, drawbezier_ );
435*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_ARC, drawarc_ );
436*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_PIE, drawpie_ );
437*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_CIRCLECUT, drawcirclecut_ );
438*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_ELLIPSE, drawellipse_ );
439*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_CONNECT, drawconnect_ );
440*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_TEXT, drawtext_ );
441*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MIRROR, mirror_ );
442*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_CROOK, crook_ );
443*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_CROP, crop_ );
444*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MOVEPOINT, movepoint_ );
445*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MOVEBEZIERWEIGHT, movebezierweight_ );
446*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_FREEHAND, drawfreehand_ );
447*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DRAW_CAPTION, drawcaption_ );
448*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_LINKDATA, linkdata_ );
449*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MOVEDATALINK, movedlnk_ );
450*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_COPYDATALINK, copydlnk_ );
451*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_LINKFILE, linkfile_ );
452*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_MOVEFILELINK, moveflnk_ );
453*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_COPYFILELINK, copyflnk_ );
454*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_CHART, chart_ );
455*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_DETECTIVE, detective_ );
456*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_PIVOT_COL, pivotcol_ );
457*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_PIVOT_ROW, pivotrow_ );
458*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_PIVOT_FIELD, pivotfld_ );
459*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_PIVOT_DELETE, pivotdel_ );
460*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_CHAIN, chain_ );
461*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_CHAIN_NOTALLOWED, chainnot_ );
462*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_TIMEEVENT_MOVE, timemove_ );
463*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_TIMEEVENT_SIZE, timesize_ );
464*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_N, asn_ );
465*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_S, ass_ );
466*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_W, asw_ );
467*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_E, ase_ );
468*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_NW, asnw_ );
469*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_NE, asne_ );
470*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_SW, assw_ );
471*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_SE, asse_ );
472*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_NS, asns_ );
473*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_WE, aswe_ );
474*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AUTOSCROLL_NSWE, asnswe_ );
475*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_AIRBRUSH, airbrush_ );
476*cdf0e10cSrcweir 			MAKE_CURSOR( POINTER_TEXT_VERTICAL, vertcurs_ );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir             // --> FME 2004-07-30 #i32329# Enhanced table selection
479*cdf0e10cSrcweir             MAKE_CURSOR( POINTER_TAB_SELECT_S, tblsels_ );
480*cdf0e10cSrcweir             MAKE_CURSOR( POINTER_TAB_SELECT_E, tblsele_ );
481*cdf0e10cSrcweir             MAKE_CURSOR( POINTER_TAB_SELECT_SE, tblselse_ );
482*cdf0e10cSrcweir             MAKE_CURSOR( POINTER_TAB_SELECT_W, tblselw_ );
483*cdf0e10cSrcweir             MAKE_CURSOR( POINTER_TAB_SELECT_SW, tblselsw_ );
484*cdf0e10cSrcweir             // <--
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir             // --> FME 2004-08-16 #i20119# Paintbrush tool
487*cdf0e10cSrcweir             MAKE_CURSOR( POINTER_PAINTBRUSH, paintbrush_ );
488*cdf0e10cSrcweir             // <--
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 		default:
491*cdf0e10cSrcweir 			fprintf( stderr, "pointer %d not implemented", ePointerStyle );
492*cdf0e10cSrcweir 			break;
493*cdf0e10cSrcweir 		}
494*cdf0e10cSrcweir 		if( !pCursor )
495*cdf0e10cSrcweir 			pCursor = gdk_cursor_new_for_display( m_pGdkDisplay, GDK_LEFT_PTR );
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 		m_aCursors[ ePointerStyle ] = pCursor;
498*cdf0e10cSrcweir 	}
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 	return m_aCursors[ ePointerStyle ];
501*cdf0e10cSrcweir }
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir int GtkSalDisplay::CaptureMouse( SalFrame* pSFrame )
504*cdf0e10cSrcweir {
505*cdf0e10cSrcweir     GtkSalFrame* pFrame = static_cast<GtkSalFrame*>(pSFrame);
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 	if( !pFrame )
508*cdf0e10cSrcweir 	{
509*cdf0e10cSrcweir 		if( m_pCapture )
510*cdf0e10cSrcweir 			static_cast<GtkSalFrame*>(m_pCapture)->grabPointer( FALSE );
511*cdf0e10cSrcweir 		m_pCapture = NULL;
512*cdf0e10cSrcweir 		return 0;
513*cdf0e10cSrcweir 	}
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 	if( m_pCapture )
516*cdf0e10cSrcweir 	{
517*cdf0e10cSrcweir 		if( pFrame == m_pCapture )
518*cdf0e10cSrcweir 			return 1;
519*cdf0e10cSrcweir 		static_cast<GtkSalFrame*>(m_pCapture)->grabPointer( FALSE );
520*cdf0e10cSrcweir 	}
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 	m_pCapture = pFrame;
523*cdf0e10cSrcweir 	static_cast<GtkSalFrame*>(pFrame)->grabPointer( TRUE );
524*cdf0e10cSrcweir     return 1;
525*cdf0e10cSrcweir }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir /***************************************************************************
528*cdf0e10cSrcweir  * class GtkXLib                                                           *
529*cdf0e10cSrcweir  ***************************************************************************/
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir class GtkXLib : public SalXLib
532*cdf0e10cSrcweir {
533*cdf0e10cSrcweir     GtkSalDisplay       *m_pGtkSalDisplay;
534*cdf0e10cSrcweir     std::list<GSource *> m_aSources;
535*cdf0e10cSrcweir     GSource             *m_pTimeout;
536*cdf0e10cSrcweir 	GSource				*m_pUserEvent;
537*cdf0e10cSrcweir     oslMutex             m_aDispatchMutex;
538*cdf0e10cSrcweir     oslCondition         m_aDispatchCondition;
539*cdf0e10cSrcweir     XIOErrorHandler      m_aOrigGTKXIOErrorHandler;
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir public:
542*cdf0e10cSrcweir 	static gboolean      timeoutFn(gpointer data);
543*cdf0e10cSrcweir 	static gboolean      userEventFn(gpointer data);
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir     GtkXLib();
546*cdf0e10cSrcweir     virtual ~GtkXLib();
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir     virtual void    Init();
549*cdf0e10cSrcweir     virtual void    Yield( bool bWait, bool bHandleAllCurrentEvents );
550*cdf0e10cSrcweir     virtual void    Insert( int fd, void* data,
551*cdf0e10cSrcweir                             YieldFunc	pending,
552*cdf0e10cSrcweir                             YieldFunc	queued,
553*cdf0e10cSrcweir                             YieldFunc	handle );
554*cdf0e10cSrcweir     virtual void    Remove( int fd );
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 	virtual void    StartTimer( sal_uLong nMS );
557*cdf0e10cSrcweir 	virtual void    StopTimer();
558*cdf0e10cSrcweir     virtual void    Wakeup();
559*cdf0e10cSrcweir     virtual void    PostUserEvent();
560*cdf0e10cSrcweir };
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir GtkXLib::GtkXLib()
563*cdf0e10cSrcweir {
564*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
565*cdf0e10cSrcweir     fprintf( stderr, "GtkXLib::GtkXLib()\n" );
566*cdf0e10cSrcweir #endif
567*cdf0e10cSrcweir     m_pGtkSalDisplay = NULL;
568*cdf0e10cSrcweir 	m_pTimeout = NULL;
569*cdf0e10cSrcweir 	m_nTimeoutMS = 0;
570*cdf0e10cSrcweir     m_pUserEvent = NULL;
571*cdf0e10cSrcweir     m_aDispatchCondition = osl_createCondition();
572*cdf0e10cSrcweir     m_aDispatchMutex = osl_createMutex();
573*cdf0e10cSrcweir     m_aOrigGTKXIOErrorHandler = NULL;
574*cdf0e10cSrcweir }
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir GtkXLib::~GtkXLib()
577*cdf0e10cSrcweir {
578*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
579*cdf0e10cSrcweir     fprintf( stderr, "GtkXLib::~GtkXLib()\n" );
580*cdf0e10cSrcweir #endif
581*cdf0e10cSrcweir 	StopTimer();
582*cdf0e10cSrcweir      // sanity check: at this point nobody should be yielding, but wake them
583*cdf0e10cSrcweir      // up anyway before the condition they're waiting on gets destroyed.
584*cdf0e10cSrcweir     osl_setCondition( m_aDispatchCondition );
585*cdf0e10cSrcweir     osl_destroyCondition( m_aDispatchCondition );
586*cdf0e10cSrcweir     osl_destroyMutex( m_aDispatchMutex );
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir     PopXErrorLevel();
589*cdf0e10cSrcweir     XSetIOErrorHandler (m_aOrigGTKXIOErrorHandler);
590*cdf0e10cSrcweir }
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir void GtkXLib::Init()
593*cdf0e10cSrcweir {
594*cdf0e10cSrcweir     int i;
595*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
596*cdf0e10cSrcweir     fprintf( stderr, "GtkXLib::Init()\n" );
597*cdf0e10cSrcweir #endif
598*cdf0e10cSrcweir 	XrmInitialize();
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir     gtk_set_locale();
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 	/*
603*cdf0e10cSrcweir 	 * open connection to X11 Display
604*cdf0e10cSrcweir 	 * try in this order:
605*cdf0e10cSrcweir 	 *  o  -display command line parameter,
606*cdf0e10cSrcweir 	 *  o  $DISPLAY environment variable
607*cdf0e10cSrcweir 	 *  o  default display
608*cdf0e10cSrcweir 	 */
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir     GdkDisplay *pGdkDisp = NULL;
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir 	// is there a -display command line parameter?
613*cdf0e10cSrcweir     rtl_TextEncoding aEnc = osl_getThreadTextEncoding();
614*cdf0e10cSrcweir 	int nParams = osl_getCommandArgCount();
615*cdf0e10cSrcweir 	rtl::OString aDisplay;
616*cdf0e10cSrcweir 	rtl::OUString aParam, aBin;
617*cdf0e10cSrcweir     char** pCmdLineAry = new char*[ nParams+1 ];
618*cdf0e10cSrcweir     osl_getExecutableFile( &aParam.pData );
619*cdf0e10cSrcweir     osl_getSystemPathFromFileURL( aParam.pData, &aBin.pData );
620*cdf0e10cSrcweir     pCmdLineAry[0] = g_strdup( OUStringToOString( aBin, aEnc ).getStr() );
621*cdf0e10cSrcweir 	for (i=0; i<nParams; i++)
622*cdf0e10cSrcweir 	{
623*cdf0e10cSrcweir 		osl_getCommandArg(i, &aParam.pData );
624*cdf0e10cSrcweir         OString aBParam( OUStringToOString( aParam, aEnc ) );
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir 		if( aParam.equalsAscii( "-display" ) || aParam.equalsAscii( "--display" ) )
627*cdf0e10cSrcweir 		{
628*cdf0e10cSrcweir 			pCmdLineAry[i+1] = g_strdup( "--display" );
629*cdf0e10cSrcweir 			osl_getCommandArg(i+1, &aParam.pData );
630*cdf0e10cSrcweir 			aDisplay = rtl::OUStringToOString( aParam, aEnc );
631*cdf0e10cSrcweir 		}
632*cdf0e10cSrcweir 		else
633*cdf0e10cSrcweir 	        pCmdLineAry[i+1] = g_strdup( aBParam.getStr() );
634*cdf0e10cSrcweir 	}
635*cdf0e10cSrcweir     // add executable
636*cdf0e10cSrcweir     nParams++;
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir     g_set_application_name(X11SalData::getFrameClassName());
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     // Set consistant name of the root accessible
641*cdf0e10cSrcweir     rtl::OUString aAppName = Application::GetAppName();
642*cdf0e10cSrcweir     if( aAppName.getLength() > 0 )
643*cdf0e10cSrcweir     {
644*cdf0e10cSrcweir         rtl::OString aPrgName = rtl::OUStringToOString(aAppName, aEnc);
645*cdf0e10cSrcweir         g_set_prgname(aPrgName);
646*cdf0e10cSrcweir     }
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir     // init gtk/gdk
649*cdf0e10cSrcweir     gtk_init_check( &nParams, &pCmdLineAry );
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir     //gtk_init_check sets XError/XIOError handlers, we want our own one
652*cdf0e10cSrcweir     m_aOrigGTKXIOErrorHandler = XSetIOErrorHandler ( (XIOErrorHandler)X11SalData::XIOErrorHdl );
653*cdf0e10cSrcweir     PushXErrorLevel( !!getenv( "SAL_IGNOREXERRORS" ) );
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 	for (i = 0; i < nParams; i++ )
656*cdf0e10cSrcweir 		g_free( pCmdLineAry[i] );
657*cdf0e10cSrcweir 	delete [] pCmdLineAry;
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
660*cdf0e10cSrcweir 	if (g_getenv ("SAL_DEBUG_UPDATES"))
661*cdf0e10cSrcweir 		gdk_window_set_debug_updates (TRUE);
662*cdf0e10cSrcweir #endif
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     pGdkDisp = gdk_display_get_default();
665*cdf0e10cSrcweir 	if ( !pGdkDisp )
666*cdf0e10cSrcweir 	{
667*cdf0e10cSrcweir 	    rtl::OUString aProgramFileURL;
668*cdf0e10cSrcweir         osl_getExecutableFile( &aProgramFileURL.pData );
669*cdf0e10cSrcweir 	    rtl::OUString aProgramSystemPath;
670*cdf0e10cSrcweir         osl_getSystemPathFromFileURL (aProgramFileURL.pData, &aProgramSystemPath.pData);
671*cdf0e10cSrcweir         rtl::OString  aProgramName = rtl::OUStringToOString(
672*cdf0e10cSrcweir                                             aProgramSystemPath,
673*cdf0e10cSrcweir                                             osl_getThreadTextEncoding() );
674*cdf0e10cSrcweir 		fprintf( stderr, "%s X11 error: Can't open display: %s\n",
675*cdf0e10cSrcweir 				aProgramName.getStr(), aDisplay.getStr());
676*cdf0e10cSrcweir 		fprintf( stderr, "   Set DISPLAY environment variable, use -display option\n");
677*cdf0e10cSrcweir 		fprintf( stderr, "   or check permissions of your X-Server\n");
678*cdf0e10cSrcweir 		fprintf( stderr, "   (See \"man X\" resp. \"man xhost\" for details)\n");
679*cdf0e10cSrcweir 		fflush( stderr );
680*cdf0e10cSrcweir 		exit(0);
681*cdf0e10cSrcweir 	}
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir 	/*
684*cdf0e10cSrcweir 	 * if a -display switch was used, we need
685*cdf0e10cSrcweir 	 * to set the environment accoringly since
686*cdf0e10cSrcweir 	 * the clipboard build another connection
687*cdf0e10cSrcweir 	 * to the xserver using $DISPLAY
688*cdf0e10cSrcweir 	 */
689*cdf0e10cSrcweir 	rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("DISPLAY"));
690*cdf0e10cSrcweir 	const gchar *name = gdk_display_get_name( pGdkDisp );
691*cdf0e10cSrcweir 	rtl::OUString envValue(name, strlen(name), aEnc);
692*cdf0e10cSrcweir 	osl_setEnvironment(envVar.pData, envValue.pData);
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir 	Display *pDisp = gdk_x11_display_get_xdisplay( pGdkDisp );
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir 	m_pGtkSalDisplay = new GtkSalDisplay( pGdkDisp );
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir     gdk_window_add_filter( NULL, call_filterGdkEvent, m_pGtkSalDisplay );
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir     PushXErrorLevel( true );
701*cdf0e10cSrcweir 	SalI18N_KeyboardExtension *pKbdExtension = new SalI18N_KeyboardExtension( pDisp );
702*cdf0e10cSrcweir 	XSync( pDisp, False );
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir 	pKbdExtension->UseExtension( ! HasXErrorOccured() );
705*cdf0e10cSrcweir     PopXErrorLevel();
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	m_pGtkSalDisplay->SetKbdExtension( pKbdExtension );
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     g_signal_connect( G_OBJECT(gdk_keymap_get_default()), "keys_changed", G_CALLBACK(signalKeysChanged), m_pGtkSalDisplay );
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir     // add signal handler to notify screen size changes
712*cdf0e10cSrcweir     int nScreens = gdk_display_get_n_screens( pGdkDisp );
713*cdf0e10cSrcweir     for( int n = 0; n < nScreens; n++ )
714*cdf0e10cSrcweir     {
715*cdf0e10cSrcweir         GdkScreen *pScreen = gdk_display_get_screen( pGdkDisp, n );
716*cdf0e10cSrcweir         if( pScreen )
717*cdf0e10cSrcweir         {
718*cdf0e10cSrcweir             g_signal_connect( G_OBJECT(pScreen), "size-changed", G_CALLBACK(signalScreenSizeChanged), m_pGtkSalDisplay );
719*cdf0e10cSrcweir             if( ! gtk_check_version( 2, 14, 0 ) ) // monitors-changed came in with 2.14, avoid an assertion
720*cdf0e10cSrcweir                 g_signal_connect( G_OBJECT(pScreen), "monitors-changed", G_CALLBACK(signalMonitorsChanged), m_pGtkSalDisplay );
721*cdf0e10cSrcweir         }
722*cdf0e10cSrcweir     }
723*cdf0e10cSrcweir }
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir extern "C"
726*cdf0e10cSrcweir {
727*cdf0e10cSrcweir     gboolean call_timeoutFn(gpointer data)
728*cdf0e10cSrcweir     {
729*cdf0e10cSrcweir         return GtkXLib::timeoutFn(data);
730*cdf0e10cSrcweir     }
731*cdf0e10cSrcweir }
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir gboolean GtkXLib::timeoutFn(gpointer data)
734*cdf0e10cSrcweir {
735*cdf0e10cSrcweir 	SalData *pSalData = GetSalData();
736*cdf0e10cSrcweir 	GtkXLib *pThis = (GtkXLib *) data;
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir 	pSalData->m_pInstance->GetYieldMutex()->acquire();
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 	if( pThis->m_pTimeout )
741*cdf0e10cSrcweir 	{
742*cdf0e10cSrcweir 		g_source_unref (pThis->m_pTimeout);
743*cdf0e10cSrcweir 		pThis->m_pTimeout = NULL;
744*cdf0e10cSrcweir 	}
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir 	// Auto-restart immediately
747*cdf0e10cSrcweir 	pThis->StartTimer( pThis->m_nTimeoutMS );
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir 	GetX11SalData()->Timeout();
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir 	pSalData->m_pInstance->GetYieldMutex()->release();
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir 	return FALSE;
754*cdf0e10cSrcweir }
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir void GtkXLib::StartTimer( sal_uLong nMS )
757*cdf0e10cSrcweir {
758*cdf0e10cSrcweir 	m_nTimeoutMS = nMS; // for restarting
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir 	if (m_pTimeout)
761*cdf0e10cSrcweir 	{
762*cdf0e10cSrcweir 		g_source_destroy (m_pTimeout);
763*cdf0e10cSrcweir 		g_source_unref (m_pTimeout);
764*cdf0e10cSrcweir 	}
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir 	m_pTimeout = g_timeout_source_new (m_nTimeoutMS);
767*cdf0e10cSrcweir     // #i36226# timers should be executed with lower priority
768*cdf0e10cSrcweir     // than XEvents like in generic plugin
769*cdf0e10cSrcweir     g_source_set_priority( m_pTimeout, G_PRIORITY_LOW );
770*cdf0e10cSrcweir 	g_source_set_can_recurse (m_pTimeout, TRUE);
771*cdf0e10cSrcweir 	g_source_set_callback (m_pTimeout, call_timeoutFn,
772*cdf0e10cSrcweir 						   (gpointer) this, NULL);
773*cdf0e10cSrcweir 	g_source_attach (m_pTimeout, g_main_context_default ());
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir     SalXLib::StartTimer( nMS );
776*cdf0e10cSrcweir }
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir void GtkXLib::StopTimer()
779*cdf0e10cSrcweir {
780*cdf0e10cSrcweir     SalXLib::StopTimer();
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir 	if (m_pTimeout)
783*cdf0e10cSrcweir 	{
784*cdf0e10cSrcweir 		g_source_destroy (m_pTimeout);
785*cdf0e10cSrcweir 		g_source_unref (m_pTimeout);
786*cdf0e10cSrcweir 		m_pTimeout = NULL;
787*cdf0e10cSrcweir 	}
788*cdf0e10cSrcweir }
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir extern "C"
791*cdf0e10cSrcweir {
792*cdf0e10cSrcweir     gboolean call_userEventFn( gpointer data )
793*cdf0e10cSrcweir     {
794*cdf0e10cSrcweir         return GtkXLib::userEventFn( data );
795*cdf0e10cSrcweir     }
796*cdf0e10cSrcweir }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir gboolean GtkXLib::userEventFn(gpointer data)
799*cdf0e10cSrcweir {
800*cdf0e10cSrcweir 	gboolean bContinue;
801*cdf0e10cSrcweir 	GtkXLib *pThis = (GtkXLib *) data;
802*cdf0e10cSrcweir 	SalData *pSalData = GetSalData();
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir 	pSalData->m_pInstance->GetYieldMutex()->acquire();
805*cdf0e10cSrcweir 	pThis->m_pGtkSalDisplay->EventGuardAcquire();
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir 	if( !pThis->m_pGtkSalDisplay->HasMoreEvents() )
808*cdf0e10cSrcweir 	{
809*cdf0e10cSrcweir 		if( pThis->m_pUserEvent )
810*cdf0e10cSrcweir 		{
811*cdf0e10cSrcweir 			g_source_unref (pThis->m_pUserEvent);
812*cdf0e10cSrcweir 			pThis->m_pUserEvent = NULL;
813*cdf0e10cSrcweir 		}
814*cdf0e10cSrcweir 		bContinue = FALSE;
815*cdf0e10cSrcweir 	}
816*cdf0e10cSrcweir 	else
817*cdf0e10cSrcweir 		bContinue = TRUE;
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir 	pThis->m_pGtkSalDisplay->EventGuardRelease();
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir 	pThis->m_pGtkSalDisplay->DispatchInternalEvent();
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir 	pSalData->m_pInstance->GetYieldMutex()->release();
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir 	return bContinue;
826*cdf0e10cSrcweir }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir // hEventGuard_ held during this invocation
829*cdf0e10cSrcweir void GtkXLib::PostUserEvent()
830*cdf0e10cSrcweir {
831*cdf0e10cSrcweir 	if( !m_pUserEvent ) // not pending anyway
832*cdf0e10cSrcweir 	{
833*cdf0e10cSrcweir 		m_pUserEvent = g_idle_source_new();
834*cdf0e10cSrcweir 		g_source_set_priority( m_pUserEvent, G_PRIORITY_HIGH );
835*cdf0e10cSrcweir 		g_source_set_can_recurse (m_pUserEvent, TRUE);
836*cdf0e10cSrcweir 		g_source_set_callback (m_pUserEvent, call_userEventFn,
837*cdf0e10cSrcweir 							   (gpointer) this, NULL);
838*cdf0e10cSrcweir 		g_source_attach (m_pUserEvent, g_main_context_default ());
839*cdf0e10cSrcweir 	}
840*cdf0e10cSrcweir     Wakeup();
841*cdf0e10cSrcweir }
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir void GtkXLib::Wakeup()
844*cdf0e10cSrcweir {
845*cdf0e10cSrcweir 	g_main_context_wakeup( g_main_context_default () );
846*cdf0e10cSrcweir }
847*cdf0e10cSrcweir 
848*cdf0e10cSrcweir void GtkXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
849*cdf0e10cSrcweir {
850*cdf0e10cSrcweir     /* #i33212# only enter g_main_context_iteration in one thread at any one
851*cdf0e10cSrcweir      * time, else one of them potentially will never end as long as there is
852*cdf0e10cSrcweir      * another thread in in there. Having only one yieldin thread actually dispatch
853*cdf0e10cSrcweir      * fits the vcl event model (see e.g. the generic plugin).
854*cdf0e10cSrcweir      */
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir     bool bDispatchThread = false;
857*cdf0e10cSrcweir     gboolean wasEvent = FALSE;
858*cdf0e10cSrcweir     {
859*cdf0e10cSrcweir         // release YieldMutex (and re-acquire at block end)
860*cdf0e10cSrcweir         YieldMutexReleaser aReleaser;
861*cdf0e10cSrcweir         if( osl_tryToAcquireMutex( m_aDispatchMutex ) )
862*cdf0e10cSrcweir             bDispatchThread = true;
863*cdf0e10cSrcweir         else if( ! bWait )
864*cdf0e10cSrcweir             return; // someone else is waiting already, return
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir         if( bDispatchThread )
868*cdf0e10cSrcweir         {
869*cdf0e10cSrcweir             int nMaxEvents = bHandleAllCurrentEvents ? 100 : 1;
870*cdf0e10cSrcweir             gboolean wasOneEvent = TRUE;
871*cdf0e10cSrcweir             while( nMaxEvents-- && wasOneEvent )
872*cdf0e10cSrcweir             {
873*cdf0e10cSrcweir                 wasOneEvent = g_main_context_iteration( NULL, FALSE );
874*cdf0e10cSrcweir                 if( wasOneEvent )
875*cdf0e10cSrcweir                     wasEvent = TRUE;
876*cdf0e10cSrcweir             }
877*cdf0e10cSrcweir             if( bWait && ! wasEvent )
878*cdf0e10cSrcweir                 wasEvent = g_main_context_iteration( NULL, TRUE );
879*cdf0e10cSrcweir         }
880*cdf0e10cSrcweir         else if( bWait )
881*cdf0e10cSrcweir        	{
882*cdf0e10cSrcweir             /* #i41693# in case the dispatch thread hangs in join
883*cdf0e10cSrcweir              * for this thread the condition will never be set
884*cdf0e10cSrcweir              * workaround: timeout of 1 second a emergency exit
885*cdf0e10cSrcweir              */
886*cdf0e10cSrcweir             // we are the dispatch thread
887*cdf0e10cSrcweir             osl_resetCondition( m_aDispatchCondition );
888*cdf0e10cSrcweir             TimeValue aValue = { 1, 0 };
889*cdf0e10cSrcweir             osl_waitCondition( m_aDispatchCondition, &aValue );
890*cdf0e10cSrcweir         }
891*cdf0e10cSrcweir     }
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir     if( bDispatchThread )
894*cdf0e10cSrcweir     {
895*cdf0e10cSrcweir         osl_releaseMutex( m_aDispatchMutex );
896*cdf0e10cSrcweir         if( wasEvent )
897*cdf0e10cSrcweir             osl_setCondition( m_aDispatchCondition ); // trigger non dispatch thread yields
898*cdf0e10cSrcweir     }
899*cdf0e10cSrcweir }
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir extern "C" {
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir typedef struct {
904*cdf0e10cSrcweir 	GSource       source;
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir 	GPollFD       pollfd;
907*cdf0e10cSrcweir 	GIOCondition  condition;
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir 	YieldFunc     pending;
910*cdf0e10cSrcweir 	YieldFunc     handle;
911*cdf0e10cSrcweir 	gpointer      user_data;
912*cdf0e10cSrcweir } SalWatch;
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir static gboolean
915*cdf0e10cSrcweir sal_source_prepare (GSource *source,
916*cdf0e10cSrcweir 					gint    *timeout)
917*cdf0e10cSrcweir {
918*cdf0e10cSrcweir 	SalWatch *watch = (SalWatch *)source;
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir 	*timeout = -1;
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir 	if (watch->pending &&
923*cdf0e10cSrcweir 	    watch->pending (watch->pollfd.fd, watch->user_data)) {
924*cdf0e10cSrcweir 		watch->pollfd.revents |= watch->condition;
925*cdf0e10cSrcweir 		return TRUE;
926*cdf0e10cSrcweir 	}
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir 	return FALSE;
929*cdf0e10cSrcweir }
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir static gboolean
932*cdf0e10cSrcweir sal_source_check (GSource *source)
933*cdf0e10cSrcweir {
934*cdf0e10cSrcweir 	SalWatch *watch = (SalWatch *)source;
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir 	return watch->pollfd.revents & watch->condition;
937*cdf0e10cSrcweir }
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir static gboolean
940*cdf0e10cSrcweir sal_source_dispatch (GSource    *source,
941*cdf0e10cSrcweir 					 GSourceFunc,
942*cdf0e10cSrcweir 					 gpointer)
943*cdf0e10cSrcweir {
944*cdf0e10cSrcweir 	SalData *pSalData = GetSalData();
945*cdf0e10cSrcweir 	SalWatch *watch = (SalWatch *) source;
946*cdf0e10cSrcweir 
947*cdf0e10cSrcweir 	pSalData->m_pInstance->GetYieldMutex()->acquire();
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir 	watch->handle (watch->pollfd.fd, watch->user_data);
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir 	pSalData->m_pInstance->GetYieldMutex()->release();
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir 	return TRUE;
954*cdf0e10cSrcweir }
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir static void
957*cdf0e10cSrcweir sal_source_finalize (GSource*)
958*cdf0e10cSrcweir {
959*cdf0e10cSrcweir }
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir static GSourceFuncs sal_source_watch_funcs = {
962*cdf0e10cSrcweir 	sal_source_prepare,
963*cdf0e10cSrcweir 	sal_source_check,
964*cdf0e10cSrcweir 	sal_source_dispatch,
965*cdf0e10cSrcweir 	sal_source_finalize,
966*cdf0e10cSrcweir     NULL,
967*cdf0e10cSrcweir     NULL
968*cdf0e10cSrcweir };
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir static GSource *
971*cdf0e10cSrcweir sal_source_create_watch (int           fd,
972*cdf0e10cSrcweir                          GIOCondition  condition,
973*cdf0e10cSrcweir                          YieldFunc     pending,
974*cdf0e10cSrcweir                          YieldFunc     handle,
975*cdf0e10cSrcweir                          gpointer      user_data)
976*cdf0e10cSrcweir {
977*cdf0e10cSrcweir 	GSource      *source;
978*cdf0e10cSrcweir 	SalWatch     *watch;
979*cdf0e10cSrcweir 	GMainContext *context = g_main_context_default ();
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir 	source = g_source_new (&sal_source_watch_funcs,
982*cdf0e10cSrcweir 			       sizeof (SalWatch));
983*cdf0e10cSrcweir 	watch = (SalWatch *) source;
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir 	watch->pollfd.fd     = fd;
986*cdf0e10cSrcweir 	watch->pollfd.events = condition;
987*cdf0e10cSrcweir 	watch->condition = condition;
988*cdf0e10cSrcweir 	watch->pending   = pending;
989*cdf0e10cSrcweir 	watch->handle    = handle;
990*cdf0e10cSrcweir 	watch->user_data = user_data;
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir 	g_source_set_can_recurse (source, TRUE);
993*cdf0e10cSrcweir 	g_source_add_poll (source, &watch->pollfd);
994*cdf0e10cSrcweir 	g_source_attach (source, context);
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir 	return source;
997*cdf0e10cSrcweir }
998*cdf0e10cSrcweir 
999*cdf0e10cSrcweir } // extern "C"
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir void GtkXLib::Insert( int       nFD,
1002*cdf0e10cSrcweir 		      void     *data,
1003*cdf0e10cSrcweir 		      YieldFunc pending,
1004*cdf0e10cSrcweir 		      YieldFunc,
1005*cdf0e10cSrcweir 		      YieldFunc handle )
1006*cdf0e10cSrcweir {
1007*cdf0e10cSrcweir 	GSource *source = sal_source_create_watch
1008*cdf0e10cSrcweir 		( nFD, (GIOCondition) ((G_IO_IN|G_IO_PRI) |
1009*cdf0e10cSrcweir 				       (G_IO_ERR|G_IO_HUP|G_IO_NVAL)),
1010*cdf0e10cSrcweir 		  pending, handle, data );
1011*cdf0e10cSrcweir 	m_aSources.push_back( source );
1012*cdf0e10cSrcweir }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir void GtkXLib::Remove( int nFD )
1015*cdf0e10cSrcweir {
1016*cdf0e10cSrcweir     ::std::list< GSource * >::iterator it;
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir 	for (it = m_aSources.begin(); it != m_aSources.end(); ++it)
1019*cdf0e10cSrcweir 	{
1020*cdf0e10cSrcweir 		SalWatch *watch = (SalWatch *) *it;
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir 		if (watch->pollfd.fd == nFD)
1023*cdf0e10cSrcweir 		{
1024*cdf0e10cSrcweir             m_aSources.erase( it );
1025*cdf0e10cSrcweir 
1026*cdf0e10cSrcweir 			g_source_destroy ((GSource *)watch);
1027*cdf0e10cSrcweir 			g_source_unref   ((GSource *)watch);
1028*cdf0e10cSrcweir 			return;
1029*cdf0e10cSrcweir 		}
1030*cdf0e10cSrcweir 	}
1031*cdf0e10cSrcweir }
1032*cdf0e10cSrcweir 
1033*cdf0e10cSrcweir /**********************************************************************
1034*cdf0e10cSrcweir  * class GtkData                                                      *
1035*cdf0e10cSrcweir  **********************************************************************/
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir GtkData::~GtkData()
1038*cdf0e10cSrcweir {
1039*cdf0e10cSrcweir }
1040*cdf0e10cSrcweir 
1041*cdf0e10cSrcweir void GtkData::Init()
1042*cdf0e10cSrcweir {
1043*cdf0e10cSrcweir     pXLib_ = new GtkXLib();
1044*cdf0e10cSrcweir     pXLib_->Init();
1045*cdf0e10cSrcweir }
1046