00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00040
00041
00042
00043
00044
00045 static int screen_right_edge = 0;
00046
00047
00048
00049
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 }