summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-01-02 08:59:01 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-01-02 08:59:01 +0000
commitb39b7b9e34ddfcd4650c8c9ad767c40f04567068 (patch)
tree9b874f9becd40743ed3d409d1f22e7316d770f69 /src/gui
parentb031790d50f9d7e3af436dce48d54e8dbc82950c (diff)
downloadfpGUI-b39b7b9e34ddfcd4650c8c9ad767c40f04567068.tar.xz
* Fixed AV that occurs when a combobox is opened and closed a few times.
* A minor improvement to the internal stringlist for ListBox components.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui_combobox.pas28
-rw-r--r--src/gui/gui_listbox.pas28
2 files changed, 37 insertions, 19 deletions
diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas
index ed23f1a6..0c9b4282 100644
--- a/src/gui/gui_combobox.pas
+++ b/src/gui/gui_combobox.pas
@@ -126,6 +126,7 @@ type
procedure HandleHide; override;
public
constructor Create(AOwner: TComponent); override;
+ destructor Destroy; override;
ListBox: TfpgListBox;
property CallerWidget: TfpgWidget read FCallerWidget write FCallerWidget;
end;
@@ -146,8 +147,8 @@ begin
inherited HandleKeyPress(keycode, shiftstate, consumed);
if keycode = keyEscape then
begin
- Close;
consumed := True;
+ Close;
end;
end;
@@ -164,10 +165,15 @@ end;
procedure TDropDownWindow.HandleHide;
begin
- FocusRootWidget.ReleaseMouse; // for internal ListBox
+ // HandleHide also gets called in TfpgWidget.Destroy so we need a few
+ // if Assigned() tests here. This should be improved on.
+ if Assigned(FocusRootWidget) then
+ FocusRootWidget.ReleaseMouse; // for internal ListBox
+
FocusRootWidget := OriginalFocusRoot;
OriginalFocusRoot := nil;
inherited HandleHide;
+
if Assigned(FocusRootWidget) then
FocusRootWidget.SetFocus;
end;
@@ -175,14 +181,16 @@ end;
constructor TDropDownWindow.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
-// WindowType := wtPopup;
-// WindowAttributes := [];
-// WindowPosition := wpUser;
-
ListBox := TfpgListBox.Create(self);
ListBox.PopupFrame := True;
end;
+destructor TDropDownWindow.Destroy;
+begin
+ ListBox.Free;
+ inherited Destroy;
+end;
+
function CreateComboBox(AOwner: TComponent; x, y, w: TfpgCoord; AList: TStringList): TfpgComboBox;
begin
Result := TfpgComboBox.Create(AOwner);
@@ -328,7 +336,7 @@ begin
begin
if SameText(FItems.Strings[i], AValue) then
begin
- SetFocusItem(i+1);
+ SetFocusItem(i+1); // our FocusItem is 1-based. TStringList is 0-based.
Break;
end;
end;
@@ -358,6 +366,9 @@ end;
procedure TfpgAbstractComboBox.HandleLMouseDown(x, y: integer; shiftstate: TShiftState);
begin
+ {$IFDEF DEBUG}
+ writeln('TfpgAbstractComboBox.HandleLMouseDown [', Classname, ']');
+ {$ENDIF}
inherited HandleLMouseDown(x, y, shiftstate);
// button state is down only if user clicked in the button rectangle.
if PtInRect(FInternalBtnRect, Point(x, y)) then
@@ -367,6 +378,9 @@ end;
procedure TfpgAbstractComboBox.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
begin
+ {$IFDEF DEBUG}
+ writeln('TfpgAbstractComboBox.HandleLMouseUp [', Classname, ']');
+ {$ENDIF}
inherited HandleLMouseUp(x, y, shiftstate);
FBtnPressed := False;
DoDropDown;
diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas
index 630390f6..a7c7e740 100644
--- a/src/gui/gui_listbox.pas
+++ b/src/gui/gui_listbox.pas
@@ -102,7 +102,6 @@ type
TfpgTextListBox = class(TfpgBaseListBox)
protected
FItems: TStringList;
- FInternalItems: TStrings;
procedure DrawItem(num: integer; rect: TfpgRect; flags: integer); override;
property Items: TStringList read FItems;
public
@@ -134,7 +133,9 @@ type
procedure SetUpdateState(Updating: Boolean); override;
public
constructor Create(AListBox: TfpgTextListBox);
+ destructor Destroy; override;
function Add(const s: String): Integer; override;
+ procedure Delete(Index: Integer); override;
end;
{ TfpgListBoxStrings }
@@ -151,18 +152,24 @@ begin
ListBox := AListBox;
end;
+destructor TfpgListBoxStrings.Destroy;
+begin
+ ListBox := nil;
+ inherited Destroy;
+end;
+
function TfpgListBoxStrings.Add(const s: String): Integer;
-//var
-// ItemWidth: Integer;
begin
Result := inherited Add(s);
if Assigned(ListBox) and (ListBox.HasHandle) then
- begin
-// ItemWidth := ListBox.Font.TextWidth(s) + 4;
-// if ItemWidth > ListBox.FMaxItemWidth then
-// ListBox.FMaxItemWidth := ItemWidth;
ListBox.UpdateScrollBar;
- end;
+end;
+
+procedure TfpgListBoxStrings.Delete(Index: Integer);
+begin
+ inherited Delete(Index);
+ if Assigned(ListBox) and (ListBox.HasHandle) then
+ ListBox.UpdateScrollBar;
end;
@@ -472,8 +479,6 @@ end;
procedure TfpgBaseListBox.HandleShow;
begin
inherited HandleShow;
-// if (csDesigning in ComponentState) then
-// Exit;
if (csLoading in ComponentState) then
Exit;
UpdateScrollBarCoords;
@@ -655,8 +660,7 @@ end;
destructor TfpgTextListBox.Destroy;
begin
- FItems.Free;
- FInternalItems.Free;
+ TfpgListBoxStrings(FItems).Free;
inherited Destroy;
end;