ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/ibcontrols/IBDynamicGrid.pas
(Generate patch)

Comparing ibx/trunk/ibcontrols/IBDynamicGrid.pas (file contents):
Revision 37 by tony, Mon Feb 15 14:44:25 2016 UTC vs.
Revision 315 by tony, Thu Feb 25 11:56:36 2021 UTC

# Line 41 | Line 41 | type
41     - automatic resizing of selected columns to fill the available row length
42     - automatic positioning and sizing of a "totals" control, typically at the
43       column footer, on a per column basis.
44 <   - DataSet resorting on header row click, sorting the dataset by the selected column.
44 >   - DataSet re-sorting on header row click, sorting the dataset by the selected column.
45       A second click on the same header cell reversed the sort order.
46     - Reselection of the same row following resorting.
47     - A new cell editor that provides the same functionality as TIBLookupComboEditBox.
# Line 150 | Line 150 | end;
150      FGrid: TCustomGrid;
151      FCol,FRow: Integer;
152      FEditText: string;
153 +    function EditingKeyField: boolean;
154    protected
155      procedure WndProc(var TheMessage : TLMessage); override;
156      procedure CloseUp; override;
# Line 166 | Line 167 | end;
167      property OnEditingDone;
168    end;
169  
170 +  TOnSelectPanelEditor = procedure(Sender: TObject; var aEditorPanel: TWinControl) of object;
171 +
172    TDBDynamicGrid = class(TDBGrid)
173    private
174      { Private declarations }
# Line 176 | Line 179 | end;
179      FOnEditorPanelHide: TNotifyEvent;
180      FOnEditorPanelShow: TNotifyEvent;
181      FOnKeyDownHander: TKeyDownHandler;
182 +    FOnSelectPanelEditor: TOnSelectPanelEditor;
183      FResizing: boolean;
184      FWeHaveFocus: boolean;
181    FHidingEditorPanel: boolean;
182    FAllowHide: boolean;
185      FMouseDown: boolean;
186      function ActiveControl: TControl;
187      procedure DoShowEditorPanel(Data: PtrInt);
# Line 223 | Line 225 | end;
225      property OnEditorPanelShow: TNotifyEvent read FOnEditorPanelShow write FOnEditorPanelShow;
226      property OnEditorPanelHide: TNotifyEvent read FOnEditorPanelHide write FOnEditorPanelHide;
227      property OnKeyDownHander: TKeyDownHandler read FOnKeyDownHander write FOnKeyDownHander;
228 +    property OnSelectPanelEditor: TOnSelectPanelEditor read FOnSelectPanelEditor
229 +                                                       write FOnSelectPanelEditor;
230   end;
231  
232    {TIBGridControlLink}
# Line 305 | Line 309 | end;
309  
310   implementation
311  
312 < uses Math, IBQuery, LCLType;
312 > uses LCLType, Variants, EditBtn;
313  
314   { TIBGridControlLink }
315  
# Line 371 | Line 375 | begin
375      else
376      begin
377        for I := 0 to  ColCount - 1 do
378 +        if (I < FixedCols) or Columns[I - FixedCols].Visible then
379           ColSum := ColSum + ColWidths[I];
380  
381        if Colsum <> ClientWidth then
382        begin
383          ResizeColCount := 0;
384          for I := 0 to Columns.Count -1 do
385 <          if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn then
385 >          if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn and Columns[I].Visible then
386            begin
387              Inc(ResizeColCount);
388              Colsum := Colsum + TDBDynamicGridColumn(Columns[I]).DesignWidth - Columns[I].Width;
# Line 390 | Line 395 | begin
395              n := (ClientWidth - ColSum) mod ResizeColCount;
396  
397              for I := 0 to Columns.Count -1 do
398 <              if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn then
398 >              if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn and Columns[I].Visible then
399                begin
400                  if I = 0 then
401                    Columns[I].Width := Columns[I].Width + adjustment + n
# Line 561 | Line 566 | begin
566        Exit; {ignore these keys if we are in a  combobox}
567  
568      if (AControl <> nil) and (AControl is TCustomMemo)
569 <                         and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore Return in a CustomMemo}
569 >                         and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore keys in a CustomMemo}
570  
571      if (AControl <> nil) and (AControl is TCustomGrid)
572 <                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_TAB]) then Exit; {Ignore Return in a CustomMemo}
572 >                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_TAB]) then Exit; {Ignore keys in a Custom Grid}
573 >
574 >    if (AControl <> nil) and (AControl is TEBEdit) and (AControl.Owner is TDateEdit) then
575 >    begin
576 >      if (Key in [VK_LEFT,VK_RIGHT]) then Exit; {Ignore navigation keys}
577 >      if TDateEdit(AControl.Owner).DroppedDown and
578 >        (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_ESCAPE]) then Exit; {Ignore TCalender navigation keys in a Data edit}
579 >    end;
580  
581      if assigned(FOnKeyDownHander) then
582        OnKeyDownHander(Sender,Key,Shift,Done);
# Line 609 | Line 621 | begin
621    if FEditorPanel <> nil then
622       RemoveFreeNotification(FEditorPanel);
623    FEditorPanel := AValue;
624 <  FreeNotification(FEditorPanel);
624 >  if FEditorPanel <> nil then
625 >     FreeNotification(FEditorPanel);
626   end;
627  
628   procedure TDBDynamicGrid.ChangeBounds(ALeft, ATop, AWidth, AHeight: integer;
# Line 676 | Line 689 | end;
689  
690   procedure TDBDynamicGrid.Notification(AComponent: TComponent;
691    Operation: TOperation);
692 + var i: integer;
693   begin
694    inherited Notification(AComponent, Operation);
695 <  if (Operation = opRemove) and
696 <     (AComponent = FEditorPanel) then FEditorPanel := nil;
695 >  if (Operation = opRemove) and not (csDestroying in ComponentState) then
696 >  begin
697 >    if AComponent = FEditorPanel then
698 >      FEditorPanel := nil
699 >    else
700 >    if AComponent is TControl then
701 >    begin
702 >      for i := 0 to Columns.Count - 1 do
703 >        if TDBDynamicGridColumn(Columns[I]).ColumnTotalsControl = AComponent then
704 >          TDBDynamicGridColumn(Columns[I]).ColumnTotalsControl := nil;
705 >    end;
706 >  end
707   end;
708  
709   procedure TDBDynamicGrid.TopLeftChanged;
# Line 692 | Line 716 | procedure TDBDynamicGrid.UpdateActive;
716   begin
717    inherited UpdateActive;
718  
719 +  if not (csLoading in ComponentState) and assigned(DataLink)
720 +                       and assigned(DataLink.DataSet) and DataLink.DataSet.Active then
721 +    DoGridResize;
722 +
723    if not (csLoading in ComponentState) and assigned(DataLink) and
724       assigned(FEditorPanel) and not FEditorPanel.Visible and
725       assigned(DataLink.DataSet) and (DataLink.DataSet.State = dsInsert) then
# Line 730 | Line 758 | begin
758   end;
759  
760   procedure TDBDynamicGrid.ShowEditorPanel;
761 + var aEditor: TWinControl;
762   begin
763    if (csDesigning in ComponentState) or
764     (DataSource = nil) or (DataSource.DataSet = nil)
765       or ((DataSource.DataSet.RecordCount = 0) and (DataSource.DataSet.State <> dsInsert)) then
766       Exit;
767 <  Editor := FEditorPanel;
767 >  aEditor := FEditorPanel;
768 >  if assigned(FOnSelectPanelEditor) then
769 >    OnSelectPanelEditor(self,aEditor);
770 >  if FEditorPanel <> aEditor then
771 >    SetEditorPanel(aEditor);
772 >  Editor := aEditor;
773    EditorMode := true;
774   end;
775  
# Line 774 | Line 808 | begin
808    Result := inherited Width
809   end;
810  
811 + type
812 +  THackedGrid = class(TIBDynamicGrid)
813 +  public
814 +    property FixedCols;
815 +  end;
816 +
817   { TDBLookupCellEditor }
818  
819 + function TDBLookupCellEditor.EditingKeyField: boolean;
820 + begin
821 +  with TIBDynamicGridColumn(TDBGrid(FGrid).Columns[FCol - THackedGrid(FGrid).FixedCols]) do
822 +    Result := CompareText(FieldName, DBLookupProperties.DataFieldName) = 0;
823 + end;
824 +
825   procedure TDBLookupCellEditor.WndProc(var TheMessage: TLMessage);
826   begin
827    if TheMessage.msg=LM_KILLFOCUS then begin
# Line 794 | Line 840 | begin
840    UpdateData(nil); {Force Record Update}
841    if FGrid<>nil then
842    Begin
843 <    (FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, Trim(Text));
843 >    if EditingKeyField then
844 >    begin
845 >      if not VarIsNull(KeyValue) then
846 >       (FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, KeyValue)
847 >    end
848 >    else
849 >      (FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, Trim(Text));
850      (FGrid as TIBDynamicGrid).UpdateData;
851    end;
852    inherited CloseUp;
# Line 819 | Line 871 | begin
871    CheckAndInsert;
872    Msg.Col := FCol;
873    Msg.Row := FRow;
874 <  Msg.Value:= Trim(Text);
874 >  if EditingKeyField then
875 >  begin
876 >    if not VarIsNull(KeyValue) then
877 >      Msg.Value:= KeyValue
878 >    else
879 >      Msg.Value:= ''
880 >  end
881 >  else
882 >    Msg.Value:= Trim(Text);
883   end;
884  
885   procedure TDBLookupCellEditor.msg_SetGrid(var Msg: TGridMessage);
# Line 907 | Line 967 | begin
967      if DataFieldName <> '' then
968          Editor.DataSource := TDBGrid(Grid).DataSource;
969    end;
970 <  Editor.Text := Editor.FEditText;
970 >  if Editor.EditingKeyField then
971 >  begin
972 >    if not Field.IsNull then
973 >      Editor.KeyValue := Editor.FEditText
974 >  end
975 >  else
976 >    Editor.Text := Editor.FEditText;
977    Editor.SelStart := Length(Editor.Text);
978   end;
979  
# Line 932 | Line 998 | end;
998   destructor TIBDynamicGridColumn.Destroy;
999   begin
1000    if assigned(FDBLookupProperties) then FDBLookupProperties.Free;
1001 +  Application.RemoveAsyncCalls(self);
1002    inherited Destroy;
1003   end;
1004  
# Line 1180 | Line 1247 | end;
1247  
1248   procedure TIBDynamicGrid.Notification(AComponent: TComponent;
1249    Operation: TOperation);
1250 + var i: integer;
1251   begin
1252    inherited Notification(AComponent, Operation);
1253 <  if (Operation = opRemove) and
1254 <     (FIBControlLink <> nil) and (AComponent = DataSource) then FIBControlLink.IBDataSet := nil;
1253 >  if (Operation = opRemove) then
1254 >  begin
1255 >    if (FIBControlLink <> nil) and (AComponent = DataSource) then
1256 >      FIBControlLink.IBDataSet := nil
1257 >    else
1258 >    if AComponent is TDataSource then
1259 >    begin
1260 >      for i := 0 to Columns.Count - 1 do
1261 >        if TIBDynamicGridColumn(Columns[I]).DBLookupProperties.ListSource = AComponent then
1262 >          TIBDynamicGridColumn(Columns[I]).DBLookupProperties.ListSource := nil;
1263 >    end
1264 >  end
1265   end;
1266  
1267   procedure TIBDynamicGrid.UpdateActive;
# Line 1213 | Line 1291 | begin
1291    if assigned(FIBControlLink) then FIBControlLink.Free;
1292    if assigned(FIndexFieldsList) then FIndexFieldsList.Free;
1293    if assigned(FDBLookupCellEditor) then FDBLookupCellEditor.Free;
1294 +  Application.RemoveAsyncCalls(self);
1295    inherited Destroy;
1296   end;
1297  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines