Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,141 @@
/* $XConsortium: AppSpecific.c /main/4 1996/05/09 03:39:11 drk $ */
#include "PrintDemo.h"
/*
* ------------------------------------------------------------------------
* Name: AppObject_new
*
* Description:
*
* Allocates a new AppObject data structure. If parent is non-NULL,
* an application-specific main window work region is created.
*
* Return value:
*
* A pointer to the new AppObject structure.
*
*/
#define LABEL_FMTSTR "Filename: %s Size: %d"
static char *
ReadFile(char * filename, int * filesize)
{
char *buffer = NULL;
FILE * file;
*filesize = 0 ;
if ((file = fopen(filename, "r")) == NULL) return NULL ;
fseek(file, 0L, SEEK_END);
*filesize = ftell(file);
rewind(file);
buffer = (char *) malloc(*filesize+1);
if (fread(buffer, 1, *filesize, file) == *filesize ) {
buffer[*filesize] = '\0';
return buffer;
}
free(buffer);
return NULL;
}
AppObject*
AppObject_new(
Widget parent,
String file_name)
{
AppObject* me = (AppObject*)XtCalloc(1, sizeof(AppObject));
int filesize ;
me->main_window = parent ;
if(file_name != (String)NULL)
me->file_name = XtNewString(file_name);
else
me->file_name = XtNewString("README.txt");
me->file_buffer = ReadFile(me->file_name, &filesize);
if (me->file_buffer == NULL) {
me->file_buffer = XtNewString("abcdefghijklmnopqrstuvwxyz");
filesize = strlen("abcdefghijklmnopqrstuvwxyz");
}
if(parent != (Widget)NULL)
{
XmString label;
String buf;
buf = XtCalloc(strlen(LABEL_FMTSTR)+strlen(me->file_name)+10,
sizeof(char));
sprintf(buf, LABEL_FMTSTR, me->file_name, filesize);
label = XmStringCreateLocalized(buf);
XtFree(buf);
me->widget =
XtVaCreateManagedWidget("AppWorkArea",
xmLabelWidgetClass,
parent,
XmNlabelString, label,
NULL);
XmStringFree(label);
}
return me;
}
/*
* ------------------------------------------------------------------------
* Name: AppObject_customizePrintSetupBox
*
* Description:
*
* Adds application specific items to the passed print setup box.
*
* The document file name is presented in the top work area.
*
* Return value:
*
* None.
*
*/
void
AppObject_customizePrintSetupBox(
AppObject* me,
Widget print_dialog)
{
Widget row;
XmString label;
Widget w;
/*
* create the app-specific top work area
*/
XtVaSetValues(print_dialog,
DtNworkAreaLocation, DtWORK_AREA_TOP,
NULL);
row = XtVaCreateManagedWidget(
"DocumentNameRow",
xmRowColumnWidgetClass,
print_dialog,
XmNorientation, XmHORIZONTAL,
NULL);
/*
* create the document name label
*/
label = XmStringCreateLocalized("Document:");
w = XtVaCreateManagedWidget("DocumentNameLabel",
xmLabelGadgetClass,
row,
XmNlabelString, label,
NULL);
XmStringFree(label);
/*
* create the document name
*/
label = XmStringCreateLocalized(me->file_name);
w = XtVaCreateManagedWidget("DocumentName",
xmLabelGadgetClass,
row,
XmNlabelString, label,
NULL);
XmStringFree(label);
}

View File

@@ -0,0 +1,27 @@
/* $XConsortium: AppSpecific.h /main/4 1996/05/09 03:39:24 drk $ */
/*
* constant definitions
*/
#define APP_CLASS "Dtprint"
/*
* Application-specific "object"
*/
typedef struct _AppObject
{
Widget main_window ;
Widget widget;
String file_name;
char * file_buffer ;
} AppObject;
/*
* public AppObject functions
*/
extern AppObject* AppObject_new(
Widget parent,
String file_name);
extern void AppObject_customizePrintSetupBox(
AppObject* me,
Widget print_dialog);

View File

