summaryrefslogtreecommitdiff
path: root/libgtk_kylix/GTKForms.pas
diff options
context:
space:
mode:
Diffstat (limited to 'libgtk_kylix/GTKForms.pas')
-rw-r--r--libgtk_kylix/GTKForms.pas109
1 files changed, 55 insertions, 54 deletions
diff --git a/libgtk_kylix/GTKForms.pas b/libgtk_kylix/GTKForms.pas
index b1467db..0dc1691 100644
--- a/libgtk_kylix/GTKForms.pas
+++ b/libgtk_kylix/GTKForms.pas
@@ -70,6 +70,9 @@ type // Some basic types
FOnShow: TNotifyEvent;
FCaption: string;
FOnDestroy: TNotifyEvent;
+ FDeleteEventSignalHandlerID: gulong;
+ FSizeAllocateSignalHandlerID: gulong;
+ FShowSignalHandlerID: gulong;
function GetWindowPosition: TWindowPosition;
function GetResizeable: boolean;
function GetWindowTypeHint: TGDKWindowTypeHint;
@@ -88,6 +91,7 @@ type // Some basic types
procedure SetWidth(Value: integer);
procedure SetHeight(Value: integer);
procedure SetDefault(Value: TGTKControl);
+ procedure ConnectDefaultSignals;
protected
procedure DoClose(var Action: TCloseAction); dynamic;
property Visible write SetVisible default False;
@@ -182,7 +186,7 @@ type // Some basic types
destructor Destroy; override;
procedure ControlDestroyed(Control: TGTKControl);
procedure CreateForm(InstanceClass: TComponentClass; var Reference);
- procedure HandleException(Sender: TObject);
+// procedure HandleException(Sender: TObject);
procedure HandleMessage;
procedure HookSynchronizeWakeup;
procedure Initialize;
@@ -192,7 +196,7 @@ type // Some basic types
Default: TMessageButton = mbNone; Escape: TMessageButton = mbNone): TMessageButton; overload;
procedure ProcessMessages;
procedure Run;
- procedure ShowException(E: Exception);
+// procedure ShowException(E: Exception);
procedure Terminate;
procedure UnhookSynchronizeWakeup;
property MainForm: TCustomGTKForm read FMainForm;
@@ -207,8 +211,6 @@ type // Some basic types
var Application: TGTKApplication;
Screen: TGDKScreen;
- Argc: Integer;
- Argv: PPChar;
function GetParentForm(Control: TGTKControl): TCustomGTKForm;
@@ -286,6 +288,9 @@ begin
FOnClose := nil;
FOnCloseQuery := nil;
FOnDestroy := nil;
+ FDeleteEventSignalHandlerID := 0;
+ FSizeAllocateSignalHandlerID := 0;
+ FShowSignalHandlerID := 0;
FCaption := '';
FAccelGroup := gtk_accel_group_new;
Screen.AddForm(Self);
@@ -293,15 +298,22 @@ end;
destructor TCustomGTKForm.Destroy;
begin
- try
- Screen.RemoveForm(Self);
- if Assigned(FOnDestroy) then FOnDestroy(Self);
- except
- end;
+ Screen.RemoveForm(Self);
+ if Assigned(FOnDestroy) then FOnDestroy(Self);
+// if FDeleteEventSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FDeleteEventSignalHandlerID);
+// if FSizeAllocateSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FSizeAllocateSignalHandlerID);
+// if FShowSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FShowSignalHandlerID);
if not Application.Terminated then gtk_widget_destroy(FWidget);
inherited Destroy;
end;
+procedure TCustomGTKForm.ConnectDefaultSignals;
+begin
+ FDeleteEventSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'delete-event', TGCallback(@TCustomGTKForm_delete_event), Self, nil, G_CONNECT_DEFAULT);
+ FSizeAllocateSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'size-allocate', TGCallback(@TCustomGTKForm_size_allocate), Self, nil, G_CONNECT_DEFAULT);
+ FShowSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'show', TGCallback(@TCustomGTKForm_show), Self, nil, G_CONNECT_DEFAULT);
+end;
+
procedure TCustomGTKForm.SetVisible(Value: Boolean);
begin
inherited Visible := Value;
@@ -339,7 +351,7 @@ end;
procedure TCustomGTKForm.Release;
begin
-// SetParent(nil);
+ SetParent(nil);
// if Assigned(FWidget) and GTK_IS_WIDGET(FWidget) then gtk_widget_destroy(PGtkWidget(FWidget));
end;
@@ -407,6 +419,7 @@ end;
function TCustomGTKForm.GetWindowState: TGDKWindowState;
begin
+ if gtk_window_is_maximized(PGtkWindow(FWidget)) then Result := wsMaximized else
Result := TGDKWindowState(gdk_window_get_state(PGdkWindow(FWidget^.window)));
end;
@@ -514,48 +527,31 @@ begin
inherited Create(AOwner);
FMainForm := nil;
FMainFormSet := False;
- if not Assigned(Classes.ApplicationHandleException) then
+{ if not Assigned(Classes.ApplicationHandleException) then
Classes.ApplicationHandleException := @HandleException;
if not Assigned(Classes.ApplicationShowException) then
- Classes.ApplicationShowException := @ShowException;
+ Classes.ApplicationShowException := @ShowException;}
CreateHandle;
HookSynchronizeWakeup;
FThreadID := 0;
end;
-procedure my_g_thread_init(vtable:Pointer);cdecl;external 'libgthread-2.0.so' name 'g_thread_init';
-
procedure TGTKApplication.CreateHandle;
-var
- I: Integer;
- Temp: string;
+var argc: gint;
+ argv: PPgchar;
+ i: Integer;
begin
- Argc := ParamCount + 1;
- Argv := AllocMem((Argc + 1) * SizeOf(PChar));
- for I := 0 to Argc - 1 do
- begin
- Temp := ParamStr(I);
- {$R-}
- PCharArray(Argv^)[I] := AllocMem(Length(Temp)+1);
- StrCopy(PCharArray(Argv^)[I], PChar(Temp));
- {$R+}
- end;
- {$R-}
- PCharArray(Argv^)[Argc] := nil;
- {$R+}
-
- // Init threads
- my_g_thread_init(nil);
-
- (* ATTENTION: do not call gdk_threads_init(), it causes deadlocks and we don't really need it *)
-// gdk_threads_init;
+ argc := ParamCount;
+ argv := g_malloc0(argc * sizeof(Pointer));
+ for i := 0 to argc - 1 do
+ argv[i] := g_strdup(PChar(ParamStr(i)));
// Initialize the widget set
gtk_init(@argc, @argv);
-{ if not gtk_init_check(@argc, @argv) then begin
- WriteLn('Unable to initialize GTK+ interface. Make sure you have correctly installed all of GTK libraries and have set a valid X server in the DISPLAY variable.');
- Halt(1);
- end; }
+
+ for i := 0 to argc - 1 do
+ g_free(argv[i]);
+ g_free(argv);
end;
destructor TGTKApplication.Destroy;
@@ -565,31 +561,34 @@ var
P: TNotifyEvent;
E: TExceptionEvent;
begin
- UnhookSynchronizeWakeup;
+{ UnhookSynchronizeWakeup;
P := @HandleException;
if @P = @Classes.ApplicationHandleException then
Classes.ApplicationHandleException := nil;
E := @ShowException;
if @E = @Classes.ApplicationShowException then
Classes.ApplicationShowException := nil;
+}
inherited Destroy;
end;
procedure TGTKApplication.HookSynchronizeWakeup;
begin
- if not Assigned(Classes.WakeMainThread) then
- Classes.WakeMainThread := WakeMainThread;
+{ if not Assigned(Classes.WakeMainThread) then
+ Classes.WakeMainThread := WakeMainThread; }
end;
procedure TGTKApplication.UnhookSynchronizeWakeup;
var
P: TNotifyEvent;
begin
- P := WakeMainThread;
+{ P := WakeMainThread;
if @P = @Classes.WakeMainThread then
Classes.WakeMainThread := nil;
+}
end;
+{
procedure TGTKApplication.HandleException(Sender: TObject);
begin
if ExceptObject is Exception then
@@ -602,6 +601,7 @@ begin
end else
SysUtils.ShowException(ExceptObject, ExceptAddr);
end;
+}
procedure TGTKApplication.CreateForm(InstanceClass: TComponentClass; var Reference);
var
@@ -662,11 +662,13 @@ function __pthread_self: __pthread_t; cdecl; external 'libpthread.so.0' name 'pt
procedure TGTKApplication.Run;
begin
- repeat
+ gtk_main();
+
+{ repeat
try
// gdk_threads_enter;
- FThreadID := __pthread_self;
- gtk_main;
+ FThreadID := __pthread_self();
+ gtk_main();
// gdk_threads_leave;
except
on E : Exception do
@@ -677,6 +679,7 @@ begin
end else HandleException(E);
end;
until Terminated;
+ }
end;
function TGTKApplication_MessageBox_key_press_event(widget: PGtkWidget; event: PGdkEventKey; user_data : gpointer): gboolean; cdecl;
@@ -709,7 +712,7 @@ begin
Result := Escape;
Exit;
end;
- Dialog := gtk_message_dialog_new(ParentWindow, [GTK_DIALOG_MODAL, GTK_DIALOG_DESTROY_WITH_PARENT], TMessageStyleID[Integer(Style)],
+ Dialog := gtk_message_dialog_new_with_markup(ParentWindow, [GTK_DIALOG_MODAL, GTK_DIALOG_DESTROY_WITH_PARENT], TMessageStyleID[Integer(Style)],
GTK_BUTTONS_NONE, '%s', [PChar(Text)]);
for i := 1 to NumMessageButtons do
if TMessageButton(i - 1) in Buttons
@@ -721,6 +724,7 @@ begin
gtk_widget_destroy(Dialog);
end;
+{
procedure TGTKApplication.ShowException(E: Exception);
var Msg: string;
begin
@@ -728,6 +732,7 @@ begin
if (Msg <> '') and (AnsiLastChar(Msg) = '.') then Delete(Msg, Length(Msg), 1);
MessageBox(Format('An unhandled exception has occured: '#10' %s'#10#10'It is strongly recommended to save your data and quit the application.', [Msg]), [mbOk], mbError);
end;
+}
procedure TGTKApplication.Terminate;
begin
@@ -751,13 +756,11 @@ begin
inherited Create(AOwner);
FWidget := gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_add_accel_group(PGtkWindow(FWidget), FAccelGroup);
- g_signal_connect_data(PGObject(FWidget), 'delete-event', TGCallback(@TCustomGTKForm_delete_event), Self, nil, G_CONNECT_DEFAULT);
- g_signal_connect_data(PGObject(FWidget), 'size-allocate', TGCallback(@TCustomGTKForm_size_allocate), Self, nil, G_CONNECT_DEFAULT);
- g_signal_connect_data(PGObject(FWidget), 'show', TGCallback(@TCustomGTKForm_show), Self, nil, G_CONNECT_DEFAULT);
Visible := False;
SetResizeable(True);
FormCreate(Self);
if Visible then Show;
+ ConnectDefaultSignals;
end;
procedure TGTKForm.Hide;
@@ -784,9 +787,6 @@ begin
if Assigned(AOwner) and (AOwner is TCustomGTKForm) then SetTransientFor(AOwner as TCustomGTKForm);
FOnResponse := nil;
gtk_window_add_accel_group(PGtkWindow(FWidget), FAccelGroup);
- g_signal_connect_data(PGObject(FWidget), 'delete-event', TGCallback(@TCustomGTKForm_delete_event), Self, nil, G_CONNECT_DEFAULT);
- g_signal_connect_data(PGObject(FWidget), 'show', TGCallback(@TCustomGTKForm_show), Self, nil, G_CONNECT_DEFAULT);
- g_signal_connect_data(PGObject(FWidget), 'response', TGCallback(@TGTKDialog_response_event), Self, nil, G_CONNECT_DEFAULT);
ClientArea := TGTKVBox.CreateLinked(Self, gtk_dialog_get_content_area(PGtkDialog(FWidget)));
ActionArea := TGTKHBox.CreateLinked(Self, gtk_dialog_get_action_area(PGtkDialog(FWidget)));
FButtons := [];
@@ -794,6 +794,7 @@ begin
SetResizeable(True);
FormCreate(Self);
if Visible then Show;
+ ConnectDefaultSignals;
end;
function TGTKDialog.Run: TMessageButton;