mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-28 09:03:50 +02:00
remove usage of fcompstyle in twin32liststringlist by using descendent class for combobox specific things
git-svn-id: trunk@6200 -
This commit is contained in:
parent
17ad66bb2a
commit
76b630a62d
@ -42,12 +42,16 @@ Begin
|
||||
Result := StrComp(AStr, BStr);
|
||||
end;
|
||||
|
||||
Procedure SetComboHeight(Sender: TWinControl;
|
||||
ALeft, ATop, AWidth, AHeight:Integer);
|
||||
Procedure SetComboHeight(Sender: TWinControl; AHeight:Integer);
|
||||
var
|
||||
Left, Top, Width: integer;
|
||||
begin
|
||||
LCLBoundsToWin32Bounds(Sender,ALeft, ATop, AWidth, AHeight);
|
||||
MoveWindow(Sender.Handle,ALeft,ATop,AWidth,AHeight,true);
|
||||
LCLControlSizeNeedsUpdate(Sender,true);
|
||||
Left := Sender.Left;
|
||||
Top := Sender.Top;
|
||||
Width := Sender.Width;
|
||||
LCLBoundsToWin32Bounds(Sender, Left, Top, Width, AHeight);
|
||||
MoveWindow(Sender.Handle, Left, Top, Width, AHeight, true);
|
||||
LCLControlSizeNeedsUpdate(Sender, true);
|
||||
end;
|
||||
|
||||
{*************************************************************}
|
||||
@ -61,8 +65,6 @@ end;
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
Constructor TWin32ListStringList.Create(List : HWND; TheOwner: TWinControl);
|
||||
Var
|
||||
R:TRect;
|
||||
Begin
|
||||
Inherited Create;
|
||||
If List = HWND(Nil) Then
|
||||
@ -72,47 +74,25 @@ Begin
|
||||
FSender := TheOwner;
|
||||
|
||||
//Set proper win32 flags for ComboBox/ListBox and get/set Combo Height
|
||||
case FSender.FCompStyle of
|
||||
csComboBox:
|
||||
begin
|
||||
FFlagSort := UINT(CBS_SORT);
|
||||
FFlagGetText := UINT(CB_GETLBTEXT);
|
||||
FFlagGetTextLen := UINT(CB_GETLBTEXTLEN);
|
||||
FFlagGetCount := UINT(CB_GETCOUNT);
|
||||
FFlagResetContent := UINT(CB_RESETCONTENT);
|
||||
FFlagDeleteString := UINT(CB_DELETESTRING);
|
||||
FFlagInsertString := UINT(CB_INSERTSTRING);
|
||||
FFlagAddString := UINT(CB_ADDSTRING);
|
||||
FFlagGetItemData := UINT(CB_GETITEMDATA);
|
||||
FFlagSetItemData := UINT(CB_SETITEMDATA);
|
||||
//Get edit and item sizes
|
||||
Windows.GetClientRect(FWin32List,@R);
|
||||
FEditHeight := R.Bottom;
|
||||
FItemHeight := Windows.SendMessage(FWin32List, CB_GETITEMHEIGHT, 0, 0);
|
||||
FDDownCount := TComboBox(FSender).DropDownCount;
|
||||
If FDDownCount = 0 then
|
||||
FDDownCount := 8;
|
||||
end;
|
||||
csListBox,csCheckListBox:
|
||||
begin
|
||||
FFlagSort := UINT(LBS_SORT);
|
||||
FFlagGetText := UINT(LB_GETTEXT);
|
||||
FFlagGetTextLen := UINT(LB_GETTEXTLEN);
|
||||
FFlagGetCount := UINT(LB_GETCOUNT);
|
||||
FFlagResetContent := UINT(LB_RESETCONTENT);
|
||||
FFlagDeleteString := UINT(LB_DELETESTRING);
|
||||
FFlagInsertString := UINT(LB_INSERTSTRING);
|
||||
FFlagAddString := UINT(LB_ADDSTRING);
|
||||
FFlagGetItemData := UINT(LB_GETITEMDATA);
|
||||
FFlagSetItemData := UINT(LB_SETITEMDATA);
|
||||
end;
|
||||
else
|
||||
raise Exception.Create('Win32ListStringList: Component type not detected');
|
||||
end;
|
||||
InitFlags;
|
||||
// Determine if the list is sorted
|
||||
FSorted := (UINT(GetWindowLong(FWin32List, GWL_STYLE)) and FFlagSort <> 0);
|
||||
End;
|
||||
|
||||
procedure TWin32ListStringList.InitFlags;
|
||||
begin
|
||||
FFlagSort := UINT(LBS_SORT);
|
||||
FFlagGetText := UINT(LB_GETTEXT);
|
||||
FFlagGetTextLen := UINT(LB_GETTEXTLEN);
|
||||
FFlagGetCount := UINT(LB_GETCOUNT);
|
||||
FFlagResetContent := UINT(LB_RESETCONTENT);
|
||||
FFlagDeleteString := UINT(LB_DELETESTRING);
|
||||
FFlagInsertString := UINT(LB_INSERTSTRING);
|
||||
FFlagAddString := UINT(LB_ADDSTRING);
|
||||
FFlagGetItemData := UINT(LB_GETITEMDATA);
|
||||
FFlagSetItemData := UINT(LB_SETITEMDATA);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TWin32ListStringList.SetSorted
|
||||
Params:
|
||||
@ -150,43 +130,21 @@ End;
|
||||
Procedure TWin32ListStringList.Assign(Source: TPersistent);
|
||||
Var
|
||||
Counter: Integer;
|
||||
EditText: String;
|
||||
Begin
|
||||
{ Do not call inherited Assign as it does things we do not want to happen }
|
||||
If Source Is TStrings Then
|
||||
Begin
|
||||
// save any text in edit box
|
||||
if FSender.FCompStyle=csComboBox then
|
||||
TWin32WSCustomComboBox.GetText(FSender, EditText);
|
||||
|
||||
Windows.SendMessage(FWin32List, FFlagResetContent, 0, 0);
|
||||
For Counter := 0 To (TStrings(Source).Count - 1) Do
|
||||
Begin
|
||||
Windows.SendMessage(FWin32List, FFlagAddString, 0, LPARAM(PChar(TStrings(Source)[Counter]))); //Insert
|
||||
PutObject(Counter, TStrings(Source).Objects[Counter]);
|
||||
end;
|
||||
|
||||
if FSender.FCompStyle=csComboBox Then
|
||||
begin
|
||||
SetComboHeight(FSender, FSender.Left, FSender.Top, FSender.Width, ComboHeight);
|
||||
// restore text in edit box
|
||||
TWin32WSCustomComboBox.SetText(FSender, EditText);
|
||||
end;
|
||||
End
|
||||
Else
|
||||
inherited Assign(Source);
|
||||
End;
|
||||
|
||||
function TWin32ListStringList.GetComboHeight: integer;
|
||||
begin
|
||||
if Count = 0 then
|
||||
begin
|
||||
Result := FEditHeight + FItemHeight + 2;
|
||||
end else begin
|
||||
Result := FEditHeight + FDDownCount*FItemHeight + 2;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TWin32ListStringList.Get
|
||||
Params:
|
||||
@ -201,7 +159,7 @@ Begin
|
||||
Raise Exception.Create('Out of bounds.')
|
||||
Else
|
||||
Begin
|
||||
Getmem(Item,Windows.SendMessage(FWin32List,FFlagGetTextLen,Index,0)+1);
|
||||
Getmem(Item, Windows.SendMessage(FWin32List, FFlagGetTextLen, Index, 0)+1);
|
||||
Windows.SendMessage(FWin32List, FFlagGetText, Index, LPARAM(Item));
|
||||
End;
|
||||
Result := StrPas(Item);
|
||||
@ -227,10 +185,7 @@ End;
|
||||
------------------------------------------------------------------------------}
|
||||
Procedure TWin32ListStringList.Clear;
|
||||
Begin
|
||||
if FSender.FCompStyle=csComboBox Then
|
||||
SetComboHeight(FSender,FSender.Left,FSender.Top,FSender.Width,
|
||||
FEditHeight + FItemHeight + 2);
|
||||
Windows.SendMessage(FWin32List,FFlagResetContent, 0, 0);
|
||||
Windows.SendMessage(FWin32List, FFlagResetContent, 0, 0);
|
||||
End;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -241,11 +196,7 @@ End;
|
||||
------------------------------------------------------------------------------}
|
||||
Procedure TWin32ListStringList.Delete(Index: Integer);
|
||||
Begin
|
||||
If (FSender.FCompStyle = csComboBox)
|
||||
and (GetCount <= 1) Then
|
||||
SetComboHeight(FSender,FSender.Left,FSender.Top,FSender.Width,
|
||||
FEditHeight + FItemHeight + 2);
|
||||
Windows.SendMessage(FWin32List,FFlagDeleteString, Index, 0);
|
||||
Windows.SendMessage(FWin32List, FFlagDeleteString, Index, 0);
|
||||
End;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -267,14 +218,10 @@ End;
|
||||
------------------------------------------------------------------------------}
|
||||
Procedure TWin32ListStringList.Insert(Index: Integer; Const S: String);
|
||||
Begin
|
||||
If (FSender.FCompStyle = csComboBox)
|
||||
and (GetCount = 0) Then
|
||||
SetComboHeight(FSender,FSender.Left,FSender.Top,FSender.Width,
|
||||
FEditHeight + FDDownCount*FItemHeight + 2);
|
||||
If FSorted Then
|
||||
Windows.SendMessage(FWin32List,FFlagAddString, 0, LPARAM(PChar(S)))
|
||||
Windows.SendMessage(FWin32List, FFlagAddString, 0, LPARAM(PChar(S)))
|
||||
Else
|
||||
Windows.SendMessage(FWin32List,FFlagInsertString, Index, LPARAM(PChar(S)));
|
||||
Windows.SendMessage(FWin32List, FFlagInsertString, Index, LPARAM(PChar(S)));
|
||||
End;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -288,6 +235,78 @@ Begin
|
||||
Windows.SendMessage(FWin32List, FFlagSetItemData, Index, LPARAM(AObject));
|
||||
End;
|
||||
|
||||
{ TWin32ComboBoxStringList }
|
||||
|
||||
procedure TWin32ComboBoxStringList.InitFlags;
|
||||
var
|
||||
R: TRect;
|
||||
begin
|
||||
FFlagSort := UINT(CBS_SORT);
|
||||
FFlagGetText := UINT(CB_GETLBTEXT);
|
||||
FFlagGetTextLen := UINT(CB_GETLBTEXTLEN);
|
||||
FFlagGetCount := UINT(CB_GETCOUNT);
|
||||
FFlagResetContent := UINT(CB_RESETCONTENT);
|
||||
FFlagDeleteString := UINT(CB_DELETESTRING);
|
||||
FFlagInsertString := UINT(CB_INSERTSTRING);
|
||||
FFlagAddString := UINT(CB_ADDSTRING);
|
||||
FFlagGetItemData := UINT(CB_GETITEMDATA);
|
||||
FFlagSetItemData := UINT(CB_SETITEMDATA);
|
||||
//Get edit and item sizes
|
||||
Windows.GetClientRect(FWin32List,@R);
|
||||
FEditHeight := R.Bottom;
|
||||
FItemHeight := Windows.SendMessage(FWin32List, CB_GETITEMHEIGHT, 0, 0);
|
||||
FDropDownCount := TComboBox(FSender).DropDownCount;
|
||||
If FDropDownCount = 0 then
|
||||
FDropDownCount := 8;
|
||||
end;
|
||||
|
||||
procedure TWin32ComboBoxStringList.Assign(Source: TPersistent);
|
||||
var
|
||||
EditText: string;
|
||||
begin
|
||||
if Source is TStrings then
|
||||
begin
|
||||
// save text in edit box, assigning strings clears the text
|
||||
TWin32WSCustomComboBox.GetText(FSender, EditText);
|
||||
|
||||
inherited Assign(Source);
|
||||
|
||||
// restore text in edit box
|
||||
SetComboHeight(FSender, ComboHeight);
|
||||
TWin32WSCustomComboBox.SetText(FSender, EditText);
|
||||
end else
|
||||
inherited Assign(Source);
|
||||
end;
|
||||
|
||||
function TWin32ComboBoxStringList.GetComboHeight: integer;
|
||||
begin
|
||||
if Count = 0 then
|
||||
begin
|
||||
Result := FEditHeight + FItemHeight + 2;
|
||||
end else begin
|
||||
Result := FEditHeight + FDropDownCount*FItemHeight + 2;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWin32ComboBoxStringList.Clear;
|
||||
begin
|
||||
SetComboHeight(FSender, FEditHeight + FItemHeight + 2);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TWin32ComboBoxStringList.Delete(Index: integer);
|
||||
begin
|
||||
if GetCount <= 1 then
|
||||
SetComboHeight(FSender, FEditHeight + FItemHeight + 2);
|
||||
end;
|
||||
|
||||
procedure TWin32ComboBoxStringList.Insert(Index: integer; const S: string);
|
||||
begin
|
||||
if GetCount = 0 then
|
||||
SetComboHeight(FSender, FEditHeight + FDropDownCount*FItemHeight + 2);
|
||||
end;
|
||||
|
||||
|
||||
{ TWin32CheckListBoxStrings }
|
||||
|
||||
constructor TWin32CheckListBoxStrings.Create(List : HWND; TheOwner: TWinControl);
|
||||
@ -549,6 +568,9 @@ End;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.36 2004/11/04 15:12:35 micha
|
||||
remove usage of fcompstyle in twin32liststringlist by using descendent class for combobox specific things
|
||||
|
||||
Revision 1.35 2004/11/04 12:05:14 micha
|
||||
fix remember edit string in combobox after assigning strings to list (fixes find in files dialog search in lazarus)
|
||||
|
||||
|
@ -32,9 +32,7 @@ Type
|
||||
FWin32List: HWND;
|
||||
FSorted: Boolean;
|
||||
FSender: TWinControl;
|
||||
FEditHeight: Integer;
|
||||
FItemHeight: Integer;
|
||||
FDDownCount: Integer;
|
||||
protected
|
||||
//Win32 Flags
|
||||
FFlagSort: Cardinal;
|
||||
FFlagGetText: Cardinal;
|
||||
@ -51,8 +49,9 @@ Type
|
||||
Function GetCount: Integer; Override;
|
||||
Function GetObject(Index: Integer): TObject; Override;
|
||||
Procedure PutObject(Index: Integer; AObject: TObject); Override;
|
||||
|
||||
procedure InitFlags; virtual;
|
||||
Procedure SetSorted(Val: Boolean); Virtual;
|
||||
function GetComboHeight: integer;
|
||||
Public
|
||||
Constructor Create(List : HWND; TheOwner: TWinControl);
|
||||
Procedure Assign(Source: TPersistent); Override;
|
||||
@ -61,9 +60,25 @@ Type
|
||||
Procedure Insert(Index: Integer; Const S: String); Override;
|
||||
Procedure Sort; Virtual;
|
||||
Property Sorted: Boolean Read FSorted Write SetSorted;
|
||||
property ComboHeight: integer read GetComboHeight;
|
||||
End;
|
||||
|
||||
TWin32ComboBoxStringList = class(TWin32ListStringList)
|
||||
private
|
||||
FEditHeight: Integer;
|
||||
FItemHeight: Integer;
|
||||
FDropDownCount: Integer;
|
||||
protected
|
||||
function GetComboHeight: integer;
|
||||
procedure InitFlags; override;
|
||||
public
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
procedure Clear; override;
|
||||
procedure Delete(Index: integer); override;
|
||||
procedure Insert(Index: integer; const S: string); override;
|
||||
|
||||
property ComboHeight: integer read GetComboHeight;
|
||||
end;
|
||||
|
||||
PWin32CheckListBoxItemRecord = ^TWin32CheckListBoxItemRecord;
|
||||
TWin32CheckListBoxItemRecord = record
|
||||
TheObject: TObject;
|
||||
@ -119,6 +134,9 @@ Type
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.17 2004/11/04 15:12:35 micha
|
||||
remove usage of fcompstyle in twin32liststringlist by using descendent class for combobox specific things
|
||||
|
||||
Revision 1.16 2004/05/08 12:32:32 micha
|
||||
fix combobox height; whatever the lcl passes as height for combobox, always calculate our own
|
||||
|
||||
|
@ -542,7 +542,7 @@ Var
|
||||
OldTop: Integer;
|
||||
{$ENDIF}
|
||||
WinHandle, BuddyHandle: HWND;
|
||||
StringList: TWin32ListStringList;
|
||||
StringList: TWin32ComboBoxStringList;
|
||||
suppressMove: boolean;
|
||||
Begin
|
||||
// if not Sender.HandleAllocated then exit; --> Already checked (LM_SETSIZE and LM_RECREATEWND)
|
||||
@ -585,7 +585,7 @@ Begin
|
||||
else
|
||||
if Sender is TCustomComboBox then
|
||||
begin
|
||||
StringList := TWin32ListStringList(GetWindowInfo(WinHandle)^.List);
|
||||
StringList := TWin32ComboBoxStringList(GetWindowInfo(WinHandle)^.List);
|
||||
if StringList <> nil then
|
||||
Height := StringList.ComboHeight;
|
||||
end;
|
||||
@ -736,6 +736,9 @@ end;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.298 2004/11/04 15:12:35 micha
|
||||
remove usage of fcompstyle in twin32liststringlist by using descendent class for combobox specific things
|
||||
|
||||
Revision 1.297 2004/11/02 17:48:19 micha
|
||||
remove usage of fcompstyle
|
||||
|
||||
|
@ -689,7 +689,7 @@ var
|
||||
winhandle: HWND;
|
||||
begin
|
||||
winhandle := ACustomComboBox.Handle;
|
||||
Result := TWin32ListStringList.Create(winhandle, ACustomComboBox);
|
||||
Result := TWin32ComboBoxStringList.Create(winhandle, ACustomComboBox);
|
||||
GetWindowInfo(winhandle)^.List := Result;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user