@@ -0,0 +1,8 @@
Dtprint.Print*background:white
Dtprint.Print*renderTable:-dt-application-medium-r-normal-serif-0-0-0-0-m-0-*-*:
Dtprint.Print*shadowThickness:0
Dtprint.Print*highlightThickness:0
Dtprint.Print*pform.marginHeight: 1in
Dtprint.Print*pform.marginWidth: 1in
Dtprint.Print*ptext.Attachment:attach_form
Dtprint.Print*ptext.wordWrap:True

View File

@@ -0,0 +1,60 @@
XCOMM $XConsortium: Imakefile /main/7 1996/10/09 14:02:30 drk $
DESKTOP_VERSION_STRING = DesktopVersionString
/* General case INCLUDES DEFINES LOCAL_LIBRARIES
* Each individual architecture may have more or less of the above.
* USE_libraryname in LOCAL_LIBRARIES is by default empty.
* It should be set when necessary to the real library macro name.
*/
DEFINES = -DXK_MISCELLANY -DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\"
INCLUDES = -I.
/* DEPLIBS contains the list of library depencies for a client.
* LOCAL_LIBRARIES contains the list of libraries on the link line.
* Generally, the dependency form of a library has DEP as a prefix.
* e.g. put $(XLIB) in LOCAL_LIBRARIES and $(DEPXLIB) in DEPLIBS.
* NOTE: if DEPLIBS is not set here, it is by default null and there
* are no library dependencies for clients.
* You cannot put -Llibpath into DEPLIBS. You must put actual
* paths to the library.
*/
DEPLIBS = $(DEPDTPRINTLIB) $(DEPDTHELPLIB) $(DEPDTSVCLIB) \
$(DEPXMLIB) $(DEPXTOOLLIB) $(DEPXLIB)
LOCAL_LIBRARIES = $(DTPRINTLIB) $(DTHELPLIB) $(DTSVCLIB) $(XMLIB) \
$(XTOOLLIB) $(XLIB) -L/proj/x11/xc/usrlib -lXp
SYS_LIBRARIES = -lm
#ifdef RsArchitecture
SYS_LIBRARIES = -lmsaa -liconv
#endif
#if defined (SunArchitecture)
SYS_LIBRARIES = -lintl -L/opt/SUNWspro/SC2.0.1 -lm -lgen -ldl -lC
#endif
#if defined (USLArchitecture)
SYS_LIBRARIES = -lm -lnsl -lsocket -lgen
#endif
#if defined(HPOSFArchitecture)
#endif
PROGRAMS=dtprint
OBJS = \
AppSpecific.o \
Main.o \
MainWindow.o \
Print.o
SRCS = \
AppSpecific.c \
Main.c \
MainWindow.c \
Print.c
all::
NormalLibraryObjectRule()
ComplexProgramTarget($(PROGRAMS))

222
cde/examples/dtprint/Main.c Normal file
View File

