//**************************************************************************** // $Module type: CLASS // $Module name: cParentFieldsTreeview.pkg // $Author : Nils G. Svedmyr // Created : 2001-08-16 @ 21:58 // // Description : // // $Rev History // 2001-08-16 Module header created //**************************************************************************** Use cRdsTreeView.pkg Use SyncFuncs.pkg Open SncTable Class cParentFieldsTreeview is a cRdsTreeView Procedure Construct_Object Forward Send Construct_Object Property Handle phoChild 0 // Must be set in the object. Property Integer piFile 0 Property Boolean pbFrom True 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 Key_Ctrl+Key_X Send DoCopyItem On_Key kEnter Send DoCopyItem On_Key kSpace Send DoCopyItemSpace On_Key Key_Insert Send DoInsertItem 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)) End_Procedure // Construct_Object Procedure DoCreateTree Handle hItem Integer iFields iFile iCount iPos iType iLength iPrec iStart iFieldCount iOpen String sFieldName sSpace sSelFields sChar sType sDriver sText sTable Send DoDeleteAllData Get piFile to iFile If iFile Get_Attribute DF_FILE_OPENED Of iFile To iOpen If Not iOpen Begin Procedure_Return // If (pbFrom(Self)) Get Field_Current_Value Of (Main_DD(Self)) Field SncTable.FromDataTable To sTable // Else Get Field_Current_Value Of (Main_DD(Self)) Field SncTable.ToDataTable To sTable // Move (Trim(sTable)) To sTable // Send Stop_Box ("The table" * sTable * "has been closed. Cannot create parent treeview") End // If Not iOpen Begin Set Dynamic_Update_State to False Get_Attribute DF_FILE_NUMBER_FIELDS of iFile to iFields Get_Attribute DF_FILE_DRIVER of iFile to sDriver If (sDriver = FLEX_DRV_ID or sDriver = DFBTRDRV_ID) ; Move 0 To iStart Else Move 1 To iStart // Move (If(sDriver = FLEX_DRV_ID, 0, 1)) to iStart // If (sDriver <> FLEX_DRV_ID) For iCount from iStart to iFields Move "" to sSpace // We need to use spaces for field numbers since list is sorted. Get_Attribute DF_FIELD_TYPE of iFile iCount to iType If (iType <> DF_OVERLAP) Begin If (iCount >= 0 and iCount < 10) Move " " To sSpace Else If (iCount >= 10 and iCount < 100) Move " " To sSpace Get FieldSpecs iFile iCount To sFieldName Get AddTreeItem (sSpace + String(iCount) * "-" * sFieldName) 0 iCount 0 0 to hItem End // If (iType <> DF_OVERLAP) Begin Loop If (phoChild(Self)) Set piFile of (phoChild(Self)) to iFile Set Dynamic_Update_State to True Send Paint End_Procedure // DoCreateTree Function PosSelectionField String sSelFields Integer iCount Returns Integer // Complex integer; Hi=Length, Low=Position. Integer iRetval iPos iField iStart Repeat Move (Pos(' ', sSelFields)) to iPos Move (Mid(sSelFields, (iPos - iStart -1), (iStart + 1))) to iField If (Abs(iField) = iCount) Break Move (Replace(' ', sSelFields, '|')) to sSelFields // Replace space with another character. Move iPos to iStart Until (Not(sSelFields contains ' ')) If (Abs(iField) = iCount) Move (((iPos - iStart -1) * 65536) + (iStart +1)) to iRetval Function_Return iRetval End_Function // PosSelectionField Procedure OnItemDblClick Handle hItem Send DoCopyToChildItem hItem End_Procedure // OnItemDblClick Procedure DoCopyItem Handle hItem Get CurrentTreeItem to hItem Send DoCopyToChildItem hItem End_Procedure // DoCopyItem Procedure DoCopyToChildItem Handle hItem Handle ho Integer iData String sLabel If Not hItem Procedure_Return Get phoChild to ho If Not ho Procedure_Return Get ItemLabel hItem to sLabel Get ItemData hItem to iData // Send DoDeleteItem hItem If ho Begin Send DoAddItem of ho sLabel iData Get NextSiblingItem hItem to hItem If hItem Set CurrentTreeItem to hItem End // If ho Begin End_Procedure // DoCopyToChildItem // We need a special procedure for the space key, // because Windows 'auto' highlights the next item: // Note: This will _not_ auto move to the next item (can't get it to work properly) Procedure DoCopyItemSpace Handle ho Integer iData String sLabel Handle hItem Get CurrentTreeItem to hItem If Not hItem Procedure_Return Get phoChild to ho If Not ho Procedure_Return Get ItemLabel hItem to sLabel Get ItemData hItem to iData If ho Send DoAddItem of ho sLabel iData End_Procedure // DoCopyToChildItem Procedure DoInsertItem Handle ho hItem Integer iData String sLabel Get phoChild to ho If Not ho Procedure_Return Get CurrentTreeItem to hItem If Not hItem Begin Get RootItem to hItem Set CurrentTreeItem to hItem End // If Not hItem Begin Get ItemLabel hItem to sLabel Get ItemData hItem to iData // Send DoDeleteItem hItem If ho Begin Send DoInsertItem of ho sLabel iData Get NextSiblingItem hItem to hItem If hItem Set CurrentTreeItem to hItem End // If ho Begin End_Procedure // DoInsertItem Procedure Set RootItem Handle hItem Send Windows_Message TVM_GETNEXTITEM TVGN_ROOT hItem End_Procedure Procedure DoAddBackItem String sLabel Integer iData Handle hItem If (sLabel contains "+") Send DoSplitLabel sLabel iData Else Get AddTreeItem sLabel 0 iData 0 0 to hItem End_Procedure // DoAddBackItem Procedure DoSplitLabel String sText Integer iData Handle hItem Integer iPos String sLabel sSpace Move (Trim(sText)) to sText Repeat Move (Pos("+", sText)) to iPos Move (Left(sText, (iPos -2))) to sLabel Move (Pos("-", sText)) to iPos Move (Left(sText, (iPos -2))) to iData Move "" to sSpace If (iData > 0 and iData < 10) Move " " to sSpace Else If (iData >= 10 and iData < 100) Move " " to sSpace Get AddTreeItem (sSpace + String(sLabel)) 0 iData 0 0 to hItem If (sText contains "+") Move (Trim(Replace((sLabel * "+"), sText, ""))) to sText Else Move (Trim(Replace(sLabel, sText, ""))) to sText Until (Trim(sText) = "") End_Procedure // DoSplitLabel Procedure DoDeleteAllData Handle hRootItem Get RootItem To hRootItem While (hRootItem <> 0) Send DoDeleteItem hRootItem Get RootItem To hRootItem Loop End_Procedure // DoDeleteAllData End_Class // cParentFieldsTreeview