GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fun with Glade,GtkBuilder, and JWasm

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
jcfuller



Joined: 31 Mar 2009
Posts: 4

PostPosted: Fri Mar 05, 2010 3:46 pm    Post subject: Fun with Glade,GtkBuilder, and JWasm Reply with quote

I'm not sure how well this will be accepted as I haven't seen any assembler code on the forum?
I am not an assembler purist. I don't particularly like "c" syntax so I decided to try JWasm ( http://www.japheth.de/JWasm.html ) using all the macro's I could find. I am really enjoying JWasm to the point I've written a couple of gtk demos. This one is a conversion of the example here: http://www.micahcarrick.com/12-24-2007/gtk-glade-tutorial-part-1.html.
Ubuntu 32 tested only, using Glade3 (ver 3.6.7).
Here is a link with the complete source attached:
http://www.masm32.com/board/index.php?topic=13530.0


James

source:
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

;=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
; Fun with Glade,GtkBuilder, and JWasm
; James C. Fuller Mar 4,2010
;=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
;compile: JWASM -elf -zcw -Fo gtkb02.o gtkb02.asm
;link: ld -s -o gtkb02 gtkb02.o -I/lib/ld-linux.so.2 `pkg-config --libs gtk+-2.0` -export-dynamic
;=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

    .486
    .model flat,c
    option casemap:none
    public _start
    include ./include/jwasm.inc
    include ./include/gtk_proto.inc
   
   
GTK_FILE_CHOOSER_ACTION_OPEN = 0
GTK_FILE_CHOOSER_ACTION_SAVE = 1
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER = 2
GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER = 3

GTK_RESPONSE_REJECT = -2
GTK_RESPONSE_ACCEPT = -3
GTK_RESPONSE_DELETE_EVENT = -4
GTK_RESPONSE_OK     = -5
GTK_RESPONSE_CANCEL = -6
GTK_RESPONSE_CLOSE  = -7
GTK_RESPONSE_YES    = -8
GTK_RESPONSE_NO     = -9
GTK_RESPONSE_APPLY  = -10
GTK_RESPONSE_HELP   = -11
   
MSGBOX_ERR MACRO t,m
    invoke MsgBox,t,m,3,1
ENDM   
MSGBOX_YN MACRO t,m
    invoke MsgBox,t,m,2,4
ENDM
MSGBOX_OK MACRO t,m
    invoke MsgBox,t,m,0,1
ENDM
   
    .data
    buffer db 512 DUP(0)


    .code
    _start:   
    call main
    invoke exit, 0
;==============================================================================   
MsgBox proc sztitle:DWORD,szmsg:DWORD,typ:DWORD,but:DWORD
    local hDlg,rv
   
    invoke gtk_message_dialog_new, 0, 0, typ, but, szmsg
    mov hDlg,eax
    invoke gtk_window_set_title, hDlg, sztitle
    invoke gtk_dialog_run, hDlg
    mov rv,eax
    invoke gtk_widget_destroy, hDlg
    mov eax,rv
    ret
MsgBox endp   
;==============================================================================
GtkFileChooser proc sztitle:DWORD,typ:DWORD
    local dialog
    local filename,rv
    invoke gtk_file_chooser_dialog_new,sztitle, 0,typ,CStr("gtk-cancel"), GTK_RESPONSE_CANCEL,CStr("gtk-open"), GTK_RESPONSE_ACCEPT,0
    mov dialog,eax
    invoke gtk_dialog_run,dialog
   
    .if eax == GTK_RESPONSE_ACCEPT
        invoke gtk_file_chooser_get_filename, dialog
        mov filename,eax
        invoke strcpy,offset buffer,filename
        invoke g_free,filename   
        mov rv,offset buffer
    .else
        mov rv,0
    .endif   
    invoke gtk_widget_destroy,dialog
    mov eax,rv
   
    ret
GtkFileChooser endp
;==============================================================================
AllDone proc
    invoke exit,0
    ret
AllDone endp
;==============================================================================
on_window_destroy proc  user_data:DWORD,object:DWORD
    invoke exit,0
    ret
on_window_destroy endp
;==============================================================================
on_about_menu_item_activate proc  user_data:DWORD,object:DWORD
    MSGBOX_OK CStr("Glade, Gtk, & JWasm"),CStr(<"JWasm Glade Example",lf,"James C. Fuller",lf,"March 2, 2010")
    ret
on_about_menu_item_activate endp
;==============================================================================
on_new_menu_item_activate proc user_data:DWORD,object:DWORD
    invoke gtk_text_view_get_buffer,user_data
    invoke gtk_text_buffer_set_text, eax,CStr(" "), -1
    ret
on_new_menu_item_activate endp
;==============================================================================
on_open_menu_item_activate proc user_data:DWORD,object:DWORD
    local bufout,bufin,len,fp
    invoke GtkFileChooser,CStr("Testing Testing"),GTK_FILE_CHOOSER_ACTION_OPEN
    .if eax == 0 
        ret
    .endif
    invoke gtk_text_view_get_buffer,user_data
    mov bufout,eax
    invoke fopen,offset buffer,CStr(<"rb">)
    .if eax == 0
        invoke printf,CStr(<"Bad Read",lf>)
        jmp @F
    .endif   
    mov fp,eax
    invoke fseek,fp,0,SEEK_END
    invoke ftell,fp
    mov len,eax   
    invoke fseek,fp,0,SEEK_SET
    invoke malloc,len
    mov bufin,eax
    invoke fread,bufin,1,len,fp
    invoke fclose,fp     
   
    invoke gtk_text_buffer_set_text, bufout, bufin, -1
@@:   
    invoke free,bufin
    ret
on_open_menu_item_activate endp
;==============================================================================
on_save_as_menu_item_activate proc user_data:DWORD,object:DWORD
    local sbid
    invoke GtkFileChooser,CStr("Testing Testing"),GTK_FILE_CHOOSER_ACTION_SAVE
    ;file path/name is now stored in buffer
    ;put it in the status bar whose handle/id is passed via user_data
    invoke gtk_statusbar_get_context_id,user_data,CStr("statusbar")
    mov sbid,eax
    invoke gtk_statusbar_pop,user_data,sbid
    invoke gtk_statusbar_push,user_data,sbid,offset buffer   
    ret
on_save_as_menu_item_activate endp
;==============================================================================
on_save_menu_item_activate proc user_data:DWORD,object:DWORD
    invoke printf,CStr(<"%s",lf>),CStr("Save Menu Item")
    ret
on_save_menu_item_activate endp
;==============================================================================

on_quit_menu_item_activate proc user_data:DWORD,object:DWORD
    invoke exit,0
    ret
on_quit_menu_item_activate endp
;==============================================================================
main proc
    local builder,window,quit_menu_item,quit_button,import_menu_item,new_import_menu_item
    local sdb_menu_item,about_menu_item
    local filein,dbfile,newimp,rb_ifdef,rb_std
       
    invoke gtk_init,0, 0
    .if (eax == 0)
        invoke printf,CStr(<"%s",lf>),CStr("No Gtk")
        jmp Terminate
    .endif
   
    invoke gtk_builder_new
    mov builder,eax
    invoke gtk_builder_add_from_file ,builder,CStr("./tut4.glade"), 0
    invoke gtk_builder_get_object,builder,CStr("window")
    mov window,eax
    invoke gtk_builder_connect_signals,builder, 0
    invoke g_object_unref,builder
    invoke gtk_widget_show,window
    invoke gtk_main
   
Terminate:   
    ret
   
main endp
end _start

Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP