flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > [solved] gtk+3 treeview example

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2014, 13:14
hi,
i am trying to use gtk3 treeview, but failed so far,

i tried the following after consulted lots revolution's websites, i got something printed out in treeview, but not the exact text i am after.

Image


Code:
format PE GUI 4.0
entry start

include 'win32ax.inc'

struct GtkTreeIter
 stamp          dd ?
 user_data      dd ?
 user_data2     dd ?
 user_data3     dd ? 
ends  

; -------------------------------------------------
section '.data' data readable writeable
; -------------------------------------------------
window1         dd ?    ; window handle
scroll1         dd ?    ; scrollable window

liststore1      dd ?    ; liststore
tree1           dd ?    ; treeview
render1         dd ?    ; render use with treeview column
treecol1        dd ?    ; treeview column
treeiter1       GtkTreeIter

hboxmain        dd ?



; -------------------------------------------------
section '.code' code readable executable
; -------------------------------------------------
start:
        cinvoke gtk_init,NULL,NULL
        cinvoke gtk_window_new,0
          mov   [window1],eax
        cinvoke gtk_window_set_title,[window1],<'GTK+3 TreeView no more listbox',0>
        cinvoke gtk_window_set_default_size,[window1],160,200
        cinvoke g_signal_connect_data,[window1],<'destroy',0>,cbSignalDestroy,NULL,NULL,NULL

        ; object creation
        ; ---------------
        cinvoke gtk_box_new,0,10
          mov   [hboxmain],eax
        cinvoke gtk_scrolled_window_new,NULL,NULL
          mov   [scroll1],eax
        cinvoke gtk_tree_view_new
          mov   [tree1],eax
        cinvoke gtk_cell_renderer_text_new
          mov   [render1],eax
        cinvoke gtk_tree_view_column_new_with_attributes,\
                <'Popular Assembler',0>,[render1],<'text',0>,0,NULL
          mov   [treecol1],eax
        cinvoke gtk_tree_view_append_column,[tree1],[treecol1]
        cinvoke gtk_scrolled_window_add_with_viewport,[scroll1],[tree1] 

        cinvoke g_type_fundamental,16
        cinvoke gtk_list_store_new,1,eax
          mov   [liststore1],eax
        
        cinvoke gtk_list_store_append,[liststore1],treeiter1
        cinvoke gtk_list_store_set,[liststore1],treeiter1,0,<'FASM',0>,-1
        cinvoke gtk_list_store_append,[liststore1],treeiter1
        cinvoke gtk_list_store_set,[liststore1],treeiter1,0,<'MASM',0>,-1
        cinvoke gtk_list_store_append,[liststore1],treeiter1
        cinvoke gtk_list_store_set,[liststore1],treeiter1,0,<'NASM',0>,-1
        cinvoke gtk_list_store_append,[liststore1],treeiter1
        cinvoke gtk_list_store_set,[liststore1],treeiter1,0,<'YASM',0>,-1
        cinvoke gtk_tree_view_set_model,[tree1],[liststore1]
        cinvoke g_object_unref,[liststore1]
        



        ; layout
        ; ------
        cinvoke gtk_container_add,[window1],[scroll1]

        cinvoke gtk_widget_show_all,[window1]
        cinvoke gtk_main
        invoke  ExitProcess,0


proc cbSignalDestroy c, data, cbdata
; -------------------------------------------------
        cinvoke gtk_main_quit
          ret
endp

; -------------------------------------------------
section '.idata' import data readable
; -------------------------------------------------
library kernel32,'KERNEL32.DLL',\
        user32,'USER32.DLL',\
        msvcrt,'MSVCRT.DLL',\
        libgtk_3_0, 'libgtk-3-0.DLL',\
        libgobject_2.0_0, 'libgobject-2.0-0.dll'

include 'API\KERNEL32.INC'
include 'API\USER32.INC'
include 'API\MSVCRT32.INC'
include 'libgtk-3-0.inc'
include 'libgobject-2.0-0.inc'
    


Last edited by sleepsleep on 12 Feb 2014, 14:44; edited 1 time in total
Post 09 Feb 2014, 13:14
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 09 Feb 2014, 16:43
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:16; edited 1 time in total
Post 09 Feb 2014, 16:43
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2014, 17:01
just checked my inbox, nothing inside.
Post 09 Feb 2014, 17:01
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 09 Feb 2014, 19:25
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:15; edited 1 time in total
Post 09 Feb 2014, 19:25
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2014, 19:49
idk what to use, i guess gtk choose me?
but what choices asm got? c gui library only a few,
Post 09 Feb 2014, 19:49
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 09 Feb 2014, 20:57
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:15; edited 1 time in total
Post 09 Feb 2014, 20:57
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2014, 21:06
i am open for suggestions
Post 09 Feb 2014, 21:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 10 Feb 2014, 00:28
The Windows API supports tree view controls natively. It has supported these ever since the dawn of history itself.
Post 10 Feb 2014, 00:28
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 10 Feb 2014, 10:00
ok,
could somebody help me with this gtk3 treeview, i don't get it why it doesn't works =(

i follow exactly the c code, afaik, it should works.

http://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Introduction
Code:


/* 
 * Compile with:
 *  gcc -o helloworld helloworld.c `pkg-config --cflags --libs gtk+-2.0`
 *
 */
 
#include <gtk/gtk.h>
 
enum
{
  COL_NAME = 0,
  COL_AGE,
  NUM_COLS
} ;
 
 
static GtkTreeModel *
create_and_fill_model (void)
{
  GtkListStore  *store;
  GtkTreeIter    iter;
 
  store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);
 
  /* Append a row and fill in some data */
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter,
                      COL_NAME, "Heinz El-Mann",
                      COL_AGE, 51,
                      -1);
 
  /* append another row and fill in some data */
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter,
                      COL_NAME, "Jane Doe",
                      COL_AGE, 23,
                      -1);
 
  /* ... and a third row */
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter,
                      COL_NAME, "Joe Bungop",
                      COL_AGE, 91,
                      -1);
 
  return GTK_TREE_MODEL (store);
}
 
