diff --git a/.gitattributes b/.gitattributes index 3e3659295a..2c0db3f002 100644 --- a/.gitattributes +++ b/.gitattributes @@ -647,6 +647,7 @@ components/customdrawn/customdrawn_win2000.pas svneol=native#text/plain components/customdrawn/customdrawn_wince.pas svneol=native#text/plain components/customdrawn/customdrawn_winxp.pas svneol=native#text/plain components/customdrawn/customdrawncontrols.pas svneol=native#text/pascal +components/customdrawn/customdrawndrawers.pas svneol=native#text/plain components/customdrawn/customdrawnextras.pas svneol=native#text/plain components/customdrawn/customdrawnutils.pas svneol=native#text/pascal components/customform/custforms.pp svneol=native#text/plain diff --git a/components/customdrawn/customdrawn.lpk b/components/customdrawn/customdrawn.lpk index 0fc0511cc3..b9b5dbf64b 100644 --- a/components/customdrawn/customdrawn.lpk +++ b/components/customdrawn/customdrawn.lpk @@ -17,7 +17,7 @@ - + @@ -63,6 +63,10 @@ + + + + diff --git a/components/customdrawn/customdrawn.pas b/components/customdrawn/customdrawn.pas index 7d7d8f5809..922c09024c 100644 --- a/components/customdrawn/customdrawn.pas +++ b/components/customdrawn/customdrawn.pas @@ -10,7 +10,7 @@ uses customdrawnextras, customdrawnutils, customdrawncontrols, customdrawn_wince, customdrawn_win2000, customdrawn_winxp, customdrawn_android, customdrawn_extra1, customdrawn_kde, customdrawn_gnome, customdrawn_common, - LazarusPackageIntf; + customdrawndrawers, LazarusPackageIntf; implementation diff --git a/components/customdrawn/customdrawn_android.pas b/components/customdrawn/customdrawn_android.pas index 99b8263e04..b9c29bd04b 100644 --- a/components/customdrawn/customdrawn_android.pas +++ b/components/customdrawn/customdrawn_android.pas @@ -14,16 +14,16 @@ uses // customdrawncontrols, customdrawnutils; -type +{type TCDButtonDrawerAndroid = class(TCDButtonDrawer) public procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override; procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override; - end; + end;} implementation -procedure TCDButtonDrawerAndroid.DrawToIntfImage(ADest: TFPImageCanvas; +{procedure TCDButtonDrawerAndroid.DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); begin @@ -66,6 +66,6 @@ begin end; initialization - RegisterButtonDrawer(TCDButtonDrawerAndroid.Create, dsAndroid); + RegisterButtonDrawer(TCDButtonDrawerAndroid.Create, dsAndroid);} end. diff --git a/components/customdrawn/customdrawn_common.pas b/components/customdrawn/customdrawn_common.pas index 9ffaeca410..02387031b1 100644 --- a/components/customdrawn/customdrawn_common.pas +++ b/components/customdrawn/customdrawn_common.pas @@ -6,69 +6,67 @@ interface uses // RTL - Classes, SysUtils, + Classes, SysUtils, Types, // fpimage fpcanvas, fpimgcanv, fpimage, // LCL -> Use only TForm, TWinControl, TCanvas and TLazIntfImage - Graphics, Controls, LCLType, LCLIntf, IntfGraphics, + Graphics, Controls, LCLType, LCLIntf, //IntfGraphics, // Others only for types StdCtrls, // - customdrawncontrols, customdrawnutils; + customdrawndrawers; type - TCDButtonDrawerCommon = class(TCDButtonDrawer) - public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override; - procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override; - end; - { TCDEditDrawerCommon } + { TCDDrawerCommon } - TCDEditDrawerCommon = class(TCDEditDrawer) + TCDDrawerCommon = class(TCDDrawer) public + // General function GetMeasures(AMeasureID: Integer): Integer; override; + function GetMeasuresEx(ADest: TCanvas; AMeasureID: Integer; + AState: TCDControlState; AStateEx: TCDControlStateEx): Integer; override; function GetColor(AColorID: Integer): TColor; override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDControl: TCDControl); override; - procedure DrawBackground(ADest: TCanvas; AControl: TCDControl); override; - procedure DrawToCanvas(ADest: TCanvas; CDControl: TCDControl); override; - end; - - { TCDCheckBoxDrawerCommon } - - TCDCheckBoxDrawerCommon = class(TCDCheckBoxDrawer) - public - function GetCaptionWidth(CDCheckBox: TCDCheckBox): Integer; - function GetCaptionHeight(CDCheckBox: TCDCheckBox): Integer; - procedure CalculatePreferredSize(CDCheckBox: TCDCheckBox; var PreferredWidth, - PreferredHeight: integer; WithThemeSpace: Boolean); override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDCheckBox: TCDCheckBox); override; - procedure DrawToCanvas(ADest: TCanvas; CDCheckBox: TCDCheckBox); override; - end; - - TCDGroupBoxDrawerCommon = class(TCDGroupBoxDrawer) - public - FCaptionMiddle: integer; - procedure SetClientRectPos(CDGroupBox: TCDGroupBox); override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDGroupBox: TCDGroupBox); override; - procedure DrawToCanvas(ADest: TCanvas; CDGroupBox: TCDGroupBox); override; - end; - - // =================================== - // Common Controls Tab - // =================================== - - { TCDListViewDrawerCommon } - - TCDListViewDrawerCommon = class(TCDListViewDrawer) - public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDListView: TCDListView); override; - procedure DrawToCanvas(ADest: TCanvas; CDListView: TCDListView); override; + procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx); override; + // =================================== + // Standard Tab + // =================================== + // TCDButton + procedure DrawButton(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDControlStateEx); override; + // TCDEdit + procedure CreateEditBackgroundBitmap(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDEditStateEx); override; + procedure DrawEdit(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDEditStateEx); override; + // TCDCheckBox + procedure CalculateCheckBoxPreferredSize(ADest: TCanvas; + AState: TCDControlState; AStateEx: TCDControlStateEx; + var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; + procedure DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDControlStateEx); override; + // TCDGroupBox + procedure DrawGroupBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDControlStateEx); override; + // =================================== + // Common Controls Tab + // =================================== + // TCDCustomTabControl + procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override; + procedure DrawTabSheet(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override; + procedure DrawTabs(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override; + procedure DrawTab(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override; + function GetPageIndexFromXY(x, y: integer): integer; override; end; { TCDCustomTabControlDrawerCommon } - TCDCustomTabControlDrawerCommon = class(TCDCustomTabControlDrawer) +{ TCDCustomTabControlDrawerCommon = class(TCDCustomTabControlDrawer) private StartIndex: integer; //FEndIndex LeftmostTabVisibleIndex: Integer; @@ -79,7 +77,6 @@ type function GetPageIndexFromXY(x, y: integer): integer; override; function GetTabHeight(AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; override; function GetTabWidth(ADest: TCanvas; AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; override; - //function GetClientRect(AControl: TCDControl): TRect; override; procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage; CDTabControl: TCDCustomTabControl); override; procedure DrawToCanvas(ADest: TCanvas; CDTabControl: TCDCustomTabControl); override; @@ -88,13 +85,285 @@ type X, Y: integer; CDTabControl: TCDCustomTabControl); override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer; CDTabControl: TCDCustomTabControl); override; - end; + end;} implementation +{ TCDDrawerCommon } + +function TCDDrawerCommon.GetMeasures(AMeasureID: Integer): Integer; +begin + case AMeasureID of + TCDEDIT_LEFT_TEXT_SPACING: Result := 4; + TCDEDIT_RIGHT_TEXT_SPACING: Result := 3; + else + Result := 0; + end; +end; + +function TCDDrawerCommon.GetMeasuresEx(ADest: TCanvas; AMeasureID: Integer; + AState: TCDControlState; AStateEx: TCDControlStateEx): Integer; +const + TCDTabControl_Common_TabCaptionExtraWidth = 20; +var + ATabsStateEx: TCDCTabControlStateEx absolute AStateEx; + lCaption: String; +begin + case AMeasureID of + TCDCONTROL_CAPTION_WIDTH: Result := ADest.TextWidth(AStateEx.Caption); + TCDCONTROL_CAPTION_HEIGHT: Result := ADest.TextHeight('ŹÇ')+3; + TCDCTABCONTROL_TAB_HEIGHT: + begin + if AStateEx.Font.Size = 0 then Result := 32 + else Result := AStateEx.Font.Size + 22; + end; + TCDCTABCONTROL_TAB_WIDTH: + begin + lCaption := ATabsStateEx.Tabs.Strings[ATabsStateEx.TabIndex]; + Result := ADest.TextWidth(lCaption) + TCDTabControl_Common_TabCaptionExtraWidth; + end + else + Result := 0; + end; +end; + +function TCDDrawerCommon.GetColor(AColorID: Integer): TColor; +begin + case AColorId of + TCDEDIT_BACKGROUND_COLOR: Result := clWhite; + TCDEDIT_TEXT_COLOR: Result := clBlack; + TCDEDIT_SELECTED_BACKGROUND_COLOR: Result := clBlue; + TCDEDIT_SELECTED_TEXT_COLOR: Result := clWhite; + else + Result := clBlack; + end; +end; + +procedure TCDDrawerCommon.DrawControl(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AControl: TCDControlID; AState: TCDControlState; + AStateEx: TCDControlStateEx); +begin + case AControl of + cidButton: DrawButton(ADest, ADestPos, ASize, AState, AStateEx); + end; +end; + +procedure TCDDrawerCommon.DrawButton(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); +var + TmpB: TBitmap; + Str: string; +begin + // Button shape -> This crashes in Gtk2 + TmpB := TBitmap.Create; + TmpB.Width := ASize.cx; + TmpB.Height := ASize.cy; + TmpB.Canvas.Brush.Color := AStateEx.RGBColor; + TmpB.Canvas.Brush.Style := bsSolid; + TmpB.Canvas.RoundRect(0, 0, TmpB.Width, TmpB.Height, 8, 8); + // CDButton.SetShape(TmpB); + + // Button image + if csfSunken in AState then + begin + TmpB.Canvas.Brush.Style := bsSolid; + TmpB.Canvas.Brush.Color := RGBToColor(230, 230, 230); + TmpB.Canvas.Pen.Color := clBlack; + TmpB.Canvas.Pen.Style := psSolid; + TmpB.Canvas.Rectangle(0, 0, TmpB.Canvas.Width, TmpB.Canvas.Height); + end + else if csfHasFocus in AState then + begin + with TmpB.Canvas do + begin + Brush.Style := bsSolid; + Brush.Color := RGBToColor($FD, $FD, $FD); + Pen.Color := clBlack; + Pen.Style := psSolid; + Rectangle(0, 0, Width, Height); + Rectangle(1, 1, Width - 1, Height - 1); // The border is thicken when focused + end; + end + else + begin + with TmpB.Canvas do + begin + Brush.Style := bsSolid; + Brush.Color := AStateEx.RGBColor; + Pen.Color := clBlack; + Pen.Style := psSolid; + Rectangle(0, 0, Width, Height); + end; + end; + + ADest.Draw(0, 0, TmpB); + + TmpB.Free; + + // Button text + ADest.Font.Assign(AStateEx.Font); + ADest.Brush.Style := bsClear; + ADest.Pen.Style := psSolid; + Str := AStateEx.Caption; + ADest.TextOut((ASize.cx - ADest.TextWidth(Str)) div 2, + (ASize.cy - ADest.TextHeight(Str)) div 2, Str); +end; + +procedure TCDDrawerCommon.CreateEditBackgroundBitmap(ADest: TCanvas; + ADestPos: TPoint; ASize: TSize; AState: TCDControlState; + AStateEx: TCDEditStateEx); +begin + // The background + ADest.Brush.Color := clWhite; + ADest.Brush.Style := bsSolid; + ADest.Pen.Color := clBlack; + ADest.Pen.Style := psSolid; + ADest.Rectangle(0, 0, ASize.cx, ASize.cy); +end; + +procedure TCDDrawerCommon.DrawEdit(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDEditStateEx); +begin + +end; + +procedure TCDDrawerCommon.CalculateCheckBoxPreferredSize(ADest: TCanvas; + AState: TCDControlState; AStateEx: TCDControlStateEx; var PreferredWidth, + PreferredHeight: integer; WithThemeSpace: Boolean); +begin + PreferredWidth := 0; + + if AStateEx.AutoSize then + PreferredWidth := 21 + GetMeasuresEx(ADest, TCDCONTROL_CAPTION_WIDTH, AState, AStateEx); + + PreferredHeight := GetMeasuresEx(ADest, TCDCONTROL_CAPTION_HEIGHT, AState, AStateEx); +end; + +procedure TCDDrawerCommon.DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); +const + CDCheckBoxCommon_Half_Height = 7; + CDCheckBoxCommon_Height = 15; +var + lHalf: Integer; + lColor: TColor; + i: Integer; +begin + lHalf := ASize.cy div 2; + + // Background + lColor := AStateEx.ParentRGBColor; + ADest.Brush.Color := lColor; + ADest.Brush.Style := bsSolid; + ADest.Pen.Style := psClear; + ADest.FillRect(0, 0, ASize.cx, ASize.cy); + + // The checkbox item itself + ADest.Brush.Color := clWhite; + ADest.Pen.Style := psSolid; + if csfSunken in AState then ADest.Pen.Color := clGray + else ADest.Pen.Color := clBlack; + ADest.Rectangle( + 1, + lHalf - CDCheckBoxCommon_Half_Height, + CDCheckBoxCommon_Height+1, + lHalf + CDCheckBoxCommon_Half_Height); + + // The Tickmark + if csfOn in AState then + begin + // 4 lines going down and to the right + for i := 0 to 3 do + ADest.Line(5+i, lHalf - CDCheckBoxCommon_Half_Height+5+i, 5+i, lHalf - CDCheckBoxCommon_Half_Height+8+i); + // Now 5 lines going up and to the right + for i := 4 to 8 do + ADest.Line(5+i, lHalf - CDCheckBoxCommon_Half_Height+5+6-i, 5+i, lHalf - CDCheckBoxCommon_Half_Height+8+6-i); + end; + + // The selection + ADest.Brush.Style := bsClear; + ADest.Pen.Color := RGBToColor($31, $C6, $D6); + ADest.Pen.Style := psSolid; + if csfHasFocus in AState then + begin + // The selection inside the square + ADest.Rectangle( + 2, + lHalf - CDCheckBoxCommon_Half_Height+1, + CDCheckBoxCommon_Height, + lHalf + CDCheckBoxCommon_Half_Height-1); + + // Selection around the text + ADest.Rectangle( + CDCheckBoxCommon_Height+4, 0, + ASize.cx, ASize.cy); + end; + + // Now the text + ADest.Font.Assign(AStateEx.Font); + ADest.TextOut(CDCheckBoxCommon_Height+5, 0, AStateEx.Caption); +end; + +procedure TCDDrawerCommon.DrawGroupBox(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); +var + FCaptionMiddle: integer; +begin + FCaptionMiddle := ADest.TextHeight('Ź') div 2; + if FCaptionMiddle = 0 then FCaptionMiddle := AStateEx.Font.Size div 2; + if FCaptionMiddle = 0 then FCaptionMiddle := 5; + + // Background + ADest.Brush.Color := AStateEx.ParentRGBColor; + ADest.Brush.Style := bsSolid; + ADest.Pen.Style := psClear; + ADest.Rectangle(0, 0, ASize.cx, ASize.cy); + + // frame + ADest.Pen.FPColor := colBlack; + ADest.Pen.Style := psSolid; + ADest.Brush.Style := bsClear; + ADest.Rectangle(0, FCaptionMiddle, ASize.cx - 1, ASize.cy - 1); + + // paint text + ADest.Pen.Style := psSolid; + ADest.Brush.Style := bsSolid; // This will fill the text background + ADest.Font.Size := 10; + ADest.TextOut(FCaptionMiddle, 0, AStateEx.Caption); +end; + +procedure TCDDrawerCommon.DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx); +begin + +end; + +procedure TCDDrawerCommon.DrawTabSheet(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx); +begin + +end; + +procedure TCDDrawerCommon.DrawTabs(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx); +begin + +end; + +procedure TCDDrawerCommon.DrawTab(ADest: TCanvas; ADestPos: TPoint; + ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx); +begin + +end; + +function TCDDrawerCommon.GetPageIndexFromXY(x, y: integer): integer; +begin + +end; + { TCDListViewDrawerCommon } -procedure TCDListViewDrawerCommon.DrawToIntfImage(ADest: TFPImageCanvas; +(*procedure TCDListViewDrawerCommon.DrawToIntfImage(ADest: TFPImageCanvas; CDListView: TCDListView); begin @@ -106,47 +375,6 @@ begin end; -{ TCDEditDrawerCommon } - -function TCDEditDrawerCommon.GetMeasures(AMeasureID: Integer): Integer; -begin - case AMeasureID of - TCDEDIT_LEFT_TEXT_SPACING: Result := 4; - TCDEDIT_RIGHT_TEXT_SPACING: Result := 3; - else - Result := inherited GetMeasures(AMeasureID); - end; -end; - -function TCDEditDrawerCommon.GetColor(AColorID: Integer): TColor; -begin - case AColorId of - TCDEDIT_BACKGROUND_COLOR: Result := clWhite; - TCDEDIT_TEXT_COLOR: Result := clBlack; - TCDEDIT_SELECTED_BACKGROUND_COLOR: Result := clBlue; - TCDEDIT_SELECTED_TEXT_COLOR: Result := clWhite; - else - Result := inherited GetColor(AColorId); - end; -end; - -procedure TCDEditDrawerCommon.DrawToIntfImage(ADest: TFPImageCanvas; - CDControl: TCDControl); -begin - -end; - -procedure TCDEditDrawerCommon.DrawBackground(ADest: TCanvas; - AControl: TCDControl); -begin - // The background - ADest.Brush.Color := clWhite; - ADest.Brush.Style := bsSolid; - ADest.Pen.Color := clBlack; - ADest.Pen.Style := psSolid; - ADest.Rectangle(0, 0, AControl.Width, AControl.Height); -end; - procedure TCDEditDrawerCommon.DrawToCanvas(ADest: TCanvas; CDControl: TCDControl); var CDEdit: TCDEdit absolute CDControl; @@ -214,175 +442,6 @@ begin end; end; -{ TCDCheckBoxDrawerCommon } - -function TCDCheckBoxDrawerCommon.GetCaptionWidth(CDCheckBox: TCDCheckBox - ): Integer; -begin - CDCheckBox.Canvas.Font.Assign(CDCheckBox.Font); - Result := CDCheckBox.Canvas.TextWidth(CDCheckBox.Caption); -end; - -function TCDCheckBoxDrawerCommon.GetCaptionHeight(CDCheckBox: TCDCheckBox - ): Integer; -begin - CDCheckBox.Canvas.Font.Assign(CDCheckBox.Font); - Result := CDCheckBox.Canvas.TextHeight('ŹÇ')+3; -end; - -procedure TCDCheckBoxDrawerCommon.CalculatePreferredSize( - CDCheckBox: TCDCheckBox; var PreferredWidth, PreferredHeight: integer; - WithThemeSpace: Boolean); -begin - PreferredWidth := 0; - - if CDCheckBox.AutoSize then - PreferredWidth := 21 + GetCaptionWidth(CDCheckBox); - - PreferredHeight := GetCaptionHeight(CDCheckBox); -end; - -procedure TCDCheckBoxDrawerCommon.DrawToIntfImage(ADest: TFPImageCanvas; - CDCheckBox: TCDCheckBox); -begin - -end; - -procedure TCDCheckBoxDrawerCommon.DrawToCanvas(ADest: TCanvas; - CDCheckBox: TCDCheckBox); -const - CDCheckBoxCommon_Half_Height = 7; - CDCheckBoxCommon_Height = 15; -var - lHalf: Integer; - lColor: TColor; - i: Integer; -begin - lHalf := CDCheckBox.Height div 2; - - // Background - lColor := CDCheckBox.GetRGBBackgroundColor(); - ADest.Brush.Color := lColor; - ADest.Brush.Style := bsSolid; - ADest.Pen.Style := psClear; - ADest.FillRect(0, 0, CDCheckBox.Width, CDCheckBox.Height); - - // The checkbox item itself - ADest.Brush.Color := clWhite; - ADest.Pen.Style := psSolid; - if CDCheckBox.IsDown then ADest.Pen.Color := clGray - else ADest.Pen.Color := clBlack; - ADest.Rectangle( - 1, - lHalf - CDCheckBoxCommon_Half_Height, - CDCheckBoxCommon_Height+1, - lHalf + CDCheckBoxCommon_Half_Height); - - // The Tickmark - if CDCheckBox.State = cbChecked then - begin - // 4 lines going down and to the right - for i := 0 to 3 do - ADest.Line(5+i, lHalf - CDCheckBoxCommon_Half_Height+5+i, 5+i, lHalf - CDCheckBoxCommon_Half_Height+8+i); - // Now 5 lines going up and to the right - for i := 4 to 8 do - ADest.Line(5+i, lHalf - CDCheckBoxCommon_Half_Height+5+6-i, 5+i, lHalf - CDCheckBoxCommon_Half_Height+8+6-i); - end; - - // The selection - ADest.Brush.Style := bsClear; - ADest.Pen.Color := RGBToColor($31, $C6, $D6); - ADest.Pen.Style := psSolid; - if CDCheckBox.Focused then - begin - // The selection inside the square - ADest.Rectangle( - 2, - lHalf - CDCheckBoxCommon_Half_Height+1, - CDCheckBoxCommon_Height, - lHalf + CDCheckBoxCommon_Half_Height-1); - - // Selection around the text - ADest.Rectangle( - CDCheckBoxCommon_Height+4, 0, - CDCheckBox.Width, CDCheckBox.Height); - end; - - // Now the text - ADest.Font.Assign(CDCheckBox.Font); - ADest.TextOut(CDCheckBoxCommon_Height+5, 0, CDCheckBox.Caption); -end; - -{ TCDButtonDrawerCommon } - -procedure TCDButtonDrawerCommon.DrawToIntfImage(ADest: TFPImageCanvas; - CDButton: TCDButton); -begin - -end; - -procedure TCDButtonDrawerCommon.DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); -var - TmpB: TBitmap; - Str: string; -begin - // Button shape -> This crashes in Gtk2 - TmpB := TBitmap.Create; - TmpB.Width := CDButton.Width; - TmpB.Height := CDButton.Height; - TmpB.Canvas.Brush.Color := CDButton.Color; - TmpB.Canvas.Brush.Style := bsSolid; - TmpB.Canvas.RoundRect(0, 0, TmpB.Width, TmpB.Height, 8, 8); - // CDButton.SetShape(TmpB); - - // Button image - if CDButton.IsDown then - begin - TmpB.Canvas.Brush.Style := bsSolid; - TmpB.Canvas.Brush.Color := GetAColor(CDButton.Color, 90); - TmpB.Canvas.Pen.Color := clBlack; - TmpB.Canvas.Pen.Style := psSolid; - TmpB.Canvas.Rectangle(0, 0, TmpB.Canvas.Width, TmpB.Canvas.Height); - end - else if CDButton.Focused then - begin - with TmpB.Canvas do - begin - Brush.Style := bsSolid; - Brush.Color := GetAColor(CDButton.Color, 99); - Pen.Color := clBlack; - Pen.Style := psSolid; - Rectangle(0, 0, Width, Height); - Rectangle(1, 1, Width - 1, Height - 1); // The border is thicken when focused - end; - end - else - begin - with TmpB.Canvas do - begin - Brush.Style := bsSolid; - Brush.Color := CDButton.Color; - Pen.Color := clBlack; - Pen.Style := psSolid; - Rectangle(0, 0, Width, Height); - end; - end; - - ADest.Draw(0, 0, TmpB); - - TmpB.Free; - - // Button text - {$ifndef CUSTOMDRAWN_USE_FREETYPE} - ADest.Font.Assign(CDButton.Font); - ADest.Brush.Style := bsClear; - ADest.Pen.Style := psSolid; - Str := CDButton.Caption; - ADest.TextOut((CDButton.Width - ADest.TextWidth(Str)) div 2, - (CDButton.Height - ADest.TextHeight(Str)) div 2, Str); - {$endif} -end; - { TCDCustomTabControlDrawerCommon } procedure TCDCustomTabControlDrawerCommon.DrawTabs(ADest: TCanvas; CDTabControl: TCDCustomTabControl); @@ -472,26 +531,6 @@ begin Result := 1; end; -function TCDCustomTabControlDrawerCommon.GetTabHeight(AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; -begin - if CDTabControl.Font.Size = 0 then - Result := 32 - else - Result := CDTabControl.Font.Size + 22; -end; - -function TCDCustomTabControlDrawerCommon.GetTabWidth(ADest: TCanvas; - AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; -const - TCDTabControl_Common_TabCaptionExtraWidth = 20; -var - lCaption: string; -begin - lCaption := CDTabControl.Tabs.Strings[AIndex]; - - Result := ADest.TextWidth(lCaption) + TCDTabControl_Common_TabCaptionExtraWidth; -end; - {function TCDCustomTabControlDrawerCommon.GetClientRect(AControl: TCDControl ): TRect; var @@ -553,133 +592,9 @@ begin ADest.Brush.Style := bsSolid; ADest.Pen.Style := psClear; ADest.Rectangle(0, 0, CDTabControl.Width, CDTabControl.Height); -end; - -procedure TCDCustomTabControlDrawerCommon.MouseDown(Button: TMouseButton; - Shift: TShiftState; X, Y: integer; CDTabControl: TCDCustomTabControl); -var - i: Integer; - CurPage: TCDTabSheet; - CurStartLeftPos: Integer = 0; - VisiblePagesStarted: Boolean = False; - lTabWidth: Integer; -begin - for i := 0 to CDTabControl.Tabs.Count - 1 do - begin - if i = LeftmostTabVisibleIndex then - VisiblePagesStarted := True; - - if VisiblePagesStarted then - begin - lTabWidth := GetTabWidth(CDTabControl.Canvas, i, CDTabControl); - if (X > CurStartLeftPos) and - (X < CurStartLeftPos + lTabWidth) and - (Y < GetTabHeight(i, CDTabControl)) then - begin - if CDTabControl is TCDPageControl then - (CDTabControl as TCDPageControl).PageIndex := i - else - CDTabControl.TabIndex := i; - - Exit; - end; - CurStartLeftPos := CurStartLeftPos + lTabWidth; - end; - end; -end; - -procedure TCDCustomTabControlDrawerCommon.MouseUp(Button: TMouseButton; - Shift: TShiftState; X, Y: integer; CDTabControl: TCDCustomTabControl); -begin - -end; - -procedure TCDGroupBoxDrawerCommon.SetClientRectPos(CDGroupBox: TCDGroupBox); -var - lRect: TRect; - lCaptionHeight: integer; -begin - lCaptionHeight := 10; - lRect := Rect(1, lCaptionHeight, CDGroupBox.Width - 1, CDGroupBox.Height - 1); - //CDGroupBox.AdjustClientRect(lRect); -end; - -procedure TCDGroupBoxDrawerCommon.DrawToIntfImage(ADest: TFPImageCanvas; - CDGroupBox: TCDGroupBox); -{$ifdef CUSTOMDRAWN_USE_FREETYPE} -var - AFont: TFreeTypeFont = nil; -{$endif} -begin - FCaptionMiddle := CDGroupBox.Canvas.TextHeight('Ź') div 2; - if FCaptionMiddle = 0 then FCaptionMiddle := CDGroupBox.Canvas.Font.Size div 2; - if FCaptionMiddle = 0 then FCaptionMiddle := 5; - - // Background - if CDGroupBox.Parent = nil then - ADest.Brush.FPColor := colLtGray - else if CDGroupBox.Parent.Color = clDefault then - ADest.Brush.FPColor := TColorToFPColor(ColorToRGB(clForm)) - else - ADest.Brush.FPColor := TColorToFPColor(ColorToRGB(CDGroupBox.Parent.Color)); - ADest.Brush.Style := bsSolid; - ADest.Pen.Style := psClear; - ADest.Rectangle(0, 0, CDGroupBox.Width, CDGroupBox.Height); - - // frame - ADest.Pen.FPColor := colBlack; - ADest.Pen.Style := psSolid; - ADest.Brush.Style := bsClear; - ADest.Rectangle(0, FCaptionMiddle, CDGroupBox.Width - 1, CDGroupBox.Height - 1); - - {$ifdef CUSTOMDRAWN_USE_FREETYPE} - // Caption background and caption - - // initialize free type font manager - opcftfont.InitEngine; - // FontMgr.SearchPath:='/usr/share/fonts/truetype/'; - AFont := TFreeTypeFont.Create; - try - // Text background - ADest.Pen.Style := psClear; - ADest.Brush.Style := bsSolid; - // The brush color was already set previously and is already correct - // ADest.Rectangle(5, 0, AFont.GetTextWidth(CDGroupBox.Caption) + 5, 10); - - // paint text - ADest.Pen.Style := psSolid; - ADest.Brush.Style := bsClear; - ADest.Font := AFont; - ADest.Font.Name := 'Arial'; - ADest.Font.Size := 10; - ADest.TextOut(5, 10, CDGroupBox.Caption); - finally - AFont.Free; - end; - {$endif} -end; - -procedure TCDGroupBoxDrawerCommon.DrawToCanvas(ADest: TCanvas; CDGroupBox: TCDGroupBox); -begin - if CDGroupBox.Parent = nil then - ADest.Brush.Color := clLtGray - else if CDGroupBox.Parent.Color = clDefault then - ADest.Brush.Color := ColorToRGB(clForm) - else - ADest.Brush.Color := ColorToRGB(CDGroupBox.Parent.Color); - - // paint text - ADest.Pen.Style := psSolid; - ADest.Brush.Style := bsSolid; // This will fill the text background - ADest.Font.Size := 10; - ADest.TextOut(FCaptionMiddle, 0, CDGroupBox.Caption); -end; +end;*) initialization - RegisterButtonDrawer(TCDButtonDrawerCommon.Create, dsCommon); - RegisterEditDrawer(TCDEditDrawerCommon.Create, dsCommon); - RegisterGroupBoxDrawer(TCDGroupBoxDrawerCommon.Create, dsCommon); - RegisterCheckBoxDrawer(TCDCheckBoxDrawerCommon.Create, dsCommon); - RegisterCustomTabControlDrawer(TCDCustomTabControlDrawerCommon.Create, dsCommon); + RegisterDrawer(TCDDrawerCommon.Create, dsCommon); end. diff --git a/components/customdrawn/customdrawn_extra1.pas b/components/customdrawn/customdrawn_extra1.pas index 9db8e111d3..f33b6dea88 100644 --- a/components/customdrawn/customdrawn_extra1.pas +++ b/components/customdrawn/customdrawn_extra1.pas @@ -14,7 +14,7 @@ uses // customdrawncontrols, customdrawnutils; -type +{type TCDButtonDrawerGrad = class(TCDButtonDrawer) public procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override; @@ -26,11 +26,11 @@ type procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage; CDTrackBar: TCDTrackBar); override; procedure GetGeometry(var ALeftBorder, ARightBorder: Integer); override; - end; + end;} implementation -procedure TCDButtonDrawerGrad.DrawToIntfImage(ADest: TFPImageCanvas; +{procedure TCDButtonDrawerGrad.DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); begin @@ -197,6 +197,6 @@ end; initialization RegisterButtonDrawer(TCDButtonDrawerGrad.Create, dsExtra1); - RegisterTrackBarDrawer(TCDTrackBarDrawerGraph.Create, dsExtra1); + RegisterTrackBarDrawer(TCDTrackBarDrawerGraph.Create, dsExtra1);} end. diff --git a/components/customdrawn/customdrawn_kde.pas b/components/customdrawn/customdrawn_kde.pas index 6ee121a9ac..60592cee03 100644 --- a/components/customdrawn/customdrawn_kde.pas +++ b/components/customdrawn/customdrawn_kde.pas @@ -14,366 +14,9 @@ uses // Others only for types StdCtrls, // - customdrawncontrols, customdrawnutils; - -type - -{ TCDCustomTabControlDrawerKDE } - - TCDCustomTabControlDrawerKDE = class(TCDCustomTabControlDrawer) - private - StartIndex: integer; //FEndIndex - LeftmostTabVisibleIndex: Integer; - procedure DrawCaptionBar(ADest: TCanvas; lRect: TRect; CL: TColor); - procedure DrawTabs(ADest: TCanvas; CDTabControl: TCDCustomTabControl); - procedure DrawTab(ADest: TCanvas; AIndex: Integer; ACurStartLeftPos: Integer; - CDTabControl: TCDCustomTabControl); - public - function GetPageIndexFromXY(x, y: integer): integer; override; - function GetTabHeight(AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; override; - function GetTabWidth(ADest: TCanvas; AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; override; - //function GetClientRect(AControl: TCDControl): TRect; override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage; - CDTabControl: TCDCustomTabControl); override; - procedure DrawToCanvas(ADest: TCanvas; CDTabControl: TCDCustomTabControl); override; - procedure DrawTabSheet(ADest: TCanvas; CDTabControl: TCDCustomTabControl); override; - procedure MouseDown(Button: TMouseButton; Shift: TShiftState; - X, Y: integer; CDTabControl: TCDCustomTabControl); override; - procedure MouseUp(Button: TMouseButton; Shift: TShiftState; - X, Y: integer; CDTabControl: TCDCustomTabControl); override; - end; + customdrawndrawers, customdrawn_common; implementation -{ TCDCustomTabControlDrawerKDE } - -procedure TCDCustomTabControlDrawerKDE.DrawCaptionBar(ADest: TCanvas; - lRect: TRect; CL: TColor); -begin - { CaptionHeight := GetTabHeight(CDPageControl.PageIndex, CDPageControl) - 4; - RButtHeight := GetTabHeight(CDPageControl.PageIndex, CDPageControl); - aRect := lRect; - ADest.Pen.Style := psSolid; - ADest.Brush.Style := bsSolid; - ADest.Pen.FPColor := TColorToFPColor(ColorToRGB(CL)); - //TColorToFPColor(ColorToRGB($009C9B91)); - ADest.Brush.FPColor := TColorToFPColor(ColorToRGB(CL)); - aRect.Left := lRect.Left; - aRect.Top := lRect.Top; - aRect.Bottom := lRect.Bottom; - aRect.Right := lRect.Right; - ADest.RecTangle(lRect); - if CDPageControl.FPages.Count = 0 then - begin - ADest.Brush.Color := clWhite; - ADest.Pen.Color := $009C9B91; - ADest.RecTangle(Rect(aRect.Left, aRect.Top, aRect.Right + 1, aRect.Bottom + 2)); - ADest.Pen.Color := clWhite; - ADest.Line(aRect.Left + 1, aRect.Bottom + 1, aRect.Right, aRect.Bottom + 1); - Exit; - end; - aRect.Left := lRect.Left + 2; - aRect.Top := lRect.Top + 3; - //ADest.TextStyle.Opaque :=false; - //SetBkMode(ADest.Handle, TRANSPARENT); - if ADest.Brush.Style = bsSolid then - SetBkMode(ADest.Handle, OPAQUE) - else - SetBkMode(ADest.Handle, TRANSPARENT); - - for i := StartIndex to CDPageControl.FPages.Count - 1 do - begin - aText := CDPageControl.FPages[i].TabPage.Caption; - rWidth := (CaptionHeight - ADest.TextHeight(aText)) + ADest.TextWidth(aText); - CDPageControl.FPages[i].Width := rWidth; - if aRect.Left + rWidth > lRect.Right - 6 then - Break - else - aRect.Right := aRect.Left + rWidth; - if CDPageControl.PageIndex = i then - begin - cRect := aRect; - if i = StartIndex then - cRect.Left := aRect.Left - 2 - else - cRect.Left := aRect.Left - 4; - cRect.Right := aRect.Right + 4; - cRect.Top := cRect.Top - 2; - bText := CDPageControl.FPages[i].TabPage.Caption; - end - else - DrawTabHead(aDest, aRect, CDPageControl.Color, False); - MaskColor := MaskBaseColor + i - StartIndex; - //DrawTabHeadMask(MaskHeadBmp.Canvas, aRect, MaskColor, False); - ADest.TextOut(aRect.Left + (aRect.Right - aRect.Left - ADest.TextWidth(aText)) div 2, - aRect.Top + (aRect.Bottom - aRect.Top - ADest.TextHeight(aText)) div 2, aText); - aRect.Left := aRect.Right + 3; - end; - ADest.Line(lRect.Left, lRect.Bottom - 1, cRect.Left, lRect.Bottom - 1); - ADest.Line(cRect.Right, lRect.Bottom - 1, lRect.Right, lRect.Bottom - 1); - DrawTabHead(aDest, cRect, clWhite, True); - ADest.TextOut(cRect.Left + (cRect.Right - cRect.Left - ADest.TextWidth(bText)) div 2, - cRect.Top + (cRect.Bottom - cRect.Top - ADest.TextHeight(bText)) div 2, bText); - if not CheckTabButton(lRect.Right - lRect.Left, CDPageControl.FPages) then - Exit; - aRect.Left := lRect.Right - RButtHeight * 2 - 3; - aRect.Top := 1; - aRect.Bottom := RButtHeight + 1; - aRect.Right := lRect.Right - RButtHeight; - //if FMDownL then - // GradFill(ADest, aRect, $00F1A079, $00EFAF9B) - //else - GradFill(ADest, aRect, $00FDD9CB, $00F2C9B8); - aRect.Left := lRect.Right - RButtHeight - 1; - aRect.Top := 1; - aRect.Bottom := RButtHeight + 1; - aRect.Right := lRect.Right; - - GradFill(ADest, aRect, $00FDD9CB, $00F2C9B8); - - ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($0085614D)); - bRect.Top := 1; - bRect.Left := lRect.Right - RButtHeight * 2 - 3; - bRect.Right := lRect.Right; - bRect.Bottom := RButtHeight + 1; - DrawArrow(ADest, bRect, True); - DrawArrow(ADest, bRect, False); - ADest.Pen.FPColor := TColorToFPColor(ColorToRGB(clWhite)); - ADest.Line(lRect.Right - RButtHeight * 2 - 3, 1, lRect.Right, 1); - ADest.Line(lRect.Right, 1, lRect.Right, RButtHeight + 1); - ADest.Line(lRect.Right, RButtHeight + 1, lRect.Right - RButtHeight * - 2 - 3, RButtHeight + 1); - ADest.Line(lRect.Right - RButtHeight * 2 - 3, RButtHeight + 1, - lRect.Right - RButtHeight * 2 - 3, 1); - ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($00E5BAA7)); - ADest.Brush.Style := bsClear; - ADest.Rectangle(lRect.Right - RButtHeight * 2 - 2, 2, lRect.Right - - 1, RButtHeight + 1); - CornerColor := TColorToFPColor(ColorToRGB($00F6E3D9)); - ADest.Colors[lRect.Right - RButtHeight * 2 - 2, 2] := CornerColor; - ADest.Colors[lRect.Right - RButtHeight * 2 - 2, RButtHeight] := CornerColor; - ADest.Colors[lRect.Right - 1, 2] := CornerColor; - ADest.Colors[lRect.Right - 1, RButtHeight] := CornerColor; - ADest.Pen.FPColor := TColorToFPColor(ColorToRGB(clWhite)); - ADest.Line(lRect.Right - 51, 1, lRect.Right, 1); - ADest.Line(lRect.Right, 1, lRect.Right, 25); - ADest.Line(lRect.Right, 25, lRect.Right - 51, 25); - ADest.Line(lRect.Right - 51, 25, lRect.Right - 51, 1); - ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($00FFFFFF));} -end; - -procedure TCDCustomTabControlDrawerKDE.DrawTabs(ADest: TCanvas; CDTabControl: TCDCustomTabControl); -var - IsPainting: Boolean = False; - CurStartLeftPos: Integer = 0; - i: Integer; -begin - for i := 0 to CDTabControl.Tabs.Count - 1 do - begin - if i = LeftmostTabVisibleIndex then - IsPainting := True; - - if IsPainting then - begin - DrawTab(ADest, i, CurStartLeftPos, CDTabControl); - CurStartLeftPos := CurStartLeftPos + GetTabWidth(ADest, i, CDTabControl); - end; - end; -end; - -procedure TCDCustomTabControlDrawerKDE.DrawTab(ADest: TCanvas; - AIndex: Integer; ACurStartLeftPos: Integer; CDTabControl: TCDCustomTabControl); -var - IsSelected: Boolean; - lTabWidth, lTabHeight, lTabTopPos: Integer; - Points: array of TPoint; - lCaption: String; -begin - IsSelected := CDTabControl.TabIndex = AIndex; - - if IsSelected then - begin - lTabTopPos := 0; - lTabHeight := GetTabHeight(AIndex, CDTabControl); - end - else - begin - lTabTopPos := 5; - lTabHeight := GetTabHeight(AIndex, CDTabControl)-5; - end; - - lTabWidth := GetTabWidth(ADest, AIndex, CDTabControl); - - // Fill the area inside the outer border - ADest.Pen.Style := psClear; - ADest.Brush.Style := bsSolid; - ADest.Brush.Color := clWhite; - SetLength(Points, 5); - Points[0] := Point(ACurStartLeftPos, lTabTopPos); - Points[1] := Point(ACurStartLeftPos+lTabWidth-5, lTabTopPos); - Points[2] := Point(ACurStartLeftPos+lTabWidth, lTabTopPos+5); - Points[3] := Point(ACurStartLeftPos+lTabWidth, lTabTopPos+lTabHeight); - Points[4] := Point(ACurStartLeftPos, lTabTopPos+lTabHeight); - ADest.Polygon(Points); - - // Draw the outer border only in the top and right sides, - // and bottom if unselected - ADest.Pen.Style := psSolid; - ADest.Brush.Style := bsClear; - ADest.Pen.Color := ColorToRGB($009C9B91); - ADest.MoveTo(ACurStartLeftPos+1, lTabTopPos); - ADest.LineTo(ACurStartLeftPos+lTabWidth-5, lTabTopPos); - ADest.LineTo(ACurStartLeftPos+lTabWidth, lTabTopPos+5); - ADest.LineTo(ACurStartLeftPos+lTabWidth, lTabTopPos+lTabHeight); - - // If it is selected, add a selection frame - if IsSelected then - begin - ADest.Pen.Color := ColorToRGB($00D6C731); - ADest.Pen.Style := psSolid; - ADest.Brush.Style := bsClear; - ADest.Rectangle( - ACurStartLeftPos+3, lTabTopPos+3, - ACurStartLeftPos+lTabWidth-5, lTabTopPos+lTabHeight-5 - ); - end; - - // Now the text - lCaption := CDTabControl.Tabs.Strings[AIndex]; - ADest.TextOut(ACurStartLeftPos+5, lTabTopPos+5, lCaption); -end; - -function TCDCustomTabControlDrawerKDE.GetPageIndexFromXY(x, y: integer - ): integer; -begin - Result := 1; -end; - -function TCDCustomTabControlDrawerKDE.GetTabHeight(AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; -begin - if CDTabControl.Font.Size = 0 then - Result := 32 - else - Result := CDTabControl.Font.Size + 22; -end; - -function TCDCustomTabControlDrawerKDE.GetTabWidth(ADest: TCanvas; - AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; -const - TCDTabControl_KDE_TabCaptionExtraWidth = 20; -var - lCaption: string; -begin - lCaption := CDTabControl.Tabs.Strings[AIndex]; - - Result := ADest.TextWidth(lCaption) + TCDTabControl_KDE_TabCaptionExtraWidth; -end; - -{function TCDCustomTabControlDrawerKDE.GetClientRect(AControl: TCDControl - ): TRect; -var - lCaptionHeight: Integer; -begin - lCaptionHeight := GetTabHeight(CDTabControl.FTabIndex) - 4; - - Result := Rect(5, lCaptionHeight + 1, CDTabControl.Width - 10, - CDTabControl.Height - lCaptionHeight - 5); -end;} - -procedure TCDCustomTabControlDrawerKDE.DrawToIntfImage(ADest: TFPImageCanvas; - FPImg: TLazIntfImage; CDTabControl: TCDCustomTabControl); -var - lColor: TColor; - lFPColor: TFPColor; - x, y: Integer; -begin - lColor := CDTabControl.GetRGBBackgroundColor(); - - // Background - lFPColor := TColorToFPColor(lColor); - FPImg.FillPixels(lFPColor); -end; - -procedure TCDCustomTabControlDrawerKDE.DrawToCanvas(ADest: TCanvas; CDTabControl: TCDCustomTabControl); -var - CaptionHeight: Integer; -begin - CaptionHeight := GetTabHeight(CDTabControl.TabIndex, CDTabControl); - - // frame - ADest.Pen.Style := psSolid; - ADest.Brush.Style := bsClear; - ADest.Pen.Color := ColorToRGB($009C9B91); - - if CDTabControl.GetTabCount = 0 then - ADest.Rectangle(0, 0, CDTabControl.Width - 2, CDTabControl.Height - 2) - else - ADest.Rectangle(0, CaptionHeight, CDTabControl.Width - 2, CDTabControl.Height - 2); - - ADest.Pen.Color := ColorToRGB($00BFCED0); - ADest.Line(CDTabControl.Width - 1, CaptionHeight + 1, - CDTabControl.Width - 1, CDTabControl.Height - 1); - ADest.Line(CDTabControl.Width - 1, CDTabControl.Height - 1, 1, - CDTabControl.Height - 1); - - // Tabs - ADest.Font.Name := CDTabControl.Font.Name; - ADest.Font.Size := CDTabControl.Font.Size; -// DrawCaptionBar(ADest, Rect(0, 0, CDPageControl.Width - -// 2, CaptionHeight + 1), CDPageControl.Color, CDPageControl); - DrawTabs(ADest, CDTabControl); -end; - -procedure TCDCustomTabControlDrawerKDE.DrawTabSheet(ADest: TCanvas; CDTabControl: TCDCustomTabControl); -begin - ADest.Brush.Color := CDTabControl.Color; - ADest.Brush.Style := bsSolid; - ADest.Pen.Style := psClear; - ADest.Rectangle(0, 0, CDTabControl.Width, CDTabControl.Height); -end; - -procedure TCDCustomTabControlDrawerKDE.MouseDown(Button: TMouseButton; - Shift: TShiftState; X, Y: integer; CDTabControl: TCDCustomTabControl); -var - i: Integer; - CurPage: TCDTabSheet; - CurStartLeftPos: Integer = 0; - VisiblePagesStarted: Boolean = False; - lTabWidth: Integer; -begin - for i := 0 to CDTabControl.Tabs.Count - 1 do - begin - if i = LeftmostTabVisibleIndex then - VisiblePagesStarted := True; - - if VisiblePagesStarted then - begin - lTabWidth := GetTabWidth(CDTabControl.Canvas, i, CDTabControl); - if (X > CurStartLeftPos) and - (X < CurStartLeftPos + lTabWidth) and - (Y < GetTabHeight(i, CDTabControl)) then - begin - if CDTabControl is TCDPageControl then - (CDTabControl as TCDPageControl).PageIndex := i - else - CDTabControl.TabIndex := i; - - Exit; - end; - CurStartLeftPos := CurStartLeftPos + lTabWidth; - end; - end; -end; - -procedure TCDCustomTabControlDrawerKDE.MouseUp(Button: TMouseButton; - Shift: TShiftState; X, Y: integer; CDTabControl: TCDCustomTabControl); -begin - -end; - -initialization - - RegisterCustomTabControlDrawer(TCDCustomTabControlDrawerKDE.Create, dsKDE); - end. diff --git a/components/customdrawn/customdrawn_win2000.pas b/components/customdrawn/customdrawn_win2000.pas index 29dbc69ca7..8d7fc3e0e9 100644 --- a/components/customdrawn/customdrawn_win2000.pas +++ b/components/customdrawn/customdrawn_win2000.pas @@ -12,18 +12,16 @@ uses // LCL -> Use only TForm, TWinControl, TCanvas and TLazIntfImage Graphics, Controls, LCLType, LCLIntf, IntfGraphics, // - customdrawncontrols, customdrawnutils; + customdrawndrawers, customdrawn_common; type - TCDButtonDrawerWin2k = class(TCDButtonDrawer) + TCDDrawerWin2k = class(TCDDrawerCommon) public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override; - procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override; end; implementation -procedure TCDButtonDrawerWin2k.DrawToIntfImage(ADest: TFPImageCanvas; +{procedure TCDButtonDrawerWin2k.DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); begin @@ -108,9 +106,9 @@ begin else ADest.TextOut((CDButton.Width - ADest.TextWidth(Str)) div 2, (CDButton.Height - ADest.TextHeight(Str)) div 2, Str); -end; +end;} initialization - RegisterButtonDrawer(TCDButtonDrawerWin2k.Create, dsWin2000); + RegisterDrawer(TCDDrawerWin2k.Create, dsWin2000); end. diff --git a/components/customdrawn/customdrawn_wince.pas b/components/customdrawn/customdrawn_wince.pas index af51d5d2fc..52d2d59805 100644 --- a/components/customdrawn/customdrawn_wince.pas +++ b/components/customdrawn/customdrawn_wince.pas @@ -14,83 +14,16 @@ uses // Others only for types StdCtrls, // - customdrawncontrols, customdrawnutils, customdrawn_common; + customdrawndrawers, customdrawn_common; type - TCDButtonDrawerWinCE = class(TCDButtonDrawer) + TCDDrawerWinCE = class(TCDDrawerCommon) public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override; - procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override; - end; - - { TCDEditDrawerWinCE } - - TCDEditDrawerWinCE = class(TCDEditDrawerCommon) - public - function GetMeasures(AMeasureID: Integer): Integer; override; - procedure DrawBackground(ADest: TCanvas; CDControl: TCDControl); override; - end; - - { TCDCheckBoxDrawerWinCE } - - TCDCheckBoxDrawerWinCE = class(TCDCheckBoxDrawer) - public - function GetCaptionWidth(CDCheckBox: TCDCheckBox): Integer; - function GetCaptionHeight(CDCheckBox: TCDCheckBox): Integer; - procedure CalculatePreferredSize(CDCheckBox: TCDCheckBox; var PreferredWidth, - PreferredHeight: integer; WithThemeSpace: Boolean); override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDCheckBox: TCDCheckBox); override; - procedure DrawToCanvas(ADest: TCanvas; CDCheckBox: TCDCheckBox); override; - end; - - TCDGroupBoxDrawerWinCE = class(TCDGroupBoxDrawer) - public - FCaptionMiddle: integer; - procedure SetClientRectPos(CDGroupBox: TCDGroupBox); override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDGroupBox: TCDGroupBox); override; - procedure DrawToCanvas(ADest: TCanvas; CDGroupBox: TCDGroupBox); override; - end; - - // =================================== - // Common Controls Tab - // =================================== - - { TCDListViewDrawerWinCE } - - TCDListViewDrawerWinCE = class(TCDListViewDrawer) - public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDListView: TCDListView); override; - procedure DrawToCanvas(ADest: TCanvas; CDListView: TCDListView); override; - end; - - { TCDCustomTabControlDrawerWinCE } - - TCDCustomTabControlDrawerWinCE = class(TCDCustomTabControlDrawer) - private - StartIndex: integer; //FEndIndex - LeftmostTabVisibleIndex: Integer; - procedure DrawCaptionBar(ADest: TCanvas; lRect: TRect; CL: TColor); - procedure DrawTabs(ADest: TCanvas; CDTabControl: TCDCustomTabControl); - procedure DrawTab(ADest: TCanvas; AIndex: Integer; ACurStartLeftPos: Integer; - CDTabControl: TCDCustomTabControl); - public - function GetPageIndexFromXY(x, y: integer): integer; override; - function GetTabHeight(AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; override; - function GetTabWidth(ADest: TCanvas; AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; override; - //function GetClientRect(AControl: TCDControl): TRect; override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage; - CDTabControl: TCDCustomTabControl); override; - procedure DrawToCanvas(ADest: TCanvas; CDTabControl: TCDCustomTabControl); override; - procedure DrawTabSheet(ADest: TCanvas; CDTabControl: TCDCustomTabControl); override; - procedure MouseDown(Button: TMouseButton; Shift: TShiftState; - X, Y: integer; CDTabControl: TCDCustomTabControl); override; - procedure MouseUp(Button: TMouseButton; Shift: TShiftState; - X, Y: integer; CDTabControl: TCDCustomTabControl); override; end; implementation -{ TCDListViewDrawerWinCE } +(*{ TCDListViewDrawerWinCE } procedure TCDListViewDrawerWinCE.DrawToIntfImage(ADest: TFPImageCanvas; CDListView: TCDListView); @@ -701,13 +634,9 @@ begin ADest.Brush.Style := bsSolid; // This will fill the text background ADest.Font.Size := 10; ADest.TextOut(FCaptionMiddle, 0, CDGroupBox.Caption); -end; +end;*) initialization - RegisterButtonDrawer(TCDButtonDrawerWinCE.Create, dsWinCE); - RegisterEditDrawer(TCDEditDrawerWinCE.Create, dsWinCE); - RegisterGroupBoxDrawer(TCDGroupBoxDrawerWinCE.Create, dsWinCE); - RegisterCheckBoxDrawer(TCDCheckBoxDrawerWinCE.Create, dsWinCE); - RegisterCustomTabControlDrawer(TCDCustomTabControlDrawerWinCE.Create, dsWinCE); + RegisterDrawer(TCDDrawerWinCE.Create, dsWinCE); end. diff --git a/components/customdrawn/customdrawn_winxp.pas b/components/customdrawn/customdrawn_winxp.pas index 1ef66a7e3a..6127bfde69 100644 --- a/components/customdrawn/customdrawn_winxp.pas +++ b/components/customdrawn/customdrawn_winxp.pas @@ -14,16 +14,16 @@ uses // customdrawncontrols, customdrawnutils; -type +{type TCDButtonDrawerXPTB = class(TCDButtonDrawer) public procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override; procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override; - end; + end;} implementation -procedure TCDButtonDrawerXPTB.DrawToIntfImage(ADest: TFPImageCanvas; +{procedure TCDButtonDrawerXPTB.DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); begin @@ -50,6 +50,6 @@ begin end; initialization - RegisterButtonDrawer(TCDButtonDrawerXPTB.Create, dsWinXP); + RegisterButtonDrawer(TCDButtonDrawerXPTB.Create, dsWinXP);} end. diff --git a/components/customdrawn/customdrawncontrols.pas b/components/customdrawn/customdrawncontrols.pas index e7e8d82eff..6aa8135fe1 100644 --- a/components/customdrawn/customdrawncontrols.pas +++ b/components/customdrawn/customdrawncontrols.pas @@ -24,84 +24,44 @@ uses // Other LCL units are only for types StdCtrls, ExtCtrls, ComCtrls, // - customdrawnutils; - -const - CDDRAWSTYLE_COUNT = 19; - - TCDEDIT_LEFT_TEXT_SPACING = $400; // The space between the start of the text and the left end of the control - TCDEDIT_RIGHT_TEXT_SPACING = $401; // The space between the end of the text and the right end of the control - TCDEDIT_BACKGROUND_COLOR = $402; - TCDEDIT_TEXT_COLOR = $403; - TCDEDIT_SELECTED_BACKGROUND_COLOR = $404; - TCDEDIT_SELECTED_TEXT_COLOR = $405; + customdrawndrawers; type - - TCDDrawStyle = ( - // The default is given by the DefaultStyle global variable - // Don't implement anything for this drawer - dsDefault = 0, - // This is a common drawer, with a minimal implementation on which other - // drawers base on - dsCommon, - // Operating system styles - dsWinCE, dsWin2000, dsWinXP, - dsKDE, dsGNOME, dsMacOSX, - dsAndroid, - // Other special styles for the user - dsExtra1, dsExtra2, dsExtra3, dsExtra4, dsExtra5, - dsExtra6, dsExtra7, dsExtra8, dsExtra9, dsExtra10 - ); - - TCDControlDrawer = class; - { TCDControl } TCDControl = class(TCustomControl) protected FDrawStyle: TCDDrawStyle; - FCurrentDrawer: TCDControlDrawer; - //constructor Create(AOwner: TComponent); override; - //destructor Destroy; override; + FDrawer: TCDDrawer; + FState: TCDControlState; + FStateEx: TCDControlStateEx; procedure PrepareCurrentDrawer(); virtual; procedure SetDrawStyle(const AValue: TCDDrawStyle); virtual; function GetClientRect: TRect; override; + function GetControlId: TCDControlID; virtual; + procedure CreateControlStateEx; virtual; + procedure PrepareControlState; virtual; + procedure PrepareControlStateEx; virtual; // mouse procedure MouseEnter; override; procedure MouseLeave; override; // property DrawStyle: TCDDrawStyle read FDrawStyle write SetDrawStyle; public - // state information - IsMouseOver: Boolean; // constructor Create(AOwner: TComponent); override; + destructor Destroy; override; procedure EraseBackground(DC: HDC); override; procedure Paint; override; end; TCDControlClass = class of TCDControl; - { TCDControlDrawer } - - TCDControlDrawer = class - public - function GetClientRect(AControl: TCDControl): TRect; virtual; - function GetMeasures(AMeasureID: Integer): Integer; virtual; - function GetColor(AColorID: Integer): TColor; virtual; - procedure DrawToIntfImage(ADest: TFPImageCanvas; AControl: TCDControl); - virtual; - procedure DrawToCanvas(ADest: TCanvas; AControl: TCDControl); virtual; - end; - // =================================== // Standard Tab // =================================== TCDButtonControl = class(TCDControl) private - // button state - FIsDown: Boolean; protected // keyboard procedure DoEnter; override; @@ -119,20 +79,18 @@ type procedure DoButtonUp(); virtual; procedure RealSetText(const Value: TCaption); override; public - // button state - property IsDown: Boolean read FIsDown write FIsDown; + //property Down: Boolean read GetDown write SetDown; end; { TCDButton } TCDButton = class(TCDButtonControl) private - procedure PrepareCurrentDrawer(); override; protected + function GetControlId: TCDControlID; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure Paint; override; published property Action; property Anchors; @@ -170,25 +128,18 @@ type property Visible; end; - { TCDButtonDrawer } - - TCDButtonDrawer = class(TCDControlDrawer) - public - function GetClientRect(AControl: TCDControl): TRect; override; - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); - virtual; abstract; - procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); virtual; abstract; - end; - { TCDEdit } TCDEdit = class(TCDControl) private + DragDropStarted: boolean; FCaretTimer: TTimer; + FEditState: TCDEditStateEx; // Points to the same object as FStateEx, so don't Free! + function GetControlId: TCDControlID; override; + procedure CreateControlStateEx; override; procedure HandleCaretTimer(Sender: TObject); procedure DoDeleteSelection; procedure DoManageVisibleTextStart; - procedure PrepareCurrentDrawer(); override; function GetText: string; procedure SetText(AValue: string); protected @@ -206,13 +157,6 @@ type procedure MouseEnter; override; procedure MouseLeave; override; public - // State information - FDragDropStarted: boolean; - FCaretIsVisible: Boolean; - FCaretPos: Integer; // zero-based position - FSelStart: Integer; // zero-based position - FSelLength: Integer; // zero means no selection. Negative numbers selection to the left from the start and positive ones to the right - FVisibleTextStart: Integer; // 1-based constructor Create(AOwner: TComponent); override; destructor Destroy; override; published @@ -221,13 +165,6 @@ type property Text: string read GetText write SetText; end; - { TCDEditDrawer } - - TCDEditDrawer = class(TCDControlDrawer) - public - procedure DrawBackground(ADest: TCanvas; AControl: TCDControl); virtual; abstract; - end; - {@@ TCDGroupBox is a custom-drawn group box control } @@ -236,46 +173,32 @@ type TCDGroupBox = class(TCDControl) private - procedure PrepareCurrentDrawer(); override; - procedure SetDrawStyle(const AValue: TCDDrawStyle); override; + function GetControlId: TCDControlID; override; protected procedure RealSetText(const Value: TCaption); override; // to update on caption changes public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure EraseBackground(DC: HDC); override; - procedure Paint; override; published property DrawStyle; property Caption; property TabStop default False; end; - { TCDGroupBoxDrawer } - - TCDGroupBoxDrawer = class(TCDControlDrawer) - public - procedure SetClientRectPos(CDGroupBox: TCDGroupBox); virtual; abstract; - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDGroupBox: TCDGroupBox); virtual; abstract; - procedure DrawToCanvas(ADest: TCanvas; CDGroupBox: TCDGroupBox); virtual; abstract; - end; - { TCDCheckBox } TCDCheckBox = class(TCDButtonControl) private FAllowGrayed: Boolean; FCheckedState: TCheckBoxState; - procedure PrepareCurrentDrawer(); override; protected procedure DoButtonUp(); override; procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; + function GetControlId: TCDControlID; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure EraseBackground(DC: HDC); override; - procedure Paint; override; published property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default False; property DrawStyle; @@ -286,7 +209,7 @@ type { TCDCheckBoxDrawer } - TCDCheckBoxDrawer = class(TCDControlDrawer) + TCDCheckBoxDrawer = class(TCDDrawer) public procedure CalculatePreferredSize(CDCheckBox: TCDCheckBox; var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); virtual; abstract; @@ -312,13 +235,16 @@ type FMax: integer; FPosition: integer; FOnChange: TNotifyEvent; - procedure PrepareCurrentDrawer(); override; procedure SetMax(Value: integer); procedure SetMin(Value: integer); procedure SetPosition(Value: integer); // function GetPositionFromMousePos(X, Y: Integer): integer; protected + FTBState: TCDTrackBarStateEx; + function GetControlId: TCDControlID; override; + procedure CreateControlStateEx; override; + procedure PrepareControlStateEx; override; procedure Changed; virtual; // keyboard procedure DoEnter; override; @@ -335,8 +261,7 @@ type public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure EraseBackground(DC: HDC); override; - procedure Paint; override; + //procedure Paint; override; published property Color; property Max: integer read FMax write SetMax default 10; @@ -348,7 +273,7 @@ type { TCDTrackBarDrawer } - TCDTrackBarDrawer = class(TCDControlDrawer) + TCDTrackBarDrawer = class(TCDDrawer) public procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage; CDTrackBar: TCDTrackBar); virtual; abstract; @@ -357,11 +282,10 @@ type { TCDListView } - TCDListView = class(TCDControl) +(* TCDListView = class(TCDControl) private DragDropStarted: boolean; // fields - procedure PrepareCurrentDrawer(); override; protected // keyboard procedure DoEnter; override; @@ -383,13 +307,7 @@ type published property Color; property TabStop default True; - end; - - TCDListViewDrawer = class(TCDControlDrawer) - public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDListView: TCDListView); virtual; abstract; - procedure DrawToCanvas(ADest: TCanvas; CDListView: TCDListView); virtual; abstract; - end; + end;*) {TCDTabControl} @@ -422,11 +340,13 @@ type procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override; //procedure MouseEnter; override; //procedure MouseLeave; override; - procedure PrepareCurrentDrawer(); override; procedure SetTabIndex(AValue: Integer); virtual; procedure SetTabs(AValue: TStringList); protected - procedure Paint; override; + FTabCState: TCDCTabControlStateEx; + function GetControlId: TCDControlID; override; + procedure CreateControlStateEx; override; + procedure PrepareControlStateEx; override; procedure CorrectTabIndex(); public constructor Create(AOwner: TComponent); override; @@ -438,23 +358,6 @@ type property TabIndex: integer read FTabIndex write SetTabIndex; end; - { TCDCustomTabControlDrawer } - - TCDCustomTabControlDrawer = class(TCDControlDrawer) - public - function GetPageIndexFromXY(x, y: integer): integer; virtual; abstract; - function GetTabHeight(AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; virtual; abstract; - function GetTabWidth(ADest: TCanvas; AIndex: Integer; CDTabControl: TCDCustomTabControl): Integer; virtual; abstract; - procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage; - CDTabControl: TCDCustomTabControl); virtual; abstract; - procedure DrawToCanvas(ADest: TCanvas; CDTabControl: TCDCustomTabControl); virtual; abstract; - procedure DrawTabSheet(ADest: TCanvas; CDTabControl: TCDCustomTabControl); virtual; abstract; - procedure MouseDown(Button: TMouseButton; Shift: TShiftState; - X, Y: integer; CDTabControl: TCDCustomTabControl); virtual; abstract; - procedure MouseUp(Button: TMouseButton; Shift: TShiftState; - X, Y: integer; CDTabControl: TCDCustomTabControl); virtual; abstract; - end; - // TTabSelectedEvent = procedure(Sender: TObject; ATab: TTabItem; // ASelected: boolean) of object; @@ -527,192 +430,11 @@ type property OnChange; end; -// Standard Tab -procedure RegisterButtonDrawer(ADrawer: TCDButtonDrawer; AStyle: TCDDrawStyle); -procedure RegisterEditDrawer(ADrawer: TCDEditDrawer; AStyle: TCDDrawStyle); -procedure RegisterGroupBoxDrawer(ADrawer: TCDGroupBoxDrawer; AStyle: TCDDrawStyle); -procedure RegisterCheckBoxDrawer(ADrawer: TCDCheckBoxDrawer; AStyle: TCDDrawStyle); -// Common Controls Tab -procedure RegisterTrackBarDrawer(ADrawer: TCDTrackBarDrawer; AStyle: TCDDrawStyle); -procedure RegisterListViewDrawer(ADrawer: TCDListViewDrawer; AStyle: TCDDrawStyle); -procedure RegisterCustomTabControlDrawer(ADrawer: TCDCustomTabControlDrawer; AStyle: TCDDrawStyle); - -var - DefaultStyle: TCDDrawStyle = dsWinCE; // For now default to the most complete one, later per platform - implementation resourcestring sTABSHEET_DEFAULT_NAME = 'CTabSheet'; -var - // Standard Tab - RegisteredButtonDrawers: array[TCDDrawStyle] of TCDButtonDrawer - = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); - RegisteredEditDrawers: array[TCDDrawStyle] of TCDEditDrawer - = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); - RegisteredGroupBoxDrawers: array[TCDDrawStyle] of TCDGroupBoxDrawer - = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); - RegisteredCheckBoxDrawers: array[TCDDrawStyle] of TCDCheckBoxDrawer - = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); - // Common Controls Tab - RegisteredTrackBarDrawers: array[TCDDrawStyle] of TCDTrackBarDrawer - = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); - RegisteredListViewDrawers: array[TCDDrawStyle] of TCDListViewDrawer - = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); - RegisteredCustomTabControlDrawers: array[TCDDrawStyle] of TCDCustomTabControlDrawer - = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); - -procedure RegisterButtonDrawer(ADrawer: TCDButtonDrawer; AStyle: TCDDrawStyle); -begin - if RegisteredButtonDrawers[AStyle] <> nil then RegisteredButtonDrawers[AStyle].Free; - RegisteredButtonDrawers[AStyle] := ADrawer; -end; - -procedure RegisterEditDrawer(ADrawer: TCDEditDrawer; AStyle: TCDDrawStyle); -begin - if RegisteredEditDrawers[AStyle] <> nil then RegisteredEditDrawers[AStyle].Free; - RegisteredEditDrawers[AStyle] := ADrawer; -end; - -procedure RegisterGroupBoxDrawer(ADrawer: TCDGroupBoxDrawer; AStyle: TCDDrawStyle); -begin - if RegisteredGroupBoxDrawers[AStyle] <> nil then RegisteredGroupBoxDrawers[AStyle].Free; - RegisteredGroupBoxDrawers[AStyle] := ADrawer; -end; - -procedure RegisterCheckBoxDrawer(ADrawer: TCDCheckBoxDrawer; AStyle: TCDDrawStyle); -begin - if RegisteredCheckBoxDrawers[AStyle] <> nil then RegisteredCheckBoxDrawers[AStyle].Free; - RegisteredCheckBoxDrawers[AStyle] := ADrawer; -end; - -procedure RegisterTrackBarDrawer(ADrawer: TCDTrackBarDrawer; AStyle: TCDDrawStyle); -begin - if RegisteredTrackBarDrawers[AStyle] <> nil then RegisteredTrackBarDrawers[AStyle].Free; - RegisteredTrackBarDrawers[AStyle] := ADrawer; -end; - -procedure RegisterListViewDrawer(ADrawer: TCDListViewDrawer; AStyle: TCDDrawStyle); -begin - if RegisteredListViewDrawers[AStyle] <> nil then RegisteredListViewDrawers[AStyle].Free; - RegisteredListViewDrawers[AStyle] := ADrawer; -end; - -procedure RegisterCustomTabControlDrawer(ADrawer: TCDCustomTabControlDrawer; AStyle: TCDDrawStyle); -begin - if RegisteredCustomTabControlDrawers[AStyle] <> nil then RegisteredCustomTabControlDrawers[AStyle].Free; - RegisteredCustomTabControlDrawers[AStyle] := ADrawer; -end; - -{ TCDControlDrawer } - -function TCDControlDrawer.GetClientRect(AControl: TCDControl): TRect; -begin - Result := AControl.BoundsRect; -end; - -function TCDControlDrawer.GetMeasures(AMeasureID: Integer): Integer; -begin - Result := 0; -end; - -function TCDControlDrawer.GetColor(AColorID: Integer): TColor; -begin - Result := clBlack; -end; - -procedure TCDControlDrawer.DrawToIntfImage(ADest: TFPImageCanvas; - AControl: TCDControl); -begin - -end; - -procedure TCDControlDrawer.DrawToCanvas(ADest: TCanvas; AControl: TCDControl); -begin - -end; - -{ TCDListView } - -procedure TCDListView.PrepareCurrentDrawer; -var - lDrawStyle: TCDDrawStyle; -begin - if DrawStyle = dsDefault then lDrawStyle := DefaultStyle - else lDrawStyle := DrawStyle; - FCurrentDrawer := RegisteredListViewDrawers[lDrawStyle]; - if FCurrentDrawer = nil then FCurrentDrawer := RegisteredListViewDrawers[dsCommon]; - if FCurrentDrawer = nil then raise Exception.Create('No registered list view drawers were found'); -end; - -procedure TCDListView.DoEnter; -begin - inherited DoEnter; -end; - -procedure TCDListView.DoExit; -begin - inherited DoExit; -end; - -procedure TCDListView.KeyDown(var Key: word; Shift: TShiftState); -begin - inherited KeyDown(Key, Shift); -end; - -procedure TCDListView.KeyUp(var Key: word; Shift: TShiftState); -begin - inherited KeyUp(Key, Shift); -end; - -procedure TCDListView.MouseDown(Button: TMouseButton; Shift: TShiftState; X, - Y: integer); -begin - inherited MouseDown(Button, Shift, X, Y); -end; - -procedure TCDListView.MouseMove(Shift: TShiftState; X, Y: integer); -begin - inherited MouseMove(Shift, X, Y); -end; - -procedure TCDListView.MouseUp(Button: TMouseButton; Shift: TShiftState; X, - Y: integer); -begin - inherited MouseUp(Button, Shift, X, Y); -end; - -procedure TCDListView.MouseEnter; -begin - inherited MouseEnter; -end; - -procedure TCDListView.MouseLeave; -begin - inherited MouseLeave; -end; - -constructor TCDListView.Create(AOwner: TComponent); -begin - inherited Create(AOwner); -end; - -destructor TCDListView.Destroy; -begin - inherited Destroy; -end; - -procedure TCDListView.EraseBackground(DC: HDC); -begin - inherited EraseBackground(DC); -end; - -procedure TCDListView.Paint; -begin - inherited Paint; -end; - { TCDEdit } function TCDEdit.GetText: string; @@ -720,16 +442,27 @@ begin Result := Caption; end; +function TCDEdit.GetControlId: TCDControlID; +begin + Result := cidEdit; +end; + +procedure TCDEdit.CreateControlStateEx; +begin + FEditState := TCDEditStateEx.Create; + FStateEx := FEditState; +end; + procedure TCDEdit.HandleCaretTimer(Sender: TObject); begin - FCaretIsVisible := not FCaretIsVisible; + FEditState.CaretIsVisible := not FEditState.CaretIsVisible; Invalidate; end; procedure TCDEdit.DoDeleteSelection; begin - FSelStart := 1; - FSelLength := 0; + FEditState.SelStart := 1; + FEditState.SelLength := 0; end; procedure TCDEdit.DoManageVisibleTextStart; @@ -739,25 +472,15 @@ var lAvailableWidth: Integer; begin // Moved to the left and we need to adjust the text start - FVisibleTextStart := Min(FCaretPos+1, FVisibleTextStart); + FEditState.VisibleTextStart := Min(FEditState.CaretPos+1, FEditState.VisibleTextStart); // Moved to the right and we need to adjust the text start - lText := Copy(Text, FVisibleTextStart, Length(Text)); - lAvailableWidth := Width - FCurrentDrawer.GetMeasures(TCDEDIT_LEFT_TEXT_SPACING) - - FCurrentDrawer.GetMeasures(TCDEDIT_RIGHT_TEXT_SPACING); + lText := Copy(Text, FEditState.VisibleTextStart, Length(Text)); + lAvailableWidth := Width + - FDrawer.GetMeasures(TCDEDIT_LEFT_TEXT_SPACING) + - FDrawer.GetMeasures(TCDEDIT_RIGHT_TEXT_SPACING); lVisibleTextCharCount := Canvas.TextFitInfo(lText, lAvailableWidth); - FVisibleTextStart := Max(FCaretPos-lVisibleTextCharCount, FVisibleTextStart); -end; - -procedure TCDEdit.PrepareCurrentDrawer; -var - lDrawStyle: TCDDrawStyle; -begin - if DrawStyle = dsDefault then lDrawStyle := DefaultStyle - else lDrawStyle := DrawStyle; - FCurrentDrawer := RegisteredEditDrawers[lDrawStyle]; - if FCurrentDrawer = nil then FCurrentDrawer := RegisteredEditDrawers[dsCommon]; - if FCurrentDrawer = nil then raise Exception.Create('No registered edit drawers were found'); + FEditState.VisibleTextStart := Max(FEditState.CaretPos-lVisibleTextCharCount, FEditState.VisibleTextStart); end; procedure TCDEdit.SetText(AValue: string); @@ -770,7 +493,7 @@ begin inherited DoEnter; FCaretTimer.Enabled := True; - FCaretIsVisible := True; + FEditState.CaretIsVisible := True; Invalidate; end; @@ -779,7 +502,7 @@ begin inherited DoExit; FCaretTimer.Enabled := False; - FCaretIsVisible := False; + FEditState.CaretIsVisible := False; Invalidate; end; @@ -796,15 +519,15 @@ begin VK_BACK: begin // Selection backspace - if FSelLength > 0 then + if FEditState.SelLength > 0 then DoDeleteSelection() // Normal backspace - else if FCaretPos > 0 then + else if FEditState.CaretPos > 0 then begin - lLeftText := Copy(lOldText, 1, FCaretPos-1); - lRightText := Copy(lOldText, FCaretPos+1, Length(lOldText)); + lLeftText := Copy(lOldText, 1, FEditState.CaretPos-1); + lRightText := Copy(lOldText, FEditState.CaretPos+1, Length(lOldText)); Text := lLeftText + lRightText; - Dec(FCaretPos); + Dec(FEditState.CaretPos); DoManageVisibleTextStart(); Invalidate; end; @@ -813,52 +536,52 @@ begin VK_DELETE: begin // Selection delete - if FSelLength > 0 then + if FEditState.SelLength > 0 then DoDeleteSelection() // Normal delete - else if FCaretPos < Length(lOldText) then + else if FEditState.CaretPos < Length(lOldText) then begin - lLeftText := Copy(lOldText, 1, FCaretPos); - lRightText := Copy(lOldText, FCaretPos+2, Length(lOldText)); + lLeftText := Copy(lOldText, 1, FEditState.CaretPos); + lRightText := Copy(lOldText, FEditState.CaretPos+2, Length(lOldText)); Text := lLeftText + lRightText; Invalidate; end; end; VK_LEFT: begin - if (FCaretPos > 0) then + if (FEditState.CaretPos > 0) then begin // Selecting to the left if ssShift in Shift then begin - Dec(FSelLength); - if FSelStart < 0 then FSelStart := FCaretPos; + Dec(FEditState.SelLength); + if FEditState.SelStart < 0 then FEditState.SelStart := FEditState.CaretPos; end // Normal move to the left - else FSelLength := 0; + else FEditState.SelLength := 0; - Dec(FCaretPos); + Dec(FEditState.CaretPos); DoManageVisibleTextStart(); - FCaretIsVisible := True; + FEditState.CaretIsVisible := True; Invalidate; end; end; VK_RIGHT: begin - if FCaretPos < Length(lOldText) then + if FEditState.CaretPos < Length(lOldText) then begin // Selecting to the right if ssShift in Shift then begin - Inc(FSelLength); - if FSelStart < 0 then FSelStart := FCaretPos; + Inc(FEditState.SelLength); + if FEditState.SelStart < 0 then FEditState.SelStart := FEditState.CaretPos; end // Normal move to the right - else FSelLength := 0; + else FEditState.SelLength := 0; - Inc(FCaretPos); + Inc(FEditState.CaretPos); DoManageVisibleTextStart(); - FCaretIsVisible := True; + FEditState.CaretIsVisible := True; Invalidate; end; end; @@ -885,11 +608,11 @@ begin // Normal characters lOldText := Text; - lLeftText := Copy(lOldText, 1, FCaretPos); - lRightText := Copy(lOldText, FCaretPos+1, Length(lOldText)); + lLeftText := Copy(lOldText, 1, FEditState.CaretPos); + lRightText := Copy(lOldText, FEditState.CaretPos+1, Length(lOldText)); Text := lLeftText + UTF8Key + lRightText; - Inc(FCaretPos); - FCaretIsVisible := True; + Inc(FEditState.CaretPos); + FEditState.CaretIsVisible := True; Invalidate; end; @@ -930,8 +653,8 @@ begin csDoubleClicks, csReplicatable]; // State information - FVisibleTextStart := 1; - FSelStart := -1; + FEditState.VisibleTextStart := 1; + FEditState.SelStart := -1; // Caret code FCaretTimer := TTimer.Create(Self); @@ -949,17 +672,6 @@ end; { TCDCheckBox } -procedure TCDCheckBox.PrepareCurrentDrawer; -var - lDrawStyle: TCDDrawStyle; -begin - if DrawStyle = dsDefault then lDrawStyle := DefaultStyle - else lDrawStyle := DrawStyle; - FCurrentDrawer := RegisteredCheckBoxDrawers[lDrawStyle]; - if FCurrentDrawer = nil then FCurrentDrawer := RegisteredCheckBoxDrawers[dsCommon]; - if FCurrentDrawer = nil then raise Exception.Create('No registered check box drawers were found'); -end; - procedure TCDCheckBox.DoButtonUp; begin inherited DoButtonUp; @@ -985,10 +697,15 @@ end; procedure TCDCheckBox.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); begin - TCDCheckBoxDrawer(FCurrentDrawer).CalculatePreferredSize( + TCDCheckBoxDrawer(FDrawer).CalculatePreferredSize( Self, PreferredWidth, PreferredHeight, WithThemeSpace) end; +function TCDCheckBox.GetControlId: TCDControlID; +begin + Result := cidCheckBox; +end; + constructor TCDCheckBox.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -1008,39 +725,6 @@ begin inherited Destroy; end; -procedure TCDCheckBox.EraseBackground(DC: HDC); -begin -end; - -procedure TCDCheckBox.Paint; -var - AImage: TLazIntfImage = nil; - ABmp: TBitmap = nil; - lCanvas: TFPImageCanvas = nil; -begin - PrepareCurrentDrawer(); - - ABmp := TBitmap.Create; - try - ABmp.Width := Width; - ABmp.Height := Height; - AImage := ABmp.CreateIntfImage; - lCanvas := TFPImageCanvas.Create(AImage); - // First step of the drawing: FCL TFPCustomCanvas for fast pixel access - TCDCheckBoxDrawer(FCurrentDrawer).DrawToIntfImage(lCanvas, Self); - ABmp.LoadFromIntfImage(AImage); - // Second step of the drawing: LCL TCustomCanvas for easy font access - TCDCheckBoxDrawer(FCurrentDrawer).DrawToCanvas(ABmp.Canvas, Self); - Canvas.Draw(0, 0, ABmp); - finally - if lCanvas <> nil then - lCanvas.Free; - if AImage <> nil then - AImage.Free; - ABmp.Free; - end; -end; - { TCDCustomTabSheet } procedure TCDCustomTabSheet.RealSetText(const Value: TCaption); @@ -1078,27 +762,45 @@ end; procedure TCDCustomTabControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); +var + i: Integer; + CurPage: TCDTabSheet; + CurStartLeftPos: Integer = 0; + VisiblePagesStarted: Boolean = False; + lTabWidth: Integer; begin - TCDCustomTabControlDrawer(FCurrentDrawer).MouseDown(Button, Shift, X, Y, Self); inherited MouseDown(Button, Shift, X, Y); + + for i := 0 to Tabs.Count - 1 do + begin + if i = FTabCState.LeftmostTabVisibleIndex then + VisiblePagesStarted := True; + + if VisiblePagesStarted then + begin + FTabCState.TabIndex := i; + lTabWidth := FDrawer.GetMeasuresEx(Canvas, TCDCTABCONTROL_TAB_WIDTH, FState, FTabCState); + if (X > CurStartLeftPos) and + (X < CurStartLeftPos + lTabWidth) and + (Y < FDrawer.GetMeasuresEx(Canvas, TCDCTABCONTROL_TAB_HEIGHT, FState, FTabCState)) then + begin + if Self is TCDPageControl then + (Self as TCDPageControl).PageIndex := i + else + TabIndex := i; + + Exit; + end; + CurStartLeftPos := CurStartLeftPos + lTabWidth; + end; + end; end; procedure TCDCustomTabControl.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); begin - TCDCustomTabControlDrawer(FCurrentDrawer).MouseUp(Button, Shift, X, Y, Self); - inherited MouseUp(Button, Shift, X, Y); -end; -procedure TCDCustomTabControl.PrepareCurrentDrawer; -var - lDrawStyle: TCDDrawStyle; -begin - if DrawStyle = dsDefault then lDrawStyle := DefaultStyle - else lDrawStyle := DrawStyle; - FCurrentDrawer := RegisteredCustomTabControlDrawers[lDrawStyle]; - if FCurrentDrawer = nil then FCurrentDrawer := RegisteredCustomTabControlDrawers[dsCommon]; - if FCurrentDrawer = nil then raise Exception.Create('No registered custom tab control drawers were found'); + inherited MouseUp(Button, Shift, X, Y); end; procedure TCDCustomTabControl.SetTabIndex(AValue: Integer); @@ -1118,6 +820,23 @@ begin Invalidate; end; +function TCDCustomTabControl.GetControlId: TCDControlID; +begin + Result := cidCustomTabControl; +end; + +procedure TCDCustomTabControl.CreateControlStateEx; +begin + FTabCState := TCDCTabControlStateEx.Create; + FStateEx := FTabCState; +end; + +procedure TCDCustomTabControl.PrepareControlStateEx; +begin + inherited PrepareControlStateEx; + +end; + constructor TCDCustomTabControl.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -1143,32 +862,6 @@ begin inherited Destroy; end; -procedure TCDCustomTabControl.Paint; -var - AImage: TLazIntfImage = nil; - ABmp: TBitmap = nil; - lCanvas: TFPImageCanvas = nil; -begin - ABmp := TBitmap.Create; - try - ABmp.Width := Width; - ABmp.Height := Height; - AImage := ABmp.CreateIntfImage; - lCanvas := TFPImageCanvas.Create(AImage); - TCDCustomTabControlDrawer(FCurrentDrawer).DrawToIntfImage(lCanvas, AImage, Self); - ABmp.LoadFromIntfImage(AImage); - ABmp.Canvas.Font.Assign(Font); - TCDCustomTabControlDrawer(FCurrentDrawer).DrawToCanvas(ABmp.Canvas, Self); - Canvas.Draw(0, 0, ABmp); - finally - if lCanvas <> nil then - lCanvas.Free; - if AImage <> nil then - AImage.Free; - ABmp.Free; - end; -end; - function TCDCustomTabControl.GetTabCount: Integer; begin Result := 0; @@ -1184,7 +877,9 @@ end; procedure TCDControl.PrepareCurrentDrawer; begin - + FDrawer := GetDrawer(FDrawStyle); + if FDrawer = nil then FDrawer := GetDrawer(dsCommon); // avoid exceptions in the object inspector if an invalid drawer is selected + if FDrawer = nil then raise Exception.Create('No registered drawers were found'); end; procedure TCDControl.SetDrawStyle(const AValue: TCDDrawStyle); @@ -1206,6 +901,35 @@ begin //Result := FCurrentDrawer.GetClientRect(Self); end; +function TCDControl.GetControlId: TCDControlID; +begin + Result := cidControl; +end; + +procedure TCDControl.CreateControlStateEx; +begin + FStateEx := TCDControlStateEx.Create; +end; + +procedure TCDControl.PrepareControlState; +begin + if Focused then FState := FState + [csfHasFocus] + else FState := FState - [csfHasFocus]; + + if Enabled then FState := FState + [csfEnabled] + else FState := FState - [csfEnabled]; +end; + +procedure TCDControl.PrepareControlStateEx; +begin + if Parent <> nil then FStateEx.ParentRGBColor := Parent.GetRGBBackgroundColor; + if Color = clDefault then FStateEx.RGBColor := FDrawer.GetControlColor(GetControlId()) + else FStateEx.RGBColor := GetRGBBackgroundColor; + FStateEx.Caption := Caption; + FStateEx.Font := Font; + FStateEx.AutoSize := AutoSize; +end; + procedure TCDControl.EraseBackground(DC: HDC); begin @@ -1213,9 +937,9 @@ end; procedure TCDControl.Paint; var - AImage: TLazIntfImage = nil; - ABmp: TBitmap = nil; - lCanvas: TFPImageCanvas = nil; + ABmp: TBitmap; + lSize: TSize; + lControlId: TCDControlID; begin inherited Paint; @@ -1225,49 +949,44 @@ begin try ABmp.Width := Width; ABmp.Height := Height; - AImage := ABmp.CreateIntfImage; - lCanvas := TFPImageCanvas.Create(AImage); - // First step of the drawing: FCL TFPCustomCanvas for fast pixel access - FCurrentDrawer.DrawToIntfImage(lCanvas, Self); - ABmp.LoadFromIntfImage(AImage); - // Second step of the drawing: LCL TCustomCanvas for easy font access - FCurrentDrawer.DrawToCanvas(ABmp.Canvas, Self); + lSize := Size(Width, Height); + lControlId := GetControlId(); + PrepareControlState; + PrepareControlStateEx; + FDrawer.DrawControl(ABmp.Canvas, Point(0, 0), + lSize, lControlId, FState, FStateEx); Canvas.Draw(0, 0, ABmp); finally - if lCanvas <> nil then - lCanvas.Free; - if AImage <> nil then - AImage.Free; ABmp.Free; end; end; procedure TCDControl.MouseEnter; begin - IsMouseOver := True; + FState := FState + [csfMouseOver]; inherited MouseEnter; end; procedure TCDControl.MouseLeave; begin - IsMouseOver := True; + FState := FState - [csfMouseOver]; inherited MouseLeave; end; constructor TCDControl.Create(AOwner: TComponent); begin inherited Create(AOwner); + CreateControlStateEx; +end; + +destructor TCDControl.Destroy; +begin + FStateEx.Free; + inherited Destroy; end; { TCDButtonDrawer } -function TCDButtonDrawer.GetClientRect(AControl: TCDControl): TRect; -var - CDButton: TCDButton absolute AControl; -begin - Result := Rect(1, 1, CDButton.Width - 1, CDButton.Height - 1); -end; - procedure TCDButtonControl.DoEnter; begin Invalidate; @@ -1316,32 +1035,30 @@ end; procedure TCDButtonControl.MouseEnter; begin - IsMouseOver := True; Invalidate; inherited MouseEnter; end; procedure TCDButtonControl.MouseLeave; begin - IsMouseOver := False; Invalidate; inherited MouseLeave; end; procedure TCDButtonControl.DoButtonDown(); begin - if not FIsDown then + if not (csfSunken in FState) then begin - FIsDown := True; + FState := FState + [csfSunken]; Invalidate; end; end; procedure TCDButtonControl.DoButtonUp(); begin - if FIsDown then + if csfSunken in FState then begin - FIsDown := False; + FState := FState - [csfSunken]; Invalidate; end; end; @@ -1352,23 +1069,17 @@ begin Invalidate; end; -procedure TCDButton.PrepareCurrentDrawer; -var - lDrawStyle: TCDDrawStyle; +function TCDButton.GetControlId: TCDControlID; begin - if DrawStyle = dsDefault then lDrawStyle := DefaultStyle - else lDrawStyle := DrawStyle; - FCurrentDrawer := RegisteredButtonDrawers[lDrawStyle]; - if FCurrentDrawer = nil then FCurrentDrawer := RegisteredButtonDrawers[dsCommon]; - if FCurrentDrawer = nil then raise Exception.Create('No registered button drawers were found'); + Result := cidButton; end; constructor TCDButton.Create(AOwner: TComponent); begin inherited Create(AOwner); TabStop := True; - Width := 120; - Height := 43; + Width := 75; + Height := 25; //Color := clTeal; ParentFont := True; Color := $00F1F5F5; @@ -1380,63 +1091,11 @@ begin inherited Destroy; end; -procedure TCDButton.Paint; -var - AImage: TLazIntfImage = nil; - ABmp: TBitmap = nil; - lCanvas: TFPImageCanvas = nil; - pColor: TColor; -begin - // inherited Paint; - - PrepareCurrentDrawer(); - - ABmp := TBitmap.Create; - try - ABmp.Width := Width; - ABmp.Height := Height; - AImage := ABmp.CreateIntfImage; - lCanvas := TFPImageCanvas.Create(AImage); - // First step of the drawing: FCL TFPCustomCanvas for fast pixel access - TCDButtonDrawer(FCurrentDrawer).DrawToIntfImage(lCanvas, Self); - ABmp.LoadFromIntfImage(AImage); - // Second step of the drawing: LCL TCustomCanvas for easy font access - TCDButtonDrawer(FCurrentDrawer).DrawToCanvas(ABmp.Canvas, Self); - - Canvas.Draw(0, 0, ABmp); - finally - if lCanvas <> nil then - lCanvas.Free; - if AImage <> nil then - AImage.Free; - ABmp.Free; - end; -end; - - { TCDGroupBox } -procedure TCDGroupBox.PrepareCurrentDrawer(); -var - lDrawStyle: TCDDrawStyle; +function TCDGroupBox.GetControlId: TCDControlID; begin - if DrawStyle = dsDefault then lDrawStyle := DefaultStyle - else lDrawStyle := DrawStyle; - FCurrentDrawer := RegisteredGroupBoxDrawers[lDrawStyle]; - if FCurrentDrawer = nil then FCurrentDrawer := RegisteredGroupBoxDrawers[dsCommon]; - if FCurrentDrawer = nil then raise Exception.Create('No registered group box drawers were found'); -end; - -procedure TCDGroupBox.SetDrawStyle(const AValue: TCDDrawStyle); -begin - if FDrawStyle = AValue then - exit; - FDrawStyle := AValue; - - Invalidate; - - PrepareCurrentDrawer(); - TCDGroupBoxDrawer(FCurrentDrawer).SetClientRectPos(Self); + Result := cidGroupBox; end; procedure TCDGroupBox.RealSetText(const Value: TCaption); @@ -1453,8 +1112,6 @@ begin TabStop := False; ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents, csDoubleClicks, csReplicatable]; - - PrepareCurrentDrawer(); end; destructor TCDGroupBox.Destroy; @@ -1462,55 +1119,8 @@ begin inherited Destroy; end; -procedure TCDGroupBox.EraseBackground(DC: HDC); -begin - -end; - -procedure TCDGroupBox.Paint; -var - AImage: TLazIntfImage = nil; - ABmp: TBitmap = nil; - lCanvas: TFPImageCanvas = nil; -begin - inherited Paint; - - PrepareCurrentDrawer(); - - ABmp := TBitmap.Create; - try - ABmp.Width := Width; - ABmp.Height := Height; - AImage := ABmp.CreateIntfImage; - lCanvas := TFPImageCanvas.Create(AImage); - // First step of the drawing: FCL TFPCustomCanvas for fast pixel access - TCDGroupBoxDrawer(FCurrentDrawer).DrawToIntfImage(lCanvas, Self); - ABmp.LoadFromIntfImage(AImage); - // Second step of the drawing: LCL TCustomCanvas for easy font access - TCDGroupBoxDrawer(FCurrentDrawer).DrawToCanvas(ABmp.Canvas, Self); - Canvas.Draw(0, 0, ABmp); - finally - if lCanvas <> nil then - lCanvas.Free; - if AImage <> nil then - AImage.Free; - ABmp.Free; - end; -end; - { TCDTrackBar } -procedure TCDTrackBar.PrepareCurrentDrawer; -var - lDrawStyle: TCDDrawStyle; -begin - if DrawStyle = dsDefault then lDrawStyle := DefaultStyle - else lDrawStyle := DrawStyle; - FCurrentDrawer := RegisteredTrackBarDrawers[lDrawStyle]; - if FCurrentDrawer = nil then FCurrentDrawer := RegisteredTrackBarDrawers[dsCommon]; - if FCurrentDrawer = nil then raise Exception.Create('No registered track bar drawers were found'); -end; - procedure TCDTrackBar.SetMax(Value: integer); begin if Value = FMax then @@ -1538,7 +1148,7 @@ function TCDTrackBar.GetPositionFromMousePos(X, Y: integer): integer; var lLeftBorder, lRightBorder: Integer; begin - TCDTrackBarDrawer(FCurrentDrawer).GetGeometry(lLeftBorder, lRightBorder); + TCDTrackBarDrawer(FDrawer).GetGeometry(lLeftBorder, lRightBorder); if X > Width - lRightBorder then Result := FMax else if X < lLeftBorder then Result := FMin else Result := FMin + (X - lLeftBorder) * (FMax - FMin + 1) div (Width - lRightBorder - lLeftBorder); @@ -1548,6 +1158,25 @@ begin if Result < FMin then Result := FMin; end; +function TCDTrackBar.GetControlId: TCDControlID; +begin + Result := cidTrackBar; +end; + +procedure TCDTrackBar.CreateControlStateEx; +begin + FTBState := TCDTrackBarStateEx.Create; + FStateEx := FTBState; +end; + +procedure TCDTrackBar.PrepareControlStateEx; +begin + inherited PrepareControlStateEx; + FTBState.Min := FMin; + FTBState.Max := FMax; + FTBState.Position := FPosition; +end; + procedure TCDTrackBar.Changed; begin @@ -1646,16 +1275,10 @@ end; destructor TCDTrackBar.Destroy; begin - FCurrentDrawer.Free; inherited Destroy; end; -procedure TCDTrackBar.EraseBackground(DC: HDC); -begin - //inherited EraseBackground(DC); -end; - -procedure TCDTrackBar.Paint; +{procedure TCDTrackBar.Paint; var AImage: TLazIntfImage = nil; ABmp: TBitmap = nil; @@ -1668,7 +1291,7 @@ begin AImage := ABmp.CreateIntfImage; lCanvas := TFPImageCanvas.Create(AImage); // First step of the drawing: FCL TFPCustomCanvas for fast pixel access - TCDTrackBarDrawer(FCurrentDrawer).DrawToIntfImage(lCanvas, AImage, Self); + FCurrentDrawer.DrawToIntfImage(lCanvas, AImage, Self); ABmp.LoadFromIntfImage(AImage); Canvas.Draw(0, 0, ABmp); finally @@ -1678,7 +1301,7 @@ begin AImage.Free; ABmp.Free; end; -end; +end;} { TCDTabSheet } @@ -1706,10 +1329,14 @@ begin end; procedure TCDTabSheet.Paint; +var + lSize: TSize; begin if CDTabControl <> nil then begin - TCDCustomTabControlDrawer(CDTabControl.FCurrentDrawer).DrawTabSheet(Canvas, CDTabControl); + lSize := Size(Width, Height); + CDTabControl.FDrawer.DrawTabSheet(Canvas, Point(0, 0), lSize, CDTabControl.FState, + CDTabControl.FTabCState); end; end; @@ -1724,10 +1351,10 @@ begin NewPage.Parent := Self; NewPage.CDTabControl := Self; //Name := Designer.CreateUniqueComponentName(ClassName); - NewPage.Name := GetUniqueName(sTABSHEET_DEFAULT_NAME, Self.Owner); +{ NewPage.Name := GetUniqueName(sTABSHEET_DEFAULT_NAME, Self.Owner); if S = '' then NewPage.Caption := NewPage.Name - else + else} NewPage.Caption := S; PositionTabSheet(NewPage); @@ -1754,10 +1381,10 @@ begin NewPage := TCDTabSheet.Create(Owner); NewPage.Parent := Self; //Name := Designer.CreateUniqueComponentName(ClassName); - NewPage.Name := GetUniqueName(sTABSHEET_DEFAULT_NAME, Self.Owner); +{ NewPage.Name := GetUniqueName(sTABSHEET_DEFAULT_NAME, Self.Owner); if S = '' then NewPage.Caption := NewPage.Name - else + else} NewPage.Caption := S; PositionTabSheet(NewPage); @@ -1906,7 +1533,8 @@ var begin // ATabSheet.SetBounds(1, 32 + 1, Width - 3, Height - 32 - 4); lIndex := FTabs.IndexOfObject(ATabSheet); - lTabHeight := TCDCustomTabControlDrawer(FCurrentDrawer).GetTabHeight(lIndex, Self); + FTabCState.TabIndex := lIndex; + lTabHeight := FDrawer.GetMeasuresEx(Canvas, TCDCTABCONTROL_TAB_HEIGHT, FState, FStateEx); ATabSheet.BorderSpacing.Top := lTabHeight; ATabSheet.BorderSpacing.Left := 2; ATabSheet.BorderSpacing.Right := 3; @@ -1929,67 +1557,5 @@ begin Result := FTabIndex; end; -var - i: Integer; -finalization - // Free all drawers - // Standard Tab - for i := 0 to CDDRAWSTYLE_COUNT-1 do - begin - if RegisteredButtonDrawers[TCDDrawStyle(i)] <> nil then - begin - RegisteredButtonDrawers[TCDDrawStyle(i)].Free; - RegisteredButtonDrawers[TCDDrawStyle(i)] := nil; - end; - end; - for i := 0 to CDDRAWSTYLE_COUNT-1 do - begin - if RegisteredEditDrawers[TCDDrawStyle(i)] <> nil then - begin - RegisteredEditDrawers[TCDDrawStyle(i)].Free; - RegisteredEditDrawers[TCDDrawStyle(i)] := nil; - end; - end; - for i := 0 to CDDRAWSTYLE_COUNT-1 do - begin - if RegisteredGroupBoxDrawers[TCDDrawStyle(i)] <> nil then - begin - RegisteredGroupBoxDrawers[TCDDrawStyle(i)].Free; - RegisteredGroupBoxDrawers[TCDDrawStyle(i)] := nil; - end; - end; - for i := 0 to CDDRAWSTYLE_COUNT-1 do - begin - if RegisteredCheckBoxDrawers[TCDDrawStyle(i)] <> nil then - begin - RegisteredCheckBoxDrawers[TCDDrawStyle(i)].Free; - RegisteredCheckBoxDrawers[TCDDrawStyle(i)] := nil; - end; - end; - // Common Controls Tab - for i := 0 to CDDRAWSTYLE_COUNT-1 do - begin - if RegisteredTrackBarDrawers[TCDDrawStyle(i)] <> nil then - begin - RegisteredTrackBarDrawers[TCDDrawStyle(i)].Free; - RegisteredTrackBarDrawers[TCDDrawStyle(i)] := nil; - end; - end; - for i := 0 to CDDRAWSTYLE_COUNT-1 do - begin - if RegisteredListViewDrawers[TCDDrawStyle(i)] <> nil then - begin - RegisteredListViewDrawers[TCDDrawStyle(i)].Free; - RegisteredListViewDrawers[TCDDrawStyle(i)] := nil; - end; - end; - for i := 0 to CDDRAWSTYLE_COUNT-1 do - begin - if RegisteredCustomTabControlDrawers[TCDDrawStyle(i)] <> nil then - begin - RegisteredCustomTabControlDrawers[TCDDrawStyle(i)].Free; - RegisteredCustomTabControlDrawers[TCDDrawStyle(i)] := nil; - end; - end; end. diff --git a/components/customdrawn/customdrawndrawers.pas b/components/customdrawn/customdrawndrawers.pas new file mode 100644 index 0000000000..8b7c6137d2 --- /dev/null +++ b/components/customdrawn/customdrawndrawers.pas @@ -0,0 +1,238 @@ +unit customdrawndrawers; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Types, + // LCL for types + Graphics; + +const + CDDRAWSTYLE_COUNT = 19; + + // Measures + TCDEDIT_LEFT_TEXT_SPACING = $400; // The space between the start of the text and the left end of the control + TCDEDIT_RIGHT_TEXT_SPACING = $401; // The space between the end of the text and the right end of the control + + // Measures Ex + TCDCONTROL_CAPTION_WIDTH = $100; + TCDCONTROL_CAPTION_HEIGHT = $101; + + TCDCTABCONTROL_TAB_HEIGHT = $1000; + TCDCTABCONTROL_TAB_WIDTH = $1001; + + // Colors + TCDEDIT_BACKGROUND_COLOR = $400; + TCDEDIT_TEXT_COLOR = $401; + TCDEDIT_SELECTED_BACKGROUND_COLOR = $402; + TCDEDIT_SELECTED_TEXT_COLOR = $403; + +type + + TCDDrawStyle = ( + // The default is given by the DefaultStyle global variable + // Don't implement anything for this drawer + dsDefault = 0, + // This is a common drawer, with a minimal implementation on which other + // drawers base on + dsCommon, + // Operating system styles + dsWinCE, dsWin2000, dsWinXP, + dsKDE, dsGNOME, dsMacOSX, + dsAndroid, + // Other special styles for the user + dsExtra1, dsExtra2, dsExtra3, dsExtra4, dsExtra5, + dsExtra6, dsExtra7, dsExtra8, dsExtra9, dsExtra10 + ); + + // Inspired by http://doc.qt.nokia.com/stable/qstyle.html#StateFlag-enum + TCDControlStateFlag = ( + // Basic state flags + csfEnabled, + csfRaised, // Raised beyond the normal state, unlike Qt for buttons + csfSunken, + csfHasFocus, + csfReadOnly, + csfMouseOver, + // for TCDCheckBox + csfOn, + csfOff, + csfPartiallyOn +{ // for TCDPageControl + csfDownArrow, + // for tool button + csfAutoRaise, + csfHorizontal, + csfTop, + csfBottom, + csfFocusAtBorder, + csfUpArrow, + csfSelected, + csfActive, + csfWindow, + csfOpen, + csfChildren, + csfItem, + csfSibling, + csfEditing, + csfKeyboardFocusChange, + // For Mac OS X + csfSmall, + csfMini} + ); + + TCDControlState = set of TCDControlStateFlag; + + TCDControlStateEx = class + public + ParentRGBColor: TColor; + RGBColor: TColor; + Caption: string; + Font: TFont; // Just a reference, never Free + AutoSize: Boolean; + end; + + TCDEditStateEx = class(TCDControlStateEx) + public + CaretIsVisible: Boolean; + CaretPos: Integer; // zero-based position + SelStart: Integer; // zero-based position + SelLength: Integer; // zero means no selection. Negative numbers selection to the left from the start and positive ones to the right + VisibleTextStart: Integer; // 1-based + end; + + TCDTrackBarStateEx = class(TCDControlStateEx) + public + Min: integer; + Max: integer; + Position: integer; + end; + + TCDCTabControlStateEx = class(TCDControlStateEx) + public + LeftmostTabVisibleIndex: Integer; + Tabs: TStringList; // Just a reference, don't Free + TabIndex: Integer; // For Tab routines, obtain the index + end; + + TCDControlID = ( + cidControl, + cidButton, + cidEdit, + cidCheckBox, + cidGroupBox, + cidTrackBar, + cidCustomTabControl + ); + + { TCDDrawer } + + TCDDrawer = class + public + function GetControlColor(AControlId: TCDControlID): TColor; + // General + function GetMeasures(AMeasureID: Integer): Integer; virtual; abstract; + function GetMeasuresEx(ADest: TCanvas; AMeasureID: Integer; + AState: TCDControlState; AStateEx: TCDControlStateEx): Integer; virtual; abstract; + function GetColor(AColorID: Integer): TColor; virtual; abstract; + procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; + // TCDButton + procedure DrawButton(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; + // TCDEdit + procedure CreateEditBackgroundBitmap(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDEditStateEx); virtual; abstract; + procedure DrawEdit(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDEditStateEx); virtual; abstract; + // TCDCheckBox + procedure CalculateCheckBoxPreferredSize(ADest: TCanvas; + AState: TCDControlState; AStateEx: TCDControlStateEx; + var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); virtual; abstract; + procedure DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; + // TCDGroupBox + procedure DrawGroupBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; + // =================================== + // Common Controls Tab + // =================================== + // TCDCustomTabControl + procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); virtual; abstract; + procedure DrawTabSheet(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); virtual; abstract; + procedure DrawTabs(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); virtual; abstract; + procedure DrawTab(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; + AState: TCDControlState; AStateEx: TCDCTabControlStateEx); virtual; abstract; + function GetPageIndexFromXY(x, y: integer): integer; virtual; abstract; + end; + +procedure RegisterDrawer(ADrawer: TCDDrawer; AStyle: TCDDrawStyle); +function GetDefaultDrawer: TCDDrawer; +function GetDrawer(AStyle: TCDDrawStyle): TCDDrawer; + +var + DefaultStyle: TCDDrawStyle = dsWinCE; // For now default to the most complete one, later per platform + +implementation + +var + RegisteredDrawers: array[TCDDrawStyle] of TCDDrawer + = (nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); + +procedure RegisterDrawer(ADrawer: TCDDrawer; AStyle: TCDDrawStyle); +begin + if RegisteredDrawers[AStyle] <> nil then RegisteredDrawers[AStyle].Free; + RegisteredDrawers[AStyle] := ADrawer; +end; + +function GetDefaultDrawer: TCDDrawer; +begin + Result := GetDrawer(dsDefault); +end; + +function GetDrawer(AStyle: TCDDrawStyle): TCDDrawer; +var + lDrawStyle: TCDDrawStyle; +begin + if AStyle = dsDefault then lDrawStyle := DefaultStyle + else lDrawStyle := AStyle; + Result := RegisteredDrawers[lDrawStyle]; +end; + +var + i: Integer; + +{ TCDDrawer } + +function TCDDrawer.GetControlColor(AControlId: TCDControlID): TColor; +begin + case AControlId of + cidControl: Result := clSilver; + cidButton: Result := clSilver; + cidEdit: Result := clSilver; + cidCheckBox: Result := clSilver; + cidGroupBox: Result := clSilver; + cidTrackBar: Result := clSilver; + cidCustomTabControl: Result := clSilver; + else + Result := clSilver; + end; +end; + +finalization + // Free all drawers + for i := 0 to CDDRAWSTYLE_COUNT-1 do + begin + if RegisteredDrawers[TCDDrawStyle(i)] <> nil then + begin + RegisteredDrawers[TCDDrawStyle(i)].Free; + RegisteredDrawers[TCDDrawStyle(i)] := nil; + end; + end; +end. + diff --git a/components/customdrawn/customdrawnextras.pas b/components/customdrawn/customdrawnextras.pas index d8d365bb84..b07f48000a 100644 --- a/components/customdrawn/customdrawnextras.pas +++ b/components/customdrawn/customdrawnextras.pas @@ -182,8 +182,11 @@ resourcestring procedure Register; begin - RegisterComponents('Custom Drawn', [TCDButton, TCDTrackBar, TCDTabControl, - TCDPageControl, TCDGroupBox]); + RegisterComponents('Custom Drawn', [ + // Standard tab + TCDButton, TCDEdit, TCDGroupBox, + // Common Controls + TCDTrackBar, TCDPageControl, TCDTabControl]); RegisterComponentEditor(TCDPageControl, TCDPageControlEditor); RegisterComponentEditor(TCDTabSheet, TCDPageControlEditor); RegisterNoIcon([TCDTabSheet]);