summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui_button.pas2
-rw-r--r--src/gui/gui_combobox.pas49
-rw-r--r--src/gui/gui_listbox.pas14
3 files changed, 37 insertions, 28 deletions
diff --git a/src/gui/gui_button.pas b/src/gui/gui_button.pas
index e6973177..85377623 100644
--- a/src/gui/gui_button.pas
+++ b/src/gui/gui_button.pas
@@ -407,7 +407,7 @@ end;
procedure TfpgButton.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
begin
// writeln('mouse up');
- inherited;
+// inherited;
if (csDesigning in ComponentState) then
Exit;
DoRelease;
diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas
index 1ad527ea..ed23f1a6 100644
--- a/src/gui/gui_combobox.pas
+++ b/src/gui/gui_combobox.pas
@@ -116,7 +116,6 @@ var
type
{ This is the class representing the dropdown window of the combo box. }
-
TDropDownWindow = class(TfpgPopupWindow)
private
FCallerWidget: TfpgWidget;
@@ -127,7 +126,6 @@ type
procedure HandleHide; override;
public
constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
ListBox: TfpgListBox;
property CallerWidget: TfpgWidget read FCallerWidget write FCallerWidget;
end;
@@ -156,19 +154,18 @@ end;
procedure TDropDownWindow.HandleShow;
begin
FocusRootWidget := ListBox;
-
- ListBox.Left := 0;
- ListBox.Top := 0;
- ListBox.Width := Width;
- ListBox.Height := Height;
-
+ ListBox.Left := 0;
+ ListBox.Top := 0;
+ ListBox.Width := Width;
+ ListBox.Height := Height;
inherited HandleShow;
-// CaptureMouse;
+ FocusRootWidget.CaptureMouse; // for internal ListBox
end;
procedure TDropDownWindow.HandleHide;
begin
- FocusRootWidget := OriginalFocusRoot;
+ FocusRootWidget.ReleaseMouse; // for internal ListBox
+ FocusRootWidget := OriginalFocusRoot;
OriginalFocusRoot := nil;
inherited HandleHide;
if Assigned(FocusRootWidget) then
@@ -186,13 +183,6 @@ begin
ListBox.PopupFrame := True;
end;
-destructor TDropDownWindow.Destroy;
-begin
-// ReleaseMouse;
- inherited Destroy;
-end;
-
-
function CreateComboBox(AOwner: TComponent; x, y, w: TfpgCoord; AList: TStringList): TfpgComboBox;
begin
Result := TfpgComboBox.Create(AOwner);
@@ -258,15 +248,17 @@ begin
rowcount := FDropDownCount;
if rowcount < 1 then
rowcount := 1;
- ddw.Height := (ddw.ListBox.RowHeight * rowcount) + 4;
- ddw.CallerWidget := self;
- ddw.ListBox.OnSelect := @InternalListBoxSelect;
+ ddw.Height := (ddw.ListBox.RowHeight * rowcount) + 4;
+ ddw.CallerWidget := self;
+ ddw.ListBox.OnSelect := @InternalListBoxSelect;
// Assign combobox text items to internal listbox and set default focusitem
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.ListBox.SetFocus;
end
else
@@ -283,9 +275,16 @@ begin
end;
procedure TfpgAbstractComboBox.InternalListBoxSelect(Sender: TObject);
+var
+ msgp: TfpgMessageParams;
begin
FFocusItem := TDropDownWindow(FDropDown).ListBox.FocusItem;
- FDropDown.Close;
+
+ { 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);
+
if HasHandle then
Repaint;
if Assigned(FOnChange) then
@@ -360,7 +359,7 @@ end;
procedure TfpgAbstractComboBox.HandleLMouseDown(x, y: integer; shiftstate: TShiftState);
begin
inherited HandleLMouseDown(x, y, shiftstate);
- // botton down only if user clicked on the button.
+ // button state is down only if user clicked in the button rectangle.
if PtInRect(FInternalBtnRect, Point(x, y)) then
FBtnPressed := True;
PaintInternalButton;
@@ -474,7 +473,7 @@ begin
FMargin := 3;
FFocusable := True;
FBtnPressed := False;
-
+
FItems := TStringList.Create;
CalculateInternalButtonRect;
@@ -483,7 +482,9 @@ end;
destructor TfpgAbstractComboBox.Destroy;
begin
- if Assigned(FDropDown) then
+ { 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;
FItems.Free;
FFont.Free;
diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas
index 64055937..630390f6 100644
--- a/src/gui/gui_listbox.pas
+++ b/src/gui/gui_listbox.pas
@@ -386,6 +386,10 @@ begin
if ItemCount < 1 then
Exit; //==>
+
+ { User clicked outside listbox bounds. ComboBox requires this check. }
+ if y < 0 then
+ Exit; //==>
FFocusItem := FFirstItem + Trunc((y - FMargin) / RowHeight);
if FFocusItem > ItemCount then
@@ -405,9 +409,13 @@ begin
FMouseDragging := False;
- FFocusItem := FFirstItem + Trunc((y - FMargin) / RowHeight);
- if FFocusItem > ItemCount then
- FFocusItem := ItemCount;
+ { User clicked outside listbox bounds. ComboBox requires this check. }
+ if not (y < 0) then
+ begin
+ FFocusItem := FFirstItem + Trunc((y - FMargin) / RowHeight);
+ if FFocusItem > ItemCount then
+ FFocusItem := ItemCount;
+ end;
FollowFocus;
Repaint;