unit CCGeneral;

interface
uses controls,classes,graphics,windows,messages,turbo;

  type
    //Forwarddeklarationen
    TCCDarstellungsMode=(ccdmNormal,ccdmCustomColor); //Notationscode: |xccdm|
  //  TCCDarstellung=class;                             //Notationscode: |xccd|
    TCCComponent=class;                                  //Notationscode: |xcco|
    TCCDarstellungsSteuerung=class;

    //richtige Deklarationen
    TCCDarstellungsSteuerung=class(TComponent)
      private
        FDarstellungsMode_xccdm:TCCDarstellungsMode;
        FOberflaecheVon3DObjekten_xf{,FOberflaecheVonDialogen_xf}:TColor;
        F3DLicht_xf,F3DGlanz_xf:TColor;
        F3DSchatten_xf:TColor;
        FDunklerSchatten_xf:TColor;

        FButtonText_xf{,FScrollBar_xf}:TColor;
        FScrollBarBk1_xf,FScrollBarBk2_xf,FScrollBarScroll_xf:TColor;
        FEdit_xf:TColor;
        FHighlight_xf,FHighlighttext_xf:TColor;
        FDisableText1_xf,FDisableText2_xf:TColor;
        FEditText_xf:TColor;
      public
        constructor create(AOwner_xc:TComponent);override;
        destructor destroy;override;
        function getColorFromWindowColorKey(wert_i:integer):TColor;
        function getAlternativColorFromWindowColorKey(wert_i:integer;nr_i:integer):TColor;
      published
        property DarstellungsMode:TCCDarstellungsMode read FDarstellungsMode_xccdm write FDarstellungsMode_xccdm;


        property Editcolor:TColor read FEdit_xf write FEdit_xf;
        property OberflaecheVon3DObjekten:TColor read FOberflaecheVon3DObjekten_xf write FOberflaecheVon3DObjekten_xf;
      //  property OberflaecheVonDialogen:TColor read FOberflaecheVonDialogen_xf write FOberflaecheVonDialogen_xf;
        property Licht:TColor read F3DLicht_xf write F3DLicht_xf;
        property Glanz:TColor read F3DGlanz_xf write F3DGlanz_xf;
        property Schatten:TColor read F3DSchatten_xf write F3DSchatten_xf;
        property DunklerSchatten:TColor read FDunklerSchatten_xf write FDunklerSchatten_xf;
        property ButtonText:TColor read FButtonText_xf write FButtonText_xf;
         //property ScrollBarText:TColor read FScrollBar_xf write FScrollBar_xf;
        property ScrollBarFarbe1:TColor read FScrollBarBk1_xf write FScrollBarBk1_xf;
        property ScrollBarFarbe2:TColor read FScrollBarBk2_xf write FScrollBarBk2_xf;
        property ScrollBarScrollFarbe:TColor read FScrollBarScroll_xf write FScrollBarScroll_xf;
        property HighlightColor:TColor read FHighlight_xf write FHighlight_xf;
        property HighlightTextColor:TColor read FHighlighttext_xf write FHighlighttext_xf;
        property DisableTextColor1:TColor read FDisableText1_xf write FDisableText1_xf;
        property DisableTextColor2:TColor read FDisableText2_xf write FDisableText2_xf;
        property EditTextColor:TColor read FEditText_xf write FEditText_xf;
    end;

    TCCComponent=class(TCustomControl)
      protected
        FDarstellungsOptionen_xccd:TCCDarstellungsSteuerung;
        FMouseOut,FMouseIn:TNotifyEvent;
        FHoverLeaveMessages_b:boolean;
      public
        property Canvas;

        constructor Create(AOwner_xc:TComponent);override;
        destructor Destroy;override;
        procedure setDarstellung(dar_xccd:TCCDarstellungsSteuerung);
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;

        procedure drawUpperRect(const x1_i,y1_i,x2_i,y2_i:integer;const dickerRahmen_b:boolean);
        procedure drawLowerButtonRect(const x1_i,y1_i,x2_i,y2_i:integer;const dickerRahmen_b:boolean);
        procedure drawLowerEditRect(const x1_i,y1_i,x2_i,y2_i:integer;const dickerRahmen_b:boolean);
      published
        property DarstellungsOptionen:TCCDarstellungsSteuerung read FDarstellungsOptionen_xccd write setDarstellung;

        //Freigeben von Eigenschaften
        property Enabled;
        property Visible;
        property TabStop;
        property TabOrder;
        property Align;
        property Anchors;
        property Cursor;

        //Freigeben von ungenutzten Eigenschaften
        property ParentColor;
        property ParentFont;

        //Freigeben der Ereignisse von TWinControl
        property OnDockDrop;
	       property OnDockOver;
        property OnEnter;
        property OnExit;
        property OnGetSiteInfo;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnMouseWheel;
        property OnMouseWheelDown;
        property OnMouseWheelUp;
        property OnUnDock;

        //Freigeben der Ereignisse von TControl
        property OnCanResize;
        property OnClick;
        property OnConstrainedResize;
        property OnDblClick;
        property OnDragDrop;
        property OnDragOver;
        property OnEndDock;
        property OnEndDrag;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnResize;
        property OnStartDock;
        property OnStartDrag;

    end;

    TCCVirtualComponent=class(TPersistent)
    protected
      control:TCCComponent;
    public
      left,top,height,width:integer;
      constructor create(aowner:TCCComponent);virtual;
      procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);virtual;abstract;
      procedure MouseMove(Shift: TShiftState; X, Y: Integer);virtual;abstract;
      procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);virtual;abstract;
      procedure KeyDown(var Key: Word; Shift: TShiftState);virtual;abstract;
      procedure KeyPress(var Key: Char);virtual;abstract;
      procedure GotFocus;virtual;abstract;
      procedure LostFocus;virtual;abstract;
      procedure WndProc(var Message: TMessage);virtual;
      procedure paint;virtual;abstract;
  end;
