Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. Index: cocoathemes.pas
  2. ===================================================================
  3. --- cocoathemes.pas (revision 61033)
  4. +++ cocoathemes.pas (working copy)
  5. @@ -22,7 +22,7 @@
  6. LCLType, LCLProc, LCLIntf, Graphics, Themes, TmSchema,
  7. customdrawndrawers,
  8. // widgetset
  9. - CocoaUtils, CocoaGDIObjects;
  10. + CocoaUtils, CocoaGDIObjects, Cocoa_Extra;
  11.  
  12. type
  13. { TCocoaThemeServices }
  14. @@ -60,8 +60,65 @@
  15. function GetOption(AOption: TThemeOption): Integer; override;
  16. end;
  17.  
  18. +// "dark" is not a good reference, as Apple might add more and more themes
  19. +function IsDarkPossible: Boolean; inline;
  20. +function IsAppDark: Boolean;
  21. +function IsCurrentDark: Boolean;
  22. +function NSAppearanceClass: pobjc_class;
  23. +function IsAppearDark(Appear: NSAppearance): Boolean; inline;
  24. +
  25. implementation
  26.  
  27. +var
  28. + _NSAppearanceClass : pobjc_class = nil;
  29. + _NSAppearanceClassTried: Boolean = false;
  30. +
  31. +function NSAppearanceClass: pobjc_class;
  32. +begin
  33. + if not _NSAppearanceClassTried then
  34. + begin
  35. + _NSAppearanceClass := objc_getClass('NSAppearance');
  36. + end;
  37. + Result := _NSAppearanceClass;
  38. +end;
  39. +
  40. +function IsAppearDark(Appear: NSAppearance): Boolean; inline;
  41. +begin
  42. + Result := Assigned(Appear)
  43. + and Appear.name.isEqualToString(NSSTR('NSAppearanceNameVibrantDark'))
  44. +end;
  45. +
  46. +function IsDarkPossible: Boolean; inline;
  47. +begin
  48. + Result := NSAppKitVersionNumber > NSAppKitVersionNumber10_12;
  49. +end;
  50. +
  51. +function IsAppDark: Boolean;
  52. +var
  53. + Appear: NSAppearance;
  54. +begin
  55. + if not isDarkPossible then
  56. + begin
  57. + Result := false;
  58. + Exit;
  59. + end;
  60. + if (not NSApplication(NSApp).respondsToSelector(ObjCSelector('appearance:'))) then begin
  61. + Result := false;
  62. + Exit;
  63. + end;
  64. +
  65. + Result := IsAppearDark(NSApplication(NSApp).appearance);
  66. +end;
  67. +
  68. +function IsCurrentDark: Boolean;
  69. +var
  70. + cls : pobjc_class;
  71. +begin
  72. + cls := NSAppearanceClass;
  73. + if not Assigned(cls) then Exit;
  74. + Result := IsAppearDark(objc_msgSend(cls, ObjCSelector('currentAppearance')));
  75. +end;
  76. +
  77. { TCocoaThemeServices }
  78.  
  79. {------------------------------------------------------------------------------
  80. Index: cocoa_extra.pas
  81. ===================================================================
  82. --- cocoa_extra.pas (revision 61033)
  83. +++ cocoa_extra.pas (working copy)
  84. @@ -56,10 +56,17 @@
  85. procedure setEnabled_(aenabled: ObjCBool); message 'setEnabled:';
  86. end;
  87.  
  88. + NSAppearance = objcclass external(NSObject)
  89. + function name: NSString; message 'name';
  90. + class function currentAppearance: NSAppearance; message 'currentAppearance';
  91. + end;
  92. +
  93. NSApplicationFix = objccategory external (NSApplication)
  94. procedure activateIgnoringOtherApps_(flag: ObjCBool); message 'activateIgnoringOtherApps:';
  95. function nextEventMatchingMask_untilDate_inMode_dequeue_(mask: NSUInteger; expiration: NSDate; mode: NSString; deqFlag: ObjCBool): NSEvent; message 'nextEventMatchingMask:untilDate:inMode:dequeue:';
  96. procedure postEvent_atStart_(event: NSEvent; flag: ObjCBool); message 'postEvent:atStart:';
  97. +
  98. + function appearance: NSAppearance; message 'appearance'; // 10.14 (10.13)
  99. end;
  100.  
  101. NSButtonFix = objccategory external(NSButton)
  102. @@ -198,6 +205,8 @@
  103. NSAppKitVersionNumber10_10 = 1343;
  104. NSAppKitVersionNumber10_11 = 1404;
  105. NSAppKitVersionNumber10_12 = 1504;
  106. + NSAppKitVersionNumber10_13 = 1561;
  107. + NSAppKitVersionNumber10_14 = 1641.10;
  108.  
  109.  
  110. const
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement