Need help with RTF in EditorGadget

Just starting out? Need help? Post your questions and find answers here.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Need help with RTF in EditorGadget

Post by Tranquil »

Hello all together!

I have a little problem displaying a smiley like the :D in an editorgadget.
That is what I've tried:

I pasted a smiley into a word document, saved it as RTF File format, as I hoped I can insert this code to an editorgadget which then displays the smiley in the according position, but this does not seem to work.

This is what Ive done so far: (just for testing purpose)

The include file can be found here: http://www.danceyourmusic.com/smiley.rtf

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  EditorGadget(0, 8, 8, 306, 133) 
  Smiley$= PeekS(?Smiley,?EndSmiley-?Smiley)
  AddGadgetItem(0,-1,Smiley$)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 


DataSection:
  Smiley:IncludeBinary "smiley.rtf"
  EndSmiley:
EndDataSection
Thanks!!
Tranquil
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

BERESHEIT
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

Thx for fast answering. I found that thread too but I hoped there is a more eayier solution like that. Thanks for spotting!
Tranquil
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

It really is quite easy. You can just include the OleEdit.pbi source srod posted and it's only:

Code: Select all

IncludeFile "OLEedit.pbi" 

OpenWindow(0, 0, 0, 600, 400, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0)) 
EditorGadget(0, 8, 8, 500, 150) 
RichEdit_SetInterface(GadgetID(0)) 
LoadRtf(0,"smiley.rtf",0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
Now that didn't hurt a bit, did it? There's a CatchRtf function too if you prefer to include it in your exe.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Here's an example I wrote for someone a little while ago.

Type some text into the string gadget at the bottom of the window and then hit send. Any occurrences of a colon followed by a close bracket will be converted to a smilie.

(If the code doesn't work properly then it will be because I didn't post the most up to date version of the 'OLEedit.pbi' source file. In this case, just let me know.)

Code: Select all

;NOTE -  I've made this more complex than it has to be in order for it to be 
;        flexible enough to handle more than one type of smiley etc.
;        Indeed, it is now trivial to add more smileys.


;**************MUST INCLUDE***************************************************************** 
XIncludeFile "OLEedit.pbi" 
;******************************************************************************************* 

Enumeration
  #editViewer
  #strUser
  #btnSend
EndEnumeration

If OpenWindow(0, 0, 0, 600, 400, "Smiley test!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  EditorGadget(#editViewer, 8, 8, 500, 300,#PB_Editor_ReadOnly) 
  StringGadget(#strUser, 8, 320, 500, 40,"",#ES_MULTILINE|#WS_VSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT) 
  ButtonGadget(#btnSend,520,320,60,40,"SEND") 
  ;Set up the com interface for the editor gadget. 
    RichEdit_SetInterface(GadgetID(#editViewer)) 
  SetActiveGadget(#strUser)
  Repeat 
    EV=WaitWindowEvent() 
    Select EV 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case #btnSend 
          ;We need to parse the string looking for ':)' smilies!
            text$ = GetGadgetText(#strUser)
            If text$
              Repeat
                loc = FindString(text$, ":",1)
                If loc And loc<Len(text$)
                  ;We have encountered a possible smiley. Need to examine more closely.
                    smiley$=Mid(text$, loc,2)
                    Select smiley$
                      Case ":)"  ;Add all other valid smileys separated by commas. E.g. Case ":)", ";)" etc.
                        ;Stream the text up to the smiley.
                          temp$ = Left(text$,loc-1)
                          If temp$
                            CatchRTF(#editViewer, @temp$, @temp$+Len(temp$)*SizeOf(CHARACTER),#SF_TEXT, #SFF_SELECTION) 
                          EndIf
                        ;Look at individual smileys.
;THIS IS WHERE YOU ADD MORE SMILEYS BY ADDING 'ElseIf's etc.
                          If smiley$=":)"
                            CatchRTF(#editViewer, ?smiley1, ?endsmiley1,#SF_RTF, #SFF_SELECTION) 
                          EndIf
                        ;Remove the already processed text.
                          text$=Right(text$, Len(text$)-loc-1)
                      Default
                        ;Stream the text up to the colon.
                          temp$ = Left(text$,loc)
                          CatchRTF(#editViewer, @temp$, @temp$+Len(temp$)*SizeOf(CHARACTER),#SF_TEXT, #SFF_SELECTION) 
                        ;Remove the already processed text.
                          text$=Right(text$, Len(text$)-loc)
                    EndSelect
                Else ; No further smileys so we stream in the remainder of the text.
                  CatchRTF(0, @text$, @text$+Len(text$)*SizeOf(CHARACTER),#SF_TEXT, #SFF_SELECTION) 
                  text$="" ;This will force an exit from the loop.
                EndIf
              Until text$=""
              AddGadgetItem(#editViewer,-1,"")
              SetGadgetText(#strUser,"")
            EndIf
            SetActiveGadget(#strUser)
        EndSelect 
    EndSelect 
    
  Until EV = #PB_Event_CloseWindow 
EndIf 
End

DataSection
  smiley1:
  Data.b 123, 92, 114, 116, 102, 49, 92, 97, 110, 115, 105, 92, 97, 110, 115, 105, 99, 112, 103, 49, 50, 53, 50, 92, 100, 101, 102, 102, 48, 92, 100, 101, 102, 108, 97, 110, 103, 50, 48, 53
  Data.b 55, 123, 92, 102, 111, 110, 116, 116, 98, 108, 123, 92, 102, 48, 92, 102, 115, 119, 105, 115, 115, 92, 102, 99, 104, 97, 114, 115, 101, 116, 48, 32, 65, 114, 105, 97, 108, 59, 125, 125
  Data.b 13, 10, 123, 92, 42, 92, 103, 101, 110, 101, 114, 97, 116, 111, 114, 32, 77, 115, 102, 116, 101, 100, 105, 116, 32, 53, 46, 52, 49, 46, 49, 53, 46, 49, 53, 48, 55, 59, 125, 92
  Data.b 118, 105, 101, 119, 107, 105, 110, 100, 52, 92, 117, 99, 49, 92, 112, 97, 114, 100, 92, 102, 48, 92, 102, 115, 50, 48, 123, 92, 112, 105, 99, 116, 92, 119, 109, 101, 116, 97, 102, 105
  Data.b 108, 101, 56, 92, 112, 105, 99, 119, 103, 111, 97, 108, 50, 49, 48, 92, 112, 105, 99, 104, 103, 111, 97, 108, 50, 52, 48, 32, 13, 10, 48, 49, 48, 48, 48, 57, 48, 48, 48, 48
  Data.b 48, 51, 102, 53, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 55, 100, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 52, 48, 48, 48, 48, 48, 48, 48, 51, 48, 49, 48, 56
  Data.b 48, 48, 48, 53, 48, 48, 48, 48, 48, 48, 48, 98, 48, 50, 48, 48, 48, 48, 48, 48, 48, 48, 48, 53, 48, 48, 48, 48, 13, 10, 48, 48, 48, 99, 48, 50, 49, 48, 48, 48
  Data.b 49, 48, 48, 48, 48, 51, 48, 48, 48, 48, 48, 48, 49, 101, 48, 48, 48, 52, 48, 48, 48, 48, 48, 48, 48, 55, 48, 49, 48, 52, 48, 48, 48, 56, 48, 48, 48, 48, 48, 48
  Data.b 50, 54, 48, 54, 48, 102, 48, 48, 48, 54, 48, 48, 53, 52, 52, 101, 53, 48, 53, 48, 48, 54, 48, 49, 52, 51, 48, 48, 13, 10, 48, 48, 48, 48, 52, 49, 48, 98, 56, 54
  Data.b 48, 48, 101, 101, 48, 48, 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 56
  Data.b 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 49, 48, 48, 48, 49, 13, 10, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
  Data.b 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
  Data.b 48, 48, 48, 48, 48, 48, 48, 48, 102, 102, 102, 102, 102, 102, 48, 48, 48, 55, 99, 48, 100, 57, 48, 51, 49, 102, 102, 48, 13, 10, 52, 57, 52, 99, 51, 102, 102, 56, 98, 102
  Data.b 48, 51, 55, 102, 102, 99, 48, 48, 48, 48, 55, 102, 102, 99, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48
  Data.b 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 55, 102, 102, 99, 102, 102, 102, 102, 55, 102, 13, 10, 102, 99, 48, 48, 48, 48, 51, 102, 102, 56
  Data.b 102, 102, 102, 102, 49, 102, 102, 48, 98, 102, 48, 51, 48, 55, 99, 48, 48, 48, 48, 48, 55, 100, 48, 48, 48, 48, 48, 48, 52, 49, 48, 98, 99, 54, 48, 48, 56, 56, 48, 48
  Data.b 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 13, 10, 48, 48, 48, 48, 50, 56, 48, 48, 48, 48
  Data.b 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 49, 48, 48, 48, 52, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
  Data.b 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 13, 10, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
  Data.b 48, 48, 48, 48, 102, 102, 102, 102, 102, 102, 48, 48, 52, 53, 52, 53, 52, 53, 48, 48, 101, 98, 102, 102, 102, 102, 48, 48, 99, 55, 102, 102, 102, 102, 48, 48, 57, 51, 102, 101
  Data.b 102, 102, 48, 48, 48, 48, 99, 101, 102, 102, 48, 48, 49, 51, 102, 100, 102, 102, 48, 48, 48, 48, 101, 97, 102, 102, 48, 48, 13, 10, 48, 48, 57, 100, 102, 101, 48, 48, 48, 48
  Data.b 99, 57, 102, 102, 48, 48, 48, 48, 98, 52, 102, 102, 48, 48, 48, 48, 101, 53, 102, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
  Data.b 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 49, 49, 49, 49, 49, 48, 49, 49, 49, 50, 50, 98, 13, 10, 98, 98, 98, 57, 50, 50, 49, 49, 49, 48
  Data.b 49, 49, 50, 54, 54, 97, 97, 97, 97, 97, 54, 57, 50, 49, 49, 48, 49, 50, 54, 54, 99, 48, 48, 48, 48, 48, 97, 54, 57, 50, 49, 48, 49, 50, 54, 56, 48, 49, 49, 49
  Data.b 49, 49, 48, 97, 54, 50, 49, 48, 50, 54, 56, 48, 49, 49, 49, 49, 49, 49, 49, 48, 97, 57, 50, 48, 50, 55, 56, 48, 13, 10, 49, 49, 49, 49, 49, 49, 49, 48, 97, 98
  Data.b 50, 48, 50, 53, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 98, 50, 48, 50, 53, 48, 56, 56, 56, 56, 56, 56, 56, 56, 56, 48, 98, 50, 48, 50, 52, 55, 56, 56, 48
  Data.b 56, 56, 56, 48, 56, 56, 97, 57, 50, 48, 49, 50, 53, 55, 56, 48, 56, 56, 56, 48, 56, 56, 54, 50, 49, 48, 49, 50, 13, 10, 52, 53, 55, 56, 56, 56, 56, 56, 56, 54
  Data.b 57, 50, 49, 48, 49, 49, 50, 51, 52, 55, 55, 56, 56, 56, 54, 57, 50, 49, 49, 48, 49, 49, 49, 50, 50, 51, 52, 53, 53, 54, 50, 50, 49, 49, 49, 48, 49, 49, 49, 49
  Data.b 49, 50, 50, 50, 50, 50, 49, 49, 49, 49, 49, 48, 48, 56, 48, 48, 48, 48, 48, 48, 50, 54, 48, 54, 48, 102, 48, 48, 13, 10, 48, 54, 48, 48, 53, 52, 52, 101, 53, 48
  Data.b 53, 48, 48, 55, 48, 49, 48, 52, 48, 48, 48, 48, 48, 48, 50, 55, 48, 49, 102, 102, 102, 102, 48, 51, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 13, 10, 125, 125, 13, 10
  Data.b 32
  endsmiley1:
EndDataSection
I may look like a mule, but I'm not a complete ass.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

netmaestro wrote:It really is quite easy. You can just include the OleEdit.pbi source srod posted and it's only:

Code: Select all

IncludeFile "OLEedit.pbi" 

OpenWindow(0, 0, 0, 600, 400, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0)) 
EditorGadget(0, 8, 8, 500, 150) 
RichEdit_SetInterface(GadgetID(0)) 
LoadRtf(0,"smiley.rtf",0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
Now that didn't hurt a bit, did it? There's a CatchRtf function too if you prefer to include it in your exe.
It didnt hurt, you are right, but I prefere to understand the source I use. With srod's include it works fine indeed! But I nearly dont understand only one line with this interfaces. But as for now, I will use this solution. Thanks both of you!!
Tranquil
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

@srod, your example is complaining about the number of parameters for CatchRtf(). If you have a more recent version of the code, could you please update it? Because I think it's a very useful include. Thank you.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Will do.

Yes I couldn't remember if I had updated the code in the relevant posting, I did think that I hadn't gotten around to it! :)
I may look like a mule, but I'm not a complete ass.
Post Reply