It is currently Fri Oct 18, 2019 7:38 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: GetGadgetItemImage()
PostPosted: Tue May 07, 2013 6:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 03, 2011 5:54 pm
Posts: 736
Location: Oldenburg (Germany)
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

_________________
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2


Last edited by uwekel on Wed May 08, 2013 8:22 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Tue May 07, 2013 11:32 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5834
Location: Wales, UK
+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.


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Sat Feb 17, 2018 8:38 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Jun 26, 2014 9:17 am
Posts: 308
Location: Germany
+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

_________________
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Sun Feb 18, 2018 7:38 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 792
+1


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Fri Mar 30, 2018 4:02 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Mar 08, 2010 9:14 pm
Posts: 100
Location: "Mens sana in corpore sano"
+1

_________________
Greetings and thanks!

Romerio Medeiros
romerio@gmail.com


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Wed Jun 13, 2018 3:28 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 911
Location: Canada
Since there is still no GetGadgetItemImage() after 5 years, I'll bump this thread as well :)

+1

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Wed Jun 13, 2018 6:59 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1681
Location: Uttoxeter, UK
+1

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Thu Jun 13, 2019 5:50 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 329
+1


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Thu Jun 13, 2019 7:21 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1102
Location: Germany::Berlin()
+1

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Thu Jun 13, 2019 11:21 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 533
+1


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Sun Jun 16, 2019 9:00 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
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
Code:
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

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 code
Code:
; ----- Wait until Window and Widgets are initialized (Necessary in Linux)
Repeat : Until WindowEvent() = 0
by the more target-oriented code
Code:
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ; ----- Wait until listIconGadget is initialized
  While gtk_widget_get_realized(GadgetID(0)) = #False
   Delay(10)
  Wend
CompilerEndIf
which only in Linux will wait until the ListIconGadget is initialized internally and the following call of GetGadgetItemImage() will safely work.


Last edited by Shardik on Fri Jul 12, 2019 6:28 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Sun Jun 16, 2019 9:41 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 329
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)?


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Sun Jun 16, 2019 10:31 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
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)?

Thank you for pinpointing me to these errors in the MacOS part. I have corrected them in my example above.


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Sun Jun 16, 2019 10:40 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1704
Location: Germany (Saxony, Deutscheinsiedel)
@Shardik:
Thank you for this code example! :D
Also showing that it should possible to add a native implementation... ;-)

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Mon Jun 17, 2019 5:52 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 441
This is wrong : the right answer is 9 (1+1+1+1+1+1+1+1+1)

I'll test this work.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye