home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume19
/
xephem
/
part18
/
preferences.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-15
|
7KB
|
248 lines
/* code to support the preferences facility.
* not much now, but expected to grow.
* not all of these are necessarily settable in the Preferences mainmenu
* pulldown yet.
*/
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/ToggleB.h>
#include <Xm/CascadeB.h>
#include "astro.h"
#include "circum.h"
#include "preferences.h"
#if defined(__STDC__) || defined(__cplusplus)
#define P_(s) s
#else
#define P_(s) ()
#endif
extern void redraw_screen P_((int how_much));
extern void set_xmstring P_((Widget w, char *resource, char *txt));
extern void xe_msg P_((char *msg, int app_modal));
void pref_create_pulldown P_((Widget menu_bar));
int pref_get P_((int pref));
static void pref_algo_cb P_((Widget w, XtPointer client, XtPointer call));
static void pref_date_cb P_((Widget w, XtPointer client, XtPointer call));
static void pref_units_cb P_((Widget w, XtPointer client, XtPointer call));
#undef P_
extern char *myclass;
extern Widget toplevel_w;
#define XtD XtDisplay(toplevel_w)
/* record of preferences values */
static int prefs[NPREFS];
/* Create "Preferences" PulldownMenu.
* use the given menu_bar widget as a base.
* this is called early when the main menu bar is being built..
* initialize the prefs[] array from the initial state of the toggle buttons.
*/
void
pref_create_pulldown (menu_bar)
Widget menu_bar;
{
Widget tb1, tb2, tb3;
Widget cascade, menu_pane, pull_right;
Arg args[20];
int n;
n = 0;
menu_pane = XmCreatePulldownMenu (menu_bar, "Preferences", args, n);
/* create the algorithms pullright menu */
n = 0;
XtSetArg (args[n], XmNradioBehavior, True); n++;
pull_right = XmCreatePulldownMenu (menu_pane, "Algorithms", args,n);
n = 0;
XtSetArg (args[n], XmNmnemonic, 'A'); n++;
tb1 = XmCreateToggleButton (pull_right, "Accurate", args, n);
XtAddCallback (tb1, XmNvalueChangedCallback, pref_algo_cb,
(XtPointer)PREF_ACCURATE);
XtManageChild (tb1);
n = 0;
XtSetArg (args[n], XmNmnemonic, 'F'); n++;
tb2 = XmCreateToggleButton (pull_right, "Fast", args, n);
XtAddCallback (tb2, XmNvalueChangedCallback, pref_algo_cb,
(XtPointer)PREF_FAST);
XtManageChild (tb2);
if (XmToggleButtonGetState(tb1))
prefs[PREF_ALGO] = PREF_ACCURATE;
else if (XmToggleButtonGetState(tb2))
prefs[PREF_ALGO] = PREF_FAST;
else {
xe_msg ("Neither Alogirthms preference is set -- defaulting to Accurate\n", 0);
XmToggleButtonSetState (tb1, True, False);
prefs[PREF_ALGO] = PREF_ACCURATE;
}
n = 0;
XtSetArg (args[n], XmNsubMenuId, pull_right); n++;
XtSetArg (args[n], XmNmnemonic, 'A'); n++;
cascade = XmCreateCascadeButton (menu_pane, "AlgorithmsCB",args,n);
XtManageChild (cascade);
set_xmstring (cascade, XmNlabelString, "Algorithms");
/* create the date formats pullright menu */
n = 0;
XtSetArg (args[n], XmNradioBehavior, True); n++;
pull_right = XmCreatePulldownMenu (menu_pane, "DateFormat",args,n);
n = 0;
XtSetArg (args[n], XmNmnemonic, 'm'); n++;
tb1 = XmCreateToggleButton (pull_right, "MDY", args, n);
XtManageChild (tb1);
XtAddCallback (tb1, XmNvalueChangedCallback, pref_date_cb,
(XtPointer)PREF_MDY);
set_xmstring (tb1, XmNlabelString, "M/D/Y");
n = 0;
XtSetArg (args[n], XmNmnemonic, 'y'); n++;
tb2 = XmCreateToggleButton (pull_right, "YMD", args, n);
XtAddCallback (tb2, XmNvalueChangedCallback, pref_date_cb,
(XtPointer)PREF_YMD);
XtManageChild (tb2);
set_xmstring (tb2, XmNlabelString, "Y/M/D");
n = 0;
XtSetArg (args[n], XmNmnemonic, 'd'); n++;
tb3 = XmCreateToggleButton (pull_right, "DMY", args, n);
XtAddCallback (tb3, XmNvalueChangedCallback, pref_date_cb,
(XtPointer)PREF_DMY);
XtManageChild (tb3);
set_xmstring (tb3, XmNlabelString, "D/M/Y");
if (XmToggleButtonGetState(tb1))
prefs[PREF_DATE_FORMAT] = PREF_MDY;
else if (XmToggleButtonGetState(tb2))
prefs[PREF_DATE_FORMAT] = PREF_YMD;
else if (XmToggleButtonGetState(tb3))
prefs[PREF_DATE_FORMAT] = PREF_DMY;
else {
xe_msg ("No DateFormat preference is set -- defaulting to MDY\n", 0);
XmToggleButtonSetState (tb1, True, False);
prefs[PREF_DATE_FORMAT] = PREF_MDY;
}
n = 0;
XtSetArg (args[n], XmNsubMenuId, pull_right); n++;
XtSetArg (args[n], XmNmnemonic, 'D'); n++;
cascade = XmCreateCascadeButton (menu_pane, "DateFormatCB",args, n);
XtManageChild (cascade);
set_xmstring (cascade, XmNlabelString, "Date formats");
/* create the units pullright menu */
n = 0;
XtSetArg (args[n], XmNradioBehavior, True); n++;
pull_right = XmCreatePulldownMenu (menu_pane, "Units", args,n);
n = 0;
XtSetArg (args[n], XmNmnemonic, 'E'); n++;
tb1 = XmCreateToggleButton (pull_right, "English", args, n);
XtAddCallback (tb1, XmNvalueChangedCallback, pref_units_cb,
(XtPointer)PREF_ENGLISH);
XtManageChild (tb1);
n = 0;
XtSetArg (args[n], XmNmnemonic, 'M'); n++;
tb2 = XmCreateToggleButton (pull_right, "Metric", args, n);
XtAddCallback (tb2, XmNvalueChangedCallback, pref_units_cb,
(XtPointer)PREF_METRIC);
XtManageChild (tb2);
if (XmToggleButtonGetState(tb1))
prefs[PREF_UNITS] = PREF_ENGLISH;
else if (XmToggleButtonGetState(tb2))
prefs[PREF_UNITS] = PREF_METRIC;
else {
xe_msg ("Neither Units preference is set -- defaulting to English\n", 0);
XmToggleButtonSetState (tb1, True, False);
prefs[PREF_UNITS] = PREF_ENGLISH;
}
n = 0;
XtSetArg (args[n], XmNsubMenuId, pull_right); n++;
XtSetArg (args[n], XmNmnemonic, 'U'); n++;
cascade = XmCreateCascadeButton (menu_pane, "UnitsCB", args, n);
XtManageChild (cascade);
set_xmstring (cascade, XmNlabelString, "Units");
n = 0;
XtSetArg (args[n], XmNsubMenuId, menu_pane); n++;
XtSetArg (args[n], XmNmnemonic, 'P'); n++;
cascade = XmCreateCascadeButton (menu_bar, "PreferencesCB", args, n);
set_xmstring (cascade, XmNlabelString, "Preferences");
XtManageChild (cascade);
}
/* called anytime we want to know a preference.
*/
int
pref_get(pref)
int pref;
{
return (prefs[pref]);
}
/* called when a PREF_ALGO preference changes.
* the new value is in client.
*/
/* ARGSUSED */
static void
pref_algo_cb (w, client, call)
Widget w;
XtPointer client;
XtPointer call;
{
XmToggleButtonCallbackStruct *s = (XmToggleButtonCallbackStruct *)call;
if (s->set) {
prefs[PREF_ALGO] = (int)client;
redraw_screen (1);
}
}
/* called when a PREF_DATE_FORMAT preference changes.
* the new value is in client.
*/
/* ARGSUSED */
static void
pref_date_cb (w, client, call)
Widget w;
XtPointer client;
XtPointer call;
{
XmToggleButtonCallbackStruct *s = (XmToggleButtonCallbackStruct *)call;
if (s->set) {
prefs[PREF_DATE_FORMAT] = (int)client;
redraw_screen (1);
}
}
/* called when a PREF_UNITS preference changes.
* the new value is in client.
*/
/* ARGSUSED */
static void
pref_units_cb (w, client, call)
Widget w;
XtPointer client;
XtPointer call;
{
XmToggleButtonCallbackStruct *s = (XmToggleButtonCallbackStruct *)call;
if (s->set) {
prefs[PREF_UNITS] = (int)client;
redraw_screen (1);
}
}