[fpc-pascal] FPC and GTK2: GtkCombo

Jan Jelowicki jasj at hydra.ar.wroc.pl
Thu Apr 21 17:07:27 CEST 2005


Thakn you,

> Marco van de Voort wrote:
>> 
>> GTK1 was debugged for Windows because lazarus used it at first. However
>> Lazarus switched to plain win32 later, so I don't think GTK2 on windows is
>> too well debugged in relation with FPC, and I know nobody that uses GTK2
>> with FPC on Windows.
>>

I do :) -- it seems much better than 1.2, an I was too lazy
to learn C fluently :(

> Well, I used my GTK 2 code on Windows and there were no problems at all. And 
> note that I initially wrote and tested that code on Linux, not on Windows.
>

I do the same.

> In summary, there are no "known general problems" with GTK 2 + Win32 + FPC. 
> Everything should work just as under X-Windows under Unices.
>
> Janusz: I think that you must reveal in more details where are your problems. 
> Show us some piece of code etc.
>

   Here it is. You may do not like that code, I do not like it too much,
   but it works. It is rather old code, many times patched and ported.
   I am not able to isolate pure GTK+ code from this bundle in a short time.

   Here I put only the crucial few lines, that invoke new gtkCombo,
   attach a list to it and mount it to outer non-gtk structure.

   The problem is that immediately after gtk_combo_new(), the result has
   in W32 its Entry field equal to NULL. So, no explicit operation could
   be done on that field, although the widget is visible, clickable etc.

   I am using gtk2-2.4.0-1 under redhat, 2.4.14-3 under fedora (they are
   OK), and 2.4.14 under w2k and wine. Using old GTK1.2, no problem is reported.

program sample;
uses
   formica;  // nonstandard, but the most important piece given below.
             // this is high-level api that abstracts from interface
             // details
var
   h: dlghandle;  // == pointer
   items: array[1..5] of shortstring;
const
   current_field: integer = 0;

begin

   formicainit('A sample application');  // calls gtk_init();

   items[1] := 'field 1';
   items[2] := 'field 2';
   items[3] := 'field 3';
   items[4] := 'field 4';
   items[5] := 'last field';
   current_field := 3;

writeln('before: --------------');
writeln(current_field, ': "', items[current_field], '"');

   h := createdialog('A sample dialog'); // calls gtk_dialog_new();
   DefListField(h, 'A sample combo list:', 5, @items, current_field);  // below
   executedialog(h, nil, nil, nil);  // calls loop with gtk_main_iteration
                                     // as many times as needeed

writeln('after: ---------------');
writeln(current_field, ': "', items[current_field], '"'); 
writeln('thanks ---------------');

end.

{
   most important piece defines combo widget in dialog
}
function DefListField(h: DlgHandle; const msg: string; n: index; keyvalues: pstringlist; var ikey: index): boolean;
var
   __p: pchar;
   i: index;
begin
   with pDialogForm(h)^ do begin
     itemTail^ := NewPDlgItem;
     with itemTail^^ do begin
       itemtype := idftype_combo;

       itemsrc_co := @ikey;
       itemvalue_co := ikey;

       ItemLabel := DefLabelWithText(Msg);

       itemBox := pgtkbox(gtk_hbox_new(FALSE, 8));
       gtk_box_pack_start(PgtkBox(itemBox), PGtkWidget(ItemLabel), false, false, 0);

       if (n>0) then begin

         itemCombo := pgtkcombo(gtk_combo_new());
// FALSE in UX, TRUE in WINDOWS
writeln('is Entry nil? ', itemcombo^.entry=nil);
         itemlist_co := nil;

         for i := 1 to n do begin
           __p := str2pchar(keyvalues^[i]);
           itemList_co := g_list_append(itemlist_co, __p);
           { this entry must be passed to the list; do not "strDispose(__p);" now! }
         end;

         gtk_combo_set_popdown_strings(itemcombo, itemList_co);
         if (ikey>0) then begin
           __p := Str2PChar(keyvalues^[ikey]);
           gtk_entry_set_text(pgtkentry(itemcombo^.entry), __p);
           strDispose(__p);
         end else
           gtk_entry_set_text(pgtkentry(itemcombo^.entry), '<???>'#0);

         gtk_combo_set_value_in_list(itemcombo, true, false);
         gtk_entry_set_editable(pgtkentry(itemcombo^.entry), false);

         gtk_box_pack_start(pgtkbox(itembox), pgtkwidget(itemCombo), false, false, 0);
         gtk_widget_show(pgtkwidget(itemCombo));

       end else
         gtk_entry_set_text(pgtkentry(itemcombo^.entry), '<???>'#0);

       itemnrows_co := n;

       gtk_box_pack_start(PGtkBox(Window^.vbox), PGtkWidget(itemBox), false, false, 0);
     end;
     itemTail := @itemTail^^.itemNext;
     result := true;
   end;
end;


(* here is my log from linux

[jasj at hydra siren]$ ../../bin/gtk/sample
before: --------------
3: "field 3"
Dialog created: "A sample dialog"
is Entry nil? FALSE
Dialog: executing
after: ---------------
5: "last field"
thanks ---------------
[jasj at hydra siren]$
*)

(* here is the same from w32 (wine, not windows -- I cut wine logs,
    but there is no difference between wine and true w2k

F:\devel\src\siren>..\..\bin\gtkw2\sample.exe
before: --------------
3: "field 3"
Dialog created: "A sample dialog"
is Entry nil? TRUE

(sample.exe): Gtk-CRITICAL **: file gtkentry.c: line 3642 (gtk_entry_set_text): assertion `GTK_IS_ENTRY (entry)' failed

(sample.exe): Gtk-CRITICAL **: file gtkentry.c: line 3777 (gtk_entry_set_editable): assertion `GTK_IS_ENTRY (entry)' failed
Dialog: executing

(sample.exe): Gtk-CRITICAL **: file gtkentry.c: line 3797 (gtk_entry_get_text): assertion `GTK_IS_ENTRY (entry)' failed

An unhandled exception occurred at $00422031 :
EAccessViolation : Access violation
F:\devel\src\siren>

*)

Is that common for GTKCombo under Windows?

With regards,


                                        Jan Je/lowicki
 		                       jasj at hydra.ar.wroc.pl
-----------------------------------------------------------------
Department of Mathematics       Katedra Matematyki
University of Agriculture       Akademia Rolnicza we Wroc/lawiu
Wroc/law, POLAND
-----------------------------------------------------------------




More information about the fpc-pascal mailing list