implementation

constructor TCCComponent.Create(aowner_xc:TComponent);
begin
  inherited create(AOwner_xc);
  FDarstellungsOptionen_xccd:=nil;
  TabStop:=true;
end;
destructor TCCComponent.Destroy;
begin
  inherited;
end;
procedure TCCComponent.setDarstellung(dar_xccd:TCCDarstellungsSteuerung);
begin
  FDarstellungsOptionen_xccd:=dar_xccd;
end;
procedure TCCComponent.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if (AComponent=FDarstellungsOptionen_xccd) and (Operation=opRemove) then
    FDarstellungsOptionen_xccd:=nil;
end;
procedure TCCComponent.drawUpperRect(const x1_i,y1_i,x2_i,y2_i:integer;const dickerRahmen_b:boolean);
begin
  if not assigned(DarstellungsOptionen) then begin
    with canvas do begin
      Pen.Color:=clRed;
      pen.Style:=psSolid;
      MoveTo(x1_i,y1_i);LineTo(x2_i,y2_i);
      MoveTo(x1_i,y2_i);LineTo(x2_i,y1_i);
    end;
    exit;
  end;
  with canvas do begin
    brush.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3dFACE);
    brush.Style:=bsSolid;
    Rectangle(x1_i,y1_i,x2_i,y2_i);
    if dickerRahmen_b then begin 
      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DHIGHLIGHT);
      MoveTo(x2_i-1,y1_i);LineTo(x1_i,y1_i);LineTo(x1_i,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DLIGHT);
      MoveTo(x2_i-2,y1_i+1);LineTo(x1_i+1,y1_i+1);LineTo(x1_i+1,y2_i-2);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DDKSHADOW);
      MoveTo(x2_i-1,y1_i+0);LineTo(x2_i-1,y2_i-1);LineTo(x1_i-1,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DSHADOW);
      MoveTo(x2_i-2,y1_i+1);LineTo(x2_i-2,y2_i-2);LineTo(x1_i,y2_i-2);
    end else begin
      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DHIGHLIGHT);
      MoveTo(x2_i-1,y1_i);LineTo(x1_i,y1_i);LineTo(x1_i,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DSHADOW);
      MoveTo(x2_i-1,y1_i+1);LineTo(x2_i-1,y2_i-1);LineTo(x1_i-1,y2_i-1);

    {  pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DLIGHT);
      MoveTo(x2_i-2,y1_i+2);LineTo(x2_i-2,y2_i-2);LineTo(x1_i,y2_i-2);            }
    end;
  end;
