Fixes form events in gtk2 and further separates the widgetsets.

git-svn-id: trunk@14862 -
This commit is contained in:
sekelsenmat 2008-04-17 09:50:17 +00:00
parent 1490cecace
commit 58d9858249
2 changed files with 125 additions and 24 deletions

View File

@ -156,7 +156,7 @@ uses
Gtk2WSExtCtrls, Gtk2WSExtCtrls,
// Gtk2WSExtDlgs, // Gtk2WSExtDlgs,
// Gtk2WSFileCtrl, // Gtk2WSFileCtrl,
// Gtk2WSForms, Gtk2WSForms,
// Gtk2WSGrids, // Gtk2WSGrids,
// Gtk2WSImgList, // Gtk2WSImgList,
// Gtk2WSMaskEdit, // Gtk2WSMaskEdit,

View File

@ -27,21 +27,22 @@ unit Gtk2WSForms;
interface interface
uses uses
//////////////////////////////////////////////////// // Bindings
// I M P O R T A N T Gtk2, Glib2, gdk2,
//////////////////////////////////////////////////// // RTL, FCL, LCL
// To get as little as posible circles, SysUtils, Classes, LCLProc, LCLType, Controls, LMessages, InterfaceBase,
// uncomment only when needed for registration Graphics, Dialogs,Forms, Math,
//////////////////////////////////////////////////// // Widgetset
// Forms, WSDialogs, WSLCLClasses, WSControls, WSForms, WSProc,
//////////////////////////////////////////////////// Gtk2Int, GtkProc, gtk2proc, GtkDef, GtkExtra, GtkGlobals, Gtk2WSControls,
WSForms, WSLCLClasses, Forms, GTKProc; // Gtk 1 stuff
gtkwsforms;
type type
{ TGtk2WSScrollingWinControl } { TGtk2WSScrollingWinControl }
TGtk2WSScrollingWinControl = class(TWSScrollingWinControl) TGtk2WSScrollingWinControl = class(TGtkWSScrollingWinControl)
private private
protected protected
public public
@ -49,7 +50,7 @@ type
{ TGtk2WSScrollBox } { TGtk2WSScrollBox }
TGtk2WSScrollBox = class(TWSScrollBox) TGtk2WSScrollBox = class(TGtkWSScrollBox)
private private
protected protected
public public
@ -57,7 +58,7 @@ type
{ TGtk2WSCustomFrame } { TGtk2WSCustomFrame }
TGtk2WSCustomFrame = class(TWSCustomFrame) TGtk2WSCustomFrame = class(TGtkWSCustomFrame)
private private
protected protected
public public
@ -65,7 +66,7 @@ type
{ TGtk2WSFrame } { TGtk2WSFrame }
TGtk2WSFrame = class(TWSFrame) TGtk2WSFrame = class(TGtkWSFrame)
private private
protected protected
public public
@ -73,21 +74,23 @@ type
{ TGtk2WSCustomForm } { TGtk2WSCustomForm }
TGtk2WSCustomForm = class(TWSCustomForm) TGtk2WSCustomForm = class(TGtkWSCustomForm)
private private
protected protected
class procedure SetCallbacks(const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); override; class procedure SetCallbacks(const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); override;
public public
class function GetDefaultClientRect(const AWinControl: TWinControl; class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
{ class function GetDefaultClientRect(const AWinControl: TWinControl;
const aLeft, aTop, aWidth, aHeight: integer; var aClientRect: TRect const aLeft, aTop, aWidth, aHeight: integer; var aClientRect: TRect
): boolean; override; ): boolean; override;
class procedure SetBorderIcons(const AForm: TCustomForm; class procedure SetBorderIcons(const AForm: TCustomForm;
const ABorderIcons: TBorderIcons); override; const ABorderIcons: TBorderIcons); override;}
end; end;
{ TGtk2WSForm } { TGtk2WSForm }
TGtk2WSForm = class(TWSForm) TGtk2WSForm = class(TGtkWSForm)
private private
protected protected
public public
@ -95,7 +98,7 @@ type
{ TGtk2WSHintWindow } { TGtk2WSHintWindow }
TGtk2WSHintWindow = class(TWSHintWindow) TGtk2WSHintWindow = class(TGtkWSHintWindow)
private private
protected protected
public public
@ -103,7 +106,7 @@ type
{ TGtk2WSScreen } { TGtk2WSScreen }
TGtk2WSScreen = class(TWSScreen) TGtk2WSScreen = class(TGtkWSScreen)
private private
protected protected
public public
@ -111,7 +114,7 @@ type
{ TGtk2WSApplicationProperties } { TGtk2WSApplicationProperties }
TGtk2WSApplicationProperties = class(TWSApplicationProperties) TGtk2WSApplicationProperties = class(TGtkWSApplicationProperties)
private private
protected protected
public public
@ -127,7 +130,7 @@ class procedure TGtk2WSCustomForm.SetCallbacks(const AWidget: PGtkWidget;
begin begin
TGtk2WSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject)); TGtk2WSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject));
if (TControl(AWidgetInfo^.LCLObject).Parent = nil) then if (TControl(AWidgetInfo^.LCLObject).Parent = nil) then
with TGTKWidgetSet(Widgetset) do with TGTK2WidgetSet(Widgetset) do
begin begin
SetCallback(LM_CONFIGUREEVENT, PGtkObject(AWidget), AWidgetInfo^.LCLObject); SetCallback(LM_CONFIGUREEVENT, PGtkObject(AWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_CLOSEQUERY, PGtkObject(AWidget), AWidgetInfo^.LCLObject); SetCallback(LM_CLOSEQUERY, PGtkObject(AWidget), AWidgetInfo^.LCLObject);
@ -140,7 +143,105 @@ begin
gtk_signal_func(@GTKWindowStateEventCB), AWidgetInfo^.LCLObject); gtk_signal_func(@GTKWindowStateEventCB), AWidgetInfo^.LCLObject);
end; end;
class function TGtk2WSCustomForm.GetDefaultClientRect( class function TGtk2WSCustomForm.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
WidgetInfo: PWidgetInfo;
p: pointer; // ptr to the newly created GtkWidget
Box: Pointer;
ABorderStyle: TFormBorderStyle;
WindowType: TGtkWindowType;
ACustomForm: TCustomForm;
AResizable: gint;
begin
// Start of old CreateForm method
ACustomForm := TCustomForm(AWinControl);
if ACustomForm.Parent = nil then
begin
if csDesigning in ACustomForm.ComponentState then
ABorderStyle:=bsSizeable
else
ABorderStyle:=ACustomForm.BorderStyle;
end
else
ABorderStyle:=bsNone;
// Maps the border style
WindowType := FormStyleMap[ABorderStyle];
if (ABorderStyle=bsNone) and (ACustomForm.FormStyle in fsAllStayOnTop) then
WindowType := GTK_WINDOW_POPUP;
if (csDesigning in ACustomForm.ComponentState) then
WindowType := GTK_WINDOW_TOPLEVEL;
if ACustomForm.Parent = nil then
begin
// create a floating form
P := gtk_window_new(WindowType);
// Sets the window as resizable or not
// Depends on the WM supporting this
if (csDesigning in ACustomForm.ComponentState) then AResizable := 1
else AResizable := FormResizableMap[ABorderStyle];
// gtk_window_set_policy is deprecated in Gtk2
{$IFDEF Gtk2}
gtk_window_set_resizable(GTK_WINDOW(P), gboolean(AResizable));
{$ELSE}
gtk_window_set_policy(GTK_WINDOW(P), AResizable, AResizable, 0);
{$ENDIF}
// Sets the title
gtk_window_set_title(PGtkWindow(P), AParams.Caption);
// the clipboard needs a widget
if (ClipboardWidget = nil) then
Gtk2WidgetSet.SetClipboardWidget(P);
end
else
begin
// create a form as child control
P := gtk_hbox_new(false, 0);
end;
WidgetInfo := CreateWidgetInfo(P, AWinControl, AParams);
Box := CreateFormContents(ACustomForm, P);
gtk_container_add(PGtkContainer(P), Box);
{$IfDef GTK2}
//so we can double buffer ourselves, eg, the Form Designer
gtk_widget_set_double_buffered(Box, False);
{$EndIf}
gtk_widget_show(Box);
// main menu
if (ACustomForm.Menu <> nil) and (ACustomForm.Menu.HandleAllocated) then
begin
gtk_box_pack_start(Box, PGtkWidget(ACustomForm.Menu.Handle), False, False,0);
end;
// End of the old CreateForm method
{$IFNDEF NoStyle}
if (ACustomForm.Parent = nil) then
gtk_widget_set_app_paintable(P, True);
{$ENDIF}
if not (csDesigning in AWinControl.ComponentState) then
WidgetInfo^.UserData := Pointer(1);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(PtrUInt(P));
Set_RC_Name(AWinControl, P);
SetCallbacks(P, WidgetInfo);
end;
{class function TGtk2WSCustomForm.GetDefaultClientRect(
const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer; const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
var aClientRect: TRect): boolean; var aClientRect: TRect): boolean;
begin begin
@ -160,7 +261,7 @@ class procedure TGtk2WSCustomForm.SetBorderIcons(const AForm: TCustomForm;
const ABorderIcons: TBorderIcons); const ABorderIcons: TBorderIcons);
begin begin
gtk_window_get_modal(); gtk_window_get_modal();
end; end;}
initialization initialization