summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gromnitsky <alexander.gromnitsky@gmail.com>2021-12-02 05:56:33 +0200
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-04-05 16:49:29 -0700
commit148a592bf5b10c5f536cb515536351d73952fc6f (patch)
tree3ea4044f7f5d058a792b4b038fcec64b84397762
parentd55f7ed9893bb74fb9d1f4cc84501928c0d52c46 (diff)
Add 'reset' button
It's very tedious to deselect multiple XLFD field names if you want to start from scratch (it's often easier to relaunch the app). Hence, a simple reset button can be handy. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--app-defaults/XFontSel7
-rw-r--r--xfontsel.c37
2 files changed, 38 insertions, 6 deletions
diff --git a/app-defaults/XFontSel b/app-defaults/XFontSel
index b0ef993..371eab1 100644
--- a/app-defaults/XFontSel
+++ b/app-defaults/XFontSel
@@ -50,8 +50,13 @@ XFontSel.cursor: left_ptr
*quitButton.left: chainLeft
*quitButton.right: chainLeft
+*resetButton.Label: reset
+*resetButton.fromHoriz: quitButton
+*resetButton.left: chainLeft
+*resetButton.right: chainLeft
+
*ownButton.Label: select
-*ownButton.fromHoriz: quitButton
+*ownButton.fromHoriz: resetButton
*ownButton.left: chainLeft
*ownButton.right: chainLeft
diff --git a/xfontsel.c b/xfontsel.c
index 2adf61d..cfa3d58 100644
--- a/xfontsel.c
+++ b/xfontsel.c
@@ -68,6 +68,7 @@ void GetFontNames(XtPointer closure);
Boolean Matches(String pattern, String fontName, Boolean fields[], int *maxfields);
Boolean DoWorkPiece(XtPointer closure);
void Quit(Widget w, XtPointer closure, XtPointer callData) _X_NORETURN;
+void Reset(Widget w, XtPointer closure, XtPointer callData);
void OwnSelection(Widget w, XtPointer closure, XtPointer callData);
void SelectField(Widget w, XtPointer closure, XtPointer callData);
void ParseFontNames(XtPointer closure);
@@ -223,6 +224,7 @@ static void ScheduleWork(XtProc proc, XtPointer closure, int priority);
static void SetCurrentFontCount(void);
static void SetNoFonts(void);
static void SetParsingFontCount(int count);
+static void reset_currentFontNameString(void);
static XtAppContext appCtx;
static int numFonts;
@@ -234,6 +236,7 @@ static FieldValueList *fieldValues[FIELD_COUNT];
static FontValues currentFont;
static int matchingFontCount;
static Boolean anyDisabled = False;
+static Widget resetButton;
static Widget ownButton;
static Widget fieldBox;
static Widget countLabel;
@@ -283,11 +286,14 @@ see 'xfontsel' manual page."
commandBox = XtCreateManagedWidget("commandBox",formWidgetClass,pane,NZ);
{
- Widget quitButton /*, ownButton , countLabel*/;
+ Widget quitButton /*, resetButton, ownButton , countLabel*/;
quitButton =
XtCreateManagedWidget("quitButton",commandWidgetClass,commandBox,NZ);
+ resetButton =
+ XtCreateManagedWidget("resetButton",commandWidgetClass,commandBox,NZ);
+
ownButton =
XtCreateManagedWidget("ownButton",toggleWidgetClass,commandBox,NZ);
@@ -295,6 +301,7 @@ see 'xfontsel' manual page."
XtCreateManagedWidget("countLabel",labelWidgetClass,commandBox,NZ);
XtAddCallback(quitButton, XtNcallback, Quit, NULL);
+ XtAddCallback(resetButton, XtNcallback, Reset, NULL);
XtAddCallback(ownButton,XtNcallback,OwnSelection,(XtPointer)True);
}
@@ -322,10 +329,7 @@ see 'xfontsel' manual page."
/* currentFontName = */
{
Arg args[1];
- currentFontNameSize = strlen(AppRes.pattern);
- if (currentFontNameSize < 128) currentFontNameSize = 128;
- currentFontNameString = XtMalloc(currentFontNameSize);
- strcpy(currentFontNameString, AppRes.pattern);
+ reset_currentFontNameString();
XtSetArg(args[0], XtNlabel, currentFontNameString);
currentFontName =
XtCreateManagedWidget("fontName",labelWidgetClass,pane,args,ONE);
@@ -910,6 +914,7 @@ static void SetNoFonts(void)
matchingFontCount = 0;
SetCurrentFontCount();
XtSetSensitive(fieldBox, False);
+ XtSetSensitive(resetButton, False);
XtSetSensitive(ownButton, False);
if (AppRes.app_defaults_version >= MIN_APP_DEFAULTS_VERSION) {
XtUnmapWidget(sampleText);
@@ -1398,6 +1403,28 @@ void Quit(Widget w, XtPointer closure, XtPointer callData)
}
+void Reset(Widget w, XtPointer closure, XtPointer callData) {
+ Arg args[1];
+ reset_currentFontNameString();
+ XtSetArg(args[0], XtNlabel, currentFontNameString);
+ XtSetValues(currentFontName, args, ONE);
+
+ for (int f = 0; f < FIELD_COUNT; f++)
+ currentFont.value_index[f] = patternFieldSpecified[f] ? 0 : -1;
+
+ SetCurrentFont(NULL);
+ EnableRemainingItems(SkipCurrentField); /* menu */
+}
+
+static void reset_currentFontNameString(void) {
+ currentFontNameSize = strlen(AppRes.pattern);
+ if (currentFontNameSize < 128) currentFontNameSize = 128;
+ XtFree(currentFontNameString);
+ currentFontNameString = XtMalloc(currentFontNameSize);
+ strcpy(currentFontNameString, AppRes.pattern);
+}
+
+
static Boolean
ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type,
XtPointer *value, unsigned long *length, int *format)