From cf44083fa20c4f39a89a63ced16974c832039325 Mon Sep 17 00:00:00 2001 From: Roland Mainz Date: Sun, 30 May 2004 22:44:01 +0000 Subject: Fix for http://freedesktop.org/bugzilla/show_bug.cgi?id=695 - Add print support to Xedit --- commands.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 4 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index f3d889e..7fd5990 100644 --- a/commands.c +++ b/commands.c @@ -29,10 +29,14 @@ #include #include #include "xedit.h" +#include "printdialog.h" +#include "print.h" #ifdef CRAY #include #endif #include +#include +#include #include #include #include @@ -41,6 +45,17 @@ #include #include +/* 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; } + +static Widget printdialog_shell = NULL; +static Widget printdialog = NULL; +static char printJobNameBuffer[PATH_MAX+256]; + void ResetSourceChanged(xedit_flist_item*); static void ResetDC(Widget, XtPointer, XtPointer); @@ -338,8 +353,8 @@ DoSave(Widget w, XtPointer client_data, XtPointer call_data) XtRemoveCallback(scratch, XtNcallback, SourceChanged, (XtPointer)item); item->source = scratch = - XtVaCreateWidget("textSource", international ? - multiSrcObjectClass : asciiSrcObjectClass, + XtVaCreateWidget("textSource", + multiSrcObjectClass, topwindow, XtNtype, XawAsciiFile, XtNeditType, XawtextEdit, @@ -476,8 +491,8 @@ ReallyDoLoad(char *name, char *filename) XtSetArg(args[num_args], XtNstring, NULL); num_args++; } - source = XtVaCreateWidget("textSource", international ? - multiSrcObjectClass : asciiSrcObjectClass, + source = XtVaCreateWidget("textSource", + multiSrcObjectClass, topwindow, XtNtype, XawAsciiFile, XtNeditType, XawtextEdit, @@ -500,6 +515,107 @@ ReallyDoLoad(char *name, char *filename) return (True); } +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(textwindow, 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, "Xedit print job"); + + DoPrintTextSource("Xedit", + textsource, topwindow, + pdcs->pdpy, pdcs->pcontext, printshellDestroyXtProc, + printJobNameBuffer, + pdcs->printToFile?pdcs->printToFileName:NULL); + + XtPopdown(printdialog_shell); +} + +static void +printCancelXtProc(Widget w, XtPointer client_data, XtPointer callData) +{ + Log(("printCancelXtProc: cancel.\n")); + XtPopdown(printdialog_shell); + + Log(("destroying print dialog shell...\n")); + XtDestroyWidget(printdialog_shell); + printdialog_shell = NULL; + printdialog = NULL; + Log(("... done\n")); +} + + +/*ARGSUSED*/ +void +PrintFile(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + DoPrint(w, NULL, NULL); +} + +/*ARGSUSED*/ +void +DoPrint(Widget w, XtPointer client_data, XtPointer call_data) +{ + Dimension width, height; + Position x, y; + Widget parent = topwindow; + Log(("print!\n")); + + if (!printdialog) { + int n; + Arg args[20]; + + n = 0; + XtSetArg(args[n], XtNallowShellResize, True); n++; + printdialog_shell = XtCreatePopupShell("printdialogshell", + transientShellWidgetClass, + topwindow, args, n); + n = 0; + printdialog = XtCreateManagedWidget("printdialog", printDialogWidgetClass, + printdialog_shell, args, n); + XtAddCallback(printdialog, XawNOkCallback, printOKXtProc, NULL); + XtAddCallback(printdialog, XawNCancelCallback, printCancelXtProc, NULL); + + XtRealizeWidget(printdialog_shell); + } + + /* Center dialog */ + XtVaGetValues(printdialog_shell, + XtNwidth, &width, + XtNheight, &height, + NULL); + + x = (Position)(XWidthOfScreen( XtScreen(parent)) - width) / 2; + y = (Position)(XHeightOfScreen(XtScreen(parent)) - height) / 3; + + XtVaSetValues(printdialog_shell, + XtNx, x, + XtNy, y, + NULL); + + XtPopup(printdialog_shell, XtGrabNonexclusive); +} + /* Function Name: SourceChanged * Description: A callback routine called when the source has changed. * Arguments: w - the text source that has changed. -- cgit v1.2.3