Adds pallete assignment in customdrawndrawers, stores the fallback palette of each drawer on creation and implements getting fallback colors in LCL-CustomDrawn

git-svn-id: trunk@33894 -
This commit is contained in:
sekelsenmat 2011-12-01 17:14:59 +00:00
parent afde9c23d7
commit 74061c4a42
7 changed files with 109 additions and 88 deletions

View File

@ -219,6 +219,8 @@ type
cidTrackBar, cidProgressBar, cidListView, cidCTabControl
);
{ TCDColorPalette }
TCDColorPalette = class
public
ScrollBar, Background, ActiveCaption, InactiveCaption,
@ -229,6 +231,7 @@ type
//
HotLight, GradientActiveCaption, GradientInactiveCaption,
MenuHighlight, MenuBar, Form: TColor;
procedure Assign(AFrom: TCDColorPalette);
end;
{ There are 5 possible sources of input for color palettes:
@ -247,6 +250,7 @@ type
protected
public
Palette: TCDColorPalette;
FallbackPalette: TCDColorPalette;
constructor Create; virtual;
destructor Destroy; override;
procedure CreateResources; virtual;
@ -383,6 +387,44 @@ end;
var
i: Integer;
{ TCDColorPalette }
procedure TCDColorPalette.Assign(AFrom: TCDColorPalette);
begin
ScrollBar := AFrom.ScrollBar;
Background := AFrom.Background;
ActiveCaption := AFrom.ActiveCaption;
InactiveCaption := AFrom.InactiveCaption;
Menu := AFrom.Menu;
Window := AFrom.Window;
WindowFrame := AFrom.WindowFrame;
MenuText := AFrom.MenuText;
WindowText := AFrom.WindowText;
CaptionText := AFrom.CaptionText;
ActiveBorder := AFrom.ActiveBorder;
InactiveBorder := AFrom.InactiveBorder;
AppWorkspace := AFrom.AppWorkspace;
Highlight := AFrom.Highlight;
HighlightText := AFrom.HighlightText;
BtnFace := AFrom.BtnFace;
BtnShadow := AFrom.BtnShadow;
GrayText := AFrom.GrayText;
BtnText := AFrom.BtnText;
InactiveCaptionText := AFrom.InactiveCaptionText;
BtnHighlight := AFrom.BtnHighlight;
color3DDkShadow := AFrom.color3DDkShadow;
color3DLight := AFrom.color3DLight;
InfoText := AFrom.InfoText;
InfoBk := AFrom.InfoBk;
//
HotLight := AFrom.HotLight;
GradientActiveCaption := AFrom.GradientActiveCaption;
GradientInactiveCaption := AFrom.GradientInactiveCaption;
MenuHighlight := AFrom.MenuHighlight;
MenuBar := AFrom.MenuBar;
Form := AFrom.Form;
end;
{ TCDListItems }
procedure TCDListItems.DoFreeItem(data, arg: pointer);
@ -430,6 +472,9 @@ begin
inherited Create;
Palette := TCDColorPalette.Create;
SetPaletteKind(palFallback);
FallbackPalette := TCDColorPalette.Create;
FallbackPalette.Assign(Palette);
SetPaletteKind(palDefault);
CreateResources;

View File

@ -40,7 +40,7 @@ uses
// Widgetset
customdrawnproc,
// LCL
customdrawn_common,
customdrawn_common, customdrawncontrols, customdrawndrawers,
lazcanvas, lazregions,
InterfaceBase, Translations,
Controls, Forms, lclproc, IntfGraphics, GraphType,

View File

@ -101,6 +101,7 @@ begin
// Prepare the non-native image and canvas
UpdateControlLazImageAndCanvas(lCurForm.Image, lCurForm.Canvas, Width, Height, clfRGBA32, pixels, True, False);
DrawFormBackground(lCurForm.Image, lCurForm.Canvas);
struct.hdc := HDC(lCurForm.Canvas);

View File

@ -57,6 +57,7 @@ procedure HideForm(ACDForm: TCDNonNativeForm);
procedure UpdateControlLazImageAndCanvas(var AImage: TLazIntfImage;
var ACanvas: TLazCanvas; AWidth, AHeight: Integer; AFormat: TUpdateLazImageFormat;
AData: Pointer = nil; AForceUpdate: Boolean = False; AFreeImageOnUpdate: Boolean = True);
procedure DrawFormBackground(var AImage: TLazIntfImage; var ACanvas: TLazCanvas);
procedure RenderChildWinControls(var AImage: TLazIntfImage;
var ACanvas: TLazCanvas; ACDControlsList: TFPList);
//procedure RenderWinControl(var AImage: TLazIntfImage;
@ -203,6 +204,16 @@ begin
{$ENDIF}
end;
procedure DrawFormBackground(var AImage: TLazIntfImage; var ACanvas: TLazCanvas);
begin
ACanvas.SaveState;
ACanvas.ResetCanvasState;
ACanvas.Brush.FPColor := TColorToFPColor(ColorToRGB(clForm));
ACanvas.Pen.FPColor := TColorToFPColor(ColorToRGB(clForm));
ACanvas.Rectangle(0, 0, AImage.Width, AImage.Height);
ACanvas.RestoreState;
end;
procedure RenderChildWinControls(var AImage: TLazIntfImage;
var ACanvas: TLazCanvas; ACDControlsList: TFPList);
var

View File

@ -3530,105 +3530,63 @@ begin
{$ifdef VerboseQtWinAPI}
WriteLn('Trace:< [WinAPI GetStockObject] Value: ', Value);
{$endif}
end;
end;*)
{------------------------------------------------------------------------------
Function: TQtWidgetSet.GetSysColor
Function: TCDWidgetSet.GetSysColor
Params: index to the syscolors array
Returns: RGB value
------------------------------------------------------------------------------}
function TQtWidgetSet.GetSysColor(nIndex: Integer): DWORD;
function GetColor(Group: QPaletteColorGroup; Role: QPaletteColorRole; ClassName: PAnsiChar = nil): TColor;
var
Handle: QPaletteH;
QColor: PQColor;
QC: QColorH;
begin
Handle := QPalette_create;
if ClassName = nil then
QApplication_palette(Handle)
else
QApplication_palette(Handle, ClassName);
QColor := QPalette_color(Handle, Group, Role);
QC := QColor_create(QColor);
try
Result := (QColor_red(QC) and $00FF) or ((QColor_green(QC) and $00FF) shl 8) or ((QColor_blue(QC) and $00FF) shl 16);
finally
QColor_destroy(QC);
end;
QPalette_destroy(Handle);
end;
function TCDWidgetSet.GetSysColor(nIndex: Integer): DWORD;
begin
if (nIndex < 0) or (nIndex > MAX_SYS_COLORS) then
begin
{$ifdef VerboseQtWinAPI}
WriteLn('Trace:Unknown lcl system color: [TQtWidgetSet.GetSysColor]');
{$endif}
DebugLn('[TCDWidgetSet.GetSysColor] Unknown lcl system color: ');
Result := 0;
Exit;
end;
if FCachedColors[nIndex] = nil then
begin
case nIndex of
COLOR_SCROLLBAR : Result:=GetColor(QPaletteActive, QPaletteButton);
COLOR_BACKGROUND : Result:=GetColor(QPaletteActive, QPaletteWindow);
COLOR_WINDOW : Result:=GetColor(QPaletteInActive, QPaletteBase);
COLOR_WINDOWFRAME : Result:=GetColor(QPaletteActive, QPaletteShadow);
COLOR_WINDOWTEXT : Result:=GetColor(QPaletteActive, QPaletteWindowText);
COLOR_ACTIVEBORDER : Result:=GetColor(QPaletteActive, QPaletteWindow);
COLOR_INACTIVEBORDER : Result:=GetColor(QPaletteInactive, QPaletteWindow);
COLOR_APPWORKSPACE : Result:=GetColor(QPaletteActive, QPaletteWindow);
COLOR_HIGHLIGHT : Result:=GetColor(QPaletteActive, QPaletteHighlight);
COLOR_HIGHLIGHTTEXT : Result:=GetColor(QPaletteActive, QPaletteHighlightedText);
COLOR_BTNFACE : Result:=GetColor(QPaletteActive, QPaletteButton);
COLOR_BTNSHADOW : Result:=GetColor(QPaletteActive, QPaletteDark);
COLOR_GRAYTEXT : Result:=GetColor(QPaletteDisabled, QPaletteText);
COLOR_BTNTEXT : Result:=GetColor(QPaletteActive, QPaletteButtonText);
COLOR_BTNHIGHLIGHT : Result:=GetColor(QPaletteActive, QPaletteLight);
COLOR_3DDKSHADOW : Result:=GetColor(QPaletteActive, QPaletteShadow);
COLOR_3DLIGHT : Result:=GetColor(QPaletteActive, QPaletteMidlight);
COLOR_INFOTEXT : Result:=GetColor(QPaletteInActive, QPaletteToolTipText);
COLOR_INFOBK : Result:=GetColor(QPaletteInActive, QPaletteToolTipBase);
COLOR_HOTLIGHT : Result:=GetColor(QPaletteActive, QPaletteLight);
// qt does not provide any methods to retrieve titlebar colors
{$IFNDEF MSWINDOWS}
COLOR_ACTIVECAPTION : Result:=GetColor(QPaletteActive, QPaletteHighlight);
COLOR_INACTIVECAPTION : Result:=GetColor(QPaletteInActive, QPaletteHighlight);
COLOR_CAPTIONTEXT : Result:=GetColor(QPaletteActive, QPaletteHighlightedText);
COLOR_INACTIVECAPTIONTEXT : Result:=GetColor(QPaletteInactive, QPaletteHighlightedText);
COLOR_GRADIENTACTIVECAPTION : Result:=GetColor(QPaletteActive, QPaletteBase);
COLOR_GRADIENTINACTIVECAPTION : Result:=GetColor(QPaletteInactive, QPaletteBase);
{$ELSE}
COLOR_ACTIVECAPTION : Result:=Windows.GetSysColor(COLOR_ACTIVECAPTION);
COLOR_INACTIVECAPTION : Result:=Windows.GetSysColor(COLOR_INACTIVECAPTION);
COLOR_CAPTIONTEXT : Result:=Windows.GetSysColor(COLOR_CAPTIONTEXT);
COLOR_INACTIVECAPTIONTEXT : Result:=Windows.GetSysColor(COLOR_INACTIVECAPTIONTEXT);
COLOR_GRADIENTACTIVECAPTION : Result:=Windows.GetSysColor(COLOR_GRADIENTACTIVECAPTION);
COLOR_GRADIENTINACTIVECAPTION : Result:=Windows.GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
{$ENDIF}
COLOR_MENU : Result:=GetColor(QPaletteActive, QPaletteButton, 'QMenu');
COLOR_MENUTEXT : Result:=GetColor(QPaletteActive, QPaletteButtonText, 'QMenu');
COLOR_MENUHILIGHT : Result:=GetColor(QPaletteDisabled, QPaletteHighlight, 'QMenu');
COLOR_MENUBAR : Result:=GetColor(QPaletteActive, QPaletteButton, 'QMenu');
COLOR_FORM : Result:=GetColor(QPaletteActive, QPaletteWindow);
else
Result:=0;
end;
FCachedColors[nIndex] := getMem(SizeOf(LongWord));
FCachedColors[nIndex]^ := Result;
end
case nIndex of
COLOR_SCROLLBAR : Result:=GetDefaultDrawer().FallbackPalette.ScrollBar;
COLOR_BACKGROUND : Result:=GetDefaultDrawer().FallbackPalette.Background;
COLOR_ACTIVECAPTION : Result:=GetDefaultDrawer().FallbackPalette.ActiveCaption;
COLOR_INACTIVECAPTION : Result:=GetDefaultDrawer().FallbackPalette.InactiveCaption;
COLOR_MENU : Result:=GetDefaultDrawer().FallbackPalette.Menu;
COLOR_WINDOW : Result:=GetDefaultDrawer().FallbackPalette.Window;
COLOR_WINDOWFRAME : Result:=GetDefaultDrawer().FallbackPalette.WindowFrame;
COLOR_MENUTEXT : Result:=GetDefaultDrawer().FallbackPalette.MenuText;
COLOR_WINDOWTEXT : Result:=GetDefaultDrawer().FallbackPalette.WindowText;
COLOR_CAPTIONTEXT : Result:=GetDefaultDrawer().FallbackPalette.CaptionText;
COLOR_ACTIVEBORDER : Result:=GetDefaultDrawer().FallbackPalette.ActiveBorder;
COLOR_INACTIVEBORDER : Result:=GetDefaultDrawer().FallbackPalette.InactiveBorder;
COLOR_APPWORKSPACE : Result:=GetDefaultDrawer().FallbackPalette.AppWorkspace;
COLOR_HIGHLIGHT : Result:=GetDefaultDrawer().FallbackPalette.Highlight;
COLOR_HIGHLIGHTTEXT : Result:=GetDefaultDrawer().FallbackPalette.HighlightText;
COLOR_BTNFACE : Result:=GetDefaultDrawer().FallbackPalette.BtnFace;
COLOR_BTNSHADOW : Result:=GetDefaultDrawer().FallbackPalette.BtnShadow;
COLOR_GRAYTEXT : Result:=GetDefaultDrawer().FallbackPalette.GrayText;
COLOR_BTNTEXT : Result:=GetDefaultDrawer().FallbackPalette.BtnText;
COLOR_INACTIVECAPTIONTEXT : Result:=GetDefaultDrawer().FallbackPalette.InactiveCaptionText;
COLOR_BTNHIGHLIGHT : Result:=GetDefaultDrawer().FallbackPalette.BtnHighlight;
COLOR_3DDKSHADOW : Result:=GetDefaultDrawer().FallbackPalette.color3DDkShadow;
COLOR_3DLIGHT : Result:=GetDefaultDrawer().FallbackPalette.color3DLight;
COLOR_INFOTEXT : Result:=GetDefaultDrawer().FallbackPalette.InfoText;
COLOR_INFOBK : Result:=GetDefaultDrawer().FallbackPalette.InfoBk;
//
COLOR_HOTLIGHT : Result:=GetDefaultDrawer().FallbackPalette.HotLight;
COLOR_GRADIENTACTIVECAPTION : Result:=GetDefaultDrawer().FallbackPalette.GradientActiveCaption;
COLOR_GRADIENTINACTIVECAPTION : Result:=GetDefaultDrawer().FallbackPalette.GradientInactiveCaption;
COLOR_MENUHILIGHT : Result:=GetDefaultDrawer().FallbackPalette.MenuHighlight;
COLOR_MENUBAR : Result:=GetDefaultDrawer().FallbackPalette.MenuBar;
//
COLOR_FORM : Result:=GetDefaultDrawer().FallbackPalette.Form;
else
Result := FCachedColors[nIndex]^;
Result:=0;
end;
end;
function TQtWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
(*function TQtWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
function GetBrush(Group: QPaletteColorGroup; Role: QPaletteColorRole; ClassName: PAnsiChar = nil): HBrush;
var

View File

@ -126,9 +126,9 @@ function GetROP2(DC: HDC): Integer; override;
function GetScrollBarSize(Handle: HWND; BarKind: Integer): integer; override;
function GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean; override;
function GetScrollInfo(Handle: HWND; BarFlag: Integer; Var ScrollInfo: TScrollInfo): Boolean; override;
function GetStockObject(Value: Integer): THandle; override;
function GetStockObject(Value: Integer): THandle; override;*)
function GetSysColor(nIndex: Integer): DWORD; override;
function GetSysColorBrush(nIndex: Integer): HBrush; override;
(*function GetSysColorBrush(nIndex: Integer): HBrush; override;
function GetSystemMetrics(nIndex: Integer): Integer; override;
function GetTextColor(DC: HDC) : TColorRef; Override;
function GetTextExtentExPoint(DC: HDC; Str: PChar; Count, MaxWidth: Integer; MaxCount, PartialWidths: PInteger; var Size: TSize): Boolean; override;*)

