Page 1 of 1

Editorgadget (windows) broken with RTF table

Posted: Wed May 26, 2021 8:42 am
by drgolf
Editorgadget dont works with rtf table.

This code works with PB 5.46 but not with PB5.73 or 6 (WINDOWS)
Any suggestion ?

Code: Select all

Enumeration
  #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Editor_0
EndEnumeration
;}
;}
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 529, 111, 400, 400,"Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
    EditorGadget(#Editor_0, 30, 20, 330, 220)
    
    t$="{\rtf1\ansi\deff0"
t$+"\trowd"
t$+"\cellx1000"
t$+"\cellx2000"
t$+"\cellx3000"
t$+"\intbl cell 1\cell"
t$+"\intbl cell 2\cell"
t$+"\intbl cell 3\cell"
t$+"\row"
t$+"} "
SetGadgetText(#Editor_0,t$)
  EndIf
EndProcedure

OpenWindow_Window_0()

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Editor_0
      EndSelect
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #Window_0
          CloseWindow(#Window_0)
          Break
      EndSelect
  EndSelect
ForEver

// Moved from "Bugs" to "Coding Questions" (Kiffi)

Re: Editorgadget (windows) broken with RTF table

Posted: Wed May 26, 2021 9:14 am
by mk-soft
No broken, PB its Unicode

Solution : https://www.purebasic.fr/english/viewto ... 36#p520036

Re: Editorgadget (windows) broken with RTF table

Posted: Wed May 26, 2021 9:48 am
by drgolf
thanx for your answer.

Dont work with your snippet with table in RTF.

Work on unicode or not with earlier version of PB.

Re: Editorgadget (windows) broken with RTF table

Posted: Wed May 26, 2021 4:19 pm
by Axolotl
Honestly, I do not have any idea, why that does not work.
Recently I followed a discussion about the support of the latest Rich Text Control (RichClass.s = "RichEdit50W")
So I was thinking that this will happen.
Maybe there is an reduced feature set implemented in PB.
With the windows API you can do what you want.

Code: Select all

#MainWindow = 1
#RICHEDITFLAGS = #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL

If OpenWindow(#MainWindow, 100, 200, 640, 480, "PureBasic Window", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget) 
  If  LoadLibrary_("MSFTEDIT.dll")
    RichClass.s = "RichEdit50W"
  ElseIf LoadLibrary_("RICHED20.DLL")
    RichClass.s = "RichEdit20A"
  ElseIf LoadLibrary_("RICHED32.DLL")
    RichClass.s = "RichEdit"
  Else
    MessageRequester("Error", "RichEdit Windows library not present.", 0)
    End
  EndIf   :Debug "RichClass == "+RichClass 
 
  hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE, RichClass, "This will With SetWindowText.", #RICHEDITFLAGS, 2, 2, 636, 476, WindowID(#MainWindow), 0, GetModuleHandle_(0), 0)
  If hWnd <> 0
    SetWindowText_(hWnd, "Move Cursor behind --+ and Press Enter:"+#CRLF$+"+---+---+---+")
;   SetForegroundWindow_(1)
  EndIf 
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break 
    EndSelect
  ForEver 
EndIf
End 

Re: Editorgadget (windows) broken with RTF table

Posted: Wed May 26, 2021 4:32 pm
by Axolotl
Second Version: With your Text you need such a function.

Code: Select all


Procedure.i SetRichEditText(hwnd, Text$) 
  Protected ret, settext.SETTEXTEX 
  Protected *mem 

  *mem = AllocateMemory(MemoryStringLength(@Text$, #PB_Unicode) + SizeOf(Character)) 
  If *mem 
    PokeS(*mem, Text$, -1, #PB_UTF8) 
    ret = SendMessage_(hwnd, #EM_SETTEXTEX, settext, *mem)                :Debug " #EM_SETTEXTEX -- result = " + ret  
    FreeMemory(*mem) 
  EndIf 
  ProcedureReturn ret  ;' returns 0|1 -- 1 = text is successfully set 
EndProcedure ;() 


#MainWindow = 1
#RICHEDITFLAGS = #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL

If OpenWindow(#MainWindow, 100, 200, 640, 480, "PureBasic Window", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget) 
  If  LoadLibrary_("MSFTEDIT.dll")
    RichClass.s = "RichEdit50W"
  ElseIf LoadLibrary_("RICHED20.DLL")
    RichClass.s = "RichEdit20A"
  ElseIf LoadLibrary_("RICHED32.DLL")
    RichClass.s = "RichEdit"
  Else
    MessageRequester("Error", "RichEdit Windows library not present.", 0)
    End
  EndIf   :Debug "RichClass == "+RichClass 
 
  hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE, RichClass, "This will With SetWindowText.", #RICHEDITFLAGS, 2, 2, 636, 476, WindowID(#MainWindow), 0, GetModuleHandle_(0), 0)
  If hWnd <> 0
;   SetWindowText_(hWnd, "Move Cursor behind --+ and Press Enter:"+#CRLF$+"+---+---+---+")

    t$="{\rtf1\ansi\deff0"
    t$+"\trowd"
    t$+"\cellx1000"
    t$+"\cellx2000"
    t$+"\cellx3000"
    t$+"\intbl cell 1\cell"
    t$+"\intbl cell 2\cell"
    t$+"\intbl cell 3\cell"
    t$+"\row"
    t$+"} "

  ; SetWindowText_(hWnd, t$)
    SetRichEditText(hwnd, t$) 
  EndIf 
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break 
    EndSelect
  ForEver 
EndIf
End