//**************************************************************************** // $Module type: CLASS // $Module name: cChildFieldsTreeView.pkg // $Author : Nils G. Svedmyr // Created : 2001-08-17 @ 15:07 // // Description : // // $Rev History // 2001-08-17 Module header created //**************************************************************************** Use cRdsTreeView.pkg Use Working.pkg Use SyncFuncs.pkg Open SncTable // Visual DataFlex 12.0 Migration Utility, added March 28, 2007: 15:13:23 #IF (!@ >= 120) { OverrideProperty=Border_Style InitialValue=Border_ClientEdge } { OverrideProperty=Border_Style EnumList="Border_None, Border_Normal, Border_Dialog, Border_Thick, Border_ClientEdge, Border_WindowEdge, Border_StaticEdge" } #ENDIF Class cChildFieldsTreeView Is A cRdsTreeView Procedure Construct_Object Forward Send Construct_Object Property Handle phoParent 0 // Visual DataFlex 12.0 Migration Utility, added March 28, 2007: 15:13:24 #IF (!@ >= 120) { InitialValue=0 } #ENDIF Property Integer Server 0 Property Integer piFile 0 Property String psFieldName "" // Visual DataFlex 12.0 Migration Utility, added March 28, 2007: 15:13:24 #IF (!@ >= 120) { InitialValue=True } #ENDIF Property Boolean pbFrom False Set pbFullRowSelect To True Set pbHotTracking To False Set pbShowTooltips To True Set pbSingleExpand To False Set piBackColor To clNone // Will be provided by Windows. Set piTextColor To clNone // Will be provided by Windows. Set TreeButtonsState To False Set TreeEditLabelsState To False Set TreeLinesState To True Set TreeRetainSelState To True Set TreeRootLinesState To True Set TreeSortedState To False Set Oem_Translate_State To False On_Key kDelete_Character Send DoCutItem On_Key Key_Ctrl+Key_X Send DoCutItem On_Key kEnter Send DoCutItem // On_Key kSpace Send DoCutItem On_Key Key_F6 Send Switch On_Key Key_Shift+Key_F6 Send Switch_Back On_Key kSave_Record Send Request_Save Of (Main_DD(Self)) On_Key Key_Ctrl+Key_S Send Request_Save Of (Main_DD(Self)) Send Ignore_Error Of Error_Info_Object 4100 // "Cannot find field". To not trigger error while trying to find a matching field name in ToFile. End_Procedure // Construct_Object Procedure End_Construct_Object If Not (phoParent(Self)) ; Send Stop_Box ("Programming Error. phoParent object not set for cChildFieldsTreeView object:" * String(Self)) If (phoParent(Self)) Set phoChild Of (phoParent(Self)) To Self If Not (Server(Self)) ; Send Stop_Box ("Programming Error. Server object not set for cChildFieldsTreeView object:" * String(Self)) If (Length(psFieldName(Self)) = 0) ; Send Stop_Box ("Programming Error. psFieldName property not set for cChildFieldsTreeView object:" * String(Self)) Forward Send End_Construct_Object End_Procedure // End_Construct_Object Procedure DoUpdateData Integer iFromFile Integer iToFile Boolean bFrom Boolean bFromLocal Get pbFrom To bFromLocal If (bFrom <> bFromLocal) Procedure_Return If (pbFrom(Self)) Set piFile To iFromFile Else Set piFile To iToFile Send OnCreateTree End_Procedure // DoUpdateData Procedure OnCreateTree Handle ho //Send StartWorkingMessage "Initializing data" // We don't want parent TreeView to fill until this object has been created: Get phoParent To ho If ho Send DoCreateTree Of ho Send DoCreateTree //Send StopWorkingMessage End_Procedure // OnCreateTree Procedure DoCreateTree Handle hItem ho Boolean bAppend bTableChanged Integer iRDCFile iRDCField iFile iField iSrv iPos iType iLength iPrec iCount iOpen String sFieldName sSelFields sSpace sChar sType sLabel sConcat sLength Set Dynamic_Update_State To False Send DoDeleteAllData Move SncTable.File_Number To iRDCFile Get piFile To iFile // The file to act upon. Get psFieldName To sFieldName If (Not(iFile) Or sFieldName = "") Begin Set Dynamic_Update_State To True Procedure_Return End Field_Map iRDCFile sFieldName To iRDCField Get Server To iSrv If (iRDCField And iSrv) Get File_Field_Current_Value Of iSrv iRDCFile iRDCField To sSelFields Move (Trim(sSelFields)) To sSelFields If iFile Get_Attribute DF_FILE_OPENED Of iFile To iOpen If (sSelFields = "" Or Not(iOpen)) Begin Set Dynamic_Update_State To True Procedure_Return End // If (sSelFields = "" Or Not(iOpen)) Begin Move (Self) To ho // This will take care of a special situation. // The user has created a record and has also specified Selfields, he then changes the // datatable comboform to another table... If (Current_Record(iSrv)) Begin If (pbFrom(Self)) Get Field_Changed_State Of iSrv Field SncTable.FromDataTable To bTableChanged Else Get Field_Changed_State Of iSrv Field SncTable.ToDataTable To bTableChanged If bTableChanged Begin // Reset DDO buffer value in case user saves the new config. Set File_Field_Changed_Value Of iSrv iRDCFile iRDCField To "" Set Dynamic_Update_State To True Procedure_Return End // If bTableChanged Begin End // If (Current_Record(iSrv)) Begin Send Ignore_Error Of Error_Info_Object 77 Indicate Err False Repeat Move (Pos(' ', sSelFields)) To iPos If iPos Begin Move (Left(sSelFields, (iPos - 1))) To iField Move (Trim(Replace((String(iField) + ' '), sSelFields, ''))) To sSelFields End Else Begin Move (Trim(sSelFields)) To iField // Last item Move "" To sSelFields End Move (iField < 0) To bAppend If bAppend Move (Abs(iField)) To iField Move "" To sSpace // We need to use spaces for field numbers to get it display correctly. If (iField >= 0 And iField < 10) Move " " To sSpace Else If (iField >= 10 And iField < 100) Move " " To sSpace Get FieldSpecs iFile iField To sFieldName // Function in SyncFuncs.pkg Increment iCount If bAppend Begin If (sConcat = "") Begin Get ItemLabel hItem To sLabel Move (String(sLabel) * "+" * String(sSpace) + String(iField) * "-" * sFieldName) To sConcat End // If (sConcat <> "") Begin Else Move (String(sConcat) * "+" * String(sSpace) + String(iField) * "-" * sFieldName) To sConcat End // If bAppend Begin Else Begin If (sConcat <> "") Begin Set ItemLabel hItem To sConcat Move "" To sConcat End // If (sConcat <> "") Begin Get AddTreeItem (sSpace + String(iField) * "-" * sFieldName) 0 iField 0 0 To hItem End // Else Begin If (sConcat <> "") Begin // If appended field on last selection field. Set ItemLabel hItem To sConcat Move "" To sConcat End // If (sConcat <> "") Begin If (Err) Break Until (Trim(sSelFields) = "") Send Trap_Error Of Error_Info_Object 77 Set Dynamic_Update_State To True Send Paint End_Procedure // DoCreateTree Procedure DoAddItem String sLabel Integer iData Handle hItem Get AddTreeItem sLabel 0 iData 0 0 To hItem End_Procedure // DoAddItem Procedure OnItemDblClick Handle hItem Send DoCutItem hItem End_Procedure // OnItemDblClick Procedure DoCutItem Handle hItem Integer iData String sLabel If Not (phoParent(Self)) Procedure_Return Get CurrentTreeItem To hItem If Not hItem Procedure_Return Get ItemLabel hItem To sLabel Get ItemData hItem To iData Send DoDeleteItem hItem // Send DoAddBackItem of (phoParent(Self)) sLabel iData End_Procedure // DoCutItem Procedure DoInsertItem String sLabel Integer iData Handle hItem If Not (phoParent(Self)) Procedure_Return Get CurrentTreeItem To hItem If Not hItem Begin Get RootItem To hItem Set CurrentTreeItem To hItem End // If Not hItem Begin Get PreviousSiblingItem hItem To hItem If Not hItem Get RootItem To hItem Get InsertTreeItem sLabel 0 hItem iData 0 0 To hItem Set CurrentTreeItem To hItem // To be or not to be... End_Procedure // DoInsertItem Function ItemNumber Handle hItem Returns Integer Integer iItems iCount iData iDataNew Handle hNext Get ItemCount To iItems Get ItemData hItem To iData Get RootItem To hNext For iCount From 0 To (iItems -1) Get ItemData hNext To iDataNew If (iData = iDataNew) Break Get NextSiblingItem hNext To hNext Loop Function_Return iCount End_Function // ItemNumber Function ItemHandle Integer iItem Returns Handle Integer iCount Handle hItem Get RootItem To hItem For iCount From 0 To (iItem -1) Get NextSiblingItem hItem To hItem Loop Function_Return hItem End_Function // ItemNumber Procedure DoUpdateDDBuffer Integer iSrv String sFieldName String sFieldCountField Handle hItem Integer iField iFile iCount iOldVal String sNewVal sOldVal sLabel sData Move SncTable.File_Number To iFile Field_Map iFile sFieldName To iField Get RootItem To hItem Repeat Get ItemLabel hItem To sLabel If (sLabel Contains "+") Get MultiFields sLabel To sData Else Get ItemData hItem To sData If (sData <> "") Move (String(sNewVal) * String(sData)) To sNewVal Get NextSiblingItem hItem To hItem Until (hItem < 1) Get ItemCount To iCount If (iCount = 0) Move " " To sNewVal // Note: Must be a space, else change is not saved. Else Move (Trim(sNewVal)) To sNewVal If iField Begin Get File_Field_Current_Value Of iSrv iFile iField To sOldVal If (Trim(sOldVal <> sNewVal)) ; Set File_Field_Changed_Value Of iSrv iFile iField To sNewVal End // If iField Begin If (sFieldCountField <> "") Begin Field_Map iFile sFieldCountField To iField If iField Begin Get File_Field_Current_Value Of iSrv iFile iField To iOldVal If (iOldVal <> iCount) ; Set File_Field_Changed_Value Of iSrv iFile iField To iCount End // If iField Begin End // If (sFieldCountField <> "") Begin End_Procedure // DoUpdateDDBuffer // Used when fields has been appended together: Function MultiFields String sLabel Returns String Integer iPos String sData sField sTmp Move (Pos("-", sLabel)) To iPos Move (Left(sLabel, (iPos - 2))) To sField Move sField To sData Move (Pos("+", sLabel)) To iPos Move (Left(sLabel, iPos)) To sTmp Move (Replace(sTmp, sLabel, "")) To sLabel Move (Trim(sLabel) * "+") To sLabel Repeat Move (Pos("+", sLabel)) To iPos If iPos Begin Move (Left(sLabel, iPos)) To sTmp Move (Pos("-", sTmp)) To iPos Move (Left(sTmp, (iPos - 2))) To sField Move ("-" + Trim(sField)) To sField Move (String(sData) * Trim(sField)) To sData Move (Replace(sTmp, sLabel, "")) To sLabel End // If iPos Begin // showln "sField = " sField " sData = " sData " sLabel = " sLabel Until (Not(sLabel Contains "+") Or Not(iPos)) Function_Return sData End_Function // MultiFields Procedure DoDeleteAllData Handle hRootItem Get RootItem To hRootItem While (hRootItem <> 0) Send DoDeleteItem hRootItem Get RootItem To hRootItem Loop End_Procedure // DoDeleteAllData End_Class // cChildFieldsTreeView