static gboolean gtkQueryTooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, Ihandle* ih) { char* value = iupAttribGet(ih, "TIPRECT"); if (value && !keyboard_mode) { GdkRectangle rect; int x1, x2, y1, y2; sscanf(value, "%d %d %d %d", &x1, &y1, &x2, &y2); rect.x = x1; rect.y = y1; rect.width = x2-x1+1; rect.height = y2-y1+1; gtk_tooltip_set_tip_area(tooltip, &rect); } else gtk_tooltip_set_tip_area(tooltip, NULL); value = iupAttribGet(ih, "TIPICON"); if (!value) gtk_tooltip_set_icon(tooltip, NULL); else { GdkPixbuf* icon = (GdkPixbuf*)iupImageGetIcon(value); if (icon) gtk_tooltip_set_icon(tooltip, icon); } (void)y; (void)x; (void)widget; return FALSE; }
static gboolean empathy_roster_view_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip) { EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget); FolksIndividual *individual; gboolean result; GtkListBoxRow *row; individual = empathy_roster_view_get_individual_at_y (self, y, &row); if (individual == NULL) return FALSE; g_signal_emit (self, signals[SIG_INDIVIDUAL_TOOLTIP], 0, individual, keyboard_mode, tooltip, &result); if (result) { GtkAllocation allocation; gtk_widget_get_allocation (GTK_WIDGET (row), &allocation); gtk_tooltip_set_tip_area (tooltip, (GdkRectangle *) &allocation); } return result; }
static gboolean pgd_selections_drawing_area_query_tooltip (GtkWidget *area, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, PgdSelectionsDemo *demo) { gboolean over_selection; if (!demo->selected_text) return FALSE; over_selection = cairo_region_contains_point (demo->selected_region, x / demo->scale, y / demo->scale); if (over_selection) { GdkRectangle selection_area; cairo_region_get_extents (demo->selected_region, (cairo_rectangle_int_t *)&selection_area); selection_area.x *= demo->scale; selection_area.y *= demo->scale; selection_area.width *= demo->scale; selection_area.height *= demo->scale; gtk_tooltip_set_text (tooltip, demo->selected_text); gtk_tooltip_set_tip_area (tooltip, &selection_area); return TRUE; } return FALSE; }
static void gtk_tooltip_reset (GtkTooltip *tooltip) { gtk_tooltip_set_markup (tooltip, NULL); gtk_tooltip_set_icon (tooltip, NULL); gtk_tooltip_set_tip_area (tooltip, NULL); /* See if the custom widget is again set from the query-tooltip * callback. */ tooltip->custom_was_reset = FALSE; }
static gboolean git_source_view_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_tooltip, GtkTooltip *tooltip) { GitSourceView *sview = (GitSourceView *) widget; GitSourceViewPrivate *priv = sview->priv; gint line_num, num_lines; gboolean ret = TRUE; GString *markup; const gchar *part; gchar *part_markup; const GitAnnotatedSourceLine *line; GitCommit *commit; if (priv->line_height < 1 || priv->paint_source == NULL) return FALSE; num_lines = git_annotated_source_get_n_lines (priv->paint_source); line_num = (y + priv->y_offset) / priv->line_height; if (x < 0 || x >= priv->max_hash_length || line_num < 0 || line_num >= num_lines) return FALSE; line = git_annotated_source_get_line (priv->paint_source, line_num); commit = line->commit; markup = g_string_new (""); if ((part = git_commit_get_prop (commit, "author"))) { part_markup = g_markup_printf_escaped ("<b>%s</b>", part); g_string_append (markup, part_markup); g_free (part_markup); } if ((part = git_commit_get_prop (commit, "author-mail"))) { if (markup->len > 0) g_string_append_c (markup, ' '); part_markup = g_markup_escape_text (part, -1); g_string_append (markup, part_markup); g_free (part_markup); } if ((part = git_commit_get_prop (commit, "author-time"))) { GTimeVal time_; char *tail; errno = 0; time_.tv_sec = strtol (part, &tail, 10); time_.tv_usec = 0; if (errno == 0 && *tail == '\0') { gchar *display_time; if (markup->len > 0) g_string_append_c (markup, '\n'); display_time = git_format_time_for_display (&time_); part_markup = g_markup_escape_text (display_time, -1); g_free (display_time); g_string_append (markup, part_markup); g_free (part_markup); } } if ((part = git_commit_get_prop (commit, "summary"))) { gchar *stripped_part; if (markup->len > 0) g_string_append_c (markup, '\n'); while (*part && isspace (*part)) part++; stripped_part = g_strdup (part); g_strchomp (stripped_part); part_markup = g_markup_printf_escaped ("<i>%s</i>", stripped_part); g_free (stripped_part); g_string_append (markup, part_markup); g_free (part_markup); } if (markup->len > 0) { GdkRectangle tip_area; tip_area.x = 0; tip_area.y = line_num * priv->line_height - priv->y_offset; tip_area.width = priv->max_hash_length; tip_area.height = priv->line_height; gtk_tooltip_set_markup (tooltip, markup->str); gtk_tooltip_set_tip_area (tooltip, &tip_area); } else ret = FALSE; g_string_free (markup, TRUE); return ret; }
static gboolean _dtv_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip) { int bin_x, bin_y; GtkTreePath *path = NULL; GtkTreeViewColumn *column; GtkTreeIter iter; GtkTreeModel *model; GdkRectangle cell_area; GString *markup; gboolean had_info = FALSE; gtk_tree_view_convert_widget_to_bin_window_coords ( GTK_TREE_VIEW (widget), x, y, &bin_x, &bin_y); if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), bin_x, bin_y, &path, &column, NULL, NULL)) { model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); if (gtk_tree_model_get_iter (model, &iter, path)) { /* show some useful information */ Diagram *diagram; Layer *layer; DiaObject *object; gtk_tree_model_get (model, &iter, DIAGRAM_COLUMN, &diagram, -1); gtk_tree_model_get (model, &iter, LAYER_COLUMN, &layer, -1); gtk_tree_model_get (model, &iter, OBJECT_COLUMN, &object, -1); markup = g_string_new (NULL); if (diagram) { gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Diagram"), diagram->filename); g_string_append (markup, em); g_free (em); } if (layer) { gchar *name = layer_get_name (layer); gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Layer"), name); g_string_append (markup, em); g_free (em); g_free (name); } else if (diagram) { int layers = data_layer_count (DIA_DIAGRAM_DATA (diagram)); g_string_append_printf (markup, g_dngettext (GETTEXT_PACKAGE, "%d Layer", "%d Layers", layers), layers); } if (object) { gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Type"), object->type->name); g_string_append (markup, em); g_free (em); g_string_append_printf (markup, "<b>%s</b>: %g,%g\n", Q_("object|Position"), object->position.x, object->position.y); g_string_append_printf (markup, "%d %s", g_list_length (object->children), _("Children")); /* and some dia_object_get_meta ? */ } else if (layer) { int objects = layer_object_count (layer); g_string_append_printf (markup, g_dngettext (GETTEXT_PACKAGE, "%d Object", "%d Objects", objects), objects); } if (markup->len > 0) { gtk_tree_view_get_cell_area (GTK_TREE_VIEW (widget), path, column, &cell_area); gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (widget), cell_area.x, cell_area.y, &cell_area.x, &cell_area.y); gtk_tooltip_set_tip_area (tooltip, &cell_area); gtk_tooltip_set_markup (tooltip, markup->str); had_info = TRUE; } /* drop references */ if (diagram) g_object_unref (diagram); g_string_free (markup, TRUE); } gtk_tree_path_free (path); if (had_info) return TRUE; } return GTK_WIDGET_CLASS (_dtv_parent_class)->query_tooltip (widget, x, y, keyboard_mode, tooltip); }