April 25, 2024, 02:46:39 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


GTK is a pain sometimes

Started by Ionic Wind Support Team, August 05, 2008, 11:44:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

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.
Ionic Wind Support Team

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

pistol350

I can't help laughing at that kind of things.  ;D
I really admire your courage Paul!  8)
Regards,

Peter B.

Allan

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!!

Ionic Wind Support Team

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.
Ionic Wind Support Team