static GtkWidget *
create_view_and_model (void)
{
  GtkCellRenderer     *renderer;
  GtkTreeModel        *model;
  GtkWidget           *view;
 
  view = gtk_tree_view_new ();
 
  /* --- Column #1 --- */
 
  renderer = gtk_cell_renderer_text_new ();
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
                                               -1,      
                                               "Name",  
                                               renderer,
                                               "text", COL_NAME,
                                               NULL);
 
  /* --- Column #2 --- */
 
  renderer = gtk_cell_renderer_text_new ();
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
                                               -1,      
                                               "Age",  
                                               renderer,
                                               "text", COL_AGE,
                                               NULL);
 
  model = create_and_fill_model ();
 
  gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
 
  /* The tree view has acquired its own reference to the
   *  model, so we can drop ours. That way the model will
   *  be freed automatically when the tree view is destroyed */
 
  g_object_unref (model);
 
  return view;
}
 
 
int
main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *view;
 
  gtk_init (&argc, &argv);
 
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "delete_event", gtk_main_quit, NULL); /* dirty */
 
  view = create_view_and_model ();
 
  gtk_container_add (GTK_CONTAINER (window), view);
 
  gtk_widget_show_all (window);
 
  gtk_main ();
 
  return 0;
}


    
Post 10 Feb 2014, 10:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 10 Feb 2014, 10:20
sleepsleep wrote:
could somebody help me with this gtk3 treeview,
Quote:
* gcc -o helloworld helloworld.c `pkg-config --cflags --libs gtk+-2.0`
I have no idea if this matters, but perhaps 2<>3?
Post 10 Feb 2014, 10:20
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 10 Feb 2014, 11:01
no luck,
i found a 3 source here maybe,
http://ubuntuforums.org/showthread.php?t=1760453

i guess the issue is on
Code:
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
    

because
Code:
    model = gtk_tree_store_new(N_COL, 
                               G_TYPE_STRING,
                               G_TYPE_STRING);
    treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
    g_object_unref(model);
    


but still no success,
Post 10 Feb 2014, 11:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 10 Feb 2014, 11:22
So switch to the well documented Windows API tree view controls instead.


Last edited by revolution on 10 Feb 2014, 11:27; edited 1 time in total
Post 10 Feb 2014, 11:22
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 10 Feb 2014, 11:26
well,
i just kinda,, frustrated why they could do it but i couldn't.
Post 10 Feb 2014, 11:26
View user's profile Send private message Reply with quote
gens



Joined: 18 Feb 2013
Posts: 161
gens 10 Feb 2014, 12:32
sleepsleep wrote:
well,
i just kinda,, frustrated why they could do it but i couldn't.


you are not the only one
Post 10 Feb 2014, 12:32
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 10 Feb 2014, 12:56
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:14; edited 1 time in total
Post 10 Feb 2014, 12:56
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 10 Feb 2014, 17:00
i still waiting for your message, HaHaAnonymous..
Post 10 Feb 2014, 17:00
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 10 Feb 2014, 20:09
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:14; edited 1 time in total
Post 10 Feb 2014, 20:09
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12845
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 10 Feb 2014, 20:34
HaHaAnonymous wrote:

Please, check your inbox...


HaHaAnonymous wrote:

And what do you want me to send you?


idk, you ask me to check my inbox,
maybe whatever, otherwise you already sent to me,
i guess, i am talking to myself again....
Post 10 Feb 2014, 20:34
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 10 Feb 2014, 21:28
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:14; edited 1 time in total
Post 10 Feb 2014, 21:28
View user's profile Send private message Reply with quote
Gunner



Joined: 28 Jul 2003
Posts: 17
Location: In my head
Gunner 12 Feb 2014, 05:04
Ok let's get this working!

This is not needed:
Code:
cinvoke g_type_fundamental,16    


But if you change this:
Code:
cinvoke gtk_list_store_new,1,eax    


To this:
Code:
cinvoke gtk_list_store_new,1,16    

It still won't work.

Let's look at the docs for G_TYPE_STRING:
Quote:
#define G_TYPE_STRING G_TYPE_MAKE_FUNDAMENTAL (16)

Ok, there is a 16 there, but what does G_TYPE_MAKE_FUNDAMENTAL do? Let's see...
Quote:
#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))


Ok getting closer... What is the value of G_TYPE_FUNDAMENTAL_SHIFT? Couldn't find it in the docs, so let's look at the source code:

gtype.h:

Quote:
#define G_TYPE_FUNDAMENTAL_SHIFT (2)


BINGO!!! G_TYPE_MAKE_FUNDAMENTAL left shifts by 2. Hmm... lets left shift 16 by 2 and we get 64.. Now we have something to work with.

Code:
cinvoke gtk_list_store_new,1,64    


VOILA!!! We now have properly displaying strings in the treeview!!!

May I ask, why you don't just use a GLADE file to create the UI?


Description: POC
Filesize: 29.32 KB
Viewed: 23584 Time(s)

2-12-2014 12-02-40 AM.png



_________________
~Rob (Gunner)
Forum Spam List Checker
Window Error Lookup Tool
and MORE!
Post 12 Feb 2014, 05:04
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.