diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-04-24 14:53:07 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-04-24 14:53:07 +0000 |
commit | 26cf9713599d0d798b4d254140dc778b04f9f0be (patch) | |
tree | c869a5c97e355e7ca94f487367b94b7ff9c63e98 /src | |
parent | 05e0c788f2e59cfe03651c1a356442f304c81317 (diff) | |
download | fpGUI-26cf9713599d0d798b4d254140dc778b04f9f0be.tar.xz |
* TfpgApplicationBase now descends from TObject instead of TComponent.
* TfpgApplication now has a FormCount property.
* TfpgApplication now has a Forms array property.
* TfpgApplication.CreateForm now works correctly and NO memory leaks occur.
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/fpgfx.pas | 24 | ||||
-rw-r--r-- | src/corelib/gdi/gfx_gdi.pas | 5 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 32 | ||||
-rw-r--r-- | src/corelib/x11/gfx_x11.pas | 5 | ||||
-rw-r--r-- | src/gui/gui_form.pas | 6 |
5 files changed, 56 insertions, 16 deletions
diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas index 05402367..36463457 100644 --- a/src/corelib/fpgfx.pas +++ b/src/corelib/fpgfx.pas @@ -197,6 +197,7 @@ type FOnException: TExceptionEvent; FStopOnException: Boolean; procedure SetupLocalizationStrings; + procedure InternalMsgClose(var msg: TfpgMessageRec); message FPGM_CLOSE; protected FDisplayParams: string; FScreenWidth: integer; @@ -760,12 +761,11 @@ begin FDisplayParams := AParams; FScreenWidth := -1; FScreenHeight := -1; - FModalFormStack := TList.Create; FMessageHookList := TFPList.Create; FStopOnException := False; try - inherited Create(aparams); + inherited Create(AParams); if IsInitialized then begin @@ -783,9 +783,15 @@ end; destructor TfpgApplication.Destroy; var i: integer; - frm: TfpgWindow; + frm: TfpgWindowBase; begin - DestroyComponents; // 2008-04-23: Is this right?? + for i := FFormList.Count - 1 downto 0 do + begin + frm := TfpgWindowBase(FFormList.Items[i]); + FFormList.Remove(frm); + frm.Free; + end; + FFormList.Free; for i := 0 to (fpgNamedFonts.Count - 1) do TNamedFontItem(fpgNamedFonts.Items[i]).Free; @@ -931,6 +937,16 @@ begin end; +procedure TfpgApplication.InternalMsgClose(var msg: TfpgMessageRec); +begin + writeln('InternalMsgClose received'); + if Assigned(msg.Sender) then + begin + FFormList.Remove(msg.Sender); + TfpgWindowBase(msg.Sender).Free; + end; +end; + procedure TfpgApplication.FreeFontRes(afontres: TfpgFontResource); var n: integer; diff --git a/src/corelib/gdi/gfx_gdi.pas b/src/corelib/gdi/gfx_gdi.pas index 26dd3eae..09f5c7fa 100644 --- a/src/corelib/gdi/gfx_gdi.pas +++ b/src/corelib/gdi/gfx_gdi.pas @@ -188,7 +188,7 @@ type FFocusedWindow: THANDLE; function DoGetFontFaceList: TStringList; override; public - constructor Create(const aparams: string); override; + constructor Create(const AParams: string); override; function DoMessagesPending: boolean; procedure DoWaitWindowMessage(atimeoutms: integer); procedure DoFlush; @@ -903,8 +903,9 @@ begin Result.Sort; end; -constructor TfpgApplicationImpl.Create(const aparams: string); +constructor TfpgApplicationImpl.Create(const AParams: string); begin + inherited Create(AParam); FIsInitialized := False; FDisplay := Windows.GetDC(0); Terminated := False; diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index b4125d4f..6fdc14a0 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -412,18 +412,21 @@ type end; - TfpgApplicationBase = class(TComponent) + TfpgApplicationBase = class(TObject) private FMainForm: TfpgWindowBase; FTerminated: boolean; + function GetForm(Index: Integer): TfpgWindowBase; + function GetFormCount: integer; function GetTopModalForm: TfpgWindowBase; protected + FFormList: TList; FOnIdle: TNotifyEvent; FIsInitialized: Boolean; FModalFormStack: TList; function DoGetFontFaceList: TStringList; virtual; abstract; public - constructor Create(const AParams: string); virtual; abstract; reintroduce; + constructor Create(const AParams: string); virtual; reintroduce; function GetFontFaceList: TStringList; procedure PushModalForm(AForm: TfpgWindowBase); procedure PopModalForm; @@ -435,13 +438,12 @@ type function Screen_dpi_y: integer; virtual; abstract; function Screen_dpi: integer; virtual; abstract; procedure Terminate; + property FormCount: integer read GetFormCount; + property Forms[Index: Integer]: TfpgWindowBase read GetForm; property IsInitialized: boolean read FIsInitialized; property TopModalForm: TfpgWindowBase read GetTopModalForm; property MainForm: TfpgWindowBase read FMainForm write FMainForm; property Terminated: boolean read FTerminated write FTerminated; - { TODO : Implement these two properties in the near future. } -// property FormCount... -// property Forms[]... property OnIdle: TNotifyEvent read FOnIdle write FOnIdle; end; @@ -1856,6 +1858,23 @@ begin Result := TFpgWindowBase(FModalFormStack.Items[FModalFormStack.Count-1]); end; +constructor TfpgApplicationBase.Create(const AParams: string); +begin + inherited Create; + FModalFormStack := TList.Create; + FFormList := TList.Create; +end; + +function TfpgApplicationBase.GetFormCount: integer; +begin + Result := FFormList.Count; +end; + +function TfpgApplicationBase.GetForm(Index: Integer): TfpgWindowBase; +begin + Result := TfpgWindowBase(FFormList.Items[Index]); +end; + function TfpgApplicationBase.GetFontFaceList: TStringList; begin Result := DoGetFontFaceList; @@ -1896,7 +1915,8 @@ procedure TfpgApplicationBase.CreateForm(AFormClass: TComponentClass; var AForm: TfpgWindowBase); begin try - AForm := TfpgWindowBase(AFormClass.Create(self)); + AForm := TfpgWindowBase(AFormClass.Create(nil)); + FFormList.Add(AForm); if FMainForm = nil then FMainForm := AForm; except diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index f32b645d..938a12cb 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -234,7 +234,7 @@ type FLastKeySym: TKeySym; // Used for KeyRelease event function DoGetFontFaceList: TStringList; override; public - constructor Create(const aparams: string); override; + constructor Create(const AParams: string); override; destructor Destroy; override; function DoMessagesPending: boolean; procedure DoWaitWindowMessage(atimeoutms: integer); @@ -684,8 +684,9 @@ begin Result.Sort; end; -constructor TfpgApplicationImpl.Create(const aparams: string); +constructor TfpgApplicationImpl.Create(const AParams: string); begin + inherited Create(AParams); FIsInitialized := False; FDisplay := XOpenDisplay(PChar(aparams)); diff --git a/src/gui/gui_form.pas b/src/gui/gui_form.pas index 1490a75d..8e0c51ec 100644 --- a/src/gui/gui_form.pas +++ b/src/gui/gui_form.pas @@ -372,9 +372,11 @@ begin caFree: begin HandleHide; - fpgApplication.RemoveComponent(self); if IsMainForm then - fpgApplication.Terminate; + fpgApplication.Terminate + else + // We can't free ourselves, somebody else needs to do it + fpgPostMessage(Self, fpgApplication, FPGM_CLOSE); end; end; { case CloseAction } end; { if CloseQuery } |