how can I copy the content of a GenText to a printer? Especially, the
text may longer than a single line, so the object has to handle line
breaks for me.
Is there a special message or a set of messages?
Thanks
Rainer
Here is some code that works for me...
First you need to add a Print Controller and to subclass your GenText objext to
match up with your Print Controller...
@class PrintGenTextClass, GenTextClass;
@endc
@classdecl PrintGenTextClass;
...
@object GenApplicationClass MyApp = {
GI_visMoniker = list {...}
GI_comp = @MyPrimary;
gcnList(MANUFACTURER_ID_GEOWORKS,GAGCNLT_WINDOWS) = @MyPrimary;
gcnList(MANUFACTURER_ID_GEOWORKS,GAGCNLT_SELF_LOAD_OPTIONS) = DLEditControl,
@DLPrintControl;
ATTR_GEN_APPLICATION_PRINT_CONTROL = @DLPrintControl;
}
@object PrintGenTextClass MyText = { /* the main text window */
GTXI_attrs = @default & ~GTA_USE_TAB_FOR_NAVIGATION /* let TABs paste in */
| GTA_INIT_SCROLLING;
GI_attrs = @default | GA_TARGETABLE; /* for controllers & mouse
selection */
ATTR_GEN_TEXT_CHAR_ATTR = (ChunkHandle) @DLTextCharAttrs; /* use mono font */
HINT_EXPAND_WIDTH_TO_FIT_PARENT ;
HINT_EXPAND_HEIGHT_TO_FIT_PARENT ;
HINT_TEXT_WHITE_WASH_COLOR ;
}
@chunk VisTextCharAttr DLTextCharAttrs =
CHAR_ATTR_FONT_SIZE(FID_DTC_URW_MONO, 12);
...
/* Amended from princ sample */
@object PrintControlClass DLPrintControl = {
GI_states = (@default | GS_ENABLED);
PCI_attrs = (@default & ~PCA_PAGE_CONTROLS);
ATTR_GEN_INTERACTION_GROUP_TYPE = GIGT_PRINT_GROUP;
PCI_output = @DirListText;
PCI_docNameOutput = @DirListText;
PCI_docSizeInfo = {(8*72), /* width */
(10.5*72), /* height */
PT_PAPER, /* layout */
{(.25)*72, (.25)*72, (.25)*72, (.25)*72}}; /* margins */
ATTR_GEN_CONTROL_PROHIBIT_UI = PRINTCF_FAX_TRIGGER;
}
/************************************************************************/
@method WhateverClass, MSG_PUT_THE_TEXT_INTO_THE_GENTEXT_OBJECT
/* do whatever to put the text in the GenText */
/* tell print controller how many pages */
lastPage = 1 + (numlines / 62);
@call DLPrintControl::MSG_PRINT_CONTROL_SET_TOTAL_PAGE_RANGE(1, lastPage);
}
/************************************************************************/
@method PrintGenTextClass, MSG_PRINT_START_PRINTING
{
word curPage;
/* this loop is from concepts code display 23-1 */
for (curPage=0; curPage < lastPage; curPage++)
{
GrSaveState(gstate);
GrApplyTranslation(gstate, 0, -MakeWWFixed(curPage
*((sdword)(10.5*72))));
/* Draw current page */
@call self::MSG_VIS_DRAW(DF_PRINT, gstate);
GrRestoreState(gstate);
GrNewPage(gstate, PEC_FORM_FEED);
}
@send DLPrintControl::MSG_PRINT_CONTROL_PRINTING_COMPLETED();
}
/***********************************************************************/
@method PrintGenTextClass, MSG_PRINT_GET_DOC_NAME
{
char *string = "My Doc Name";
@call printCtrlOD::MSG_PRINT_CONTROL_SET_DOC_NAME(string);
}
Hope this helps...
John ;-)
thanks, the code works fine ;-) but in an unexpected way. It "copies"
the current appearance of the GenText to the printer - this means, I
get different results (line length, line breaks ..) when I resize the
text and do printing again.
I had expexeded that the printer margins are used to "best fit" the
text on the paper. But the GenText ignores the printer margins and uses
its current bounds on the screen.
This may be nice, but it is not what I want.
Even the Message:
@call MyPrintControl::MSG_PRINT_CONTROL_GET_PRINTER_MARGINS(
&margins, /* Get margins */
TRUE); /* and use it as doc margins */
does not work.
At this time, I have solved my problem by IACP to the Editor
application (write the text to a file and give it to the editor) and
sending the Editor PrintControl object a "DO_PRINT" message. But I'm
not happy with this solution because I have no control about the font
and font size e.g.
And it would be very intresting to see if the GenText ist able to do
the work in the way I wish. Is there a message to set the bounds of a
GenText objecht (probabely an"invisible" object which works with a copy
of the text)? And is there a way to find out how many lines the text
needs to display the text in its current bounds?
Ok, a lot of questions ;-)
Best Regards
Rainer
Well, I think the way around your bounds problem is to use a VisLargeText object
instead of a GenText object. That's what we use in Breadbox's Banker
application for the Reports module. You can use the region functionality of
VisLargeText to deal with pages (and maybe margins) for the printer.
I worked on this problem a long time ago and got help form some of the guys at
Geoworks. They even wrote a sample app (I think it was Nathan Fiedler who wrote
it) and put it in later version of the SDK. If you don't have it let me know
and I will send it to you.
John ;-)