static void clear_button(struct index_button *idxbutton, gint cell_index) { GtkEventBox *button; GtkWidget *label; idxbutton->cand_index_in_page = -1; button = idxbutton->button; label = gtk_bin_get_child(GTK_BIN(button)); gtk_label_set_text(GTK_LABEL(label), ""); scale_label(button, PANGO_SCALE_LARGE); }
static GtkEventBox* assign_cellbutton(UIMCandWinHorizontalGtk *horizontal_cwin, gint cand_index, gint display_limit) { struct index_button *idxbutton; int len; GPtrArray *buttons; buttons = horizontal_cwin->buttons; len = buttons->len; if (len <= cand_index) { GtkWidget *button; GtkWidget *label; button = gtk_event_box_new(); gtk_event_box_set_above_child(GTK_EVENT_BOX(button), TRUE); label = gtk_label_new(""); gtk_container_add(GTK_CONTAINER(button), label); scale_label(GTK_EVENT_BOX(button), PANGO_SCALE_LARGE); g_signal_connect(button, "button-press-event", G_CALLBACK(button_clicked), horizontal_cwin); #if GTK_CHECK_VERSION(2, 90, 0) g_signal_connect_after(label, "draw", G_CALLBACK(label_draw), horizontal_cwin); #else g_signal_connect_after(label, "expose-event", G_CALLBACK(label_exposed), horizontal_cwin); #endif #if GTK_CHECK_VERSION(3, 4, 0) gtk_widget_set_hexpand(button, TRUE); gtk_widget_set_vexpand(button, TRUE); gtk_grid_attach(GTK_GRID(UIM_CAND_WIN_GTK(horizontal_cwin)->view), button, cand_index, 0, 1, 1); #else gtk_table_attach_defaults(GTK_TABLE(UIM_CAND_WIN_GTK(horizontal_cwin)->view), button, cand_index, cand_index + 1, 0, 1); #endif idxbutton = g_malloc(sizeof(struct index_button)); if (idxbutton) { idxbutton->button = GTK_EVENT_BOX(button); clear_button(idxbutton, cand_index); idxbutton->cand_index_in_page = cand_index; } g_ptr_array_add(horizontal_cwin->buttons, idxbutton); } else { idxbutton = g_ptr_array_index(buttons, cand_index); idxbutton->cand_index_in_page = cand_index; } return idxbutton->button; }
static void init_screen_part_section (ZoomOptionsPrivate *priv, PangoAttrList *pango_attrs) { gboolean lens_mode; GSList *mouse_mode_group; GSList *focus_mode_group; GSList *caret_mode_group; priv->follow_mouse_radio = WID ("moveableLens"); priv->screen_part_radio = WID ("screenPart"); priv->centered_radio = WID ("centered"); priv->push_radio = WID ("push"); priv->proportional_radio = WID ("proportional"); priv->extend_beyond_checkbox = WID ("scrollAtEdges"); /* Scale the labels of the toggles */ scale_label (GTK_BIN(priv->follow_mouse_radio), pango_attrs); scale_label (GTK_BIN(priv->screen_part_radio), pango_attrs); scale_label (GTK_BIN(priv->centered_radio), pango_attrs); scale_label (GTK_BIN(priv->push_radio), pango_attrs); scale_label (GTK_BIN(priv->proportional_radio), pango_attrs); scale_label (GTK_BIN(priv->extend_beyond_checkbox), pango_attrs); lens_mode = g_settings_get_boolean (priv->settings, "lens-mode"); set_active (priv->follow_mouse_radio, lens_mode); set_active (priv->screen_part_radio, !lens_mode); mouse_mode_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->centered_radio)); focus_mode_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->push_radio)); caret_mode_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->centered_radio)); init_mouse_mode_radio_group (mouse_mode_group, priv); init_focus_mode_radio_group (focus_mode_group, priv); init_caret_mode_radio_group (caret_mode_group, priv); set_enable_screen_part_ui (priv->screen_part_radio, priv); g_settings_bind (priv->settings, "lens-mode", priv->follow_mouse_radio, "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (priv->settings, "scroll-at-edges", priv->extend_beyond_checkbox, "active", G_SETTINGS_BIND_DEFAULT); g_signal_connect (G_OBJECT (priv->screen_part_radio), "toggled", G_CALLBACK (set_enable_screen_part_ui), priv); g_signal_connect (G_OBJECT (priv->settings), "changed::mouse-tracking", G_CALLBACK (tracking_notify_cb), priv); g_signal_connect (G_OBJECT (priv->settings), "changed::focus-tracking", G_CALLBACK (tracking_notify_cb), priv); g_signal_connect (G_OBJECT (priv->settings), "changed::caret-tracking", G_CALLBACK (tracking_notify_cb), priv); }
static void update_table_button(UIMCandWinHorizontalGtk *horizontal_cwin, guint new_page) { UIMCandWinGtk *cwin; GtkTreeModel *model; GPtrArray *buttons; GtkTreeIter ti; gboolean has_next; gint display_limit, len, cand_index = 0; cwin = UIM_CAND_WIN_GTK(horizontal_cwin); if (!cwin->stores->pdata[new_page]) { return; } model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]); buttons = horizontal_cwin->buttons; display_limit = cwin->display_limit; len = buttons->len; clear_all_buttons(buttons); has_next = gtk_tree_model_get_iter_first(model, &ti); while (has_next) { gchar *heading; gchar *cand_str; GtkEventBox *button = NULL; gtk_tree_model_get(model, &ti, COLUMN_HEADING, &heading, COLUMN_CANDIDATE, &cand_str, TERMINATOR); if (cand_str != NULL) { button = assign_cellbutton(horizontal_cwin, cand_index, display_limit); if (button != NULL) { GtkWidget *label; label = gtk_bin_get_child(GTK_BIN(button)); if (heading && heading[0] != '\0') { gchar *text = g_strdup_printf("%s: %s", heading, cand_str); gtk_label_set_text(GTK_LABEL(label), text); g_free(text); } else { gtk_label_set_text(GTK_LABEL(label), cand_str); } scale_label(button, PANGO_SCALE_LARGE); } } g_free(cand_str); g_free(heading); cand_index++; has_next = gtk_tree_model_iter_next(model, &ti); } if (cand_index < len) { gint i; for (i = len - 1; i >= cand_index; i--) { struct index_button *idxbutton; idxbutton = g_ptr_array_index(buttons, i); if (idxbutton == horizontal_cwin->selected) horizontal_cwin->selected = NULL; gtk_widget_destroy(GTK_WIDGET(idxbutton->button)); g_free(idxbutton); g_ptr_array_remove_index(buttons, i); } #if !GTK_CHECK_VERSION(3, 4, 0) gtk_table_resize(GTK_TABLE(cwin->view), 1, cand_index); #endif } }
static void uim_cand_win_horizontal_gtk_init (UIMCandWinHorizontalGtk *horizontal_cwin) { gint col; GtkWidget *viewport; UIMCandWinGtk *cwin; cwin = UIM_CAND_WIN_GTK(horizontal_cwin); horizontal_cwin->buttons = g_ptr_array_new(); horizontal_cwin->selected = NULL; #if GTK_CHECK_VERSION(3, 4, 0) cwin->view = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(cwin->view), 10); #else cwin->view = gtk_table_new(1, DEFAULT_NR_CELLS, FALSE); gtk_table_set_col_spacings(GTK_TABLE(cwin->view), 10); #endif viewport = gtk_viewport_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(viewport), cwin->view); gtk_container_add(GTK_CONTAINER(cwin->scrolled_window), viewport); gtk_container_set_resize_mode(GTK_CONTAINER(viewport), GTK_RESIZE_PARENT); for (col = 0; col < DEFAULT_NR_CELLS; col++) { GtkWidget *button; GtkWidget *label; struct index_button *idxbutton; button = gtk_event_box_new(); gtk_event_box_set_above_child(GTK_EVENT_BOX(button), TRUE); label = gtk_label_new(""); gtk_container_add(GTK_CONTAINER(button), label); scale_label(GTK_EVENT_BOX(button), PANGO_SCALE_LARGE); g_signal_connect(button, "button-press-event", G_CALLBACK(button_clicked), horizontal_cwin); #if GTK_CHECK_VERSION(2, 90, 0) g_signal_connect_after(label, "draw", G_CALLBACK(label_draw), horizontal_cwin); #else g_signal_connect_after(label, "expose-event", G_CALLBACK(label_exposed), horizontal_cwin); #endif #if GTK_CHECK_VERSION(3, 4, 0) gtk_widget_set_hexpand(button, TRUE); gtk_widget_set_vexpand(button, TRUE); gtk_grid_attach(GTK_GRID(cwin->view), button, col, 0, 1, 1); #else gtk_table_attach_defaults(GTK_TABLE(cwin->view), button, col, col + 1, 0, 1); #endif idxbutton = g_malloc(sizeof(struct index_button)); if (idxbutton) { idxbutton->button = GTK_EVENT_BOX(button); clear_button(idxbutton, col); } g_ptr_array_add(horizontal_cwin->buttons, idxbutton); } gtk_widget_show_all(cwin->view); gtk_widget_show(viewport); gtk_widget_set_size_request(cwin->num_label, DEFAULT_MIN_WINDOW_WIDTH, -1); gtk_window_set_default_size(GTK_WINDOW(cwin), DEFAULT_MIN_WINDOW_WIDTH, -1); gtk_window_set_resizable(GTK_WINDOW(cwin), FALSE); }
static void zoom_options_init (ZoomOptions *self) { ZoomOptionsPrivate *priv; GtkWidget *w; PangoAttrList *pango_attrs; PangoAttribute *attr; GError *err = NULL; priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ZOOM_TYPE_OPTIONS, ZoomOptionsPrivate); priv->builder = gtk_builder_new (); gtk_builder_set_translation_domain (priv->builder, GETTEXT_PACKAGE); gtk_builder_add_from_file (priv->builder, SAGARMATHACC_UI_DIR "/zoom-options.ui", &err); if (err) { g_warning ("Could not load interface file: %s", err->message); g_error_free (err); g_object_unref (priv->builder); priv->builder = NULL; return; } priv->settings = g_settings_new ("org.sagarmatha.desktop.a11y.magnifier"); priv->application_settings = g_settings_new ("org.sagarmatha.desktop.a11y.applications"); pango_attrs = pango_attr_list_new (); attr = pango_attr_scale_new (FONT_SCALE); pango_attr_list_insert (pango_attrs, attr); /* Zoom switch */ g_settings_bind (priv->application_settings, "screen-magnifier-enabled", WID ("seeing_zoom_switch"), "active", G_SETTINGS_BIND_DEFAULT); /* Magnification factor */ w = WID ("magFactorSpinButton"); g_settings_bind (priv->settings, "mag-factor", gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (w)), "value", G_SETTINGS_BIND_DEFAULT); /* Screen position combo */ w = WID ("screen_position_combo_box"); screen_position_notify_cb (priv->settings, "screen-position", self); g_signal_connect (G_OBJECT (priv->settings), "changed::screen-position", G_CALLBACK (screen_position_notify_cb), self); g_signal_connect (G_OBJECT (w), "changed", G_CALLBACK (screen_position_combo_changed_cb), self); /* Screen part section */ init_screen_part_section (priv, pango_attrs); /* Cross hairs: show/hide ... */ w = WID ("xhairsEnabledSwitch"); g_settings_bind (priv->settings, "show-cross-hairs", w, "active", G_SETTINGS_BIND_DEFAULT); /* ... Cross hairs: color and opacity */ w = WID ("xHairsPicker"); init_xhairs_color_opacity (GTK_COLOR_BUTTON (w), priv->settings); g_signal_connect (G_OBJECT (priv->settings), "changed::cross-hairs-color", G_CALLBACK (xhairs_color_notify_cb), w); g_signal_connect (G_OBJECT (priv->settings), "changed::cross-hairs-opacity", G_CALLBACK (xhairs_opacity_notify_cb), w); g_signal_connect (G_OBJECT (w), "color-set", G_CALLBACK (xhairs_color_opacity_changed), priv); /* ... Cross hairs: thickness ... */ w = WID ("xHairsThicknessSlider"); g_settings_bind (priv->settings, "cross-hairs-thickness", gtk_range_get_adjustment (GTK_RANGE (w)), "value", G_SETTINGS_BIND_DEFAULT); /* ... Cross hairs: clip ... */ w = WID ("xHairsClipCheckbox"); scale_label (GTK_BIN(w), pango_attrs); g_settings_bind (priv->settings, "cross-hairs-clip", w, "active", G_SETTINGS_BIND_INVERT_BOOLEAN); /* ... Cross hairs: length ... */ w = WID ("xHairsLengthSlider"); xhairs_length_add_marks (GTK_SCALE (w)); g_settings_bind (priv->settings, "cross-hairs-length", gtk_range_get_adjustment (GTK_RANGE (w)), "value", G_SETTINGS_BIND_DEFAULT); /* ... Color effects ... */ w = WID ("inverseEnabledSwitch"); g_settings_bind (priv->settings, "invert-lightness", w, "active", G_SETTINGS_BIND_DEFAULT); w = WID ("brightnessSlider"); priv->brightness_slider = w; init_effects_slider (GTK_RANGE(w), priv, brightness_keys, G_CALLBACK (brightness_slider_notify_cb)); w = WID ("contrastSlider"); priv->contrast_slider = w; init_effects_slider (GTK_RANGE(w), priv, contrast_keys, G_CALLBACK (contrast_slider_notify_cb)); w = WID ("grayscale_slider"); g_settings_bind (priv->settings, "color-saturation", gtk_range_get_adjustment (GTK_RANGE (w)), "value", G_SETTINGS_BIND_DEFAULT); gtk_scale_add_mark (GTK_SCALE(w), 1.0, GTK_POS_BOTTOM, NULL); /* ... Window itself ... */ priv->dialog = WID ("magPrefsDialog"); w = WID ("closeButton"); g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (zoom_option_close_dialog_cb), priv); g_signal_connect (G_OBJECT (priv->dialog), "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL); pango_attr_list_unref (pango_attrs); }