It is currently Wed Sep 18, 2019 2:04 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: GetGadgetItemImage()
PostPosted: Mon Jun 17, 2019 7:14 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 262
Olliv wrote:
This is wrong : the right answer is 9 (1+1+1+1+1+1+1+1+1)
I'll test this work.

What?


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Mon Jun 17, 2019 8:15 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1094
Location: Germany::Berlin()
Andre wrote:
Also showing that it should possible to add a native implementation... ;-)

+1

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Mon Jun 17, 2019 8:26 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3573
Location: Utah, USA
Olliv wrote:
This is wrong : the right answer is 9 (1+1+1+1+1+1+1+1+1)
I'll test this work.

It is now 11 (op +1 +1 +1 +1 +1 +1 +1 +1 +1 * 2). :)

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: GetGadgetItemImage()
PostPosted: Sun Jul 14, 2019 10:08 am 
Offline
Addict
Addict
User avatar

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


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 10 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