Page 2 of 6

Re: RichEdit Functions (OOP)

Posted: Fri Jul 29, 2011 5:08 am
by electrochrisso
That would be good ts, as I have always wanted to have the images although the file size can get a little bit large. :D

Re: RichEdit Functions (OOP)

Posted: Sun Jul 31, 2011 10:37 pm
by ts-soft
Update
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()
added many new examples and a spellchecker!

Re: RichEdit Functions (OOP)

Posted: Mon Aug 01, 2011 1:39 am
by rsts
Outstanding! :D

Just keep getting better and better.

Many thanks for sharing.

Re: RichEdit Functions (OOP)

Posted: Mon Aug 01, 2011 4:54 pm
by ts-soft
Update
Historie wrote:; Version 1.9, August 01, 2011
; added: SetInterface() for ImageSupport
; added: SetImage()
Thanks to jacobus for some code-examples.

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
Preview:
Image

No Unicode-Support for Images!

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

Posted: Mon Aug 01, 2011 10:34 pm
by Jacobus
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)

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

Posted: Mon Aug 01, 2011 10:50 pm
by ts-soft
Thx for the bugreport, it is fixed in next release.

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
This should do the trick.

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

Posted: Wed Aug 03, 2011 10:07 pm
by ts-soft
Update
Historie wrote:; Version 2.0, August 03, 2011
; fixed bug in Print method
; added Unicode-Support for SetImage
Here a small example to drop image or imagefile to editorgadget:

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
ToDo: Table Support

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

Posted: Thu Aug 04, 2011 3:53 am
by electrochrisso
WOW, you have made great progress on this ts. :wink:
I am now off to check out the image stuff. :D

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

Posted: Thu Aug 04, 2011 4:13 am
by ts-soft
:D thx and have fun!

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

Greetings
Thomas

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

Posted: Fri Aug 05, 2011 7:42 am
by electrochrisso
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...

Code: Select all

UsePNGImageDecoder()  ; only required for loadimage (not for dropimage!)
UseJPEGImageDecoder() ; only required for loadimage (not for dropimage!)
Change Defines to...

Code: Select all

Define.s File, Files, Ext
Define.i Result, i, mx, my, align, j
Place these lines after - Edit = New_RichEdit(0, 0, 0, 0); die grösse können wir ignorieren, passt sich im SizeEvent an!...

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)
Place these lines after - Select WaitWindowEvent()...

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 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. :D

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

Posted: Mon Aug 08, 2011 5:13 pm
by yrreti
Hi electrochrisso

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)
I'm still using PB4.51 until PB4.6 gets out of beta this time.
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

Posted: Mon Aug 08, 2011 5:16 pm
by ts-soft
For download see first post!

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

Posted: Mon Aug 08, 2011 7:47 pm
by leofenix
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

Posted: Mon Aug 08, 2011 7:52 pm
by yrreti
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.

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

Posted: Tue Aug 09, 2011 6:22 am
by electrochrisso
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. :lol: