cocoa: Restricts reloading the NSPanel Browser only for Mac OS X versions that are affected by the Mac bug, while adding an utility function to get the OS version also refactored the two utility units into one

git-svn-id: trunk@55407 -
This commit is contained in:
sekelsenmat 2017-06-27 20:51:24 +00:00
parent ffc24202c1
commit a2fecca799
10 changed files with 306 additions and 1428 deletions

1
.gitattributes vendored
View File

@ -7874,7 +7874,6 @@ lcl/interfaces/cocoa/cocoalclintf.inc svneol=native#text/pascal
lcl/interfaces/cocoa/cocoalclintfh.inc svneol=native#text/pascal
lcl/interfaces/cocoa/cocoaobject.inc svneol=native#text/pascal
lcl/interfaces/cocoa/cocoaprivate.pp svneol=native#text/plain
lcl/interfaces/cocoa/cocoaproc.pas svneol=native#text/pascal
lcl/interfaces/cocoa/cocoathemes.pas svneol=native#text/plain
lcl/interfaces/cocoa/cocoatrayicon.inc svneol=native#text/pascal
lcl/interfaces/cocoa/cocoautils.pas svneol=native#text/plain

View File

@ -8,7 +8,6 @@ uses
cocoagdiobjects{%H-},
cocoaint{%H-},
cocoaprivate{%H-},
cocoaproc{%H-},
cocoathemes{%H-},
cocoautils{%H-},
cocoawsbuttons{%H-},

View File

@ -63,6 +63,12 @@ type
procedure setAppleMenu(AMenu: NSMenu); message 'setAppleMenu:';
end;}
NSOperatingSystemVersion = record
majorVersion: NSInteger;
minorVersion: NSInteger;
patchVersion: NSInteger;
end;
implementation
end.

View File

@ -10,7 +10,7 @@ interface
uses
MacOSAll, // for CGContextRef
LCLtype, LCLProc, Graphics, Controls, fpcanvas,
CocoaAll, CocoaProc, CocoaUtils,
CocoaAll, CocoaUtils,
cocoa_extra,
{$ifndef CocoaUseHITheme}
customdrawndrawers, customdrawn_mac,

View File

@ -36,7 +36,7 @@ uses
LCLPlatformDef, InterfaceBase, GraphType,
// private
CocoaAll, CocoaPrivate, CocoaUtils, CocoaGDIObjects,
CocoaProc, cocoa_extra, CocoaWSMenus, CocoaWSForms,
cocoa_extra, CocoaWSMenus, CocoaWSForms,
// LCL
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
Controls, Forms, Themes, Menus,

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ uses
LCLType, LCLProc, LCLIntf, Graphics, Themes, TmSchema,
customdrawndrawers,
// widgetset
CocoaProc, CocoaUtils, CocoaGDIObjects;
CocoaUtils, CocoaGDIObjects;
type
{ TCocoaThemeServices }

View File

