unit addresslist; {$mode DELPHI} interface uses LCLIntf, LCLType, Classes, SysUtils, controls, stdctrls, comctrls, ExtCtrls, graphics, math, MemoryRecordUnit, FPCanvas, cefuncproc, newkernelhandler, menus,dom, XMLRead,XMLWrite, symbolhandler, AddresslistEditor, inputboxtopunit, frmMemrecComboboxUnit, commonTypeDefs, multilineinputqueryunit, LazUTF8; type TTreeviewWithScroll=class(TTreeview) protected procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; published property ScrolledTop; end; type TDropByListviewEvent=procedure(sender: TObject; node: TTreenode; attachmode: TNodeAttachMode) of object; TAutoAssemblerEditEvent=procedure(sender: TObject; memrec: TMemoryRecord) of object; TCompareRoutine=function(a: tmemoryrecord; b: tmemoryrecord): integer of object; TMemRecChangeEvent=function(sender: TObject; memrec: TMemoryRecord):boolean of object; TAddresslist=class(TPanel) private lastSelected: integer; header: THeaderControl; Treeview: TTreeviewWithScroll; //TTreeview;//WithScroll; CurrentlyDraggedOverNode: TTreenode; CurrentlyDraggedOverBefore: boolean; //set to true if inserting before CurrentlyDraggedOverAfter: boolean; //set to true if inserting after fOnDropByListview: TDropByListviewEvent; fOnAutoAssemblerEdit: TAutoAssemblerEditEvent; activesortdirection: boolean; descriptionsortdirection: boolean; addresssortdirection: boolean; valuetypesortdirection: boolean; valuesortdirection: boolean; AddressListEditor: TAddressListEditor; fCheckboxActiveSelectedColor: TColor; fCheckboxActiveColor: TColor; fCheckboxSelectedColor: TColor; fCheckboxColor: TColor; fSelectedBackgroundColor: TColor; fSelectedSecondaryBackgroundColor: TColor; fExpandSignColor: TColor; fDecreaseArrowColor: TColor; fIncreaseArrowColor: TColor; fOnDescriptionChange: TMemRecChangeEvent; fOnAddressChange: TMemRecChangeEvent; fOnTypeChange: TMemRecChangeEvent; fOnValueChange: TMemRecChangeEvent; animationtimer: TTimer; procedure doAnimation(sender: TObject); function getTreeNodes: TTreenodes; procedure setTreeNodes(t: TTreenodes); //Rendering happens here... procedure AdvancedCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage; var PaintImages, DefaultDraw: Boolean); //^^^ procedure SelectionUpdate(sender: TObject); procedure sectiontrack(HeaderControl: TCustomHeaderControl; Section: THeaderSection; Width: Integer; State: TSectionTrackState); procedure sectionClick(HeaderControl: TCustomHeaderControl; Section: THeaderSection); procedure FocusChange(sender: TObject); procedure DragOver(Sender, Source: TObject; X,Y: Integer; State: TDragState; var Accept: Boolean); procedure DragDrop(Sender, Source: TObject; X,Y: Integer); procedure DragEnd(Sender, Target: TObject; X,Y: Integer); procedure TreeviewOnCollapse(Sender: TObject; Node: TTreeNode; var AllowCollapse: Boolean); procedure TreeviewOnExpand(Sender: TObject; Node: TTreeNode; var AllowExpansion: Boolean); procedure TreeviewDblClick(Sender: TObject); procedure TreeviewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); // procedure TreeviewKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure EditorDoubleclick(sender: tobject); //callback procedure MultiEdit(memrec: Tmemoryrecord); procedure descriptiondblclick(node: TTreenode); procedure addressdblclick(node: TTreenode); procedure typedblclick(node: TTreenode); procedure valuedblclick(node: TTreenode); procedure valueclick(node: TTreenode); function GetCount: integer; function GetSelcount: integer; function GetMemRecItemByIndex(i: integer): TMemoryRecord; procedure setPopupMenu(menu: TPopupMenu); function getPopupMenu: TPopupMenu; function getSelectedRecord: TMemoryRecord; procedure setSelectedRecord(memrec: TMemoryrecord); function hasSelectedParent(memrec: TMemoryRecord): boolean; function CheatTableNodeHasOnlyAutoAssemblerScripts(CheatTable: TDOMNode): boolean; //helperfunction function activecompare(a: tmemoryrecord; b: tmemoryrecord): integer; function descriptioncompare(a: tmemoryrecord; b: tmemoryrecord): integer; function addresscompare(a: tmemoryrecord; b: tmemoryrecord): integer; function valuetypecompare(a: tmemoryrecord; b: tmemoryrecord): integer; function valuecompare(a: tmemoryrecord; b: tmemoryrecord): integer; procedure sort(firstnode: ttreenode; compareRoutine: TCompareRoutine; direction: boolean); procedure SymbolsLoaded(sender: TObject); public //needsToReinterpret: boolean; procedure getAddressList(list: Tstrings); function focused:boolean; override; procedure sortByActive; procedure sortByDescription; procedure sortByAddress; procedure sortByValueType; procedure sortByValue; procedure RefreshCustomTypes; procedure ReinterpretAddresses; procedure ApplyFreeze; procedure refresh; procedure SelectAll; procedure saveTableXMLToNode(CheatEntries: TDOMNode; selectedOnly: boolean=false); procedure loadTableXMLFromNode(CheatEntries: TDOMNode); function GetTableXMLAsText(selectedonly: boolean): string; procedure AddTableXMLAsText(xml: string; simpleCopyPaste: boolean=true); procedure DeleteSelected(ask: boolean=true); procedure ActivateSelected(FreezeType: TFreezeType=ftFrozen); //activates all selected entries in the addresslist procedure DeactivateSelected; procedure CreateGroup(groupname: string); procedure addAutoAssembleScript(script: string); function addAddressManually(initialaddress: string=''; vartype: TVariableType=vtDword): TMemoryRecord; function addaddress(description: string; address: string; const offsets: array of integer; offsetcount: integer; vartype: TVariableType; customtypename: string=''; length: integer=0; startbit: integer=0; unicode: boolean=false; node: TTreenode=nil; attachmode: TNodeAttachMode=naAdd): TMemoryRecord; function getRecordWithDescription(description: string): TMemoryRecord; function getRecordWithID(id: integer): TMemoryRecord; function GetUniqueMemrecId: integer; procedure doDescriptionChange; procedure doAddressChange; procedure doTypeChange; procedure doValueChange; constructor Create(AOwner: TComponent); override; destructor Destroy; override; property Items: TTreeNodes read getTreeNodes write SetTreeNodes; procedure clear; property MemRecItems[Index: Integer]: TMemoryRecord read GetMemRecItemByIndex; default; property OnDropByListview: TDropByListviewEvent read FOnDropByListview write FOnDropByListview; property OnAutoAssemblerEdit: TAutoAssemblerEditEvent read fOnAutoAssemblerEdit write fOnAutoAssemblerEdit; procedure DoAutoSize; override; property headers: THeaderControl read header; published property Count: Integer read GetCount; property SelCount: Integer read GetSelCount; property SelectedRecord: TMemoryRecord read getSelectedRecord write setSelectedRecord; property PopupMenu: TpopupMenu read getPopupMenu write setPopupMenu; property checkboxActiveSelectedColor: TColor read fCheckboxActiveSelectedColor write fCheckboxActiveSelectedColor; property CheckboxActiveColor: TColor read fCheckboxActiveColor write fCheckboxActiveColor; property CheckboxSelectedColor: TColor read fCheckboxSelectedColor write fCheckboxSelectedColor; property CheckboxColor: TColor read fCheckboxColor write fCheckboxColor; property SelectedBackgroundColor: TColor read fSelectedBackgroundColor write fSelectedBackgroundColor; property SelectedSecondaryBackgroundColor: TColor read fSelectedSecondaryBackgroundColor write fSelectedSecondaryBackgroundColor; property ExpandSignColor: TColor read fExpandSignColor write fExpandSignColor; property IncreaseArrowColor: TColor read fIncreaseArrowColor write fIncreaseArrowColor; property DecreaseArrowColor: TColor read fDecreaseArrowColor write fDecreaseArrowColor; property OnDescriptionChange: TMemRecChangeEvent read fOnDescriptionChange write fOnDescriptionChange; property OnAddressChange: TMemRecChangeEvent read fOnAddressChange write fOnAddressChange; property OnTypeChange: TMemRecChangeEvent read fOnTypeChange write fOnTypeChange; property OnValueChange: TMemRecChangeEvent read fOnValueChange write fOnValueChange; end; implementation uses dialogs, formAddressChangeUnit, TypePopup, PasteTableentryFRM, mainunit, ProcessHandlerUnit, frmEditHistoryUnit; resourcestring rsDoYouWantToDeleteTheSelectedAddress = 'Do you want to delete the selected address?'; rsDoYouWantToDeleteTheSelectedAddresses = 'Do you want to delete the selected addresses?'; rsChangeDescription = 'Change Description'; rsWhatWillBeTheNewDescription = 'What will be the new description?'; rsChangeValue = 'Change Value'; rsWhatValueToChangeThisTo = 'what value to change this to?'; rsTheValueCouldNotBeParsed = 'The value %s could not be parsed'; rsNotAllValueTypesCouldHandleTheValue = 'Not all value types could handle ' +'the value %s'; rsActive = 'Active'; rsDescription = 'Description'; rsAddress = 'Address'; rsType = 'Type'; rsValue = 'Value'; rsScript = '