//TH-Header //***************************************************************************************** // Copyright (c) 2003 Bernhard Ponemayr // All rights reserved. // // $FileName : .\hammer\Pkg\cSciCodelist.pkg // $ProjectName : Listview API // $Author : Bernhard Ponemayr // $Created : 20.01.2003 16:07 // // Contents: Abstraction class for the Autocomplete functionality in scintilla control to // work similar as the codemax codesense control that is to be found in cCodelist.pkg // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Define LVS_SORTASCENDING For |CI$0010 Define LVS_EX_TRACKSELECT For |CI$00000008 Define LVS_EX_ONECLICKACTIVATE For |CI$00000040 Struct tCodeList String sSortValue // used for sorting/searching the case insensitive variant that DF claims works, doesn't work String sValue Integer iRef String sBitmap Integer iInsertOrder // Set as item number in the original inserting order before sorting! End_Struct // tCodeList Class cSciCodelist is a Array Procedure Construct_Object Forward Send Construct_Object Property Handle phoCodelist 0 // not used Property Integer pbUseBitmaps TRUE // not used (need xpm images) Property Integer piRefValue 0 // The ref value contains additional info such as a record id or status about a variable Property Handle phLastUsedFont 0 // not used Property Integer piCurrent -1 // The current item (aka, the one just selected) Property tCodeList[] pCodeList End_Procedure Procedure Codelist_Connect Handle hCodelist Integer bUseBitmaps Set phoCodelist To hCodelist // not used Set piCurrent To -1 If ( bUseBitmaps ) Begin Set pbUseBitmaps To TRUE End Else Begin Set pbUseBitmaps To FALSE End End_Procedure Procedure Codelist_Disconnect Send Codelist_delete_data // Remove all Items from list Set phoCodelist To 0 End_Procedure // // While it is called "add_item" in the original code it is actually inserting the data // at the bottom. As that's slow, we will reverse the array before sorting. // Function Codelist_Add_Item String sText String sBitmap Integer iRefValue Returns Integer Integer iCount Integer iRet tCodeList CodeItem tCodeList[] CodeList Move 0 To iRet If (sText<>"") Begin Get pCodeList To CodeList Move (SizeOfArray(CodeList)) To iCount Move (lowercase(sText)) To CodeItem.sSortValue Move sText To CodeItem.sValue Move sBitmap To CodeItem.sBitmap Move iRefValue To CodeItem.iRef //Move (InsertInArray(CodeList,0,CodeItem)) To CodeList Move CodeItem To CodeList[iCount] Set pCodeList To CodeList End Function_Return iRet End_Function Procedure Codelist_delete_data tCodeList[] CodeList Move (ResizeArray(CodeList,0)) To CodeList Set pCodeList To CodeList End_Procedure Function Codelist_value Integer iItem Returns String Integer iRefVal String sText tCodeList[] CodeList Get pCodeList To CodeList If (iItem < SizeOfArray(CodeList) and iItem<>-1) Begin Move CodeList[iItem].sValue To sText Move CodeList[iItem].iRef To iRefVal End Set piRefValue To iRefVal Function_Return sText End_Function Function Codelist_bitmap Integer iItem Returns String String sBitmap tCodeList[] CodeList Move "" To sBitmap Get pCodeList To CodeList If (iItem < SizeOfArray(CodeList) and iItem<>-1) Begin Move CodeList[iItem].sBitmap To sBitmap End If (sBitmap<>"") Begin Get_File_Path sBitmap To sBitmap End Function_Return sBitmap End_Function // // This item number is used to refer to the ORIGINAL item id in the object that supplied the data // it should not be used to retrieve the data of this array as you'll end up getting different data. // Capiche? // Function Codelist_current_item Returns Integer Integer iCurrent Integer iItem tCodeList[] CodeList Move -1 To iItem Get piCurrent To iCurrent Get pCodeList To CodeList If (iCurrent<>-1 and iCurrent < SizeOfArray(CodeList)) Begin Move CodeList[iCurrent].iInsertOrder To iItem End Function_Return iItem End_Function Function Codelist_find_item String sItem Returns Integer Integer iItem tCodeList SearchCode tCodeList[] CodeList Get pCodeList To CodeList //Move (SearchArray(sItem, CodeList, Desktop, (RefFunc(DFSTRICMP)))) to iItem Move (Lowercase(sItem)) To SearchCode.sSortValue Move (SearchArray(SearchCode,CodeList)) To iItem Set piCurrent To iItem Function_Return iItem End_Function // // Add index numbers to the array // Procedure LabelArray tCodeList[] ByRef CodeList Integer iItem Integer iCount Move (SizeOfArray(CodeList)) To iCount If (iCount>0) Begin For iItem From 0 To (iCount-1) Move iItem To CodeList[iItem].iInsertOrder Loop End End_Procedure // Does a few things: // - Will first reverse the array as our items have been added instead of inserted like in the original code // - Then it will add index numbers so that we can return original references // - After which we will sort the list, this might not be needed, but it is a precaution for if somebody // made an error while inserting data in a non ascending order. // Procedure SortAscending tCodeList[] CodeList Get pCodeList To CodeList Move (ReverseArray(CodeList)) To CodeList Send LabelArray (&CodeList) //Move (SortArray(CodeList, Desktop, (RefFunc(DFSTRICMP)))) to CodeList Move (SortArray(CodeList)) To CodeList Set pCodeList To CodeList End_Procedure Procedure Set Codelist_style Integer iStyle End_Procedure Procedure Set Codelist_font Integer hFont End_Procedure // // We don't use this in scintilla, instead we show the autocomplete list // and pass the word to select. // //Function Codelist_SelectClosestItem String sText Returns Integer // Function_Return iItem //End_Function Function Codelist_Item_count Returns Integer Integer iCount Move (SizeOfArray(pCodeList(Self))) To iCount Function_Return iCount End_Function // // ToDo: Codelist_Beginning_Of_Data // Procedure Codelist_Beginning_Of_Data //String sVal sLvItem //Pointer pVal pLvItem //Integer iRet iItem //If (phoCodelist(self)) Eq 0 Procedure_Return //zerotype LVITEM to sLvItem //getaddress Of sLvItem to pLvItem // //put LVIF_STATE to sLvItem at LVITEM.mask //put 0 to sLvItem at LVITEM.iItem //put (LVIS_SELECTED Ior LVIS_FOCUSED) to sLvItem at LVITEM.state //put (LVIS_SELECTED Ior LVIS_FOCUSED) to sLvItem at LVITEM.stateMask // //Move (ListView_SetItemState(phoCodelist(self),0,pLvItem)) to iRet //If (Not(iRet)) Procedure_Return //Move (ListView_EnsureVisible(phoCodelist(self),0,FALSE)) to iRet End_Procedure // // ToDo: Codelist_End_Of_Data // Procedure Codelist_End_Of_Data //String sVal sLvItem //Pointer pVal pLvItem //Integer iRet iItem //If (phoCodelist(self)) Eq 0 Procedure_Return //zerotype LVITEM to sLvItem //getaddress Of sLvItem to pLvItem // //put LVIF_STATE to sLvItem at LVITEM.mask ////Move (Listview_GetItemCount(phoCodelist(self))) to iItem //Get Item_Count to iItem //If iItem Eq -1 Procedure_Return //Move (iItem-1) to iItem //put iItem to sLvItem at LVITEM.iItem //put (LVIS_SELECTED Ior LVIS_FOCUSED) to sLvItem at LVITEM.state //put (LVIS_SELECTED Ior LVIS_FOCUSED) to sLvItem at LVITEM.stateMask // //Move (ListView_SetItemState(phoCodelist(self),iItem,pLvItem)) to iRet //If (Not(iRet)) Procedure_Return //Move (ListView_EnsureVisible(phoCodelist(self),iItem,FALSE)) to iRet End_Procedure End_Class // BP CodeList Support // this object is just for testing the codelist functions // SVN Global_Variable Integer ghoCodeList Object oCodelist is a cSciCodelist Object oClassDataCache is an Array End_Object Property Integer piListReason 0 Property Integer piSourceObject 0 Property Integer piSourceLine 0 Property String psSourceLine "" Property String psSourceRefVal "" Move self To ghoCodeList Function Codelist_Add_CachedItem String sText String sBitmap Integer iRefValue Returns Integer String sArrayValue Integer iRet Move ( sText + "\new\" + (String(iRefValue)) + "\new\" ) To sArrayValue If ( (pbUseBitmaps(self)) And (sBitmap Eq "") ) Begin Move "default.bmp" To sBitmap End If sBitmap Ne "" Begin Move (sArrayValue + (String(sBitmap)) ) To sArrayValue End Else Begin Move (sArrayValue + "-1") To sArrayValue End Move (sArrayValue + "\new\" ) To sArrayValue Set Value Of oClassDataCache Item (item_count(oClassDataCache(self))) To sArrayValue Set Value Item (CodeList_Item_Count(Self)) To sText Function_Return iRet End_Function Procedure FillCodelistFromCache Integer iItem iRet String sText sRefValue sBitmap sLine For iItem From 0 To ( (item_count(oClassDataCache(self))) -1) Get Value Of oClassDataCache Item iItem To sLine Move (Left(sLine,((Pos("\new\",sLine))+4))) To sText Move (Replace(sText,sLine,"")) To sLine Move (Replace("\new\",sText,"")) To sText Move (Left(sLine,((Pos("\new\",sLine))+4))) To sRefValue Move (Replace(sRefValue,sLine,"")) To sBitmap Move (Replace("\new\",sRefValue,"")) To sRefValue Move (Replace("\new\",sBitmap,"")) To sBitmap Get Codelist_Add_Item sText sBitmap sRefValue To iRet Loop End_Procedure End_Object // BP