1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 05:48:01 +01:00

WPrefs: Add ability to set integer values in Expert panel

Previously, only boolean values could be changed using the Expert panel.
This patch adds the ability to change integer values.  A new class,
OPTION_WMAKER_INT, is added.  When this class is used, a textfield and two
buttons (up and down) appear instead of a checkbox.  Users can either type
the integer value or increment/decrement it using the arrows.
This commit is contained in:
Doug Torrance
2015-06-23 19:34:59 -05:00
committed by Carlos R. Mafra
parent 443a08ea16
commit fa821810cf

View File

@@ -33,7 +33,8 @@ static const struct {
enum {
OPTION_WMAKER,
OPTION_WMAKER_ARRAY,
OPTION_USERDEF
OPTION_USERDEF,
OPTION_WMAKER_INT
} class;
const char *op_name; /* The identifier for the option in the config file */
@@ -96,6 +97,7 @@ static const struct {
};
typedef struct _Panel {
WMBox *box;
char *sectionName;
@@ -108,10 +110,37 @@ typedef struct _Panel {
WMButton *swi[wlengthof_nocheck(expert_options)];
WMTextField *textfield[wlengthof_nocheck(expert_options)];
} _Panel;
#define ICON_FILE "expert"
static void changeIntTextfield(void *data, int delta)
{
WMTextField *textfield;
char *text;
int value;
textfield = (WMTextField *)data;
text = WMGetTextFieldText(textfield);
value = atoi(text);
value += delta;
sprintf(text, "%d", value);
WMSetTextFieldText(textfield, text);
}
static void downButtonCallback(WMWidget *self, void *data)
{
(void) self;
changeIntTextfield(data, -1);
}
static void upButtonCallback(WMWidget *self, void *data)
{
(void) self;
changeIntTextfield(data, 1);
}
static void createPanel(Panel *p)
{
@@ -137,11 +166,13 @@ static void createPanel(Panel *p)
udb = WMGetStandardUserDefaults();
for (i = 0; i < wlengthof(expert_options); i++) {
panel->swi[i] = WMCreateSwitchButton(f);
WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
WMMoveWidget(panel->swi[i], 5, 5 + i * 25);
if (expert_options[i].class != OPTION_WMAKER_INT) {
panel->swi[i] = WMCreateSwitchButton(f);
WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
WMMoveWidget(panel->swi[i], 5, 5 + i * 25);
WMSetButtonText(panel->swi[i], _(expert_options[i].label));
WMSetButtonText(panel->swi[i], _(expert_options[i].label));
}
switch (expert_options[i].class) {
case OPTION_WMAKER:
@@ -163,6 +194,49 @@ static void createPanel(Panel *p)
state = WMGetUDBoolForKey(udb, expert_options[i].op_name);
break;
case OPTION_WMAKER_INT:
{
char tmp[10];
WMButton *up, *down;
WMLabel *label;
panel->textfield[i] = WMCreateTextField(f);
WMResizeWidget(panel->textfield[i], 41, 20);
WMMoveWidget(panel->textfield[i], 22, 7 + i * 25);
down = WMCreateCommandButton(f);
WMSetButtonImage(down, WMGetSystemPixmap(WMWidgetScreen(down), WSIArrowDown));
WMSetButtonAltImage(down,
WMGetSystemPixmap(WMWidgetScreen(down), WSIHighlightedArrowDown));
WMSetButtonImagePosition(down, WIPImageOnly);
WMSetButtonAction(down, downButtonCallback, panel->textfield[i]);
WMResizeWidget(down, 16, 16);
WMMoveWidget(down, 5, 9 + i * 25);
up = WMCreateCommandButton(f);
WMSetButtonImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIArrowUp));
WMSetButtonAltImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIHighlightedArrowUp));
WMSetButtonImagePosition(up, WIPImageOnly);
WMSetButtonAction(up, upButtonCallback, panel->textfield[i]);
WMResizeWidget(up, 16, 16);
WMMoveWidget(up, 64, 9 + i * 25);
label = WMCreateLabel(f);
WMSetLabelText(label, _(expert_options[i].label));
WMResizeWidget(label, FRAME_WIDTH - 99, 25);
WMMoveWidget(label, 85, 5 + i * 25);
if (GetStringForKey(expert_options[i].op_name))
state = GetIntegerForKey(expert_options[i].op_name);
else
state = expert_options[i].def_state;
sprintf(tmp, "%d", state);
WMSetTextFieldText(panel->textfield[i], tmp);
break;
}
default:
#ifdef DEBUG
wwarning("export_options[%d].class = %d, this should not happen\n",
@@ -171,7 +245,8 @@ static void createPanel(Panel *p)
state = expert_options[i].def_state;
break;
}
WMSetButtonSelected(panel->swi[i], state);
if (expert_options[i].class != OPTION_WMAKER_INT)
WMSetButtonSelected(panel->swi[i], state);
}
WMMapSubwidgets(panel->box);
@@ -204,6 +279,18 @@ static void storeDefaults(_Panel *panel)
case OPTION_USERDEF:
WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
break;
case OPTION_WMAKER_INT:
{
char *text;
int value;
text = WMGetTextFieldText(panel->textfield[i]);
value = atoi(text);
SetIntegerForKey(value, expert_options[i].op_name);
break;
}
}
}
}