summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Mainz <roland.mainz@nrubsig.org>2004-06-08 02:44:35 +0000
committerRoland Mainz <roland.mainz@nrubsig.org>2004-06-08 02:44:35 +0000
commit7cf0973ed5076c513b3a970a8250066a05b0473e (patch)
treeb3fe30966fe86d7b7e707c33570872f4136dc9b5
parent113139a1b202d0b94dcd24facc7b2c584faf294e (diff)
Fix for http://freedesktop.org/bugzilla/show_bug.cgi?id=668 - Add print
support to xman
-rw-r--r--ScrollByL.c33
-rw-r--r--ScrollByL.h4
-rw-r--r--ScrollByLP.h4
-rw-r--r--buttons.c15
-rw-r--r--defs.h3
-rw-r--r--handler.c114
-rw-r--r--man.h20
-rw-r--r--misc.c11
-rw-r--r--print.c377
-rw-r--r--print.h47
-rw-r--r--search.c2
-rw-r--r--version.h2
12 files changed, 598 insertions, 34 deletions
diff --git a/ScrollByL.c b/ScrollByL.c
index 9f8c359..c679145 100644
--- a/ScrollByL.c
+++ b/ScrollByL.c
@@ -93,6 +93,10 @@ static XtResource resources[] = {
Offset(symbol_font), XtRString, MANPAGE_SYMBOL},
{XtNfile, XtCFile, XtRFile, sizeof(FILE *),
Offset(file), XtRImmediate, (caddr_t) NULL},
+ {XtNNumTotalLines, XtCNumTotalLines, XtRInt, sizeof(int),
+ Offset(lines), XtRImmediate, (caddr_t) 0},
+ {XtNNumVisibleLines, XtCNumVisibleLines, XtRInt, sizeof(int),
+ Offset(num_visible_lines), XtRImmediate, (caddr_t) 0},
};
#undef Offset
@@ -104,6 +108,7 @@ static XtResource resources[] = {
*
****************************************************************/
+static void CreateScrollbar(Widget w);
static Boolean ScrollVerticalText(Widget w, int new_line, Boolean force_redisp);
static void Layout(Widget w);
static void LoadFile(Widget w);
@@ -197,6 +202,8 @@ Layout(Widget w)
Widget bar;
Position bar_bw;
+ CreateScrollbar(w);
+
/*
* For now always show the bar.
*/
@@ -222,6 +229,8 @@ Layout(Widget w)
XtResizeWidget(bar, bar->core.width, height, bar->core.border_width);
SetThumbHeight(w);
+
+ sblw->scroll.num_visible_lines = height / sblw->scroll.font_height + 1;
}
/* ARGSUSED */
@@ -277,22 +286,20 @@ static void
PaintText(Widget w, int y_loc, int height)
{
ScrollByLineWidget sblw = (ScrollByLineWidget) w;
- int start_line, num_lines, location;
+ int start_line, location;
start_line = y_loc / sblw->scroll.font_height + sblw->scroll.line_pointer;
if (start_line >= sblw->scroll.lines)
return;
- num_lines = height / sblw->scroll.font_height + 1;
-
/*
* Only integer arithmetic makes this possible.
*/
location = y_loc / sblw->scroll.font_height * sblw->scroll.font_height;
- PrintText(w, start_line, num_lines, location);
+ PrintText(w, start_line, sblw->scroll.num_visible_lines, location);
}
/* Function Name: Page
@@ -384,7 +391,7 @@ int new_line,
Boolean force_redisp)
{
ScrollByLineWidget sblw = (ScrollByLineWidget) w;
- int num_lines = (int)w->core.height / sblw->scroll.font_height + 1;
+ int num_lines = sblw->scroll.num_visible_lines;
int max_lines, old_line;
Boolean move_thumb = FALSE;
@@ -598,8 +605,6 @@ VerticalScroll(Widget w, XtPointer client_data, XtPointer call_data)
SetThumb( (Widget) sblw);
}
-int h_width; /* main font width */
-
/* ARGSUSED */
static void
Initialize(Widget req, Widget new, ArgList args, Cardinal *num_args)
@@ -619,12 +624,9 @@ Initialize(Widget req, Widget new, ArgList args, Cardinal *num_args)
atomNum = XInternAtom(XtDisplay(req), "FIGURE_WIDTH", False);
if (XGetFontProperty(sblw->scroll.normal_font, atomNum, &figWidth))
- h_width = figWidth;
+ sblw->scroll.h_width = figWidth;
else
- h_width = XTextWidth(sblw->scroll.normal_font, "$", 1);
-
-
-
+ sblw->scroll.h_width = XTextWidth(sblw->scroll.normal_font, "$", 1);
} /* Initialize. */
/* Function Name: CreateGCs
@@ -721,7 +723,7 @@ static Boolean
SetValuesHook(Widget w, ArgList args, Cardinal *num_args)
{
Boolean ret = TRUE;
- int i;
+ Cardinal i;
for (i = 0; i < *num_args; i++) {
if (strcmp(XtNfile, args[i].name) == 0) {
@@ -819,6 +821,7 @@ LoadFile(Widget w)
* Copy the file into memory.
*/
+ fseek(file, 0L, SEEK_SET);
if (fread(page, sizeof(char), fileinfo.st_size, file) == 0)
XtAppError(XtWidgetToApplicationContext(w),
"SBLW LoadFile: Failure in fread.");
@@ -1021,7 +1024,7 @@ PrintText(Widget w, int start_line, int num_lines, int location)
italicflag = FALSE;
x_loc = sblw->scroll.offset + sblw->scroll.indent;
h_col = h_col + 8 - (h_col%8);
- x_loc += h_width * h_col;
+ x_loc += sblw->scroll.h_width * h_col;
break;
case ' ':
@@ -1042,7 +1045,7 @@ PrintText(Widget w, int start_line, int num_lines, int location)
x_loc = sblw->scroll.offset + sblw->scroll.indent;
h_col += (h_c - c);
- x_loc += h_width * h_col;
+ x_loc += sblw->scroll.h_width * h_col;
c = h_c - 1;
break;
diff --git a/ScrollByL.h b/ScrollByL.h
index cdf8e2e..0283893 100644
--- a/ScrollByL.h
+++ b/ScrollByL.h
@@ -60,8 +60,12 @@ from the X Consortium.
#define XtNmanualFontBold "manualFontBold"
#define XtNmanualFontItalic "manualFontItalic"
#define XtNmanualFontSymbol "manualFontSymbol"
+#define XtNNumTotalLines "numTotalLines"
+#define XtNNumVisibleLines "numVisibleLines"
#define XtCIndent "Indent"
+#define XtCNumTotalLines "NumTotalLines"
+#define XtCNumVisibleLines "NumVisibleLines"
/* Class record constants */
diff --git a/ScrollByLP.h b/ScrollByLP.h
index 0947707..25402d7 100644
--- a/ScrollByLP.h
+++ b/ScrollByLP.h
@@ -68,6 +68,7 @@ typedef struct _ScrollByLinePart {
* normal_font,
* italic_font,
* symbol_font;
+ int h_width; /* Main font width */
/* variables not in resource list. */
@@ -80,7 +81,8 @@ typedef struct _ScrollByLinePart {
GC bold_gc, normal_gc, italic_gc, symbol_gc; /* gc for drawing. */
char ** top_line; /* The top line of the file. */
- int lines; /* number of line in the file. */
+ int lines; /* Total number of line in the file. */
+ int num_visible_lines; /* Number of lines visible */
} ScrollByLinePart;
/****************************************************************
diff --git a/buttons.c b/buttons.c
index d30d52f..ca0d514 100644
--- a/buttons.c
+++ b/buttons.c
@@ -121,13 +121,7 @@ MakeTopBox(void)
/* add WM_COMMAND property */
XSetCommand(XtDisplay(top), XtWindow(top), saved_argv, saved_argc);
- man_globals = (ManpageGlobals*) XtMalloc( (Cardinal) sizeof(ManpageGlobals));
- man_globals->label = NULL;
- man_globals->search_widget = NULL;
- man_globals->manpagewidgets.directory = NULL;
- man_globals->manpagewidgets.manpage = NULL;
- man_globals->manpagewidgets.box = NULL;
- man_globals->current_directory = 0;
+ man_globals = (ManpageGlobals*) XtCalloc(ONE, (Cardinal) sizeof(ManpageGlobals));
MakeSearchWidget(man_globals, top);
MakeSaveWidgets(man_globals, top);
@@ -435,6 +429,7 @@ CreateOptionMenu(ManpageGlobals * man_globals, Widget parent)
BOTH_SCREENS,
REMOVE_MANPAGE,
OPEN_MANPAGE,
+ PRINT_MANPAGE,
SHOW_VERSION,
QUIT
};
@@ -470,12 +465,16 @@ CreateOptionMenu(ManpageGlobals * man_globals, Widget parent)
man_globals->open_entry = entry;
break;
case 7:
- man_globals->version_entry = entry;
+ man_globals->print_entry = entry;
break;
case 8:
+ man_globals->version_entry = entry;
+ break;
+ case 9:
man_globals->quit_entry = entry;
break;
default:
+ Error(("CreateOptionMenu: Unknown id=%d\n", i));
break;
}
}
diff --git a/defs.h b/defs.h
index 3077f79..812c3c8 100644
--- a/defs.h
+++ b/defs.h
@@ -67,7 +67,7 @@ from the X Consortium.
/* Names of the menu buttons */
-#define NUM_OPTIONS 9 /* Number of menu options. */
+#define NUM_OPTIONS 10 /* Number of menu options. */
#define DIRECTORY "displayDirectory"
#define MANPAGE "displayManualPage"
@@ -76,6 +76,7 @@ from the X Consortium.
#define BOTH_SCREENS "showBothScreens"
#define REMOVE_MANPAGE "removeThisManpage"
#define OPEN_MANPAGE "openNewManpage"
+#define PRINT_MANPAGE "printManualPage"
#define SHOW_VERSION "showVersion"
#define QUIT "quit"
diff --git a/handler.c b/handler.c
index 8a8f4f9..83b8f3f 100644
--- a/handler.c
+++ b/handler.c
@@ -40,6 +40,8 @@ from the X Consortium.
#include <sys/stat.h>
#include "globals.h"
#include "vendor.h"
+#include "printdialog.h"
+#include "print.h"
static void PutUpManpage(ManpageGlobals * man_globals, FILE * file);
static void ToggleBothShownState(ManpageGlobals * man_globals);
@@ -79,6 +81,8 @@ OptionCallback(Widget w, XtPointer pointer, XtPointer junk)
RemoveThisManpage(XtParent(w), NULL, NULL, NULL);
else if ( w == man_globals->open_entry) /* Open new manpage */
CreateNewManpage(XtParent(w), NULL, NULL, NULL);
+ else if ( w == man_globals->print_entry) /* Print current manpage */
+ PrintThisManpage(man_globals);
else if ( w == man_globals->version_entry) /* Get version */
ShowVersion(XtParent(w), NULL, NULL, NULL);
else if ( w == man_globals->quit_entry) /* Quit. */
@@ -215,7 +219,9 @@ DirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val)
file = FindManualFile(man_globals, man_globals->current_directory,
ret_struct->list_index);
PutUpManpage(man_globals, file);
- fclose(file);
+ if ((file != NULL) && (file != man_globals->curr_file)) {
+ fclose(file);
+ }
}
/* Function Name: DirPopupCallback
@@ -589,10 +595,112 @@ Search(Widget w, XEvent * event, String * params, Cardinal * num_params)
else {
PutUpManpage(man_globals, file);
}
- if (file != NULL)
- fclose(file);
+ if ((file != NULL) && (file != man_globals->curr_file)) {
+ fclose(file);
+ }
+}
+
+static void
+printshellDestroyXtProc(Widget w, XtPointer client_data, XtPointer callData)
+{
+ ManpageGlobals *mg = GetGlobals(w);
+ XawPrintDialogClosePrinterConnection(mg->printdialog, False);
+}
+
+static void
+printOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
+{
+ XawPrintDialogCallbackStruct *pdcs = (XawPrintDialogCallbackStruct *)callData;
+ Cardinal n;
+ Arg args[2];
+ ManpageGlobals *mg = GetGlobals(w);
+ Widget topwindow = mg->This_Manpage;
+ FILE *file;
+
+ Log(("printOKXtProc: OK.\n"));
+
+ /* Get file object */
+ n = 0;
+ XtSetArg(args[n], XtNfile, &file); n++;
+ XtGetValues(mg->manpagewidgets.manpage, args, n);
+ Assertion(file != NULL, (("printOKXtProc: file == NULL.\n")));
+
+ DoPrintManpage("Xman",
+ file, topwindow,
+ pdcs->pdpy, pdcs->pcontext, printshellDestroyXtProc,
+ mg->manpage_title,
+ pdcs->printToFile?pdcs->printToFileName:NULL);
+
+ XtPopdown(mg->printdialog_shell);
}
+static void
+printCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
+{
+ ManpageGlobals * mg = GetGlobals(w);
+
+ Log(("printCancelXtProc: cancel.\n"));
+ XtPopdown(mg->printdialog_shell);
+
+ Log(("destroying print dialog shell...\n"));
+ XtDestroyWidget(mg->printdialog_shell);
+ mg->printdialog_shell = NULL;
+ mg->printdialog = NULL;
+ Log(("... done\n"));
+}
+
+/* Function Name: PrintThisManpage
+ * Description: Print the current manual page.
+ * Arguments: mg - manpage globals
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+PrintThisManpage(ManpageGlobals *mg)
+{
+ Dimension width, height;
+ Position x, y;
+ Widget parent = mg->This_Manpage;
+ Widget topwindow = mg->This_Manpage;
+ Log(("print!\n"));
+
+ if (!mg->printdialog) {
+ int n;
+ Arg args[20];
+
+ n = 0;
+ XtSetArg(args[n], XtNallowShellResize, True); n++;
+ mg->printdialog_shell = XtCreatePopupShell("printdialogshell",
+ transientShellWidgetClass,
+ topwindow, args, n);
+ n = 0;
+ mg->printdialog = XtCreateManagedWidget("printdialog", printDialogWidgetClass,
+ mg->printdialog_shell, args, n);
+ XtAddCallback(mg->printdialog, XawNOkCallback, printOKXtProc, NULL);
+ XtAddCallback(mg->printdialog, XawNCancelCallback, printCancelXtProc, NULL);
+
+ XtRealizeWidget(mg->printdialog_shell);
+ }
+
+ /* Center dialog */
+ XtVaGetValues(mg->printdialog_shell,
+ XtNwidth, &width,
+ XtNheight, &height,
+ NULL);
+
+ x = (Position)(XWidthOfScreen( XtScreen(parent)) - width) / 2;
+ y = (Position)(XHeightOfScreen(XtScreen(parent)) - height) / 3;
+
+ XtVaSetValues(mg->printdialog_shell,
+ XtNx, x,
+ XtNy, y,
+ NULL);
+
+ XtPopup(mg->printdialog_shell, XtGrabNonexclusive);
+}
+
+
/* Function Name: ShowVersion
* Description: Show current version.
* Arguments: w - any widget in the manpage.
diff --git a/man.h b/man.h
index 576c40b..6a382ff 100644
--- a/man.h
+++ b/man.h
@@ -1,5 +1,5 @@
/* $XConsortium: man.h,v 1.31 94/12/16 21:36:53 gildea Exp $ */
-/* $XdotOrg: $ */
+/* $XdotOrg: xc/programs/xman/man.h,v 1.3 2004/05/22 19:20:06 alanc Exp $ */
/*
Copyright (c) 1987, 1988 X Consortium
@@ -43,6 +43,7 @@ from the X Consortium.
/* Std system and C header files */
#include <stdio.h>
+#include <limits.h>
#include <X11/Xfuncs.h>
#include <X11/Xos.h>
@@ -72,6 +73,13 @@ from the X Consortium.
#include "version.h"
#include "defs.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; }
+
/*
* Assigning values here allows the user of Bitwise Or.
*/
@@ -137,7 +145,13 @@ typedef struct _ManpageGlobals{
Widget dir_entry, manpage_entry, help_entry,
search_entry, both_screens_entry, remove_entry, open_entry,
- version_entry, quit_entry;
+ print_entry, version_entry, quit_entry;
+
+ /* Print objects and data */
+ Widget printdialog_shell; /* Shell for the print dialog */
+ Widget printdialog; /* Print dialog */
+
+ /* Misc. */
char manpage_title[80]; /* The label to use for the current manpage. */
@@ -157,6 +171,7 @@ typedef struct _ManpageGlobals{
Widget This_Manpage; /* a pointer to the root of
this manpage. */
+ FILE *curr_file; /* Current file shown in manpage widget */
} ManpageGlobals;
@@ -221,6 +236,7 @@ void Quit(Widget w, XEvent * event, String * params, Cardinal * num_params);
void RemoveThisManpage(Widget w, XEvent * event, String * params, Cardinal * num_params);
void SaveFormattedPage(Widget w, XEvent * event, String * params, Cardinal * num_params);
void Search(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void PrintThisManpage(ManpageGlobals *mg);
void ShowVersion(Widget w, XEvent * event, String * params, Cardinal * num_params);
/* help.c */
diff --git a/misc.c b/misc.c
index e2d4d00..77aafea 100644
--- a/misc.c
+++ b/misc.c
@@ -1,5 +1,5 @@
/* $XConsortium: misc.c,v 1.31 94/12/16 21:36:53 gildea Exp $ */
-/* $XdotOrg: $ */
+/* $XdotOrg: xc/programs/xman/misc.c,v 1.3 2004/05/22 19:20:06 alanc Exp $ */
/*
Copyright (c) 1987, 1988 X Consortium
@@ -153,8 +153,15 @@ OpenFile(ManpageGlobals * man_globals, FILE * file)
{
Arg arglist[1];
Cardinal num_args = 0;
+
+ if (man_globals->curr_file) {
+#if 0 /* Ownership rules need to be fixed first */
+ fclose(man_globals->curr_file);
+#endif
+ }
+ man_globals->curr_file = file;
- XtSetArg(arglist[num_args], XtNfile, file); num_args++;
+ XtSetArg(arglist[num_args], XtNfile, man_globals->curr_file); num_args++;
XtSetValues(man_globals->manpagewidgets.manpage, arglist, num_args);
}
diff --git a/print.c b/print.c
new file mode 100644
index 0000000..0b47b97
--- /dev/null
+++ b/print.c
@@ -0,0 +1,377 @@
+/*
+ * $Xorg: print.c,v 1.1 2004/04/30 02:05:54 gisburn Exp $
+ *
+Copyright 2004 Roland Mainz <roland.mainz@nrubsig.org>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ */
+
+/* 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; }
+
+#include "print.h"
+#include "ScrollByL.h"
+#include <X11/Xaw/Form.h>
+#include <X11/Xaw/Label.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static Widget
+CreatePrintShell(Widget videoshell,
+ Screen *pscreen,
+ String printshell_name,
+ ArgList args,
+ Cardinal numargs)
+{
+ String videoname,
+ videoclass;
+ Widget pappshell,
+ printshell;
+ Display *pdpy = XDisplayOfScreen(pscreen);
+ int dummyc = 0;
+ String dummys = "";
+ XtGetApplicationNameAndClass(XtDisplay(videoshell),
+ &videoname, &videoclass);
+
+ /* XXX: Why is the |dummyc|&&|dummys| stuff needed here ? */
+ XtDisplayInitialize(XtWidgetToApplicationContext(videoshell), pdpy,
+ videoname, videoclass,
+ NULL, 0,
+ &dummyc, &dummys);
+
+ pappshell = XtVaAppCreateShell(videoname, videoclass,
+ applicationShellWidgetClass,
+ pdpy,
+ XtNscreen, pscreen,
+ NULL);
+ printshell = XtCreatePopupShell(printshell_name,
+ xawPrintShellWidgetClass,
+ pappshell, args, numargs);
+
+
+ /* we're mapping/unmapping at start/end page time */
+ XtSetMappedWhenManaged(printshell, False);
+
+ /* We realise the widget when we're done with building the widget tree... */
+
+ return printshell;
+}
+
+typedef struct
+{
+ const char *programname;
+ Widget toplevel;
+ Bool isPrinting;
+ Widget printshell;
+ struct
+ {
+ Widget form;
+ Widget pageheaderlabel;
+ Widget manpage;
+ } content; /* content to print */
+ int numpages;
+ Display *pdpy;
+ Screen *pscreen;
+ XPContext pcontext;
+ XtCallbackProc pdpyDestroyCallback;
+ void *printtofile_handle;
+ const char *jobtitle;
+} AppPrintData;
+
+static AppPrintData apdx;
+static AppPrintData *apd = &apdx;
+
+/* "Count" pages in a scrollByLineWidgetClass widget */
+static
+long CountPages(Widget sblw)
+{
+ long num_pages = 0;
+ Cardinal n;
+ Arg args[3];
+ int num_total_lines = 0,
+ num_visible_lines = 0;
+
+ n = 0;
+ XtSetArg(args[n], XtNNumTotalLines, &num_total_lines); n++;
+ XtSetArg(args[n], XtNNumVisibleLines, &num_visible_lines); n++;
+ XtGetValues(sblw, args, n);
+
+#define DIV_ROUND_UP(a, b) (((a)+((b)-1)) / (b))
+ /* scrollByLineWidgetClass's "Page(forward)" always overlaps by one
+ * line so we use |num_visible_lines-1| instead of |num_visible_lines| */
+ num_pages = DIV_ROUND_UP(num_total_lines, num_visible_lines-1);
+#undef DIV_ROUND_UP
+
+ return num_pages;
+}
+
+static void
+PageSetupCB(Widget widget, XtPointer client_data, XtPointer call_data)
+{
+ Widget pshell = widget;
+ XawPrintShellCallbackStruct *psp = (XawPrintShellCallbackStruct *)call_data;
+ AppPrintData *p = (AppPrintData *)client_data;
+
+ Log(("--> PageSetupCB\n"));
+
+ if (!psp->last_page_in_job) {
+ int currpage;
+ char buffer[256];
+
+ XtVaGetValues(pshell, XawNcurrPageNumInJob, &currpage, NULL);
+
+ sprintf(buffer, "Title: %s / Page: %d/%d", p->jobtitle, currpage, p->numpages);
+ XtVaSetValues(apd->content.pageheaderlabel, XtNlabel, buffer, NULL);
+
+ /* Note: XawPrintShell's pagecount starts with '1'
+ * (=first page is page no. '1') */
+ if (currpage > 1) {
+ String params[] = { "Forward" };
+ Log(("pagedown %d\n", currpage));
+ /* "Page(Forward)" is scrollByLineWidgetClass's way to
+ * move one page forward */
+ XtCallActionProc(p->content.manpage, "Page", NULL, params, ONE);
+ }
+ else
+ {
+ Log(("first page\n"));
+ }
+
+ if (currpage >= p->numpages) {
+ psp->last_page_in_job = True;
+ }
+ }
+}
+
+static
+void FinishPrinting(AppPrintData *p)
+{
+ /* Wait for the job to finish */
+ if (p->printtofile_handle) {
+ if (XpuWaitForPrintFileChild(p->printtofile_handle) != XPGetDocFinished) {
+ fprintf(stderr, "%s: Error while printing to file.\n", apd->programname);
+ }
+ p->printtofile_handle = NULL;
+ }
+
+ /* Avoid that the manpage object tries to close the |FILE *|-handle at destruction time */
+ XtVaSetValues(p->content.manpage, XtNfile, NULL, NULL);
+
+ if (p->printshell) {
+ XtDestroyWidget(p->printshell);
+ p->printshell = NULL;
+ }
+
+ /* 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)(p->toplevel, 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;
+ p->pdpy = NULL;
+ p->pscreen = NULL;
+ p->pcontext = None;
+}
+
+static
+void PrintEndJobCB(Widget pshell, XtPointer client_data, XtPointer call_data)
+{
+ AppPrintData *p = (AppPrintData *)client_data;
+
+ Log(("--> PrintEndJobCB\n"));
+
+ /* Finish printing and destroy print shell (it's legal to destroy Xt
+ * widgets from within it's own callbacks) */
+ FinishPrinting(p);
+}
+
+static
+XFontStruct *GetPrintTextFont(Display *pdpy, const char *fontprefix, long dpi)
+{
+ XFontStruct *font;
+ char fontname[1024];
+
+ sprintf(fontname, "%s--*-120-%ld-%ld-*-*-iso8859-1", fontprefix, dpi, dpi);
+ font = XLoadQueryFont(pdpy, fontname);
+ if (!font) {
+ sprintf(fontname, "-adobe-courier-medium-r-normal--*-120-%ld-%ld-*-*-iso8859-1", dpi, dpi);
+ font = XLoadQueryFont(pdpy, fontname);
+ }
+ if (!font) {
+ sprintf(fontname, "-*-*-*-*-*-*-*-120-%ld-%ld-*-*-iso8859-1", dpi, dpi);
+ font = XLoadQueryFont(pdpy, fontname);
+ }
+ if (!font)
+ Error(("XLoadQueryFont failure.\n"));
+ return font;
+
+}
+
+void DoPrintManpage(const char *programname,
+ FILE *manpagefile, Widget toplevel,
+ Display *pdpy, XPContext pcontext,
+ XtCallbackProc pdpyDestroyCB,
+ const char *jobtitle, const char *toFile)
+{
+ long dpi = 0;
+ int n;
+ Arg args[20];
+ XFontStruct *printFontNormal;
+ XFontStruct *printFontBold;
+ XFontStruct *printFontItalic;
+ XFontStruct *printFontSymbol;
+
+ if (!manpagefile) {
+ Error(("DoPrintManpage: No FILE given."));
+ }
+
+ apd->programname = programname;
+ apd->pdpyDestroyCallback = pdpyDestroyCB;
+
+ if (apd->isPrinting) {
+ fprintf(stderr, "%s: Already busy with printing.\n", apd->programname);
+ return;
+ }
+
+ /* Configure the print context (paper size, title etc.)
+ * We must do this before creating any Xt widgets - otherwise they will
+ * make wrong assuptions about fonts, resultions etc. ...
+ */
+ XpuSetJobTitle(pdpy, pcontext, jobtitle);
+
+ /* Configuration done, set the context */
+ XpSetContext(pdpy, pcontext);
+
+ /* Get default printer resolution */
+ if (XpuGetResolution(pdpy, pcontext, &dpi) != 1) {
+ fprintf(stderr, "%s: No default resolution for printer.\n", apd->programname);
+ XpuClosePrinterDisplay(pdpy, pcontext);
+ return;
+ }
+
+ apd->toplevel = toplevel;
+ apd->pdpy = pdpy;
+ apd->pcontext = pcontext;
+ apd->pscreen = XpGetScreenOfContext(pdpy, pcontext);
+ apd->jobtitle = jobtitle;
+
+ n = 0;
+ XtSetArg(args[n], XawNlayoutMode, XawPrintLAYOUTMODE_DRAWABLEAREA); n++;
+ apd->printshell = CreatePrintShell(toplevel, apd->pscreen, "printshell", 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);
+
+ printFontNormal = GetPrintTextFont(pdpy, "-*-courier-medium-r-*", dpi);
+ printFontBold = GetPrintTextFont(pdpy, "-*-courier-bold-r-*", dpi);
+ printFontItalic = GetPrintTextFont(pdpy, "-*-courier-medium-o-*", dpi);
+ printFontSymbol = GetPrintTextFont(pdpy, "-*-symbol-*-*-*", dpi);
+
+ n = 0;
+ XtSetArg(args[n], XtNfromHoriz, NULL); n++;
+ XtSetArg(args[n], XtNfromVert, NULL); n++;
+ XtSetArg(args[n], XtNtop, XtChainTop); n++;
+ XtSetArg(args[n], XtNright, XtChainRight); n++;
+ XtSetArg(args[n], XtNresizable, True); n++;
+ XtSetArg(args[n], XtNfont, printFontNormal); n++; /* fontset would be better */
+ 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);
+
+ n = 0;
+ XtSetArg(args[n], XtNfile, manpagefile); n++;
+
+/* 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
+ * text widget squishes itself into the bottom half of the page and only occupies
+ * 1/2 of the page's with... ;-(( */
+#define WORKAROUND_FOR_SOMETHING_IS_WRONG 1
+#ifdef WORKAROUND_FOR_SOMETHING_IS_WRONG
+ XtSetArg(args[n], XtNtop, XtChainTop); n++;
+ XtSetArg(args[n], XtNright, XtChainRight); n++;
+ XtSetArg(args[n], XtNvertDistance, (printFontNormal->ascent+printFontNormal->descent+2)*2); n++;
+#else
+ XtSetArg(args[n], XtNfromHoriz, NULL); n++;
+ XtSetArg(args[n], XtNfromVert, apd->content.pageheaderlabel); n++;
+#endif
+
+ XtSetArg(args[n], XtNmanualFontNormal, printFontNormal); n++;
+ XtSetArg(args[n], XtNmanualFontBold, printFontBold); n++;
+ XtSetArg(args[n], XtNmanualFontItalic, printFontItalic); n++;
+ XtSetArg(args[n], XtNmanualFontSymbol, printFontSymbol); n++;
+ apd->content.manpage = XtCreateManagedWidget("manpage", scrollByLineWidgetClass, apd->content.form, args, n);
+
+ XtAddCallback(apd->printshell, XawNpageSetupCallback, PageSetupCB, (XtPointer)apd);
+ XtAddCallback(apd->printshell, XawNendJobCallback, PrintEndJobCB, (XtPointer)apd);
+
+ /* Realise print shell (which will set position+size of the child
+ * widgets based on the current page size) */
+ XtRealizeWidget(apd->printshell);
+
+ /* Count number of pages in the manpage widget */
+ apd->numpages = CountPages(apd->content.manpage);
+
+ /* Make sure that the Xt machinery is really using the right screen (assertion) */
+ if (XpGetScreenOfContext(XtDisplay(apd->printshell), apd->pcontext) != XtScreen(apd->printshell))
+ Error(("Widget's screen != print screen. BAD.\n"));
+
+ apd->isPrinting = True;
+
+ if (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");
+ apd->isPrinting = False;
+ return;
+ }
+ }
+ else
+ {
+ printf("%s: Printing to printer...\n", apd->programname);
+ XpuStartJobToSpooler(pdpy);
+ }
+}
+
+
diff --git a/print.h b/print.h
new file mode 100644
index 0000000..0466563
--- /dev/null
+++ b/print.h
@@ -0,0 +1,47 @@
+/*
+ * $Xorg: print.h,v 1.1 2004/04/30 02:05:54 gisburn Exp $
+ *
+Copyright 2004 Roland Mainz <roland.mainz@nrubsig.org>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ */
+
+#ifndef XMAN_PRINT_H
+#define XMAN_PRINT_H 1
+
+#include <X11/Intrinsic.h>
+#include <X11/StringDefs.h>
+#include <X11/Shell.h>
+#include <X11/Xaw/Print.h>
+#include <X11/Xaw/Cardinals.h>
+#include <X11/XprintUtil/xprintutil.h>
+
+/* Prototypes */
+void DoPrintManpage(const char *programname,
+ FILE *manpage,
+ Widget toplevel,
+ Display *pdpy, XPContext pcontext,
+ XtCallbackProc printDisplayDestroyCallback,
+ const char *jobTitle,
+ const char *toFile);
+
+#endif /* !XMAN_PRINT_H */
diff --git a/search.c b/search.c
index 48d048a..542d2de 100644
--- a/search.c
+++ b/search.c
@@ -265,7 +265,7 @@ DoSearch(ManpageGlobals * man_globals, int type)
strcpy(man_globals->manpage_title,label);
ChangeLabel(man_globals->label,label);
- fseek(file, 0L, 0); /* reset file to point at top. */
+ fseek(file, 0L, SEEK_SET); /* reset file to point at top. */
}
else { /* MANUAL SEACH */
file = DoManualSearch(man_globals, search_string);
diff --git a/version.h b/version.h
index ff3ade8..d715308 100644
--- a/version.h
+++ b/version.h
@@ -29,4 +29,4 @@ from the X Consortium.
*/
-#define XMAN_VERSION "Xman Version 3.1.6 - X11R6."
+#define XMAN_VERSION "Xman Version 3.2.0 - X11R6.7.1"