What?Olliv wrote:This is wrong : the right answer is 9 (1+1+1+1+1+1+1+1+1)
I'll test this work.
GetGadgetItemImage()
Re: GetGadgetItemImage()
- RSBasic
- Moderator
- Posts: 1218
- Joined: Thu Dec 31, 2009 11:05 pm
- Location: Gernsbach (Germany)
- Contact:
Re: GetGadgetItemImage()
+1Andre wrote:Also showing that it should possible to add a native implementation...
Re: GetGadgetItemImage()
It is now 11 (op +1 +1 +1 +1 +1 +1 +1 +1 +1 * 2).Olliv wrote:This is wrong : the right answer is 9 (1+1+1+1+1+1+1+1+1)
I'll test this work.
Re: GetGadgetItemImage()
While my previous posting in this thread presented a cross-platform procedure GetGadgetItemImage() for the ListIconGadget, the following example demonstrates a cross-platform procedure GetGadgetItemImage() for the TreeGadget. The Linux part is identical to the ListIconGadget example while in MacOS and Windows the code is different. Especially the MacOS part in the following example is a hack. Although it works without problems with PB 5.46 in ASCII and Unicode mode in Snow Leopard (x86 PB compiler) and Mojave (x64 PB compiler), the code is dependent on PureBasic internals and may break in future versions. Therefore only a native implementation would be future-proof...
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
#G_TYPE_OBJECT = 20 << 2
ImportC ""
g_object_get_property(*Object.GObject, PropertyName.P-UTF8,
*PropertyValue.GValue)
g_type_check_instance_is_a(*Instance.GTypeInstance, *Type.GTypeClass)
gtk_cell_layout_get_cells(*CellLayout)
gtk_widget_get_realized(*Widget.GtkWidget)
EndImport
CompilerEndIf
Procedure GetGadgetItemImage(TreeGadgetID.I, Row.I)
Protected Image.I
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected CellRenderer.I
Protected CellRendererList.I
Protected PixBuf.GValue
Protected SelectedRow.I
Protected *TreeColumn
SelectedRow = GetGadgetState(TreeGadgetID)
SetGadgetState(TreeGadgetID, Row)
*TreeColumn = gtk_tree_view_get_column_(GadgetID(TreeGadgetID), 0)
CellRendererList = gtk_cell_layout_get_cells(*TreeColumn)
CellRenderer = g_list_nth_data_(CellRendererList, 0)
If g_type_check_instance_is_a(CellRenderer,
gtk_cell_renderer_pixbuf_get_type_())
PixBuf\g_type = #G_TYPE_OBJECT
g_object_get_property(CellRenderer, "pixbuf", @PixBuf)
Image = g_value_get_object_(@PixBuf)
EndIf
SetGadgetState(TreeGadgetID, SelectedRow)
g_list_free_(CellRendererList)
CompilerCase #PB_OS_MacOS
Protected Item.I
Item = CocoaMessage(0, GadgetID(TreeGadgetID), "itemAtRow:", Row)
Image = PeekI(PeekI(PeekI(Item + SizeOf(Integer))) + SizeOf(Integer) * 3)
CompilerCase #PB_OS_Windows
Protected Bitmap.BITMAP
Protected IconHandle.I
Protected IconInfo.ICONINFO
Protected Item.TVITEM
Item\hItem = GadgetItemID(TreeGadgetID, Row)
Item\mask = #TVIF_IMAGE
SendMessage_(GadgetID(TreeGadgetID), #TVM_GETITEM, 0, @Item)
IconHandle = ImageList_GetIcon_(SendMessage_(GadgetID(TreeGadgetID),
#TVM_GETIMAGELIST, #TVSIL_NORMAL, 0), Item\iImage, 0)
If GetIconInfo_(IconHandle, IconInfo)
If GetObject_(IconInfo\hbmMask, SizeOf(BITMAP), Bitmap)
Image = CreateImage(#PB_Any, Bitmap\bmWidth, Bitmap\bmHeight, 32)
If Image
If StartDrawing(ImageOutput(Image))
Box(0, 0, Bitmap\bmWidth, Bitmap\bmHeight, #White)
DrawImage(IconHandle, 0, 0)
StopDrawing()
Image = ImageID(Image)
Else
FreeImage(Image)
Image = 0
EndIf
EndIf
EndIf
EndIf
CompilerEndSelect
ProcedureReturn Image
EndProcedure
If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/Drive.bmp") = 0
MessageRequester("Error", "Unable to load image Drive.bmp")
End
ElseIf LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/File.bmp") = 0
MessageRequester("Error", "Unable to load image File.bmp")
End
EndIf
OpenWindow(0, 270, 100, 220, 155, "GetGadgetItemImage()")
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 70)
AddGadgetItem(0, -1, "Item 1", ImageID(0))
AddGadgetItem(0, -1, "Subitem 1.1", 0, 1)
AddGadgetItem(0, -1, "Subitem 1.2", ImageID(1), 1)
SetGadgetItemState(0, 0, #PB_Tree_Expanded)
TextGadget(1, 10, GadgetHeight(0) + 20, 150, 25, "Grabbed image row 0:")
ImageGadget(2, 165, GadgetHeight(0) + 22, 16, 16, 0)
TextGadget(3, 10, GadgetHeight(0) + 45, 150, 25, "Grabbed image row 2:")
ImageGadget(4, 165, GadgetHeight(0) + 45, 16, 16, 0)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
; ----- Wait until TreeGadget is initialized
While gtk_widget_get_realized(GadgetID(0)) = #False
Delay(10)
Wend
CompilerEndIf
; ----- Draw grabbed images
SetGadgetState(2, GetGadgetItemImage(0, 0))
SetGadgetState(4, GetGadgetItemImage(0, 2))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: GetGadgetItemImage()
This is an old thread, but I also want to ask Fred and company to add GetGadgetItemImage() to PureBasic, especially if any solution that Shardik or somebody else comes up with will be dependent on PureBasic internals.
(I just tried to call GetGadgetItemImage() on a TreeGadget and got the message "[COMPILER] Line 113: GetGadgetItemImage() is not a function, array, list, map or macro." I'm using PureBasic 5.72 (64-bit) on Linux Mint 19.)
Please add this. Why have SetGadgetItemImage() but not GetGadgetItemImage()?
(I just tried to call GetGadgetItemImage() on a TreeGadget and got the message "[COMPILER] Line 113: GetGadgetItemImage() is not a function, array, list, map or macro." I'm using PureBasic 5.72 (64-bit) on Linux Mint 19.)
Please add this. Why have SetGadgetItemImage() but not GetGadgetItemImage()?
Re: GetGadgetItemImage()
Did you try my TreeGadget example from above? I just tested it on Linux Mint Cinnamon 19.3 'Tricia' x64 with PB 5.72 x64 and it works like a charm.Karig1965 wrote:(I just tried to call GetGadgetItemImage() on a TreeGadget and got the message "[COMPILER] Line 113: GetGadgetItemImage() is not a function, array, list, map or macro." I'm using PureBasic 5.72 (64-bit) on Linux Mint 19.)
Because GetGadgetItemImage() is currently not implemented in PureBasic 5.72, you have to copy the ImportC block and the procedure GetGadgetItemImage() into your own code before being able to call GetGadgetItemImage().
Re: GetGadgetItemImage()
I haven't tried it. I thought about it, but if there's a fair chance that your code may stop working with a future release of PureBasic, I'd rather have a solution that's more future-proof. (*shrug*) Images in the tree gadget are a "nice to have", not a hard requirement for my project, and I can live without them.Shardik wrote:Did you try my TreeGadget example from above? I just tested it on Linux Mint Cinnamon 19.3 'Tricia' x64 with PB 5.72 x64 and it works like a charm.Karig1965 wrote:(I just tried to call GetGadgetItemImage() on a TreeGadget and got the message "[COMPILER] Line 113: GetGadgetItemImage() is not a function, array, list, map or macro." I'm using PureBasic 5.72 (64-bit) on Linux Mint 19.)
Because GetGadgetItemImage() is currently not implemented in PureBasic 5.72, you have to copy the ImportC block and the procedure GetGadgetItemImage() into your own code before being able to call GetGadgetItemImage().
Thanks anyway.