⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wwexpandbutton.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 3 页
字号:

procedure TwwCustomCheckBox.DataChange(Sender: TObject);
begin
end;

procedure TwwCustomCheckBox.CMTextChanged(var Message: TMessage);
begin
  if IsTransparentEffective and
    ((not Focused) or AlwaysTransparent) then
     Frame.RefreshTransparentText(False, False);

  inherited;
end;

procedure TwwCustomCheckBox.SetValueChecked(const Value: string);
begin
  FValueChecked := Value;
  DataChange(Self);
end;

procedure TwwCustomCheckBox.SetValueUnchecked(const Value: string);
begin
  FValueUnchecked := Value;
  DataChange(Self);
end;

constructor TwwCheckBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csReplicatable];
  State := cbUnchecked;
  FDataLink := TFieldDataLink.Create;
  FDataLink.Control := Self;
  FDataLink.OnDataChange := DataChange;
  FDataLink.OnUpdateData := UpdateData;
//  FPaintControl := TPaintControl.Create(Self, 'BUTTON');
//  FPaintControl.Ctl3DButton := True;
end;

destructor TwwCheckBox.Destroy;
begin
//  FPaintControl.Free;
  FDataLink.Free;
  FDataLink := nil;
  inherited Destroy;
end;

procedure TwwCheckBox.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (FDataLink <> nil) and
    (AComponent = DataSource) then DataSource := nil;
end;

function TwwCheckBox.UseRightToLeftAlignment: Boolean;
begin
  Result := DBUseRightToLeftAlignment(Self, Field);
end;

function TwwCustomCheckBox.GetFieldState: TCheckBoxState;
begin
   result:= State;
end;

function TwwCheckBox.GetFieldState: TCheckBoxState;
var
  Text: string;
begin
  if FDatalink.Field <> nil then
    if FDataLink.Field.IsNull then
      Result := cbGrayed
    else if FDataLink.Field.DataType = ftBoolean then
      if FDataLink.Field.AsBoolean then
        Result := cbChecked
      else
        Result := cbUnchecked
    else
    begin
      Result := cbGrayed;
      Text := FDataLink.Field.Text;
      if ValueMatch(FValueChecked, Text) then Result := cbChecked else
        if ValueMatch(FValueUnchecked, Text) then Result := cbUnchecked;
    end
  else
    Result:= State;
//    Result := cbUnchecked;
end;

procedure TwwCheckBox.DataChange(Sender: TObject);
begin
  State := GetFieldState;
  if (DataSource<>nil) and (DataSource.State=dsBrowse) then FModified:=False;
end;

procedure TwwCheckBox.UpdateData(Sender: TObject);
var
  Pos: Integer;
  S: string;
begin
  if State = cbGrayed then
    FDataLink.Field.Clear
  else
    if FDataLink.Field.DataType = ftBoolean then
      FDataLink.Field.AsBoolean := Checked
    else
    begin
      if Checked then S := FValueChecked else S := FValueUnchecked;
      Pos := 1;
      FDataLink.Field.Text := ExtractFieldName(S, Pos);
    end;
end;

function TwwCheckBox.ValueMatch(const ValueList, Value: string): Boolean;
var
  Pos: Integer;
begin
  Result := False;
  Pos := 1;
  while Pos <= Length(ValueList) do
    if AnsiCompareText(ExtractFieldName(ValueList, Pos), Value) = 0 then
    begin
      Result := True;
      Break;
    end;
end;

Function TwwCheckBox.IsDataBound: boolean;
begin
   result:= (DataSource<>nil) and
            (DataField<>'');
end;

function TwwCustomCheckbox.GetModified: Boolean;
begin
  Result := FModified;
end;

procedure TwwCustomCheckbox.SetModified(Value: Boolean);
begin
   FModified := Value;
end;

procedure TwwCheckBox.Toggle;
begin
  if IsDataBound then
  begin
     if FDataLink.Edit then
     begin
       inherited Toggle;
       FDataLink.Modified;
       Modified:= True;
//       if not (csPaintCopy in ControlState) then modified:=True;
     end;
  end
  else if not ReadOnly then inherited Toggle
end;

function TwwCheckBox.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;

procedure TwwCheckBox.SetDataSource(Value: TDataSource);
begin
  if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
    FDataLink.DataSource := Value;
  if Value <> nil then Value.FreeNotification(Self);
end;

function TwwCheckBox.GetDataField: string;
begin
  Result := FDataLink.FieldName;
end;

procedure TwwCheckBox.SetDataField(const Value: string);
begin
  FDataLink.FieldName := Value;
end;

function TwwCheckBox.GetReadOnly: Boolean;
begin
  Result := FDataLink.ReadOnly;
end;

procedure TwwCheckBox.SetReadOnly(Value: Boolean);
begin
  FDataLink.ReadOnly := Value;
end;

function TwwCheckBox.GetField: TField;
begin
  Result := FDataLink.Field;
end;

