static void remmina_main_init(RemminaMain *remminamain) { RemminaMainPriv *priv; GtkWidget *vbox; GtkWidget *menubar; GtkWidget *hbox; GtkWidget *quickconnect; GtkWidget *tool_item; GtkUIManager *uimanager; GtkActionGroup *action_group; GtkWidget *scrolledwindow; GtkWidget *tree; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GError *error; priv = g_new0(RemminaMainPriv, 1); remminamain->priv = priv; remminamain->priv->expanded_group = remmina_string_array_new_from_string(remmina_pref.expanded_group); /* Create main window */ g_signal_connect(G_OBJECT(remminamain), "delete-event", G_CALLBACK(remmina_main_on_delete_event), NULL); g_signal_connect(G_OBJECT(remminamain), "destroy", G_CALLBACK(remmina_main_destroy), NULL); g_signal_connect(G_OBJECT(remminamain), "window-state-event", G_CALLBACK(remmina_main_on_window_state_event), NULL); gtk_container_set_border_width(GTK_CONTAINER(remminamain), 0); gtk_window_set_title(GTK_WINDOW(remminamain), _("Remmina Remote Desktop Client")); gtk_window_set_default_size(GTK_WINDOW(remminamain), remmina_pref.main_width, remmina_pref.main_height); gtk_window_set_position(GTK_WINDOW(remminamain), GTK_WIN_POS_CENTER); if (remmina_pref.main_maximize) { gtk_window_maximize(GTK_WINDOW(remminamain)); } /* Create the main container */ #if GTK_VERSION == 3 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); #elif GTK_VERSION == 2 vbox = gtk_vbox_new(FALSE, 0); #endif gtk_container_add(GTK_CONTAINER(remminamain), vbox); gtk_widget_show(vbox); /* Create the menubar and toolbar */ uimanager = gtk_ui_manager_new(); priv->uimanager = uimanager; action_group = gtk_action_group_new("RemminaMainActions"); gtk_action_group_set_translation_domain(action_group, NULL); gtk_action_group_add_actions(action_group, remmina_main_ui_menu_entries, G_N_ELEMENTS(remmina_main_ui_menu_entries), remminamain); gtk_action_group_add_toggle_actions(action_group, remmina_main_ui_toggle_menu_entries, G_N_ELEMENTS(remmina_main_ui_toggle_menu_entries), remminamain); gtk_action_group_add_radio_actions(action_group, remmina_main_ui_view_file_mode_entries, G_N_ELEMENTS(remmina_main_ui_view_file_mode_entries), remmina_pref.view_file_mode, G_CALLBACK(remmina_main_action_view_file_mode), remminamain); gtk_ui_manager_insert_action_group(uimanager, action_group, 0); g_object_unref(action_group); priv->main_group = action_group; action_group = gtk_action_group_new("RemminaMainFileSensitiveActions"); gtk_action_group_set_translation_domain(action_group, NULL); gtk_action_group_add_actions(action_group, remmina_main_ui_file_sensitive_menu_entries, G_N_ELEMENTS(remmina_main_ui_file_sensitive_menu_entries), remminamain); gtk_ui_manager_insert_action_group(uimanager, action_group, 0); g_object_unref(action_group); priv->file_sensitive_group = action_group; error = NULL; gtk_ui_manager_add_ui_from_string(uimanager, remmina_main_ui_xml, -1, &error); if (error) { g_message("building menus failed: %s", error->message); g_error_free(error); } remmina_plugin_manager_for_each_plugin(REMMINA_PLUGIN_TYPE_TOOL, remmina_main_add_tool_plugin, remminamain); menubar = gtk_ui_manager_get_widget(uimanager, "/MenuBar"); gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0); priv->toolbar = gtk_ui_manager_get_widget(uimanager, "/ToolBar"); #if GTK_VERSION == 3 gtk_style_context_add_class(gtk_widget_get_style_context(priv->toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); #endif gtk_box_pack_start(GTK_BOX(vbox), priv->toolbar, FALSE, FALSE, 0); tool_item = gtk_ui_manager_get_widget(uimanager, "/ToolBar/ConnectionConnect"); gtk_tool_item_set_is_important (GTK_TOOL_ITEM(tool_item), TRUE); tool_item = gtk_ui_manager_get_widget(uimanager, "/ToolBar/ConnectionNew"); gtk_tool_item_set_is_important (GTK_TOOL_ITEM(tool_item), TRUE); remmina_main_create_quick_search(remminamain); gtk_window_add_accel_group(GTK_WINDOW(remminamain), gtk_ui_manager_get_accel_group(uimanager)); gtk_action_group_set_sensitive(priv->file_sensitive_group, FALSE); /* Add a Fast Connection box */ #if GTK_VERSION == 3 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); #elif GTK_VERSION == 2 hbox = gtk_hbox_new(FALSE, 0); #endif priv->quickconnect_protocol = gtk_combo_box_text_new(); #if GTK_VERSION == 3 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "RDP", "RDP"); gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "VNC", "VNC"); gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "NX", "NX"); gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "SSH", "SSH"); #elif GTK_VERSION == 2 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "RDP"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "VNC"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "NX"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->quickconnect_protocol), "SSH"); #endif gtk_combo_box_set_active(GTK_COMBO_BOX(priv->quickconnect_protocol), 0); gtk_widget_show(priv->quickconnect_protocol); gtk_box_pack_start(GTK_BOX(hbox), priv->quickconnect_protocol, FALSE, FALSE, 0); priv->quickconnect_server = gtk_entry_new(); gtk_entry_set_width_chars(GTK_ENTRY(priv->quickconnect_server), 25); gtk_widget_show(priv->quickconnect_server); gtk_box_pack_start(GTK_BOX(hbox), priv->quickconnect_server, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(priv->quickconnect_server), "key-press-event", G_CALLBACK(remmina_main_quickconnect_on_key_press), remminamain); quickconnect = gtk_button_new_with_label("Connect !"); gtk_widget_show(quickconnect); gtk_box_pack_start(GTK_BOX(hbox), quickconnect, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(quickconnect), "clicked", G_CALLBACK(remmina_main_quickconnect_on_click), remminamain); gtk_container_add(GTK_CONTAINER(vbox), hbox); gtk_widget_show(hbox); /* Create the scrolled window for the file list */ scrolledwindow = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(scrolledwindow); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(vbox), scrolledwindow, TRUE, TRUE, 0); /* Create the remmina file list */ tree = gtk_tree_view_new(); column = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(column, _("Name")); gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_column_set_sort_column_id(column, NAME_COLUMN); renderer = gtk_cell_renderer_pixbuf_new(); gtk_tree_view_column_pack_start(column, renderer, FALSE); gtk_tree_view_column_add_attribute(column, renderer, "icon-name", PROTOCOL_COLUMN); g_object_set(G_OBJECT(renderer), "stock-size", GTK_ICON_SIZE_LARGE_TOOLBAR, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(column, renderer, FALSE); gtk_tree_view_column_add_attribute(column, renderer, "text", NAME_COLUMN); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Group"), renderer, "text", GROUP_COLUMN, NULL); gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_column_set_sort_column_id(column, GROUP_COLUMN); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); priv->group_column = column; renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Server"), renderer, "text", SERVER_COLUMN, NULL); gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_column_set_sort_column_id(column, SERVER_COLUMN); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); gtk_container_add(GTK_CONTAINER(scrolledwindow), tree); gtk_widget_show(tree); gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)), remmina_main_selection_func, remminamain, NULL); g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(remmina_main_file_list_on_button_press), remminamain); g_signal_connect(G_OBJECT(tree), "key-press-event", G_CALLBACK(remmina_main_file_list_on_key_press), remminamain); priv->file_list = tree; /* Create statusbar */ priv->statusbar = gtk_statusbar_new(); gtk_box_pack_start(GTK_BOX(vbox), priv->statusbar, FALSE, FALSE, 0); gtk_widget_show(priv->statusbar); /* Prepare the data */ remmina_main_load_files(remminamain, FALSE); /* Load the preferences */ if (remmina_pref.hide_toolbar) { gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_action_group_get_action(priv->main_group, "ViewToolbar")), FALSE); } if (remmina_pref.hide_statusbar) { gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_action_group_get_action(priv->main_group, "ViewStatusbar")), FALSE); } if (remmina_pref.show_quick_search) { gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(gtk_action_group_get_action(priv->main_group, "ViewQuickSearch")), TRUE); } if (remmina_pref.small_toolbutton) { gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(gtk_action_group_get_action(priv->main_group, "ViewSmallToolbutton")), TRUE); } /* Drag-n-drop support */ gtk_drag_dest_set(GTK_WIDGET(remminamain), GTK_DEST_DEFAULT_ALL, remmina_drop_types, 1, GDK_ACTION_COPY); g_signal_connect(G_OBJECT(remminamain), "drag-data-received", G_CALLBACK(remmina_main_on_drag_data_received), NULL); priv->initialized = TRUE; remmina_widget_pool_register(GTK_WIDGET(remminamain)); }
static void gtk_level_bar_draw_fill_continuous (GtkLevelBar *self, cairo_t *cr, gboolean inverted, cairo_rectangle_int_t *fill_area) { GtkWidget *widget = GTK_WIDGET (self); GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStateFlags flags = gtk_widget_get_state_flags (widget); cairo_rectangle_int_t base_area, block_area; GtkBorder block_margin; gdouble fill_percentage; gtk_style_context_save (context); gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK); gtk_style_context_get_margin (context, flags, &block_margin); /* render the empty (unfilled) part */ base_area = *fill_area; base_area.x += block_margin.left; base_area.y += block_margin.top; base_area.width -= block_margin.left + block_margin.right; base_area.height -= block_margin.top + block_margin.bottom; gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK); gtk_render_background (context, cr, base_area.x, base_area.y, base_area.width, base_area.height); gtk_render_frame (context, cr, base_area.x, base_area.y, base_area.width, base_area.height); gtk_style_context_remove_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK); /* now render the filled part on top of it */ block_area = base_area; fill_percentage = (self->priv->cur_value - self->priv->min_value) / (self->priv->max_value - self->priv->min_value); if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) { block_area.width = (gint) floor (block_area.width * fill_percentage); if (inverted) block_area.x += base_area.width - block_area.width; } else { block_area.height = (gint) floor (block_area.height * fill_percentage); if (inverted) block_area.y += base_area.height - block_area.height; } gtk_render_background (context, cr, block_area.x, block_area.y, block_area.width, block_area.height); gtk_render_frame (context, cr, block_area.x, block_area.y, block_area.width, block_area.height); gtk_style_context_restore (context); }
static GtkWidget * gs_update_list_get_section_header (GsUpdateList *update_list, GsUpdateListSection section) { GsUpdateListPrivate *priv = gs_update_list_get_instance_private (update_list); GtkStyleContext *context; GtkWidget *header; GtkWidget *label; GtkWidget *button = NULL; /* get labels and buttons for everything */ if (section == GS_UPDATE_LIST_SECTION_OFFLINE_FIRMWARE) { /* TRANSLATORS: This is the header for system firmware that * requires a reboot to apply */ label = gtk_label_new (_("Integrated Firmware")); /* TRANSLATORS: This is the button for upgrading all * system firmware */ button = gtk_button_new_with_label (_("Restart & Update")); g_signal_connect (button, "clicked", G_CALLBACK (gs_update_list_update_offline_firmware_cb), update_list); } else if (section == GS_UPDATE_LIST_SECTION_OFFLINE) { /* TRANSLATORS: This is the header for offline OS and offline * app updates that require a reboot to apply */ label = gtk_label_new (_("Requires Restart")); /* TRANSLATORS: This is the button for upgrading all * offline updates */ button = gtk_button_new_with_label (_("Restart & Update")); g_signal_connect (button, "clicked", G_CALLBACK (gs_update_list_update_offline_cb), update_list); } else if (section == GS_UPDATE_LIST_SECTION_ONLINE) { /* TRANSLATORS: This is the header for online runtime and * app updates, typically flatpaks or snaps */ label = gtk_label_new (_("Application Updates")); /* TRANSLATORS: This is the button for upgrading all * online-updatable applications */ button = gtk_button_new_with_label (_("Update All")); g_signal_connect (button, "clicked", G_CALLBACK (gs_update_list_update_online_cb), update_list); } else if (section == GS_UPDATE_LIST_SECTION_ONLINE_FIRMWARE) { /* TRANSLATORS: This is the header for device firmware that can * be installed online */ label = gtk_label_new (_("Device Firmware")); } else { g_assert_not_reached (); } /* create header */ header = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); gtk_size_group_add_widget (priv->sizegroup_header, header); context = gtk_widget_get_style_context (header); gtk_style_context_add_class (context, "app-listbox-header"); /* put label into the header */ gtk_box_pack_start (GTK_BOX (header), label, TRUE, TRUE, 0); gtk_widget_set_visible (label, TRUE); gtk_widget_set_margin_start (label, 6); gtk_label_set_xalign (GTK_LABEL (label), 0.0); context = gtk_widget_get_style_context (label); gtk_style_context_add_class (context, "app-listbox-header-title"); /* add button if one is specified */ if (button != NULL) { gtk_box_pack_end (GTK_BOX (header), button, FALSE, FALSE, 0); gtk_widget_set_visible (button, TRUE); gtk_widget_set_margin_end (button, 6); gtk_size_group_add_widget (priv->sizegroup_button, button); } /* success */ return header; }
// static wxVisualAttributes wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, bool WXUNUSED_IN_GTK3(useBase), int state) { wxVisualAttributes attr; GtkWidget* tlw = NULL; if (gtk_widget_get_parent(widget) == NULL) { tlw = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_add(GTK_CONTAINER(tlw), widget); } #ifdef __WXGTK3__ GtkStateFlags stateFlag = GTK_STATE_FLAG_NORMAL; if (state) { wxASSERT(state == GTK_STATE_ACTIVE); stateFlag = GTK_STATE_FLAG_ACTIVE; } GtkStyleContext* sc = gtk_widget_get_style_context(widget); GdkRGBA c; gtk_style_context_get_color(sc, stateFlag, &c); attr.colFg = wxColour(c); gtk_style_context_get_background_color(sc, stateFlag, &c); attr.colBg = wxColour(c); wxNativeFontInfo info; gtk_style_context_get( sc, stateFlag, GTK_STYLE_PROPERTY_FONT, &info.description, NULL); attr.font = wxFont(info); #else GtkStyle* style; style = gtk_rc_get_style(widget); if (!style) style = gtk_widget_get_default_style(); if (style) { // get the style's colours attr.colFg = wxColour(style->fg[state]); if (useBase) attr.colBg = wxColour(style->base[state]); else attr.colBg = wxColour(style->bg[state]); // get the style's font if (!style->font_desc) style = gtk_widget_get_default_style(); if (style && style->font_desc) { wxNativeFontInfo info; info.description = style->font_desc; attr.font = wxFont(info); info.description = NULL; } } else attr = wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); #endif if (!attr.font.IsOk()) { GtkSettings *settings = gtk_settings_get_default(); gchar *font_name = NULL; g_object_get ( settings, "gtk-font-name", &font_name, NULL); if (!font_name) attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); else attr.font = wxFont(wxString::FromAscii(font_name)); g_free (font_name); } if (tlw) gtk_widget_destroy(tlw); return attr; }
static gboolean gtk_color_swatch_render (GtkCssGadget *gadget, cairo_t *cr, int x, int y, int width, int height, gpointer data) { GtkWidget *widget; GtkColorSwatch *swatch; GtkStyleContext *context; widget = gtk_css_gadget_get_owner (gadget); swatch = GTK_COLOR_SWATCH (widget); context = gtk_widget_get_style_context (widget); if (swatch->priv->has_color) { cairo_pattern_t *pattern; cairo_matrix_t matrix; gtk_render_content_path (context, cr, x, y, width, height); if (swatch->priv->use_alpha) { cairo_save (cr); cairo_clip_preserve (cr); cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); cairo_fill_preserve (cr); pattern = _gtk_color_chooser_get_checkered_pattern (); cairo_matrix_init_scale (&matrix, 0.125, 0.125); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); cairo_mask (cr, pattern); cairo_pattern_destroy (pattern); cairo_restore (cr); gdk_cairo_set_source_rgba (cr, &swatch->priv->color); } else { cairo_set_source_rgb (cr, swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue); } cairo_fill (cr); } gtk_render_frame (context, cr, x, y, width, height); gtk_css_gadget_draw (swatch->priv->overlay_gadget, cr); return gtk_widget_has_visible_focus (widget); }
static void draw_menu (GtkWidget *widget, cairo_t *cr, gint x, gint y, gint width, gint *height) { GtkStyleContext *menu_context; GtkStyleContext *menuitem_context; GtkStyleContext *hovermenuitem_context; GtkStyleContext *hoveredarrowmenuitem_context; GtkStyleContext *arrowmenuitem_context; GtkStyleContext *checkmenuitem_context; GtkStyleContext *disabledarrowmenuitem_context; GtkStyleContext *disabledcheckmenuitem_context; GtkStyleContext *radiomenuitem_context; GtkStyleContext *disablemenuitem_context; GtkStyleContext *disabledradiomenuitem_context; GtkStyleContext *separatormenuitem_context; gint menuitem1_height, menuitem2_height, menuitem3_height, menuitem4_height, menuitem5_height; gint contents_x, contents_y, contents_width, contents_height; gint menu_x, menu_y, menu_width, menu_height; gint arrow_width, arrow_height, arrow_size; gint toggle_x, toggle_y, toggle_width, toggle_height; /* This information is taken from the GtkMenu docs, see "CSS nodes" */ menu_context = get_style (gtk_widget_get_style_context(widget), "menu"); hovermenuitem_context = get_style (menu_context, "menuitem:hover"); hoveredarrowmenuitem_context = get_style (hovermenuitem_context, "arrow.right:dir(ltr)"); menuitem_context = get_style (menu_context, "menuitem"); arrowmenuitem_context = get_style (menuitem_context, "arrow:dir(rtl)"); disablemenuitem_context = get_style (menu_context, "menuitem:disabled"); disabledarrowmenuitem_context = get_style (disablemenuitem_context, "arrow:dir(rtl)"); checkmenuitem_context = get_style (menuitem_context, "check:checked"); disabledcheckmenuitem_context = get_style (disablemenuitem_context, "check"); separatormenuitem_context = get_style (menu_context, "separator:disabled"); radiomenuitem_context = get_style (menuitem_context, "radio:checked"); disabledradiomenuitem_context = get_style (disablemenuitem_context, "radio"); *height = 0; query_size (menu_context, NULL, height); menuitem1_height = 0; query_size (hovermenuitem_context, NULL, &menuitem1_height); query_size (hoveredarrowmenuitem_context, NULL, &menuitem1_height); *height += menuitem1_height; menuitem2_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (menuitem_context, NULL, &menuitem2_height); query_size (arrowmenuitem_context, NULL, &menuitem2_height); query_size (disabledarrowmenuitem_context, NULL, &menuitem2_height); *height += menuitem2_height; menuitem3_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (menuitem_context, NULL, &menuitem3_height); query_size (checkmenuitem_context, NULL, &menuitem3_height); query_size (disabledcheckmenuitem_context, NULL, &menuitem3_height); *height += menuitem3_height; menuitem4_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (separatormenuitem_context, NULL, &menuitem4_height); *height += menuitem4_height; menuitem5_height = 0; query_size (menu_context, NULL, &menuitem5_height); query_size (menuitem_context, NULL, &menuitem5_height); query_size (radiomenuitem_context, NULL, &menuitem5_height); query_size (disabledradiomenuitem_context, NULL, &menuitem5_height); *height += menuitem5_height; draw_style_common (menu_context, cr, x, y, width, *height, &menu_x, &menu_y, &menu_width, &menu_height); /* Hovered with right arrow */ gtk_style_context_get (hoveredarrowmenuitem_context, "min-width", &arrow_width, "min-height", &arrow_height, NULL); arrow_size = MIN (arrow_width, arrow_height); draw_style_common (hovermenuitem_context, cr, menu_x, menu_y, menu_width, menuitem1_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_render_arrow (hoveredarrowmenuitem_context, cr, G_PI / 2, contents_x + contents_width - arrow_size, contents_y + (contents_height - arrow_size) / 2, arrow_size); /* Left arrow sensitive, and right arrow insensitive */ draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height, menu_width, menuitem2_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_style_context_get (arrowmenuitem_context, "min-width", &arrow_width, "min-height", &arrow_height, NULL); arrow_size = MIN (arrow_width, arrow_height); gtk_render_arrow (arrowmenuitem_context, cr, G_PI / 2, contents_x, contents_y + (contents_height - arrow_size) / 2, arrow_size); gtk_style_context_get (disabledarrowmenuitem_context, "min-width", &arrow_width, "min-height", &arrow_height, NULL); arrow_size = MIN (arrow_width, arrow_height); gtk_render_arrow (disabledarrowmenuitem_context, cr, G_PI / 2, contents_x + contents_width - arrow_size, contents_y + (contents_height - arrow_size) / 2, arrow_size); /* Left check enabled, sensitive, and right check unchecked, insensitive */ draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height, menu_width, menuitem3_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_style_context_get (checkmenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (checkmenuitem_context, cr, contents_x, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (checkmenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); gtk_style_context_get (disabledcheckmenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (disabledcheckmenuitem_context, cr, contents_x + contents_width - toggle_width, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (disabledcheckmenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); /* Separator */ draw_style_common (separatormenuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height + menuitem3_height, menu_width, menuitem4_height, NULL, NULL, NULL, NULL); /* Left check enabled, sensitive, and right check unchecked, insensitive */ draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height + menuitem3_height + menuitem4_height, menu_width, menuitem5_height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_style_context_get (radiomenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (radiomenuitem_context, cr, contents_x, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (radiomenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); gtk_style_context_get (disabledradiomenuitem_context, "min-width", &toggle_width, "min-height", &toggle_height, NULL); draw_style_common (disabledradiomenuitem_context, cr, contents_x + contents_width - toggle_width, contents_y, toggle_width, toggle_height, &toggle_x, &toggle_y, &toggle_width, &toggle_height); gtk_render_check (disabledradiomenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height); g_object_unref (menu_context); g_object_unref (menuitem_context); g_object_unref (hovermenuitem_context); g_object_unref (hoveredarrowmenuitem_context); g_object_unref (arrowmenuitem_context); g_object_unref (checkmenuitem_context); g_object_unref (disabledarrowmenuitem_context); g_object_unref (disabledcheckmenuitem_context); g_object_unref (radiomenuitem_context); g_object_unref (disablemenuitem_context); g_object_unref (disabledradiomenuitem_context); g_object_unref (separatormenuitem_context); }
void *dt_control_expose(void *voidptr) { int width, height, pointerx, pointery; if(!darktable.gui->surface) return NULL; width = dt_cairo_image_surface_get_width(darktable.gui->surface); height = dt_cairo_image_surface_get_height(darktable.gui->surface); GtkWidget *widget = dt_ui_center(darktable.gui->ui); GdkDevice *device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget))); gdk_window_get_device_position(gtk_widget_get_window(widget), device, &pointerx, &pointery, NULL); // create a gtk-independent surface to draw on cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr = cairo_create(cst); // TODO: control_expose: only redraw the part not overlapped by temporary control panel show! // float tb = 8; // fmaxf(10, width/100.0); darktable.control->tabborder = tb; darktable.control->width = width; darktable.control->height = height; GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(widget); gboolean color_found = gtk_style_context_lookup_color (context, "bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_set_line_width(cr, tb); cairo_rectangle(cr, tb / 2., tb / 2., width - tb, height - tb); cairo_stroke(cr); cairo_set_line_width(cr, 1.5); color_found = gtk_style_context_lookup_color (context, "really_dark_bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_rectangle(cr, tb, tb, width - 2 * tb, height - 2 * tb); cairo_stroke(cr); cairo_save(cr); cairo_translate(cr, tb, tb); cairo_rectangle(cr, 0, 0, width - 2 * tb, height - 2 * tb); cairo_clip(cr); cairo_new_path(cr); // draw view dt_view_manager_expose(darktable.view_manager, cr, width - 2 * tb, height - 2 * tb, pointerx - tb, pointery - tb); cairo_restore(cr); // draw log message, if any dt_pthread_mutex_lock(&darktable.control->log_mutex); if(darktable.control->log_ack != darktable.control->log_pos) { cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); const float fontsize = DT_PIXEL_APPLY_DPI(14); cairo_set_font_size(cr, fontsize); cairo_text_extents_t ext; cairo_text_extents(cr, darktable.control->log_message[darktable.control->log_ack], &ext); const float pad = DT_PIXEL_APPLY_DPI(20.0f), xc = width / 2.0; const float yc = height * 0.85 + DT_PIXEL_APPLY_DPI(10), wd = pad + ext.width * .5f; float rad = DT_PIXEL_APPLY_DPI(14); cairo_set_line_width(cr, 1.); cairo_move_to(cr, xc - wd, yc + rad); for(int k = 0; k < 5; k++) { cairo_arc(cr, xc - wd, yc, rad, M_PI / 2.0, 3.0 / 2.0 * M_PI); cairo_line_to(cr, xc + wd, yc - rad); cairo_arc(cr, xc + wd, yc, rad, 3.0 * M_PI / 2.0, M_PI / 2.0); cairo_line_to(cr, xc - wd, yc + rad); if(k == 0) { color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_fill_preserve(cr); } cairo_set_source_rgba(cr, 0., 0., 0., 1.0 / (1 + k)); cairo_stroke(cr); rad += .5f; } color_found = gtk_style_context_lookup_color (context, "fg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_move_to(cr, xc - wd + .5f * pad, yc + 1. / 3. * fontsize); cairo_show_text(cr, darktable.control->log_message[darktable.control->log_ack]); } // draw busy indicator if(darktable.control->log_busy > 0) { cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); const float fontsize = DT_PIXEL_APPLY_DPI(14); cairo_set_font_size(cr, fontsize); cairo_text_extents_t ext; cairo_text_extents(cr, _("working.."), &ext); const float xc = width / 2.0, yc = height * 0.85 - DT_PIXEL_APPLY_DPI(30), wd = ext.width * .5f; cairo_move_to(cr, xc - wd, yc + 1. / 3. * fontsize); cairo_text_path(cr, _("working..")); cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); cairo_fill_preserve(cr); cairo_set_line_width(cr, 0.7); cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); cairo_stroke(cr); } dt_pthread_mutex_unlock(&darktable.control->log_mutex); cairo_destroy(cr); cairo_t *cr_pixmap = cairo_create(darktable.gui->surface); cairo_set_source_surface(cr_pixmap, cst, 0, 0); cairo_paint(cr_pixmap); cairo_destroy(cr_pixmap); cairo_surface_destroy(cst); return NULL; }
void conterm_init(void) { GtkWidget *console; #ifdef G_OS_UNIX gchar *error = NULL; int pty_master; char *pty_name; #endif conterm_load_config(); #ifdef G_OS_UNIX program_window = get_widget("program_window"); console = vte_terminal_new(); gtk_widget_show(console); program_terminal = VTE_TERMINAL(console); g_object_ref(program_terminal); gtk_container_add(GTK_CONTAINER(program_window), console); g_signal_connect_after(program_terminal, "realize", G_CALLBACK(on_vte_realize), NULL); terminal_parent = get_widget("terminal_parent"); g_signal_connect(terminal_parent, "delete-event", G_CALLBACK(on_terminal_parent_delete), NULL); terminal_window = get_widget("terminal_window"); terminal_show = GTK_CHECK_MENU_ITEM(get_widget("terminal_show")); if (pref_terminal_padding) { gint vte_border_x, vte_border_y; #if GTK_CHECK_VERSION(3, 4, 0) GtkStyleContext *context; GtkBorder border; context = gtk_widget_get_style_context (console); gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &border); vte_border_x = border.left + border.right; vte_border_y = border.top + border.bottom; #elif VTE_CHECK_VERSION(0, 24, 0) GtkBorder *border = NULL; gtk_widget_style_get(console, "inner-border", &border, NULL); if (border) { vte_border_x = border->left + border->right; vte_border_y = border->top + border->bottom; gtk_border_free(border); } else vte_border_x = vte_border_y = 2; #else /* VTE 0.24.0 */ /* VTE manual says "deprecated since 0.26", but it's since 0.24 */ vte_terminal_get_padding(program_terminal, &vte_border_x, &vte_border_y); #endif /* VTE 0.24.0 */ pref_terminal_width += vte_border_x; pref_terminal_height += vte_border_y; pref_terminal_padding = FALSE; } if (openpty(&pty_master, &pty_slave, NULL, NULL, NULL) == 0 && grantpt(pty_master) == 0 && unlockpt(pty_master) == 0 && (pty_name = ttyname(pty_slave)) != NULL) { #if VTE_CHECK_VERSION(0, 25, 0) GError *gerror = NULL; VtePty *pty = vte_pty_new_foreign(pty_master, &gerror); if (pty) { vte_terminal_set_pty_object(program_terminal, pty); slave_pty_name = g_strdup(pty_name); } else { error = g_strdup(gerror->message); g_error_free(gerror); } #else /* VTE 0.25.0 */ vte_terminal_set_pty(program_terminal, pty_master); slave_pty_name = g_strdup(pty_name); #endif /* VTE 0.25.0 */ } else error = g_strdup_printf("pty: %s", g_strerror(errno)); if (error) { gtk_widget_set_sensitive(program_window, FALSE); gtk_widget_set_sensitive(GTK_WIDGET(terminal_show), FALSE); msgwin_status_add(_("Scope: %s."), error); g_free(error); } else menu_connect("terminal_menu", &terminal_menu_info, GTK_WIDGET(program_terminal)); #else /* G_OS_UNIX */ gtk_widget_hide(get_widget("program_window")); #endif /* G_OS_UNIX */ #ifdef G_OS_UNIX if (pref_debug_console_vte) { console = vte_terminal_new(); gtk_widget_show(console); debug_console = VTE_TERMINAL(console); dc_output = console_output; dc_output_nl = console_output_nl; g_signal_connect_after(debug_console, "realize", G_CALLBACK(on_vte_realize), NULL); menu_connect("console_menu", &console_menu_info, console); } else #endif /* G_OS_UNIX */ { static const char *const colors[NFD] = { "#00C0C0", "#C0C0C0", "#C00000", "#C0C0C0", "#C000C0" }; guint i; console = get_widget("debug_context"); context_apply_config(console); debug_context = GTK_TEXT_VIEW(console); dc_output = context_output; dc_output_nl = context_output_nl; context = gtk_text_view_get_buffer(debug_context); for (i = 0; i < NFD; i++) { fd_tags[i] = gtk_text_buffer_create_tag(context, NULL, "foreground", colors[i], NULL); } g_signal_connect(console, "button-press-event", G_CALLBACK(on_console_button_3_press), menu_connect("console_menu", &console_menu_info, NULL)); } gtk_container_add(GTK_CONTAINER(get_widget("debug_window")), console); g_signal_connect(console, "key-press-event", G_CALLBACK(on_console_key_press), NULL); }
static gboolean expose_event(GtkWidget* widget, GdkEventExpose* gdk_event, wxMiniFrame* win) #endif { #ifdef __WXGTK3__ if (!gtk_cairo_should_draw_window(cr, gtk_widget_get_window(widget))) return false; GtkStyleContext* sc = gtk_widget_get_style_context(widget); gtk_style_context_save(sc); gtk_style_context_add_class(sc, GTK_STYLE_CLASS_BUTTON); gtk_render_frame(sc, cr, 0, 0, win->m_width, win->m_height); gtk_style_context_restore(sc); wxGTKCairoDC dc(cr); #else if (gdk_event->count > 0 || gdk_event->window != gtk_widget_get_window(widget)) { return false; } gtk_paint_shadow (gtk_widget_get_style(widget), gtk_widget_get_window(widget), GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, NULL, NULL, // FIXME: No clipping? 0, 0, win->m_width, win->m_height); wxClientDC dc(win); wxDCImpl *impl = dc.GetImpl(); wxClientDCImpl *gtk_impl = wxDynamicCast( impl, wxClientDCImpl ); gtk_impl->m_gdkwindow = gtk_widget_get_window(widget); // Hack alert #endif int style = win->GetWindowStyle(); if (style & wxRESIZE_BORDER) { dc.SetBrush( *wxGREY_BRUSH ); dc.SetPen( *wxTRANSPARENT_PEN ); dc.DrawRectangle( win->m_width - 14, win->m_height-14, 14, 14 ); } if (win->m_miniTitle && !win->GetTitle().empty()) { dc.SetFont( *wxSMALL_FONT ); wxBrush brush( LightContrastColour( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) ) ); dc.SetBrush( brush ); dc.SetPen( *wxTRANSPARENT_PEN ); dc.DrawRectangle( win->m_miniEdge-1, win->m_miniEdge-1, win->m_width - (2*(win->m_miniEdge-1)), 15 ); dc.SetTextForeground( *wxWHITE ); dc.DrawText( win->GetTitle(), 6, 4 ); if (style & wxCLOSE_BOX) dc.DrawBitmap( win->m_closeButton, win->m_width-18, 3, true ); } return false; }
static void empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) { GtkBuilder *gui; char *filename; GtkWidget *contents; GtkWidget *account_hbox, *blocked_contacts_view, *blocked_contacts_sw, *remove_toolbar; GtkEntryCompletion *completion; TpAccountManager *am; GtkStyleContext *context; TpSimpleClientFactory *factory; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG, EmpathyContactBlockingDialogPrivate); gtk_window_set_title (GTK_WINDOW (self), _("Edit Blocked Contacts")); gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui", "libempathy-gtk"); gui = empathy_builder_get_file (filename, "contents", &contents, "account-hbox", &account_hbox, "add-button", &self->priv->add_button, "add-contact-entry", &self->priv->add_contact_entry, "blocked-contacts", &self->priv->blocked_contacts, "blocked-contacts-sw", &blocked_contacts_sw, "blocked-contacts-view", &blocked_contacts_view, "remove-button", &self->priv->remove_button, "remove-toolbar", &remove_toolbar, NULL); empathy_builder_connect (gui, self, "add-button", "clicked", contact_blocking_dialog_add_contact, "add-contact-entry", "activate", contact_blocking_dialog_add_contact, "remove-button", "clicked", contact_blocking_dialog_remove_contacts, NULL); /* join the remove toolbar to the treeview */ context = gtk_widget_get_style_context (blocked_contacts_sw); gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); context = gtk_widget_get_style_context (remove_toolbar); gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); /* add the contents to the dialog */ gtk_container_add ( GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))), contents); gtk_widget_show (contents); /* set up the tree selection */ self->priv->selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (blocked_contacts_view)); gtk_tree_selection_set_mode (self->priv->selection, GTK_SELECTION_MULTIPLE); g_signal_connect (self->priv->selection, "changed", G_CALLBACK (contact_blocking_dialog_view_selection_changed), self); /* build the contact entry */ self->priv->completion_contacts = gtk_list_store_new (N_COMPLETION_COLUMNS, G_TYPE_STRING, /* id */ G_TYPE_STRING, /* text */ TP_TYPE_CONTACT); /* contact */ completion = gtk_entry_completion_new (); gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (self->priv->completion_contacts)); gtk_entry_completion_set_text_column (completion, COL_COMPLETION_TEXT); gtk_entry_completion_set_match_func (completion, contact_selector_dialog_match_func, NULL, NULL); g_signal_connect (completion, "match-selected", G_CALLBACK (contact_selector_dialog_match_selected_cb), self); gtk_entry_set_completion (GTK_ENTRY (self->priv->add_contact_entry), completion); g_object_unref (completion); g_object_unref (self->priv->completion_contacts); /* add the account chooser */ self->priv->account_chooser = empathy_account_chooser_new (); contact_blocking_dialog_refilter_account_chooser (self); g_signal_connect (self->priv->account_chooser, "changed", G_CALLBACK (contact_blocking_dialog_account_changed), self); gtk_box_pack_start (GTK_BOX (account_hbox), self->priv->account_chooser, TRUE, TRUE, 0); gtk_widget_show (self->priv->account_chooser); /* add an error warning info bar */ self->priv->info_bar = gtk_info_bar_new (); gtk_box_pack_start (GTK_BOX (contents), self->priv->info_bar, FALSE, TRUE, 0); gtk_info_bar_set_message_type (GTK_INFO_BAR (self->priv->info_bar), GTK_MESSAGE_ERROR); self->priv->info_bar_label = gtk_label_new (""); gtk_container_add (GTK_CONTAINER ( gtk_info_bar_get_content_area (GTK_INFO_BAR (self->priv->info_bar))), self->priv->info_bar_label); gtk_widget_show (self->priv->info_bar_label); /* prepare the account manager */ am = tp_account_manager_dup (); factory = tp_proxy_get_factory (am); tp_simple_client_factory_add_connection_features_varargs (factory, TP_CONNECTION_FEATURE_CONTACT_BLOCKING, NULL); tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self); g_object_unref (am); g_free (filename); g_object_unref (gui); }
static gboolean budgie_popover_draw(GtkWidget *widget, cairo_t *cr, gboolean draw) { BudgiePopover *self = BUDGIE_POPOVER(widget); GtkStyleContext *style; GtkAllocation alloc; GtkPositionType gap_side; GdkRGBA color; gdouble x, y, tail_height, gap_width; gdouble margin, width, height, gap1, gap2; x = 0; y = 0; tail_height = 12; gap_width = 24; margin = 11; x += margin; y += margin; style = gtk_widget_get_style_context(widget); gtk_style_context_add_class(style, GTK_STYLE_CLASS_FRAME); gtk_widget_get_allocation(widget, &alloc); /* Have parent class do drawing, so we gain shadows */ ((GtkWidgetClass*)budgie_popover_parent_class)->draw(widget, cr); /* Remove height of tail, and margin, from our rendered size */ width = alloc.width; height = alloc.height - tail_height; height -= margin; width -= margin*2; cairo_set_operator(cr, CAIRO_OPERATOR_OVER); gap1 = (alloc.width/2)-(gap_width/2); gap1 = self->widg_x; gap2 = gap1 + gap_width; gap2 -= margin; gap_side = self->top == TRUE ? GTK_POS_TOP : GTK_POS_BOTTOM; /* Render a gap in the bottom center for our arrow */ gtk_render_frame_gap(style, cr, x, y, width, height, gap_side, gap1, gap2); /* Fill in the background (pre-clip) */ gtk_render_background(style, cr, x, y, width, height); /* Clip to the tail, fill in the arrow background */ cairo_save(cr); if (self->top) budgie_tail_path(cr, gap1, gap_width, y-margin, tail_height, self->top); else budgie_tail_path(cr, gap1, gap_width, height+margin, tail_height, self->top); cairo_clip(cr); if (self->top) gtk_render_background(style, cr, x, y-tail_height, alloc.width, alloc.height); else gtk_render_background(style, cr, x, y, alloc.width, alloc.height); cairo_restore(cr); /* Draw in the border */ gtk_style_context_get_border_color(style, gtk_widget_get_state_flags(widget), &color); gdk_cairo_set_source_rgba(cr, &color); cairo_set_line_width(cr, 1); if (self->top) budgie_tail_path(cr, gap1, gap_width, y-margin, tail_height, self->top); else budgie_tail_path(cr, gap1, gap_width, height+margin, tail_height, self->top); cairo_stroke(cr); /* Draw children */ gtk_container_propagate_draw(GTK_CONTAINER(widget), gtk_bin_get_child(GTK_BIN(widget)), cr); return TRUE; }
static gboolean swatch_draw (GtkWidget *widget, cairo_t *cr) { GtkColorSwatch *swatch = (GtkColorSwatch*)widget; gdouble width, height; GtkStyleContext *context; GtkStateFlags state; GtkIconTheme *theme; GtkBorder border, padding; GdkRectangle rect; GtkIconInfo *icon_info = NULL; theme = gtk_icon_theme_get_default (); context = gtk_widget_get_style_context (widget); state = gtk_style_context_get_state (context); width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); gtk_render_background (context, cr, 0, 0, width, height); if (swatch->priv->has_color) { cairo_pattern_t *pattern; cairo_matrix_t matrix; gtk_render_content_path (context, cr, 0, 0, width, height); if (swatch->priv->use_alpha) { cairo_save (cr); cairo_clip_preserve (cr); cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); cairo_fill_preserve (cr); pattern = _gtk_color_chooser_get_checkered_pattern (); cairo_matrix_init_scale (&matrix, 0.125, 0.125); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); cairo_mask (cr, pattern); cairo_pattern_destroy (pattern); cairo_restore (cr); gdk_cairo_set_source_rgba (cr, &swatch->priv->color); } else { cairo_set_source_rgb (cr, swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue); } cairo_fill (cr); } gtk_render_frame (context, cr, 0, 0, width, height); if (swatch->priv->icon) { icon_info = gtk_icon_theme_lookup_icon (theme, swatch->priv->icon, PIXBUF_SIZE, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); } else if ((state & GTK_STATE_FLAG_SELECTED) != 0) { GIcon *gicon; gicon = g_themed_icon_new ("object-select-symbolic"); /* fallback for themes that don't have object-select-symbolic */ g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply"); icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, PIXBUF_SIZE, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); g_object_unref (gicon); } /* now draw the overlay image */ gtk_style_context_get_border (context, state, &border); gtk_style_context_get_padding (context, state, &padding); rect.width = width - (border.left + border.right + padding.left + padding.right); rect.height = height - (border.top + border.bottom + padding.top + padding.bottom); rect.x = border.left + padding.left; rect.y = border.top + padding.top; gtk_style_context_save (context); gtk_style_context_add_class (context, "overlay"); gtk_render_background (context, cr, rect.x, rect.y, rect.width, rect.height); gtk_render_frame (context, cr, rect.x, rect.y, rect.width, rect.height); if (icon_info != NULL) { GdkPixbuf *pixbuf; pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL); if (pixbuf != NULL) { gtk_render_icon (context, cr, pixbuf, rect.x + (rect.width - gdk_pixbuf_get_width (pixbuf)) / 2, rect.y + (rect.height - gdk_pixbuf_get_height (pixbuf)) / 2); g_object_unref (pixbuf); } g_object_unref (icon_info); } if (gtk_widget_has_visible_focus (widget)) { gtk_render_focus (context, cr, 0, 0, width, height); } gtk_style_context_restore (context); return FALSE; }
static void gtk_rotated_bin_realize (GtkWidget *widget) { GtkRotatedBin *bin = GTK_ROTATED_BIN (widget); GtkAllocation allocation; GtkStyleContext *context; GdkWindow *window; GdkWindowAttr attributes; gint attributes_mask; guint border_width; GtkRequisition child_requisition; gtk_widget_set_realized (widget, TRUE); gtk_widget_get_allocation (widget, &allocation); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); attributes.x = allocation.x + border_width; attributes.y = allocation.y + border_width; attributes.width = allocation.width - 2 * border_width; attributes.height = allocation.height - 2 * border_width; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK; attributes.visual = gtk_widget_get_visual (widget); attributes.wclass = GDK_INPUT_OUTPUT; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gtk_widget_set_window (widget, window); gdk_window_set_user_data (window, widget); g_signal_connect (window, "pick-embedded-child", G_CALLBACK (pick_offscreen_child), bin); attributes.window_type = GDK_WINDOW_OFFSCREEN; child_requisition.width = child_requisition.height = 0; if (bin->child && gtk_widget_get_visible (bin->child)) { GtkAllocation child_allocation; gtk_widget_get_allocation (bin->child, &child_allocation); attributes.width = child_allocation.width; attributes.height = child_allocation.height; } bin->offscreen_window = gdk_window_new (gdk_screen_get_root_window (gtk_widget_get_screen (widget)), &attributes, attributes_mask); gdk_window_set_user_data (bin->offscreen_window, widget); if (bin->child) gtk_widget_set_parent_window (bin->child, bin->offscreen_window); gdk_offscreen_window_set_embedder (bin->offscreen_window, window); g_signal_connect (bin->offscreen_window, "to-embedder", G_CALLBACK (offscreen_window_to_parent), bin); g_signal_connect (bin->offscreen_window, "from-embedder", G_CALLBACK (offscreen_window_from_parent), bin); context = gtk_widget_get_style_context (widget); gtk_style_context_set_background (context, window); gtk_style_context_set_background (context, bin->offscreen_window); gdk_window_show (bin->offscreen_window); }
static gboolean gtk_switch_draw (GtkWidget *widget, cairo_t *cr) { GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv; GtkStyleContext *context; GdkRectangle handle; PangoLayout *layout; PangoRectangle rect; gint label_x, label_y; GtkBorder padding; GtkStateFlags state; gint x, y, width, height; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_save (context); gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER); gtk_style_context_get_padding (context, state, &padding); gtk_style_context_restore (context); x = 0; y = 0; width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); gtk_style_context_save (context); gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH); gtk_render_background (context, cr, x, y, width, height); gtk_render_frame (context, cr, x, y, width, height); width -= padding.left + padding.right; height -= padding.top + padding.bottom; x += padding.left; y += padding.top; handle.y = y; handle.width = width / 2; handle.height = height; /* Translators: if the "on" state label requires more than three * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for * the state */ layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON")); pango_layout_get_extents (layout, NULL, &rect); pango_extents_to_pixels (&rect, NULL); label_x = x + ((width / 2) - rect.width) / 2; label_y = y + (height - rect.height) / 2; gtk_render_layout (context, cr, label_x, label_y, layout); g_object_unref (layout); /* Translators: if the "off" state label requires more than three * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state */ layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF")); pango_layout_get_extents (layout, NULL, &rect); pango_extents_to_pixels (&rect, NULL); label_x = x + (width / 2) + ((width / 2) - rect.width) / 2; label_y = y + (height - rect.height) / 2; gtk_render_layout (context, cr, label_x, label_y, layout); g_object_unref (layout); handle.x = x + priv->handle_x; gtk_style_context_restore (context); gtk_switch_paint_handle (widget, cr, &handle); if (gtk_widget_has_visible_focus (widget)) { gtk_render_focus (context, cr, handle.x, handle.y, handle.width, handle.height); } return FALSE; }
gint main (gint argc, gchar *argv[]) { GtkStyleContext *context; GtkWidget *a; GtkWidget *avatar; GtkWidget *grid; GtkWidget *l; GtkWidget *main_vbox; GtkWidget *scroller; GtkWidget *toolbar; GtkWidget *window; GtkWidget *vbox; GtkWidget *viewport; gint i; gtk_init(&argc, &argv); window = g_object_new(GTK_TYPE_WINDOW, "title", _("Simply Chat"), NULL); main_vbox = g_object_new(GTK_TYPE_VBOX, "visible", TRUE, NULL); gtk_container_add(GTK_CONTAINER(window), main_vbox); toolbar = g_object_new(GTK_TYPE_TOOLBAR, "show-arrow", FALSE, "visible", TRUE, NULL); gtk_style_context_add_class(gtk_widget_get_style_context(toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); gtk_container_add_with_properties(GTK_CONTAINER(main_vbox), toolbar, "expand", FALSE, NULL); l = g_object_new(GTK_TYPE_COMBO_BOX, "has-entry", TRUE, "visible", TRUE, NULL); gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(l))), "Available"); a = g_object_new(GTK_TYPE_TOOL_ITEM, "child", l, "visible", TRUE, NULL); gtk_container_add_with_properties(GTK_CONTAINER(toolbar), a, "expand", TRUE, NULL); scroller = g_object_new(GTK_TYPE_SCROLLED_WINDOW, "visible", TRUE, NULL); gtk_container_add(GTK_CONTAINER(main_vbox), scroller); viewport = g_object_new(GTK_TYPE_VIEWPORT, "visible", TRUE, NULL); context = gtk_widget_get_style_context(viewport); gtk_style_context_add_class(context, GTK_STYLE_CLASS_VIEW); gtk_container_add(GTK_CONTAINER(scroller), viewport); vbox = g_object_new(GTK_TYPE_VBOX, "border-width", 6, "spacing", 6, "visible", TRUE, NULL); gtk_container_add(GTK_CONTAINER(viewport), vbox); a = g_object_new(GTK_TYPE_ALIGNMENT, "left-padding", 12, "right-padding", 6, "visible", TRUE, NULL); grid = g_object_new(CHAT_TYPE_GRID, "column-spacing", 6, "row-spacing", 6, "visible", TRUE, NULL); l = g_object_new(GTK_TYPE_LABEL, "label", "<b>_Frequent <span size='smaller'>(20)</span></b>", "mnemonic-widget", grid, "use-markup", TRUE, "use-underline", TRUE, "visible", TRUE, "xalign", 0.0f, NULL); gtk_container_add_with_properties(GTK_CONTAINER(vbox), l, "expand", FALSE, NULL); gtk_container_add(GTK_CONTAINER(a), grid); gtk_container_add_with_properties(GTK_CONTAINER(vbox), a, "expand", FALSE, NULL); for (i = 0; i < 20; i++) { avatar = g_object_new(CHAT_TYPE_AVATAR, "visible", TRUE, NULL); gtk_container_add(GTK_CONTAINER(grid), avatar); } a = g_object_new(GTK_TYPE_ALIGNMENT, "left-padding", 12, "right-padding", 6, "visible", TRUE, NULL); grid = g_object_new(CHAT_TYPE_GRID, "column-spacing", 6, "row-spacing", 6, "visible", TRUE, NULL); l = g_object_new(GTK_TYPE_LABEL, "label", "<b>_Buddies <span size='smaller'>(100)</span></b>", "mnemonic-widget", grid, "use-markup", TRUE, "use-underline", TRUE, "visible", TRUE, "xalign", 0.0f, NULL); gtk_container_add_with_properties(GTK_CONTAINER(vbox), l, "expand", FALSE, NULL); gtk_container_add(GTK_CONTAINER(a), grid); gtk_container_add_with_properties(GTK_CONTAINER(vbox), a, "expand", FALSE, NULL); for (i = 0; i < 100; i++) { avatar = g_object_new(CHAT_TYPE_AVATAR, "visible", TRUE, NULL); gtk_container_add(GTK_CONTAINER(grid), avatar); } g_signal_connect(window, "delete-event", gtk_main_quit, NULL); gtk_window_present(GTK_WINDOW(window)); gtk_main(); return 0; }
static void gdaui_bar_init (GdauiBar *bar) { GtkWidget *widget = GTK_WIDGET (bar); GtkWidget *content_area; GtkWidget *action_area; bar->priv = g_new0 (GdauiBarPrivate, 1); content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_show (content_area); gtk_box_pack_start (GTK_BOX (bar), content_area, TRUE, TRUE, 0); action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_show (action_area); gtk_box_pack_start (GTK_BOX (bar), action_area, FALSE, TRUE, 0); gtk_widget_set_app_paintable (widget, TRUE); gtk_widget_set_redraw_on_allocate (widget, TRUE); bar->priv->content_area = content_area; bar->priv->action_area = action_area; /* set default spacings */ gtk_box_set_spacing (GTK_BOX (bar->priv->action_area), ACTION_AREA_DEFAULT_SPACING); gtk_container_set_border_width (GTK_CONTAINER (bar->priv->action_area), ACTION_AREA_DEFAULT_BORDER); gtk_box_set_spacing (GTK_BOX (bar->priv->content_area), CONTENT_AREA_DEFAULT_SPACING); gtk_container_set_border_width (GTK_CONTAINER (bar->priv->content_area), CONTENT_AREA_DEFAULT_BORDER); bar->priv->show_icon = FALSE; bar->priv->icon = gtk_image_new (); gtk_misc_set_alignment (GTK_MISC (bar->priv->icon), 1., 0.5); gtk_widget_hide (bar->priv->icon); gtk_box_pack_end (GTK_BOX (bar->priv->content_area), bar->priv->icon, FALSE, TRUE, 0); bar->priv->label = gtk_label_new (""); gtk_label_set_selectable (GTK_LABEL (bar->priv->label), FALSE); gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0., 0.5); gtk_box_pack_end (GTK_BOX (bar->priv->content_area), bar->priv->label, TRUE, TRUE, 0); gtk_widget_show (bar->priv->label); /* CSS theming */ GtkStyleContext *context; if (!css_provider) { #define CSS ".gdauibar {\n" \ "background-color: #b3b3b3;\n" \ "padding: 5px;\n" \ "}" \ ".gdauibar_button {\n" \ "-GtkButton-default-border : 0px;\n" \ "-GtkButton-default-outside-border : 0px;\n" \ "-GtkWidget-focus-line-width : 0px;\n" \ "-GtkWidget-focus-padding : 0px;\n" \ "padding: 0px;\n" \ "-GtkButtonBox-child-internal-pad-x : 1px;\n" \ "-GtkButtonBox-child-min-width : 0px;\n" \ "border-style: none;\n" \ "}" \ ".gdauibar_entry {\n" \ "-GtkWidget-focus-line-width : 0px;\n" \ "-GtkWidget-focus-padding : 0px;\n" \ "padding: 1px;\n" \ "-GtkButtonBox-child-internal-pad-x : 1px;\n" \ "-GtkButtonBox-child-min-width : 0px;\n" \ "border-style: solid;\n" \ "border-radius: 5px;\n" \ "}" css_provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ()); gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (css_provider), CSS, -1, NULL); } context = gtk_widget_get_style_context (GTK_WIDGET (bar)); gtk_style_context_add_provider (context, css_provider, G_MAXUINT); gtk_style_context_add_class (context, "gdauibar"); }
/** * gail_misc_get_default_attributes: * @attrib_set: The #AtkAttributeSet to add the attribute to * @layout: The PangoLayout from which the attributes will be obtained * @widget: The GtkWidget for which the default attributes are required. * * Adds the default attributes to the specified attribute set. * * Returns: A pointer to the #AtkAttributeSet. **/ AtkAttributeSet* gail_misc_get_default_attributes (AtkAttributeSet *attrib_set, PangoLayout *layout, GtkWidget *widget) { PangoContext *context; GtkStyleContext *style_context; gint int_value; PangoWrapMode mode; GdkRGBA color; gchar *value; attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_DIRECTION, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, gtk_widget_get_direction (widget)))); context = pango_layout_get_context (layout); if (context) { PangoLanguage* language; PangoFontDescription* font; language = pango_context_get_language (context); if (language) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LANGUAGE, g_strdup (pango_language_to_string (language))); } font = pango_context_get_font_description (context); if (font) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STYLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STYLE, pango_font_description_get_style (font)))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_VARIANT, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_VARIANT, pango_font_description_get_variant (font)))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRETCH, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRETCH, pango_font_description_get_stretch (font)))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FAMILY_NAME, g_strdup (pango_font_description_get_family (font))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WEIGHT, g_strdup_printf ("%d", pango_font_description_get_weight (font))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SIZE, g_strdup_printf ("%i", pango_font_description_get_size (font) / PANGO_SCALE)); } } if (pango_layout_get_justify (layout)) { int_value = 3; } else { PangoAlignment align; align = pango_layout_get_alignment (layout); if (align == PANGO_ALIGN_LEFT) int_value = 0; else if (align == PANGO_ALIGN_CENTER) int_value = 2; else /* if (align == PANGO_ALIGN_RIGHT) */ int_value = 1; } attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_JUSTIFICATION, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_JUSTIFICATION, int_value))); mode = pango_layout_get_wrap (layout); if (mode == PANGO_WRAP_WORD) int_value = 2; else /* if (mode == PANGO_WRAP_CHAR) */ int_value = 1; attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WRAP_MODE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_WRAP_MODE, int_value))); style_context = gtk_widget_get_style_context (widget); gtk_style_context_get_background_color (style_context, 0, &color); value = g_strdup_printf ("%u,%u,%u", (guint) ceil (color.red * 65536 - color.red), (guint) ceil (color.green * 65536 - color.green), (guint) ceil (color.blue * 65536 - color.blue)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_COLOR, value); gtk_style_context_get_color (style_context, 0, &color); value = g_strdup_printf ("%u,%u,%u", (guint) ceil (color.red * 65536 - color.red), (guint) ceil (color.green * 65536 - color.green), (guint) ceil (color.blue * 65536 - color.blue)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_COLOR, value); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_STIPPLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_FG_STIPPLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_STIPPLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_BG_STIPPLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRIKETHROUGH, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRIKETHROUGH, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_UNDERLINE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_UNDERLINE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RISE, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SCALE, g_strdup_printf ("%g", 1.0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_FULL_HEIGHT, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_BELOW_LINES, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_ABOVE_LINES, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_EDITABLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_EDITABLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_INVISIBLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_INVISIBLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_INDENT, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RIGHT_MARGIN, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LEFT_MARGIN, g_strdup_printf ("%i", 0)); return attrib_set; }
/* Construct the status bar widget. */ static GtkWidget * libre_impuesto_window_construct_headerbar (LibreImpuestoWindow *impuesto_window) { gint size; time_t secs; GDate *today; struct tm *tm; GtkStateFlags state; GtkWidget *headerbar; gchar buffer[100] = ""; GtkWidget *header_area; GtkWidget *grid_layout; GtkStyleContext *context; PangoFontDescription *font_desc; GtkWidget *label_libre_impuesto, *label_software_libre, *label_date; secs = time (NULL); tm = localtime (&secs); header_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1); g_object_bind_property ( impuesto_window, "headerbar-visible", header_area, "visible", G_BINDING_SYNC_CREATE); headerbar = gtk_event_box_new(); gtk_box_pack_start (GTK_BOX (header_area), headerbar, FALSE, FALSE, 0); gtk_widget_set_name (headerbar, "libre-impuesto-header"); gtk_widget_set_size_request (headerbar, -1, 56); grid_layout = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (headerbar), grid_layout); gtk_grid_set_column_homogeneous (GTK_GRID(grid_layout), TRUE); gtk_grid_set_row_homogeneous (GTK_GRID (grid_layout), TRUE); label_libre_impuesto = gtk_label_new (_("Libre Impuestos")); gtk_grid_attach (GTK_GRID (grid_layout), label_libre_impuesto, 0, 0, 1, 1); context = gtk_widget_get_style_context (label_libre_impuesto); state = gtk_widget_get_state_flags (label_libre_impuesto); size = pango_font_description_get_size (gtk_style_context_get_font ( context, state)); font_desc = pango_font_description_new (); pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); pango_font_description_set_size (font_desc, size * PANGO_SCALE_X_LARGE); gtk_widget_override_font (label_libre_impuesto, font_desc); pango_font_description_free (font_desc); gtk_misc_set_alignment (GTK_MISC (label_libre_impuesto), 0.2, 0.4); gtk_widget_show (label_libre_impuesto); label_software_libre = gtk_label_new (_("www.softwarelibre.org.bo")); gtk_grid_attach (GTK_GRID (grid_layout), label_software_libre, 1, 0, 1, 1); gtk_misc_set_alignment (GTK_MISC (label_software_libre), 0.5, 0.8); gtk_widget_show (label_software_libre); today = g_date_new_dmy((gint)tm->tm_mday, (gint)tm->tm_mon + 1, 1900 + tm->tm_year); g_date_strftime (buffer, 100-1, "%A, %d de %B de %Y", today); label_date = gtk_label_new (g_ascii_strup (buffer,100-1)); g_date_free(today); gtk_grid_attach (GTK_GRID (grid_layout), label_date, 2, 0, 1, 1); gtk_misc_set_alignment (GTK_MISC (label_date), 0.9, 0.5); return header_area; }
/** * main * @argc: number of arguments * @argv: arguments * * Description: * main * * Returns: * exit code **/ int main (int argc, char *argv[]) { GtkWidget *errordialog; GtkWidget *vbox, *menubar, *toolbar, *statusbar, *gridframe; GtkUIManager *ui_manager; GOptionContext *context; struct timeval tv; gint i; gchar *config; gboolean retval; GError *error = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); games_scores_startup (); gettimeofday (&tv, NULL); srand (tv.tv_usec); context = g_option_context_new (NULL); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); retval = g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (!retval) { g_print ("%s", error->message); g_error_free (error); exit (1); } g_set_application_name (_("Robots")); highscores = games_scores_new ("gnobots2", scorecats, G_N_ELEMENTS (scorecats), NULL, NULL, 0 /* default category */, GAMES_SCORES_STYLE_PLAIN_DESCENDING); settings = g_settings_new ("org.gnome.gnobots2"); gtk_window_set_default_icon_name ("gnobots2"); app = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (app), _("Robots")); g_signal_connect (GTK_WINDOW (app), "configure-event", G_CALLBACK (window_configure_event_cb), NULL); g_signal_connect (GTK_WINDOW (app), "window-state-event", G_CALLBACK (window_state_event_cb), NULL); gtk_window_set_default_size (GTK_WINDOW (app), g_settings_get_int (settings, "window-width"), g_settings_get_int (settings, "window-height")); if (g_settings_get_boolean (settings, "window-is-fullscreen")) gtk_window_fullscreen (GTK_WINDOW (app)); if (g_settings_get_boolean (settings, "window-is-maximized")) gtk_window_maximize (GTK_WINDOW (app)); g_signal_connect (G_OBJECT (app), "delete_event", G_CALLBACK (quit_game), NULL); statusbar = gnobots_statusbar_new (); ui_manager = gtk_ui_manager_new (); games_stock_prepare_for_statusbar_tooltips (ui_manager, statusbar); create_game_menus (ui_manager); gtk_window_add_accel_group (GTK_WINDOW (app), gtk_ui_manager_get_accel_group (ui_manager)); menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu"); toolbar = gtk_ui_manager_get_widget (ui_manager, "/Toolbar"); gtk_style_context_add_class (gtk_widget_get_style_context (toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); make_cursors (); game_area = gtk_drawing_area_new (); gtk_widget_add_events (game_area, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); g_signal_connect (G_OBJECT (game_area), "button-press-event", G_CALLBACK (mouse_cb), NULL); g_signal_connect (G_OBJECT (game_area), "motion-notify-event", G_CALLBACK (move_cb), NULL); g_signal_connect (G_OBJECT (game_area), "configure-event", G_CALLBACK (resize_cb), NULL); g_signal_connect (G_OBJECT (game_area), "draw", G_CALLBACK (draw_cb), NULL); gridframe = games_grid_frame_new (GAME_WIDTH, GAME_HEIGHT); gtk_container_add (GTK_CONTAINER (gridframe), game_area); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), gridframe, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (app), vbox); gtk_widget_set_size_request (GTK_WIDGET (game_area), MINIMUM_TILE_WIDTH * GAME_WIDTH, MINIMUM_TILE_HEIGHT * GAME_HEIGHT); /* Set the window position if it was set by the session manager */ if (session_xpos >= 0 && session_ypos >= 0) { gtk_window_move (GTK_WINDOW (app), session_xpos, session_ypos); } gtk_widget_show_all (app); if (!load_game_configs ()) { /* Oops, no configs, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _("No game data could be found."), _ ("The program Robots was unable to find any valid game configuration files. Please check that the program is installed correctly.")); gtk_window_set_resizable (GTK_WINDOW (errordialog), FALSE); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } load_properties (); if (!load_game_graphics ()) { /* Oops, no graphics, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (app), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _ ("Some graphics files are missing or corrupt."), _ ("The program Robots was unable to load all the necessary graphics files. Please check that the program is installed correctly.")); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } connect_toolbar_toggle (toolbar); init_sound (); init_game (); if (cmdline_scenario) { set_game_graphics (cmdline_scenario); } if (cmdline_config) { for (i = 0; i < num_game_configs (); ++i) { config = game_config_name (i); if (!strcmp (cmdline_config, config)) { properties_set_config (i); g_free (config); break; } g_free (config); } } gtk_main (); g_settings_sync(); return 0; }
static void cc_background_panel_init (CcBackgroundPanel *self) { CcBackgroundPanelPrivate *priv; gchar *objects[] = { "style-liststore", "sources-liststore", "background-panel", "sizegroup", NULL }; GError *err = NULL; GtkWidget *widget; GtkListStore *store; GtkStyleContext *context; priv = self->priv = BACKGROUND_PANEL_PRIVATE (self); priv->builder = gtk_builder_new (); gtk_builder_add_objects_from_file (priv->builder, DATADIR"/background.ui", objects, &err); if (err) { g_warning ("Could not load ui: %s", err->message); g_error_free (err); return; } /* See shell_notify_cb for details */ g_signal_connect (WID ("scrolledwindow1"), "realize", G_CALLBACK (scrolled_realize_cb), self); priv->settings = g_settings_new (WP_PATH_ID); g_settings_delay (priv->settings); store = (GtkListStore*) gtk_builder_get_object (priv->builder, "sources-liststore"); priv->wallpapers_source = bg_wallpapers_source_new (); gtk_list_store_insert_with_values (store, NULL, G_MAXINT, COL_SOURCE_NAME, _("Wallpapers"), COL_SOURCE_TYPE, SOURCE_WALLPAPERS, COL_SOURCE, priv->wallpapers_source, -1); priv->pictures_source = bg_pictures_source_new (); gtk_list_store_insert_with_values (store, NULL, G_MAXINT, COL_SOURCE_NAME, _("Pictures Folder"), COL_SOURCE_TYPE, SOURCE_PICTURES, COL_SOURCE, priv->pictures_source, -1); priv->colors_source = bg_colors_source_new (); gtk_list_store_insert_with_values (store, NULL, G_MAXINT, COL_SOURCE_NAME, _("Colors & Gradients"), COL_SOURCE_TYPE, SOURCE_COLORS, COL_SOURCE, priv->colors_source, -1); #ifdef HAVE_LIBSOCIALWEB priv->flickr_source = bg_flickr_source_new (); gtk_list_store_insert_with_values (store, NULL, G_MAXINT, COL_SOURCE_NAME, _("Flickr"), COL_SOURCE_TYPE, SOURCE_FLICKR, COL_SOURCE, priv->flickr_source, -1); #endif /* add the top level widget */ widget = WID ("background-panel"); gtk_container_add (GTK_CONTAINER (self), widget); gtk_widget_show_all (GTK_WIDGET (self)); /* connect to source change signal */ widget = WID ("sources-combobox"); g_signal_connect (widget, "changed", G_CALLBACK (source_changed_cb), priv); /* select first item */ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); /* connect to the background iconview change signal */ widget = WID ("backgrounds-iconview"); g_signal_connect (widget, "selection-changed", G_CALLBACK (backgrounds_changed_cb), self); /* Join treeview and buttons */ widget = WID ("scrolledwindow1"); context = gtk_widget_get_style_context (widget); gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); widget = WID ("toolbar1"); context = gtk_widget_get_style_context (widget); gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); g_signal_connect (WID ("add_button"), "clicked", G_CALLBACK (add_button_clicked), self); g_signal_connect (WID ("remove_button"), "clicked", G_CALLBACK (remove_button_clicked), self); /* Add drag and drop support for bg images */ widget = WID ("scrolledwindow1"); gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY); gtk_drag_dest_add_uri_targets (widget); g_signal_connect (widget, "drag-data-received", G_CALLBACK (cc_background_panel_drag_uris), self); /* setup preview area */ gtk_label_set_ellipsize (GTK_LABEL (WID ("background-label")), PANGO_ELLIPSIZE_END); widget = WID ("preview-area"); g_signal_connect (widget, "draw", G_CALLBACK (preview_draw_cb), self); priv->display_base = gdk_pixbuf_new_from_file (DATADIR "/display-base.png", NULL); priv->display_overlay = gdk_pixbuf_new_from_file (DATADIR "/display-overlay.png", NULL); g_signal_connect (WID ("style-combobox"), "changed", G_CALLBACK (style_changed_cb), self); g_signal_connect (WID ("style-pcolor"), "color-set", G_CALLBACK (color_changed_cb), self); g_signal_connect (WID ("style-scolor"), "color-set", G_CALLBACK (color_changed_cb), self); g_signal_connect (WID ("swap-color-button"), "clicked", G_CALLBACK (swap_colors_clicked), self); priv->copy_cancellable = g_cancellable_new (); priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL); load_current_bg (self); update_preview (priv, NULL); /* Setup the edit box with our current settings */ source_update_edit_box (priv, TRUE); }
int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *ebox; GtkStyleContext *context; GtkStyleProvider *provider; gtk_init (&argc, &argv); if (argc > 1) what = argv[1]; else what = "check"; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE); ebox = gtk_event_box_new (); gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), TRUE); gtk_container_add (GTK_CONTAINER (window), ebox); gtk_widget_set_name (ebox, "ebox"); context = gtk_widget_get_style_context (ebox); provider = (GtkStyleProvider *)gtk_css_provider_new (); gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), ".frame1 {\n" " border-image: url('gradient1.png') 10 10 10 10 stretch;\n" "}\n" ".frame2 {\n" " border-style: solid;\n" " border-color: rgb(255,0,0);\n" " border-width: 10;\n" " border-radius: 10;\n" "}\n" ".frame3 {\n" " border-style: solid;\n" " border-color: rgb(0,0,0);\n" " border-width: 2;\n" " border-radius: 10;\n" "}\n" ".background {\n" " border-radius: 10;\n" " border-width: 0;\n" " background-image: -gtk-gradient (linear, left top, right bottom, from(#ff00ff), to(#aabbcc));\n" "}\n" ".frame {\n" " border-style: solid;\n" " border-width: 1;\n" " border-radius: 0;\n" "}\n", -1, NULL); gtk_style_context_add_provider (context, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_signal_connect_after (ebox, "draw", G_CALLBACK (draw_cb), NULL); gtk_widget_show_all (window); gtk_main (); gtk_style_context_remove_provider (context, provider); return 0; }
static void entry_value_changed(GtkWidget *widget, XmiMsimGuiContinuousEnergyDialog *dialog) { char *textPtr1, *textPtr2, *textPtr3, *textPtr4, *textPtr5, *textPtr6, *textPtr7; char *endPtr1, *endPtr2, *endPtr3, *endPtr4, *endPtr5, *endPtr6, *endPtr7; char *lastPtr1, *lastPtr4, *lastPtr5, *lastPtr6, *lastPtr7; int ok1, ok2, ok3, ok4, ok5, ok6, ok7; double value1, value2, value3, value4, value5, value6, value7, value8; GtkStyleContext *style_context = NULL; if (widget != NULL) style_context = gtk_widget_get_style_context(GTK_WIDGET(widget)); textPtr1 = (char *) gtk_entry_get_text(GTK_ENTRY(dialog->energy_entry)); textPtr2 = (char *) gtk_entry_get_text(GTK_ENTRY(dialog->hor_intensity_entry)); textPtr3 = (char *) gtk_entry_get_text(GTK_ENTRY(dialog->ver_intensity_entry)); textPtr4 = (char *) gtk_entry_get_text(GTK_ENTRY(dialog->sigma_x_entry)); textPtr5 = (char *) gtk_entry_get_text(GTK_ENTRY(dialog->sigma_y_entry)); textPtr6 = (char *) gtk_entry_get_text(GTK_ENTRY(dialog->sigma_xp_entry)); textPtr7 = (char *) gtk_entry_get_text(GTK_ENTRY(dialog->sigma_yp_entry)); #define energy_short2(n,my_entry) value ## n = g_ascii_strtod(textPtr ## n, &endPtr ## n);\ lastPtr ## n = textPtr ## n + strlen(textPtr ## n);\ if (lastPtr ## n == endPtr ## n && strcmp(textPtr ## n,"") != 0 && value ## n >= 0.0) \ ok ## n = 1;\ else\ ok ## n = 0;\ if (widget == my_entry) {\ if (ok ## n)\ gtk_style_context_remove_class(style_context, "red"); \ else {\ gtk_style_context_add_class(style_context, "red"); \ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE);\ }\ } #define energy_short3(n,my_entry) value ## n = g_ascii_strtod(textPtr ## n, &endPtr ## n);\ lastPtr ## n = textPtr ## n + strlen(textPtr ## n);\ if (lastPtr ## n == endPtr ## n && strcmp(textPtr ## n,"") != 0 && value ## n > 0.0 && value ## n <= 200.0) \ ok ## n = 1;\ else\ ok ## n = 0;\ if (widget == my_entry) {\ if (ok ## n)\ gtk_style_context_remove_class(style_context, "red"); \ else {\ gtk_style_context_add_class(style_context, "red"); \ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE);\ }\ } energy_short3(1, dialog->energy_entry) energy_short2(4, dialog->sigma_x_entry) energy_short2(5, dialog->sigma_y_entry) energy_short2(6, dialog->sigma_xp_entry) energy_short2(7, dialog->sigma_yp_entry) // investigate the intensities value2 = g_ascii_strtod(textPtr2, &endPtr2); value3 = g_ascii_strtod(textPtr3, &endPtr3); if (textPtr2 + strlen(textPtr2) == endPtr2 && value2 > 0.0) ok2 = 2; // proper strictly positive value else if (textPtr2 + strlen(textPtr2) == endPtr2 && strlen(textPtr2) > 0 && value2 == 0.0) ok2 = 1; // proper 0 else if (strlen(textPtr2) == 0) ok2 = -1; // empty else ok2 = 0; // bad if (textPtr3 + strlen(textPtr3) == endPtr3 && value3 > 0.0) ok3 = 2; // proper strictly positive value else if (textPtr3 + strlen(textPtr3) == endPtr3 && strlen(textPtr3) > 0 && value3 == 0.0) ok3 = 1; // proper 0 else if (strlen(textPtr3) == 0) ok3 = -1; // empty else ok3 = 0; // bad if (abs(ok2) > 0) gtk_style_context_remove_class(gtk_widget_get_style_context(dialog->hor_intensity_entry), "red"); else gtk_style_context_add_class(gtk_widget_get_style_context(dialog->hor_intensity_entry), "red"); if (abs(ok3) > 0) gtk_style_context_remove_class(gtk_widget_get_style_context(dialog->ver_intensity_entry), "red"); else gtk_style_context_add_class(gtk_widget_get_style_context(dialog->ver_intensity_entry), "red"); // if both are zeroes, that's fine if (ok2 < 0) ok2 = 0; if (ok3 < 0) ok3 = 0; if (ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok7) gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, TRUE); else gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE); return; }
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; if(!self || !(self->data)) return; GtkListStore *store; GtkTreeIter iter; GtkWidget *view = GTK_WIDGET(((dt_lib_modulelist_t *)self->data)->tree); GtkCellRenderer *pix_renderer, *fav_renderer, *text_renderer; GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(view); gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } store = gtk_list_store_new(NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_POINTER); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref(store); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_MODULE, _lib_modulelist_gui_sort, NULL, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_MODULE, GTK_SORT_ASCENDING); pix_renderer = gtk_cell_renderer_pixbuf_new(); g_object_set(pix_renderer, "cell-background-rgba", &color, NULL); fav_renderer = gtk_cell_renderer_pixbuf_new(); cairo_surface_t *fav_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ICON_SIZE, ICON_SIZE); cairo_t *fav_cr = cairo_create(fav_cst); cairo_set_source_rgb(fav_cr, 0.7, 0.7, 0.7); dtgtk_cairo_paint_modulegroup_favorites(fav_cr, 0, 0, ICON_SIZE, ICON_SIZE, 0); cairo_destroy(fav_cr); guchar *data = cairo_image_surface_get_data(fav_cst); dt_draw_cairo_to_gdk_pixbuf(data, ICON_SIZE, ICON_SIZE); ((dt_lib_modulelist_t *)self->data)->fav_pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, ICON_SIZE, ICON_SIZE, cairo_image_surface_get_stride(fav_cst), NULL, NULL); g_object_set(fav_renderer, "cell-background-rgba", &color, NULL); g_object_set(fav_renderer, "width", gdk_pixbuf_get_width(((dt_lib_modulelist_t *)self->data)->fav_pixbuf), NULL); text_renderer = gtk_cell_renderer_text_new(); g_object_set(text_renderer, "cell-background-rgba", &color, NULL); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view), FALSE); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); GtkTreeViewColumn *col; col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 0, "favorite", fav_renderer, favorite_renderer_function, NULL, NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 1); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 1, "image", pix_renderer, image_renderer_function, NULL, NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 2, "name", text_renderer, text_renderer_function, NULL, NULL); /* go thru list of iop modules and add them to the list */ GList *modules = g_list_last(darktable.iop); char datadir[PATH_MAX] = { 0 }; dt_loc_get_datadir(datadir, sizeof(datadir)); while(modules) { dt_iop_module_so_t *module = (dt_iop_module_so_t *)(modules->data); if(!dt_iop_so_is_hidden(module) && !(module->flags() & IOP_FLAGS_DEPRECATED)) { GdkPixbuf *pixbuf; char filename[PATH_MAX] = { 0 }; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.svg", datadir, module->op); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.svg", datadir); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.png", datadir); pixbuf = load_image(filename); if(pixbuf) goto end; // wow, we could neither load the SVG nor the PNG files. something is f****d up. pixbuf = gdk_pixbuf_new_from_data(fallback_pixel, GDK_COLORSPACE_RGB, TRUE, 8, 1, 1, 4, NULL, NULL); end: gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, COL_IMAGE, pixbuf, COL_MODULE, module, -1); g_object_unref(pixbuf); } modules = g_list_previous(modules); } }
GtkWidget * reader_window_new(GtkApplication *application, CainteoirSettings *settings, CainteoirSpeechSynthesizers *synthesizers, const gchar *filename) { ReaderWindow *reader = READER_WINDOW(g_object_new(READER_TYPE_WINDOW, "application", application, nullptr)); ReaderWindowPrivate *priv = READER_WINDOW_PRIVATE(reader); priv->self = GTK_WIDGET(reader); priv->settings = CAINTEOIR_SETTINGS(g_object_ref(G_OBJECT(settings))); priv->tts = CAINTEOIR_SPEECH_SYNTHESIZERS(g_object_ref(G_OBJECT(synthesizers))); priv->application = READER_APPLICATION(application); gtk_window_set_default_size(GTK_WINDOW(reader), INDEX_PANE_WIDTH + DOCUMENT_PANE_WIDTH + 5, 300); gtk_window_set_title(GTK_WINDOW(reader), i18n("Cainteoir Text-to-Speech")); GtkWidget *layout = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(reader), layout); priv->header = gtk_header_bar_new(); gtk_header_bar_set_title(GTK_HEADER_BAR(priv->header), i18n("Cainteoir Text-to-Speech")); if (cainteoir_settings_get_boolean(priv->settings, "window", "have-csd", TRUE)) { // Use client-side decorations (e.g. on Gnome Shell and Unity) ... gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(priv->header), TRUE); gtk_window_set_titlebar(GTK_WINDOW(reader), priv->header); } else { // Don't use client-side decorations (e.g. on KDE) ... gtk_box_pack_start(GTK_BOX(layout), priv->header, FALSE, FALSE, 0); } priv->actions = create_action_group(priv); gtk_widget_insert_action_group(GTK_WIDGET(reader), "cainteoir", G_ACTION_GROUP(priv->actions)); priv->view = reader_document_view_new(priv->settings); gtk_box_pack_start(GTK_BOX(layout), priv->view, TRUE, TRUE, 0); reader_document_view_set_index_pane_close_action_name(READER_DOCUMENT_VIEW(priv->view), "cainteoir.side-pane"); GtkWidget *bottombar = gtk_toolbar_new(); gtk_widget_set_size_request(bottombar, -1, 45); gtk_style_context_add_class(gtk_widget_get_style_context(bottombar), "bottombar"); gtk_box_pack_start(GTK_BOX(layout), bottombar, FALSE, FALSE, 0); GtkToolItem *record = gtk_tool_button_new(gtk_image_new_from_icon_name("media-record-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR), nullptr); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), record, -1); gtk_actionable_set_action_name(GTK_ACTIONABLE(record), "cainteoir.record"); priv->play_stop = gtk_tool_button_new(nullptr, nullptr); gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(priv->play_stop), "media-playback-start-symbolic"); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), priv->play_stop, -1); gtk_actionable_set_action_name(GTK_ACTIONABLE(priv->play_stop), "cainteoir.play-stop"); GtkToolItem *open = gtk_tool_button_new(gtk_image_new_from_icon_name("document-open-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR), nullptr); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), open, -1); gtk_actionable_set_action_name(GTK_ACTIONABLE(open), "cainteoir.open"); GtkToolItem *timebar = gtk_tool_item_new(); gtk_tool_item_set_expand(GTK_TOOL_ITEM(timebar), TRUE); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), timebar, -1); priv->timebar = cainteoir_timebar_new(); gtk_style_context_add_class(gtk_widget_get_style_context(priv->timebar), "timebar"); gtk_container_add(GTK_CONTAINER(timebar), priv->timebar); priv->previous = gtk_button_new(); gtk_button_set_image(GTK_BUTTON(priv->previous), gtk_image_new_from_icon_name("go-previous-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR)); gtk_header_bar_pack_start(GTK_HEADER_BAR(priv->header), priv->previous); gtk_actionable_set_action_name(GTK_ACTIONABLE(priv->previous), "cainteoir.view-previous"); GtkWidget *menu_button = gtk_menu_button_new(); gtk_button_set_image(GTK_BUTTON(menu_button), gtk_image_new_from_icon_name(HAMBURGER_MENU_ICON, GTK_ICON_SIZE_SMALL_TOOLBAR)); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menu_button), create_main_menu()); gtk_header_bar_pack_end(GTK_HEADER_BAR(priv->header), menu_button); g_signal_connect(reader, "window-state-event", G_CALLBACK(on_window_state_changed), priv->settings); g_signal_connect(reader, "delete_event", G_CALLBACK(on_window_delete), priv); g_signal_connect(reader, "show", G_CALLBACK(on_window_show), priv); g_signal_connect(priv->tts, "speaking", G_CALLBACK(on_speaking), priv); g_signal_connect(priv->tts, "text-range-changed", G_CALLBACK(on_text_range_changed), priv); gtk_window_resize(GTK_WINDOW(reader), cainteoir_settings_get_integer(priv->settings, "window", "width", 700), cainteoir_settings_get_integer(priv->settings, "window", "height", 445)); gtk_window_move(GTK_WINDOW(reader), cainteoir_settings_get_integer(priv->settings, "window", "left", 0), cainteoir_settings_get_integer(priv->settings, "window", "top", 0)); if (cainteoir_settings_get_boolean(priv->settings, "window", "maximized", FALSE)) gtk_window_maximize(GTK_WINDOW(reader)); if (filename) reader_window_load_document(reader, filename); else { gchar *prev_filename = cainteoir_settings_get_string(priv->settings, "document", "filename", nullptr); if (prev_filename) { reader_window_load_document(reader, prev_filename); g_free(prev_filename); } } gchar *anchor = cainteoir_settings_get_string(priv->settings, "highlight", "anchor", "none"); if (anchor) { if (!strcmp(anchor, "top")) reader_window_set_highlight_anchor(reader, GTK_ALIGN_START); else if (!strcmp(anchor, "middle")) reader_window_set_highlight_anchor(reader, GTK_ALIGN_CENTER); else if (!strcmp(anchor, "bottom")) reader_window_set_highlight_anchor(reader, GTK_ALIGN_END); g_free(anchor); } return GTK_WIDGET(reader); }
static gboolean gtk_color_swatch_render_overlay (GtkCssGadget *gadget, cairo_t *cr, int x, int y, int width, int height, gpointer data) { GtkWidget *widget; GtkColorSwatch *swatch; GtkStyleContext *context; GtkStateFlags state; GtkIconTheme *theme; GtkIconInfo *icon_info = NULL; gint scale; widget = gtk_css_gadget_get_owner (gadget); swatch = GTK_COLOR_SWATCH (widget); theme = gtk_icon_theme_get_default (); context = gtk_widget_get_style_context (widget); state = gtk_style_context_get_state (context); scale = gtk_widget_get_scale_factor (widget); if (swatch->priv->icon) { icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, swatch->priv->icon, PIXBUF_SIZE, scale, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); } else if ((state & GTK_STATE_FLAG_SELECTED) != 0) { GIcon *gicon; gicon = g_themed_icon_new ("object-select-symbolic"); /* fallback for themes that don't have object-select-symbolic */ g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply"); icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, gicon, PIXBUF_SIZE, scale, GTK_ICON_LOOKUP_USE_BUILTIN); g_object_unref (gicon); } /* now draw the overlay image */ if (icon_info != NULL) { GdkPixbuf *pixbuf; pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL); if (pixbuf != NULL) { cairo_surface_t *surface; surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (widget)); gtk_render_icon_surface (context, cr, surface, x, y); cairo_surface_destroy (surface); g_object_unref (pixbuf); } g_object_unref (icon_info); } return FALSE; }
void pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme) { GtkIconFactory *icon_factory; gsize i; GtkWidget *win; if (theme != NULL) { purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", purple_theme_get_name(PURPLE_THEME(theme))); purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", purple_theme_get_dir(PURPLE_THEME(theme))); } else { purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", ""); purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", ""); } icon_factory = gtk_icon_factory_new(); gtk_icon_factory_add_default(icon_factory); win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_realize(win); /* All non-sized icons */ for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) { GtkIconSource *source; GtkIconSet *iconset; gchar *filename; if (stock_icons[i].dir == NULL) { /* GTK+ Stock icon */ iconset = gtk_style_context_lookup_icon_set(gtk_widget_get_style_context(win), stock_icons[i].filename); } else { filename = find_file(stock_icons[i].dir, stock_icons[i].filename); if (filename == NULL) continue; source = gtk_icon_source_new(); gtk_icon_source_set_filename(source, filename); gtk_icon_source_set_direction_wildcarded(source, TRUE); gtk_icon_source_set_size_wildcarded(source, TRUE); gtk_icon_source_set_state_wildcarded(source, TRUE); iconset = gtk_icon_set_new(); gtk_icon_set_add_source(iconset, source); gtk_icon_source_free(source); g_free(filename); } gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); gtk_icon_set_unref(iconset); } /* All non-status sized icons */ for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++) { GtkIconSet *iconset = gtk_icon_set_new(); #define ADD_SIZED_ICON(name, size) \ if (sized_stock_icons[i].name) \ add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE); ADD_SIZED_ICON(microscopic, "11"); ADD_SIZED_ICON(extra_small, "16"); ADD_SIZED_ICON(small, "22"); ADD_SIZED_ICON(medium, "32"); ADD_SIZED_ICON(large, "48"); ADD_SIZED_ICON(huge, "64"); #undef ADD_SIZED_ICON gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset); gtk_icon_set_unref(iconset); } gtk_widget_destroy(win); g_object_unref(G_OBJECT(icon_factory)); reload_settings(); }
static void gtk_level_bar_draw_fill_discrete (GtkLevelBar *self, cairo_t *cr, gboolean inverted, cairo_rectangle_int_t *fill_area) { GtkWidget *widget = GTK_WIDGET (self); GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStateFlags flags = gtk_widget_get_state_flags (widget); gint num_blocks, num_filled, idx; gint block_width, block_height; gint block_draw_width, block_draw_height; GtkBorder block_margin; cairo_rectangle_int_t block_area; gtk_level_bar_get_min_block_size (self, &block_width, &block_height); block_area = *fill_area; num_blocks = gtk_level_bar_get_num_blocks (self); num_filled = (gint) round (self->priv->cur_value) - (gint) round (self->priv->min_value); if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) block_width = MAX (block_width, (gint) floor (block_area.width / num_blocks)); else block_height = MAX (block_height, (gint) floor (block_area.height / num_blocks)); gtk_style_context_save (context); gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK); gtk_style_context_get_margin (context, flags, &block_margin); block_draw_width = block_width - block_margin.left - block_margin.right; block_draw_height = block_height - block_margin.top - block_margin.bottom; if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) { block_draw_height = MAX (block_draw_height, block_area.height - block_margin.top - block_margin.bottom); block_area.y += block_margin.top; if (inverted) block_area.x += block_area.width - block_draw_width; } else { block_draw_width = MAX (block_draw_width, block_area.width - block_margin.left - block_margin.right); block_area.x += block_margin.left; if (inverted) block_area.y += block_area.height - block_draw_height; } for (idx = 0; idx < num_blocks; idx++) { if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) { if (inverted) block_area.x -= block_margin.right; else block_area.x += block_margin.left; } else { if (inverted) block_area.y -= block_margin.bottom; else block_area.y += block_margin.top; } if (idx > num_filled - 1) gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK); gtk_render_background (context, cr, block_area.x, block_area.y, block_draw_width, block_draw_height); gtk_render_frame (context, cr, block_area.x, block_area.y, block_draw_width, block_draw_height); if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) { if (inverted) block_area.x -= block_draw_width + block_margin.left; else block_area.x += block_draw_width + block_margin.right; } else { if (inverted) block_area.y -= block_draw_height + block_margin.top; else block_area.y += block_draw_height + block_margin.bottom; } } gtk_style_context_restore (context); }
static void add_row (NetDeviceEthernet *device, NMConnection *connection) { GtkWidget *row; GtkWidget *widget; GtkWidget *box; GtkWidget *details; NMDevice *nmdev; NMActiveConnection *aconn; gboolean active; GtkWidget *image; active = FALSE; nmdev = net_device_get_nm_device (NET_DEVICE (device)); aconn = nm_device_get_active_connection (nmdev); if (aconn) { const gchar *path1, *path2; path1 = nm_active_connection_get_connection (aconn); path2 = nm_connection_get_path (connection); active = g_strcmp0 (path1, path2) == 0; } row = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (row), box, FALSE, TRUE, 0); widget = gtk_label_new (nm_connection_get_id (connection)); gtk_widget_set_margin_start (widget, 12); gtk_widget_set_margin_end (widget, 12); gtk_widget_set_margin_top (widget, 12); gtk_widget_set_margin_bottom (widget, 12); gtk_box_pack_start (GTK_BOX (box), widget, FALSE, TRUE, 0); if (active) { widget = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU); gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); gtk_widget_set_valign (widget, GTK_ALIGN_CENTER); gtk_box_pack_start (GTK_BOX (box), widget, FALSE, TRUE, 0); details = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (details), 10); gtk_grid_set_column_spacing (GTK_GRID (details), 10); gtk_box_pack_start (GTK_BOX (row), details, FALSE, TRUE, 0); add_details (details, nmdev, connection); } /* filler */ widget = gtk_label_new (""); gtk_widget_set_hexpand (widget, TRUE); gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 0); image = gtk_image_new_from_icon_name ("emblem-system-symbolic", GTK_ICON_SIZE_MENU); gtk_widget_show (image); widget = gtk_button_new (); gtk_style_context_add_class (gtk_widget_get_style_context (widget), "image-button"); gtk_widget_set_margin_start (widget, 12); gtk_widget_set_margin_end (widget, 12); gtk_widget_set_margin_top (widget, 12); gtk_widget_set_margin_bottom (widget, 12); gtk_widget_show (widget); gtk_container_add (GTK_CONTAINER (widget), image); gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); gtk_widget_set_valign (widget, GTK_ALIGN_CENTER); atk_object_set_name (gtk_widget_get_accessible (widget), _("Options…")); gtk_box_pack_start (GTK_BOX (box), widget, FALSE, TRUE, 0); g_object_set_data (G_OBJECT (row), "edit", widget); g_object_set_data (G_OBJECT (widget), "row", row); g_signal_connect (widget, "clicked", G_CALLBACK (show_details_for_row), device); gtk_widget_show_all (row); g_object_set_data (G_OBJECT (row), "connection", connection); gtk_container_add (GTK_CONTAINER (device->list), row); }
static void fg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) { GtkStyleContext* sc = gtk_widget_get_style_context(widget); gtk_style_context_get_color(sc, state, &gdkRGBA); }
static void build_ui (EmerillonWindow *self) { GtkAction *action; GtkWidget *vbox; GtkWidget *menubar; GtkToolItem *throbber; GtkWidget *viewport; GtkWidget *hpaned; GtkWidget *embed_view; ClutterActor *scale; GError *error = NULL; /* Action entries. */ self->priv->main_actions = gtk_action_group_new ("MenuActionsWindow"); gtk_action_group_set_translation_domain (self->priv->main_actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (self->priv->main_actions, action_entries, G_N_ELEMENTS (action_entries), self); /* Toggle entries. */ gtk_action_group_add_toggle_actions (self->priv->main_actions, toggle_entries, G_N_ELEMENTS (toggle_entries), self); /* Radio entries. */ gtk_action_group_add_radio_actions (self->priv->main_actions, radio_entries, G_N_ELEMENTS (radio_entries), 0, G_CALLBACK (cmd_map_change_map), self); /* Short labels. */ action = gtk_action_group_get_action (self->priv->main_actions, "ViewZoomIn"); g_object_set (action, "short_label", _("In"), NULL); action = gtk_action_group_get_action (self->priv->main_actions, "ViewZoomOut"); g_object_set (action, "short_label", _("Out"), NULL); /* UI manager. */ self->priv->ui_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (self->priv->ui_manager, self->priv->main_actions, 0); if (!gtk_ui_manager_add_ui_from_file (self->priv->ui_manager, EMERILLON_DATADIR "/emerillon-ui.xml", &error)) { g_warning ("building menus failed: %s", error->message); g_error_free (error); return; } g_signal_connect (self->priv->ui_manager, "connect_proxy", G_CALLBACK (connect_proxy_cb), self); g_signal_connect (self->priv->ui_manager, "disconnect_proxy", G_CALLBACK (disconnect_proxy_cb), self); gtk_window_add_accel_group (GTK_WINDOW (self), gtk_ui_manager_get_accel_group (self->priv->ui_manager)); /* Main box. */ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (self), vbox); gtk_widget_show (vbox); /* Menu. */ menubar = gtk_ui_manager_get_widget (self->priv->ui_manager, "/MainMenu"); g_assert (GTK_IS_WIDGET (menubar)); gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0); gtk_widget_show (menubar); /* Toolbar. */ self->priv->toolbar = gtk_ui_manager_get_widget (self->priv->ui_manager, "/Toolbar"); gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->toolbar), "primary-toolbar"); self->priv->throbber = gtk_spinner_new (); throbber = gtk_tool_item_new (); gtk_container_add (GTK_CONTAINER (throbber), self->priv->throbber); gtk_widget_show (GTK_WIDGET (self->priv->throbber)); gtk_widget_show (GTK_WIDGET (throbber)); gtk_toolbar_insert (GTK_TOOLBAR (self->priv->toolbar), throbber, -1); gtk_box_pack_start (GTK_BOX (vbox), self->priv->toolbar, FALSE, FALSE, 0); gtk_widget_show (self->priv->toolbar); /* Statusbar. */ self->priv->statusbar = gtk_statusbar_new (); gtk_box_pack_end (GTK_BOX (vbox), GTK_WIDGET (self->priv->statusbar), FALSE, FALSE, 0); gtk_widget_show (self->priv->statusbar); self->priv->tooltip_message_context_id = gtk_statusbar_get_context_id ( GTK_STATUSBAR (self->priv->statusbar), "tooltip-message"); /* Viewport. */ viewport = gtk_frame_new (NULL); /* Map. */ embed_view = gtk_champlain_embed_new (); gtk_container_add (GTK_CONTAINER (viewport), embed_view); /* FIXME: workaround for a champlain-gtk bug, replace with _show(). */ gtk_widget_show_all (embed_view); self->priv->view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (embed_view)); g_signal_connect (self->priv->view, "notify::zoom-level", G_CALLBACK (zoom_changed_cb), self); g_signal_connect (self->priv->view, "notify::map-source", G_CALLBACK (zoom_changed_cb), self); g_signal_connect (self->priv->view, "notify::state", G_CALLBACK (state_changed_cb), self); g_object_set (self->priv->view, "zoom-level", 1, "kinetic-mode", TRUE, NULL); champlain_view_center_on (self->priv->view, 40, 0); scale = champlain_scale_new (); champlain_scale_connect_view (CHAMPLAIN_SCALE (scale), self->priv->view); /* align to the bottom left */ champlain_view_bin_layout_add (self->priv->view, scale, CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END); /* Sidebar. */ self->priv->sidebar = emerillon_sidebar_new (); gtk_widget_set_size_request (self->priv->sidebar, 200, -1); /* Horizontal pane. */ hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL); gtk_paned_pack1 (GTK_PANED (hpaned), self->priv->sidebar, FALSE, FALSE); gtk_paned_pack2 (GTK_PANED (hpaned), viewport, TRUE, FALSE); gtk_widget_show (self->priv->sidebar); gtk_widget_show (viewport); g_signal_connect_after (self->priv->sidebar, "show", G_CALLBACK (sidebar_visibility_changed_cb), self); g_signal_connect_after (self->priv->sidebar, "hide", G_CALLBACK (sidebar_visibility_changed_cb), self); gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0); gtk_widget_show (hpaned); update_ui_visibility (self); }