diff --git a/src/dialogs/settings/clipboard.c b/src/dialogs/settings/clipboard.c index dcfd6ce..ba6d493 100644 --- a/src/dialogs/settings/clipboard.c +++ b/src/dialogs/settings/clipboard.c @@ -32,16 +32,112 @@ * */ - #include + #include "private.h" #include #include +/*--[ Constants ]------------------------------------------------------------------------------------*/ + + enum { + COPY_SETTINGS, + PASTE_SETTINGS, + HTML_SETTINGS, + + GRID_COUNT + }; + + static const struct ToggleButtonDefinition toggles[] = { + { + .left = 0, + .top = 0, + .width = 1, + .grid = COPY_SETTINGS, + .id = LIB3270_TOGGLE_RECTANGLE_SELECT, + }, + + { + .left = 2, + .top = 0, + .width = 1, + .grid = COPY_SETTINGS, + .id = LIB3270_TOGGLE_MARGINED_PASTE, + }, + + { + .left = 0, + .top = 0, + .width = 1, + .grid = PASTE_SETTINGS, + .id = LIB3270_TOGGLE_SMART_PASTE, + } + + }; + + static const struct ComboBoxDefinition combos[] = { + + { + .grid = HTML_SETTINGS, + .left = 0, + .top = 0, + .width = 1, + .height = 1, + .label = N_("Font"), +// .tooltip = + + .n_columns = 2, + .types = (const GType []) { + G_TYPE_STRING, + G_TYPE_UINT + } + + }, + + { + .grid = HTML_SETTINGS, + .left = 0, + .top = 1, + .width = 1, + .height = 1, + .label = N_("Color theme"), +// .tooltip = + + .n_columns = 1, + .types = (const GType []) { + G_TYPE_STRING + } + + }, + + { + .grid = COPY_SETTINGS, + .left = 0, + .top = 1, + .width = 1, + .height = 1, + .label = N_("Format"), +// .tooltip = + + .n_columns = 2, + .types = (const GType []) { + G_TYPE_STRING, + G_TYPE_UINT + } + + }, + + }; + /*--[ Globals ]--------------------------------------------------------------------------------------*/ typedef struct _V3270ClipboardSettings { V3270Settings parent; + struct { + GtkToggleButton * toggles[G_N_ELEMENTS(toggles)]; ///< @brief Toggle checks. + GtkComboBox * combos[G_N_ELEMENTS(combos)]; ///< @brief Combo-boxes. + } input; + } V3270ClipboardSettings; @@ -70,6 +166,71 @@ static void V3270ClipboardSettings_class_init(V3270ClipboardSettingsClass *klass static void V3270ClipboardSettings_init(V3270ClipboardSettings *widget) { + size_t ix; + GtkWidget * grids[GRID_COUNT]; + + // Create grids + { + static const gchar * labels[GRID_COUNT] = { + N_("Copy options"), + N_("Common paste options"), + N_("HTML Paste options") + }; + + for(ix = 0; ix < G_N_ELEMENTS(labels); ix++) { + + grids[ix] = gtk_grid_new(); + + gtk_grid_set_row_spacing(GTK_GRID(grids[ix]),6); + gtk_grid_set_column_spacing(GTK_GRID(grids[ix]),12); + + gtk_grid_attach( + GTK_GRID(widget), + v3270_dialog_create_frame(grids[ix],g_dgettext(PACKAGE_NAME,labels[ix])), + 0,ix,1,1 + ); + + } + + } + + v3270_settings_create_toggle_buttons(toggles, G_N_ELEMENTS(toggles), grids, widget->input.toggles); + v3270_settings_create_combos(combos, G_N_ELEMENTS(combos), grids, widget->input.combos); + + // Setup combos + { + GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); + GtkTreeIter iter; + GtkListStore * model; + + for(ix = 0; ix < G_N_ELEMENTS(combos); ix++) { + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combos[ix]), text_renderer, TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combos[ix]), text_renderer, "text", 0, NULL); + } + + // Copy format combo + static const gchar * copy_formats[] = { + N_("Plain text only"), + N_("Complete with terminal attributes") + }; + + model = GTK_LIST_STORE(gtk_combo_box_get_model(widget->input.combos[2])); + for(ix = 0;ix < G_N_ELEMENTS(copy_formats); ix++) { + + gtk_list_store_append(model, &iter); + gtk_list_store_set( + model, + &iter, + 0, g_dgettext(PACKAGE_NAME, copy_formats[ix]), + 1, (guint) ix, + -1 + ); + + } + + + } + } GtkWidget * v3270_clipboard_settings_new() { @@ -82,11 +243,20 @@ GtkWidget * v3270_clipboard_settings_new() { return GTK_WIDGET(settings); } -static void apply(GtkWidget *w, GtkWidget *terminal) { +static void load(GtkWidget *w, GtkWidget *terminal) { + + V3270ClipboardSettings *widget = (V3270ClipboardSettings *) w; + + v3270_settings_load_toggle_buttons(toggles, G_N_ELEMENTS(toggles), terminal, widget->input.toggles); } -static void load(GtkWidget *w, GtkWidget *terminal) { +static void apply(GtkWidget *w, GtkWidget *terminal) { + + V3270ClipboardSettings *widget = (V3270ClipboardSettings *) w; + + v3270_settings_apply_toggle_buttons(toggles,G_N_ELEMENTS(toggles),terminal,widget->input.toggles); } + diff --git a/src/dialogs/settings/host.c b/src/dialogs/settings/host.c index 9d75c03..bac3312 100644 --- a/src/dialogs/settings/host.c +++ b/src/dialogs/settings/host.c @@ -766,13 +766,7 @@ static void apply(GtkWidget *w, GtkWidget *terminal) } // Apply toggles - size_t toggle; - - for(toggle = 0; toggle < G_N_ELEMENTS(toggleList); toggle++) - { - if(widget->input.toggles[toggle]) - v3270_set_toggle(terminal, toggleList[toggle].id, gtk_toggle_button_get_active(widget->input.toggles[toggle])); - } + v3270_settings_apply_toggle_buttons(toggleList,G_N_ELEMENTS(toggleList),terminal,widget->input.toggles); // Apply oversize lib3270_set_oversize(hSession,gtk_entry_get_text(widget->input.entry[ENTRY_OVERSIZE])); @@ -900,13 +894,7 @@ static void load(GtkWidget *w, GtkWidget *terminal) } // Load toggles - size_t toggle; - - for(toggle = 0; toggle < G_N_ELEMENTS(toggleList); toggle++) - { - if(widget->input.toggles[toggle]) - gtk_toggle_button_set_active(widget->input.toggles[toggle],v3270_get_toggle(terminal,toggleList[toggle].id)); - } + v3270_settings_load_toggle_buttons(toggleList, G_N_ELEMENTS(toggleList), terminal, widget->input.toggles); // Load oversize const char * oversize = lib3270_get_oversize(hSession); diff --git a/src/dialogs/settings/private.h b/src/dialogs/settings/private.h index 099f0e9..5e2b939 100644 --- a/src/dialogs/settings/private.h +++ b/src/dialogs/settings/private.h @@ -44,6 +44,8 @@ }; G_GNUC_INTERNAL void v3270_settings_create_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget **grids, GtkToggleButton **toggles); + G_GNUC_INTERNAL void v3270_settings_load_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles); + G_GNUC_INTERNAL void v3270_settings_apply_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles); /// @brief Entry field factory. struct EntryFieldDefinition { @@ -58,4 +60,18 @@ G_GNUC_INTERNAL void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries); + /// @brief Combo Box factory + struct ComboBoxDefinition { + + ENTRY_FIELD_HEAD + + unsigned short grid; + + gint n_columns; + const GType *types; + + }; + + G_GNUC_INTERNAL void v3270_settings_create_combos(const struct ComboBoxDefinition * definitions, size_t length, GtkWidget **grids, GtkComboBox **combos); + #endif // PRIVATE_H_INCLUDED diff --git a/src/dialogs/settings/tools.c b/src/dialogs/settings/tools.c index ac08b38..1fc2a02 100644 --- a/src/dialogs/settings/tools.c +++ b/src/dialogs/settings/tools.c @@ -58,6 +58,32 @@ } + void v3270_settings_load_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles) { + + size_t toggle; + + for(toggle = 0; toggle < length; toggle++) { + + if(toggles[toggle]) + gtk_toggle_button_set_active(toggles[toggle],v3270_get_toggle(terminal,definitions[toggle].id)); + + } + + } + + void v3270_settings_apply_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget *terminal, GtkToggleButton **toggles) { + + size_t toggle; + + for(toggle = 0; toggle < length; toggle++) { + + if(toggles[toggle]) + v3270_set_toggle(terminal, definitions[toggle].id, gtk_toggle_button_get_active(toggles[toggle])); + + } + + } + void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries) { size_t entry; @@ -78,3 +104,31 @@ } + void v3270_settings_create_combos(const struct ComboBoxDefinition * definitions, size_t length, GtkWidget **grids, GtkComboBox **combos) { + + size_t combo; + + for(combo = 0; combo < length; combo++) { + + if(definitions[combo].n_columns) { + + GtkTreeModel * model = GTK_TREE_MODEL(gtk_list_store_newv(definitions[combo].n_columns,(GType *) definitions[combo].types)); + combos[combo] = GTK_COMBO_BOX(gtk_combo_box_new_with_model(model)); + + } else { + + combos[combo] = GTK_COMBO_BOX(gtk_combo_box_new()); + + } + + v3270_grid_attach( + GTK_GRID(grids[definitions[combo].grid]), + (struct v3270_entry_field *) & definitions[combo], + GTK_WIDGET(combos[combo]) + ); + + } + + } + + -- libgit2 0.21.2