View File

@ -525,13 +525,15 @@ class procedure TCDWSCustomForm.EvMousePressed(const AWinControl: TWinControl; A
var
MouseButton: TMouseButton;
lTarget: TWinControl;
lEventPos: TPoint;
begin
lTarget := FindControlWhichReceivedEvent(TCustomForm(AWinControl), AWindowInfo.Children, Event.x, Event.y);
AWindowInfo.LastMouseDownControl := lTarget;
lEventPos := FormPosToControlPos(lTarget, Event.x, Event.y);
if XButtonToMouseButton(Event.button, MouseButton) then
begin
LCLSendMouseDownMsg(lTarget, Event.x, Event.y, MouseButton, [])
LCLSendMouseDownMsg(lTarget, lEventPos.x, lEventPos.y, MouseButton, [])
end
else
begin
@ -590,10 +592,13 @@ class procedure TCDWSCustomForm.EvMouseMove(const AWinControl: TWinControl; AWin
var Event: TXMotionEvent);
var
lTarget: TWinControl;
lEventPos: TPoint;
begin
lTarget := FindControlWhichReceivedEvent(TCustomForm(AWinControl), AWindowInfo.Children, Event.x, Event.y);
LCLSendMouseMoveMsg(lTarget, Event.x, Event.y, []);
lEventPos := FormPosToControlPos(lTarget, Event.x, Event.y);
LCLSendMouseMoveMsg(lTarget, lEventPos.x, lEventPos.y, []);
end;
// Top-level windows receive LM_ACTIVATE while constrols receive LM_SETFOCUS
@ -647,6 +652,7 @@ begin
DirectColor = 5;}
{$ENDIF}
UpdateControlLazImageAndCanvas(AWindowInfo.Image, AWindowInfo.Canvas, lWidth, lHeight, clfBGR24);
DrawFormBackground(AWindowInfo.Image, AWindowInfo.Canvas);
struct.hdc := HDC(AWindowInfo.Canvas);