@ -8,7 +8,8 @@ interface
uses
classes,
MacOSAll, CocoaAll,
Types, LCLType, LCLProc, menus, forms, controls;
SysUtils, Types, LCLType, LCLClasses, LCLProc, menus,//LMessages,
Controls, Forms, Graphics, Math, GraphType;
const
LCLEventSubTypeMessage = MaxShort - 1;
@ -75,6 +76,25 @@ const
function CFStringToStr(AString: CFStringRef; Encoding: CFStringEncoding = DEFAULT_CFSTRING_ENCODING): String;
function CFStringToString(AString: CFStringRef): String;
// Missing things from NSTableColumns.inc
const
NSTableColumnAutoresizingMask = 1 shl 0;
NSTableColumnUserResizingMask = 1 shl 1;
{$I mackeycodes.inc}
function VirtualKeyCodeToMac(AKey: Word): Word;
procedure FillStandardDescription(out Desc: TRawImageDescription);
procedure CreateCFString(const S: String; out AString: CFStringRef);
procedure CreateCFString(const Data: CFDataRef; Encoding: CFStringEncoding; out AString: CFStringRef);
procedure FreeCFString(var AString: CFStringRef);
function CFStringToData(AString: CFStringRef; Encoding: CFStringEncoding = DEFAULT_CFSTRING_ENCODING): CFDataRef;
function GetCurrentEventTime: double;
function GetMacOSXVersion: Integer;
implementation
procedure ColorToRGBFloat(cl: TColorRef; var r,g,b: Single); inline;
@ -186,40 +206,6 @@ begin
ShiftKeyMask := ShiftKeyMask + NSCommandKeyMask;
end;
function CFStringToStr(AString: CFStringRef; Encoding: CFStringEncoding = DEFAULT_CFSTRING_ENCODING): String;
var
Str: Pointer;
StrSize: CFIndex;
StrRange: CFRange;
begin
if AString = nil then
begin
Result := '';
Exit;
end;
// Try the quick way first
Str := CFStringGetCStringPtr(AString, Encoding);
if Str <> nil then
Result := PChar(Str)
else
begin
// if that doesn't work this will
StrRange.location := 0;
StrRange.length := CFStringGetLength(AString);
CFStringGetBytes(AString, StrRange, Encoding,
Ord('?'), False, nil, 0, StrSize);
SetLength(Result, StrSize);
if StrSize > 0 then
CFStringGetBytes(AString, StrRange, Encoding,
Ord('?'), False, @Result[1], StrSize, StrSize);
end;
end;
function CFStringToString(AString: CFStringRef): String;
begin
result:=CFStringToStr(AString);
@ -450,7 +436,268 @@ begin
Result := NSStringToString(self.className);
end;
initialization
{------------------------------------------------------------------------------
Name: VirtualKeyCodeToMac
Returns: The Mac virtual key (MK_) code for the specified virtual
key code (VK_) or 0
------------------------------------------------------------------------------}
function VirtualKeyCodeToMac(AKey: Word): Word;
begin
case AKey of
VK_BACK : Result := MK_BACKSPACE;
VK_TAB : Result := MK_TAB;
VK_RETURN : Result := MK_ENTER;
VK_PAUSE : Result := MK_PAUSE;
VK_CAPITAL : Result := MK_CAPSLOCK;
VK_ESCAPE : Result := MK_ESC;
VK_SPACE : Result := MK_SPACE;
VK_PRIOR : Result := MK_PAGUP;
VK_NEXT : Result := MK_PAGDN;
VK_END : Result := MK_END;
VK_HOME : Result := MK_HOME;
VK_LEFT : Result := MK_LEFT;
VK_UP : Result := MK_UP;
VK_RIGHT : Result := MK_RIGHT;
VK_DOWN : Result := MK_DOWN;
VK_SNAPSHOT : Result := MK_PRNSCR;
VK_INSERT : Result := MK_INS;
VK_DELETE : Result := MK_DEL;
VK_HELP : Result := MK_HELP;
VK_SLEEP : Result := MK_POWER;
VK_NUMPAD0 : Result := MK_NUMPAD0;
VK_NUMPAD1 : Result := MK_NUMPAD1;
VK_NUMPAD2 : Result := MK_NUMPAD2;
VK_NUMPAD3 : Result := MK_NUMPAD3;
VK_NUMPAD4 : Result := MK_NUMPAD4;
VK_NUMPAD5 : Result := MK_NUMPAD5;
VK_NUMPAD6 : Result := MK_NUMPAD6;
VK_NUMPAD7 : Result := MK_NUMPAD7;
VK_NUMPAD8 : Result := MK_NUMPAD8;
VK_NUMPAD9 : Result := MK_NUMPAD9;
VK_MULTIPLY : Result := MK_PADMULT;
VK_ADD : Result := MK_PADADD;
VK_SEPARATOR : Result := MK_PADDEC;
VK_SUBTRACT : Result := MK_PADSUB;
VK_DECIMAL : Result := MK_PADDEC;
VK_DIVIDE : Result := MK_PADDIV;
VK_F1 : Result := MK_F1;
VK_F2 : Result := MK_F2;
VK_F3 : Result := MK_F3;
VK_F4 : Result := MK_F4;
VK_F5 : Result := MK_F5;
VK_F6 : Result := MK_F6;
VK_F7 : Result := MK_F7;
VK_F8 : Result := MK_F8;
VK_F9 : Result := MK_F9;
VK_F10 : Result := MK_F10;
VK_F11 : Result := MK_F11;
VK_F12 : Result := MK_F12;
VK_F13 : Result := MK_F13;
VK_F14 : Result := MK_F14;
VK_F15 : Result := MK_F15;
VK_NUMLOCK : Result := MK_NUMLOCK;
VK_SCROLL : Result := MK_SCRLOCK;
VK_SHIFT : Result := MK_SHIFTKEY;
VK_CONTROL : Result := MK_COMMAND;
VK_MENU : Result := MK_ALT;
VK_OEM_3 : Result := MK_TILDE;
VK_OEM_MINUS : Result := MK_MINUS;
VK_OEM_PLUS : Result := MK_EQUAL;
VK_OEM_5 : Result := MK_BACKSLASH;
VK_OEM_4 : Result := MK_LEFTBRACKET;
VK_OEM_6 : Result := MK_RIGHTBRACKET;
VK_OEM_1 : Result := MK_SEMICOLON;
VK_OEM_7 : Result := MK_QUOTE;
VK_OEM_COMMA : Result := MK_COMMA;
VK_OEM_PERIOD: Result := MK_PERIOD;
VK_OEM_2 : Result := MK_SLASH;
else
Result := 0;
end;
end;
{------------------------------------------------------------------------------
Name: FillStandardDescription
Params: Desc - Raw image description
Fills the raw image description with standard Cocoa internal image storing
description
------------------------------------------------------------------------------}
procedure FillStandardDescription(out Desc: TRawImageDescription);
begin
Desc.Init;
Desc.Format := ricfRGBA;
// Width and Height skipped
Desc.PaletteColorCount := 0;
Desc.BitOrder := riboReversedBits;
Desc.ByteOrder := riboMSBFirst;
Desc.LineEnd := rileDQWordBoundary; // 128bit aligned
Desc.LineOrder := riloTopToBottom;
Desc.BitsPerPixel := 32;
Desc.Depth := 32;
// 8-8-8-8 mode, $AARRGGBB
Desc.RedPrec := 8;
Desc.GreenPrec := 8;
Desc.BluePrec := 8;
Desc.AlphaPrec := 8;
Desc.AlphaShift := 24;
Desc.RedShift := 16;
Desc.GreenShift := 08;
Desc.BlueShift := 00;
Desc.MaskBitOrder := riboReversedBits;
Desc.MaskBitsPerPixel := 1;
Desc.MaskLineEnd := rileByteBoundary;
Desc.MaskShift := 0;
end;
{------------------------------------------------------------------------------
Name: CreateCFString
Params: S - UTF-8 string
AString - Core Foundation string ref
Creates new Core Foundation string from the specified string
------------------------------------------------------------------------------}
procedure CreateCFString(const S: String; out AString: CFStringRef);
begin
AString := CFStringCreateWithCString(nil, Pointer(PChar(S)), DEFAULT_CFSTRING_ENCODING);
end;
{------------------------------------------------------------------------------
Name: CreateCFString
Params: Data - CFDataRef
Encoding - Data encoding format
AString - Core Foundation string ref
Creates new Core Foundation string from the specified data and format
------------------------------------------------------------------------------}
procedure CreateCFString(const Data: CFDataRef; Encoding: CFStringEncoding; out
AString: CFStringRef);
begin
AString := nil;
if Data = nil then Exit;
AString := CFStringCreateWithBytes(nil, CFDataGetBytePtr(Data),
CFDataGetLength(Data), Encoding, False);
end;
{------------------------------------------------------------------------------
Name: FreeCFString
Params: AString - Core Foundation string ref to free
Frees specified Core Foundation string
------------------------------------------------------------------------------}
procedure FreeCFString(var AString: CFStringRef);
begin
if AString <> nil then
CFRelease(Pointer(AString));
end;
{------------------------------------------------------------------------------
Name: CFStringToStr
Params: AString - Core Foundation string ref
Encoding - Result data encoding format
Returns: UTF-8 string
Converts Core Foundation string to string
------------------------------------------------------------------------------}
function CFStringToStr(AString: CFStringRef; Encoding: CFStringEncoding): String;
var
Str: Pointer;
StrSize: CFIndex;
StrRange: CFRange;
begin
if AString = nil then
begin
Result := '';
Exit;
end;
// Try the quick way first
Str := CFStringGetCStringPtr(AString, Encoding);
if Str <> nil then
Result := PChar(Str)
else
begin
// if that doesn't work this will
StrRange.location := 0;
StrRange.length := CFStringGetLength(AString);
CFStringGetBytes(AString, StrRange, Encoding,
Ord('?'), False, nil, 0, StrSize);
SetLength(Result, StrSize);
if StrSize > 0 then
CFStringGetBytes(AString, StrRange, Encoding,
Ord('?'), False, @Result[1], StrSize, StrSize);
end;
end;
{------------------------------------------------------------------------------
Name: CFStringToData
Params: AString - Core Foundation string ref
Encoding - Result data encoding format
Returns: CFDataRef
Converts Core Foundation string to data
------------------------------------------------------------------------------}
function CFStringToData(AString: CFStringRef; Encoding: CFStringEncoding): CFDataRef;
var
S: String;
begin
Result := nil;
if AString = nil then Exit;
S := CFStringToStr(AString, Encoding);
if Length(S) > 0 then
Result := CFDataCreate(nil, @S[1], Length(S))
else
Result := CFDataCreate(nil, nil, 0);
end;
function GetCurrentEventTime: double;
// returns seconds since system startup
begin
Result := AbsoluteToDuration(UpTime) / 1000.0;
end;
function GetMacOSXVersion: Integer;
var
lVersionNSStr: NSString;
lVersionStr: string;
lParser: TStringList;
lMajor: integer = 0;
lMinor: integer = 0;
lFix: integer = 0;
begin
Result := 0;
lVersionNSStr := NSProcessInfo.processInfo.operatingSystemVersionString;
lVersionStr := NSStringToString(lVersionNSStr);
lParser := TStringList.Create;
try
lParser.Delimiter := ' ';
lParser.DelimitedText := lVersionStr;
if lParser.Count >= 2 then
begin
lVersionStr := lParser.Strings[1];
lParser.Delimiter := '.';
lParser.DelimitedText := lVersionStr;
if lParser.Count = 3 then
begin
TryStrToInt(lParser.Strings[0], lMajor);
TryStrToInt(lParser.Strings[1], lMinor);
TryStrToInt(lParser.Strings[2], lFix);
end;
end;
finally
lParser.Free;
end;
Result := lMajor*$10000 + lMinor*$100 + lFix;
end;
end.

