Copy RTF text?

Just starting out? Need help? Post your questions and find answers here.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

This works here, I'm not sure if this is what you're looking for:

Code: Select all

#RECO_COPY = 2

If OpenWindow(0, 200, 50, 640, 480, "Editor Gadget Copy Paste", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget)=0:End:EndIf
If CreateMenu(0, WindowID(0))=0:End:EndIf
  MenuTitle("&Edit")
    MenuItem(0, "Paste to 2")
If CreateGadgetList(WindowID(0))=0:End:EndIf 
EditorGadget(0, 0, 0, WindowWidth(0)/2, WindowHeight(0))
EditorGadget(1, WindowWidth(0)/2, 0, WindowWidth(0)/2, WindowHeight(0))
Repeat
  EventID = WaitWindowEvent()
  If EventID=#PB_Event_Menu And EventMenu()=0
    SendMessage_(GadgetID(0), #EM_GETOLEINTERFACE, 0, @Object.IRichEditOle)
    chr.s = Space(8):PokeL(@chr, 0):PokeL(@chr+4, -1) ; Workaround for bug in IRichEditOle::GetClipboardData PB definition
;    chr.CHARRANGE\cpMax = -1                    ; end char (0, -1): the whole data
;    Object\GetClipboardData(@chr, #RECO_COPY, @dataobj.IDataObject)
    Object\GetClipboardData(chr, #RECO_COPY, @dataobj.IDataObject)
    SendMessage_(GadgetID(1), #EM_GETOLEINTERFACE, 0, @Object2.IRichEditOle)
    Object2\ImportDataObject(dataobj, 0, 0) ; text will replace current selection or
  EndIf                                        ; placed at currect cursor position
Until EventID=#PB_Event_CloseWindow
End
El_Choni
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

That works very nice El_Choni, thank you!

However Iam still having trouble:
Iam using a callback to check if tab has been pressed or editorgadget has changed. The mask is:

Code: Select all

  ;...We catch the events in the #WM_COMMAND and #WM_NOTIFY msg in our CallBack procedure
  SendMessage_(GadgetID(#MainEditor), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS|#ENM_CHANGE|SendMessage_(GadgetID(#MainEditor), #EM_GETEVENTMASK, 0, 0))
This effects editorgadget so that it doesn't change RTF-text background color when using your copy snippet, however all other changes seem to work all right.
If the mask is removed copying works well.

Timo
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

You mean, if you use that mask, the text background color isn't copied?
El_Choni
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

I thought that the mask or the callback was causing the problem, but I made another code and disabling either mask or callback; no problem, copy still works.

I must check what is really causing the problem...

Timo
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

The change event in the editorgadget was reason for that.
The copy snippet works great, me just being really stupid!!!

:oops: Timo
Post Reply