]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/utilsgtk.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/utilsgtk.cpp 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  10 // For compilers that support precompilation, includes "wx.h". 
  11 #include "wx/wxprec.h" 
  14 #include "wx/string.h" 
  16 #include "wx/apptrait.h" 
  20 #include "wx/process.h" 
  22 #include "wx/unix/execute.h" 
  27 #include <sys/types.h> 
  28 #include <sys/wait.h>   // for WNOHANG 
  36 #ifdef HAVE_X11_XKBLIB_H 
  37     /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with 
  38      * field named "explicit" - which is, of course, an error for a C++ 
  39      * compiler. To be on the safe side, just redefine it everywhere. */ 
  40     #define explicit __wx_explicit 
  42     #include "X11/XKBlib.h" 
  45 #endif // HAVE_X11_XKBLIB_H 
  47 //----------------------------------------------------------------------------- 
  49 //----------------------------------------------------------------------------- 
  51 extern GtkWidget 
*wxGetRootWindow(); 
  53 //---------------------------------------------------------------------------- 
  55 //---------------------------------------------------------------------------- 
  57 // on OS/2, we use the wxBell from wxBase library 
  65 /* Don't synthesize KeyUp events holding down a key and producing 
  66    KeyDown events with autorepeat. */ 
  67 #ifdef HAVE_X11_XKBLIB_H 
  68 bool wxSetDetectableAutoRepeat( bool flag 
) 
  71     XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag
, &result 
); 
  72     return result
;       /* TRUE if keyboard hardware supports this mode */ 
  75 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) ) 
  81 // Escapes string so that it is valid Pango markup XML string: 
  82 wxString 
wxEscapeStringForPangoMarkup(const wxString
& str
) 
  84     size_t len 
= str
.length(); 
  87     for (size_t i 
= 0; i 
< len
; i
++) 
 116 // ---------------------------------------------------------------------------- 
 117 // display characterstics 
 118 // ---------------------------------------------------------------------------- 
 122     return GDK_DISPLAY(); 
 125 void wxDisplaySize( int *width
, int *height 
) 
 127     if (width
) *width 
= gdk_screen_width(); 
 128     if (height
) *height 
= gdk_screen_height(); 
 131 void wxDisplaySizeMM( int *width
, int *height 
) 
 133     if (width
) *width 
= gdk_screen_width_mm(); 
 134     if (height
) *height 
= gdk_screen_height_mm(); 
 137 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
) 
 139     // This is supposed to return desktop dimensions minus any window 
 140     // manager panels, menus, taskbars, etc.  If there is a way to do that 
 141     // for this platform please fix this function, otherwise it defaults 
 142     // to the entire desktop. 
 145     wxDisplaySize(width
, height
); 
 148 void wxGetMousePosition( int* x
, int* y 
) 
 150     gdk_window_get_pointer( (GdkWindow
*) NULL
, x
, y
, (GdkModifierType
*) NULL 
); 
 153 bool wxColourDisplay() 
 160     return gdk_window_get_visual( wxGetRootWindow()->window 
)->depth
; 
 163 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo() 
 165     static wxToolkitInfo info
; 
 166     info
.shortName 
= _T("gtk2"); 
 167     info
.name 
= _T("wxGTK"); 
 168 #ifdef __WXUNIVERSAL__ 
 169     info
.shortName 
<< _T("univ"); 
 170     info
.name 
<< _T("/wxUniversal"); 
 172     info
.versionMajor 
= gtk_major_version
; 
 173     info
.versionMinor 
= gtk_minor_version
; 
 178 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
) 
 180     return wxGenericFindWindowAtPoint(pt
); 
 184 // ---------------------------------------------------------------------------- 
 185 // subprocess routines 
 186 // ---------------------------------------------------------------------------- 
 190 void GTK_EndProcessDetector(gpointer data
, gint source
, 
 191                             GdkInputCondition 
WXUNUSED(condition
) ) 
 193    wxEndProcessData 
*proc_data 
= (wxEndProcessData 
*)data
; 
 195    // has the process really terminated? unfortunately GDK (or GLib) seem to 
 196    // generate G_IO_HUP notification even when it simply tries to read from a 
 197    // closed fd and hasn't terminated at all 
 198    int pid 
= (proc_data
->pid 
> 0) ? proc_data
->pid 
: -(proc_data
->pid
); 
 200    int rc 
= waitpid(pid
, &status
, WNOHANG
); 
 204        // no, it didn't exit yet, continue waiting 
 208    // set exit code to -1 if something bad happened 
 209    proc_data
->exitcode 
= rc 
!= -1 && WIFEXITED(status
) ? WEXITSTATUS(status
) 
 212    // child exited, end waiting 
 215    // don't call us again! 
 216    gdk_input_remove(proc_data
->tag
); 
 218    wxHandleProcessTermination(proc_data
); 
 222 int wxAddProcessCallback(wxEndProcessData 
*proc_data
, int fd
) 
 224     int tag 
= gdk_input_add(fd
, 
 226                             GTK_EndProcessDetector
, 
 227                             (gpointer
)proc_data
);