JWasm example using Glade & GtkBuilder (Linux tested only)

Started by jcfuller, March 03, 2010, 11:28:35 AM

Previous topic - Next topic

jcfuller

Here is a Linux (ubuntu 32 tested) example of JWasm using Glade3 (ver 3.6.7). Glade file in the zip.
James

source:

;=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
; 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