@@ -0,0 +1,222 @@
/* $XConsortium: Main.c /main/6 1996/06/07 12:04:30 daniel $ */
#include "PrintDemo.h"
/*
* VideoShell structure definition
*/
typedef struct _VideoShell
{
Widget widget;
Boolean print_only;
String file_name;
} VideoShell;
/*
* application-level resources
*/
static XrmOptionDescRec XrmOptions[] =
{
{"-print", "printOnly", XrmoptionNoArg, (caddr_t)"True"},
{"-fileName", "fileName", XrmoptionSepArg, (caddr_t)NULL},
};
static XtResource VideoResources[] =
{
{"printOnly", "PrintOnly", XmRBoolean, sizeof (Boolean),
XtOffsetOf (VideoShell, print_only), XmRImmediate, (XtPointer)False,
},
{"fileName", "FileName", XmRString, sizeof (char *),
XtOffsetOf (VideoShell, file_name), XmRImmediate, (XtPointer)NULL,
},
};
/*
* static function declarations
*/
static VideoShell* VideoShell_new(Display* display);
/*
* ------------------------------------------------------------------------
* Name: VideoShell_new
*
* Description:
*
* Allocates a new VideoShell data structure.
*
* This function creates a top level application shell on the passed
* video display.
*
* Return value:
*
* A pointer to the new VideoShell structure.
*/
static VideoShell*
VideoShell_new(Display* display)
{
VideoShell* me = (VideoShell*)XtCalloc(1, sizeof(VideoShell));
me->widget = XtVaAppCreateShell(NULL, APP_CLASS,
applicationShellWidgetClass,
display,
XmNtitle, "DtPrint Demo",
NULL);
XtGetApplicationResources(me->widget, me,
VideoResources, XtNumber(VideoResources),
NULL, 0);
return me;
}
/*
* ------------------------------------------------------------------------
* Name: CloseProgramCB
*
* Description:
*
* Exit the program.
*
* Return value:
*
* None.
*/
void
CloseProgramCB(
Widget w,
XtPointer client_data,
XtPointer call_data)
{
AppPrintData * p = (AppPrintData *) client_data ;
/* we want to wait for the current job to complete before exiting */
/* if a job is running, just unmap the windows and install itself
as endjob callback, which will be called when printed_lines is
back to zero */
if (p->printed_lines) {
/* put up a dialog saying it's waiting for the job
to complete */
XtAddCallback(p->print_shell, XmNendJobCallback, CloseProgramCB, p);
} else {
exit(0);
}
}
static String fallbacks[] = {
"Dtprint.Print*background:white",
"Dtprint.Print*renderTable:-dt-application-bold-r-normal-serif-0-0-0-0-p-0-iso8859-1",
"Dtprint.Print*shadowThickness:0",
"Dtprint.Print*highlightThickness:0",
"Dtprint.Print*pform.marginHeight: 1in",
"Dtprint.Print*pform.marginWidth: 1in",
"Dtprint.Print*ptext.Attachment:attach_form",
NULL
};
/*
* ------------------------------------------------------------------------
* Name: main
*
* Description:
*
* "main" function for the DtPrint demo program.
*
*
*/
int main(int argc, char* argv[])
{
XtAppContext app_context;
VideoShell* video_shell;
MainWindow* main_window;
Display* video_display;
AppPrintData* p;
/*
* attempt to open the X video display
*/
XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
XtToolkitInitialize();
app_context = XtCreateApplicationContext();
video_display = XtOpenDisplay(app_context, NULL, NULL, APP_CLASS,
XrmOptions, XtNumber(XrmOptions),
&argc, argv);
XtAppSetFallbackResources(app_context, fallbacks);
if(video_display == (Display*)NULL)
{
/*
* parse command line and determine if "GUI-less" printing is
* desired
*/
/*
* XXX exit for now
*/
fprintf(stderr, "unable to open display\n");
return 1;
}
/*
* Create the top level video shell
*/
video_shell = VideoShell_new(video_display);
/*
* one AppPrintData object per app
*/
p = AppPrintData_new();
p->print_only = video_shell->print_only;
/*
* check to see if we're running the app, or just printing (e.g. from
* within a print action)
*/
if(video_shell->print_only)
{
/*
* create the application-specific object, and add it to the
* AppPrintData structure.
*/
p->app_object = AppObject_new((Widget)NULL, video_shell->file_name);
/*
* create the print setup box as the child of the top level shell
*/
CreatePrintSetup(video_shell->widget, p);
/*
* set the cancel button to exit the program
*/
XtAddCallback(p->print_dialog, DtNcancelCallback, CloseProgramCB, p);
/*
* manage the print setup box
*/
XtManageChild(p->print_dialog);
}
else
{
/*
* create the main window
*/
main_window = MainWindow_new(video_shell->widget);
/*
* add callbacks to the main window
*/
XtAddCallback(main_window->print_menu_button, XmNactivateCallback,
PrintMenuCB, p);
p->pr_button = main_window->print_menu_button;
XtAddCallback(main_window->quick_print_button, XmNactivateCallback,
QuickPrintCB, p);
XtAddCallback(main_window->exit_button, XmNactivateCallback,
CloseProgramCB, p);
/*
* create the application-specific object, and add it to the
* AppPrintData structure.
*/
p->app_object =
AppObject_new(main_window->widget, video_shell->file_name);
/*
* manage the main window
*/
XtManageChild(main_window->widget);
}
/*
* main loop
*/
XtRealizeWidget(video_shell->widget);
XtAppMainLoop(app_context);
/*
* we never get here, but this makes the compiler happy
*/
return 0;
}

