
RichEdit Functions (OOP) New: with Image-Support
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: RichEdit Functions (OOP)
That would be good ts, as I have always wanted to have the images although the file size can get a little bit large. 

PureBasic! Purely the best 

Re: RichEdit Functions (OOP)
Update
added many new examples and a spellchecker!Historie wrote:; Version 1.8, July 31, 2011 (neotoma)
; added: IsAlignJustify(),GetWordUnderCursorStart(), GetWordUnderCursorEnd()
; added: GetScrollPosX(), GetScrollPosY(),SetScrollPos(), SetLink()
; added: SetUndoLimit()
; modified : GetWordAtPosition(), GetWordUnderCursor()
; added again: SetTextBackColor()
; added: AppendText()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: RichEdit Functions (OOP)
Outstanding!
Just keep getting better and better.
Many thanks for sharing.

Just keep getting better and better.
Many thanks for sharing.
Re: RichEdit Functions (OOP)
Update
Example:
Preview:

No Unicode-Support for Images!
Thanks to jacobus for some code-examples.Historie wrote:; Version 1.9, August 01, 2011
; added: SetInterface() for ImageSupport
; added: SetImage()
Example:
Code: Select all
EnableExplicit
XIncludeFile "RichEdit.pbi"
Define.RichEdit Edit
OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 100, "Test Image")
Edit = New_RichEdit(0, 0, 600, 100)
Edit\SetInterface()
Edit\SetText("This is a picture: ")
LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\PureBasicLogo.bmp")
Edit\SetImage(ImageID(0))
Edit\SetText(" in a EditorGadget!" + #CRLF$)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

No Unicode-Support for Images!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: RichEdit Functions (OOP) New: with Image-Support
Work impressive and useful, I will adopt it!
But there is a problem with RichEdit_Print() that bug if it cancels
Look in my example code, the Editor_DefaultPrinter() function that solves the problem with a test If / EndIF
here If PrintDlg_(lppd)
But there is a problem with RichEdit_Print() that bug if it cancels
Look in my example code, the Editor_DefaultPrinter() function that solves the problem with a test If / EndIF
here If PrintDlg_(lppd)
PureBasicien tu es, PureBasicien tu resteras.
Re: RichEdit Functions (OOP) New: with Image-Support
Thx for the bugreport, it is fixed in next release.
I have changed to:
This should do the trick.
I have changed to:
Code: Select all
Procedure RichEdit_Print(*this.RichEditClassTemplate, DocName.s = "pbprint", dialog.i = #False)
Protected.PRINTDLG lppd
Protected.RECT cRect
Protected.FORMATRANGE FormatRange
Protected.Docinfo Docinfo
Protected LastChar.l, MaxLen.l, OldMapMode.l, OffsetX.l, OffsetY.l, HorzRes.l, VertRes.l
Protected DC.i, i.i = 1
If dialog
lppd\lStructsize = SizeOf(PRINTDLG)
lppd\Flags = #PD_ALLPAGES | #PD_HIDEPRINTTOFILE | #PD_NOSELECTION | #PD_RETURNDC
If PrintDlg_(@lppd)
DC = lppd\hDC
EndIf
Else
DC = DefaultPrinter()
EndIf
If DC
Docinfo\cbSize = SizeOf(Docinfo)
Docinfo\lpszDocName = @DocName
StartDoc_(DC, Docinfo)
MaxLen = Len(GetGadgetText(*this\ID)) - SendMessage_(*this\hWnd, #EM_GETLINECOUNT, 0, 0)
OldMapMode = GetMapMode_(DC)
SetMapMode_(DC, #MM_TWIPS)
OffsetX = GetDeviceCaps_(DC, #PHYSICALOFFSETX)
OffsetY = - GetDeviceCaps_(DC, #PHYSICALOFFSETY)
HorzRes = GetDeviceCaps_(DC, #HORZRES)
VertRes = - GetDeviceCaps_(DC, #VERTRES)
SetRect_(cRect, OffsetX, OffsetY, HorzRes, VertRes)
DPtoLP_(DC, cRect, 2)
SetMapMode_(DC, OldMapMode)
FormatRange\hDC = DC
FormatRange\hdcTarget = DC
FormatRange\rc\left = cRect\left
FormatRange\rc\top = cRect\top
FormatRange\rc\right = cRect\right
FormatRange\rc\bottom = cRect\bottom
FormatRange\rcPage\left = cRect\left
FormatRange\rcPage\top = cRect\top
FormatRange\rcPage\right = cRect\right
FormatRange\rcPage\bottom = cRect\bottom
Repeat
StartPage_(DC)
FormatRange\chrg\cpMax = - 1
LastChar = SendMessage_(*this\hWnd, #EM_FORMATRANGE, #True, @FormatRange)
FormatRange\chrg\cpMin = LastChar
SendMessage_(*this\hWnd, #EM_DISPLAYBAND, 0, cRect)
i + 1
EndPage_(DC)
Until LastChar >= MaxLen Or LastChar = -1
EndDoc_(DC)
SendMessage_(*this\hWnd, #EM_FORMATRANGE, 0, 0)
EndIf
EndProcedure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: RichEdit Functions (OOP) New: with Image-Support
Update
ToDo: Table Support
Here a small example to drop image or imagefile to editorgadget:Historie wrote:; Version 2.0, August 03, 2011
; fixed bug in Print method
; added Unicode-Support for SetImage
Code: Select all
EnableExplicit
XIncludeFile "RichEdit.pbi"
UsePNGImageDecoder()
UseJPEGImageDecoder()
Define.RichEdit Edit
Define.s Files, File, Ext
Define.i i, j
OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "EditorGadget with ImageDrop-Support", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
Edit = New_RichEdit(5, 5, 630, 470)
Edit\SetInterface()
EnableGadgetDrop(Edit\GetID(), #PB_Drop_Image | #PB_Drop_Files, #PB_Drag_Copy | #PB_Drag_Move)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_SizeWindow
ResizeGadget(Edit\GetID(), #PB_Ignore, #PB_Ignore, WindowWidth(0) - 10, WindowHeight(0) - 10)
Case #PB_Event_GadgetDrop
If EventGadget() = edit\GetID()
Select EventDropType()
Case #PB_Drop_Image
If EventDropImage(0)
Edit\SetImage(ImageID(0))
EndIf
Case #PB_Drop_Files
Files = EventDropFiles()
j = CountString(Files, #LF$) + 1
For i = 1 To j
File = StringField(Files, i, #LF$)
Ext = LCase(GetExtensionPart(File))
Select Ext
Case "bmp", "jpg", "png"
If LoadImage(0, File)
Edit\SetImage(ImageID(0))
EndIf
Case "rtf"
Edit\LoadRTF(File, #True)
Case "txt"
Edit\LoadText(File, #True)
EndSelect
Next
EndSelect
EndIf
EndSelect
ForEver
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: RichEdit Functions (OOP) New: with Image-Support
WOW, you have made great progress on this ts.
I am now off to check out the image stuff.

I am now off to check out the image stuff.

PureBasic! Purely the best 

Re: RichEdit Functions (OOP) New: with Image-Support

I have some help from the forum and i will use this file for one of my next projects.
Time is money

Greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: RichEdit Functions (OOP) New: with Image-Support
I have tested the image support and it saves and loads a-ok, file sizes can get quite large, probably because they end up in the bitmap world, but can be compressed down heaps. I am looking into compressing the saved files then decompress them when loading as an extra option.
Here is a modification to RichEdit_Example.pb taken from the RichEdit_Example_DropImage.pb for image support.
I hope this is Ok.
Put these at the top...
Change Defines to...
Place these lines after - Edit = New_RichEdit(0, 0, 0, 0); die grösse können wir ignorieren, passt sich im SizeEvent an!...
Place these lines after - Select WaitWindowEvent()...
I have also added this mod - Case #WM_LBUTTONUP, #WM_KEYUP, to make changes to the status and toolbars when moving the cursor using the keyboard as well as the mouse.
I was wondering if it would be a good idea to add an option to - ProcedureDLL.i New_RichEdit(x.l, y.l, w.l, h.l), to make the EditorGadget #PB_Editor_ReadOnly for rtf read only help files and the such.
Anyway thanks for this addition to the forum, and your fine coding ts.
Here is a modification to RichEdit_Example.pb taken from the RichEdit_Example_DropImage.pb for image support.
I hope this is Ok.
Put these at the top...
Code: Select all
UsePNGImageDecoder() ; only required for loadimage (not for dropimage!)
UseJPEGImageDecoder() ; only required for loadimage (not for dropimage!)
Code: Select all
Define.s File, Files, Ext
Define.i Result, i, mx, my, align, j
Code: Select all
Edit\SetInterface() ; this enables the image-support and shows images in rtf-files
EnableGadgetDrop(Edit\GetID(), #PB_Drop_Image | #PB_Drop_Files, #PB_Drag_Copy | #PB_Drag_Move)
Code: Select all
Case #PB_Event_GadgetDrop
If EventGadget() = edit\GetID()
Select EventDropType()
Case #PB_Drop_Image
If EventDropImage(0)
Edit\SetImage(ImageID(0))
EndIf
Case #PB_Drop_Files
Files = EventDropFiles()
j = CountString(Files, #LF$) + 1
For i = 1 To j
File = StringField(Files, i, #LF$)
Ext = LCase(GetExtensionPart(File))
Select Ext
Case "bmp", "jpg", "png"
If LoadImage(0, File)
Edit\SetImage(ImageID(0))
EndIf
Case "rtf"
Edit\LoadRTF(File, #True)
Case "txt"
Edit\LoadText(File, #True)
EndSelect
Next
EndSelect
EndIf
I was wondering if it would be a good idea to add an option to - ProcedureDLL.i New_RichEdit(x.l, y.l, w.l, h.l), to make the EditorGadget #PB_Editor_ReadOnly for rtf read only help files and the such.

Anyway thanks for this addition to the forum, and your fine coding ts.

PureBasic! Purely the best 

Re: RichEdit Functions (OOP) New: with Image-Support
Hi electrochrisso
But where can I get the Edit\SetInterface() code needed for your additions to work?
Searching the forum I found RichEdit_SetInterface(hwnd), but that's the only thing close
that I found, and it's not it.
Thanks for your help
I'm still using PB4.51 until PB4.6 gets out of beta this time.Code: Select all
Place these lines after - Edit = New_RichEdit(0, 0, 0, 0); die grösse können wir ignorieren, passt sich im SizeEvent an!... Code: Edit\SetInterface() ; this enables the image-support and shows images in rtf-files EnableGadgetDrop(Edit\GetID(), #PB_Drop_Image | #PB_Drop_Files, #PB_Drag_Copy | #PB_Drag_Move)
But where can I get the Edit\SetInterface() code needed for your additions to work?
Searching the forum I found RichEdit_SetInterface(hwnd), but that's the only thing close
that I found, and it's not it.
Thanks for your help
Re: RichEdit Functions (OOP) New: with Image-Support
For download see first post!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: RichEdit Functions (OOP) New: with Image-Support
Hi, I'm trying to use the GetTextColor() function and I can't find a way to make it work, it always returns 0. Someone made it work, can post an example of it? I used the example post it on thread below is how I'm always get 0 as result.
Code: Select all
EnableExplicit
XIncludeFile "RichEdit.pbi"
Define.RichEdit Edit
Define.s Text
Macro FE()
While WindowEvent() : Wend
Delay(2000)
EndMacro
OpenWindow(0, #PB_Ignore, #PB_Ignore, 400, 140, "")
Edit = New_RichEdit(0, 0, WindowWidth(0), WindowHeight(0))
Edit\SetReadOnly(#True)
Edit\SetLeftMargin(5)
Edit\SetRightMargin(5)
; adding some text
Text = #CRLF$ + "Feel the ..Pure.. Power" + #CRLF$ + #CRLF$ + "Example ©2011 by ts-soft" + #CRLF$
; format the text
Edit\SetAlignment(#PB_Text_Center)
Edit\SetFont("Comic Sans MS")
Edit\SetText(Text)
Edit\SetSelection(1, 1)
Edit\SetFontSize(16)
Edit\SetFontStyle(#PB_Font_Bold)
Edit\SetTextColor(#Blue)
Debug Edit\GetTextColor() ; <---- Here try to get the color that was set above, 0 is the result
FE()
; make "..Pure.." big and colored
If Edit\FindText("..Pure..")
FE()
Edit\SetTextColor(#Yellow, #Blue)
Edit\SetFontSize(26)
EndIf
FE()
; make Copyright small, left align, Arial, black
If Edit\FindText("Example ©2011 by ts-soft")
FE()
Edit\SetFont("Arial")
Edit\SetFontSize(8)
Edit\SetFontStyle()
Debug Edit\GetTextColor()
Edit\SetTextColor(#Black)
Edit\SetCursorPos(1, 4)
FE()
Edit\SetAlignment()
EndIf
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: RichEdit Functions (OOP) New: with Image-Support
Hi ts-soft
I downloaded it yesterday and it wasn't in the files I downloaded.
But I just downloaded it again now, and it's in there. Yesterdays download
must of somehow grabbed it from FireFox's cache.
Thanks much.
I downloaded it yesterday and it wasn't in the files I downloaded.
But I just downloaded it again now, and it's in there. Yesterdays download
must of somehow grabbed it from FireFox's cache.
Thanks much.
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: RichEdit Functions (OOP) New: with Image-Support
Hi Yrreti
You may have had Firefox in Work Offline, I did that the other day and ended up with old postings and got a bit confused for a while until i realised.
You may have had Firefox in Work Offline, I did that the other day and ended up with old postings and got a bit confused for a while until i realised.

PureBasic! Purely the best 
