diff --git a/lcl/interfaces/wince/wincewscomctrls.pp b/lcl/interfaces/wince/wincewscomctrls.pp index 24a88aeb81..d49a9daec2 100644 --- a/lcl/interfaces/wince/wincewscomctrls.pp +++ b/lcl/interfaces/wince/wincewscomctrls.pp @@ -99,6 +99,8 @@ type // items class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override; class function ItemDisplayRect(const ALV: TCustomListView; const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect; override; + class procedure ItemExchange(const ALV: TCustomListView; AItem: TListItem; const AIndex1, AIndex2: Integer); override; + class procedure ItemMove(const ALV: TCustomListView; AItem: TListItem; const AFromIndex, AToIndex: Integer); override; class function ItemGetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem): Boolean; override; class function ItemGetPosition(const ALV: TCustomListView; const AIndex: Integer): TPoint; override; class function ItemGetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported diff --git a/lcl/interfaces/wince/wincewscustomlistview.inc b/lcl/interfaces/wince/wincewscustomlistview.inc index f2dc4ebb51..445d5c258b 100644 --- a/lcl/interfaces/wince/wincewscustomlistview.inc +++ b/lcl/interfaces/wince/wincewscustomlistview.inc @@ -313,6 +313,68 @@ begin SendMessage(ALV.Handle, mes, AIndex, lparam(@Result)); end; +class procedure TWinCEWSCustomListView.ItemExchange(const ALV: TCustomListView; + AItem: TListItem; const AIndex1, AIndex2: Integer); +var + B1, B2: Boolean; + i: Integer; + AItem1, AItem2: TListItem; +begin + if not WSCheckHandleAllocated(ALV, 'ItemExchange') then + exit; + + //We have to reassign TLvItem to AIndex1 and AIndex2 + //or use RecreateWnd() which is very expensive + + AItem1 := ALV.Items[AIndex2]; + AItem2 := ALV.Items[AIndex1]; + if ALV.Checkboxes then + begin + B2 := AItem1.Checked; + B1 := AItem2.Checked; + end; + + ItemSetText(ALV, AIndex2, AItem1, 0, AItem1.Caption); + for i := 0 to AItem1.SubItems.Count - 1 do + ItemSetText(ALV, AIndex2, AItem1, i + 1, AItem1.SubItems[i]); + + + ItemSetText(ALV, AIndex1, AItem2, 0, AItem2.Caption); + for i := 0 to AItem2.SubItems.Count - 1 do + ItemSetText(ALV, AIndex1, AItem2, i + 1, AItem2.SubItems[i]); + + + // set state images + if Assigned(TListView(ALV).StateImages) then + begin + ItemSetStateImage(ALV, AIndex2,AItem1,0, AItem1.StateIndex); + ItemSetStateImage(ALV, AIndex1,AItem2,0, AItem2.StateIndex); + end; + + // set images + if AItem1.ImageIndex >= 0 then + ItemSetImage(ALV, AIndex2, AItem1, 0, AItem1.ImageIndex); + if AItem2.ImageIndex >= 0 then + ItemSetImage(ALV, AIndex1, AItem2, 0, AItem2.ImageIndex); + + // apply checkbox states + if ALV.Checkboxes then + begin + ItemSetChecked(ALV, AIndex2, AItem1, B1); + ItemSetChecked(ALV, AIndex1, AItem2, B2); + end; + //TODO: selection and focused item. + // that works but triggers selection change in LCL ... +end; + +class procedure TWinCEWSCustomListView.ItemMove(const ALV: TCustomListView; + AItem: TListItem; const AFromIndex, AToIndex: Integer); +begin + if not WSCheckHandleAllocated(ALV, 'ItemMove') then + exit; + ItemExchange(ALV, AItem, AFromIndex, AToIndex); +end; + class function TWinCEWSCustomListView.ItemGetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem): Boolean; begin Result := False;