View File

@ -17,7 +17,7 @@ uses
// WS
WSComCtrls,
// Cocoa WS
CocoaPrivate, CocoaUtils, CocoaProc, CocoaWSCommon;
CocoaPrivate, CocoaUtils, CocoaWSCommon;
type

View File

@ -202,7 +202,8 @@ var
lFilter.setTarget(lFilter);
lFilter.setAction(objcselector('comboboxAction:'));
lFilter.updateFilterList();
lFilter.setDialogFilter(0);
lFilter.lastSelectedItemIndex := FileDialog.FilterIndex-1;
lFilter.setDialogFilter(lFilter.lastSelectedItemIndex);
accessoryView.addSubview(lText.autorelease);
accessoryView.addSubview(lFilter.autorelease);
@ -261,6 +262,8 @@ begin
FileDialog.Files.Add(NSStringToString(
NSURL(openDlg.URLs.objectAtIndex(i)).path));
FileDialog.UserChoice := mrOk;
if lFilter <> nil then
FileDialog.FilterIndex := lFilter.lastSelectedItemIndex+1;
end;
end
else if FileDialog.FCompStyle = csSaveFileDialog then
@ -278,9 +281,12 @@ begin
FileDialog.FileName := NSStringToString(saveDlg.URL.path);
FileDialog.Files.Clear;
FileDialog.UserChoice := mrOk;
if lFilter <> nil then
FileDialog.FilterIndex := lFilter.lastSelectedItemIndex+1;
end;
end;
// release everything
LocalPool.Release;
@ -646,7 +652,7 @@ procedure TCocoaFilterComboBox.setDialogFilter(ASelectedFilterIndex: Integer);
var
lCurFilter: TStringList;
ns: NSString;
i: Integer;
i, lOSVer: Integer;
lStr: String;
begin
if Filters = nil then Exit;
@ -676,7 +682,11 @@ begin
DialogHandle.validateVisibleColumns();
// work around for bug in validateVisibleColumns() in Mavericks till 10.10.2
// see https://bugs.freepascal.org/view.php?id=28687
reloadNSPanelBrowser(DialogHandle, IsOpenDialog);
lOSVer := GetMacOSXVersion();
if (lOSVer >= $090000) and (lOSVer <= $0A0A02) then
begin
reloadNSPanelBrowser(DialogHandle, IsOpenDialog);
end;
// Felipe: setAllowedFileTypes generates misterious crashes on dialog close after combobox change if uncommented :(
// DialogHandle.setAllowedFileTypes(NSFilters);