Images in Editor gadgets!

Share your advanced PureBasic knowledge/code with the community.
PHP
User
User
Posts: 65
Joined: Sat Sep 10, 2005 5:38 pm

Post by PHP »

Ups ... i've made a mistake... just inserting the data but not the rtf-ansi-header of the new image (using the given one from the source code here).

Now it works really good but 2 questions i still have:

1) Is it possible to avoid resizing the images in the EditorGadget?

2) Does anyone knows in which format the wmetafile is? Something like .bmp? How to convert a jpg/bmp to this rtf-stuff? I would like to let users upload their (.jpg-)pictures and they should be send to the pb-client which should show those pictures in the EditorGadget()...

Code: Select all

a$="{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}}"
a$+"\viewkind4\uc1\pard\f0\fs20{\pict\wmetafile8\picw397\pich397\picwgoal225\pichgoal225 "

a$+"010009000003f500000002007e0000000000050000000b0200000000050000000c028d018d0125"
a$+"000000f70000031000ffea00004545450000000000ffce0000ffc90000fe9d0000ffb40000fffe"
a$+"9300fffd1300ffffc700ffe50000ffffeb00000000000000000000000000000000000400000034"
a$+"0200000300000035007e000000430f2000cc0000000f000f00000000008d018d01000000002800"
a$+"00000f0000000f000000010004000000000078000000c40e0000c40e0000100000000000000000"
a$+"eaff00454545000000000000ceff0000c9ff00009dfe0000b4ff0093feff0013fdff00c7ffff00"
a$+"00e5ff00ebffff0000000000000000000000000000000000ccccc11111ccccc0ccc116666511cc"
a$+"c0cc13344444351cc0c13320000a2351c0c1300222220431c013000000000a4510180000000000"
a$+"4610170000000000461017800200020046101980020002004510c1720000000231c0c197200000"
a$+"2351c0cc1b988000351cc0ccc11b977311ccc0ccccc11111ccccc02d000000f700000314000000"
a$+"0000800000000080000080800000000080008000800000808000c0c0c000c0dcc000a6caf000ff"
a$+"fbf000a0a0a40080808000ff00000000ff0000ffff00000000ff00ff00ff0000ffff00ffffff00"
a$+"040000003402010004000000f0010000030000000000"
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

1) I don't know enough about ole/com to do this properly. I know it can be done because I have applications that do it. We did hack up a solution which was based on setting the editor gadget to read only and then intercepting mouse clicks, tabs etc. It wasn't pretty but it worked. It's in these forums somewhere.

2) The following posted by dare (somewhere on the first page) leads to some VB code which does something along the lines of what you're after:
http://www.vbforums.com/showthread.php? ... ost2131039.

I'd be interested to see how you get on with this. 8)
I may look like a mule, but I'm not a complete ass.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

A code exists, realized by Sir Dr Dri : http://purebasic.myftp.org/?filename=fi ... Editor.zip
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That is really cool. When I get time I might incorporate that into the little lib above. Well done sir Dri! :)

Thanks for posting that Progi1984.
I may look like a mule, but I'm not a complete ass.
PHP
User
User
Posts: 65
Joined: Sat Sep 10, 2005 5:38 pm

Post by PHP »

Hm don't running in PB4 nor PB3.93 ?!??!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Haven't actually run it (lack of time) but I can see that it produces the rtf string required to embed the image within an ole enabled rich edit control.

Is it crashing out or just doesn't appear to do anything?
I may look like a mule, but I'm not a complete ass.
PHP
User
User
Posts: 65
Joined: Sat Sep 10, 2005 5:38 pm

Post by PHP »

Hm, if using some smileys in a chat-window it refreshes really slow after some minutes... even the mouse turns shortly to the wait-hourglass-icon.

So i better use an ordinary WebGadget() for this purpose.

There you can include images of all kinds (jpg, animated gifs, even flash) and auto-scrolling down is also no problem.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Oh yes, the web gadget will render the image directly, reading from a binary file. Converting to rtf first is not going to be quick!

:)
I may look like a mule, but I'm not a complete ass.
PHP
User
User
Posts: 65
Joined: Sat Sep 10, 2005 5:38 pm

Post by PHP »

The images (smileys) are already converted in rtf-ansi, but if you want to add new chat messages to the gadget, you can't stream... you must take the first part of the gadget (rtf-header including old messages)... put the new one in the middle and add at the end a "}" ... and then write it back to the gadget.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Code: Select all

#SFF_SELECTION
Stream in with the above flag and the rtf content will be inserted wherever the caret happens to be.
I may look like a mule, but I'm not a complete ass.
User avatar
macros
User
User
Posts: 88
Joined: Wed Mar 15, 2006 1:47 pm
Location: Munich

Post by macros »

Is it possible to free the memory used by the images?

Freegadget and setgadgettext("") don't work

Look at the Memory usage of this example:

Code: Select all

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



