2009-08-06 14:32:07 +00:00
|
|
|
unit KOLEcmListEdit;
|
|
|
|
{$DEFINE rbutton_sel}
|
|
|
|
{* TKOLEcmListEdit - ���������� ������������ ListView ������������ ��������������
|
|
|
|
|=================================================================================
|
|
|
|
| Version 1.17
|
|
|
|
|Copyright (C) by ECM, 2004..2006 <ecm@ua.fm>
|
|
|
|
|This unit conains objects TEcmListEdit.
|
|
|
|
|<pre>
|
|
|
|
�������: ListEdit "������" ����������� � lvsDetail(lvsDetailNoHeader) � �� DBLCLICK ����
|
|
|
|
�� Enter ��� �� "��������������" ������� � ����������
|
|
|
|
(���� ���������� StartEdit)����������� � �����
|
|
|
|
"��������������" - ������ �� ������� ������ ListEdit �������������
|
|
|
|
"���������� ��������" (��-��������� EditBox)
|
|
|
|
� ���� ������ ����� ���������� ����� ����� ����� �������� �����
|
|
|
|
��� � StringGrid-�. ����� �� ������ �������������� - Esc, StopEdit
|
|
|
|
��� ����� ������
|
|
|
|
|
|
|
|
��� ������� �� KOLmdvXLGrid - �� "�� ����" ����������� ����� ( ~3.9 ��)
|
|
|
|
|
|
|
|
��������(����): KOLListEdit - ��������� ������� - thanks! (��� ��������� ������
|
|
|
|
����������� ���������)
|
|
|
|
����� �� ��������� � ���������� (KOLListEdit):
|
|
|
|
|
|
|
|
- ������� ��� ����� ��������� � StringGrid �� ���� ��������� � �����������
|
|
|
|
��������� ����� � ����� ������� ������������ ��������� ������ ������ (��. OnColAdjust);
|
|
|
|
|
|
|
|
- �������������� ��������� ListView � ������ �������������� (��� �� ���������
|
|
|
|
��� � �� �����������)+ ����������� ����� �������� �� ����������� ��������� �����-������;
|
|
|
|
|
|
|
|
- �������������� �������: OnGetEditText,OnPutEditText,OnStopEdit,OnEditChar,
|
|
|
|
OnColAdjust,OnCreateEdit
|
|
|
|
|
|
|
|
����������� ��������� ��������� ����������� ��������� � �������� ����� ����������������
|
|
|
|
|</pre>
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version 1.17 (29.06.2006)
|
|
|
|
// ��������� ��� ��������� Align ��� Inplace Editor - ������� Matveev Dmitry
|
|
|
|
// ��������� ������� OnDrawCell (by Matveev Dmitry)
|
|
|
|
// ��������� ���� ������ ������ ������ ��� lvoRowSelect = True
|
|
|
|
// ���������� ������ �������� � ����� �������������� �� ������� Ctrl - ������� Matveev Dmitry
|
|
|
|
|
|
|
|
// Version 1.16 (27.02.2006)
|
|
|
|
// ��������� ����������� � ���� ������-��������� ������ �����
|
|
|
|
|
|
|
|
// Version 1.15 (3.1.2006)
|
|
|
|
// ��������� ���� �� $DEFINE USE_PROP ������ � ����������� � KOL.PAS(����� ������ ��� �������!)
|
|
|
|
|
|
|
|
// Version 1.14 (19.10.2005)
|
|
|
|
// ���: Dcr-���� ������������ � ������ �� ���� ���������� �� pas-������� �
|
|
|
|
// dpk-�����
|
|
|
|
|
|
|
|
// Version 1.13 (2.10.2005)
|
|
|
|
// ��������� �������� AutoHide � TOnCreateEdit
|
|
|
|
// AutoHide = True (default) - ������������� ��������� Inplace Editor
|
|
|
|
// ��� ������ ������� ������ �����. False - ��������� ��� ��������
|
|
|
|
|
|
|
|
// Version 1.12 (14.07.2005)
|
|
|
|
// ��������� ������� WndProcListViewWOResizeFlicks
|
|
|
|
|
|
|
|
// Version 1.11 (24.01.2005)
|
|
|
|
// ������ ������ ��������� ��� ������ SetCurLVPos
|
|
|
|
// thanx Sphinxx for bugreport
|
|
|
|
|
|
|
|
// Version 1.10 (18.01.2005)
|
|
|
|
// ��� ������ DrawText �������� ������� DT_NOPREFIX
|
|
|
|
|
|
|
|
// Version 1.09 (24.12.2004)
|
|
|
|
// [+] ��������� ������� UpdateRow
|
|
|
|
|
|
|
|
// Version 1.08 (17.11.2004)
|
|
|
|
// [-] ���������� ��������� ����� ���� ��� ����������� ���������. (���-��
|
|
|
|
// ���� � ������� ��� ListView - � ��������� Color = clWindow � �������
|
|
|
|
// ����� �������� �� ���������� ������ )
|
|
|
|
|
|
|
|
// Version 1.07 (25.10.2004)
|
|
|
|
// [+] ��������� ��������� ������� ����� (��������� ����� LVDrawItem - ������
|
|
|
|
// ��������������� - ���� ���� ����� �������������� ������������ ������)
|
|
|
|
// [-] ���������� ������ �������� ��������� - ����� ����� ������� ������ ���
|
|
|
|
// ������ ���������� � ����������� ����� ������
|
|
|
|
// [-] ��������� ����� InternalStopEdit (by Dmitry Matveev)
|
|
|
|
// [*] ��������� ������ ��������� (� �������� ��������� ������� ���������
|
|
|
|
// ������ �������)
|
|
|
|
|
|
|
|
// Version 1.06 (4.10.2004)
|
|
|
|
// [*] ��������� ������ � ������� KOL 1.96 - ������ NO_ITEMHEIGHT �� �����
|
|
|
|
|
|
|
|
// Version 1.05 (28.09.2004)
|
|
|
|
// [+] ������� � OnCreateEdit �������� ReadOnly. ��� ��������� ��� � True
|
|
|
|
// �������� �� ��������� (by Matveev Dmitry)
|
|
|
|
// [+] DEFINE NO_ITEMHEIGHT - ��� ���������� ���� ������������� ������ �����
|
|
|
|
// (���������� ������������� ����� � � ������� ���� ������������ ������
|
|
|
|
// KOL 1.95+ - � ��� ���������� ������� �������� � ListView)
|
|
|
|
// ���� KOL+MCK �� 1.95 �� ������ 1.95+ ������������ �������� � ����������
|
|
|
|
// ������ ����� ��� ListView ����� ����� http://kolibdb.100free.com/kolmck195Plus.zip
|
|
|
|
|
|
|
|
// Version 1.04 (16.09.2004)
|
|
|
|
// [+] ������� ����������� ��������� lvsDetailNoHeader (by Matveev Dmitry)
|
|
|
|
|
|
|
|
// Version 1.03 (15.09.2004)
|
|
|
|
// [-] ����� "����������" ������� ��������� �� ��������� ��� ��������� ScrollBar-��
|
|
|
|
// [*] ����� ����� �������� ������ ��� ������ �� ������ ������ ������ (by Matveev Dmitry)
|
|
|
|
|
|
|
|
// Version 1.02 (14.09.2004)
|
|
|
|
// [*] ������������� ��������� - ������ ������ �������
|
|
|
|
// [+] ���������� ��������� ��� ����� ������
|
|
|
|
// [*] ������������� ������������ � ������ ����������� ��������� ������
|
|
|
|
// (�� ������� ���� ��� taLeft) ����������� Indent � OnColAdjust ��� �������������
|
|
|
|
// [+] ������� ������� OnCreateEdit - ������ ����� ����������� ������ ������ "�����������"
|
|
|
|
// EditBox-� - ������ �������� (���� �������� �� CheckBox � ComboBox)
|
|
|
|
// ������ ������������� � ����� ... ����������������� ���� - ����� ����
|
|
|
|
// ��������... :(
|
|
|
|
|
|
|
|
// Version 1.01 (10.09.2004)
|
|
|
|
// [+] ������ ����� ��������� OwnerDraw - ���������� ����� ������ ����� VCL-StringGrid
|
|
|
|
// (� ������ FixedCols = 0 ; Options= [..,goEditing,goDrawFocusSelect,..])
|
|
|
|
// � ���� ������ ����� ������ ������������� �������������� ColOptions.Indent - InPlaceEditor
|
|
|
|
// ��-��������� ����� �������� ����� �� ���� ����� ��� � ������ � ListView
|
|
|
|
// (�� ������� ���� ��� �������� taLeft.
|
|
|
|
// [+] ������� ����������� ������������� ������ �����(������ ��� �������� OwnerDraw)
|
|
|
|
// ��������������� � �������������� ��������� NewEcmListEdit, � MCK - ItemHeight
|
|
|
|
// [+] StartEdit ������ ���������� ��� � ��� WM_CHAR (����� Enter) �� ListView-� /by SeM/
|
|
|
|
// [*] ����� ������ �����������
|
|
|
|
|
|
|
|
// Version 1.00 (6.09.2004)
|
|
|
|
// ������ ����������
|
|
|
|
//
|
|
|
|
{$I KOLDEF.INC}
|
|
|
|
//{$DEFINE _LE_DEBUG_}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Windows, Messages, KOL;
|
|
|
|
|
2017-03-17 05:02:39 +00:00
|
|
|
const
|
|
|
|
INPLACE_ITEMS_SEP = ';';
|
|
|
|
|
2009-08-06 14:32:07 +00:00
|
|
|
type
|
|
|
|
PEditorOptions = ^TEditorOptions;
|
|
|
|
TEditorOptions = packed record
|
|
|
|
Indent: TRect;
|
|
|
|
TextAlign: TTextAlign;
|
|
|
|
Options: TEditOptions;
|
|
|
|
end;
|
|
|
|
|
2017-09-20 09:42:57 +00:00
|
|
|
TOnEditText = procedure(Sender: PControl; ACol, ARow: Integer; var Value: KOLString) of object;
|
2009-08-06 14:32:07 +00:00
|
|
|
TOnEditChar = procedure(Sender: PControl; ACol, ARow: Integer; var Key: KOLChar; Shift: DWORD) of object;
|
|
|
|
TOnEndEdit = procedure(Sender: PControl; ACol, ARow: Integer; CellChanged: Boolean) of object;
|
|
|
|
TOnCreateEdit = procedure(Sender: PControl; ACol: Integer; var Editor: PControl; var ReadOnly: Boolean; var AutoHide: Boolean) of object;
|
|
|
|
TOnColAdjust = procedure(Sender: PControl; ACol: Integer; var ColOption: TEditorOptions) of object;
|
|
|
|
TOnDrawCell = function(Sender: PObj; DC: HDC; const Rect: TRect; ACol, ARow: Integer; DrawAction: TDrawAction; ItemState: TDrawState): Boolean of object;
|
|
|
|
|
|
|
|
PEcmListEdit = ^TEcmListEdit;
|
|
|
|
TEcmListEdit = object(TObj)
|
|
|
|
{* TEcmListEdit ��������� ��� ���������������� KOLEcmListEdit.
|
|
|
|
|<p>
|
|
|
|
KOLEcmListEdit ��������� ��� ������ NewEcmListEdit, ������� ������������
|
|
|
|
TEcmListEdit � �������� KOLEcmListEdit.CustomObj � ���������� ����� ����������
|
|
|
|
�������. ������� ��� ������� � TEcmListEdit � ���������� ������������ �����
|
|
|
|
�����������:
|
|
|
|
! PEcmListEdit(KOLEcmListEdit1.CustomObj)
|
|
|
|
� MCK ��� ������������ �������������.
|
|
|
|
|</p>
|
|
|
|
}
|
|
|
|
private
|
2017-01-12 12:59:05 +00:00
|
|
|
FOnCreateEdit: TOnCreateEdit;
|
2009-08-06 14:32:07 +00:00
|
|
|
FOnDrawCell: TOnDrawCell;
|
|
|
|
procedure EditOnKeyDown(Sender: PControl; var Key: Longint; Shift: DWORD);
|
|
|
|
procedure EditOnChar(Sender: PControl; var Key: KOLChar; Shift: DWORD);
|
|
|
|
procedure SetCurIdx(const Value: Integer);
|
|
|
|
protected
|
2017-09-20 09:42:57 +00:00
|
|
|
fOwner: PControl;
|
|
|
|
fColOptions: PList;
|
|
|
|
fCurIdx: Integer;
|
|
|
|
fCurLine: Integer;
|
|
|
|
fScroll: Integer;
|
|
|
|
fOnPutText: TOnEditText;
|
|
|
|
fOnGetText: TOnEditText;
|
|
|
|
fOnEndEdit: TOnEndEdit;
|
2009-08-06 14:32:07 +00:00
|
|
|
FOnColAdjust: TOnColAdjust;
|
2017-09-20 09:42:57 +00:00
|
|
|
fStarted: Boolean;
|
|
|
|
fOnEditChar: TOnEditChar;
|
|
|
|
fShift: Integer;
|
|
|
|
fEmbedEd: Boolean;
|
|
|
|
fAutoHide: Boolean;
|
2017-01-12 12:59:05 +00:00
|
|
|
function NewInPlaceEdit(Options: TEditOptions; Align: TTextAlign): PControl;
|
2009-08-06 14:32:07 +00:00
|
|
|
procedure DestroyInPlaceEditor;
|
|
|
|
procedure SetEditPos;
|
|
|
|
procedure LoadEditValues;
|
|
|
|
function GetLVItemAtPos(Pt: TSmallPoint; var SubItem: Integer): Integer;
|
|
|
|
procedure DoColAdjust(ColCount: Integer);
|
|
|
|
procedure InternalStopEdit(const Store: Boolean);
|
|
|
|
procedure HideInplaceEd(ActivateOwner: Boolean);
|
2017-09-20 09:42:57 +00:00
|
|
|
function LVDrawItem(Sender: PObj; DC: HDC; const Rect: TRect; ItemIdx: Integer; DrawAction: TDrawAction; ItemState: TDrawState): Boolean;
|
2009-08-06 14:32:07 +00:00
|
|
|
procedure ComboBox_CloseUp(Sender: PObj);
|
|
|
|
public
|
2014-12-03 10:58:03 +00:00
|
|
|
fInPlaceEd: PControl;
|
|
|
|
IsComboEditor: Boolean;
|
|
|
|
ComboOptions: TComboOptions;
|
|
|
|
ComboText: KOLString;
|
2009-08-06 14:32:07 +00:00
|
|
|
destructor Destroy; virtual; // Do not call this destructor. Use Free method instead.
|
|
|
|
procedure SetCurLVPos(ALine, AIdx: Integer);
|
|
|
|
procedure StartEdit;
|
|
|
|
{*
|
|
|
|
|<p>
|
|
|
|
��������� ������ � ��������� �������������� Editing=True. ����������
|
|
|
|
�������� ���������� �� ������� (LVCurItem) ������ ������.
|
|
|
|
���� � ������ ��� ��������� ������ (LVCurItem=-1), �������������
|
|
|
|
���������� ������(0) ������ ������ ListView.
|
|
|
|
���������� ������������� ��� DblClick-� ������ ��� �� ������� Enter.
|
|
|
|
����� ������� ����������:
|
|
|
|
! PEcmListEdit(KOLEcmListEdit1.CustomObj).StartEdit
|
|
|
|
|
|
|
|
|</p>
|
|
|
|
}
|
|
|
|
procedure StopEdit(Store: Boolean);
|
|
|
|
{*
|
|
|
|
|<p>
|
|
|
|
������� ������ �� ��������� �������������� Editing=False.
|
|
|
|
�������� Store ���������� ����� �� ����������� ������ ��
|
|
|
|
����������� ��������� � ListView.
|
|
|
|
���������� ������������� ��� ������� ������� Esc (Store=False),
|
|
|
|
����� ������ (� ������ OwnerDraw!)
|
|
|
|
����� ������� ����������:
|
|
|
|
! PEcmListEdit(KOLEcmListEdit1.CustomObj).StopEdit(True)
|
|
|
|
|</p>
|
|
|
|
}
|
|
|
|
procedure SelectCell(ACol, ARow: Integer);
|
2017-03-17 05:02:39 +00:00
|
|
|
//* ������������ ������� ������ }
|
2009-08-06 14:32:07 +00:00
|
|
|
procedure UpdateRow(ARow: Integer);
|
2017-03-17 05:02:39 +00:00
|
|
|
//* ����������� (Invalidate) ��������� ������ }
|
2009-08-06 14:32:07 +00:00
|
|
|
property Editing: Boolean read fStarted;
|
2017-03-17 05:02:39 +00:00
|
|
|
//* True - ���������� �������� �������. }
|
2009-08-06 14:32:07 +00:00
|
|
|
property OnGetEditText: TOnEditText read fOnGetText write fOnGetText;
|
2017-03-17 05:02:39 +00:00
|
|
|
//* ���������� ��� �������� ������ �� ���������� ��������. (�������� ��� ������ �������).
|
2009-08-06 14:32:07 +00:00
|
|
|
property OnPutEditText: TOnEditText read fOnPutText write fOnPutText;
|
2017-03-17 05:02:39 +00:00
|
|
|
//* ���������� ��� �������� ������ �� ����������� ���������. (�������� ��� ������ �������).
|
2009-08-06 14:32:07 +00:00
|
|
|
property OnStopEdit: TOnEndEdit read fOnEndEdit write fOnEndEdit;
|
2017-03-17 05:02:39 +00:00
|
|
|
//* ���������� ��� ����� ������ �������������� � ��� ���������� StopEdit. }
|
2009-08-06 14:32:07 +00:00
|
|
|
property OnEditChar: TOnEditChar read fOnEditChar write fOnEditChar;
|
2017-03-17 05:02:39 +00:00
|
|
|
//* ���������� ��� ��������� ���������� ���������� ������� WM_CHAR. �����
|
|
|
|
// ������������ ��� ��������� �����
|
|
|
|
//---------------------------------------------------------------------------
|
2009-08-06 14:32:07 +00:00
|
|
|
property OnColAdjust: TOnColAdjust read FOnColAdjust write fOnColAdjust;
|
|
|
|
{*
|
|
|
|
|<p>
|
|
|
|
���������� ��� �������� ����������� ���������. (�������� ��� �������
|
|
|
|
�������). ������������ ��� ������� ��������� ���������.
|
|
|
|
|
|
|
|
|</p>
|
|
|
|
}
|
|
|
|
property CurIdx: Integer read fCurIdx write SetCurIdx;
|
|
|
|
{*
|
|
|
|
|<p>
|
|
|
|
������������� ����� �� ��������� �������.
|
|
|
|
|</p>
|
|
|
|
}
|
2017-01-12 12:59:05 +00:00
|
|
|
property OnCreateEdit: TOnCreateEdit read FOnCreateEdit write FOnCreateEdit;
|
2009-08-06 14:32:07 +00:00
|
|
|
{* ���������� ��� �������� ��������� ������. ����� �������������� ���
|
|
|
|
���������� ����������� EditBox-� ������� ������������. }
|
|
|
|
|
|
|
|
property OnDrawCell: TOnDrawCell read FOnDrawCell write FOnDrawCell;
|
|
|
|
{*
|
|
|
|
|<p>
|
|
|
|
��������� ����������� ����������� ��������� ����� (�� � ������ ��������������)
|
|
|
|
���������� �������� ��� ������ ������. ���� ���������� ���������� False - ������
|
|
|
|
�������� ����������.
|
|
|
|
|</p>
|
|
|
|
}
|
|
|
|
end;
|
|
|
|
// mck class
|
|
|
|
TKOLEcmListEdit = PControl;
|
|
|
|
|
|
|
|
function NewEcmListEdit(AParent: PControl; Style: TListViewStyle; Options: TListViewOptions; ImageListSmall, ImageListNormal, ImageListState: PImageList): PControl;
|
|
|
|
function WndProcEcmListEdit(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
|
|
|
|
function WndProcListViewWOResizeFlicks(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
const
|
|
|
|
LEN_COL_ADJUST = WM_USER + 223;
|
|
|
|
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
procedure AddLog(Addr: Pointer; const S: string);
|
|
|
|
var
|
|
|
|
TS: TSystemTime;
|
|
|
|
SS: String;
|
|
|
|
begin
|
|
|
|
GetSystemTime(TS);
|
|
|
|
SS := Format(' %2d:%.2d:%.2d:%.3d | %.8x ', [TS.wHour, TS.wMinute, TS.wSecond, TS.wMilliseconds, Integer(Addr)]);
|
|
|
|
LogFileOutput('.\LE_Log.txt', SS + S);
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
function WndProcEcmListEdit(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
|
|
|
|
var
|
|
|
|
R: TRect;
|
|
|
|
NMhdr: PNMHdr;
|
|
|
|
NewLine: Integer;
|
|
|
|
NewCurIdx: Integer;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
with PEcmListEdit(Sender.CustomObj)^ do begin
|
|
|
|
case Msg.message of
|
|
|
|
LVM_INSERTCOLUMNA, LVM_INSERTCOLUMNW, LVM_DELETECOLUMN:
|
2017-09-20 09:42:57 +00:00
|
|
|
begin
|
2009-08-06 14:32:07 +00:00
|
|
|
PostMessage(Msg.hwnd, LEN_COL_ADJUST, 0, 0);
|
2017-09-20 09:42:57 +00:00
|
|
|
end;
|
2009-08-06 14:32:07 +00:00
|
|
|
LEN_COL_ADJUST:
|
2017-09-20 09:42:57 +00:00
|
|
|
begin
|
2009-08-06 14:32:07 +00:00
|
|
|
DoColAdjust(Sender.LVColCount);
|
2017-09-20 09:42:57 +00:00
|
|
|
end;
|
2009-08-06 14:32:07 +00:00
|
|
|
WM_LBUTTONDOWN{$IFDEF rbutton_sel}, WM_RBUTTONDOWN{$ENDIF}:
|
|
|
|
begin
|
|
|
|
NewLine := GetLVItemAtPos(TSmallPoint(Msg.lParam), NewCurIdx);
|
|
|
|
SetCurLVPos(NewLine, NewCurIdx);
|
|
|
|
Sender.Focused := True;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
WM_LBUTTONDBLCLK{$IFDEF rbutton_sel}, WM_RBUTTONDBLCLK{$ENDIF}:
|
|
|
|
begin
|
|
|
|
NewLine := GetLVItemAtPos(TSmallPoint(Msg.lParam), NewCurIdx);
|
|
|
|
SetCurLVPos(NewLine, NewCurIdx);
|
2017-09-20 09:42:57 +00:00
|
|
|
if (NewLine <> -1) and (NewCurIdx <> -1) then
|
|
|
|
StartEdit;
|
2009-08-06 14:32:07 +00:00
|
|
|
Sender.Tabstop := False;
|
2017-09-20 09:42:57 +00:00
|
|
|
Result := True;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
WM_KEYDOWN:
|
|
|
|
begin
|
|
|
|
if (Msg.WParam = VK_RETURN) then
|
|
|
|
StartEdit
|
|
|
|
else begin
|
|
|
|
case Msg.WParam of
|
|
|
|
VK_LEFT, VK_RIGHT:
|
|
|
|
begin
|
|
|
|
SetCurLVPos(Sender.LVCurItem, fCurIdx + Msg.wParam - 38);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
SetEditPos;
|
|
|
|
end;
|
|
|
|
end;
|
2017-09-20 09:42:57 +00:00
|
|
|
WM_CHAR: // by SeM
|
|
|
|
begin
|
|
|
|
if (GetKeyState(VK_CONTROL) >= 0) then begin // ! by Matveev Dmitry
|
|
|
|
case Msg.wParam of
|
|
|
|
VK_ESCAPE, VK_RETURN, VK_TAB:
|
|
|
|
;
|
|
|
|
else begin
|
|
|
|
StartEdit;
|
|
|
|
Sender.Tabstop := False;
|
|
|
|
if Assigned(fInPlaceEd) then
|
|
|
|
fInPlaceEd.Postmsg(Msg.message, Msg.wParam, Msg.lParam);
|
|
|
|
Result := True;
|
|
|
|
end;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
WM_NCPAINT, WM_PAINT:
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Sender, 'ListEdit:WM_PAINT');
|
|
|
|
{$ENDIF}
|
|
|
|
SetEditPos();
|
|
|
|
end;
|
|
|
|
// �����-�� ���� � ����������� ����� � ������ lvoGridLines ��� �������������
|
|
|
|
// ���� XP - ��� ��������� ScrollBar(������ �������� "�����","����") ����������
|
|
|
|
// ������ ���������� ����� - � ���������� �������� ������ ���������� ��������������
|
|
|
|
// ���� "������" ��������� ������ ���������� ��������
|
|
|
|
// ���� ��� ����� ��� ��������� - �������� ��� ...
|
|
|
|
WM_VSCROLL:
|
|
|
|
begin
|
|
|
|
if (Msg.wParam = SB_ENDSCROLL) then begin
|
|
|
|
InvalidateRect(fOwner.Handle, nil, True);
|
|
|
|
UpdateWindow(fOwner.Handle);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
WM_NOTIFY:
|
|
|
|
begin
|
|
|
|
NMHdr := Pointer(Msg.lParam);
|
|
|
|
case NMHdr.code of
|
|
|
|
NM_KILLFOCUS:
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Sender, 'ListEdit:NM_KILLFOCUS');
|
|
|
|
{$ENDIF}
|
2017-09-20 09:42:57 +00:00
|
|
|
R := fOwner.ClientRect;
|
|
|
|
InvalidateRect(fOwner.Handle, @R, False); //UpdateRow(fCurLine);
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
NM_SETFOCUS:
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Sender, 'ListEdit:NM_SETFOCUS');
|
|
|
|
{$ENDIF}
|
|
|
|
//SetCurLVPos(fOwner.LVCurItem,fCurIdx);
|
|
|
|
end;
|
|
|
|
LVN_ITEMCHANGED:
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Sender, 'ListEdit:LVN_ITEMCHANGED');
|
|
|
|
{$ENDIF}
|
2010-03-18 18:37:07 +00:00
|
|
|
if (fCurLine <> fOwner.LVCurItem) then
|
|
|
|
SetCurLVPos(fOwner.LVCurItem, fCurIdx);
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
//by Matveev Dmitry
|
|
|
|
function WndProcInPlaceEd(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
|
|
|
|
var
|
|
|
|
pLE: PEcmListEdit;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
case Msg.message of
|
|
|
|
WM_KEYDOWN:
|
|
|
|
begin
|
2017-09-20 09:42:57 +00:00
|
|
|
if (Msg.wParam = VK_ESCAPE) then
|
2009-08-06 14:32:07 +00:00
|
|
|
PEcmListEdit(Sender.Parent.CustomObj).StopEdit(False);
|
|
|
|
end;
|
|
|
|
WM_KILLFOCUS:
|
|
|
|
begin
|
|
|
|
pLE := PEcmListEdit(Sender.Parent.CustomObj);
|
2010-03-18 18:37:07 +00:00
|
|
|
if Assigned(pLE) then begin
|
2017-09-20 09:42:57 +00:00
|
|
|
if pLE.fEmbedEd and pLE.fAutoHide then begin
|
|
|
|
pLE.InternalStopEdit(True);
|
|
|
|
pLE.HideInPlaceEd(True);
|
|
|
|
end;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
2017-09-20 09:42:57 +00:00
|
|
|
WM_CHAR: //+dufa
|
2009-08-06 14:32:07 +00:00
|
|
|
if (Msg.wParam = VK_RETURN) then begin
|
|
|
|
Msg.message := WM_KILLFOCUS;
|
|
|
|
WndProcInPlaceEd(Sender, Msg, Rslt);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2017-09-20 09:42:57 +00:00
|
|
|
// ��������� � ������� ������� ���������� �� ������� "��������" ��� ���������
|
2009-08-06 14:32:07 +00:00
|
|
|
// ��������. ����� �������������� ��� ������������ KOLListView.
|
|
|
|
// ��� ���������� ����� �������� ListView-� (ListEdit-�) ���������� ������������
|
|
|
|
// ������ ������� ������� ListViewXXX.AttachProc(@WndProcListViewWOResizeFlicks);
|
|
|
|
function WndProcListViewWOResizeFlicks(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
|
|
|
|
var
|
|
|
|
rUnder: TRect;
|
|
|
|
rRight: TRect;
|
|
|
|
rClient: TRect;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if (Msg.message = WM_ERASEBKGND) then begin
|
|
|
|
rClient := Sender.ClientRect;
|
|
|
|
if (Sender.LVCount > 0) then begin
|
|
|
|
rUnder := Sender.LVSubItemRect(Sender.LVCount - 1, 0);
|
|
|
|
rUnder.Top := rUnder.Bottom;
|
|
|
|
rUnder.Bottom := rClient.Bottom;
|
|
|
|
rRight.Left := rUnder.Right;
|
|
|
|
rRight.Right := rClient.Right;
|
|
|
|
rRight.Top := rClient.Top;
|
|
|
|
rRight.Bottom := rClient.Bottom;
|
|
|
|
FillRect(Msg.wParam, rRight, Sender.Canvas.Brush.Handle);
|
|
|
|
end else
|
|
|
|
rUnder := rClient;
|
2017-09-20 09:42:57 +00:00
|
|
|
|
2009-08-06 14:32:07 +00:00
|
|
|
FillRect(Msg.wParam, rUnder, Sender.Canvas.Brush.Handle);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// PEcmListEdit
|
|
|
|
|
|
|
|
function NewEcmListEdit;
|
|
|
|
var
|
|
|
|
pLD: PEcmListEdit;
|
|
|
|
mOpt: TListViewOptions;
|
|
|
|
begin
|
|
|
|
mOpt := Options + [lvoHideSel, lvoOwnerDrawFixed];
|
2017-09-20 09:42:57 +00:00
|
|
|
if ((Style <> lvsDetail) and (Style <> lvsDetailNoHeader)) then
|
|
|
|
Style := lvsDetail;
|
|
|
|
|
2009-08-06 14:32:07 +00:00
|
|
|
Result := NewListView(AParent, Style, mOpt, ImageListSmall, ImageListNormal, ImageListState);
|
|
|
|
New(pLD, Create);
|
|
|
|
pLD.fOwner := Result;
|
|
|
|
pLD.fEmbedEd := False;
|
|
|
|
pLD.fColOptions := NewList;
|
|
|
|
pLD.fCurLine := -1;
|
|
|
|
Result.CustomObj := pLD;
|
|
|
|
Result.OnDrawItem := pLD.LVDrawItem;
|
|
|
|
Result.AttachProc(WndProcEcmListEdit);
|
|
|
|
Result.AttachProc(WndProcListViewWOResizeFlicks); //beta, �� �� ���� �����
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TEcmListEdit.Destroy;
|
|
|
|
begin
|
|
|
|
InternalStopEdit(False);
|
|
|
|
fColOptions.Release;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.ComboBox_CloseUp(Sender: PObj);
|
|
|
|
begin
|
|
|
|
StopEdit(True);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.EditOnKeyDown(Sender: PControl; var Key: Longint; Shift: DWORD);
|
|
|
|
begin
|
|
|
|
if (fScroll <> 0) then
|
2017-09-20 09:42:57 +00:00
|
|
|
fOwner.Postmsg(LVM_SCROLL, fScroll, 0);
|
|
|
|
|
2009-08-06 14:32:07 +00:00
|
|
|
case key of
|
|
|
|
// VK_RETURN:
|
|
|
|
// StoreEditValues;
|
|
|
|
// VK_ESCAPE: StopEdit(False);
|
|
|
|
VK_UP, VK_DOWN:
|
|
|
|
begin
|
|
|
|
SetCurLVPos(fCurLine + (Key - 39), fCurIdx);
|
|
|
|
Key := 0;
|
|
|
|
end;
|
|
|
|
VK_LEFT:
|
|
|
|
if (Sender.SelStart = 0) and (Sender.SelLength = 0) and (fCurIdx > 0) then begin
|
|
|
|
SetCurLVPos(fCurLine, fCurIdx - 1);
|
|
|
|
Key := 0;
|
|
|
|
end;
|
|
|
|
VK_RIGHT:
|
|
|
|
if (Sender.SelStart = Length(Sender.Text)) and (fCurIdx < fOwner.LVColCount - 1) then begin
|
|
|
|
SetCurLVPos(fCurLine, fCurIdx + 1);
|
|
|
|
Key := 0;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.DestroyInPlaceEditor;
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'DestroyInPlaceEditor');
|
|
|
|
{$ENDIF}
|
|
|
|
if fEmbedEd and Assigned(fInPlaceEd) then
|
2017-09-20 09:42:57 +00:00
|
|
|
Free_And_Nil(fInPlaceEd);
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.SetEditPos;
|
|
|
|
var
|
|
|
|
R, Re: TRect;
|
|
|
|
cw: Integer;
|
|
|
|
pEO: PEditorOptions;
|
|
|
|
Header: THandle;
|
|
|
|
HeaderHeight: Integer;
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'SetEditPos');
|
|
|
|
{$ENDIF}
|
2017-03-17 05:02:39 +00:00
|
|
|
R := fOwner.LVSubItemRect(fOwner.LVCurItem, fCurIdx);
|
|
|
|
cw := fOwner.LVColWidth[fCurIdx];
|
|
|
|
R.Right := R.Left + cw;
|
|
|
|
if Assigned(fInPlaceEd) then begin
|
|
|
|
Header := fOwner.Perform(LVM_GETHEADER, 0, 0);
|
|
|
|
GetWindowRect(Header, Re);
|
|
|
|
HeaderHeight := Re.Bottom - Re.Top;
|
|
|
|
if (R.Top >= HeaderHeight) then begin
|
2017-09-20 09:42:57 +00:00
|
|
|
if fEmbedEd and (fInPlaceEd.Perform(EM_GETRECT, 0, LPARAM(@Re)) > 0) then begin
|
2017-03-17 05:02:39 +00:00
|
|
|
if (R.Bottom - R.Top) > (Re.Bottom - Re.Top) then begin
|
|
|
|
cw := ((R.Bottom - R.Top) - (Re.Bottom - Re.Top)) div 2;
|
|
|
|
Inc(R.Top, cw);
|
|
|
|
Dec(R.Bottom, cw);
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
2017-09-20 09:42:57 +00:00
|
|
|
Inc(R.Left, fShift - Re.Left);
|
2017-03-17 05:02:39 +00:00
|
|
|
Dec(R.Right, fShift - Re.Left);
|
|
|
|
end;
|
|
|
|
pEO := fColOptions.Items[fCurIdx];
|
|
|
|
with pEO.Indent do begin
|
|
|
|
Inc(R.Left, Left);
|
|
|
|
Dec(R.Right, Right);
|
|
|
|
Inc(R.Top, Top);
|
|
|
|
Dec(R.Bottom, Bottom);
|
2017-09-20 09:42:57 +00:00
|
|
|
if fEmbedEd then //?
|
2017-03-17 05:02:39 +00:00
|
|
|
Dec(R.Left, 2);
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
FillChar(R, SizeOf(R), 0);
|
|
|
|
|
|
|
|
// for listview
|
|
|
|
if (fInPlaceEd.SubClassName = 'obj_SysListView32') then
|
2017-05-13 15:07:19 +00:00
|
|
|
R.Bottom := R.Bottom + (R.Bottom - R.Top) * 7;
|
2017-03-17 05:02:39 +00:00
|
|
|
|
|
|
|
// set rect
|
|
|
|
fInPlaceEd.BoundsRect := R;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
2017-03-17 05:02:39 +00:00
|
|
|
if (R.Left <= 0) then
|
|
|
|
fScroll := R.Left
|
|
|
|
else if (R.Right > fOwner.Width - 24) then
|
|
|
|
fScroll := R.Right - (fOwner.Width - 24)
|
|
|
|
else
|
|
|
|
fScroll := 0;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.LoadEditValues;
|
|
|
|
var
|
2017-03-17 05:02:39 +00:00
|
|
|
i: Integer;
|
2017-09-20 09:42:57 +00:00
|
|
|
S: KOLString;
|
|
|
|
V: KOLString;
|
2009-08-06 14:32:07 +00:00
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'LoadEditValues');
|
|
|
|
{$ENDIF}
|
2017-01-12 12:59:05 +00:00
|
|
|
S := fOwner.LVItems[fOwner.LVCurItem, fCurIdx];
|
|
|
|
if Assigned(fOnGetText) then
|
|
|
|
fOnGetText(fOwner, fCurIdx, fOwner.LVCurItem, S);
|
|
|
|
|
|
|
|
if IsComboEditor then begin
|
2017-03-17 05:02:39 +00:00
|
|
|
IsComboEditor := False;
|
2017-01-12 12:59:05 +00:00
|
|
|
fInPlaceEd.CurIndex := fInPlaceEd.IndexOf(S);
|
2017-09-20 09:42:57 +00:00
|
|
|
//fInPlaceEd.DroppedDown := True; <-- unfortunly don'work... combobox force close after open
|
2017-01-12 12:59:05 +00:00
|
|
|
end else begin //if fEmbedEd then begin
|
|
|
|
if (fInPlaceEd.SubClassName = 'obj_COMBOBOX') then begin
|
2017-03-17 05:02:39 +00:00
|
|
|
i := fInPlaceEd.IndexOf(S);
|
|
|
|
if (i = -1) then
|
2017-01-12 12:59:05 +00:00
|
|
|
fInPlaceEd.Text := S
|
|
|
|
else
|
2017-03-17 05:02:39 +00:00
|
|
|
fInPlaceEd.CurIndex := i;
|
|
|
|
end else if (fInPlaceEd.SubClassName = 'obj_SysListView32') then begin
|
|
|
|
fInPlaceEd.LVItemStateImgIdx[-1] := 1;
|
|
|
|
repeat
|
|
|
|
V := Parse(S, INPLACE_ITEMS_SEP);
|
|
|
|
if (V = '') and (S = '') then
|
|
|
|
Break;
|
|
|
|
// set flag
|
|
|
|
i := fInPlaceEd.LVIndexOf(V);
|
|
|
|
if (i > -1) then
|
|
|
|
fInPlaceEd.LVItemStateImgIdx[i] := 2;
|
|
|
|
until False;
|
2017-01-12 12:59:05 +00:00
|
|
|
end else begin // 'obj_EDIT'
|
|
|
|
fInPlaceEd.Text := S;
|
|
|
|
fInPlaceEd.SelectAll;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TEcmListEdit.NewInPlaceEdit(Options: TEditOptions; Align: TTextAlign): PControl;
|
|
|
|
var
|
|
|
|
RO: Boolean; // readonly
|
|
|
|
AH: Boolean; // autohide
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
RO := False;
|
|
|
|
AH := True;
|
|
|
|
if Assigned(FOnCreateEdit) then
|
|
|
|
FOnCreateEdit(fOwner, fCurIdx, Result, RO, AH);
|
|
|
|
|
|
|
|
if not RO then begin
|
|
|
|
fEmbedEd := not Assigned(Result);
|
|
|
|
if fEmbedEd then begin
|
|
|
|
if IsComboEditor then begin
|
|
|
|
Result := NewCombobox(fOwner, ComboOptions);
|
|
|
|
Result.OnCloseUp := ComboBox_CloseUp;
|
|
|
|
repeat
|
2017-03-17 05:02:39 +00:00
|
|
|
Result.Add(Parse(ComboText, INPLACE_ITEMS_SEP));
|
2017-01-12 12:59:05 +00:00
|
|
|
until (ComboText = '');
|
|
|
|
end else
|
|
|
|
Result := NewEditBox(fOwner, Options);
|
|
|
|
Result.Font.Assign(fOwner.Font);
|
|
|
|
Result.Color := fOwner.LVTextBkColor;
|
|
|
|
Result.ExStyle := Result.ExStyle and not (WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE or WS_EX_CLIENTEDGE);
|
|
|
|
Result.OnKeyDown := EditOnKeyDown;
|
|
|
|
Result.AttachProc(WndProcInPlaceEd); //by Matveev Dmitry
|
|
|
|
end else begin
|
2017-09-20 09:42:57 +00:00
|
|
|
Result.Parent := fOwner;
|
2017-01-12 12:59:05 +00:00
|
|
|
//Result.Focused := True;
|
|
|
|
Result.Visible := True;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
2017-01-12 12:59:05 +00:00
|
|
|
//Result.Tabstop := True;
|
|
|
|
fAutoHide := AH;
|
|
|
|
Result.OnChar := EditOnChar;
|
|
|
|
Result.TabOrder := fOwner.TabOrder;
|
|
|
|
Result.TextAlign := Align;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.StartEdit;
|
|
|
|
var
|
|
|
|
pEO: PEditorOptions;
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'StartEdit');
|
|
|
|
{$ENDIF}
|
2017-09-20 09:42:57 +00:00
|
|
|
if (fOwner.LVColCount = 0) or (fOwner.LVCount = 0) or fStarted or (fCurIdx = -1) then
|
|
|
|
Exit;
|
|
|
|
|
2009-08-06 14:32:07 +00:00
|
|
|
fCurLine := fOwner.LVCurItem;
|
|
|
|
if (fCurLine = -1) then begin
|
2017-09-20 09:42:57 +00:00
|
|
|
fCurLine := 0;
|
2009-08-06 14:32:07 +00:00
|
|
|
fOwner.LVCurItem := 0;
|
|
|
|
end;
|
2017-09-20 09:42:57 +00:00
|
|
|
|
2009-08-06 14:32:07 +00:00
|
|
|
if not fStarted then begin
|
|
|
|
DestroyInPlaceEditor;
|
|
|
|
if (fOwner.LVColCount > 0) then begin
|
2017-09-20 09:42:57 +00:00
|
|
|
pEO := fColOptions.Items[fCurIdx];
|
2017-01-12 12:59:05 +00:00
|
|
|
fInPlaceEd := NewInPlaceEdit(pEO.Options, pEO.TextAlign);
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
2017-09-20 09:42:57 +00:00
|
|
|
|
2009-08-06 14:32:07 +00:00
|
|
|
if Assigned(fInPlaceEd) then begin
|
|
|
|
fStarted := True;
|
|
|
|
SetEditPos;
|
|
|
|
LoadEditValues;
|
2017-09-20 09:42:57 +00:00
|
|
|
fOwner.Tabstop := False;
|
2009-08-06 14:32:07 +00:00
|
|
|
fInPlaceEd.Visible := True;
|
|
|
|
fInPlaceEd.Focused := True;
|
|
|
|
UpdateRow(fCurLine);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.StopEdit(Store: Boolean);
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'StopEdit: ' + Int2Str(Integer(Store)));
|
|
|
|
{$ENDIF}
|
|
|
|
InternalStopEdit(Store);
|
|
|
|
HideInPlaceEd(True);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TEcmListEdit.GetLVItemAtPos(Pt: TSmallPoint; var SubItem: Integer): Integer;
|
|
|
|
var
|
|
|
|
HTI: TLVHitTestInfo;
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'GetLVItemAtPos: ' + Int2Str(SubItem));
|
|
|
|
{$ENDIF}
|
|
|
|
HTI.pt.x := Pt.X;
|
|
|
|
HTI.pt.y := Pt.Y;
|
|
|
|
fOwner.Perform(LVM_SUBITEMHITTEST, 0, Integer(@HTI));
|
2017-09-20 09:42:57 +00:00
|
|
|
Result := HTI.iItem;
|
2009-08-06 14:32:07 +00:00
|
|
|
SubItem := HTI.iSubItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.EditOnChar(Sender: PControl; var Key: KOLChar; Shift: DWORD);
|
|
|
|
begin
|
|
|
|
case Key of
|
|
|
|
#13:
|
|
|
|
begin
|
|
|
|
StopEdit(True);
|
|
|
|
Key := #0
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Assigned(fOnEditChar) then begin
|
2017-09-20 09:42:57 +00:00
|
|
|
// BackSpace! - ������ ������������
|
|
|
|
if (Key <> #08) then // wtf? backspace is 9!
|
2009-08-06 14:32:07 +00:00
|
|
|
fOnEditChar(fInPlaceEd, fCurIdx, fOwner.LVCurItem, Key, Shift);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TEcmListEdit.LVDrawItem(Sender: PObj; DC: HDC; const Rect: TRect; ItemIdx: Integer; DrawAction: TDrawAction; ItemState: TDrawState): Boolean;
|
|
|
|
var
|
|
|
|
fBr: HBRUSH;
|
|
|
|
cBr: TColor;
|
|
|
|
i: Integer;
|
2017-09-20 09:42:57 +00:00
|
|
|
S: KOLString;
|
2009-08-06 14:32:07 +00:00
|
|
|
P: TPoint;
|
|
|
|
R: TRect;
|
|
|
|
dt: DWORD;
|
|
|
|
pEO: PEditorOptions;
|
|
|
|
begin
|
2017-09-20 09:42:57 +00:00
|
|
|
fShift := 0;
|
|
|
|
for i := 0 to fOwner.LVColCount - 1 do begin
|
|
|
|
R := fOwner.LVSubItemRect(ItemIdx, i);
|
|
|
|
P := fOwner.LVItemPos[i];
|
|
|
|
if (i = 0) then begin
|
|
|
|
R.Right := R.Left + fOwner.LVColWidth[0];
|
|
|
|
fShift := P.X - R.Left + 1; // dufa. 9.05.13, ������ ���� 2. � 1 ����� ListView + LVSCW_AUTOSIZE �������� ��� ����;
|
|
|
|
end;
|
|
|
|
if (fOwner.Perform(LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0) and LVS_EX_GRIDLINES) <> 0 then begin
|
|
|
|
Inc(R.Left);
|
|
|
|
Dec(R.Bottom);
|
|
|
|
end;
|
|
|
|
if Assigned(FOnDrawCell) then
|
|
|
|
if FOnDrawCell(Sender, DC, R, i, ItemIdx, DrawAction, ItemState) then Continue; //by Matveev Dmitry
|
2009-08-06 14:32:07 +00:00
|
|
|
|
2017-09-20 09:42:57 +00:00
|
|
|
if fOwner.Enabled then
|
|
|
|
cBr := fOwner.LVTextBkColor
|
|
|
|
else
|
|
|
|
cBr := clBtnFace;
|
|
|
|
|
|
|
|
if (ItemIdx = fCurLine) then begin
|
|
|
|
if (fOwner.Focused or (Assigned(fInPlaceEd) and fInPlaceEd.Visible)) and fOwner.Enabled then begin
|
|
|
|
if (i = fCurIdx) then begin
|
|
|
|
if fStarted then
|
|
|
|
cBr := fOwner.LVTextBkColor
|
|
|
|
else
|
|
|
|
cBr := clHighlight;
|
|
|
|
SetTextColor(DC, Color2RGB(clHighlightText));
|
|
|
|
end else begin
|
|
|
|
if (fOwner.Perform(LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0) and LVS_EX_FULLROWSELECT) <> 0 then
|
|
|
|
cBr := $F3E6CD;
|
|
|
|
SetTextColor(DC, Color2RGB(fOwner.Font.Color));
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
SetTextColor(DC, Color2RGB(fOwner.Font.Color));
|
|
|
|
if fOwner.Enabled then begin
|
2009-08-06 14:32:07 +00:00
|
|
|
if (i = fCurIdx) then begin
|
|
|
|
if fStarted then
|
|
|
|
cBr := fOwner.LVTextBkColor
|
|
|
|
else
|
2017-09-20 09:42:57 +00:00
|
|
|
cBr := clInactiveBorder;
|
2009-08-06 14:32:07 +00:00
|
|
|
end else begin
|
2017-09-20 09:42:57 +00:00
|
|
|
cBr := $F0F0F0;
|
2009-08-06 14:32:07 +00:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
end;
|
2017-09-20 09:42:57 +00:00
|
|
|
end else
|
|
|
|
SetTextColor(DC, Color2RGB(fOwner.Font.Color));
|
|
|
|
|
|
|
|
fBr := CreateSolidBrush(Color2RGB(cBr));
|
|
|
|
FillRect(DC, R, fBr);
|
|
|
|
DeleteObject(fBr);
|
|
|
|
|
|
|
|
if not ((ItemIdx = fOwner.LVCurItem) and (fStarted) and (i = fCurIdx)) then begin
|
|
|
|
S := fOwner.LVItems[ItemIdx, i];
|
|
|
|
dt := DT_END_ELLIPSIS or DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX;
|
|
|
|
|
|
|
|
if (fColOptions.Count <> fOwner.LVColCount) then
|
|
|
|
DoColAdjust(fOwner.LVColCount);
|
|
|
|
pEO := fColOptions.Items[i];
|
|
|
|
case pEO.TextAlign of
|
|
|
|
taRight: dt := dt or DT_RIGHT;
|
|
|
|
taCenter: dt := dt or DT_CENTER;
|
|
|
|
end;
|
|
|
|
Dec(R.Right, fShift);
|
|
|
|
Inc(R.Left, fShift);
|
|
|
|
DrawText(DC, @S[1], Length(S), R, dt);
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.DoColAdjust(ColCount: Integer);
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
pEO: PEditorOptions;
|
|
|
|
begin
|
|
|
|
if (ColCount <> fColOptions.Count) then begin
|
2017-09-20 09:42:57 +00:00
|
|
|
//for i := fColOptions.Count - 1 downto 0 do // downto - for what?
|
|
|
|
// FreeMem(fColOptions.Items[i]);
|
|
|
|
//fColOptions.Clear;
|
|
|
|
fColOptions.ReleaseItems;
|
2009-08-06 14:32:07 +00:00
|
|
|
|
2017-09-20 09:42:57 +00:00
|
|
|
for i := 0 to Pred(ColCount) do begin
|
2009-08-06 14:32:07 +00:00
|
|
|
New(pEO);
|
|
|
|
ZeroMemory(pEO, SizeOf(TEditorOptions));
|
|
|
|
pEO.TextAlign := fOwner.LVColAlign[i];
|
|
|
|
if Assigned(fOnColAdjust) then
|
|
|
|
fOnColAdjust(fOwner, i, pEO^);
|
|
|
|
fColOptions.Add(pEO);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.SetCurLVPos(ALine, AIdx: Integer);
|
|
|
|
var
|
|
|
|
NewIdx: Integer;
|
|
|
|
begin
|
|
|
|
// NewIdx := AIdx;
|
|
|
|
with fOwner^ do begin
|
|
|
|
// if (ALine = LVCurItem) and (AIdx = fCurIdx) then Exit;
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'SetCurLVPos: ' + Int2Str(ALine) + ',' + Int2Str(AIdx));
|
|
|
|
{$ENDIF}
|
|
|
|
if (AIdx >= 0) and (AIdx < LVColCount) and (ALine >= 0) and (ALine < LVCount) then
|
|
|
|
NewIdx := AIdx
|
|
|
|
else
|
|
|
|
NewIdx := fCurIdx;
|
|
|
|
InternalStopEdit(True);
|
|
|
|
|
|
|
|
fCurIdx := NewIdx;
|
|
|
|
if (ALine >= 0) and (ALine < LVCount) then begin
|
|
|
|
if ALine <> LVCurItem then begin
|
|
|
|
NewIdx := LVCurItem;
|
|
|
|
LVCurItem := ALine;
|
|
|
|
UpdateRow(NewIdx);
|
|
|
|
end;
|
|
|
|
fCurLine := LVCurItem;
|
|
|
|
end;
|
|
|
|
HideInPlaceEd(True);
|
|
|
|
SetEditPos;
|
|
|
|
if (fScroll <> 0) then
|
|
|
|
PostMessage(Handle, LVM_SCROLL, fScroll, 0);
|
|
|
|
|
|
|
|
if (ALine <> -1) then
|
|
|
|
PostMessage(Handle, LVM_ENSUREVISIBLE, fCurLine, 0);
|
|
|
|
|
|
|
|
UpdateRow(fCurLine);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.InternalStopEdit(const Store: Boolean);
|
|
|
|
var
|
2017-03-17 05:02:39 +00:00
|
|
|
i: Integer;
|
2017-09-20 09:42:57 +00:00
|
|
|
newValue: KOLString;
|
2009-08-06 14:32:07 +00:00
|
|
|
fCellChanged: Boolean;
|
|
|
|
begin
|
|
|
|
if fStarted then begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'InternalStopEdit: ' + Int2Str(Integer(Store)));
|
|
|
|
{$ENDIF}
|
|
|
|
fCellChanged := False;
|
|
|
|
if Store then begin
|
2017-03-17 05:02:39 +00:00
|
|
|
// get new value for listview
|
|
|
|
if (fInPlaceEd.SubClassName = 'obj_SysListView32') then begin
|
|
|
|
newValue := '';
|
|
|
|
for I := 0 to Pred(fInPlaceEd.LVCount) do begin
|
|
|
|
if (fInPlaceEd.LVItemStateImgIdx[I] = 2) then begin
|
|
|
|
if (newValue <> '') then
|
|
|
|
newValue := newValue + INPLACE_ITEMS_SEP;
|
|
|
|
newValue := newValue + fInPlaceEd.LVItems[I, 0];
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end else // get new value other
|
|
|
|
newValue := fInPlaceEd.Text;
|
|
|
|
|
|
|
|
// compare new with old
|
|
|
|
if (fOwner.LVItems[fOwner.LVCurItem, fCurIdx] <> newValue) then begin
|
2017-01-12 12:59:05 +00:00
|
|
|
if Assigned(fOnPutText) then
|
2017-03-17 05:02:39 +00:00
|
|
|
fOnPutText(fOwner, fCurIdx, fOwner.LVCurItem, newValue);
|
|
|
|
|
|
|
|
if (fOwner.LVItems[fOwner.LVCurItem, fCurIdx] <> newValue) then begin
|
2017-01-12 12:59:05 +00:00
|
|
|
fCellChanged := True;
|
2017-03-17 05:02:39 +00:00
|
|
|
fOwner.LVItems[fOwner.LVCurItem, fCurIdx] := newValue;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
2017-03-17 05:02:39 +00:00
|
|
|
|
|
|
|
fInPlaceEd.Text := newValue;
|
2009-08-06 14:32:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
fStarted := False;
|
|
|
|
if Assigned(fOnEndEdit) then
|
|
|
|
fOnEndEdit(fOwner, fCurIdx, fOwner.LVCurItem, fCellChanged);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.HideInplaceEd(ActivateOwner: Boolean);
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'HideInplaceEd: ' + Int2Str(Integer(ActivateOwner)));
|
|
|
|
{$ENDIF}
|
|
|
|
if Assigned(fInPlaceEd) then begin
|
|
|
|
// fInPlaceEd.Tabstop := False;
|
|
|
|
fOwner.TabOrder := fInPlaceEd.TabOrder;
|
|
|
|
{if ActivateOwner then }fOwner.Focused := True;
|
|
|
|
fOwner.Tabstop := True;
|
|
|
|
fInPlaceEd.Visible := False;
|
|
|
|
UpdateRow(fCurLine);
|
|
|
|
//fOwner.Invalidate;
|
|
|
|
end;
|
|
|
|
//if fInPlaceEd <> nil then DestroyInPlaceEditor();
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.SetCurIdx(const Value: Integer);
|
|
|
|
begin
|
|
|
|
fOwner.Focused := True;
|
|
|
|
SetCurLVPos(fOwner.LVCurItem, Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.SelectCell(ACol, ARow: Integer);
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'SelectCell: ' + Int2Str(ACol) + ',' + Int2Str(ARow));
|
|
|
|
{$ENDIF}
|
|
|
|
fOwner.Focused := True;
|
|
|
|
SetCurLVPos(ARow, ACol);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TEcmListEdit.UpdateRow(ARow: Integer);
|
|
|
|
var
|
|
|
|
R: TRect;
|
|
|
|
begin
|
|
|
|
{$IFDEF _LE_DEBUG_}
|
|
|
|
AddLog(Self.fOwner, 'UpdateRow": ' + Int2Str(ARow));
|
|
|
|
{$ENDIF}
|
|
|
|
R := fOwner.LVSubItemRect(ARow, 0);
|
|
|
|
InvalidateRect(fOwner.Handle, @R, False);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2017-01-12 12:59:05 +00:00
|
|
|
end.
|