summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Mainz <roland.mainz@nrubsig.org>2004-05-30 22:44:01 +0000
committerRoland Mainz <roland.mainz@nrubsig.org>2004-05-30 22:44:01 +0000
commitcf44083fa20c4f39a89a63ced16974c832039325 (patch)
tree67d06e3aab038d423ea38299395483bda6fec6d6
parent3b70888a54396c1b5ab67be863b189c7b8775695 (diff)
Fix for http://freedesktop.org/bugzilla/show_bug.cgi?id=695 - Add print
support to Xedit
-rw-r--r--commands.c124
-rw-r--r--hook.c4
-rw-r--r--ispell.c22
-rw-r--r--print.c21
-rw-r--r--print.h14
-rw-r--r--xedit.c24
-rw-r--r--xedit.h3
7 files changed, 161 insertions, 51 deletions
diff --git a/commands.c b/commands.c
index f3d889e..7fd5990 100644
--- a/commands.c
+++ b/commands.c
@@ -29,10 +29,14 @@
#include <X11/Xfuncs.h>
#include <X11/Xos.h>
#include "xedit.h"
+#include "printdialog.h"
+#include "print.h"
#ifdef CRAY
#include <unistd.h>
#endif
#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
#include <string.h>
#include <dirent.h>
#include <pwd.h>
@@ -41,6 +45,17 @@
#include <X11/IntrinsicP.h>
#include <X11/Xaw/TextSrcP.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; }
+
+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.
diff --git a/hook.c b/hook.c
index 5e10a39..9352ea4 100644
--- a/hook.c
+++ b/hook.c
@@ -388,9 +388,11 @@ LineEditAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
XawTextBlock block;
- if (international)
+ if (True) {
/* XXX FIXME */
+ fprintf(stderr, "LineEditAction: Not working in international mode.\n");
return;
+ }
block.firstPos = 0;
block.format = FMT8BIT;
diff --git a/ispell.c b/ispell.c
index 037699d..3706c34 100644
--- a/ispell.c
+++ b/ispell.c
@@ -27,7 +27,7 @@
* Author: Paulo César Pereira de Andrade
*/
-/* $XdotOrg: xc/programs/xedit/ispell.c,v 1.20 2003/12/19 02:05:39 dawes Exp $ */
+/* $XdotOrg: xc/programs/xedit/ispell.c,v 1.2 2004/04/23 19:54:43 eich Exp $ */
/* $XFree86: xc/programs/xedit/ispell.c,v 1.19 2002/10/19 20:04:20 herrb Exp $ */
#include "xedit.h"
@@ -938,10 +938,7 @@ IspellSend(void)
return (-1);
}
for (i = 0; i < block.length; i++) {
- if (international)
- wctomb(mb, ((wchar_t*)block.ptr)[i]);
- else
- *mb = block.ptr[i];
+ wctomb(mb, ((wchar_t*)block.ptr)[i]);
if (amplen) {
if (amplen + 2 >= sizeof(ampbuf)) {
if (!ispell.terse_mode)
@@ -1039,10 +1036,7 @@ IspellSend(void)
return (-1);
}
for (i = 0; i < block.length; i++) {
- if (international)
- wctomb(mb, ((wchar_t*)block.ptr)[i]);
- else
- *mb = block.ptr[i];
+ wctomb(mb, ((wchar_t*)block.ptr)[i]);
if (amplen) {
if (amplen + 2 >= sizeof(ampbuf)) {
if (!ispell.terse_mode)
@@ -1566,18 +1560,12 @@ ReplaceIspell(Widget w, XtPointer client_data, XtPointer call_data)
char mb[sizeof(wchar_t)];
if (XawTextSourceRead(ispell.source, pos - 1, &check, 1) > 0) {
- if (international)
- wctomb(mb, *(wchar_t*)check.ptr);
- else
- *mb = *check.ptr;
+ wctomb(mb, *(wchar_t*)check.ptr);
do_replace = !isalpha(*mb) && *mb && !strchr(ispell.wchars, *mb);
}
if (do_replace &&
XawTextSourceRead(ispell.source, pos + search.length, &check, 1) > 0) {
- if (international)
- wctomb(mb, *(wchar_t*)check.ptr);
- else
- *mb = *check.ptr;
+ wctomb(mb, *(wchar_t*)check.ptr);
do_replace = !isalpha(*mb) && *mb && !strchr(ispell.wchars, *mb);
}
if (do_replace) {
diff --git a/print.c b/print.c
index d44b97e..73dcd0a 100644
--- a/print.c
+++ b/print.c
@@ -265,15 +265,15 @@ XFontSet GetPrintTextFontSet(const char *appname, Display *pdpy, long dpi)
}
if (!fontset)
- Error(("XCreateFontSet() failure.\n"));
+ Error(("GetPrintTextFontSet: XCreateFontSet() failure.\n"));
return fontset;
}
-void DoPrint(const char *programname,
- Widget textsource, Widget toplevel,
- Display *pdpy, XPContext pcontext,
- XtCallbackProc pdpyDestroyCB,
- const char *jobtitle, const char *toFile)
+void DoPrintTextSource(const char *programname,
+ Widget textsource, Widget toplevel,
+ Display *pdpy, XPContext pcontext,
+ XtCallbackProc pdpyDestroyCB,
+ const char *jobtitle, const char *toFile)
{
long dpi = 0;
int n;
@@ -313,7 +313,7 @@ void DoPrint(const char *programname,
n = 0;
XtSetArg(args[n], XawNlayoutMode, XawPrintLAYOUTMODE_DRAWABLEAREA); n++;
- apd->printshell = CreatePrintShell(toplevel, apd->pscreen, "print", args, n);
+ apd->printshell = CreatePrintShell(toplevel, apd->pscreen, "printshell", args, n);
n = 0;
XtSetArg(args[n], XtNresizable, True); n++;
@@ -324,6 +324,7 @@ void DoPrint(const char *programname,
#ifdef PRINT_PAGEHEADER
n = 0;
+ XtSetArg(args[n], XtNinternational, True); n++;
XtSetArg(args[n], XtNfromHoriz, NULL); n++;
XtSetArg(args[n], XtNfromVert, NULL); n++;
XtSetArg(args[n], XtNtop, XtChainTop); n++;
@@ -335,13 +336,14 @@ void DoPrint(const char *programname,
apd->content.pageheaderlabel = XtCreateManagedWidget("pageinfo", labelWidgetClass, apd->content.form, args, n);
#endif /* PRINT_PAGEHEADER */
+ font_extents = XExtentsOfFontSet(textfontset);
+
n = 0;
+ XtSetArg(args[n], XtNinternational, True); 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
@@ -358,6 +360,7 @@ void DoPrint(const char *programname,
#endif
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);
diff --git a/print.h b/print.h
index e098531..69321a1 100644
--- a/print.h
+++ b/print.h
@@ -36,12 +36,12 @@ in this Software without prior written authorization from The Open Group.
#include <X11/XprintUtil/xprintutil.h>
/* Prototypes */
-void DoPrint(const char *programname,
- Widget textsource,
- Widget toplevel,
- Display *pdpy, XPContext pcontext,
- XtCallbackProc printDisplayDestroyCallback,
- const char *jobTitle,
- const char *toFile);
+void DoPrintTextSource(const char *programname,
+ Widget textsource,
+ Widget toplevel,
+ Display *pdpy, XPContext pcontext,
+ XtCallbackProc printDisplayDestroyCallback,
+ const char *jobTitle,
+ const char *toFile);
#endif /* !XMORE_PRINT_H */
diff --git a/xedit.c b/xedit.c
index 8648c06..ccab87d 100644
--- a/xedit.c
+++ b/xedit.c
@@ -41,6 +41,7 @@ static XtActionsRec actions[] = {
{"quit", QuitAction},
{"save-file", SaveFile},
{"load-file", LoadFile},
+{"print-file", PrintFile},
{"find-file", FindFile},
{"cancel-find-file", CancelFindFile},
{"file-completion", FileCompletion},
@@ -71,7 +72,6 @@ static XawTextPositionInfo infos[3];
Widget topwindow, textwindow, messwidget, labelwindow, filenamewindow;
Widget scratch, hpane, vpanes[2], labels[3], texts[3], forms[3], positions[3];
Widget options_popup, dirlabel, dirwindow;
-Boolean international;
Boolean line_edit;
XawTextWrapMode wrapmodes[3];
@@ -111,6 +111,11 @@ static XtResource resources[] = {
#undef Offset
+String fallback_resources[] = {
+ "*international: True", /* set this globally for ALL widgets to avoid wiered crashes */
+ NULL
+};
+
int
main(int argc, char *argv[])
{
@@ -118,7 +123,7 @@ main(int argc, char *argv[])
unsigned num_loaded = 0;
XtSetLanguageProc(NULL, NULL, NULL);
- topwindow = XtAppInitialize(&appcon, "Xedit", NULL, 0, &argc, argv, NULL, NULL, 0);
+ topwindow = XtAppInitialize(&appcon, "Xedit", NULL, 0, &argc, argv, fallback_resources, NULL, 0);
XtAppAddActions(appcon, actions, XtNumber(actions));
XtOverrideTranslations
@@ -240,9 +245,8 @@ main(int argc, char *argv[])
flags = 0;
XtSetArg(args[num_args], XtNstring, NULL); num_args++;
}
- source = XtVaCreateWidget("textSource", international ?
- multiSrcObjectClass
- : asciiSrcObjectClass, topwindow,
+ source = XtVaCreateWidget("textSource",
+ multiSrcObjectClass, topwindow,
XtNtype, XawAsciiFile,
XtNeditType, XawtextEdit,
NULL, NULL);
@@ -302,6 +306,7 @@ makeButtonsAndBoxes(Widget parent)
MakeCommandButton(b_row, "quit", DoQuit);
MakeCommandButton(b_row, "save", DoSave);
MakeCommandButton(b_row, "load", DoLoad);
+ MakeCommandButton(b_row, "print", DoPrint);
filenamewindow = MakeStringBox(b_row, "filename", NULL);
}
hintswindow = XtCreateManagedWidget("bc_label", labelWidgetClass,
@@ -347,15 +352,10 @@ makeButtonsAndBoxes(Widget parent)
textwindow = XtCreateManagedWidget(editWindow, asciiTextWidgetClass,
vpanes[0], arglist, num_args);
num_args = 0;
- XtSetArg(arglist[num_args], XtNinternational, &international); ++num_args;
- XtGetValues(textwindow, arglist, num_args);
-
- num_args = 0;
XtSetArg(arglist[num_args], XtNtype, XawAsciiFile); ++num_args;
XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); ++num_args;
- scratch = XtVaCreateWidget("textSource", international ?
- multiSrcObjectClass
- : asciiSrcObjectClass, topwindow,
+ scratch = XtVaCreateWidget("textSource",
+ multiSrcObjectClass, topwindow,
XtNtype, XawAsciiFile,
XtNeditType, XawtextEdit,
NULL, NULL);
diff --git a/xedit.h b/xedit.h
index f347aa3..88cec65 100644
--- a/xedit.h
+++ b/xedit.h
@@ -100,7 +100,6 @@ extern struct _app_resources {
extern Widget topwindow, textwindow, labelwindow, filenamewindow, messwidget;
extern Widget dirlabel, dirwindow;
-extern Boolean international;
extern Boolean line_edit;
/* externals in xedit.c */
@@ -132,9 +131,11 @@ void QuitAction(Widget, XEvent*, String*, Cardinal*);
void DoSave(Widget, XtPointer, XtPointer);
void SaveFile(Widget, XEvent*, String*, Cardinal*);
void DoLoad(Widget, XtPointer, XtPointer);
+void DoPrint(Widget, XtPointer, XtPointer);
void CancelFindFile(Widget, XEvent*, String*, Cardinal*);
void FindFile(Widget, XEvent*, String*, Cardinal*);
void LoadFile(Widget, XEvent*, String*, Cardinal*);
+void PrintFile(Widget, XEvent*, String*, Cardinal*);
void FileCompletion(Widget, XEvent*, String*, Cardinal*);
void KillFile(Widget, XEvent*, String*, Cardinal*);
void DirWindowCB(Widget, XtPointer, XtPointer);