mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-12 09:59:17 +02:00
cocoa: update control title routine. Using the function for CocoaBox titles. fixes #33989
git-svn-id: trunk@58520 -
This commit is contained in:
parent
88721aeed3
commit
5b97504b36
@ -102,6 +102,13 @@ procedure NSResponderHotKeys(asender: NSResponder; event: NSEvent; var handled:
|
||||
function DateTimeToNSDate(const aDateTime : TDateTime): NSDate;
|
||||
function NSDateToDateTime(const aDateTime: NSDate): TDateTime;
|
||||
|
||||
// The function removes single & and replaced && with &
|
||||
// (removing LCL (Windows) specific caption convention
|
||||
function ControlTitleToStr(const ATitle: string): String;
|
||||
// The returned NSString doesn't require a release
|
||||
// (it would happen in NSAutoRelease pool)
|
||||
function ControlTitleToNSStr(const ATitle: string): NSString;
|
||||
|
||||
implementation
|
||||
|
||||
procedure ColorToRGBFloat(cl: TColorRef; var r,g,b: Single); inline;
|
||||
@ -794,6 +801,20 @@ begin
|
||||
Result:= aDateTime.timeIntervalSince1970 / SecsPerDay + EncodeDate(1970, 1, 1);
|
||||
end;
|
||||
|
||||
function ControlTitleToStr(const ATitle: string): String;
|
||||
begin
|
||||
Result := ATitle;
|
||||
DeleteAmpersands(Result);
|
||||
end;
|
||||
|
||||
function ControlTitleToNSStr(const ATitle: string): NSString;
|
||||
var
|
||||
t: string;
|
||||
begin
|
||||
t := ControlTitleToStr(ATitle);
|
||||
if t = '' then Result:=NSString.string_ // empty string
|
||||
else Result := NSString.stringWithUTF8String( @t[1] );
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -414,12 +414,10 @@ end;
|
||||
class procedure TCocoaWSCustomPage.SetProperties(
|
||||
const ACustomPage: TCustomPage; ACocoaControl: NSTabViewItem);
|
||||
var
|
||||
lHintStr, lTitle: string;
|
||||
lHintStr: string;
|
||||
begin
|
||||
// title
|
||||
lTitle := ACustomPage.Caption;
|
||||
DeleteAmpersands(lTitle);
|
||||
ACocoaControl.setLabel(NSStringUTF8(lTitle));
|
||||
ACocoaControl.setLabel(ControlTitleToNSStr(ACustomPage.Caption));
|
||||
|
||||
// hint
|
||||
if ACustomPage.ShowHint then lHintStr := ACustomPage.Hint
|
||||
@ -445,9 +443,7 @@ begin
|
||||
|
||||
page := GetCocoaTabPageFromHandle(AWinControl.Handle);
|
||||
if not Assigned(page) then Exit;
|
||||
lTitle := AText;
|
||||
DeleteAmpersands(lTitle);
|
||||
page.setLabel(NSStringUTF8(lTitle));
|
||||
page.setLabel(ControlTitleToNSStr(AText));
|
||||
end;
|
||||
|
||||
class function TCocoaWSCustomPage.GetText(const AWinControl: TWinControl;
|
||||
|
@ -112,7 +112,6 @@ type
|
||||
class function NSMenuCheckmark: NSImage;
|
||||
class function NSMenuRadio: NSImage;
|
||||
class function isSeparator(const ACaption: AnsiString): Boolean;
|
||||
class function MenuCaption(const ACaption: AnsiString): AnsiString;
|
||||
published
|
||||
class procedure AttachMenu(const AMenuItem: TMenuItem); override;
|
||||
class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override;
|
||||
@ -413,17 +412,6 @@ begin
|
||||
Result:=ACaption='-';
|
||||
end;
|
||||
|
||||
class function TCocoaWSMenuItem.MenuCaption(const ACaption: AnsiString): AnsiString;
|
||||
var
|
||||
i : Integer;
|
||||
begin
|
||||
i:=Pos('&', ACaption);
|
||||
if i>0 then
|
||||
Result:=Copy(ACaption, 1, i-1)+Copy(ACaption,i+1, length(ACaption))
|
||||
else
|
||||
Result:=ACaption;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCocoaWSMenuItem.AttachMenu
|
||||
Params: AMenuItem - LCL menu item
|
||||
@ -435,8 +423,6 @@ var
|
||||
ParObj : NSObject;
|
||||
Parent : TCocoaMenu;
|
||||
item : NSMenuItem;
|
||||
ns : NSString;
|
||||
str : string;
|
||||
begin
|
||||
if not Assigned(AMenuItem) or (AMenuItem.Handle=0) or not Assigned(AMenuItem.Parent) or (AMenuItem.Parent.Handle=0) then Exit;
|
||||
ParObj:=NSObject(AMenuItem.Parent.Handle);
|
||||
@ -446,13 +432,9 @@ begin
|
||||
begin
|
||||
if not NSMenuItem(ParObj).hasSubmenu then
|
||||
begin
|
||||
str := AMenuItem.Parent.Caption;
|
||||
DeleteAmpersands(str);
|
||||
ns := NSStringUtf8(pchar(str));
|
||||
Parent := TCocoaMenu.alloc.initWithTitle(ns);
|
||||
Parent := TCocoaMenu.alloc.initWithTitle( ControlTitleToNSStr(AMenuItem.Parent.Caption));
|
||||
Parent.setDelegate(TCocoaMenuItem(ParObj));
|
||||
NSMenuItem(ParObj).setSubmenu(Parent);
|
||||
ns.release;
|
||||
end
|
||||
else
|
||||
Parent:=TCocoaMenu(NSMenuItem(ParObj).submenu);
|
||||
@ -475,7 +457,6 @@ class function TCocoaWSMenuItem.CreateHandle(const AMenuItem: TMenuItem): HMENU;
|
||||
var
|
||||
item : NSMenuItem;
|
||||
ANSMenu : NSMenu;
|
||||
s : string;
|
||||
ns : NSString;
|
||||
nsKey : NSString;
|
||||
key : string;
|
||||
@ -504,12 +485,11 @@ begin
|
||||
end
|
||||
else
|
||||
begin
|
||||
s := AMenuItem.Caption;
|
||||
DeleteAmpersands(s);
|
||||
ShortcutToKeyEquivalent(AMenuItem.ShortCut, nsKey, ShiftSt);
|
||||
|
||||
ns := NSStringUtf8(s);
|
||||
item := TCocoaMenuItem(TCocoaMenuItem.alloc).initWithTitle_action_keyEquivalent(ns,
|
||||
ns := ControlTitleToNSStr(AMenuItem.Caption);
|
||||
item := TCocoaMenuItem(TCocoaMenuItem.alloc).initWithTitle_action_keyEquivalent(
|
||||
ns,
|
||||
objcselector('lclItemSelected:'), nsKey);
|
||||
item.setKeyEquivalentModifierMask(ShiftSt);
|
||||
TCocoaMenuItem(item).FMenuItemTarget := AMenuItem;
|
||||
|
@ -328,20 +328,13 @@ const
|
||||
);
|
||||
|
||||
function AllocButton(const ATarget: TWinControl; const ACallBackClass: TLCLButtonCallBackClass; const AParams: TCreateParams; btnBezel: NSBezelStyle; btnType: NSButtonType): TCocoaButton;
|
||||
var
|
||||
titel:string;
|
||||
cap: NSString;
|
||||
begin
|
||||
Result := TCocoaButton.alloc.lclInitWithCreateParams(AParams);
|
||||
if Assigned(Result) then
|
||||
begin
|
||||
TCocoaButton(Result).callback := ACallBackClass.Create(Result, ATarget);
|
||||
titel:=aParams.Caption;
|
||||
DeleteAmpersands(titel);
|
||||
cap := NSStringUTF8(titel);
|
||||
|
||||
Result.setTitle(cap);
|
||||
cap.release;
|
||||
Result.setTitle(ControlTitleToNSStr(AParams.Caption));
|
||||
if btnBezel <> 0 then
|
||||
Result.setBezelStyle(btnBezel);
|
||||
Result.setButtonType(btnType);
|
||||
@ -524,15 +517,8 @@ end;
|
||||
|
||||
|
||||
class procedure TCocoaWSButton.SetText(const AWinControl: TWinControl; const AText: String);
|
||||
var
|
||||
titel:string;
|
||||
cap: NSString;
|
||||
begin
|
||||
titel:=AText;
|
||||
DeleteAmpersands(titel);
|
||||
cap := NSStringUTF8(titel);
|
||||
NSButton(AWinControl.Handle).setTitle(cap);
|
||||
cap.release;
|
||||
NSButton(AWinControl.Handle).setTitle(ControlTitleToNSStr(AText));
|
||||
end;
|
||||
|
||||
class function TCocoaWSButton.GetText(const AWinControl: TWinControl;
|
||||
@ -1563,7 +1549,7 @@ var
|
||||
box: TCocoaGroupBox;
|
||||
begin
|
||||
box := TCocoaGroupBox(AWinControl.Handle);
|
||||
box.setTitle(NSStringUTF8(AText));
|
||||
box.setTitle(ControlTitleToNSStr(AText));
|
||||
end;
|
||||
|
||||
{ TCocoaWSCustomListBox }
|
||||
|
Loading…
Reference in New Issue
Block a user