fixedtip.c

Go to the documentation of this file.
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 
00003 /* Metacity fixed tooltip routine */
00004 
00005 /* 
00006  * Copyright (C) 2001 Havoc Pennington
00007  * 
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00021  * 02111-1307, USA.
00022  */
00023 
00024 #include <config.h>
00025 #include "fixedtip.h"
00026 #include "ui.h"
00027 
00032 static GtkWidget *tip = NULL;
00033 
00037 static GtkWidget *label = NULL;
00038 /*
00039  * X coordinate of the right-hand edge of the screen.
00040  *
00041  * \bug  This appears to be a bug; screen_right_edge is calculated only when
00042  *       the window is redrawn.  Actually we should never cache it because
00043  *       different windows are different sizes.
00044  */
00045 static int screen_right_edge = 0;
00046 /*
00047  * Y coordinate of the bottom edge of the screen.
00048  *
00049  * \bug  As with screen_right_edge.
00050  */
00051 static int screen_bottom_edge = 0;
00052 
00053 static gint
00054 expose_handler (GtkTooltips *tooltips)
00055 {
00056   gtk_paint_flat_box (tip->style, tip->window,
00057                       GTK_STATE_NORMAL, GTK_SHADOW_OUT, 
00058                       NULL, tip, "tooltip",
00059                       0, 0, -1, -1);
00060 
00061   return FALSE;
00062 }
00063 
00064 void
00065 meta_fixed_tip_show (Display *xdisplay, int screen_number,
00066                      int root_x, int root_y,
00067                      const char *markup_text)
00068 {
00069   int w, h;
00070   
00071   if (tip == NULL)
00072     {      
00073       tip = gtk_window_new (GTK_WINDOW_POPUP);
00074       {
00075         GdkScreen *gdk_screen;
00076         GdkRectangle monitor;
00077         gint mon_num;
00078 
00079         gdk_screen = gdk_display_get_screen (gdk_display_get_default (),
00080                                              screen_number);
00081         gtk_window_set_screen (GTK_WINDOW (tip),
00082                                gdk_screen);
00083         mon_num = gdk_screen_get_monitor_at_point (gdk_screen, root_x, root_y);
00084         gdk_screen_get_monitor_geometry (gdk_screen, mon_num, &monitor);
00085         screen_right_edge = monitor.x + monitor.width;
00086         screen_bottom_edge = monitor.y + monitor.height;
00087       }
00088       
00089       gtk_widget_set_app_paintable (tip, TRUE);
00090       gtk_window_set_policy (GTK_WINDOW (tip), FALSE, FALSE, TRUE);
00091       gtk_widget_set_name (tip, "gtk-tooltips");
00092       gtk_container_set_border_width (GTK_CONTAINER (tip), 4);
00093 
00094       g_signal_connect_swapped (tip, "expose_event",
00095                                  G_CALLBACK (expose_handler), NULL);
00096 
00097       label = gtk_label_new (NULL);
00098       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
00099       gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
00100       gtk_widget_show (label);
00101       
00102       gtk_container_add (GTK_CONTAINER (tip), label);
00103 
00104       g_signal_connect (tip, "destroy",
00105                         G_CALLBACK (gtk_widget_destroyed), &tip);
00106     }
00107 
00108   gtk_label_set_markup (GTK_LABEL (label), markup_text);
00109   
00110   gtk_window_get_size (GTK_WINDOW (tip), &w, &h);
00111 
00112   if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
00113       root_x = MAX(0, root_x - w);
00114 
00115   if ((root_x + w) > screen_right_edge)
00116     root_x -= (root_x + w) - screen_right_edge;
00117   
00118   gtk_window_move (GTK_WINDOW (tip), root_x, root_y);
00119 
00120   gtk_widget_show (tip);
00121 }
00122 
00123 void
00124 meta_fixed_tip_hide (void)
00125 {
00126   if (tip)
00127     {
00128       gtk_widget_destroy (tip);
00129       tip = NULL;
00130     }
00131 }

Generated on Sat Aug 23 22:04:18 2008 for metacity by  doxygen 1.5.5