IonicWind Software

IWBasic for Linux => General IWLP Discussion => Topic started by: Ionic Wind Support Team on August 05, 2008, 11:44:37 PM

Title: GTK is a pain sometimes
Post by: Ionic Wind Support Team on August 05, 2008, 11:44:37 PM
Whew....
Just in case your wondering why it takes so long between updates.  I've been matching Windows functionality for controls so that you can compile your Emergence Windows source code in the Linux version with little or no changes.  Some controls were easy, like buttons and single line edit controls. 

The list box control was a real pain as there isn't a 1 to 1 match.  In fact GTK2.0 doesn't have a list box control, you have to use a single column GtkTreeView control and set it up to mimic a list box control.  Finally finished it this evening, in Windows creating a list box control is 1 line of API code.  In GTK2 it looks like this:


pScrollWindow = gtk_scrolled_window_new(NULL,NULL)
gtk_scrolled_window_set_policy(pScrollWindow,1,1)
gtk_scrolled_window_set_shadow_type(pScrollWindow,GTK_SHADOW_IN)
hControl = gtk_tree_view_new()
gtk_tree_view_set_headers_visible(hControl, FALSE)
pointer column,renderer
renderer = gtk_cell_renderer_text_new()
column=gtk_tree_view_column_new_with_attributes("",renderer, "text", 0, NULL)
gtk_tree_view_append_column(hControl, column)
pointer pStore:pStore =  gtk_list_store_new(1, G_TYPE_STRING)
gtk_tree_view_set_model(hControl, pStore)
g_object_unref(pStore)
pointer selection
selection = gtk_tree_view_get_selection(hControl)
if (flags & @CTLISTMULTI) = @CTLISTMULTI
gtk_tree_selection_set_mode(selection,3)
endif
if (flags & @CTLISTEXTENDED) = @CTLISTEXTENDED
gtk_tree_selection_set_mode(selection,3)
endif
if (flags & @CTLISTSORT) = @CTLISTSORT
gtk_tree_sortable_set_sort_column_id(pStore,0,0)
gtk_tree_sortable_set_sort_func(pStore,0,&ListboxSortCallback,win,NULL)
endif
gtk_container_add(pScrollWindow,hControl)
'connect signal handlers
g_signal_connect_data(selection,"changed",&ListboxChangedCallback,win,NULL,1 << 0)
g_signal_connect_data(hControl,"row-activated",&ListboxDclickCallback,win,NULL,1 << 0)
'
gtk_fixed_put(win.hClient,pScrollWindow,l,t)
gtk_widget_set_size_request(pScrollWindow,w,h)
g_object_set_data(pScrollWindow,"EBIDENT",id)
g_object_set_data(hControl,"EBIDENT",id)
g_object_set_data(pScrollWindow,"EBTYPE",typ)
g_object_set_data(pScrollWindow,"EBSTYLE",flags)
gtk_widget_show_all(pScrollWindow)
gtk_widget_modify_font(hControl,hFont)
pango_font_description_free(hfont)
return


That doesn't include all of the support functions like addstring, deletestring, getstringcount, etc.  All of which took gobs of code to mimic.  But at least it works and you can happily use one line of Emergence code:

control win,@listbox,"",20,20,150,200,@CTLISTMULTI|@CTLISTSORT,101

Paul.
Title: Re: GTK is a pain sometimes
Post by: LarryMc on August 06, 2008, 12:08:34 AM
amazing! :o

Larry
Title: Re: GTK is a pain sometimes
Post by: pistol350 on August 06, 2008, 02:35:58 AM
I can't help laughing at that kind of things.  ;D
I really admire your courage Paul!  8)
Title: Re: GTK is a pain sometimes
Post by: Allan on August 06, 2008, 04:29:32 PM
It is great how you are doing this so that most of the code is usable.

I have tried it out and it is quite impressive how you have it going.

Actually had SQLite3 running in it yesterday.

Hot Source!!
Title: Re: GTK is a pain sometimes
Post by: Ionic Wind Support Team on August 07, 2008, 02:27:30 AM
It is a struggle sometimes.  Probably wrote about 3000 lines of code total in the last week.

But the benefits are well worth it.  It is getting to the point where very few adjustments are needed from Windows to Linux, at least for programs that stick to the built in Emergence commands.

Keyboard mapping requires more code that you can imagine.  Simple things that you've gotten used to in Windows require a lot more development thought in the Linux port.  Control characters, like CTRL-C, which you expect to be 0x03 ASCII don't work that way in X11.  So there is a lot of translations going on.

The design methodology seems to almost be polar opposites when comparing WinAPI code to GTK.  GTK/X11 likes to be proactive, doing things for you and then sending you a signal when it is done.  Where the WinAPI is reactive, it tells you something needs to be done and its up to your program to do it. An example would be scrollbars...in Windows it sends messages that the user wants to move the thumb slider, and your program decides whether it should be moved and tells Windows where to put it.  In GTK the thumb slider is moved and then it tells your program how much.  So in order to mimic the same functionality I have to tell GTK not to move the slider.

Later,
Paul.