OpenWindow(0, 0, 0, 600, 400, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
EditorGadget(0, 8, 8, 500, 150)

;Set up the com interface for the editor gadget.
RichEdit_SetInterface(GadgetID(0))

;Load some .rtf content with a simple metafile.

Begin$ = "{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}"
Begin$ +"{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20"

a$+"{\pict\wmetafile8\picwgoal903\pichgoal825 "
a$+"010009000003e402000008000601000000000400000003010800050000000b0200000000050000"
a$+"000c025e017d01040000002e0118001c000000fb021000070000000000bc020000000001020222"
a$+"53797374656d00017d010000f7a9724500ea120004ee8339706e22000c020000040000002d0100"
a$+"0004000000020101001c000000fb029cff0000000000009001000000000440001254696d657320"
a$+"4e657720526f6d616e0000000000000000000000000000000000040000002d0101000500000009"
a$+"02000000020d000000320a5700fdff01000400fdfffdff7a015b0120d92d00030000001e000700"
a$+"0000fc020000ff0000000000040000002d010200040000000601010008000000fa020500000000"
a$+"00ffffff00040000002d0103000601000024038100bb000300b1000300a80004009f0005009600"
a$+"06008d00080084000a007b000d00730010006b001300630017005b001b00540020004c00240045"
a$+"0029003f002f003800340032003a002c0040002700470022004d001d00540019005b0015006200"
a$+"11006a000e0072000b0079000800810006008a000500920003009a000300a3000200ac000300b4"
a$+"000300bd000500c5000600ce000800d6000b00de000e00e6001100ed001500f5001900fc001d00"
a$+"030122000a01270011012c00170132001d01380023013f00280145002e014c003301540037015b"
a$+"003c01630040016b004401730047017b004a0184004d018d004f01960051019f005201a8005301"
a$+"b1005401bb005401c4005401ce005301d7005201e0005101e9004f01f2004d01fa004a01030147"
a$+"010b014401130140011a013c01220137012901330130012e01370128013d01230143011d014901"
a$+"17014f01110154010a01580103015d01fc006101f5006501ed006801e6006b01de006d01d6006f"
a$+"01ce007101c5007201bd007301b4007301ac007301a30072019a00710192006f018a006d018100"
a$+"6b0179006801720065016a00610162005d015b005801540054014d004f0147004901400043013a"
a$+"003d01340037012f003001290029012400220120001a011b00130117000b01130003011000fa00"
a$+"0d00f2000a00e9000800e0000600d7000500ce000400c4000300bb00030008000000fa02000000"
a$+"00000000000000040000002d010400040000000601010007000000fc020000ffffff0000000400"
a$+"00002d01050008000000fa0200000600000000000000040000002d01060007000000fc02010000"
a$+"0000000000040000002d0107000601000025038100bb000300b1000300a80004009f0005009600"
a$+"06008d00080084000a007b000d00730010006b001300630017005b001b00540020004c00240045"
a$+"0029003f002f003800340032003a002c0040002700470022004d001d00540019005b0015006200"
a$+"11006a000e0072000b0079000800810006008a000500920003009a000300a3000200ac000300b4"
a$+"000300bd000500c5000600ce000800d6000b00de000e00e6001100ed001500f5001900fc001d00"
a$+"030122000a01270011012c00170132001d01380023013f00280145002e014c003301540037015b"
a$+"003c01630040016b004401730047017b004a0184004d018d004f01960051019f005201a8005301"
a$+"b1005401bb005401c4005401ce005301d7005201e0005101e9004f01f2004d01fa004a01030147"
a$+"010b014401130140011a013c01220137012901330130012e01370128013d01230143011d014901"
a$+"17014f01110154010a01580103015d01fc006101f5006501ed006801e6006b01de006d01d6006f"
a$+"01ce007101c5007201bd007301b4007301ac007301a30072019a00710192006f018a006d018100"
a$+"6b0179006801720065016a00610162005d015b005801540054014d004f0147004901400043013a"
a$+"003d01340037012f003001290029012400220120001a011b00130117000b01130003011000fa00"
a$+"0d00f2000a00e9000800e0000600d7000500ce000400c4000300bb000300040000002d01040004"
a$+"0000002d01050004000000f0010600040000002701ffff040000002d010000030000000000"

String$+Begin$
For I=1 To 100
  String$+a$+"}"
Next

SetGadgetText(0, String$) ; Fill the gadget...Memory is now in use
SetGadgetText(0, "") ; Now i clear the gadget but the memory is still in use


Repeat

  For a=1 To 50
    If WindowEvent()=#PB_Event_CloseWindow
      End
    EndIf
    Delay(2)
  Next

  SetGadgetText(0, String$) ; Fill the gadget...Memory is now in use
  SetGadgetText(0, "") ;Memory is still in Use
Until WaitWindowEvent() = #PB_Event_CloseWindow
Macros
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Windows freed the Gadgetmemory, but you should free the Stringvariable:

Code: Select all

String$ = ""
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

No, Macros is correct in that there is a major memory leak here. Afraid I don't really know enough about COM to get to the bottom of this. I'll keep looking though.
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 »

Right, I've found the problem. It'll take a while to fix though.
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 »

@macros, I have a fix, but I'm not sure how stable this will be. It will need a bit more testing.

Basically, in the include file, switch the RichEdit_GetNewStorage() procedure for:

Code: Select all

Procedure.l RichEdit_GetNewStorage(*pObject.RichEditOle, lplpstg)
  Protected sc, lpLockBytes, t.ILockBytes
;Attempt to create a byte array object which acts as the 'foundation' for the upcoming compound file.
  sc=CreateILockBytesOnHGlobal_(#Null, #True, @lpLockBytes) 
  If sc ;This means that the allocation failed.
    ProcedureReturn sc
  EndIf
;Allocation succeeded so we now attempt to create a compound file storage object.
  sc=StgCreateDocfileOnILockBytes_(lpLockBytes, #STGM_SHARE_EXCLUSIVE|#STGM_READWRITE|#STGM_CREATE, 0, lplpstg)
  t = lpLockBytes
  t\Release()  
EndProcedure
Common sense dictates that this should not work, but if the proof of the pudding is in the eating... :)

I'll keep looking for a better solution.
I may look like a mule, but I'm not a complete ass.
Post Reply