procedure TwwCheckBox.KeyPress(var Key: Char);
begin
  inherited KeyPress(Key);
  case Key of
    #8, ' ':
      FDataLink.Edit;
    #27:
      begin
        FDataLink.Reset;
        Modified:= False;
      end
  end;
end;

procedure TwwCheckBox.WndProc(var Message: TMessage);
begin
  inherited;
end;

procedure TwwCheckBox.WMPaint(var Message: TWMPaint);
var OldState: TCheckboxState;
    tc,bc: TColor;
  procedure CanvasNeeded;
  begin
    if FCanvas = nil then
    begin
      FCanvas := TControlCanvas.Create;
      FCanvas.Control := Self;
    end;
  end;

begin
  if not (csPaintCopy in ControlState) then
  begin
     inherited;
     PaintBorder;
  end
  else
  begin
//      OldState:= State;
      ClicksDisabled:= True;
      Try
        // This code works for inspector
        if IsInGridPaint(self) and (message.dc<>0) then
        begin
           tc:= GetTextColor(message.dc);
//           bc:= GetBkColor(message.dc);
        end;
        CanvasNeeded;
        FCanvas.Handle := Message.dc;
        FCanvas.Font:= Font;
        if IsInGridPaint(self) and (message.dc<>0) then
        begin
           FCanvas.Font.Color:= tc;
//           FCanvas.Brush.Color:= bc;
        end;
        Paint;
        FCanvas.Handle := 0;

      finally
        ClicksDisabled:= False;
      end;
  end;
end;

procedure TwwCheckBox.CMExit(var Message: TCMExit);
begin
  try
    FDataLink.UpdateRecord;
  except
    SetFocus;
    raise;
  end;
  inherited;
end;

procedure TwwCheckBox.CMGetDataLink(var Message: TMessage);
begin
  Message.Result := Integer(FDataLink);
end;

function TwwCheckBox.ExecuteAction(Action: TBasicAction): Boolean;
begin
  Result := inherited ExecuteAction(Action) or (FDataLink <> nil) and
    FDataLink.ExecuteAction(Action);
end;

function TwwCheckBox.UpdateAction(Action: TBasicAction): Boolean;
begin
  Result := inherited UpdateAction(Action) or (FDataLink <> nil) and
    FDataLink.UpdateAction(Action);
end;

Function TwwCustomCheckBox.GetCanvas: TCanvas;
begin
   if Focused and (FPaintBitmap<>nil) then
      result:= FPaintCanvas
   else
      result:= FCanvas;
end;

procedure TwwCustomCheckBox.KeyUp(var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=vk_space then
  begin
     if SpaceKeyPressed then Toggle;
     SpaceKeyPressed:=False;
  end
end;

procedure TwwCustomCheckBox.KeyDown(var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=vk_space then
  begin
     SpaceKeyPressed:=True;
  end
end;

procedure TwwCustomCheckBox.CNKeyDown(var Message: TWMKeyDown);
begin
  if not (csDesigning in ComponentState) then
  begin
    with Message do
       if (charcode = VK_SPACE) then SpaceKeyPressed:=True;
  end;

  inherited;
end;

procedure TwwCustomCheckBox.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if Operation = opRemove then
  begin
    if AComponent = Images then Images := nil;
  end;
end;

procedure TwwCustomCheckBox.CNCommand(var Message: TWMCommand);
begin
  // Handle toggling ourselves instead of control
  // as when control is in inspector it does not work otherwise
  // Therefore we do not call inherited CNCommand
end;

procedure TwwCustomCheckBox.DoMouseEnter;
begin
  try
     If Assigned( FOnMouseEnter ) Then FOnMouseEnter( self );
  except
    exit;
  end;
  if Frame.IsFrameEffective and (not Focused) and
     Frame.MouseEnterSameAsFocus then
     wwDrawEdge(self, Frame, GetCanvas, True);
end;

procedure TwwCustomCheckBox.DoMouseLeave;
begin
  try
    If Assigned( FOnMouseLeave ) Then FOnMouseLeave( self );
  except
    exit;
  end;
  if Frame.IsFrameEffective and (not Focused) and
     Frame.MouseEnterSameAsFocus then begin
     wwDrawEdge(self, Frame, GetCanvas, False);
     if IsTransparentEffective then
        Frame.CreateTransparent:= True;
     RecreateWnd;
  end;
end;

procedure TwwCustomCheckBox.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  DoMouseEnter;
//  if cslButtonDown in ControlState then
//     Invalidate;
end;

procedure TwwCustomCheckBox.CMMouseLeave(var Message: TMessage);
var r:TRect;
    pt:TPoint;
begin
  GetCursorPos(pt);
  pt := ScreenToClient(pt);
  r := ClientRect;
  if (PtInRect(r,pt)) then exit;

  inherited;
  DoMouseLeave;

//  if cslButtonDown in ControlState then Invalidate;
end;

function TwwCustomCheckbox.GetField: TField;
begin
   result:=nil;
end;

procedure TwwCustomCheckbox.EMGetModify(var Message: TMessage);
begin
   If FModified then message.result:=1
   else message.result:=0;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -