Images in Editor gadgets!

Share your advanced PureBasic knowledge/code with the community.
User avatar
macros
User
User
Posts: 88
Joined: Wed Mar 15, 2006 1:47 pm
Location: Munich

Post by macros »

Thank you very much.

Here it works nearly perfekt Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

More testing seems to confirm that this is a 'stable' solution, but on the face of it, it appears that the memory being set aside for the OLE object being streamed is immediately deleted. However, there seems to be something in the IStorage interface which I now presume is making a copy of the data.

COM does my head in at the best of times! :)
I may look like a mule, but I'm not a complete ass.
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

Some suggestions for modifications:

Code: Select all

Structure RichEditOle
   *pIntf.IRicheditOle
   Refcount.l
   hwnd.l
EndStructure


Procedure.l RichEdit_SetInterface(hWnd)
  Protected No_Com.l

  ForEach RichComObject()
      If RichComObject()\hwnd=hwnd
          No_Com=1
          Break
      EndIf 
  Next 
    
  If No_Com=0
   AddElement(RichComObject())
   RichComObject()\pIntf = ?VTable
   RichComObject()\hwnd=hwnd
   SendMessage_(hWnd, #EM_SETOLECALLBACK, 0, RichComObject())
   ProcedureReturn RichComObject()
  EndIf
EndProcedure

Procedure.l RichEdit_QueryInterface(*pObject.RichEditOle, REFIID, *ppvObj.LONG)
  Protected *pointeur.IRicheditOle
  *pointeur=*pObject
  If CompareMemory(REFIID, ?IID_IUnknown, 16)=1 Or CompareMemory(REFIID, ?IID_IRichEditOleCallback, 16)=1
    Debug "QueryInterface"
    *ppvObj\l = *pObject
    *pointeur\AddRef()
    ProcedureReturn #S_OK
  Else
    *ppvObject=0
    ProcedureReturn #E_NOINTERFACE
  EndIf
EndProcedure


IID_IRichEditOleCallback: ;" 0x00020D03, 0, 0, 0xC0,0,0,0,0,0,0,0x46"
Data.l $00020D03
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46  

IID_IUnknown:   ;"{00000000-0000-0000-C000-000000000046}"
Data.l $00000000
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46  
Last edited by Nico on Sun Jul 01, 2007 11:24 am, edited 1 time in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi Nico.

One question; what does it do? :)
I may look like a mule, but I'm not a complete ass.
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

Your procedure RichEdit_QueryInterface was not complete even if we can do without it, and I completed your procedure RichEdit_SetInterface to avoid several instance of RicheditOle for the same Gadget.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Got it, thanks. COM isn't one of my strong points I'm afraid!

The following is what I have at the moment and includes some rich edit formatting commands which I've picked up along the way.

CODE REMOVED - see the first post for the updated code.
Last edited by srod on Thu Nov 29, 2007 11:17 am, edited 2 times in total.
I may look like a mule, but I'm not a complete ass.
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

If you want, you can include my last procedure to copy an image without using the clipboard.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Update : 29th Nov 2007.
Have adjusted the CatchRTF() and LoadRTF() functions which now add a second optional parameter in which you specify the format of the stream/file being loaded; #SF_TEXT (default) or #SF_RTF.

See topic : http://www.purebasic.fr/english/viewtop ... 733#220733

See the first post for the code.
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

srod wrote:I can prevent the drop easily enough, - snip

My suspicion is that you will need to intercept the drop, open the file yourself and somehow stream the contents whilst converting to rtf format yourself!

I'll keep searching however. :D
I'm using an ole enabled editorgadget into which I would like to dropprivate. Since olenabling appears to interfer with PB's native dragDrop processing, I'm very interested in learning how I can "intercept the drop" as referenced above.

It appears to be possible via the RichEdit_QueryAcceptData, however I am getting two notifications for each drag and drop - one when the dragged item enters the editorgadget boundary and another when it is dropped.

Does anyone know what additional information is available which will allow me to determine which of those actions it may have been?

Or perhaps if there's a better method?

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Seems to work okay here with private drags and OLE enabled editor gadgets!

Here's the code I just quickly tried :

Code: Select all

XIncludeFile "OLEedit.pbi"

OpenWindow(0,0,0,480,400,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
ListIconGadget(0,20,20,200,300,"Gadget 0", 195, #PB_ListIcon_FullRowSelect) 
EditorGadget(1,250,20,200,300) 
  RichEdit_SetInterface(GadgetID(1))

AddGadgetItem(0, -1, "c:\test.txt") 
AddGadgetItem(0, -1, "Beryl") 
AddGadgetItem(0, -1, "Charles") 
AddGadgetItem(0, -1, "Daniel") 
AddGadgetItem(0, -1, "Ernest") 

EnableGadgetDrop(1,#PB_Drop_Private, #PB_Drag_Move, 1) 

Repeat 
  ev = WaitWindowEvent() 
  Select ev 
    Case #PB_Event_GadgetDrop 
      If EventDropType() = #PB_Drop_Private
        Debug "Private drop " + Str(EventDropPrivate())
      EndIf
    Case #PB_Event_Gadget 
      If EventType() = #PB_EventType_DragStart
        DragPrivate(1, #PB_Drag_Move)
      EndIf 
 EndSelect 
Until ev = #PB_Event_CloseWindow 
I pasted some images alongside the drags... no problem!
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Bug fixed in the above code... :oops:
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

srod wrote:Bug fixed in the above code... :oops:
You really had me going there for a while :D

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I see how certain drag operations seem to be upset by using PB's drag & drop commands which is no surprise really considering that rich edit controls seem to enable OLE drag/drop by default anyhow.
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

OK, yours works fine.

Mine, on the other hand, accepts items dragged from outside the window (srod's does not) but does not seem to trigger a drop event for those dragged from the listicongadget. It does, however receive events in the RichEdit_QueryAcceptData procedure. One for any 'entry' and one when it's dropped. No way I can tell to distinguish them though.

Show us code! Well, as far as I can tell, it's as srods, the editorgadget does have some characteristics set via sendmessage to recognize links, etc, but the enablegadgetdrop is per srods example. The program weighs in at 20,000+ lines, so showing code is somewhat problematic.

Just wondering if someone may have come across this before and be able to offer a suggestion/hint.

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Check out the 'fReally' parameter of the RichEdit_QueryAcceptData() function. I think this should allow you to determine when the drop actually occurs.
I may look like a mule, but I'm not a complete ass.
Post Reply