ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/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 41 by tony, Sat Jul 16 12:25:48 2016 UTC

# 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;
185      FHidingEditorPanel: boolean;
# Line 223 | Line 227 | end;
227      property OnEditorPanelShow: TNotifyEvent read FOnEditorPanelShow write FOnEditorPanelShow;
228      property OnEditorPanelHide: TNotifyEvent read FOnEditorPanelHide write FOnEditorPanelHide;
229      property OnKeyDownHander: TKeyDownHandler read FOnKeyDownHander write FOnKeyDownHander;
230 +    property OnSelectPanelEditor: TOnSelectPanelEditor read FOnSelectPanelEditor
231 +                                                       write FOnSelectPanelEditor;
232   end;
233  
234    {TIBGridControlLink}
# Line 305 | Line 311 | end;
311  
312   implementation
313  
314 < uses Math, IBQuery, LCLType;
314 > uses Math, IBQuery, LCLType, Variants;
315  
316   { TIBGridControlLink }
317  
# Line 371 | Line 377 | begin
377      else
378      begin
379        for I := 0 to  ColCount - 1 do
380 +        if (I < FixedCols) or Columns[I - FixedCols].Visible then
381           ColSum := ColSum + ColWidths[I];
382  
383        if Colsum <> ClientWidth then
384        begin
385          ResizeColCount := 0;
386          for I := 0 to Columns.Count -1 do
387 <          if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn then
387 >          if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn and Columns[I].Visible then
388            begin
389              Inc(ResizeColCount);
390              Colsum := Colsum + TDBDynamicGridColumn(Columns[I]).DesignWidth - Columns[I].Width;
# Line 390 | Line 397 | begin
397              n := (ClientWidth - ColSum) mod ResizeColCount;
398  
399              for I := 0 to Columns.Count -1 do
400 <              if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn then
400 >              if TDBDynamicGridColumn(Columns[I]).AutoSizeColumn and Columns[I].Visible then
401                begin
402                  if I = 0 then
403                    Columns[I].Width := Columns[I].Width + adjustment + n
# Line 609 | Line 616 | begin
616    if FEditorPanel <> nil then
617       RemoveFreeNotification(FEditorPanel);
618    FEditorPanel := AValue;
619 <  FreeNotification(FEditorPanel);
619 >  if FEditorPanel <> nil then
620 >     FreeNotification(FEditorPanel);
621   end;
622  
623   procedure TDBDynamicGrid.ChangeBounds(ALeft, ATop, AWidth, AHeight: integer;
# Line 676 | Line 684 | end;
684  
685   procedure TDBDynamicGrid.Notification(AComponent: TComponent;
686    Operation: TOperation);
687 + var i: integer;
688   begin
689    inherited Notification(AComponent, Operation);
690 <  if (Operation = opRemove) and
691 <     (AComponent = FEditorPanel) then FEditorPanel := nil;
690 >  if (Operation = opRemove) and not (csDestroying in ComponentState) then
691 >  begin
692 >    if AComponent = FEditorPanel then
693 >      FEditorPanel := nil
694 >    else
695 >    if AComponent is TControl then
696 >    begin
697 >      for i := 0 to Columns.Count - 1 do
698 >        if TDBDynamicGridColumn(Columns[I]).ColumnTotalsControl = AComponent then
699 >          TDBDynamicGridColumn(Columns[I]).ColumnTotalsControl := nil;
700 >    end;
701 >  end
702   end;
703  
704   procedure TDBDynamicGrid.TopLeftChanged;
# Line 692 | Line 711 | procedure TDBDynamicGrid.UpdateActive;
711   begin
712    inherited UpdateActive;
713  
714 +  if not (csLoading in ComponentState) and assigned(DataLink)
715 +                       and assigned(DataLink.DataSet) and DataLink.DataSet.Active then
716 +    DoGridResize;
717 +
718    if not (csLoading in ComponentState) and assigned(DataLink) and
719       assigned(FEditorPanel) and not FEditorPanel.Visible and
720       assigned(DataLink.DataSet) and (DataLink.DataSet.State = dsInsert) then
# Line 730 | Line 753 | begin
753   end;
754  
755   procedure TDBDynamicGrid.ShowEditorPanel;
756 + var aEditor: TWinControl;
757   begin
758    if (csDesigning in ComponentState) or
759     (DataSource = nil) or (DataSource.DataSet = nil)
760       or ((DataSource.DataSet.RecordCount = 0) and (DataSource.DataSet.State <> dsInsert)) then
761       Exit;
762 <  Editor := FEditorPanel;
762 >  aEditor := FEditorPanel;
763 >  if assigned(FOnSelectPanelEditor) then
764 >    OnSelectPanelEditor(self,aEditor);
765 >  if FEditorPanel <> aEditor then
766 >    SetEditorPanel(aEditor);
767 >  Editor := aEditor;
768    EditorMode := true;
769   end;
770  
# Line 774 | Line 803 | begin
803    Result := inherited Width
804   end;
805  
806 + type
807 +  THackedGrid = class(TIBDynamicGrid)
808 +  public
809 +    property FixedCols;
810 +  end;
811 +
812   { TDBLookupCellEditor }
813  
814 + function TDBLookupCellEditor.EditingKeyField: boolean;
815 + begin
816 +  with TIBDynamicGridColumn(TDBGrid(FGrid).Columns[FCol - THackedGrid(FGrid).FixedCols]) do
817 +    Result := CompareText(FieldName, DBLookupProperties.DataFieldName) = 0;
818 + end;
819 +
820   procedure TDBLookupCellEditor.WndProc(var TheMessage: TLMessage);
821   begin
822    if TheMessage.msg=LM_KILLFOCUS then begin
# Line 794 | Line 835 | begin
835    UpdateData(nil); {Force Record Update}
836    if FGrid<>nil then
837    Begin
838 <    (FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, Trim(Text));
838 >    if EditingKeyField then
839 >    begin
840 >      if not VarIsNull(KeyValue) then
841 >       (FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, KeyValue)
842 >    end
843 >    else
844 >      (FGrid as TIBDynamicGrid).EditorTextChanged(FCol, FRow, Trim(Text));
845      (FGrid as TIBDynamicGrid).UpdateData;
846    end;
847    inherited CloseUp;
# Line 819 | Line 866 | begin
866    CheckAndInsert;
867    Msg.Col := FCol;
868    Msg.Row := FRow;
869 <  Msg.Value:= Trim(Text);
869 >  if EditingKeyField then
870 >  begin
871 >    if not VarIsNull(KeyValue) then
872 >      Msg.Value:= KeyValue
873 >    else
874 >      Msg.Value:= ''
875 >  end
876 >  else
877 >    Msg.Value:= Trim(Text);
878   end;
879  
880   procedure TDBLookupCellEditor.msg_SetGrid(var Msg: TGridMessage);
# Line 907 | Line 962 | begin
962      if DataFieldName <> '' then
963          Editor.DataSource := TDBGrid(Grid).DataSource;
964    end;
965 <  Editor.Text := Editor.FEditText;
965 >  if Editor.EditingKeyField then
966 >  begin
967 >    if not Field.IsNull then
968 >      Editor.KeyValue := Editor.FEditText
969 >  end
970 >  else
971 >    Editor.Text := Editor.FEditText;
972    Editor.SelStart := Length(Editor.Text);
973   end;
974  
# Line 1180 | Line 1241 | end;
1241  
1242   procedure TIBDynamicGrid.Notification(AComponent: TComponent;
1243    Operation: TOperation);
1244 + var i: integer;
1245   begin
1246    inherited Notification(AComponent, Operation);
1247 <  if (Operation = opRemove) and
1248 <     (FIBControlLink <> nil) and (AComponent = DataSource) then FIBControlLink.IBDataSet := nil;
1247 >  if (Operation = opRemove) then
1248 >  begin
1249 >    if (FIBControlLink <> nil) and (AComponent = DataSource) then
1250 >      FIBControlLink.IBDataSet := nil
1251 >    else
1252 >    if AComponent is TDataSource then
1253 >    begin
1254 >      for i := 0 to Columns.Count - 1 do
1255 >        if TIBDynamicGridColumn(Columns[I]).DBLookupProperties.ListSource = AComponent then
1256 >          TIBDynamicGridColumn(Columns[I]).DBLookupProperties.ListSource := nil;
1257 >    end
1258 >  end
1259   end;
1260  
1261   procedure TIBDynamicGrid.UpdateActive;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines