Back to index

lightning-sunbird  0.9+nobinonly
nsGtkUtils.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <unistd.h>
00039 #include <string.h>
00040 
00041 #include "nsGtkUtils.h"
00042 
00043 #include <gdk/gdkx.h>
00044 #include <gdk/gdkprivate.h>
00045 
00046 #ifdef NEED_USLEEP_PROTOTYPE
00047 extern "C" int usleep(unsigned int);
00048 #endif
00049 #if defined(__QNX__)
00050 #define usleep(s)    sleep(s)
00051 #endif
00052 
00054 #if 0
00055 /* staitc */ gint
00056 nsGtkUtils::gdk_query_pointer(GdkWindow * window,
00057                                                    gint *      x_out,
00058                                                    gint *      y_out)
00059 {
00060   g_return_val_if_fail(NULL != window, FALSE);
00061   g_return_val_if_fail(NULL != x_out, FALSE);
00062   g_return_val_if_fail(NULL != y_out, FALSE);
00063 
00064   Window root;
00065   Window child;
00066   int rootx, rooty;
00067   int winx = 0;
00068   int winy = 0;
00069   unsigned int xmask = 0;
00070   gint result = FALSE;
00071   
00072   *x_out = -1;
00073   *y_out = -1;
00074   
00075   result = XQueryPointer(GDK_WINDOW_XDISPLAY(window),
00076                          GDK_WINDOW_XWINDOW(window),
00077                          &root, 
00078                          &child,
00079                          &rootx,
00080                          &rooty,
00081                          &winx,
00082                          &winy,
00083                          &xmask);
00084   
00085   if (result)
00086   {
00087     *x_out = rootx;
00088     *y_out = rooty;
00089   }
00090 
00091   return result;
00092 }
00093 #endif
00094 
00095 /* static */ void 
00096 nsGtkUtils::gtk_widget_set_color(GtkWidget *  widget,
00097                                                          GtkRcFlags   flags,
00098                                                          GtkStateType state,
00099                                                          GdkColor *   color)
00100 {
00101   GtkRcStyle * rc_style;
00102 
00103   g_return_if_fail (widget != NULL);
00104   g_return_if_fail (GTK_IS_WIDGET (widget));
00105   g_return_if_fail (color != NULL);
00106   g_return_if_fail (flags == 0);
00107 
00108   rc_style = (GtkRcStyle *) gtk_object_get_data (GTK_OBJECT (widget), 
00109                                                                                      "modify-style");
00110 
00111   if (!rc_style)
00112   {
00113        rc_style = gtk_rc_style_new ();
00114 
00115        gtk_widget_modify_style (widget, rc_style);
00116 
00117        gtk_object_set_data (GTK_OBJECT (widget), "modify-style", rc_style);
00118   }
00119 
00120   if (flags & GTK_RC_FG)
00121   {
00122     rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_FG);
00123     rc_style->fg[state] = *color;
00124   }
00125 
00126   if (flags & GTK_RC_BG)
00127   {
00128     rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_BG);
00129     rc_style->bg[state] = *color;
00130   }
00131 
00132   if (flags & GTK_RC_TEXT)
00133   {
00134     rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_TEXT);
00135     rc_style->text[state] = *color;
00136   }
00137 
00138   if (flags & GTK_RC_BASE)
00139   {
00140     rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_BASE);
00141     rc_style->base[state] = *color;
00142   }
00143 }
00145 /* static */ GdkModifierType
00146 nsGtkUtils::gdk_keyboard_get_modifiers()
00147 {
00148   GdkModifierType m = (GdkModifierType) 0;
00149 
00150   gdk_window_get_pointer(NULL,NULL,NULL,&m);
00151 
00152   return m;
00153 }
00155 /* static */ void
00156 nsGtkUtils::gdk_window_flash(GdkWindow *    aGdkWindow,
00157                              unsigned int   aTimes,
00158                              unsigned long  aInterval,
00159                              GdkRegion * aRegion)
00160 {
00161   gint         x;
00162   gint         y;
00163   gint         width;
00164   gint         height;
00165   guint        i;
00166   GdkGC *      gc = 0;
00167   GdkColor     white;
00168 
00169   gdk_window_get_geometry(aGdkWindow,
00170                           NULL,
00171                           NULL,
00172                           &width,
00173                           &height,
00174                           NULL);
00175 
00176   gdk_window_get_origin (aGdkWindow,
00177                          &x,
00178                          &y);
00179 
00180   gc = gdk_gc_new(GDK_ROOT_PARENT());
00181 
00182   white.pixel = WhitePixel(gdk_display,DefaultScreen(gdk_display));
00183 
00184   gdk_gc_set_foreground(gc,&white);
00185   gdk_gc_set_function(gc,GDK_XOR);
00186   gdk_gc_set_subwindow(gc,GDK_INCLUDE_INFERIORS);
00187   
00188   gdk_region_offset(aRegion, x, y);
00189   gdk_gc_set_clip_region(gc, aRegion);
00190 
00191   /*
00192    * Need to do this twice so that the XOR effect can replace 
00193    * the original window contents.
00194    */
00195   for (i = 0; i < aTimes * 2; i++)
00196   {
00197     gdk_draw_rectangle(GDK_ROOT_PARENT(),
00198                        gc,
00199                        TRUE,
00200                        x,
00201                        y,
00202                        width,
00203                        height);
00204 
00205     gdk_flush();
00206     
00207     usleep(aInterval);
00208   }
00209 
00210   gdk_gc_destroy(gc);
00211 
00212   gdk_region_offset(aRegion, -x, -y);
00213 }