View File

@@ -0,0 +1,148 @@
/* $XConsortium: MainWindow.c /main/3 1996/05/09 03:39:51 drk $ */
#include "PrintDemo.h"
/*
* static function declarations
*/
static void MainWindow_createMenuBar(MainWindow* me);
static void MainWindow_createToolBar(MainWindow* me);
/*
* ------------------------------------------------------------------------
* Name: MainWindow_new
*
* Description:
*
* Creates the main window of the DtPrint demo program.
*
* Return value:
*
* A pointer to a new MainWindow structure.
*
*/
MainWindow*
MainWindow_new(Widget parent)
{
MainWindow* me = (MainWindow*)XtCalloc(1, sizeof(MainWindow));
/*
* create the main window
*/
me->widget =
XtVaCreateWidget("MainWindow",
xmMainWindowWidgetClass,
parent,
NULL);
/*
* create the menu bar and tool bar
*/
MainWindow_createMenuBar(me);
MainWindow_createToolBar(me);
/*
* return
*/
return me;
}
/*
* ------------------------------------------------------------------------
* Name: MainWindow_createMenuBar
*
* Description:
*
* Creates the menu bar for the main window of the DtPrint demo
* program.
*
*/
static void
MainWindow_createMenuBar(MainWindow* me)
{
Widget file_menu;
Widget menu_bar;
XmString label;
Widget w;
/*
* create the menu bar
*/
menu_bar = XmCreateMenuBar(me->widget, "MenuBar", NULL, 0);
/*
* create the file menu
*/
file_menu = XmCreatePulldownMenu(menu_bar, "FileMenu", NULL, 0);
/*
* create the file menu cascade button
*/
label = XmStringCreateLocalized("File");
XtVaCreateManagedWidget("FileCascade",
xmCascadeButtonGadgetClass,
menu_bar,
XmNsubMenuId, file_menu,
XmNlabelString, label,
NULL);
XmStringFree(label);
/*
* create the "Print..." file menu item
*/
label = XmStringCreateLocalized("Print...");
me->print_menu_button =
XtVaCreateManagedWidget("PrintButton",
xmPushButtonWidgetClass,
file_menu,
XmNlabelString, label,
NULL);
XmStringFree(label);
/*
* separator
*/
XtVaCreateManagedWidget("", xmSeparatorGadgetClass, file_menu, NULL);
/*
* "Exit" button
*/
label = XmStringCreateLocalized("Exit");
me->exit_button =
XtVaCreateManagedWidget("ExitButton",
xmPushButtonWidgetClass,
file_menu,
XmNlabelString, label,
NULL);
XmStringFree(label);
/*
* manage the menu bar and return it
*/
XtManageChild(menu_bar);
}
/*
* ------------------------------------------------------------------------
* Name: MainWindow_createToolBar
*
* Description:
*
* Creates a simple tool bar for the main window of the DtPrint demo
* program.
*
*/
static void
MainWindow_createToolBar(MainWindow* me)
{
Widget row;
XmString label;
row = XtVaCreateManagedWidget(
"ToolBarRow",
xmRowColumnWidgetClass,
me->widget,
XmNorientation, XmHORIZONTAL,
XmNscrolledWindowChildType, XmCOMMAND_WINDOW,
NULL);
/*
* create just the "quick print" button
*/
label = XmStringCreateLocalized("Quick Print");
me->quick_print_button =
XtVaCreateManagedWidget("QuickPrintButton",
xmPushButtonWidgetClass,
row,
XmNlabelString, label,
NULL);
XmStringFree(label);
}

View File

