Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-09

GtkWidget questions

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

SteveG

Need some pointers on the way Laz/fpc handle gtkwidgets if possible.

I am attempting (as a test) to get and then set the size and position of a Laz form using Gtk / Gdk - (not necessary I know, just leading to further things)

The Form1.Handle is a pointer to a gtkwidget - saved as 'WinHandle'. From this, I can retrieve its name, and so know I have the right pointer. How can I alter the forms size / pos using the widget handle ?

TGtkWidget( PGtkWidget(Winhandle)^).allocation.width - returns garbage gtk_widget_size_request(Winhandle, @GtkAllocation) - returns 0's

Working on the theory that I have to use the GDKWindow instead, TGtkWidget( PGtkWidget(Winhandle)^).Window - returns a number (no idea if its correct)
but trying to use it with any GDK_Window_ procedures gives various errors (depending on proc called)

Even simply attempting to get the TopLevel windows seems beyond me -
gList := gdk_window_get_toplevels();
gdk_window_get_position( GDK_WINDOW(gList^.data), pXPos, pYPos);

fails with 'GLib-GObject-CRITICAL - use IA__g_type_init() prior to this function
though I can easily accept that my understanding of glists is built on shakey ground

I know that Laz/fpc can handle most of this 'internally' for its own forms/controls - I am wanting to extend programming control outside of my app itself
eg - finding xcalc by name, moving / sizing / keystrokes / etc (not just xcalc obviously)

Any suggestions appreciated, as its damned frustrating knowing whats possible using Gtk/Gdk/GScreen/etc - and its just out of reach :)

Thanks - SteveG

Reply by email

SteveG
to Mattias Gärtner

Thanks for your answer here Mattias -

GetActiveWindow does seem to be just what I need to be able to create my own code from - but I cant get it to work :(
I have extracted the function and placed in a new app - causes exception at gtk_is_window

Are Gtk windows the same as Gdk windows ? - 'get_toplevels' returns gdkwindows, but using as gtkwindow ?

uses gtk2, glib, gdk;
function GetActiveWindow :integer;
var
  TopList, List: PGList;
  Widget: PGTKWidget;
  Window: PGTKWindow;
begin
  Result := 0;
  TopList := glib.pglist(gdk_window_get_toplevels);
  List := TopList;
  while List  nil do begin
    if (List^.Data  nil) then begin
      gdk_window_get_user_data(PGDKWindow(List^.Data), Pgpointer(@Window));
// --------FAILS AT NEXT LINE //
      if gtk_is_window(Window) then begin
        Widget := Window^.focus_widget;
        if Widget=nil then Widget:=PGtkWidget(Window);
        if (Widget  nil) and gtk_widget_has_focus(Widget) then begin
          Result := 1;//PtrUInt(GetMainWidget(PGtkWidget(Window)));
          Break;
        end;
      end;
    end;
    list := g_list_next(list);
  end;
  if TopList  nil then g_list_free(TopList);
end;
Mattias G?rtner wrote 15 lines
Zitat von SteveG : > Need some pointers on the way Laz/fpc handle gtkwidgets if possible. > > I am attempting (as a test) to get and then set the size and position of > a Laz form using Gtk / Gdk - (not necessary I know, just leading to > further things) > See in gtk intf: procedure SetWindowSizeAndPosition

Reply by email

SteveG
to Mattias Gärtner

Still fails at same point unfortunately

Mattias G?rtner wrote 26 lines
Zitat von SteveG : > Thanks for your answer here Mattias - > > GetActiveWindow does seem to be just what I need to be able to create my > own code from - but I cant get it to work :( > I have extracted the function and placed in a new app - causes exception > at gtk_is_window > > Are Gtk windows the same as Gdk windows ? - 'get_toplevels' returns > gdkwindows, but using as gtkwindow ? > > uses gtk2, glib, gdk; > uses gtk2, glib2, gdk2 Mattias _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to SteveG
Still fails at same point unfortunately

Please give more details about failure and a more complete example.

Mattias

Show quoted text 33 lines
Mattias G?rtner wrote: > Zitat von SteveG : > > >> Thanks for your answer here Mattias - >> >> GetActiveWindow does seem to be just what I need to be able to >> create my own code from - but I cant get it to work :( >> I have extracted the function and placed in a new app - causes >> exception at gtk_is_window >> >> Are Gtk windows the same as Gdk windows ? - 'get_toplevels' returns >> gdkwindows, but using as gtkwindow ? >> >> uses gtk2, glib, gdk; >> > > uses gtk2, glib2, gdk2 > > Mattias > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > > _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

SteveG
to Mattias Gaertner

Mattias - following is the code (from a new project in Laz) I am using to test this

It is just a direct copy from the gtk code supplied with Laz/fpc (with 3 lines added for testing) - and the result is being ignored My form has a button (button1) and memo (memo1) - nothing else The memo receives 'Test 1' and 'Test 2', never reaches 'Test 3' - fails with 'access violation'
With further testing of functions, I find that any call using a gdkwindow fails for me - so must be something simple somewhere

Using Laz ver 0.9.25 (svn 15686) on Ubuntu 804

unit Unit1;
{$mode objfpc}{$H+}
interface
uses Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, gtk2, glib2, gdk2;
type
  { TForm1 }
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;
var
  Form1: TForm1;
implementation
function GetActiveWindow :integer;
var
  TopList, List: PGList;
  Widget: PGTKWidget;
  Window: PGTKWindow;
begin
  Result := 0;
  TopList := pglist(gdk_window_get_toplevels);
  List := TopList;
  while List  nil do begin
    if (List^.Data  nil) then begin
Form1.memo1.lines.add('TEST 1');
      gdk_window_get_user_data(PGDKWindow(List^.Data), Pgpointer(@Window));
Form1.memo1.lines.add('TEST 2');
      if gtk_is_window(Window) then begin
Form1.memo1.lines.add('TEST 3');
        Widget := Window^.focus_widget;
        if Widget=nil then Widget:=PGtkWidget(Window);
        if (Widget  nil) and gtk_widget_has_focus(Widget) then begin
          Result := 1;//PtrUInt(GetMainWidget(PGtkWidget(Window)));
          Break;
        end;
      end;
    end;
    list := g_list_next(list);
  end;
  if TopList  nil then g_list_free(TopList);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  GetActiveWindow();
end;
initialization
  {$I Unit1.lrs}
end.
Mattias Gaertner wrote 13 lines
On Sun, 14 Sep 2008 00:33:33 +1000 SteveG wrote: > Still fails at same point unfortunately > Please give more details about failure and a more complete example. Mattias

Reply by email