1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (C) 2016 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "meta-tooltip.h"
struct _MetaTooltip
{
GtkWindow parent;
GtkWidget *box;
GtkWidget *label;
};
G_DEFINE_TYPE (MetaTooltip, meta_tooltip, GTK_TYPE_WINDOW)
static void
meta_tooltip_realize (GtkWidget *widget)
{
GdkScreen *screen;
GdkVisual *visual;
gboolean has_rgba;
GtkStyleContext *context;
screen = gtk_widget_get_screen (widget);
visual = gdk_screen_get_rgba_visual (screen);
has_rgba = visual && gdk_screen_is_composited (screen);
context = gtk_widget_get_style_context (widget);
if (has_rgba)
{
gtk_widget_set_visual (widget, visual);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_CSD);
}
else
{
gtk_style_context_add_class (context, "solid-csd");
}
GTK_WIDGET_CLASS (meta_tooltip_parent_class)->realize (widget);
}
static void
meta_tooltip_class_init (MetaTooltipClass *tooltip_class)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (tooltip_class);
widget_class->realize = meta_tooltip_realize;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_TIP);
gtk_widget_class_set_css_name (widget_class, "tooltip");
}
static void
meta_tooltip_init (MetaTooltip *tooltip)
{
tooltip->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_container_add (GTK_CONTAINER (tooltip), tooltip->box);
gtk_widget_show (tooltip->box);
gtk_widget_set_margin_start (tooltip->box, 6);
gtk_widget_set_margin_end (tooltip->box, 6);
gtk_widget_set_margin_top (tooltip->box, 6);
gtk_widget_set_margin_bottom (tooltip->box, 6);
tooltip->label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (tooltip->box), tooltip->label, FALSE, FALSE, 0);
gtk_label_set_line_wrap (GTK_LABEL (tooltip->label), TRUE);
gtk_label_set_max_width_chars (GTK_LABEL (tooltip->label), 70);
}
GtkWidget *
meta_tooltip_new (void)
{
return g_object_new (META_TYPE_TOOLTIP,
"type", GTK_WINDOW_POPUP,
"type-hint", GDK_WINDOW_TYPE_HINT_TOOLTIP,
"resizable", FALSE,
NULL);
}
void
meta_tooltip_set_label_markup (MetaTooltip *tooltip,
const gchar *markup)
{
if (markup != NULL)
{
gtk_label_set_markup (GTK_LABEL (tooltip->label), markup);
gtk_widget_show (tooltip->label);
}
else
{
gtk_widget_hide (tooltip->label);
}
}
void
meta_tooltip_set_label_text (MetaTooltip *tooltip,
const gchar *text)
{
if (text != NULL)
{
gtk_label_set_text (GTK_LABEL (tooltip->label), text);
gtk_widget_show (tooltip->label);
}
else
{
gtk_widget_hide (tooltip->label);
}
}
|