@@ -0,0 +1,481 @@
/* $XConsortium: Print.c /main/16 1996/11/11 10:56:18 drk $ */
#include "PrintDemo.h"
/*
* static function declarations
*/
static void PrintCB(Widget, XtPointer, XtPointer);
static void DoPrint(Widget widget, AppPrintData * p) ;
static void StartJobCB(Widget, XtPointer, XtPointer);
static void Print(AppPrintData *p);
static void PrintCloseDisplayCB(Widget, XtPointer, XtPointer);
static void PageSetupCB(Widget, XtPointer, XtPointer);
static void PdmNotifyCB(Widget, XtPointer, XtPointer);
static void PrintSetupCB(Widget, XtPointer, XtPointer);
static void FinishPrintToFile(Display*, XPContext, XPGetDocStatus, XPointer);
static void CreatePrintShell(Widget, AppPrintData*);
/*
* ------------------------------------------------------------------------
* Name: PdmNotifyCB
*
* Description:
*
* Called when the PDM is up, or down.
*
*/
static void
PdmNotifyCB(Widget pr_shell, XtPointer client_data, XtPointer call_data)
{
XmPrintShellCallbackStruct* pr_cbs =
(XmPrintShellCallbackStruct*) call_data;
AppPrintData * p = (AppPrintData *) client_data ;
if (pr_cbs->reason == XmCR_PDM_NONE) {
/* put out a real message dialog */
printf("No PDM found in the environment\n");
} else
if (pr_cbs->reason == XmCR_PDM_START_ERROR) {
/* put out a real message dialog */
printf("Cannot start the PDM\n");
} else
if (pr_cbs->reason == XmCR_PDM_START_VXAUTH) {
/* put out a real message dialog */
printf("PDM is not authorized to connect to Video display\n");
} else
if (pr_cbs->reason == XmCR_PDM_START_PXAUTH) {
/* put out a real message dialog */
printf("PDM is not authorized to connect to Print display\n");
}
}
/*
* ------------------------------------------------------------------------
* Name: PrintMenuCB
*
* Description:
*
* Called when the user selects the "Print..." menu item.
*
*/
void
PrintMenuCB(Widget pr_button, XtPointer client_data, XtPointer call_data)
{
AppPrintData* p = (AppPrintData*)client_data;
/* only propose a new print job if one is not already running
shouldn't happen since we put the button insensitive */
if (!p->printed_lines) {
CreatePrintSetup(pr_button, p);
XtManageChild(p->print_dialog); /* popup dialog each time */
} else {
/* real dialog here */
printf("Print job already running\n");
}
}
/*
* ------------------------------------------------------------------------
* Name: CreatePrintShell
*
* Description:
*
* Called when the user selects the "Print" or the "Setup..." button
* in the setupbox.
*
*/
static void CreatePrintShell(Widget widget, AppPrintData* p)
{
/*
* create a print_shell if none available. the print dialog callback
* always provides valid printer context and print display initialized:
* XpInitContext called, attributes set.
*/
if (!p->print_shell) {
p->print_shell =
XmPrintSetup(widget,
XpGetScreenOfContext(p->print_data->print_display,
p->print_data->print_context),
"Print", NULL, 0);
XtAddCallback(p->print_shell, XmNpageSetupCallback,
PageSetupCB, (XtPointer)p);
XtAddCallback(p->print_shell, XmNpdmNotificationCallback,
PdmNotifyCB, (XtPointer)p);
}
}
/*
* ------------------------------------------------------------------------
* Name: PrintSetupCB
*
* Description:
*
* Called when the user presses the setup box "Setup..." button.
*
*/
static void
PrintSetupCB(Widget print_dialog, XtPointer client_data, XtPointer call_data)
{
AppPrintData *p = (AppPrintData*)client_data;
DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*)call_data;
int copies ;
XtVaGetValues(print_dialog, DtNcopies, &copies, NULL);
if (copies == 3) {
String attr ;
Display * pdpy = pbs->print_data->print_display ;
XPContext pcontext = pbs->print_data->print_context ;
attr = XpGetAttributes (pdpy, pcontext, XPPageAttr);
if (attr) printf ("XPPageAttr:\n%s\n----------------------\n", attr);
attr = XpGetAttributes (pdpy, pcontext, XPDocAttr);
if (attr) printf ("XPDocAttr:\n%s\n----------------------\n", attr);
attr = XpGetAttributes (pdpy, pcontext, XPJobAttr);
if (attr) printf ("XPJobAttr:\n%s\n----------------------\n", attr);
attr = XpGetAttributes (pdpy, pcontext, XPPrinterAttr);
if (attr) printf ("XPPrinterAttr:\n%s\n----------------------\n", attr);
attr = XpGetAttributes (pdpy, pcontext, XPServerAttr);
if (attr) printf ("XPServerAttr:\n%s\n----------------------\n", attr);
return ;
}
/* copy the setup data into our space */
if (p->print_data->print_display != NULL)
DtPrintFreeSetupData(p->print_data);
DtPrintCopySetupData(p->print_data, pbs->print_data);
/* create a print shell if not already done */
CreatePrintShell(print_dialog, p);
/* pop up the PDM */
if (XmPrintPopupPDM(p->print_shell, XtParent(print_dialog))
!= XmPDM_NOTIFY_SUCCESS) {
/* post a message error dialog */
printf("XmPrintPopupPDM failed\n");
}
/* Free the setup data - use fresh data when Print button pressed. */
DtPrintFreeSetupData(p->print_data);
}
static void
CancelCB(Widget print_dialog, XtPointer client_data, XtPointer call_data)
{
AppPrintData *p = (AppPrintData*)client_data;
DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*)call_data;
/* mostly to try it out */
XtDestroyWidget(print_dialog); p->print_dialog = NULL ;
}
/*
* ------------------------------------------------------------------------
* Name: CreatePrintSetup
*
* Description:
*
* Creates a DtPrintSetupBox dialog.
*
*/
void
CreatePrintSetup(Widget parent, AppPrintData* p)
{
/*
* only create one PrintSetupBox
*/
if(!p->print_dialog)
{
Cardinal n = 0;
Arg args[5];
/* can be called when print_only is up, which means no need
for a dialog */
if(XtIsApplicationShell(parent))
p->print_dialog =
DtCreatePrintSetupBox(parent, "PrintSetup", NULL, 0);
else
{
XmString title = XmStringCreateLocalized("Print");
XtSetArg(args[n], XmNdialogTitle, title); n++;
p->print_dialog =
DtCreatePrintSetupDialog(parent, "PrintSetup", args, n);
XmStringFree(title);
}
/*
* allow the application to customize the print setup box
*/
AppObject_customizePrintSetupBox(p->app_object, p->print_dialog);
/*
* add typically used callbacks
*/
XtAddCallback(p->print_dialog, DtNclosePrintDisplayCallback,
PrintCloseDisplayCB, p);
XtAddCallback(p->print_dialog, DtNsetupCallback,
PrintSetupCB, p);
XtAddCallback(p->print_dialog, DtNprintCallback,
PrintCB, p);
XtAddCallback(p->print_dialog, DtNcancelCallback,
CancelCB, p);
/*
* other callbacks, for attributes management, are available
*/
}
}
/*
* ------------------------------------------------------------------------
* Name: PrintCB
*
* Description:
*
* Called when the user presses the setup box "Print" button.
*
*/
static void
PrintCB(Widget print_dialog, XtPointer client_data, XtPointer call_data)
{
AppPrintData *p = (AppPrintData*)client_data;
DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*)call_data;
/*
* get the new printer data from the DtPrintSetupBox, and copy it
* into our AppPrint data
*/
if (p->print_data->print_display != NULL)
DtPrintFreeSetupData(p->print_data);
DtPrintCopySetupData(p->print_data, pbs->print_data);
DoPrint(print_dialog, p);
}
/*
* ------------------------------------------------------------------------
* Name: QuickPrintCB
*
* Description:
*
* Called when the user hits "Print" quick button.
*/
void
QuickPrintCB(Widget pr_button, XtPointer client_data, XtPointer call_data)
{
AppPrintData *p = (AppPrintData*)client_data;
CreatePrintSetup(pr_button, p);
/*
* check if the DtPrintSetupBox ("Print...") has been called yet
*/
if(p->print_data->print_display == NULL)
{
/*
* first time thru print setup, so get default data
*/
if (DtPrintFillSetupData(p->print_dialog, p->print_data)
!= DtPRINT_SUCCESS) {
/* post some message error dialog */
printf("DtPrintFillSetupData failed\n");
return ;
}
}
DoPrint(pr_button, p) ;
}
/*
* ------------------------------------------------------------------------
* Name: FinishPrintToFile
*
* Description:
*
* App-specific print data holder allocate function.
*
*/
static void FinishPrintToFile(Display *display,
XPContext context,
XPGetDocStatus status,
XPointer client_data)
{
if (status != XPGetDocFinished)
/* put out a real message dialog */
printf("Something went wrong with XmPrintToFile...\n");
else
printf("XmPrintToFile completed OK\n");
}
/*
* ------------------------------------------------------------------------
* Name: DoPrint
*
* Description:
*
* Routine used from the "Print" button and from the OK button of the
* "Print..." dialog.
*
*/
static void
DoPrint(Widget widget, AppPrintData * p)
{
int save_data = XPSpool;
/* create print shell, if not done yet */
CreatePrintShell(widget, p);
if (p->print_data->destination == DtPRINT_TO_FILE)
save_data = XPGetData;
/* start job must precede XpGetDocumentData in XmPrintToFile */
XpStartJob(XtDisplay(p->print_shell), save_data);
/* setup print to file */
if (p->print_data->destination == DtPRINT_TO_FILE)
{
if (!XmPrintToFile(XtDisplay(p->print_shell),
p->print_data->dest_info, FinishPrintToFile, NULL))
{
/* Add real error message here. */
printf("XmPrintToFile: Unable to print to file %s\n",
p->print_data->dest_info);
XpCancelJob(XtDisplay(p->print_shell), False);
/* we can go back to the event loop as if we had never
printed */
return;
}
}
XtSetSensitive(p->pr_button, False);
}
/*
* ------------------------------------------------------------------------
* Name: PageSetupCB
*
* Description:
*
* Called when the print shell receives the XP events.
*
*/
static void
PageSetupCB(Widget widget, XtPointer client_data, XtPointer call_data)
{
Widget pshell = widget ;
XmPrintShellCallbackStruct* pr_cbs =
(XmPrintShellCallbackStruct*) call_data;
AppPrintData * p = (AppPrintData *) client_data ;
/* could have real indicator of progress here */
printf("Printed Lines %d\n", p->printed_lines);
/* the first time around, create a print text widget and get
line info - equivalent for testing for first page*/
if (!pr_cbs->last_page && !p->printed_lines) {
/* create the widgets once */
if (!p->pform) {
/* create a form widget with some fixed margins */
p->pform = XtVaCreateManagedWidget("pform", xmFormWidgetClass,
pshell, NULL);
/* create a text widget */
p->ptext = XtVaCreateManagedWidget("ptext", xmTextWidgetClass,
p->pform, NULL);
}
/* transfer value from file buffer to print text widget */
XmTextSetString(p->ptext, p->app_object->file_buffer );
/* get lines per page and total lines */
XtVaGetValues(p->ptext, XmNrows, &(p->lines_per_page),
XmNtotalLines, &(p->total_lines), NULL);
p->printed_lines += p->lines_per_page ;
/* If I'm already done: fit in one page, set last_page up */
if (p->printed_lines >= p->total_lines)
pr_cbs->last_page = True ;
/* that will have for effect in the shell to start a page, end it,
and then end the job */
return ;
}
/* if not the first page - see previous test, and not the last
scroll for next page */
if (!pr_cbs->last_page) {
XmTextScroll(p->ptext, p->lines_per_page);
p->printed_lines += p->lines_per_page ;
/* if last page, say it */
if (p->printed_lines >= p->total_lines) pr_cbs->last_page = True ;
} else {
/* job done. reset our counter, and keep print shell around
for next print job, just pop it down
reset the Print... button sensitive */
XtPopdown(pshell);
p->printed_lines = 0 ;
XtSetSensitive(p->pr_button, True);
}
}
/*
* ------------------------------------------------------------------------
* Name: PrintCloseDisplayCB
*
* Description:
*
* Called when the print setup box is about to close the print
* display (in response to a new printer on a different display, or
* when the setup box is destroyed, or from DtPrintResetConnection).
*/
static void
PrintCloseDisplayCB(
Widget widget,
XtPointer client_data,
XtPointer call_data)
{
DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*)call_data;
AppPrintData *p = (AppPrintData*)client_data;
if (p->print_shell)
{
XtDestroyWidget(p->print_shell);
p->print_shell = (Widget)NULL ;
/* must remember that the children are gone, as well */
p->ptext = p->pform = NULL;
}
DtPrintFreeSetupData(p->print_data);
/* that nulls out p->print_data->print_display */
}
/*
* ------------------------------------------------------------------------
* Name: AppPrintData_new
*
* Description:
*
* App-specific print data holder allocate function.
*
*/
AppPrintData*
AppPrintData_new()
{
AppPrintData* p = (AppPrintData*)XtCalloc(1, sizeof(AppPrintData));
p->print_data = (DtPrintSetupData*)XtCalloc(1, sizeof(DtPrintSetupData));
return p;
}

