void gimp_text_editor_set_direction (GimpTextEditor *editor, GimpTextDirection base_dir) { g_return_if_fail (GIMP_IS_TEXT_EDITOR (editor)); if (editor->base_dir == base_dir) return; editor->base_dir = base_dir; if (editor->view) { switch (editor->base_dir) { case GIMP_TEXT_DIRECTION_LTR: case GIMP_TEXT_DIRECTION_TTB_RTL: case GIMP_TEXT_DIRECTION_TTB_RTL_UPRIGHT: case GIMP_TEXT_DIRECTION_TTB_LTR: case GIMP_TEXT_DIRECTION_TTB_LTR_UPRIGHT: gtk_widget_set_direction (editor->view, GTK_TEXT_DIR_LTR); break; case GIMP_TEXT_DIRECTION_RTL: gtk_widget_set_direction (editor->view, GTK_TEXT_DIR_RTL); break; } } gimp_ui_manager_update (editor->ui_manager, editor); g_signal_emit (editor, text_editor_signals[DIR_CHANGED], 0); }
static gint moz_gtk_scrollbar_trough_paint(GtkThemeWidgetType widget, GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, GtkTextDirection direction) { GtkStyle* style; GtkScrollbar *scrollbar; ensure_scrollbar_widget(); if (widget == MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL) scrollbar = GTK_SCROLLBAR(gParts->horizScrollbarWidget); else scrollbar = GTK_SCROLLBAR(gParts->vertScrollbarWidget); gtk_widget_set_direction(GTK_WIDGET(scrollbar), direction); style = gtk_widget_get_style(GTK_WIDGET(scrollbar)); TSOffsetStyleGCs(style, rect->x, rect->y); gtk_paint_box(style, drawable, GTK_STATE_ACTIVE, GTK_SHADOW_IN, cliprect, GTK_WIDGET(scrollbar), "trough", rect->x, rect->y, rect->width, rect->height); if (state->focused) { gtk_paint_focus(style, drawable, GTK_STATE_ACTIVE, cliprect, GTK_WIDGET(scrollbar), "trough", rect->x, rect->y, rect->width, rect->height); } return MOZ_GTK_SUCCESS; }
bool RenderThemeGtk::paintSliderTrack(RenderObject* object, const PaintInfo& info, const IntRect& rect) { if (info.context->paintingDisabled()) return false; ControlPart part = object->style()->appearance(); ASSERT(part == SliderHorizontalPart || part == SliderVerticalPart); // We shrink the trough rect slightly to make room for the focus indicator. IntRect troughRect(IntPoint(), rect.size()); // This is relative to rect. GtkWidget* widget = 0; if (part == SliderVerticalPart) { widget = gtkVScale(); troughRect.inflateY(-gtk_widget_get_style(widget)->ythickness); } else { widget = gtkHScale(); troughRect.inflateX(-gtk_widget_get_style(widget)->xthickness); } gtk_widget_set_direction(widget, gtkTextDirection(object->style()->direction())); WidgetRenderingContext widgetContext(info.context, rect); widgetContext.gtkPaintBox(troughRect, widget, GTK_STATE_ACTIVE, GTK_SHADOW_OUT, "trough"); if (isFocused(object)) widgetContext.gtkPaintFocus(IntRect(IntPoint(), rect.size()), widget, getGtkStateType(object), "trough"); return false; }
bool RenderThemeGtk::paintSliderThumb(RenderObject* object, const PaintInfo& info, const IntRect& rect) { if (info.context->paintingDisabled()) return false; ControlPart part = object->style()->appearance(); ASSERT(part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart); GtkWidget* widget = 0; const char* detail = 0; GtkOrientation orientation; if (part == SliderThumbVerticalPart) { widget = gtkVScale(); detail = "vscale"; orientation = GTK_ORIENTATION_VERTICAL; } else { widget = gtkHScale(); detail = "hscale"; orientation = GTK_ORIENTATION_HORIZONTAL; } gtk_widget_set_direction(widget, gtkTextDirection(object->style()->direction())); // Only some themes have slider thumbs respond to clicks and some don't. This information is // gathered via the 'activate-slider' property, but it's deprecated in GTK+ 2.22 and removed in // GTK+ 3.x. The drawback of not honoring it is that slider thumbs change color when you click // on them. IntRect thumbRect(IntPoint(), rect.size()); WidgetRenderingContext widgetContext(info.context, rect); widgetContext.gtkPaintSlider(thumbRect, widget, getGtkStateType(object), GTK_SHADOW_OUT, detail, orientation); return false; }
void TestRunner::setTextDirection(JSStringRef direction) { GUniquePtr<gchar> writingDirection(JSStringCopyUTF8CString(direction)); WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); if (g_str_equal(writingDirection.get(), "auto")) gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_NONE); else if (g_str_equal(writingDirection.get(), "ltr")) gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_LTR); else if (g_str_equal(writingDirection.get(), "rtl")) gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_RTL); else fprintf(stderr, "TestRunner::setTextDirection called with unknown direction: '%s'.\n", writingDirection.get()); }
static void ekiga_dialpad_init (EkigaDialpad *dialpad) { unsigned i; dialpad->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialpad, EKIGA_TYPE_DIALPAD, EkigaDialpadPrivate); gtk_grid_set_column_spacing (GTK_GRID (dialpad), 2); gtk_grid_set_row_spacing (GTK_GRID (dialpad), 2); gtk_grid_set_column_homogeneous (GTK_GRID (dialpad), TRUE); gtk_grid_set_row_homogeneous (GTK_GRID (dialpad), TRUE); // the dialpad is LTR even for RTL languages gtk_widget_set_direction (GTK_WIDGET (dialpad), GTK_TEXT_DIR_LTR); /* Create the buttons */ for (i = 0; i < G_N_ELEMENTS (keys_info); i++) { GtkWidget *box; GtkWidget *label; GtkWidget *button; gchar *text; GtkWidget *alignment; box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); label = gtk_label_new (keys_info[i].number); gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0); gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); label = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0); if (strlen (keys_info [i].letters) > 0) { text = g_strdup_printf ("<sub><span size=\"small\">%s</span></sub>", _(keys_info [i].letters)); gtk_label_set_markup (GTK_LABEL (label), text); g_free (text); } gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0); alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); gtk_container_add (GTK_CONTAINER (alignment), box); button = gtk_button_new (); gtk_container_set_border_width (GTK_CONTAINER (button), 0); gtk_container_add (GTK_CONTAINER (button), alignment); dialpad->priv->buttons[i] = button; gtk_grid_attach (GTK_GRID (dialpad), button, i % 3, i / 3, 1, 1 ); g_signal_connect (button, "clicked", G_CALLBACK (on_dialpad_button_clicked), dialpad); } }
static void gcal_date_selector_constructed (GObject *object) { GcalDateSelectorPrivate *priv; GtkWidget *label, *box; GList *l, *aux; priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (object)); /* chaining up */ G_OBJECT_CLASS (gcal_date_selector_parent_class)->constructed (object); /* set labels, on the first row */ label = gtk_grid_get_child_at (GTK_GRID (priv->grid), priv->day_pos, 0); gtk_label_set_text (GTK_LABEL (label), _("Day")); label = gtk_grid_get_child_at (GTK_GRID (priv->grid), priv->month_pos, 0); gtk_label_set_text (GTK_LABEL (label), _("Month")); label = gtk_grid_get_child_at (GTK_GRID (priv->grid), priv->year_pos, 0); gtk_label_set_text (GTK_LABEL (label), _("Year")); /* retrieve components from UI definition: entries */ box = gtk_grid_get_child_at (GTK_GRID (priv->grid), 0, 1); aux = gtk_container_get_children (GTK_CONTAINER (box)); for (l = aux; l != NULL; l = g_list_next (l)) { gint position; gtk_container_child_get (GTK_CONTAINER (box), l->data, "position", &position, NULL); if (position == priv->day_pos) priv->entries[DAY] = l->data; if (position == priv->month_pos) priv->entries[MONTH] = l->data; if (position == priv->year_pos) priv->entries[YEAR] = l->data; if (position == priv->day_pos || position == priv->month_pos) gtk_entry_set_max_length (GTK_ENTRY (l->data), 2); } g_list_free (aux); gtk_widget_set_direction (box, GTK_TEXT_DIR_LTR); gtk_widget_set_direction (priv->grid, GTK_TEXT_DIR_LTR); }
static void gcal_time_selector_constructed (GObject *object) { GcalTimeSelector *selector = GCAL_TIME_SELECTOR (object); /* chaining up */ G_OBJECT_CLASS (gcal_time_selector_parent_class)->constructed (object); gtk_widget_set_direction (selector->grid, GTK_TEXT_DIR_LTR); }
bool RenderThemeGtk::paintButton(RenderObject* object, const PaintInfo& info, const IntRect& rect) { if (info.context->paintingDisabled()) return false; GtkWidget* widget = gtkButton(); IntRect buttonRect(IntPoint(), rect.size()); IntRect focusRect(buttonRect); GtkStateType state = getGtkStateType(object); gtk_widget_set_state(widget, state); gtk_widget_set_direction(widget, gtkTextDirection(object->style()->direction())); if (isFocused(object)) { if (isEnabled(object)) { #if !GTK_CHECK_VERSION(2, 22, 0) GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS); #endif g_object_set(widget, "has-focus", TRUE, NULL); } gboolean interiorFocus = 0, focusWidth = 0, focusPadding = 0; gtk_widget_style_get(widget, "interior-focus", &interiorFocus, "focus-line-width", &focusWidth, "focus-padding", &focusPadding, NULL); // If we are using exterior focus, we shrink the button rect down before // drawing. If we are using interior focus we shrink the focus rect. This // approach originates from the Mozilla theme drawing code (gtk2drawing.c). if (interiorFocus) { GtkStyle* style = gtk_widget_get_style(widget); focusRect.inflateX(-style->xthickness - focusPadding); focusRect.inflateY(-style->ythickness - focusPadding); } else { buttonRect.inflateX(-focusWidth - focusPadding); buttonRect.inflateY(-focusPadding - focusPadding); } } WidgetRenderingContext widgetContext(info.context, rect); GtkShadowType shadowType = state == GTK_STATE_ACTIVE ? GTK_SHADOW_IN : GTK_SHADOW_OUT; widgetContext.gtkPaintBox(buttonRect, widget, state, shadowType, "button"); if (isFocused(object)) widgetContext.gtkPaintFocus(focusRect, widget, state, "button"); #if !GTK_CHECK_VERSION(2, 22, 0) GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_FOCUS); #endif g_object_set(widget, "has-focus", FALSE, NULL); return false; }
static void gvc_balance_bar_set_balance_type (GvcBalanceBar *bar, GvcBalanceType btype) { GtkWidget *frame; GtkAdjustment *adjustment; /* Create adjustment with limits for balance and fade types because * some limits must be provided. * If subwoofer type is used instead, the limits will be changed when * stream is set. */ adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -1.0, 1.0, 0.05, 0.5, 0.0)); bar->priv->btype = btype; bar->priv->adjustment = GTK_ADJUSTMENT (g_object_ref_sink (adjustment)); g_signal_connect (G_OBJECT (adjustment), "value-changed", G_CALLBACK (on_adjustment_value_changed), bar); switch (btype) { case BALANCE_TYPE_RL: bar->priv->label = gtk_label_new_with_mnemonic (_("_Balance:")); break; case BALANCE_TYPE_FR: bar->priv->label = gtk_label_new_with_mnemonic (_("_Fade:")); break; case BALANCE_TYPE_LFE: bar->priv->label = gtk_label_new_with_mnemonic (_("_Subwoofer:")); break; } gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0.0, 0.0); /* Frame */ frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); gtk_box_pack_start (GTK_BOX (bar), frame, TRUE, TRUE, 0); /* Box with scale */ create_scale_box (bar); gtk_container_add (GTK_CONTAINER (frame), bar->priv->scale_box); gtk_label_set_mnemonic_widget (GTK_LABEL (bar->priv->label), bar->priv->scale); gtk_widget_set_direction (bar->priv->scale, GTK_TEXT_DIR_LTR); gtk_widget_show_all (frame); g_object_notify_by_pspec (G_OBJECT (bar), properties[PROP_BALANCE_TYPE]); }
static GtkWidget * _gtk_text_handle_ensure_widget (GtkTextHandle *handle, GtkTextHandlePosition pos) { GtkTextHandlePrivate *priv; priv = handle->priv; if (!priv->windows[pos].widget) { GtkWidget *widget, *window; GtkStyleContext *context; widget = gtk_event_box_new (); gtk_event_box_set_visible_window (GTK_EVENT_BOX (widget), TRUE); gtk_widget_set_events (widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); gtk_widget_set_direction (widget, priv->windows[pos].dir); g_signal_connect (widget, "draw", G_CALLBACK (gtk_text_handle_widget_draw), handle); g_signal_connect (widget, "event", G_CALLBACK (gtk_text_handle_widget_event), handle); g_signal_connect (widget, "style-updated", G_CALLBACK (gtk_text_handle_widget_style_updated), handle); priv->windows[pos].widget = g_object_ref_sink (widget); window = gtk_widget_get_ancestor (priv->parent, GTK_TYPE_WINDOW); _gtk_window_add_popover (GTK_WINDOW (window), widget, priv->parent, FALSE); context = gtk_widget_get_style_context (widget); gtk_style_context_set_parent (context, gtk_widget_get_style_context (priv->parent)); gtk_css_node_set_name (gtk_widget_get_css_node (widget), I_("cursor-handle")); if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END) { gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM); if (priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR) gtk_style_context_add_class (context, GTK_STYLE_CLASS_INSERTION_CURSOR); } else gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP); } return priv->windows[pos].widget; }
static gint moz_gtk_progress_chunk_paint(GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkTextDirection direction) { GtkStyle* style; ensure_progress_widget(); gtk_widget_set_direction(gParts->progresWidget, direction); style = gtk_widget_get_style(gParts->progresWidget); TSOffsetStyleGCs(style, rect->x, rect->y); gtk_paint_box(style, drawable, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, cliprect, gParts->progresWidget, "bar", rect->x, rect->y, rect->width, rect->height); return MOZ_GTK_SUCCESS; }
bool RenderThemeGtk::paintTextField(RenderObject* renderObject, const PaintInfo& info, const IntRect& rect) { GtkWidget* widget = gtkEntry(); bool enabled = isEnabled(renderObject) && !isReadOnlyControl(renderObject); GtkStateType backgroundState = enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE; gtk_widget_set_sensitive(widget, enabled); gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style().direction())); setWidgetHasFocus(widget, isFocused(renderObject)); WidgetRenderingContext widgetContext(info.context, rect); IntRect textFieldRect(IntPoint(), rect.size()); // The entry background is only painted over the interior part of the GTK+ entry, not // the entire frame. This happens in the Mozilla theme drawing code as well. IntRect interiorRect(textFieldRect); GtkStyle* style = gtk_widget_get_style(widget); interiorRect.inflateX(-style->xthickness); interiorRect.inflateY(-style->ythickness); widgetContext.gtkPaintFlatBox(interiorRect, widget, backgroundState, GTK_SHADOW_NONE, "entry_bg"); // This is responsible for drawing the actual frame. widgetContext.gtkPaintShadow(textFieldRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "entry"); gboolean interiorFocus; gint focusWidth; gtk_widget_style_get(widget, "interior-focus", &interiorFocus, "focus-line-width", &focusWidth, NULL); if (isFocused(renderObject) && !interiorFocus) { // When GTK+ paints a text entry with focus, it shrinks the size of the frame area by the // focus width and paints over the previously unfocused text entry. We need to emulate that // by drawing both the unfocused frame above and the focused frame here. IntRect shadowRect(textFieldRect); shadowRect.inflate(-focusWidth); widgetContext.gtkPaintShadow(shadowRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "entry"); widgetContext.gtkPaintFocus(textFieldRect, widget, GTK_STATE_NORMAL, "entry"); } return false; }
void _gtk_text_handle_set_direction (GtkTextHandle *handle, GtkTextHandlePosition pos, GtkTextDirection dir) { GtkTextHandlePrivate *priv; g_return_if_fail (GTK_IS_TEXT_HANDLE (handle)); priv = handle->priv; pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR, GTK_TEXT_HANDLE_POSITION_SELECTION_START); priv->windows[pos].dir = dir; if (priv->windows[pos].widget) { gtk_widget_set_direction (priv->windows[pos].widget, dir); _gtk_text_handle_update (handle, pos); } }
bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) { GtkWidget* widget = gtkProgressBar(); gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style().direction())); WidgetRenderingContext widgetContext(paintInfo.context, rect); IntRect fullProgressBarRect(IntPoint(), rect.size()); widgetContext.gtkPaintBox(fullProgressBarRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "trough"); GtkStyle* style = gtk_widget_get_style(widget); IntRect progressRect(fullProgressBarRect); progressRect.inflateX(-style->xthickness); progressRect.inflateY(-style->ythickness); progressRect = RenderThemeGtk::calculateProgressRect(renderObject, progressRect); if (!progressRect.isEmpty()) widgetContext.gtkPaintBox(progressRect, widget, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, "bar"); return false; }
static void create_dialog (CcMousePropertiesPrivate *d) { GtkSizeGroup *size_group; size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (size_group, WID ("primary_button_label")); gtk_size_group_add_widget (size_group, WID ("pointer_speed_label")); gtk_size_group_add_widget (size_group, WID ("double_click_label")); gtk_size_group_add_widget (size_group, WID ("touchpad_pointer_speed_label")); size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (size_group, WID ("pointer_speed_fast_label")); gtk_size_group_add_widget (size_group, WID ("double_click_fast_label")); gtk_size_group_add_widget (size_group, WID ("touchpad_pointer_speed_fast_label")); size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (size_group, WID ("pointer_speed_slow_label")); gtk_size_group_add_widget (size_group, WID ("double_click_slow_label")); gtk_size_group_add_widget (size_group, WID ("touchpad_pointer_speed_slow_label")); gtk_widget_set_direction (WID ("primary_button_box"), GTK_TEXT_DIR_LTR); }
static void gimp_number_pair_entry_init (GimpNumberPairEntry *entry) { GimpNumberPairEntryPrivate *priv; entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry, GIMP_TYPE_NUMBER_PAIR_ENTRY, GimpNumberPairEntryPrivate); priv = GIMP_NUMBER_PAIR_ENTRY_GET_PRIVATE (entry); priv->left_number = 1.0; priv->right_number = 1.0; priv->default_left_number = 1.0; priv->default_right_number = 1.0; priv->user_override = FALSE; priv->font_italic = FALSE; priv->separators = NULL; priv->default_text = NULL; priv->num_separators = 0; priv->allow_simplification = FALSE; priv->min_valid_value = G_MINDOUBLE; priv->max_valid_value = G_MAXDOUBLE; g_signal_connect (entry, "changed", G_CALLBACK (gimp_number_pair_entry_changed), NULL); g_signal_connect (entry, "focus-out-event", G_CALLBACK (gimp_number_pair_entry_events), NULL); g_signal_connect (entry, "key-press-event", G_CALLBACK (gimp_number_pair_entry_events), NULL); gtk_widget_set_direction (GTK_WIDGET (entry), GTK_TEXT_DIR_LTR); }
static void paintToggle(RenderThemeGtk* theme, RenderObject* renderObject, const PaintInfo& info, const IntRect& rect, GtkWidget* widget) { // We do not call gtk_toggle_button_set_active here, because some themes begin a series of // animation frames in a "toggled" signal handler. This puts some checkboxes in a half-way // checked state. Every GTK+ theme I tested merely looks at the shadow type (and not the // 'active' property) to determine whether or not to draw the check. gtk_widget_set_sensitive(widget, theme->isEnabled(renderObject) && !theme->isReadOnlyControl(renderObject)); gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style().direction())); bool indeterminate = theme->isIndeterminate(renderObject); gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(widget), indeterminate); GtkShadowType shadowType = GTK_SHADOW_OUT; if (indeterminate) // This originates from the Mozilla code. shadowType = GTK_SHADOW_ETCHED_IN; else if (theme->isChecked(renderObject)) shadowType = GTK_SHADOW_IN; WidgetRenderingContext widgetContext(info.context, rect); IntRect buttonRect(IntPoint(), rect.size()); GtkStateType toggleState = getGtkStateType(theme, renderObject); const char* detail = 0; if (GTK_IS_RADIO_BUTTON(widget)) { detail = "radiobutton"; widgetContext.gtkPaintOption(buttonRect, widget, toggleState, shadowType, detail); } else { detail = "checkbutton"; widgetContext.gtkPaintCheck(buttonRect, widget, toggleState, shadowType, detail); } if (theme->isFocused(renderObject)) { IntRect focusRect(buttonRect); adjustRectForFocus(widget, focusRect, true); widgetContext.gtkPaintFocus(focusRect, widget, toggleState, detail); } }
static GtkWidget * create_tree (gboolean rtl) { GtkWidget *sw; GtkWidget *treeview; GtkListStore *list_store; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GdkPixbuf *pixbuf; sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); gtk_widget_set_direction (sw, rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); list_store = create_list_store (); treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store)); gtk_widget_set_direction (treeview, rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); gtk_container_add (GTK_CONTAINER (sw), treeview); /* Line number */ renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("#", renderer, "text", COL_LINE_NUM, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); /* Description */ renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "font", "monospace", NULL); column = gtk_tree_view_column_new_with_attributes ("Description", renderer, "text", 0, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); /* Test text */ renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Test", renderer, "text", 1, "xpad", 2, "ypad", 3, "xalign", 4, "yalign", 5, "sensitive", 6, "width", 7, "height", 8, "width_chars", 9, "wrap_width", 10, "wrap_mode", 11, "single_paragraph_mode", 12, "ellipsize", 13, "alignment", 14, "cell_background", 15, NULL); gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); /* Empty column */ pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL); renderer = gtk_cell_renderer_pixbuf_new (); g_object_set (renderer, "pixbuf", pixbuf, "xpad", 10, "ypad", 10, NULL); column = gtk_tree_view_column_new_with_attributes ("Empty", renderer, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); return sw; }
static void mdm_lang_setup_treeview (void) { if (dialog == NULL) { GtkWidget *main_vbox; GtkWidget *button; GtkWidget **tmp_p; GtkWidget *swindow; GtkWidget *label; char *s; dialog = gtk_dialog_new_with_buttons (_("Select a Language"), #ifdef TODO GTK_WINDOW (parent_window), #endif NULL, 0, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); button = gtk_button_new_with_mnemonic (_("Change _Language")); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); gtk_widget_show (button); gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); main_vbox = gtk_vbox_new (FALSE, 6); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 5); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox, TRUE, TRUE, 0); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); /* evil gcc warnings */ tmp_p = &dialog; g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *)tmp_p); s = g_strdup (_("_Select the language for your session to use:")); label = gtk_label_new_with_mnemonic (s); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); g_free (s); gtk_label_set_use_markup (GTK_LABEL (label), TRUE); gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0); tv = gtk_tree_view_new (); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tv), TRUE); gtk_label_set_mnemonic_widget (GTK_LABEL (label), tv); /* FIXME: we should handle this better, but things really look * bad if we aren't always LTR */ gtk_widget_set_direction (tv, GTK_TEXT_DIR_LTR); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tv), FALSE); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), GTK_DIALOG_MODAL, NULL, gtk_cell_renderer_text_new (), "text", TRANSLATED_NAME_COLUMN, NULL); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), GTK_DIALOG_MODAL, NULL, gtk_cell_renderer_text_new (), "markup", UNTRANSLATED_NAME_COLUMN, NULL); swindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (swindow), tv); gtk_box_pack_start (GTK_BOX (main_vbox), swindow, TRUE, TRUE, 0); gtk_window_set_default_size (GTK_WINDOW (dialog), MIN (400, mdm_wm_screen.width), MIN (600, mdm_wm_screen.height)); g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tv))), "changed", (GCallback) selection_changed, NULL); g_signal_connect (G_OBJECT (tv), "row_activated", (GCallback) tree_row_activated, NULL); gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (lang_model)); } }
int main (int argc, char **argv) { GtkWidget *window; GtkWidget *table; GtkWidget *label; GtkWidget *entry; GtkWidget *button; GIcon *icon; GtkTargetList *tlist; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Gtk Entry Icons Test"); gtk_container_set_border_width (GTK_CONTAINER (window), 12); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); table = gtk_table_new (2, 4, FALSE); gtk_container_add (GTK_CONTAINER (window), table); gtk_table_set_row_spacings (GTK_TABLE (table), 6); gtk_table_set_col_spacings (GTK_TABLE (table), 6); /* * Open File - Sets the icon using a GIcon */ label = gtk_label_new ("Open File:"); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); entry = gtk_entry_new (); gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); icon = g_themed_icon_new ("folder"); g_themed_icon_append_name (G_THEMED_ICON (icon), "gtk-directory"); gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, icon); gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, FALSE); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, "Open a file"); button = gtk_button_new_with_label ("Properties"); gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1, GTK_FILL, GTK_FILL, 0, 0); g_signal_connect (button, "clicked", G_CALLBACK (properties_cb), entry); /* * Save File - sets the icon using a stock id. */ label = gtk_label_new ("Save File:"); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.5); entry = gtk_entry_new (); gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); gtk_entry_set_text (GTK_ENTRY (entry), "Right-to-left"); gtk_widget_set_direction (entry, GTK_TEXT_DIR_RTL); gtk_entry_set_icon_from_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_SAVE); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, "Save a file"); tlist = gtk_target_list_new (NULL, 0); gtk_target_list_add_text_targets (tlist, 0); gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, tlist, GDK_ACTION_COPY); g_signal_connect_after (entry, "drag-begin", G_CALLBACK (drag_begin_cb), NULL); g_signal_connect (entry, "drag-data-get", G_CALLBACK (drag_data_get_cb), NULL); gtk_target_list_unref (tlist); button = gtk_button_new_with_label ("Properties"); gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2, GTK_FILL, GTK_FILL, 0, 0); g_signal_connect (button, "clicked", G_CALLBACK (properties_cb), entry); /* * Search - Uses a helper function */ label = gtk_label_new ("Search:"); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); entry = gtk_entry_new (); gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); gtk_entry_set_icon_from_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND); gtk_entry_set_icon_from_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); g_signal_connect (entry, "icon-press", G_CALLBACK (clear_pressed), NULL); button = gtk_button_new_with_label ("Properties"); gtk_table_attach (GTK_TABLE (table), button, 2, 3, 2, 3, GTK_FILL, GTK_FILL, 0, 0); g_signal_connect (button, "clicked", G_CALLBACK (properties_cb), entry); /* * Password - Sets the icon using a stock id */ label = gtk_label_new ("Password:"******"Properties"); gtk_table_attach (GTK_TABLE (table), button, 2, 3, 3, 4, GTK_FILL, GTK_FILL, 0, 0); g_signal_connect (button, "clicked", G_CALLBACK (properties_cb), entry); /* Name - Does not set any icons. */ label = gtk_label_new ("Name:"); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5, GTK_FILL, GTK_FILL, 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); entry = gtk_entry_new (); gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 4, 5, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); button = gtk_button_new_with_label ("Properties"); gtk_table_attach (GTK_TABLE (table), button, 2, 3, 4, 5, GTK_FILL, GTK_FILL, 0, 0); g_signal_connect (button, "clicked", G_CALLBACK (properties_cb), entry); gtk_widget_show_all (window); gtk_main(); return 0; }
static VALUE rg_set_direction(VALUE self, VALUE dir) { gtk_widget_set_direction(_SELF(self), RVAL2GENUM(dir, GTK_TYPE_TEXT_DIRECTION)); return self; }
int main(int argc, char * argv[]){ GtkWidget * window; GtkWidget *vbox, *hbox, *hbox1, *hbox2, *hbox3, *hbox4; GtkWidget * button; GtkWidget * label; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL); gtk_window_set_title(GTK_WINDOW(window), "calculator"); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_container_set_border_width(GTK_CONTAINER(window), 10); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); label = gtk_label_new("calculator"); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 5); button = gtk_button_new_with_label("C"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_clear_clicked), NULL); entry = gtk_entry_new(); gtk_widget_set_direction(entry, GTK_TEXT_DIR_RTL); gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 5); hbox1 = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 5); button = gtk_button_new_with_label("3"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("2"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("1"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("+"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_punc_clicked), (gpointer)1); hbox2 = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 5); button = gtk_button_new_with_label("6"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("5"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("4"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("-"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_punc_clicked), (gpointer)2); hbox3 = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox3, FALSE, FALSE, 5); button = gtk_button_new_with_label("9"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("8"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("7"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("*"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_punc_clicked), (gpointer)3); hbox4 = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox4, FALSE, FALSE, 5); button = gtk_button_new_with_label("0"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_num_clicked), NULL); button = gtk_button_new_with_label("."); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_dot_clicked), NULL); button = gtk_button_new_with_label("="); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_eq_clicked), NULL); button = gtk_button_new_with_label("/"); gtk_box_pack_start(GTK_BOX(hbox1), button, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_punc_clicked), (gpointer)4); gtk_widget_show_all(window); gtk_main(); return 0; }
static gint moz_gtk_entry_paint(GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, GtkWidget* widget, GtkTextDirection direction) { GtkStateType bg_state = state->disabled ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL; gint x, y, width = rect->width, height = rect->height; GtkStyle* style; gboolean interior_focus; gboolean theme_honors_transparency = FALSE; gint focus_width; gtk_widget_set_direction(widget, direction); style = gtk_widget_get_style(widget); gtk_widget_style_get(widget, "interior-focus", &interior_focus, "focus-line-width", &focus_width, "honors-transparent-bg-hint", &theme_honors_transparency, NULL); /* gtkentry.c uses two windows, one for the entire widget and one for the * text area inside it. The background of both windows is set to the "base" * color of the new state in gtk_entry_state_changed, but only the inner * textarea window uses gtk_paint_flat_box when exposed */ TSOffsetStyleGCs(style, rect->x, rect->y); /* This gets us a lovely greyish disabledish look */ gtk_widget_set_sensitive(widget, !state->disabled); /* GTK fills the outer widget window with the base color before drawing the widget. * Some older themes rely on this behavior, but many themes nowadays use rounded * corners on their widgets. While most GTK apps are blissfully unaware of this * problem due to their use of the default window background, we render widgets on * many kinds of backgrounds on the web. * If the theme is able to cope with transparency, then we can skip pre-filling * and notify the theme it will paint directly on the canvas. */ if (theme_honors_transparency) { g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE)); } else { gdk_draw_rectangle(drawable, style->base_gc[bg_state], TRUE, cliprect->x, cliprect->y, cliprect->width, cliprect->height); g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(FALSE)); } /* Get the position of the inner window, see _gtk_entry_get_borders */ x = XTHICKNESS(style); y = YTHICKNESS(style); if (!interior_focus) { x += focus_width; y += focus_width; } /* Simulate an expose of the inner window */ gtk_paint_flat_box(style, drawable, bg_state, GTK_SHADOW_NONE, cliprect, widget, "entry_bg", rect->x + x, rect->y + y, rect->width - 2*x, rect->height - 2*y); /* Now paint the shadow and focus border. * We do like in gtk_entry_draw_frame, we first draw the shadow, a tad * smaller when focused if the focus is not interior, then the focus. */ x = rect->x; y = rect->y; if (state->focused && !state->disabled) { /* This will get us the lit borders that focused textboxes enjoy on * some themes. */ GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS); if (!interior_focus) { /* Indent the border a little bit if we have exterior focus (this is what GTK does to draw native entries) */ x += focus_width; y += focus_width; width -= 2 * focus_width; height -= 2 * focus_width; } } gtk_paint_shadow(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN, cliprect, widget, "entry", x, y, width, height); if (state->focused && !state->disabled) { if (!interior_focus) { gtk_paint_focus(style, drawable, GTK_STATE_NORMAL, cliprect, widget, "entry", rect->x, rect->y, rect->width, rect->height); } /* Now unset the focus flag. We don't want other entries to look * like they're focused too! */ GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_FOCUS); } return MOZ_GTK_SUCCESS; }
static gint moz_gtk_scrollbar_thumb_paint(GtkThemeWidgetType widget, GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, GtkTextDirection direction) { GtkStateType state_type = (state->inHover || state->active) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL; GtkShadowType shadow_type = GTK_SHADOW_OUT; GtkStyle* style; GtkScrollbar *scrollbar; GtkAdjustment *adj; gboolean activate_slider; ensure_scrollbar_widget(); if (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) scrollbar = GTK_SCROLLBAR(gParts->horizScrollbarWidget); else scrollbar = GTK_SCROLLBAR(gParts->vertScrollbarWidget); gtk_widget_set_direction(GTK_WIDGET(scrollbar), direction); /* Make sure to set the scrollbar range before painting so that everything is drawn properly. At least the bluecurve (and maybe other) themes don't draw the top or bottom black line surrounding the scrollbar if the theme thinks that it's butted up against the scrollbar arrows. Note the increases of the clip rect below. */ /* Changing the cliprect is pretty bogus. This lets themes draw outside the frame, which means we don't invalidate them correctly. See bug 297508. But some themes do seem to need it. So we modify the frame's overflow area to account for what we're doing here; see nsNativeThemeGTK::GetWidgetOverflow. */ adj = gtk_range_get_adjustment(GTK_RANGE(scrollbar)); if (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) { cliprect->x -= 1; cliprect->width += 2; gtk_adjustment_set_page_size(adj, rect->width); } else { cliprect->y -= 1; cliprect->height += 2; gtk_adjustment_set_page_size(adj, rect->height); } #if GTK_CHECK_VERSION(2, 14, 0) gtk_adjustment_configure(adj, state->curpos, 0, state->maxpos, gtk_adjustment_get_step_increment(adj), gtk_adjustment_get_page_increment(adj), gtk_adjustment_get_page_size(adj)); #else adj->lower = 0; adj->value = state->curpos; adj->upper = state->maxpos; gtk_adjustment_changed(adj); #endif style = gtk_widget_get_style(GTK_WIDGET(scrollbar)); gtk_widget_style_get(GTK_WIDGET(scrollbar), "activate-slider", &activate_slider, NULL); if (activate_slider && state->active) { shadow_type = GTK_SHADOW_IN; state_type = GTK_STATE_ACTIVE; } TSOffsetStyleGCs(style, rect->x, rect->y); gtk_paint_slider(style, drawable, state_type, shadow_type, cliprect, GTK_WIDGET(scrollbar), "slider", rect->x, rect->y, rect->width, rect->height, (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL); return MOZ_GTK_SUCCESS; }
/* Create a new (empty) Sticky Note at a specific position and with specific size */ static StickyNote * stickynote_new_aux (GdkScreen *screen, gint x, gint y, gint w, gint h) { StickyNote *note; GtkBuilder *builder; note = g_new (StickyNote, 1); builder = gtk_builder_new (); gtk_builder_add_from_file (builder, BUILDER_PATH, NULL); note->w_window = GTK_WIDGET (gtk_builder_get_object (builder, "stickynote_window")); gtk_window_set_screen(GTK_WINDOW(note->w_window),screen); gtk_window_set_decorated (GTK_WINDOW (note->w_window), FALSE); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (note->w_window), TRUE); gtk_window_set_skip_pager_hint (GTK_WINDOW (note->w_window), TRUE); gtk_widget_add_events (note->w_window, GDK_BUTTON_PRESS_MASK); note->w_title = GTK_WIDGET (gtk_builder_get_object (builder, "title_label")); note->w_body = GTK_WIDGET (gtk_builder_get_object (builder, "body_text")); note->w_scroller = GTK_WIDGET (gtk_builder_get_object (builder, "body_scroller")); note->w_lock = GTK_WIDGET (gtk_builder_get_object (builder, "lock_button")); gtk_widget_add_events (note->w_lock, GDK_BUTTON_PRESS_MASK); note->buffer = GTK_SOURCE_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(note->w_body))); note->w_close = GTK_WIDGET (gtk_builder_get_object (builder, "close_button")); gtk_widget_add_events (note->w_close, GDK_BUTTON_PRESS_MASK); note->w_resize_se = GTK_WIDGET (gtk_builder_get_object (builder, "resize_se_box")); gtk_widget_add_events (note->w_resize_se, GDK_BUTTON_PRESS_MASK); note->w_resize_sw = GTK_WIDGET (gtk_builder_get_object (builder, "resize_sw_box")); gtk_widget_add_events (note->w_resize_sw, GDK_BUTTON_PRESS_MASK); note->img_lock = GTK_IMAGE (gtk_builder_get_object (builder, "lock_img")); note->img_close = GTK_IMAGE (gtk_builder_get_object (builder, "close_img")); note->img_resize_se = GTK_IMAGE (gtk_builder_get_object (builder, "resize_se_img")); note->img_resize_sw = GTK_IMAGE (gtk_builder_get_object (builder, "resize_sw_img")); /* deal with RTL environments */ gtk_widget_set_direction (GTK_WIDGET (gtk_builder_get_object (builder, "resize_bar")), GTK_TEXT_DIR_LTR); note->w_menu = GTK_WIDGET (gtk_builder_get_object (builder, "stickynote_menu")); note->ta_lock_toggle_item = GTK_TOGGLE_ACTION (gtk_builder_get_object (builder, "popup_toggle_lock")); note->w_properties = GTK_WIDGET (gtk_builder_get_object (builder, "stickynote_properties")); gtk_window_set_screen (GTK_WINDOW (note->w_properties), screen); note->w_entry = GTK_WIDGET (gtk_builder_get_object (builder, "title_entry")); note->w_color = GTK_WIDGET (gtk_builder_get_object (builder, "note_color")); note->w_color_label = GTK_WIDGET (gtk_builder_get_object (builder, "color_label")); note->w_font_color = GTK_WIDGET (gtk_builder_get_object (builder, "font_color")); note->w_font_color_label = GTK_WIDGET (gtk_builder_get_object (builder, "font_color_label")); note->w_font = GTK_WIDGET (gtk_builder_get_object (builder, "note_font")); note->w_font_label = GTK_WIDGET (gtk_builder_get_object (builder, "font_label")); note->w_def_color = GTK_WIDGET (>K_CHECK_BUTTON ( gtk_builder_get_object (builder, "def_color_check"))->toggle_button); note->w_def_font = GTK_WIDGET (>K_CHECK_BUTTON ( gtk_builder_get_object (builder, "def_font_check"))->toggle_button); note->color = NULL; note->font_color = NULL; note->font = NULL; note->locked = FALSE; note->x = x; note->y = y; note->w = w; note->h = h; /* Customize the window */ if (g_settings_get_boolean (stickynotes->settings, "sticky")) gtk_window_stick(GTK_WINDOW(note->w_window)); if (w == 0 || h == 0) gtk_window_resize (GTK_WINDOW(note->w_window), g_settings_get_int (stickynotes->settings, "default-width"), g_settings_get_int (stickynotes->settings, "default-height")); else gtk_window_resize (GTK_WINDOW(note->w_window), note->w, note->h); if (x != -1 && y != -1) gtk_window_move (GTK_WINDOW(note->w_window), note->x, note->y); /* Set the button images */ gtk_image_set_from_icon_name (note->img_close, STICKYNOTES_STOCK_CLOSE, GTK_ICON_SIZE_MENU); gtk_image_set_pixel_size (note->img_close, STICKYNOTES_ICON_SIZE); gtk_image_set_from_icon_name (note->img_resize_se, STICKYNOTES_STOCK_RESIZE_SE, GTK_ICON_SIZE_MENU); gtk_image_set_pixel_size (note->img_resize_se, STICKYNOTES_ICON_SIZE); gtk_image_set_from_icon_name (note->img_resize_sw, STICKYNOTES_STOCK_RESIZE_SW, GTK_ICON_SIZE_MENU); gtk_image_set_pixel_size (note->img_resize_sw, STICKYNOTES_ICON_SIZE); gtk_widget_show(note->w_lock); gtk_widget_show(note->w_close); gtk_widget_show(GTK_WIDGET (gtk_builder_get_object (builder, "resize_bar"))); /* Customize the title and colors, hide and unlock */ stickynote_set_title(note, NULL); stickynote_set_color(note, NULL, NULL, TRUE); stickynote_set_font(note, NULL, TRUE); stickynote_set_locked(note, FALSE); gtk_widget_realize (note->w_window); /* Connect a popup menu to all buttons and title */ /* GtkBuilder holds and drops the references to all the widgets it * creates for as long as it exist (GtkBuilder). Hence in our callback * we would have an invalid GtkMenu. We need to ref it. */ g_object_ref (note->w_menu); g_signal_connect (G_OBJECT (note->w_window), "button-press-event", G_CALLBACK (stickynote_show_popup_menu), note->w_menu); g_signal_connect (G_OBJECT (note->w_lock), "button-press-event", G_CALLBACK (stickynote_show_popup_menu), note->w_menu); g_signal_connect (G_OBJECT (note->w_close), "button-press-event", G_CALLBACK (stickynote_show_popup_menu), note->w_menu); g_signal_connect (G_OBJECT (note->w_resize_se), "button-press-event", G_CALLBACK (stickynote_show_popup_menu), note->w_menu); g_signal_connect (G_OBJECT (note->w_resize_sw), "button-press-event", G_CALLBACK (stickynote_show_popup_menu), note->w_menu); /* Connect a properties dialog to the note */ gtk_window_set_transient_for (GTK_WINDOW(note->w_properties), GTK_WINDOW(note->w_window)); gtk_dialog_set_default_response (GTK_DIALOG(note->w_properties), GTK_RESPONSE_CLOSE); g_signal_connect (G_OBJECT (note->w_properties), "response", G_CALLBACK (response_cb), note); /* Connect signals to the sticky note */ g_signal_connect (G_OBJECT (note->w_lock), "clicked", G_CALLBACK (stickynote_toggle_lock_cb), note); g_signal_connect (G_OBJECT (note->w_close), "clicked", G_CALLBACK (stickynote_close_cb), note); g_signal_connect (G_OBJECT (note->w_resize_se), "button-press-event", G_CALLBACK (stickynote_resize_cb), note); g_signal_connect (G_OBJECT (note->w_resize_sw), "button-press-event", G_CALLBACK (stickynote_resize_cb), note); g_signal_connect (G_OBJECT (note->w_window), "button-press-event", G_CALLBACK (stickynote_move_cb), note); g_signal_connect (G_OBJECT (note->w_window), "configure-event", G_CALLBACK (stickynote_configure_cb), note); g_signal_connect (G_OBJECT (note->w_window), "delete-event", G_CALLBACK (stickynote_delete_cb), note); g_signal_connect (gtk_builder_get_object (builder, "popup_create"), "activate", G_CALLBACK (popup_create_cb), note); g_signal_connect (gtk_builder_get_object (builder, "popup_destroy"), "activate", G_CALLBACK (popup_destroy_cb), note); g_signal_connect (gtk_builder_get_object (builder, "popup_toggle_lock"), "toggled", G_CALLBACK (popup_toggle_lock_cb), note); g_signal_connect (gtk_builder_get_object (builder, "popup_properties"), "activate", G_CALLBACK (popup_properties_cb), note); g_signal_connect_swapped (G_OBJECT (note->w_entry), "changed", G_CALLBACK (properties_apply_title_cb), note); g_signal_connect (G_OBJECT (note->w_color), "color-set", G_CALLBACK (properties_color_cb), note); g_signal_connect (G_OBJECT (note->w_font_color), "color-set", G_CALLBACK (properties_color_cb), note); g_signal_connect_swapped (G_OBJECT (note->w_def_color), "toggled", G_CALLBACK (properties_apply_color_cb), note); g_signal_connect (G_OBJECT (note->w_font), "font-set", G_CALLBACK (properties_font_cb), note); g_signal_connect_swapped (G_OBJECT (note->w_def_font), "toggled", G_CALLBACK (properties_apply_font_cb), note); g_signal_connect (G_OBJECT (note->w_entry), "activate", G_CALLBACK (properties_activate_cb), note); g_signal_connect (G_OBJECT (note->w_properties), "delete-event", G_CALLBACK (gtk_widget_hide), note); g_object_unref(builder); g_signal_connect_after (note->w_body, "button-press-event", G_CALLBACK (gtk_true), note); g_signal_connect (gtk_text_view_get_buffer(GTK_TEXT_VIEW(note->w_body)), "changed", G_CALLBACK (buffer_changed), note); return note; }
static gint moz_gtk_scrollbar_button_paint(GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, GtkScrollbarButtonFlags flags, GtkTextDirection direction) { GtkStateType state_type = ConvertGtkState(state); GtkShadowType shadow_type = (state->active) ? GTK_SHADOW_IN : GTK_SHADOW_OUT; GdkRectangle arrow_rect; GtkStyle* style; GtkWidget *scrollbar; GtkAllocation allocation; GtkArrowType arrow_type; gint arrow_displacement_x, arrow_displacement_y; const char* detail = (flags & MOZ_GTK_STEPPER_VERTICAL) ? "vscrollbar" : "hscrollbar"; ensure_scrollbar_widget(); if (flags & MOZ_GTK_STEPPER_VERTICAL) scrollbar = gParts->vertScrollbarWidget; else scrollbar = gParts->horizScrollbarWidget; gtk_widget_set_direction(scrollbar, direction); /* Some theme engines (i.e., ClearLooks) check the scrollbar's allocation to determine where it should paint rounded corners on the buttons. We need to trick them into drawing the buttons the way we want them. */ gtk_widget_get_allocation(scrollbar, &allocation); allocation.x = rect->x; allocation.y = rect->y; allocation.width = rect->width; allocation.height = rect->height; if (flags & MOZ_GTK_STEPPER_VERTICAL) { allocation.height *= 5; if (flags & MOZ_GTK_STEPPER_DOWN) { arrow_type = GTK_ARROW_DOWN; if (flags & MOZ_GTK_STEPPER_BOTTOM) allocation.y -= 4 * rect->height; else allocation.y -= rect->height; } else { arrow_type = GTK_ARROW_UP; if (flags & MOZ_GTK_STEPPER_BOTTOM) allocation.y -= 3 * rect->height; } } else { allocation.width *= 5; if (flags & MOZ_GTK_STEPPER_DOWN) { arrow_type = GTK_ARROW_RIGHT; if (flags & MOZ_GTK_STEPPER_BOTTOM) allocation.x -= 4 * rect->width; else allocation.x -= rect->width; } else { arrow_type = GTK_ARROW_LEFT; if (flags & MOZ_GTK_STEPPER_BOTTOM) allocation.x -= 3 * rect->width; } } gtk_widget_set_allocation(scrollbar, &allocation); style = gtk_widget_get_style(scrollbar); TSOffsetStyleGCs(style, rect->x, rect->y); gtk_paint_box(style, drawable, state_type, shadow_type, cliprect, scrollbar, detail, rect->x, rect->y, rect->width, rect->height); arrow_rect.width = rect->width / 2; arrow_rect.height = rect->height / 2; arrow_rect.x = rect->x + (rect->width - arrow_rect.width) / 2; arrow_rect.y = rect->y + (rect->height - arrow_rect.height) / 2; if (state_type == GTK_STATE_ACTIVE) { gtk_widget_style_get(scrollbar, "arrow-displacement-x", &arrow_displacement_x, "arrow-displacement-y", &arrow_displacement_y, NULL); arrow_rect.x += arrow_displacement_x; arrow_rect.y += arrow_displacement_y; } gtk_paint_arrow(style, drawable, state_type, shadow_type, cliprect, scrollbar, detail, arrow_type, TRUE, arrow_rect.x, arrow_rect.y, arrow_rect.width, arrow_rect.height); return MOZ_GTK_SUCCESS; }
static gint moz_gtk_toggle_paint(GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, gboolean selected, gboolean inconsistent, gboolean isradio, GtkTextDirection direction) { GtkStateType state_type = ConvertGtkState(state); GtkShadowType shadow_type = (selected)?GTK_SHADOW_IN:GTK_SHADOW_OUT; gint indicator_size, indicator_spacing; gint x, y, width, height; gint focus_x, focus_y, focus_width, focus_height; GtkWidget *w; GtkStyle *style; if (isradio) { moz_gtk_radio_get_metrics(&indicator_size, &indicator_spacing); w = gParts->radiobuttonWidget; } else { moz_gtk_checkbox_get_metrics(&indicator_size, &indicator_spacing); w = gParts->checkboxWidget; } // "GetMinimumWidgetSize was ignored" // FIXME: This assert causes a build failure in WebKitGTK+ debug // builds, because it uses 'false' in its definition. We may want // to force this file to be built with g++, by renaming it. // ASSERT(rect->width == indicator_size); /* * vertically center in the box, since XUL sometimes ignores our * GetMinimumWidgetSize in the vertical dimension */ x = rect->x; y = rect->y + (rect->height - indicator_size) / 2; width = indicator_size; height = indicator_size; focus_x = x - indicator_spacing; focus_y = y - indicator_spacing; focus_width = width + 2 * indicator_spacing; focus_height = height + 2 * indicator_spacing; style = gtk_widget_get_style(w); TSOffsetStyleGCs(style, x, y); gtk_widget_set_sensitive(w, !state->disabled); gtk_widget_set_direction(w, direction); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), selected); if (isradio) { gtk_paint_option(style, drawable, state_type, shadow_type, cliprect, gParts->radiobuttonWidget, "radiobutton", x, y, width, height); if (state->focused) { gtk_paint_focus(style, drawable, GTK_STATE_ACTIVE, cliprect, gParts->radiobuttonWidget, "radiobutton", focus_x, focus_y, focus_width, focus_height); } } else { /* * 'indeterminate' type on checkboxes. In GTK, the shadow type * must also be changed for the state to be drawn. */ if (inconsistent) { gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(gParts->checkboxWidget), TRUE); shadow_type = GTK_SHADOW_ETCHED_IN; } else { gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(gParts->checkboxWidget), FALSE); } gtk_paint_check(style, drawable, state_type, shadow_type, cliprect, gParts->checkboxWidget, "checkbutton", x, y, width, height); if (state->focused) { gtk_paint_focus(style, drawable, GTK_STATE_ACTIVE, cliprect, gParts->checkboxWidget, "checkbutton", focus_x, focus_y, focus_width, focus_height); } } return MOZ_GTK_SUCCESS; }
static gint moz_gtk_button_paint(GdkDrawable* drawable, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, GtkReliefStyle relief, GtkWidget* widget, GtkTextDirection direction) { GtkShadowType shadow_type; GtkStyle* style = gtk_widget_get_style(widget); GtkStateType button_state = ConvertGtkState(state); gint x = rect->x, y=rect->y, width=rect->width, height=rect->height; gboolean interior_focus; gint focus_width, focus_pad; moz_gtk_widget_get_focus(widget, &interior_focus, &focus_width, &focus_pad); gtk_widget_set_state(widget, button_state); gtk_widget_set_direction(widget, direction); if (state->isDefault) GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_DEFAULT); gtk_button_set_relief(GTK_BUTTON(widget), relief); /* Some theme engines love to cause us pain in that gtk_paint_focus is a no-op on buttons and button-like widgets. They only listen to this flag. */ if (state->focused && !state->disabled) GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS); if (!interior_focus && state->focused) { x += focus_width + focus_pad; y += focus_width + focus_pad; width -= 2 * (focus_width + focus_pad); height -= 2 * (focus_width + focus_pad); } shadow_type = button_state == GTK_STATE_ACTIVE || state->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; if (state->isDefault && relief == GTK_RELIEF_NORMAL) { gtk_paint_box(style, drawable, button_state, shadow_type, cliprect, widget, "buttondefault", x, y, width, height); } if (relief != GTK_RELIEF_NONE || state->depressed || (button_state != GTK_STATE_NORMAL && button_state != GTK_STATE_INSENSITIVE)) { TSOffsetStyleGCs(style, x, y); /* the following line can trigger an assertion (Crux theme) file ../../gdk/gdkwindow.c: line 1846 (gdk_window_clear_area): assertion `GDK_IS_WINDOW (window)' failed */ gtk_paint_box(style, drawable, button_state, shadow_type, cliprect, widget, "button", x, y, width, height); } if (state->focused) { if (interior_focus) { GtkStyle* style = gtk_widget_get_style(widget); x += style->xthickness + focus_pad; y += style->ythickness + focus_pad; width -= 2 * (style->xthickness + focus_pad); height -= 2 * (style->ythickness + focus_pad); } else { x -= focus_width + focus_pad; y -= focus_width + focus_pad; width += 2 * (focus_width + focus_pad); height += 2 * (focus_width + focus_pad); } TSOffsetStyleGCs(style, x, y); gtk_paint_focus(style, drawable, button_state, cliprect, widget, "button", x, y, width, height); } GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_DEFAULT); GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_FOCUS); return MOZ_GTK_SUCCESS; }
bool RenderThemeGtk::paintInnerSpinButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) { // We expand the painted area by 2 pixels on the top and bottom and 2 pixels on the right. This // is because GTK+ themes want to draw over the text box borders, but WebCore renders the inner // spin button inside the text box. IntRect expandedRect(rect); expandedRect.inflateY(2); expandedRect.setWidth(rect.width() + 2); WidgetRenderingContext widgetContext(paintInfo.context, expandedRect); GtkWidget* widget = gtkSpinButton(); gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style().direction())); IntRect fullSpinButtonRect(IntPoint(), expandedRect.size()); widgetContext.gtkPaintBox(fullSpinButtonRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "spinbutton"); bool upPressed = isSpinUpButtonPartPressed(renderObject); bool upHovered = isSpinUpButtonPartHovered(renderObject); bool controlActive = isEnabled(renderObject) && !isReadOnlyControl(renderObject); GtkShadowType shadowType = upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; GtkStateType stateType = GTK_STATE_INSENSITIVE; if (controlActive) { if (isPressed(renderObject) && upPressed) stateType = GTK_STATE_ACTIVE; else if (isHovered(renderObject) && upHovered) stateType = GTK_STATE_PRELIGHT; else stateType = GTK_STATE_NORMAL; } IntRect topRect(IntPoint(), expandedRect.size()); topRect.setHeight(expandedRect.height() / 2); widgetContext.gtkPaintBox(topRect, widget, stateType, shadowType, "spinbutton_up"); // The arrow size/position calculation here is based on the arbitrary gymnastics that happen // in gtkspinbutton.c. It isn't pretty there and it isn't pretty here. This manages to make // the button look native for many themes though. IntRect arrowRect; int arrowSize = (expandedRect.width() - 3) / 2; arrowSize -= (arrowSize % 2) - 1; // Force odd. arrowRect.setWidth(arrowSize); arrowRect.setHeight(arrowSize); arrowRect.move((expandedRect.width() - arrowRect.width()) / 2, (topRect.height() - arrowRect.height()) / 2 + 1); widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_UP, "spinbutton"); shadowType = isPressed(renderObject) && !upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; if (controlActive) { if (isPressed(renderObject) && !upPressed) stateType = GTK_STATE_ACTIVE; else if (isHovered(renderObject) && !upHovered) stateType = GTK_STATE_PRELIGHT; else stateType = GTK_STATE_NORMAL; } IntRect bottomRect(IntPoint(0, expandedRect.height() / 2), expandedRect.size()); bottomRect.setHeight(expandedRect.height() - bottomRect.y()); widgetContext.gtkPaintBox(bottomRect, widget, stateType, shadowType, "spinbutton_down"); arrowRect.setY(arrowRect.y() + bottomRect.y() - 1); widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_DOWN, "spinbutton"); return false; }