May 05, 2024, 04:42:12 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Printing problem using Scintilla editor

Started by LarryMc, March 10, 2010, 07:11:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

March 10, 2010, 07:11:23 AM Last Edit: March 10, 2010, 07:14:03 AM by Larry McCaughn
I'm working on the printing module of the Visual Designer.

According to what I can see in the scintilla docs this should turn wordwrap on in the printer output.
CallScintilla(code,SCI_SETPRINTWRAPMODE,1,0)
I can't seem to get it to do anything.
when the printed line hits the right margin it is just truncated.

Here's my code:

sub PrintCode()

PRINTDLG pd
FORMATRANGE frPrint
Point ptPage
Point ptDpi
winrect rectMargins, rectPhysMargins
DOCINFO di
ZeroMemory(pd,LEN(PRINTDLG))
ZeroMemory(frPrint,LEN(FORMATRANGE))
ZeroMemory(di, LEN(DOCINFO))

pd.lStructSize = LEN(PRINTDLG)
pd.Flags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_HIDEPRINTTOFILE | PD_NOSELECTION | PD_RETURNDC
pd.hwndOwner = 0
IF PrintDlg(pd) <> 0
_fpreset()
int nHorizRes = GetDeviceCaps(pd.hdc, HORZRES)
int nVertRes = GetDeviceCaps(pd.hdc, VERTRES)
'Get printer resolution
ptDpi.x = GetDeviceCaps(pd.hdc, LOGPIXELSX)
ptDpi.y = GetDeviceCaps(pd.hdc, LOGPIXELSY)

'Get the dimensions of the unprintable
'part of the page (in device units).
rectPhysMargins.left = GetDeviceCaps(pd.hdc, PHYSICALOFFSETX)
rectPhysMargins.top = GetDeviceCaps(pd.hdc, PHYSICALOFFSETY)

'To get the right and lower unprintable area,
'we take the entire width and height of the paper and
'subtract everything else.
'total paper width-printable width-left unprintable margin
rectPhysMargins.right = ptPage.x _
- GetDeviceCaps(pd.hdc, HORZRES) _
- rectPhysMargins.left
     'total paper height-printable height-right unprintable margin
rectPhysMargins.bottom = ptPage.y _
-GetDeviceCaps(pd.hdc, VERTRES) _
- rectPhysMargins.top
           
'make adjustments to margins here
rectMargins.left = rectPhysMargins.left+400
rectMargins.top = rectPhysMargins.top+200
rectMargins.right = rectPhysMargins.right+200
rectMargins.bottom = rectPhysMargins.bottom
'rectMargins now contains the values used to shrink the printable
'area of the page.

'Convert device coordinates into logical coordinates
DPtoLP(pd.hdc, &rectMargins, 2)
DPtoLP(pd.hdc, &rectPhysMargins, 2)

'Convert page size to logical units and we're done!
DPtoLP(pd.hdc,&ptPage, 1)

frPrint.hdc = pd.hdc
frPrint.hdcTarget = pd.hdc
frPrint.rc.left = rectMargins.left - rectPhysMargins.left
frPrint.rc.top = rectMargins.top - rectPhysMargins.top
frPrint.rc.right = ptPage.x - rectMargins.right - rectPhysMargins.left
frPrint.rc.bottom = ptPage.y - rectMargins.bottom - rectPhysMargins.top

frPrint.rcPage.left = 0
frPrint.rcPage.top = 0
frPrint.rcPage.right = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1
frPrint.rcPage.bottom = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1

'handle headers/footers
/*
if (headerFormat.size()) {
frPrint.rc.top += headerLineHeight + headerLineHeight / 2
}
if (footerFormat.size()) {
frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2
}
*/
int lTextLength = 0
int lTextPrinted = 0


CallScintilla(code,SCI_SETPRINTWRAPMODE,1,0)  <======doesn't do anything

'Find out real size of document in characters.
lTextLength = CallScintilla(code,SCI_GetLength,0,0)

'Default the range of text to print as the entire document.
frPrint.chrg.cpMin = 0
frPrint.chrg.cpMax =lTextLength

'Set up the print job (standard printing stuff here).
di.cbSize = LEN(DOCINFO)
di.lpszDocName = "(Untitled)"

'Do not print to file.
di.lpszOutput = NULL

'Start the document.
StartDoc(pd.hdc, di)
do
'Start the page.
StartPage(pd.hdc)

lTextPrinted = CallScintilla(code,SCI_FORMATRANGE,true,&frPrint)

'Print last page.
EndPageA(pd.hdc)

if (lTextPrinted < lTextLength)
frPrint.chrg.cpMin = lTextPrinted
frPrint.chrg.cpMax = lTextLength
endif
until lTextPrinted >= lTextLength
'release cached information.
CallScintilla(code,SCI_FORMATRANGE,0,null)
EndDoc (pd.hdc)
DeleteDC(pd.hdc)
ENDIF
RETURN
ENDSUB


any help would be appreciated

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Found this answer (stumbled across it)

Looked at the source for Aurora and the message was using lparam set for direct.
The scintilla doc didn't say anything about that for the message.

So I tried this and it wrapped like I wanted.
CallScintilla(code,SCI_SETPRINTWRAPMODE,1,1)

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library