end;
procedure TCCComponent.drawLowerButtonRect(const x1_i,y1_i,x2_i,y2_i:integer;const dickerRahmen_b:boolean);
begin
  if not assigned(DarstellungsOptionen) then begin
    with canvas do begin
      Pen.Color:=clRed;
      pen.Style:=psSolid;
      MoveTo(x1_i,y1_i);LineTo(x2_i,y2_i);
      MoveTo(x1_i,y2_i);LineTo(x2_i,y1_i);
    end;
    exit;
  end;
  with canvas do begin
    if brush.Style<>bsClear then begin
      brush.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_BTNFACE);
      Rectangle(x1_i,y1_i,x2_i,y2_i);
    end;
    if dickerRahmen_b then begin
      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DDKSHADOW);
      MoveTo(x2_i-1,y1_i);LineTo(x1_i,y1_i);LineTo(x1_i,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DSHADOW);
      MoveTo(x2_i-2,y1_i+1);LineTo(x1_i+1,y1_i+1);LineTo(x1_i+1,y2_i-2);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DHIGHLIGHT);
      MoveTo(x2_i-1,y1_i+1);LineTo(x2_i-1,y2_i-1);LineTo(x1_i-1,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DLIGHT);
      MoveTo(x2_i-2,y1_i+2);LineTo(x2_i-2,y2_i-2);LineTo(x1_i,y2_i-2);
    end else begin
      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DSHADOW);
      MoveTo(x2_i-1,y1_i);LineTo(x1_i,y1_i);LineTo(x1_i,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DHIGHLIGHT);
      MoveTo(x2_i-1,y1_i+1);LineTo(x2_i-1,y2_i-1);LineTo(x1_i-1,y2_i-1);

    {  pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DLIGHT);
      MoveTo(x2_i-2,y1_i+2);LineTo(x2_i-2,y2_i-2);LineTo(x1_i,y2_i-2);            }
    end;
  end;
end;
procedure TCCComponent.drawLowerEditRect(const x1_i,y1_i,x2_i,y2_i:integer;const dickerRahmen_b:boolean);
begin
  if not assigned(DarstellungsOptionen) then begin
    with canvas do begin
      Pen.Color:=clRed;
      pen.Style:=psSolid;
      MoveTo(x1_i,y1_i);LineTo(x2_i,y2_i);
      MoveTo(x1_i,y2_i);LineTo(x2_i,y1_i);
    end;
    exit;
  end;
  with canvas do begin
    if brush.Style<>bsClear then begin
      brush.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_WINDOW);
      Rectangle(x1_i,y1_i,x2_i,y2_i);
    end;
    if dickerRahmen_b then begin
      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DSHADOW);
      MoveTo(x2_i-1,y1_i);LineTo(x1_i,y1_i);LineTo(x1_i,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DDKSHADOW);
      MoveTo(x2_i-2,y1_i+1);LineTo(x1_i+1,y1_i+1);LineTo(x1_i+1,y2_i-2);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DHIGHLIGHT);
      MoveTo(x2_i-1,y1_i+1);LineTo(x2_i-1,y2_i-1);LineTo(x1_i-1,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DLIGHT);
      MoveTo(x2_i-2,y1_i+2);LineTo(x2_i-2,y2_i-2);LineTo(x1_i,y2_i-2);
    end else begin
      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DSHADOW);
      MoveTo(x2_i-1,y1_i);LineTo(x1_i,y1_i);LineTo(x1_i,y2_i-1);

      pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DHIGHLIGHT);
      MoveTo(x2_i-1,y1_i+1);LineTo(x2_i-1,y2_i-1);LineTo(x1_i-1,y2_i-1);

    {  pen.Color:=DarstellungsOptionen.getColorFromWindowColorKey(COLOR_3DLIGHT);
      MoveTo(x2_i-2,y1_i+2);LineTo(x2_i-2,y2_i-2);LineTo(x1_i,y2_i-2);            }
    end;
  end;
end;

constructor TCCDarstellungsSteuerung.create(AOwner_xc:TComponent);
begin
  inherited;
  OberflaecheVon3DObjekten:=GetSysColor(COLOR_3DFACE);
  Licht:=GetSysColor(COLOR_3DLIGHT);
  Glanz:=GetSysColor(COLOR_3DHIGHLIGHT);
  Schatten:=GetSysColor(COLOR_3DSHADOW);
  DunklerSchatten:=GetSysColor(COLOR_3DDKSHADOW);
  ButtonText:=GetSysColor(COLOR_BTNTEXT);
