Hi,
I am trying to print multiple widgets using PpPrintWidget() but getting
weird results. Here is the code that I am using. This is slightly modified
from the example code taken from the HelpViewer.
When I view using Preview, What I see is the “but” PtButton while I am
printing the “quit” PtButton and the “txt” PtText.
Can someone point out where I am going wrong and what is the right way to
do it?
TIA for your help.
Code
#include <stdio.h>
#include <stdlib.h>
#include <Pt.h>
#include <errno.h>
PtWidget_t *pane, *window;
PpPrintContext_t *pc;
PtWidget_t *print, *quit,*but,*txt;
int quit_cb ( PtWidget_t *widget, void *data,
PtCallbackInfo_t *cbinfo)
{
PpReleasePC (pc);
exit (EXIT_SUCCESS);
return (Pt_CONTINUE);
}
int print_cb ( PtWidget_t *widget, void *data,
PtCallbackInfo_t *cbinfo)
{
int action;
int ret;
/* You could make these calls to PpSetPC() right
after creating the print context. Having it here
lets you reuse the print context. */
PhDim_t size = { 850, 1100 };
ret = PpSetPC(pc, Pp_PC_SOURCE_SIZE, &size, 0);
if(ret !=0)
printf(“Errno is = %s \n”,strerror(errno));
fflush(stdout);
action = PtPrintSelection(window, NULL,
“Demo Print Selector”, pc,
Pt_PRINTSEL_DFLT_LOOK);
if (action != Pt_PRINTSEL_CANCEL)
{
PpStartJob(pc);
PpContinueJob(pc);
/* Print the widget. */
PpPrintWidget(pc,quit, NULL, NULL, 0);
PpPrintWidget(pc,txt, NULL, NULL, 0);
/* Close the print context. */
PpSuspendJob(pc);
PpEndJob(pc);
}
return (Pt_CONTINUE);
}
int main(int argc, char *argv[])
{
PtArg_t args[4];
PhDim_t win_dim = { 300, 300 };
PhArea_t pane_area = { {0, 0}, {200, 150} };
PhArea_t print_area = { {30, 170}, {60, 20} };
PhArea_t quit_area = { {110, 170}, {60, 20} };
PhPoint_t pos = {35,20};
PhArea_t text_area = { {35, 20}, {130,30} };
PhArea_t but_area = { {35, 70}, {100,30} };
PtCallback_t callbacks[2] = { {print_cb, NULL},
{quit_cb, NULL} };
if (PtInit(NULL) == -1)
PtExit(EXIT_FAILURE);
/* Create the main window. */
PtSetArg (&args[0], Pt_ARG_DIM, &win_dim, 0);
PtSetArg (&args[1], Pt_ARG_WINDOW_TITLE,
“Print Example”, 0);
if ((window = PtCreateWidget(PtWindow, Pt_NO_PARENT,
2, args)) == NULL)
PtExit(EXIT_FAILURE);
/* Create a print context. */
pc = PpCreatePC();
/* Create the pane to be printed. */
PtSetArg (&args[0], Pt_ARG_AREA, &pane_area, 0);
pane = PtCreateWidget (PtPane, window, 1, args);
/* put some stuff in the pane to be printed. */
//PtSetArg(&args[0],Pt_ARG_POS,&pos,0);
PtSetArg(&args[0],Pt_ARG_AREA,&text_area,0);
PtSetArg(&args[1],Pt_ARG_TEXT_STRING,“Are you seeing this”,0);
txt = PtCreateWidget(PtText,pane,2,args);
PtSetArg(&args[0],Pt_ARG_AREA,&but_area,0);
PtSetArg(&args[1],Pt_ARG_TEXT_STRING,“Button”,0);
PtSetArg(&args[2],Pt_ARG_COLOR,Pg_BLUE,0);
but = PtCreateWidget(PtButton,pane,3,args);
/* Create the print button. */
PtSetArg(&args[0], Pt_ARG_AREA, &print_area, 0);
PtSetArg(&args[1], Pt_ARG_TEXT_STRING, “Print”, 0);
PtSetArg(&args[2], Pt_CB_ACTIVATE, &callbacks[0], 0);
print = PtCreateWidget (PtButton, window, 3, args);
/* Create the quit button. */
PtSetArg(&args[0], Pt_ARG_AREA, &quit_area, 0);
PtSetArg(&args[1], Pt_ARG_TEXT_STRING, “Quit”, 0);
PtSetArg(&args[2], Pt_CB_ACTIVATE, &callbacks[1], 0);
quit = PtCreateWidget (PtButton, window, 3, args);
PtRealizeWidget(window);
PtMainLoop();
return (EXIT_SUCCESS);
}
Rajan