View File

@@ -0,0 +1,65 @@
/* $XConsortium: PrintDemo.h /main/6 1996/05/09 03:40:22 drk $ */
#include <Xm/XmAll.h>
#include <Xm/Print.h>
#include <Dt/Print.h>
#include "AppSpecific.h"
/*
* ------------------------------------------------------------------------
* Module: Print
*
*/
/*
* app specific print data holder
*/
typedef struct _AppPrintData
{
Widget print_dialog;
Widget print_shell;
Widget pr_button;
Boolean print_only;
DtPrintSetupData *print_data;
AppObject* app_object;
/* used during pagesetup callback logic */
int printed_lines ;
int total_lines ;
short lines_per_page ;
Widget ptext, pform;
} AppPrintData;
extern AppPrintData* AppPrintData_new();
/*
* Print module exported functions
*/
extern void CreatePrintSetup(Widget parent, AppPrintData* p);
extern void PrintMenuCB(Widget, XtPointer, XtPointer);
extern void QuickPrintCB(Widget, XtPointer, XtPointer);
/*
* ------------------------------------------------------------------------
* Module: Main
*
*/
extern void CloseProgramCB(Widget, XtPointer, XtPointer);
/*
* ------------------------------------------------------------------------
* Module: MainWindow
*
*/
/*
* MainWindow structure
*/
typedef struct _MainWindow
{
Widget widget;
Widget print_menu_button;
Widget quick_print_button;
Widget exit_button;
} MainWindow;
extern MainWindow* MainWindow_new(Widget parent);

