//**************************************************************************** // $Module type: Package // $Module name: cRDCCJSelectionGrid.pkg // // $Author : Nils Svedmyr, RDC Tools International. // Copyright (c) 2018 RDC Tools International // E-mail : support@rdctools.com // Web-site : http://www.rdctools.com // // Created : 2018-12-17 @ 08:04 (Military date format - Year-Month-Day) // // Note : Grid class that uses a checkbox column for selecting items. // // The code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // This is free software; you can redistribute it and/or modify it under the terms of the // GNU Lesser General Public License - see the "GNU Lesser General Public License.txt" // in the help folder for more details. // //**************************************************************************** Use cCJGrid.pkg Use cCJGridColumn.pkg Use cCJGridColumnRowIndicator.pkg Use Cursor.pkg Use vWin32fh.pkg #IFNDEF clGreenGrey Define clGreenGrey for (RGB(64, 84, 93)) Define clGreenGreyLight for (RGB(7, 117, 104)) #ENDIF #IFNDEF CS_Settings Define CS_Settings for "Settings" #ENDIF #IFNDEF CS_GridRowBackgroundColor Define CS_GridRowBackgroundColor for "GridRowBackgroundColor" #ENDIF #IFNDEF _struct_tsSearchResult Struct tsSearchResult String sFilename String sAlternateFileName // 8.3 format DateTime dtCreationDateTime DateTime dtLastAccessDateTime DateTime dtLastWriteDateTime BigInt biFileSize Integer iFileAttributes End_Struct #ENDIF Enum_List Define cx_Select_All Define cx_Select_None Define cx_Select_Invert End_Enum_List // Classes used by the cRDCCJSelectionGrid Class cRDCCJToggleSelectMenuItem is a cCJMenuItem Procedure Construct_Object Forward Send Construct_Object Set psCaption to "Toggle Current Item" Set psImage to "ToggleOn.ico" Set psShortcut to "Space-Bar" End_Procedure Procedure OnExecute Variant vCommandBarControl Forward Send OnExecute vCommandBarControl Send ToggleCurrentItem End_Procedure End_Class Class cRDCCJSelectAllMenuItem is a cCJMenuItem Procedure Construct_Object Forward Send Construct_Object Set pbControlBeginGroup to True Set psCaption to "Select All" Set psImage to "SelectAll.ico" Set psShortcut to "Ctrl+A" End_Procedure Procedure OnExecute Variant vCommandBarControl Forward Send OnExecute vCommandBarControl Set SelectItems to cx_Select_All End_Procedure End_Class Class cRDCCJDeSelectAllMenuItem is a cCJMenuItem Procedure Construct_Object Forward Send Construct_Object Set psCaption to "Select None" Set psImage to "SelectNone.ico" Set psShortcut to "Ctrl+N" End_Procedure Procedure OnExecute Variant vCommandBarControl Forward Send OnExecute vCommandBarControl Set SelectItems to cx_Select_None End_Procedure End_Class Class cRDCCJInvertSelectionsMenuItem is a cCJMenuItem Procedure Construct_Object Forward Send Construct_Object Set psCaption to "Invert Selection" Set psImage to "SelectInvert.ico" Set psShortcut to "Ctrl+I" End_Procedure Procedure OnExecute Variant vCommandBarControl Forward Send OnExecute vCommandBarControl Set SelectItems to cx_Select_Invert End_Procedure End_Class Class cRDCCJAddFolderMenuItem is a cCJMenuItem Procedure Construct_Object Forward Send Construct_Object Set psCaption to "Add Folder" Set psImage to "AddFolder.ico" Set psShortcut to "Ins" End_Procedure Procedure OnExecute Variant vCommandBarControl Forward Send OnExecute vCommandBarControl Send BrowseForFolder End_Procedure End_Class Class cRDCCJRemoveItemMenuItem is a cCJMenuItem Procedure Construct_Object Forward Send Construct_Object Set psCaption to "Remove From Grid" Set psImage to "ActionDelete.ico" Set psShortcut to "Del" End_Procedure Procedure OnExecute Variant vCommandBarControl Forward Send OnExecute vCommandBarControl Send Request_Delete End_Procedure End_Class Register_Function pbShowAddFolderMenuItem Returns Boolean Register_Function pbShowRemoveFolderMenuItem Returns Boolean Class cGridContext_mnu is a cCJContextMenu Procedure Construct_Object Handle hoMenuItem Forward Send Construct_Object Get Create (RefClass(cRDCCJToggleSelectMenuItem)) to hoMenuItem Get Create (RefClass(cRDCCJSelectAllMenuItem)) to hoMenuItem Get Create (RefClass(cRDCCJDeSelectAllMenuItem)) to hoMenuItem Get Create (RefClass(cRDCCJInvertSelectionsMenuItem)) to hoMenuItem If (pbShowAddFolderMenuItem(Self) = True) Begin Get Create (RefClass(cRDCCJAddFolderMenuItem)) to hoMenuItem Set pbControlBeginGroup of hoMenuItem to True End If (pbShowRemoveFolderMenuItem(Self) = True) Begin Get Create (RefClass(cRDCCJRemoveItemMenuItem)) to hoMenuItem If (pbShowAddFolderMenuItem(Self) = False) Begin Set pbControlBeginGroup of hoMenuItem to True End End End_Procedure End_Class Use cRDCCJGrid.pkg Class cRDCCJSelectionGrid is a cCJGrid Procedure Construct_Object Forward Send Construct_Object // This must be set manually in the grid column object for the 'data' column (or one of them): Property Handle phoData_Col 0 { Visibility=Private } Property Handle phoCheckbox_Col 0 Property Boolean pbShowAddFolderMenuItem False Property Boolean pbShowRemoveFolderMenuItem False Property Boolean pbEnableMoveKeys False Set pbRestoreLayout to True Set psLayoutSection to (Name(Self) + "_grid") Set psNoItemsText to "No data found..." Set pbHeaderReorders to True Set pbHeaderPrompts to False Set pbHeaderTogglesDirection to True Set pbSelectionEnable to True Set pbAllowInsertRow to False Set pbAllowAppendRow to False Set pbShowRowFocus to True Set pbShowFooter to True Set pbMultipleSelection to True Set pbHotTracking to True Set pbEditOnClick to True Set piLayoutBuild to 4 Set Status_Help to "Select with the spacebar" Set pbUseAlternateRowBackgroundColor to True Set peAnchors to anAll // This makes the ticked checkboxes to appear as bold. #IF (!@ > 180) Set peVisualTheme to xtpReportThemeVisualStudio2012Light #ENDIF On_Key Key_Space Send ToggleCurrentItem On_Key Key_Delete Send Request_Delete On_Key Key_Insert Send BrowseForFolder On_Key Key_Ctrl+Key_A Send SelectAll On_Key Key_Ctrl+Key_N Send SelectNone On_Key Key_Ctrl+Key_I Send SelectInvert On_Key kCancel Send CancelIfPopupObject On_Key Key_Alt+Key_Down_Arrow Send MoveDown On_Key Key_Alt+Key_Up_Arrow Send MoveUp End_Procedure Procedure MoveUp tDataSourceRow[] TheData tDataSourceRow TheRow Handle hDataSource Integer iCurrentRow If (pbEnableMoveKeys(Self) = False) Begin Procedure_Return End Get phoDataSource to hDataSource Get DataSource of hDataSource to TheData Get SelectedRow of hDataSource to iCurrentRow If (iCurrentRow > 0) Begin Move TheData[iCurrentRow - 1] to TheRow Move TheData[iCurrentRow] to TheData[iCurrentRow - 1] Move TheRow to TheData[iCurrentRow] Send ReInitializeData TheData True Send MoveToRow (iCurrentRow - 1) End End_Procedure Procedure MoveDown tDataSourceRow[] TheData tDataSourceRow TheRow Handle hDataSource Integer iCurrentRow If (pbEnableMoveKeys(Self) = False) Begin Procedure_Return End Get phoDataSource to hDataSource Get DataSource of hDataSource to TheData Get SelectedRow of hDataSource to iCurrentRow If ((iCurrentRow + 1) < SizeOfArray(TheData)) Begin Move TheData[iCurrentRow] to TheRow Move TheData[iCurrentRow + 1] to TheData[iCurrentRow] Move TheRow to TheData[iCurrentRow + 1] Send ReInitializeData TheData True Send MoveToRow (iCurrentRow + 1) End End_Procedure Procedure CancelIfPopupObject Boolean bIsInPopupObject Delegate Get Popup_State to bIsInPopupObject If (bIsInPopupObject = True) Begin Send Close_Panel End End_Procedure Procedure End_Construct_Object String sColor Handle hoContextMenu Forward Send End_Construct_Object Object oCheckbox_col is a cCJGridColumn Set phoCheckbox_Col to Self Set piWidth to 60 Set pbResizable to False Set psCaption to "Select" Set psToolTip to "Select an item by using the space bar or click with the mouse." Set pbCheckbox to True Set peHeaderAlignment to xtpAlignmentCenter Set peFooterAlignment to xtpAlignmentCenter Set peDataType to Mask_Numeric_Window End_Object Get ReadString of ghoApplication CS_Settings CS_GridRowBackgroundColor clGreenGreyLight to sColor If (sColor = "clBlueGreyLight") Begin Move "clGreenGrey" to sColor End Set piSelectedRowBackColor to sColor Set piHighlightBackColor to sColor Get Create (RefClass(cGridContext_mnu)) to hoContextMenu Set phoContextMenu to hoContextMenu End_Procedure Procedure OnCreateGridControl Handle hoObject Integer iToolTipStyle Boolean bIsBalloonStyleSupported Forward Send OnCreateGridControl Get phoToolTipContext to hoObject If (hoObject <> 0) Begin Move xtpToolTipStandard to iToolTipStyle // Baloon tooltip style requires IE 5.0 or later, so check if installed. // The ComShowTitleAndDescription also requires IE 5.0. Get ComIsBalloonStyleSupported of hoObject to bIsBalloonStyleSupported If (bIsBalloonStyleSupported = True) Begin Send ComShowTitleAndDescription of hoObject True xtpToolTipIconInfo End Set ComStyle of hoObject to iToolTipStyle Set ComShowOfficeBorder of hoObject to True Set ComShowShadow of hoObject to True // Set the max width for a tooltip. 250 just seems to be a good // compromise. After 250 pixels the text will wrap to the next line automatically. Set ComMaxTipWidth of hoObject to 250 // In pixels End End_Procedure Procedure AddItem String sDataValue Handle hoDataSource tDataSourceRow[] TheData tsSearchResult[] asFolderArray Integer iSize iData_Col iCheckbox_Col If (not(IsComObjectCreated(Self))) Begin Procedure_Return End Get piColumnId of (phoData_Col(Self)) to iData_Col Get piColumnId of (phoCheckbox_Col(Self)) to iCheckbox_Col Get phoDataSource to hoDataSource Get DataSource of hoDataSource to TheData Move (SizeOfArray(TheData)) to iSize Move sDataValue to TheData[iSize].sValue[iData_Col] Move False to TheData[iSize].sValue[iCheckbox_Col] Send ReInitializeData TheData False Send MoveToFirstRow End_Procedure Procedure BrowseForFolder String sFolderName Get vSHBrowseForFolder "Select Folder to Add" to sFolderName If (sFolderName <> "") Begin Send AddItem sFolderName End End_Procedure // We don't want columns to be editable. But setting // pbEditable = False or pbReadOnly makes it very hard to read, // and makes it impossible to select the checkbox column with the mouse. // So we disable those columns instead. Function CanEditColumn Integer iCol Returns Boolean Handle hoCol Boolean bRetval Forward Get CanEditColumn iCol to bRetval Get piColumnId of (phoCheckbox_Col(Self)) to hoCol If (iCol <> hoCol) Begin Move False to bRetval End Else Begin Move True to bRetval End Function_Return bRetval End_Function Procedure Request_Clear_All tDataSourceRow[] EmptyData Handle hoGrid hoDataSource Move Self to hoGrid If (IsComObjectCreated(hoGrid)) Begin Get phoDataSource of hoGrid to hoDataSource Send InitializeData of hoGrid EmptyData Send DoSetCheckboxFooterText End End_Procedure { EnumList="cx_Select_All, cx_Select_None, cx_Select_Invert" } // Set checkboxes of the first column as selected. // iState can be one of the following: // cx_Select_All, cx_Select_None or cx_Select_Invert Procedure Set SelectItems Integer iState Integer iCount iSize iCheckbox_Col Boolean bChecked Handle hoDataSource tDataSourceRow[] TheData Get piColumnId of (phoCheckbox_Col(Self)) to iCheckbox_Col Get phoDataSource to hoDataSource Get DataSource of hoDataSource to TheData Move (SizeOfArray(TheData)) to iSize Decrement iSize For iCount from 0 to iSize Case Begin Case (iState = cx_Select_All) Move True to TheData[iCount].sValue[iCheckbox_Col] Case Break Case (iState = cx_Select_None) Move False to TheData[iCount].sValue[iCheckbox_Col] Case Break Case (iState = cx_Select_Invert) Move TheData[iCount].sValue[iCheckbox_Col] to bChecked Move (not(bChecked)) to TheData[iCount].sValue[iCheckbox_Col] Case Break Case End Loop Send ReInitializeData TheData False Send DoSetCheckboxFooterText End_Procedure // Returns a string array with selected values for the data column (phoData_Col). Function SelectedItems Returns String[] Integer i iItems iSize iCheckbox_Col iData_Col String[] sDataArray Handle hoDataSource tDataSourceRow[] TheData Boolean bChecked Get piColumnId of (phoData_Col(Self)) to iData_Col Get piColumnId of oCheckbox_Col to iCheckbox_Col Get phoDataSource to hoDataSource Get DataSource of hoDataSource to TheData Move (SizeOfArray(TheData)) to iItems Decrement iItems For i from 0 to iItems Move TheData[i].sValue[iCheckbox_Col] to bChecked If (bChecked = True) Begin Move (SizeOfArray(sDataArray)) to iSize Move TheData[i].sValue[iData_Col] to sDataArray[iSize] End Loop Function_Return sDataArray End_Function Procedure SelectAll Set SelectItems to cx_Select_All End_Procedure Procedure SelectNone Set SelectItems to cx_Select_None End_Procedure Procedure SelectInvert Set SelectItems to cx_Select_Invert End_Procedure // Returns number of items. Function ItemCount Returns Integer Integer iItems Handle hoDataSource tDataSourceRow[] TheData Get phoDataSource to hoDataSource Get DataSource of hoDataSource to TheData Move (SizeOfArray(TheData)) to iItems Function_Return iItems End_Function // Returns number of checked items. Function CheckedItems Returns Integer Integer iCount iItems iCheckbox_Col iRetval Handle hoDataSource tDataSourceRow[] TheData Boolean bChecked Get piColumnId of (phoCheckbox_Col(Self)) to iCheckbox_Col Get phoDataSource to hoDataSource Get DataSource of hoDataSource to TheData Move (SizeOfArray(TheData)) to iItems Decrement iItems For iCount from 0 to iItems Move TheData[iCount].sValue[iCheckbox_Col] to bChecked If (bChecked = True) Begin Increment iRetval End Loop Function_Return iRetval End_Function // Toggles the current row on/off (the checkbox) Procedure ToggleCurrentItem Boolean bChecked Integer iCol Handle hoCol Get piColumnId of (phoCheckbox_Col(Self)) to iCol Get ColumnObject iCol to hoCol Get SelectedRowValue of hoCol to bChecked Send UpdateCurrentValue of hoCol (not(bChecked)) Send Request_Save Send DoSetCheckboxFooterText End_Procedure Procedure OnComMouseUp Short llButton Short llShift Integer llx Integer lly Forward Send OnComMouseUp llButton llShift llx lly Send Request_Save Send DoSetCheckboxFooterText End_Procedure Procedure DoSetCheckboxFooterText Integer iCol iSelected iItems Handle hoCol If ((phoData_Col(Self) <> 0)) Begin Move 1 to iCol End Else Begin Get piColumnId of (phoData_Col(Self)) to iCol End Get ItemCount to iItems Get ColumnObject iCol to hoCol Get CheckedItems to iSelected Set psFooterText of hoCol to ("Selected:" * String(iSelected) * "of" * String(iItems)) End_Procedure // Augment to load data to the grid. Is called automatically // from procedure Activating Procedure LoadData End_Procedure // Automatically load data into the grid when activating. Procedure Activating Send Cursor_Wait of Cursor_Control Send LoadData Send Cursor_Ready of Cursor_Control End_Procedure End_Class