//ScrollBarText:=GetSysColor(COLOR_CAPTIONTEXT);
  ScrollBarFarbe1:=GetSysColor(COLOR_SCROLLBAR);
  ScrollBarFarbe2:=AufHellenDurchAddition(GetSysColor(COLOR_SCROLLBAR),100);
  FEdit_xf:=GetSysColor(COLOR_WINDOW);
  FDisableText1_xf:=GetSysColor(COLOR_GRAYTEXT);
  FDisableText2_xf:=AufHellenDurchAddition(GetSysColor(COLOR_GRAYTEXT),100);
  FHighlight_xf:=GetSysColor(COLOR_HIGHLIGHT);
  FHighlighttext_xf:=GetSysColor(COLOR_HIGHLIGHTTEXT);
  FEditText_xf:=GetSysColor(COLOR_WINDOWTEXT);
//  FDarstellung_xccd:=TCCDarstellung.create(nil);
end;
destructor TCCDarstellungsSteuerung.destroy;
begin
 // FDarstellung_xccd.Free;
  inherited;
end;
function TCCDarstellungsSteuerung.getColorFromWindowColorKey(wert_i:integer):TColor;
begin
  if FDarstellungsMode_xccdm=ccdmNormal then
    result:=getSysColor(wert_i)
   else
    case wert_i of
      COLOR_3DDKSHADOW: Result:=FDunklerSchatten_xf;
      COLOR_3DFACE: result:=FOberflaecheVon3DObjekten_xf;
//      COLOR_BTNFACE: Result:=FOberflaecheVonDialogen_xf;
      COLOR_3DHIGHLIGHT{,COLOR_3DHILIGHT,COLOR_BTNHIGHLIGHT,COLOR_BTNHILIGHT}: Result:=F3DGlanz_xf;
      color_3dlight: Result:=f3dlicht_xf;
      COLOR_3DSHADOW: Result:=F3DSchatten_xf;
      COLOR_BTNTEXT: Result:=FButtonText_xf;
//    COLOR_CAPTIONTEXT: Result:=FScrollBar_xf;
      COLOR_SCROLLBAR: Result:=FScrollBarBk1_xf;
      color_window: Result:=FEdit_xf;
      COLOR_HIGHLIGHT: Result:=FHighlight_xf;
      COLOR_HIGHLIGHTTEXT: Result:=FHighlighttext_xf;
      COLOR_GRAYTEXT: Result:=FDisableText1_xf;
      COLOR_WINDOWTEXT:result:=FEditText_xf;
      else result:=getSysColor(wert_i);
    end;
end;
function TCCDarstellungsSteuerung.getAlternativColorFromWindowColorKey(wert_i,nr_i:integer):TColor;
begin
  if (wert_i<>color_scrollbar)and(wert_i<>color_graytext) then
    result:=getColorFromWindowColorKey(wert_i)
   else begin
     if wert_i=color_graytext then begin
       case nr_i of
        1:if (DarstellungsMode=ccdmNormal) then
           result:=SetHelligkeit(GetSysColor(COLOR_GRAYTEXT),100)
          else
           result:=FDisableText2_xf;
        else Result:=getColorFromWindowColorKey(wert_i);
       end;
     end else begin
       case nr_i of
        1:if (DarstellungsMode=ccdmNormal) then
           result:=AufHellenDurchAddition(GetSysColor(COLOR_SCROLLBAR),100)
          else
           result:=FScrollBarBk2_xf;
        2:if (DarstellungsMode=ccdmNormal) then
           result:=GetSysColor(COLOR_BTNTEXT)
          else
           result:=FScrollBarScroll_xf;
        else result:=getColorFromWindowColorKey(wert_i);
       end;
     end;
  end;
end;

constructor TCCVirtualComponent.create(aowner:TCCComponent);
begin
  control:=aowner;
  width:=control.Width;
  height:=control.Height;
  left:=0;
  top:=0;
end;
procedure TCCVirtualComponent.WndProc(var Message: TMessage);
begin
  case message.Msg of
    WM_SIZE: begin
               width:=TWMSize(message).Width;
               height:=TWMSize(message).Height;
             end;
  end;
end;
end.
