Added shortcut keys to labels

Support for alphabetically sorting the properties
Standardize message and add shortcuts ala Kylix
Published BorderStyle, unpublished BorderWidth
ShowAccelChar and FocusControl
ShowAccelChar and FocusControl for TLabel, escaped ampersands now work.

git-svn-id: trunk@894 -
This commit is contained in:
lazarus 2002-02-09 01:47:17 +00:00
parent 732844d0f9
commit 82e53e439f

View File

@ -1579,37 +1579,22 @@ begin
Result := Integer(gtk_object_get_data(Widget, 'AccelKey')); Result := Integer(gtk_object_get_data(Widget, 'AccelKey'));
end; end;
procedure Accelerate(const Widget : Pointer; const Msg : TLMShortCut); procedure Accelerate(const Widget : Pointer; const Msg : TLMShortCut; const Signal : string);
var GDKModifier : integer; var GDKModifier : integer;
GDKKey : word; GDKKey : word;
begin begin
if Msg.OldKey <> 0 then if Msg.OldKey <> 0 then
gtk_widget_remove_accelerators(Widget, 'activate_item', false); gtk_widget_remove_accelerators(Widget, PChar(Signal), false);
{ Map the shift states }
GDKModifier:= 0;
if ssShift in Msg.NewModifier then GDKModifier:= GDK_SHIFT_MASK;
if ssAlt in Msg.NewModifier then GDKModifier:= GDKModifier + GDK_MOD1_MASK;
if ssCtrl in Msg.NewModifier then GDKModifier:= GDKModifier + GDK_CONTROL_MASK;
GDKKey:= VK2GDK(Msg.NewKey);
{ Set the accelerator }
gtk_widget_add_accelerator(Widget, 'activate_item',
gtk_accel_group_get_default(), GDKKey, GDKModifier, GTK_ACCEL_VISIBLE);
end;
procedure AccelerateButton(const Widget : Pointer; const Msg : TLMShortCut);
var GDKModifier : integer;
GDKKey : word;
begin
if Msg.OldKey <> 0 then
gtk_widget_remove_accelerators(Widget, 'clicked', false);
{ Map the shift states } { Map the shift states }
GDKModifier:= 0; GDKModifier:= 0;
if ssShift in Msg.NewModifier then GDKModifier:= GDK_SHIFT_MASK; if ssShift in Msg.NewModifier then GDKModifier:= GDK_SHIFT_MASK;
if ssAlt in Msg.NewModifier then GDKModifier:= GDKModifier + GDK_MOD1_MASK; if ssAlt in Msg.NewModifier then GDKModifier:= GDKModifier + GDK_MOD1_MASK;
if ssCtrl in Msg.NewModifier then GDKModifier:= GDKModifier + GDK_CONTROL_MASK; if ssCtrl in Msg.NewModifier then GDKModifier:= GDKModifier + GDK_CONTROL_MASK;
GDKKey:= VK2GDK(Msg.NewKey); GDKKey:= VK2GDK(Msg.NewKey);
{ Set the accelerator } { Set the accelerator }
gtk_widget_add_accelerator(Widget, 'clicked', gtk_widget_add_accelerator(Widget, PChar(Signal),
gtk_accel_group_get_default(), GDKKey, GDKModifier, GTK_ACCEL_VISIBLE); gtk_accel_group_get_default(), GDKKey, GDKModifier, GTK_ACCEL_VISIBLE);
end; end;
@ -2706,42 +2691,56 @@ end;
Function Ampersands2Underscore(Src: PChar) : PChar; Function Ampersands2Underscore(Src: PChar) : PChar;
var var
i, j: Longint; i, j: Longint;
AmpersandCount, FirstAmpersand, NewLength: integer; ShortenChars, FirstAmpersand, NewLength, SrcLength: integer;
begin begin
// count ampersands and find first ampersand // count ampersands and find first ampersand
AmpersandCount:=0; ShortenChars:= 0;
FirstAmpersand:=-1; FirstAmpersand:= -1;
NewLength:=StrLen(Src); SrcLength:= StrLen(Src);
for i:=0 to NewLength-1 do begin
if Src[i]='&' then begin { Look for amperands. If found, check if it is an escaped ampersand.
inc(AmpersandCount); If it is, don't count it in. }
if FirstAmpersand<0 then FirstAmpersand:=i;
for i:= 0 to SrcLength - 1 do begin
if Src[i] = '&' then begin
if (i < SrcLength - 1) and (Src[i+1] = '&') then Continue;
Inc(ShortenChars);
if (FirstAmpersand < 0) and not ((i > 0) and (Src[i-1] = '&')) then begin
FirstAmpersand:= i;
Dec(ShortenChars);
end;
end; end;
end; end;
// create new PChar // create new PChar
if AmpersandCount>1 then NewLength:= SrcLength - ShortenChars;
dec(NewLength,AmpersandCount-1);
Result:=StrAlloc(NewLength+1); // +1 for #0 char at end Result:=StrAlloc(NewLength+1); // +1 for #0 char at end
// copy string without ampersands // copy string without ampersands
i:=0; i:=0;
j:=0; j:=0;
while (j<NewLength) do begin while (j < NewLength) do begin
if Src[i]<>'&' then begin if Src[i] <> '&' then begin
// copy normal char // copy normal char
Result[j]:=Src[i]; Result[j]:= Src[i];
inc(i);
inc(j);
end else begin end else begin
if i=FirstAmpersand then begin if i = FirstAmpersand then begin
// replace first ampersand with underscore // replace first ampersand with underscore
Result[j]:='_'; Result[j]:='_';
inc(i);
inc(j);
end else begin end else begin
// skip ampersand if (i < (SrcLength - 1)) and (Src[i+1] = '&') then begin
inc(i); Result[j]:= '&';
end else begin
// skip ampersand
inc(i);
continue;
end;
end; end;
end; end;
Inc(i);
Inc(j);
end; end;
Result[NewLength]:=#0; Result[NewLength]:=#0;
end; end;
@ -2753,6 +2752,14 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.86 2002/09/03 11:32:51 lazarus
Added shortcut keys to labels
Support for alphabetically sorting the properties
Standardize message and add shortcuts ala Kylix
Published BorderStyle, unpublished BorderWidth
ShowAccelChar and FocusControl
ShowAccelChar and FocusControl for TLabel, escaped ampersands now work.
Revision 1.85 2002/09/03 08:07:21 lazarus Revision 1.85 2002/09/03 08:07:21 lazarus
MG: image support, TScrollBox, and many other things from Andrew MG: image support, TScrollBox, and many other things from Andrew