summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--XMore.ad60
-rw-r--r--print.c127
-rw-r--r--print.h5
-rw-r--r--printdialog.c66
-rw-r--r--printdialog.h1
-rw-r--r--xmore.c141
-rw-r--r--xmore.h12
7 files changed, 327 insertions, 85 deletions
diff --git a/XMore.ad b/XMore.ad
new file mode 100644
index 0000000..1392d46
--- /dev/null
+++ b/XMore.ad
@@ -0,0 +1,60 @@
+! XMore.ad
+
+! keyboard translations
+*text.Translations: #override\n\
+ Ctrl<Key>S: no-op(RingBell)\n\
+ Ctrl<Key>R: no-op(RingBell)\n\
+ <Key>space: next-page()\n\
+ <Key>F: next-page()\n\
+ Ctrl<Key>B: previous-page()\n\
+ <Key>B: previous-page()\n\
+ <Key>K: scroll-one-line-down()\n\
+ <Key>Y: scroll-one-line-down()\n\
+ <Key>Return: scroll-one-line-up()\n\
+ <Key>J: scroll-one-line-up()\n\
+ <Key>E: scroll-one-line-up()\n\
+ <Key>p: print()\n\
+ <Key>q: quit()\n
+*text.baseTranslations: #override\n\
+ <Key>space: next-page()\n\
+ <Key>F: next-page()\n\
+ Ctrl<Key>B: previous-page()\n\
+ <Key>K: scroll-one-line-down()\n\
+ <Key>Y: scroll-one-line-down()\n\
+ <Key>Return: scroll-one-line-up()\n\
+ <Key>J: scroll-one-line-up()\n\
+ <Key>E: scroll-one-line-up()\n\
+ <Key>p: print()\n\
+ <Key>q: quit()\n
+
+! tip messages
+*quit.tip: Quit application
+*print.tip: Print file
+
+! tip messages for print dialog
+*printdialog*main*ok.tip: Print
+*printdialog*main*cancel.tip: Cancel printing
+*printdialog*main*setup.tip: Configure printer options (page size, orientation, etc.)
+*printdialog*main*desclabel.tip: Short description of printer
+*printdialog*main*desc.tip: Short description of printer
+*printdialog*main*info.tip: Display additional information about this printer
+*printdialog*main*namelabel.tip: Name of selected printer
+*printdialog*main*name.tip: Name of selected printer
+*printdialog*main*selectprinter.tip: Select a different printer
+*printdialog*main*filenamelabel.tip: File where the output should be stored
+*printdialog*main*filename.tip: File where the output should be stored
+*printdialog*main*selectfile.tip: Select file where the output should be stored
+*printdialog*main*printtoprinter.tip: Send print job to printer
+*printdialog*main*printtofile.tip: Save print job in a file
+*printdialog*setup*ok.tip: Commit changes
+*printdialog*setup*cancel.tip: Cancel and reset to defaults
+*printdialog*setup*paperlist.tip: Select paper size
+*printdialog*setup*resolutionlist.tip: Select page resolution
+*printdialog*setup*orientationlist.tip: Select page orientation
+*printdialog*setup*plexlist.tip: Select page plex mode (simplex, duplex, etc.)
+*printdialog*setup*jobcopieslabel.tip: Set number of job copies
+*printdialog*setup*jobcopies.tip: Set number of job copies
+*printdialog*printerselection*ok.tip: Switch printer
+*printdialog*printerselection*cancel.tip: Cancel printer selection
+*printdialog*printerselection*list.tip: Select printer name from list
+! EOF.
diff --git a/print.c b/print.c
index d8d93d7..d44b97e 100644
--- a/print.c
+++ b/print.c
@@ -32,7 +32,6 @@ in this Software without prior written authorization from The Open Group.
#define Assertion(expr, msg) { if (!(expr)) { Error msg } }
#define Log(x) { if(True) printf x; }
-#include "xmore.h"
#include "print.h"
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
@@ -85,21 +84,23 @@ CreatePrintShell(Widget videoshell,
typedef struct
{
- Widget toplevel;
- Bool isPrinting;
- Widget printshell;
+ const char *programname;
+ Widget toplevel;
+ Bool isPrinting;
+ Widget printshell;
struct
{
- Widget form;
- Widget pageheaderlabel;
- Widget text;
+ Widget form;
+ Widget pageheaderlabel;
+ Widget text;
} content; /* content to print */
- int numpages;
- Display *pdpy;
- Screen *pscreen;
- XPContext pcontext;
- void *printtofile_handle;
- const char *jobtitle;
+ int numpages;
+ Display *pdpy;
+ Screen *pscreen;
+ XPContext pcontext;
+ XtCallbackProc pdpyDestroyCallback;
+ void *printtofile_handle;
+ const char *jobtitle;
} AppPrintData;
static AppPrintData apdx;
@@ -182,11 +183,12 @@ PageSetupCB(Widget widget, XtPointer client_data, XtPointer call_data)
}
}
+static
void FinishPrinting(AppPrintData *p)
{
if (p->printtofile_handle) {
if (XpuWaitForPrintFileChild(p->printtofile_handle) != XPGetDocFinished) {
- fprintf(stderr, "%s: Error while printing to file.\n", ProgramName);
+ fprintf(stderr, "%s: Error while printing to file.\n", apd->programname);
}
p->printtofile_handle = NULL;
}
@@ -196,8 +198,24 @@ void FinishPrinting(AppPrintData *p)
p->printshell = NULL;
}
- /* |p->pdpy| and |p->pcontext| are destroyed when th
- * print dialog widget gets destroyed. */
+ /* Two issues here:
+ * 1. The print display connection is owned by the print dialog
+ * To avoid any problems with that use a callback back to the main
+ * application which calls
+ * |XawPrintDialogClosePrinterConnection(w, False)| to ask the
+ * print dialog widget to close all print display resources and
+ * disown the object.
+ * 2. We have to use XpDestroyContext() and XtCloseDisplay()
+ * instead of XpuClosePrinterDisplay() to make libXt happy...
+ *
+ * Call callback... */
+ (*apd->pdpyDestroyCallback)(NULL, NULL, NULL); /* HACK! */
+
+ /* ... and then get rid of the display */
+ if (p->pcontext != None) {
+ XpDestroyContext(p->pdpy, p->pcontext);
+ }
+ XtCloseDisplay(p->pdpy);
p->toplevel = NULL;
p->isPrinting = False;
@@ -218,32 +236,56 @@ void PrintEndJobCB(Widget pshell, XtPointer client_data, XtPointer call_data)
FinishPrinting(p);
}
-XFontStruct *GetPrintTextFont(Display *pdpy, long dpi)
+static
+XFontSet GetPrintTextFontSet(const char *appname, Display *pdpy, long dpi)
{
- XFontStruct *font;
+ XFontSet fontset;
char fontname[1024];
+ char **missing_charset_list_return;
+ int missing_charset_count_return;
+ char *def_string_return;
+ int i;
+ long font_size;
+
+ /* Scale font size with DPI */
+ font_size = (40L * dpi) / 300L;
- sprintf(fontname, "-adobe-courier-medium-r-normal--40-*-%ld-%ld-*-*-iso8859-1", dpi, dpi);
- font = XLoadQueryFont(pdpy, fontname);
- if (!font) {
- sprintf(fontname, "-*-*-*-*-*-*-*-160-%ld-%ld-*-*-iso8859-1", dpi, dpi);
- font = XLoadQueryFont(pdpy, fontname);
+ sprintf(fontname, "-adobe-courier-medium-r-normal--%ld-*-%ld-%ld-*-*,"
+ "-*-*-*-*-*-*-%ld-*-%ld-%ld-*-*",
+ font_size, dpi, dpi,
+ font_size, dpi, dpi);
+ fontset = XCreateFontSet(pdpy, fontname,
+ &missing_charset_list_return,
+ &missing_charset_count_return,
+ &def_string_return);
+
+ for( i=0 ; i < missing_charset_count_return ; i++ ) {
+ fprintf(stderr, "%s: warning: font for charset %s is lacking.\n",
+ appname, missing_charset_list_return[i]);
}
- if (!font)
- Error(("XLoadQueryFont failure.\n"));
- return font;
+
+ if (!fontset)
+ Error(("XCreateFontSet() failure.\n"));
+ return fontset;
}
-void DoPrint(Widget toplevel, Display *pdpy, XPContext pcontext,
+void DoPrint(const char *programname,
+ Widget textsource, Widget toplevel,
+ Display *pdpy, XPContext pcontext,
+ XtCallbackProc pdpyDestroyCB,
const char *jobtitle, const char *toFile)
{
- long dpi = 0;
- int n;
- Arg args[20];
- XFontStruct *textfont = NULL;
+ long dpi = 0;
+ int n;
+ Arg args[20];
+ XFontSet textfontset = NULL;
+ XFontSetExtents *font_extents;
+
+ apd->programname = programname;
+ apd->pdpyDestroyCallback = pdpyDestroyCB;
if (apd->isPrinting) {
- fprintf(stderr, "%s: Already busy with printing.\n", ProgramName);
+ fprintf(stderr, "%s: Already busy with printing.\n", apd->programname);
return;
}
@@ -258,7 +300,7 @@ void DoPrint(Widget toplevel, Display *pdpy, XPContext pcontext,
/* Get default printer resolution */
if (XpuGetResolution(pdpy, pcontext, &dpi) != 1) {
- fprintf(stderr, "%s: No default resolution for printer.\n", ProgramName);
+ fprintf(stderr, "%s: No default resolution for printer.\n", apd->programname);
XpuClosePrinterDisplay(pdpy, pcontext);
return;
}
@@ -271,14 +313,14 @@ void DoPrint(Widget toplevel, Display *pdpy, XPContext pcontext,
n = 0;
XtSetArg(args[n], XawNlayoutMode, XawPrintLAYOUTMODE_DRAWABLEAREA); n++;
- apd->printshell = CreatePrintShell(toplevel, apd->pscreen, "Print", args, n);
+ apd->printshell = CreatePrintShell(toplevel, apd->pscreen, "print", args, n);
n = 0;
XtSetArg(args[n], XtNresizable, True); n++;
XtSetArg(args[n], XtNright, XtChainRight); n++;
apd->content.form = XtCreateManagedWidget("form", formWidgetClass, apd->printshell, args, n);
- textfont = GetPrintTextFont(pdpy, dpi);
+ textfontset = GetPrintTextFontSet(apd->programname, pdpy, dpi);
#ifdef PRINT_PAGEHEADER
n = 0;
@@ -287,18 +329,19 @@ void DoPrint(Widget toplevel, Display *pdpy, XPContext pcontext,
XtSetArg(args[n], XtNtop, XtChainTop); n++;
XtSetArg(args[n], XtNright, XtChainRight); n++;
XtSetArg(args[n], XtNresizable, True); n++;
- XtSetArg(args[n], XtNfont, textfont); n++; /* fontset would be better */
+ XtSetArg(args[n], XtNfontSet, textfontset); n++;
XtSetArg(args[n], XtNlabel, "Page: n/n"); n++;
XtSetArg(args[n], XtNjustify, XtJustifyRight); n++;
apd->content.pageheaderlabel = XtCreateManagedWidget("pageinfo", labelWidgetClass, apd->content.form, args, n);
#endif /* PRINT_PAGEHEADER */
n = 0;
- XtSetArg(args[n], XtNtype, XawAsciiFile); n++;
- XtSetArg(args[n], XtNstring, viewFileName); n++;
+ XtSetArg(args[n], XtNtextSource, textsource); n++;
XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollNever); n++;
XtSetArg(args[n], XtNscrollVertical, XawtextScrollNever); n++;
+ font_extents = XExtentsOfFontSet(textfontset);
+
/* Usually I would expect that using |XtNfromVert, apd->content.pageheaderlabel|
* would be the correct way to place the text widget with the main content below
* the page header widget - but for an unknown reason this doesn not work: The
@@ -308,12 +351,12 @@ void DoPrint(Widget toplevel, Display *pdpy, XPContext pcontext,
#ifdef WORKAROUND_FOR_SOMETHING_IS_WRONG
XtSetArg(args[n], XtNtop, XtChainTop); n++;
XtSetArg(args[n], XtNright, XtChainRight); n++;
- XtSetArg(args[n], XtNvertDistance, (textfont->ascent+textfont->descent+2)*2); n++;
+ XtSetArg(args[n], XtNvertDistance, (font_extents->max_logical_extent.height+2)*2); n++;
#else
XtSetArg(args[n], XtNfromHoriz, NULL); n++;
XtSetArg(args[n], XtNfromVert, apd->content.pageheaderlabel); n++;
#endif
- XtSetArg(args[n], XtNfont, textfont); n++; /* fontset would be better */
+ XtSetArg(args[n], XtNfontSet, textfontset); n++;
apd->content.text = XtCreateManagedWidget("text", asciiTextWidgetClass, apd->content.form, args, n);
/* Disable the caret - that is not needed for printing */
XawTextDisplayCaret(apd->content.text, False);
@@ -335,7 +378,7 @@ void DoPrint(Widget toplevel, Display *pdpy, XPContext pcontext,
apd->isPrinting = True;
if (toFile) {
- printf("%s: Printing to file '%s'...\n", ProgramName, toFile);
+ printf("%s: Printing to file '%s'...\n", apd->programname, toFile);
apd->printtofile_handle = XpuStartJobToFile(pdpy, pcontext, toFile);
if (!apd->printtofile_handle) {
perror("XpuStartJobToFile failure");
@@ -345,7 +388,7 @@ void DoPrint(Widget toplevel, Display *pdpy, XPContext pcontext,
}
else
{
- printf("%s: Printing to printer...\n", ProgramName);
+ printf("%s: Printing to printer...\n", apd->programname);
XpuStartJobToSpooler(pdpy);
}
}
diff --git a/print.h b/print.h
index 0dc94df..e098531 100644
--- a/print.h
+++ b/print.h
@@ -36,8 +36,11 @@ in this Software without prior written authorization from The Open Group.
#include <X11/XprintUtil/xprintutil.h>
/* Prototypes */
-void DoPrint(Widget toplevel,
+void DoPrint(const char *programname,
+ Widget textsource,
+ Widget toplevel,
Display *pdpy, XPContext pcontext,
+ XtCallbackProc printDisplayDestroyCallback,
const char *jobTitle,
const char *toFile);
diff --git a/printdialog.c b/printdialog.c
index 7c5eb60..8d31020 100644
--- a/printdialog.c
+++ b/printdialog.c
@@ -69,7 +69,7 @@ static void printOKXtProc(Widget w, XtPointer client_data, XtPointer callDat
static void printSetupXtProc(Widget w, XtPointer client_data, XtPointer callData);
static void printFileSelectedXtProc(Widget w, XtPointer client_data, XtPointer callData);
static void buildFileDialog(PrintDialogWidget pdw);
-static void closePrinterConnection(PrintDialogWidget pdw);
+static void closePrinterConnection(PrintDialogWidget pdw, Bool closeDisplay);
static Bool openPrinterConnection(PrintDialogWidget pdw);
static void destroyPrintSetupDialog(PrintDialogWidget pdw);
static Widget buildPrintSetupDialog(PrintDialogWidget pdw);
@@ -191,14 +191,13 @@ printSetupOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
PrintDialogWidget pdw = (PrintDialogWidget)client_data;
PrintDialogPart *pdp = &pdw->printdialog;
char *s;
- int c;
XawListReturnStruct *lrs;
Log(("## printSetupOK: closing print setup!\n"));
/* Set copy count (if the value is invalid beep and return to the user ) */
XtVaGetValues(pdp->setup.jobcopies, XtNstring, &s, NULL);
if (s) {
- c = atoi(s);
+ int c = atoi(s);
if (c < 1 || c > 999) {
do_beep(pdw);
XtVaSetValues(pdp->setup.jobcopies, XtNstring, "1", NULL);
@@ -271,20 +270,20 @@ printSetupJobCopiesXtProc(Widget w, XtPointer client_data, XtPointer callData)
XtVaGetValues(pdp->setup.jobcopies, XtNstring, &string, NULL);
if (string) {
char *s;
- int c;
+ int i;
Bool isValidNumber = True;
/* First check for invalid characters... */
- for( s = string ; (c = *s++) != '\0' ; s++ ) {
- if (!isdigit(c)) {
+ for( s = string ; *s != '\0' ; s++ ) {
+ if (!isdigit(*s)) {
isValidNumber = False;
break;
}
}
/* .. and the do a range check... */
- c = atoi(string);
- if (c < 1 || c > 999) {
+ i = atoi(string);
+ if (i < 1 || i > 999) {
isValidNumber = False;
}
@@ -426,7 +425,7 @@ void buildFileDialog(PrintDialogWidget pdw)
int n;
Arg args[20];
- pdp->selectFile.shell = XtCreatePopupShell("shell",
+ pdp->selectFile.shell = XtCreatePopupShell("selectfile",
transientShellWidgetClass,
(Widget)pdw, NULL, 0);
n = 0;
@@ -440,7 +439,7 @@ void buildFileDialog(PrintDialogWidget pdw)
}
static
-void closePrinterConnection(PrintDialogWidget pdw)
+void closePrinterConnection(PrintDialogWidget pdw, Bool closeDisplay)
{
PrintDialogPart *pdp = &pdw->printdialog;
@@ -490,7 +489,9 @@ void closePrinterConnection(PrintDialogWidget pdw)
}
if (pdp->pdpy) {
- XpuClosePrinterDisplay(pdp->pdpy, pdp->pcontext);
+ if (closeDisplay) {
+ XpuClosePrinterDisplay(pdp->pdpy, pdp->pcontext);
+ }
pdp->pdpy = NULL;
pdp->pcontext = None;
}
@@ -499,14 +500,14 @@ void closePrinterConnection(PrintDialogWidget pdw)
}
static
-Bool openPrinterConnection(PrintDialogWidget pdw)
+Bool openPrinterConnection(PrintDialogWidget pdw)
{
PrintDialogPart *pdp = &pdw->printdialog;
Log(("# openPrinterConnection\n"));
/* Close any outstanding connection first... */
- closePrinterConnection(pdw);
+ closePrinterConnection(pdw, True);
if (!pdp->printer_name) {
Log(("# error: openPrinterConnection: No printer name.\n"));
@@ -596,7 +597,7 @@ Widget buildPrintSetupDialog(PrintDialogWidget pdw)
n = 0;
XtSetArg(args[n], XtNallowShellResize, True); n++;
- pdp->setup.popup = XtCreatePopupShell("popup", transientShellWidgetClass, (Widget)pdw, args, n);
+ pdp->setup.popup = XtCreatePopupShell("setup", transientShellWidgetClass, (Widget)pdw, args, n);
n = 0;
pdp->setup.form = XtCreateManagedWidget("form", formWidgetClass, pdp->setup.popup, args, n);
@@ -879,7 +880,7 @@ printerSelectionOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
/* Close any outstanding printer connection since user has selected
* a different printer */
- closePrinterConnection(pdw);
+ closePrinterConnection(pdw, True);
printerSelectionClose(pdw);
@@ -905,7 +906,7 @@ Bool buildPrinterSelectionDialog(PrintDialogWidget pdw)
n = 0;
XtSetArg(args[n], XtNallowShellResize, True); n++;
- pdp->selectPrinter.popup = XtCreatePopupShell("popup", transientShellWidgetClass, (Widget)pdw, args, n);
+ pdp->selectPrinter.popup = XtCreatePopupShell("printerselection", transientShellWidgetClass, (Widget)pdw, args, n);
n = 0;
pdp->selectPrinter.form = XtCreateManagedWidget("form", formWidgetClass, pdp->selectPrinter.popup, args, n);
@@ -998,7 +999,7 @@ createprintdialogchildren(Widget w)
n = 0;
XtSetArg(args[n], XtNborderWidth, 0); n++;
- pdp->main.form = XtCreateManagedWidget("form", formWidgetClass, (Widget)pdw, args, n);
+ pdp->main.form = XtCreateManagedWidget("main", formWidgetClass, (Widget)pdw, args, n);
n = 0;
pdp->main.innerform = XtCreateManagedWidget("innerform", formWidgetClass, pdp->main.form, args, n);
@@ -1365,11 +1366,36 @@ XawPrintDialogDestroy(Widget w)
destroyPrintSetupDialog(pdw);
destroyPrinterSelectionDialog(pdw);
- closePrinterConnection(pdw);
+ closePrinterConnection(pdw, True);
Log(("# XawPrintDialogDestroy: done.\n"));
}
-
-
+/*
+ * Function:
+ * XawPrintDialogClosePrinterConnection
+ *
+ * Parameters:
+ * w - Print Dialog Widget
+ * closeDisplay - Boolean which decides whether |Display *|
+ * and |XPContext| should be disposed, too.
+ *
+ * Description:
+ * The print display connection is owned by the print dialog
+ * by default.
+ * If the application wishes to close the display connection
+ * to the print server, either to close it itself or force
+ * a disconnection for other reasons this function can be used.
+ *
+ * Notes
+ * 1. PUBLIC API
+ * 2. After this function returns all resources returned by the
+ * print dialog which are related to the status of the printer
+ * connection are stale.
+ */
+void
+XawPrintDialogClosePrinterConnection(Widget w, Bool closeDisplay)
+{
+ closePrinterConnection((PrintDialogWidget)w, closeDisplay);
+}
diff --git a/printdialog.h b/printdialog.h
index 7ac8e48..a549a1e 100644
--- a/printdialog.h
+++ b/printdialog.h
@@ -78,6 +78,7 @@ extern WidgetClass printDialogWidgetClass;
_XFUNCPROTOBEGIN
/* Prototypes */
+void XawPrintDialogClosePrinterConnection(Widget w, Bool closeDisplay);
_XFUNCPROTOEND
diff --git a/xmore.c b/xmore.c
index 1dae07f..b9812b3 100644
--- a/xmore.c
+++ b/xmore.c
@@ -44,41 +44,129 @@ in this Software without prior written authorization from The Open Group.
#include <stdlib.h>
#include <stdio.h>
+#include <limits.h>
/* Turn a NULL pointer string into an empty string */
#define NULLSTR(x) (((x)!=NULL)?(x):(""))
#define Error(x) { printf x ; exit(EXIT_FAILURE); }
#define Assertion(expr, msg) { if (!(expr)) { Error msg } }
-#define Log(x) { if(True) printf x; }
+#define Log(x) { if (userOptions.verbose) printf x; }
/* Global vars */
-XtAppContext app;
-Widget printdialog_shell = NULL;
-Widget printdialog = NULL;
-Widget toplevel;
-const char *ProgramName; /* program name (from argv[0]) */
-const char *viewFileName; /* file to browse (from argv[1]) */
-char printJobNameBuffer[1024];
+static Widget printdialog_shell = NULL;
+static Widget printdialog = NULL;
+static Widget toplevel = NULL;
+static Widget text = NULL;
+static char printJobNameBuffer[PATH_MAX+256];
+static const char *ProgramName; /* program name (from argv[0]) */
+static const char *viewFileName; /* file to browse (from argv[1]) */
+
+/* prototypes */
+static void quitAction(Widget w, XEvent *event, String *params, Cardinal *num_params);
+static void quitXtProc(Widget w, XtPointer client_data, XtPointer callData);
+static void printAction(Widget w, XEvent *event, String *params, Cardinal *num_params);
+static void printXtProc(Widget w, XtPointer client_data, XtPointer callData);
+
+static XrmOptionDescRec options[] = {
+{
+ "-v", "*verbose", XrmoptionNoArg, (XPointer) "on" },
+};
+
+
+static XtActionsRec actions[] = {
+ { "quit", quitAction },
+ { "print", printAction }
+};
+
+/* See xmore.h */
+XMoreResourceData userOptions;
+
+#define Offset(field) XtOffsetOf(XMoreResourceData, field)
+
+XtResource resources[] = {
+ {"verbose", "Verbose", XtRBoolean, sizeof(Boolean), Offset(verbose), XtRImmediate, (XtPointer)False},
+ {"textfont", XtCFont, XtRFontSet, sizeof(XFontSet), Offset(textfont), XtRString, STANDARDFONT},
+};
+
+
+String fallback_resources[] = {
+#ifdef NOTYET
+ "*iconPixmap: xmore32",
+ "*iconMask: xmore32",
+#endif /* NOTYET */
+ "*textfont: " STANDARDFONT,
+ "*international: True", /* set this globally for ALL widgets to avoid wiered crashes */
+ "*text.Translations: #override \\n\\"
+ "\tCtrl<Key>S: no-op(RingBell)\\n\\"
+ "\tCtrl<Key>R: no-op(RingBell)\\n\\"
+ "\t<Key>space: next-page()\\n\\"
+ "\t<Key>F: next-page()\\n\\"
+ "\tCtrl<Key>B: previous-page()\\n\\"
+ "\t<Key>B: previous-page()\\n\\"
+ "\t<Key>K: scroll-one-line-down()\\n\\"
+ "\t<Key>Y: scroll-one-line-down()\\n\\"
+ "\t<Key>Return: scroll-one-line-up()\\n\\"
+ "\t<Key>J: scroll-one-line-up()\\n\\"
+ "\t<Key>E: scroll-one-line-up()\\n\\"
+ "\t<Key>p: print()\\n\\"
+ "\t<Key>q: quit()\\n",
+ "*text.baseTranslations: #override \\n\\"
+ "\t<Key>space: next-page()\\n\\"
+ "\t<Key>F: next-page()\\n\\"
+ "\tCtrl<Key>B: previous-page()\\n\\"
+ "\t<Key>K: scroll-one-line-down()\\n\\"
+ "\t<Key>Y: scroll-one-line-down()\\n\\"
+ "\t<Key>Return: scroll-one-line-up()\\n\\"
+ "\t<Key>J: scroll-one-line-up()\\n\\"
+ "\t<Key>E: scroll-one-line-up()\\n\\"
+ "\t<Key>p: print()\\n\\"
+ "\t<Key>q: quit()\\n",
+ NULL,
+};
+
+static void
+quitAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
+{
+ XtAppSetExitFlag(XtWidgetToApplicationContext(w));
+}
static void
quitXtProc(Widget w, XtPointer client_data, XtPointer callData)
{
- XtAppSetExitFlag(app);
+ XtCallActionProc(w, "quit", NULL, NULL, 0);
+}
+
+static void
+printshellDestroyXtProc(Widget w, XtPointer client_data, XtPointer callData)
+{
+ XawPrintDialogClosePrinterConnection(printdialog, False);
}
static void
printOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
{
XawPrintDialogCallbackStruct *pdcs = (XawPrintDialogCallbackStruct *)callData;
+ Cardinal n;
+ Arg args[2];
+ Widget textsource;
Log(("printOKXtProc: OK.\n"));
+ /* Get TextSource object */
+ n = 0;
+ XtSetArg(args[n], XtNtextSource, &textsource); n++;
+ XtGetValues(text, args, n);
+
+ Assertion(textsource != NULL, (("printOKXtProc: textsource == NULL.\n")));
+
/* ||printJobNameBuffer| must live as long the print job prints
* because it is used for the job title AND the page headers... */
sprintf(printJobNameBuffer, "XMore print job %s", viewFileName);
- DoPrint(toplevel, pdcs->pdpy, pdcs->pcontext,
+ DoPrint(ProgramName,
+ textsource, toplevel,
+ pdcs->pdpy, pdcs->pcontext, printshellDestroyXtProc,
printJobNameBuffer,
pdcs->printToFile?pdcs->printToFileName:NULL);
@@ -101,10 +189,16 @@ printCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
static void
printXtProc(Widget w, XtPointer client_data, XtPointer callData)
{
+ XtCallActionProc(toplevel, "print", NULL, NULL, 0);
+}
+
+static void
+printAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
+{
Dimension width, height;
- Position x, y;
- Widget parent = toplevel;
- puts("print!");
+ Position x, y;
+ Widget parent = toplevel;
+ Log(("print!\n"));
if (!printdialog) {
int n;
@@ -112,7 +206,7 @@ printXtProc(Widget w, XtPointer client_data, XtPointer callData)
n = 0;
XtSetArg(args[n], XtNallowShellResize, True); n++;
- printdialog_shell = XtCreatePopupShell("shell",
+ printdialog_shell = XtCreatePopupShell("printdialogshell",
transientShellWidgetClass,
toplevel, args, n);
n = 0;
@@ -144,8 +238,8 @@ printXtProc(Widget w, XtPointer client_data, XtPointer callData)
int main( int argc, char *argv[] )
{
+ XtAppContext app;
Widget form;
- Widget text;
Widget printbutton;
Widget quitbutton;
int n;
@@ -153,7 +247,10 @@ int main( int argc, char *argv[] )
ProgramName = argv[0];
- toplevel = XtAppInitialize(&app, "XMore", NULL, 0, &argc, argv, NULL, NULL, 0);
+ toplevel = XtOpenApplication(&app, "XMore",
+ options, XtNumber(options),
+ &argc, argv, fallback_resources,
+ sessionShellWidgetClass, NULL, ZERO);
if (argc != 2)
{
@@ -161,6 +258,11 @@ int main( int argc, char *argv[] )
exit(EXIT_FAILURE);
}
+ XtGetApplicationResources(toplevel, (XtPointer)&userOptions, resources,
+ XtNumber(resources), NULL, 0);
+
+ XtAppAddActions(app, actions, XtNumber(actions));
+
viewFileName = argv[1];
form = XtCreateManagedWidget("form", formWidgetClass, toplevel, NULL, 0);
@@ -168,10 +270,11 @@ int main( int argc, char *argv[] )
n = 0;
XtSetArg(args[n], XtNtype, XawAsciiFile); n++;
XtSetArg(args[n], XtNstring, viewFileName); n++;
- XtSetArg(args[n], XtNwidth, 500); n++;
- XtSetArg(args[n], XtNheight, 600); n++;
- XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollWhenNeeded); n++;
+ XtSetArg(args[n], XtNwidth, 700); n++;
+ XtSetArg(args[n], XtNheight, 300); n++;
+ XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollAlways); n++;
XtSetArg(args[n], XtNscrollVertical, XawtextScrollAlways); n++;
+ XtSetArg(args[n], XtNfontSet, userOptions.textfont); n++;
text = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, n);
n = 0;
diff --git a/xmore.h b/xmore.h
index 496aa15..101f73a 100644
--- a/xmore.h
+++ b/xmore.h
@@ -28,8 +28,14 @@ in this Software without prior written authorization from The Open Group.
#ifndef XMORE_XMORE_H
#define XMORE_XMORE_H 1
-/* Global vars */
-extern const char *ProgramName; /* program name (from argv[0]) */
-extern const char *viewFileName; /* file to browse (from argv[1]) */
+#include <X11/Intrinsic.h>
+
+typedef struct {
+ Boolean verbose;
+ XFontSet textfont;
+} XMoreResourceData, *XMoreResourceDataPtr;
+
+#define STANDARDFONT "-adobe-courier-medium-r-normal--12-*-*-*-*-*," \
+ "-*-*-*-*-*-*-12-*-*-*-*-*"
#endif /* !XMORE_XMORE_H */