View File

@@ -0,0 +1,70 @@
/* $XConsortium: README.txt /main/3 1996/07/15 14:00:43 drk $ */
-*- text -*-
OVERVIEW
This directory contains example source demonstrating application
printing using the X Print Service, the Motif printing functions,
and the DtPrintSetupBox widget.
FILES
Main.c
Contains main(), etc.
Print.c
Contains printing callbacks and functions that are
conceptually application-independent.
MainWindow.c
Creates a simple top-level main window.
PrintDemo.h
Contains declarations exported by Main, Print, and MainWindow.
AppSpecific.[ch]
Contains application-specific logic.
Imakefile
For use within the CDEnext build tree.
USAGE
dtprint [-fileName <filename>] [-print]
where:
-fileName <filename> is application-specific data to print.
-print indicates that the application should perform the print
operation, then exit when printing is complete. This option is
used for "Print" actions.
STATUS (12/4/95)
What the demo currently *can* do:
The demo currently demostrates how an application that prints
using the X Print Service can incorporate the DtPrintSetupBox
to be used with a "Print..." menu button, a "Quick-Print"
toolbar button, or a "-print" option intended for use within a
"Print" action for an application-specific data type.
The demo can establish connections to X print servers.
The demo recognizes the XPRINTER environment variable and the
XpServerList and XpPrinterNameMode resources.
What the demo currently *does not* do:
The demo does not actally print at this time.
Printing where no video display is available is not
demonstrated at this time. This mode will conceivably be used
for batch printing.
Print rendering in a separate process is not implemented.
The demo currently does not recognize LPDEST, PRINTER,
PDPRINTER, or XpPrinter.