mbColorLib: Fix keyboard handling of HexaColorPicker

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5513 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-12-16 09:13:01 +00:00
parent 03c37e0120
commit 78c00d2240

View File

@ -103,16 +103,17 @@ type
// procedure CreateWnd; override; // procedure CreateWnd; override;
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
// procedure KeyDownInterface(var Key: Word; Shift: TShiftState); override;
procedure Paint; override; procedure Paint; override;
procedure Resize; override; procedure Resize; override;
{$IFDEF DELPHI} {$IFDEF DELPHI}
procedure CNKeyDown(var Message: TWMKeyDown); message CN_KEYDOWN;
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW; procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN; procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP; procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE; procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
{$ELSE} {$ELSE}
procedure CNKeyDown(var Message: TLMKeyDown); message CN_KEYDOWN;
procedure CMHintShow(var Message: TLMessage); message CM_HINTSHOW; procedure CMHintShow(var Message: TLMessage); message CM_HINTSHOW;
procedure WMLButtonDown(var Message: TLMLButtonDown); message LM_LBUTTONDOWN; procedure WMLButtonDown(var Message: TLMLButtonDown); message LM_LBUTTONDOWN;
procedure WMLButtonUp(var Message: TLMLButtonUp); message LM_LBUTTONUP; procedure WMLButtonUp(var Message: TLMLButtonUp); message LM_LBUTTONUP;
@ -253,6 +254,34 @@ begin
end; end;
end; end;
procedure THexaColorPicker.KeyDown(var Key: Word; Shift: TShiftState);
var
eraseKey: Boolean;
begin
eraseKey := true;
if ssCtrl in Shift then
case Key of
VK_LEFT: SetSelectedColor(clWhite);
VK_RIGHT: SetSelectedColor(clBlack);
VK_UP: if FSliderVisible then SetIntensity(100);
VK_DOWN: if FSliderVisible then SetIntensity(0);
else
eraseKey := false;
end
else
case Key of
VK_LEFT: SelectCombIndex(GetPreviousCombIndex(GetSelectedCombIndex));
VK_RIGHT: SelectCombIndex(GetNextCombIndex(GetSelectedCombIndex));
VK_UP: if FSliderVisible then ChangeIntensity(true);
VK_DOWN: if FSliderVisible then ChangeIntensity(false);
else
eraseKey := false;
end;
if eraseKey then
Key := 0;
inherited;
end;
(* (*
procedure THexaColorPicker.CreateWnd; procedure THexaColorPicker.CreateWnd;
var var
@ -355,9 +384,9 @@ begin
for I := 0 to High(FColorCombs) do for I := 0 to High(FColorCombs) do
begin begin
Brush.Color := FColorCombs[I].Color; Brush.Color := FColorCombs[I].Color;
Pen.mode := pmCopy; // the pen is set here so there are no gaps between the combs Pen.Mode := pmCopy; // the pen is set here so there are no gaps between the combs
Pen.style := psSolid; Pen.Style := psSolid;
Pen.color := FColorCombs[I].Color; Pen.Color := FColorCombs[I].Color;
DrawComb(OffScreen.Canvas, FColorCombs[I].Position.X + XOffs, FColorCombs[I].Position.Y + YOffs, FCombSize); DrawComb(OffScreen.Canvas, FColorCombs[I].Position.X + XOffs, FColorCombs[I].Position.Y + YOffs, FCombSize);
end; end;
@ -1345,7 +1374,7 @@ procedure THexaColorPicker.ChangeIntensity(increase: boolean);
var var
i: integer; i: integer;
begin begin
i := ROUND(FCenterIntensity * 100); i := round(FCenterIntensity * 100);
if increase then if increase then
begin begin
Inc(i, FIncrement); Inc(i, FIncrement);
@ -1399,17 +1428,15 @@ begin
rw := Round(Width/2 - 5); rw := Round(Width/2 - 5);
rh := Round((24/53)*(Height - 6)); rh := Round((24/53)*(Height - 6));
SetRadius(Min(rw, rh)); SetRadius(Min(rw, rh));
end;
inherited; inherited;
end; end;
end; (*
procedure THexaColorPicker.CNKeyDown( procedure THexaColorPicker.CNKeyDown(
var Message: {$IFDEF FPC}TLMKeyDown{$ELSE}TWMKeyDown{$ENDIF}); var Message: {$IFDEF FPC}TLMKeyDown{$ELSE}TWMKeyDown{$ENDIF});
var var
Shift: TShiftState; Shift: TShiftState;
FInherited: boolean;
begin begin
FInherited := false;
Shift := KeyDataToShiftState(Message.KeyData); Shift := KeyDataToShiftState(Message.KeyData);
if ssCtrl in Shift then if ssCtrl in Shift then
case Message.CharCode of case Message.CharCode of
@ -1418,10 +1445,8 @@ begin
VK_UP: if FSliderVisible then SetIntensity(100); VK_UP: if FSliderVisible then SetIntensity(100);
VK_DOWN: if FSliderVisible then SetIntensity(0); VK_DOWN: if FSliderVisible then SetIntensity(0);
else else
begin if Assigned(OnKeyDown) then
FInherited := true; OnKeyDown(Self, Message.CharCode, Shift);
inherited;
end;
end end
else else
case Message.CharCode of case Message.CharCode of
@ -1430,15 +1455,12 @@ begin
VK_UP: if FSliderVisible then ChangeIntensity(true); VK_UP: if FSliderVisible then ChangeIntensity(true);
VK_DOWN: if FSliderVisible then ChangeIntensity(false); VK_DOWN: if FSliderVisible then ChangeIntensity(false);
else else
begin if Assigned(OnKeyDown) then
FInherited := true;
inherited;
end;
end;
if not FInherited and Assigned(OnKeyDown) then
OnKeyDown(Self, Message.CharCode, Shift); OnKeyDown(Self, Message.CharCode, Shift);
end; end;
Message.CharCode := 0;
end;
*)
function THexaColorPicker.SelectAvailableColor(Color: TColor): boolean; function THexaColorPicker.SelectAvailableColor(Color: TColor): boolean;
var var
I: integer; I: integer;