summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-01-21 11:18:44 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-01-21 11:18:44 +0000
commit8d23789d877af358edb1aeca75e42e6953f0179f (patch)
tree9a4c6e10c001b782d38b63446f02e4073f2f9e33 /src/gui
parentaa2a6e1dac26b8813891b23f14dccbc476329fec (diff)
downloadfpGUI-8d23789d877af358edb1aeca75e42e6953f0179f.tar.xz
* Fixed some memory leaks in TfpgComboBox.
* Fixed the destruction order of TfpgComboBox. * Introduced DoRemoveWindowLookup() in gfxbase.pas so that we can offload some of the responsibility from DoReleaseWindowHandle() * Add two new debug methods to help debug fpGUI and fpGUI based applications. They are PrintCallTrace() and PrintCallTraceDbgln(). * Fixed 'Index out of bounds' error when quiting your application. * I included lots of debug output in this revision, so I can test under Windows. As soon as I confirmed everything works, I'll remove the debug output again.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/fpgui_package.lpk13
-rw-r--r--src/gui/gui_combobox.pas73
-rw-r--r--src/gui/gui_form.pas9
-rw-r--r--src/gui/gui_gauge.pas12
-rw-r--r--src/gui/gui_listbox.pas12
-rw-r--r--src/gui/gui_listview.pas3
6 files changed, 81 insertions, 41 deletions
diff --git a/src/gui/fpgui_package.lpk b/src/gui/fpgui_package.lpk
index a9716935..54ded6b2 100644
--- a/src/gui/fpgui_package.lpk
+++ b/src/gui/fpgui_package.lpk
@@ -17,6 +17,11 @@
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
+ <Linking>
+ <Debugging>
+ <GenerateDebugInfo Value="True"/>
+ </Debugging>
+ </Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
@@ -143,12 +148,12 @@
<LazDoc Paths="../../docs/xml/gui/"/>
<RequiredPkgs Count="2">
<Item1>
- <PackageName Value="FCL"/>
- <MinVersion Major="1" Valid="True"/>
- </Item1>
- <Item2>
<PackageName Value="fpgfx_package"/>
<MinVersion Minor="5" Valid="True"/>
+ </Item1>
+ <Item2>
+ <PackageName Value="FCL"/>
+ <MinVersion Major="1" Valid="True"/>
</Item2>
</RequiredPkgs>
<UsageOptions>
diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas
index 0c9b4282..cfe2c966 100644
--- a/src/gui/gui_combobox.pas
+++ b/src/gui/gui_combobox.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Library
- Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -19,6 +19,8 @@ unit gui_combobox;
{$mode objfpc}{$H+}
+{.$Define DEBUG}
+
{ TODO: When combobox Items changes, the combobox needs to refresh. We need a
custom StringItems class to notify us of changes. See TfpgListBox for
an example. }
@@ -56,6 +58,7 @@ type
procedure SetFocusItem(const AValue: integer);
procedure SetFontDesc(const AValue: string);
procedure CalculateInternalButtonRect;
+ procedure MsgPopupClose(var msg: TfpgMessageRec); message FPGM_POPUPCLOSE;
protected
FMargin: integer;
FBtnPressed: Boolean;
@@ -114,7 +117,6 @@ var
OriginalFocusRoot: TfpgWidget;
type
-
{ This is the class representing the dropdown window of the combo box. }
TDropDownWindow = class(TfpgPopupWindow)
private
@@ -131,12 +133,13 @@ type
property CallerWidget: TfpgWidget read FCallerWidget write FCallerWidget;
end;
+
{ TDropDownWindow }
procedure TDropDownWindow.HandlePaint;
begin
Canvas.BeginDraw;
- inherited HandlePaint;
+// inherited HandlePaint;
Canvas.Clear(clWhite);
Canvas.EndDraw;
end;
@@ -186,8 +189,10 @@ begin
end;
destructor TDropDownWindow.Destroy;
+var
+ tmp: IInterface;
begin
- ListBox.Free;
+ tmp := PrintCallTrace(ClassName, 'Destroy');
inherited Destroy;
end;
@@ -228,6 +233,7 @@ end;
function TfpgAbstractComboBox.GetText: string;
begin
+ PrintCallTraceDbgLn('FocusItem = ' + IntToStr(FocusItem));
if (FocusItem > 0) and (FocusItem <= FItems.Count) then
Result := FItems.Strings[FocusItem-1]
else
@@ -241,15 +247,19 @@ end;
procedure TfpgAbstractComboBox.DoDropDown;
var
+ tmp: IInterface;
ddw: TDropDownWindow;
rowcount: integer;
begin
+ tmp := PrintCallTrace(Classname, 'DoDropDown');
if (not Assigned(FDropDown)) or (not FDropDown.HasHandle) then
begin
+ PrintCallTraceDbgLn('DoDropDown - Part 1');
+ FreeAndNil(FDropDown);
OriginalFocusRoot := FocusRootWidget;
- FDropDown := TDropDownWindow.Create(nil);
- ddw := TDropDownWindow(FDropDown);
- ddw.Width := Width;
+ FDropDown := TDropDownWindow.Create(nil);
+ ddw := TDropDownWindow(FDropDown);
+ ddw.Width := Width;
// adjust the height of the dropdown
rowcount := FItems.Count;
if rowcount > FDropDownCount then
@@ -264,15 +274,16 @@ begin
ddw.ListBox.Items.Assign(FItems);
ddw.ListBox.FocusItem := FFocusItem;
- FDropDown.ShowAt(Parent, Left, Top+Height);
- FDropDown.DontCloseWidget := self; // now we can control when the popup window closes
-// FDropDown.ActiveWidget := ddw.ListBox;
+// ddw.DontCloseWidget := self; // now we can control when the popup window closes
+ ddw.ShowAt(Parent, Left, Top+Height);
ddw.ListBox.SetFocus;
end
else
begin
+ PrintCallTraceDbgLn('DoDropDown - Part 2');
FBtnPressed := False;
- FDropDown.Close;
+ ddw := TDropDownWindow(FDropDown);
+ ddw.Close;
FreeAndNil(FDropDown);
end;
end;
@@ -285,13 +296,16 @@ end;
procedure TfpgAbstractComboBox.InternalListBoxSelect(Sender: TObject);
var
msgp: TfpgMessageParams;
+ tmp: IInterface;
begin
+ tmp := PrintCallTrace(ClassName, 'InternalListBoxSelect');
FFocusItem := TDropDownWindow(FDropDown).ListBox.FocusItem;
{ Don't use .Close because this method is called by FDropDown.ListBox and
- causes issues if it's freed to quickly. }
-// FDropDown.Close;
- fpgSendMessage(self, FDropDown, FPGM_CLOSE, msgp);
+ causes issues if it's freed to quickly. We can't destroy the ListBox while
+ it's still executing it's event handler - instead we send a message to self. }
+ FDropDown.Close;
+// fpgSendMessage(self, self, FPGM_POPUPCLOSE, msgp); // request to close the dropdown.
if HasHandle then
Repaint;
@@ -357,6 +371,14 @@ begin
FInternalBtnRect.SetRect(Width - Min(Height, 20), 2, Min(Height, 20)-2, Height-4);
end;
+procedure TfpgAbstractComboBox.MsgPopupClose(var msg: TfpgMessageRec);
+var
+ tmp: IInterface;
+begin
+ tmp := PrintCallTrace(Classname, 'MsgPopupClose');
+ DoDropDown;
+end;
+
procedure TfpgAbstractComboBox.SetHeight(const AValue: TfpgCoord);
begin
inherited;
@@ -365,10 +387,10 @@ begin
end;
procedure TfpgAbstractComboBox.HandleLMouseDown(x, y: integer; shiftstate: TShiftState);
+var
+ tmp: IInterface;
begin
- {$IFDEF DEBUG}
- writeln('TfpgAbstractComboBox.HandleLMouseDown [', Classname, ']');
- {$ENDIF}
+ tmp := PrintCallTrace(Classname, 'HandleLMouseDown');
inherited HandleLMouseDown(x, y, shiftstate);
// button state is down only if user clicked in the button rectangle.
if PtInRect(FInternalBtnRect, Point(x, y)) then
@@ -377,10 +399,10 @@ begin
end;
procedure TfpgAbstractComboBox.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
+var
+ tmp: IInterface;
begin
- {$IFDEF DEBUG}
- writeln('TfpgAbstractComboBox.HandleLMouseUp [', Classname, ']');
- {$ENDIF}
+ tmp := PrintCallTrace(Classname, 'HandleLMouseUp');
inherited HandleLMouseUp(x, y, shiftstate);
FBtnPressed := False;
DoDropDown;
@@ -495,11 +517,12 @@ begin
end;
destructor TfpgAbstractComboBox.Destroy;
+var
+ tmp: IInterface;
begin
- { Todo: Double check FDropDown.Free call, because we are closing FDropDown
- via a fpgSendMessage call. This needs improving. }
- if Assigned(FDropDown) and (FDropDown.HasHandle) then
- FDropDown.Free;
+ tmp := PrintCallTrace(ClassName, 'Destroy');
+ FDropDown.Free;
+ PrintCallTraceDbgLn('**** Freeing off the ComboBox items');
FItems.Free;
FFont.Free;
inherited Destroy;
@@ -507,7 +530,7 @@ end;
procedure TfpgAbstractComboBox.Update;
begin
- FFocusItem := 1;
+ FFocusItem := 0;
Repaint;
end;
diff --git a/src/gui/gui_form.pas b/src/gui/gui_form.pas
index bf2ae6bc..0828c927 100644
--- a/src/gui/gui_form.pas
+++ b/src/gui/gui_form.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Library
- Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -244,10 +244,13 @@ begin
end;
procedure TfpgForm.MsgClose(var msg: TfpgMessageRec);
+var
+ tmp: IInterface;
begin
- HandleClose;
+ tmp := PrintCallTrace(Classname, 'MsgClose');
if Assigned(FOnClose) then
FOnClose(self);
+ HandleClose;
end;
procedure TfpgForm.HandleClose;
@@ -257,9 +260,9 @@ end;
procedure TfpgForm.HandleHide;
begin
- inherited HandleHide;
if Assigned(FOnHide) then
FOnHide(self);
+ inherited HandleHide;
end;
procedure TfpgForm.HandleShow;
diff --git a/src/gui/gui_gauge.pas b/src/gui/gui_gauge.pas
index 3d0317c8..52ac9df3 100644
--- a/src/gui/gui_gauge.pas
+++ b/src/gui/gui_gauge.pas
@@ -45,7 +45,7 @@ type
FPosition: Longint;
FKind: TGaugeKind;
FShowText: Boolean;
- {TODO _ Implement Border style }
+ { TODO: Implement Border style }
FBorderStyle: TBorderStyle;
FColor: TfpgColor; // Background color
{ Currently little used colors, should be derived from style and possibly
@@ -53,7 +53,7 @@ type
or give pair? }
FFirstColor: TfpgColor; // Text and Needle color
FSecondColor: TfpgColor; // Bar, Pie etc. main color
- { Currently unused - TODO - Implement Low Watermark and High Watermark }
+ { TODO: Currently unused. Implement Low Watermark and High Watermark }
FLWMColor: TfpgColor; // Low Watermark Color
FLWMValue: Longint; // Low Watermark Value
FHWMColor: TfpgColor; // High Watermark Color
@@ -448,7 +448,7 @@ begin
if AValue <> FBorderStyle then
begin
FBorderStyle := AValue;
- {TODO - Implement Border style }
+ { TODO: Implement Border style }
// Graeme: Wouldn't descending from TfpgBevel give you this functionality already?
// It could be a option.
//RePaint;
@@ -460,7 +460,7 @@ begin
if AValue <> FFirstColor then
begin
FFirstColor := AValue;
- {TODO - allow user colors}
+ { TODO: allow user colors}
//RePaint;
end;
end;
@@ -470,7 +470,7 @@ begin
if AValue <> FSecondColor then
begin
FSecondColor := AValue;
- {TODO - allow user colors}
+ { TODO: allow user colors}
//RePaint;
end;
end;
@@ -525,7 +525,7 @@ begin
FPosition := AValue;
if CurrPercentage <> Percentage then // Visible value has changed
MustRepaint := True;
- { TODO Check against low and high watermarks }
+ { TODO: Check against low and high watermarks }
end;
if MustRepaint then
RePaint;
diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas
index a7c7e740..4e2a2f39 100644
--- a/src/gui/gui_listbox.pas
+++ b/src/gui/gui_listbox.pas
@@ -388,7 +388,10 @@ begin
end;
procedure TfpgBaseListBox.HandleLMouseDown(x, y: integer; shiftstate: TShiftState);
+var
+ tmp: IInterface;
begin
+ tmp := PrintCallTrace(ClassName, 'HandleLMouseDown');
inherited HandleLMouseDown(x, y, shiftstate);
if ItemCount < 1 then
@@ -593,7 +596,7 @@ begin
FScrollBar := TfpgScrollBar.Create(self);
FScrollBar.OnScroll := @ScrollBarMove;
- FScrollBar.Visible := False;
+// FScrollBar.Visible := False;
FFocusable := True;
FFocusItem := 1;
@@ -659,7 +662,11 @@ begin
end;
destructor TfpgTextListBox.Destroy;
+var
+ tmp: IInterface;
begin
+ tmp := PrintCallTrace(ClassName, 'Destroy');
+ PrintCallTraceDbgLn('**** Freeing off the listbox items');
TfpgListBoxStrings(FItems).Free;
inherited Destroy;
end;
@@ -670,7 +677,10 @@ begin
end;
function TfpgTextListBox.Text: string;
+var
+ tmp: IInterface;
begin
+ tmp := PrintCallTrace(Classname, 'Text');
if (FocusItem > 0) and (FocusItem <= FItems.Count) then
result := FItems.Strings[FocusItem-1]
else
diff --git a/src/gui/gui_listview.pas b/src/gui/gui_listview.pas
index a3eaba43..0a2ff4f8 100644
--- a/src/gui/gui_listview.pas
+++ b/src/gui/gui_listview.pas
@@ -572,7 +572,6 @@ procedure TfpgListView.ItemChanged(AIndex: Integer);
begin
if FUpdateCount = 0 then
DoRePaint;
- // TODO
end;
procedure TfpgListView.ItemsUpdated;
@@ -1374,7 +1373,7 @@ begin
if lvppIcon in PaintPart then
begin
- // TODO paint icon
+ { TODO: paint icon }
end;
if lvppFocused in PaintPart then