GetGadgetItemImage()
GetGadgetItemImage()
Hi,
recently we've got the SetGadgetItemImage() method, so now we can change the images very easy. Today i needed the GetGadgetItemImage() as well. Would you mind adding this to PB?
Best regards
Uwe
recently we've got the SetGadgetItemImage() method, so now we can change the images very easy. Today i needed the GetGadgetItemImage() as well. Would you mind adding this to PB?
Best regards
Uwe
Last edited by uwekel on Wed May 08, 2013 8:22 pm, edited 1 time in total.
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: GetGadgetItemImage()
+1 Actually, seems strange that we haven't got it, don't normally have a Set without a Get.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: GetGadgetItemImage()
+1
Since the absence of GetGadgetItemImage() annoyed me every time I use GadgetItemImages(and makes me clueless how to solve), I'm joining in with the urgent request to add this feature.
Charly
Since the absence of GetGadgetItemImage() annoyed me every time I use GadgetItemImages(and makes me clueless how to solve), I'm joining in with the urgent request to add this feature.
Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
- holzhacker
- Enthusiast
- Posts: 123
- Joined: Mon Mar 08, 2010 9:14 pm
- Location: "Mens sana in corpore sano"
- Contact:
Re: GetGadgetItemImage()
Since there is still no GetGadgetItemImage() after 5 years, I'll bump this thread as well
+1
+1
Re: GetGadgetItemImage()
After more than 6 years of waiting for an implementation in PureBasic, I decided to program a cross-platform GetGadgetItemImage() procedure which I have tested successfully with PB 5.46 in both ASCII and Unicode mode on these operating systems:
- Linux Mint 19.1 x64 'Tessa' with Cinnamon using GTK2 and GTK3
- MacOS 10.6.8 'Snow Leopard'
- MacOS 10.14.5 'Mojave'
- Windows 7 x64 SP1
- Windows 10 x64 Version 1809
Update:
- I had to update the Linux part of procedure GetGadgetItemImage() because the old code didn't use the row parameter and always returned the image which was the last to have been rendered by the CellRenderer. The trick is to store the actual selected row in variable SelectedRow, select the wanted row (that will now be rendered again by the correct CellRenderer) and afterwards restore the selected row from variable SelectedRow (which may be -1, if no row was selected at all).
- I replaced the general codeby the more target-oriented codewhich only in Linux will wait until the ListIconGadget is initialized internally and the following call of GetGadgetItemImage() will safely work.
- Linux Mint 19.1 x64 'Tessa' with Cinnamon using GTK2 and GTK3
- MacOS 10.6.8 'Snow Leopard'
- MacOS 10.14.5 'Mojave'
- Windows 7 x64 SP1
- Windows 10 x64 Version 1809
Code: Select all
EnableExplicit
UsePNGImageDecoder()
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(ListIconID.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(ListIconID)
; ----- Select row with image to get the correct CellRenderer
; for that row
SetGadgetState(ListIconID, Row)
*TreeColumn = gtk_tree_view_get_column_(GadgetID(ListIconID), 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(ListIconID, SelectedRow)
g_list_free_(CellRendererList)
CompilerCase #PB_OS_MacOS
Protected ColumnObject.I
Protected ColumnObjectArray.I
Protected ImageCell.I
CocoaMessage(@ColumnObjectArray, GadgetID(ListIconID), "tableColumns")
CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", 0)
If PeekS(CocoaMessage(0, CocoaMessage(0,
ColumnObject, "identifier"), "UTF8String"), -1, #PB_UTF8) = "Image"
ImageCell = CocoaMessage(0, GadgetID(ListIconID),
"preparedCellAtColumn:", 0,
"row:", 0)
If ImageCell
Image = CocoaMessage(0, ImageCell, "image")
EndIf
EndIf
CompilerCase #PB_OS_Windows
Protected ImageIndex.I
Protected ImageListHandle.I
Protected Item.LV_ITEM
Item.LV_ITEM
Item\Mask = #LVIF_IMAGE
Item\iItem = Row
SendMessage_(GadgetID(ListIconID), #LVM_GETITEM, 0, @Item)
ImageIndex = Item\iImage
ImageListHandle = SendMessage_(GadgetID(ListIconID), #LVM_GETIMAGELIST,
#LVSIL_SMALL, 0)
Image = ImageList_GetIcon_(ImageListHandle, ImageIndex, #ILD_TRANSPARENT)
CompilerEndSelect
ProcedureReturn Image
EndProcedure
If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png") = 0
MessageRequester("Error",
"Unable to load image CdPlayer.ico")
End
EndIf
OpenWindow(0, 270, 100, 220, 130, "GetGadgetItemImage()")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 50,
"Column 1", WindowWidth(0) - 52)
AddGadgetItem(0, -1, "Row with image")
TextGadget(1, 10, GadgetHeight(0) + 20, 100, 25, "Grabbed image:")
ImageGadget(2, 110, GadgetHeight(0) + 20, 16, 16, 0)
SetGadgetItemImage(0, 0, ImageID(0))
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
; ----- Wait until ListIconGadget is initialized
While gtk_widget_get_realized(GadgetID(0)) = #False
Delay(10)
Wend
CompilerEndIf
SetGadgetState(2, GetGadgetItemImage(0, 0))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
- I had to update the Linux part of procedure GetGadgetItemImage() because the old code didn't use the row parameter and always returned the image which was the last to have been rendered by the CellRenderer. The trick is to store the actual selected row in variable SelectedRow, select the wanted row (that will now be rendered again by the correct CellRenderer) and afterwards restore the selected row from variable SelectedRow (which may be -1, if no row was selected at all).
- I replaced the general code
Code: Select all
; ----- Wait until Window and Widgets are initialized (Necessary in Linux)
Repeat : Until WindowEvent() = 0
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
; ----- Wait until listIconGadget is initialized
While gtk_widget_get_realized(GadgetID(0)) = #False
Delay(10)
Wend
CompilerEndIf
Last edited by Shardik on Fri Jul 12, 2019 6:28 pm, edited 4 times in total.
Re: GetGadgetItemImage()
Shardik, thanks for that. Don't know why some simple requests like this get ignored for so long. It's quite depressing.
I also notice that in your #PB_OS_MacOS section you've got GadgetID(0). Shouldn't that be GadgetID(ListIconID)?
I also notice that in your #PB_OS_MacOS section you've got GadgetID(0). Shouldn't that be GadgetID(ListIconID)?
Re: GetGadgetItemImage()
Thank you for pinpointing me to these errors in the MacOS part. I have corrected them in my example above.BarryG wrote:Shardik, thanks for that. Don't know why some simple requests like this get ignored for so long. It's quite depressing.
I also notice that in your #PB_OS_MacOS section you've got GadgetID(0). Shouldn't that be GadgetID(ListIconID)?
- Andre
- PureBasic Team
- Posts: 2071
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: GetGadgetItemImage()
@Shardik:
Thank you for this code example!
Also showing that it should possible to add a native implementation...
Thank you for this code example!
Also showing that it should possible to add a native implementation...
Re: GetGadgetItemImage()
This is wrong : the right answer is 9 (1+1+1+1+1+1+1+1+1)
I'll test this work.
I'll test this work.