Example #1
0
 partial void ObserveSystemThemeChanges()
 {
     NSDistributedNotificationCenter.GetDefaultCenter().AddObserver(
         this,
         _modeSelector,
         _themeChangedNotification,
         null);
 }
Example #2
0
        public static void Init(IActivationState activationState)
        {
            if (IsInitialized)
            {
                return;
            }

            ActivationState = activationState;
            IsInitialized   = true;

            Microsoft.Maui.Controls.Internals.Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim);

            //TODO: MAUI Accent Color?
            Color.SetAccent(Color.FromRgba(50, 79, 133, 255));

            Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c)));

#if __MOBILE__
            Device.SetIdiom(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone);
            Device.SetFlowDirection(UIApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection());
#else
            // Subscribe to notifications in OS Theme changes
            NSDistributedNotificationCenter.GetDefaultCenter().AddObserver((NSString)"AppleInterfaceThemeChangedNotification", (n) =>
            {
                var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");

                var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua);
                NSApplication.SharedApplication.Appearance = aquaAppearance;

                Application.Current?.TriggerThemeChanged(new AppThemeChangedEventArgs(interfaceStyle == "Dark" ? OSAppTheme.Dark : OSAppTheme.Light));
            });

            Device.SetIdiom(TargetIdiom.Desktop);
            Device.SetFlowDirection(NSApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection());

            if (IsMojaveOrNewer)
            {
                var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");
                var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua);
                NSApplication.SharedApplication.Appearance = aquaAppearance;
            }
#endif
            Device.SetFlags(s_flags);
            var platformServices = new IOSPlatformServices();

            Device.PlatformServices = platformServices;

#if __MOBILE__
            Device.PlatformInvalidator = platformServices;
            Device.Info = new IOSDeviceInfo();
#else
            Device.Info = new Platform.macOS.MacDeviceInfo();
#endif

            Controls.Internals.Registrar.RegisterAll(new[]
                                                     { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute), typeof(ExportFontAttribute) });
            ExpressionSearch.Default = new iOSExpressionSearch();
        }
Example #3
0
File: Forms.cs Project: hevey/maui
        static void SetupInit(IMauiContext context, InitializationOptions?maybeOptions = null)
        {
            MauiContext = context;

            Microsoft.Maui.Controls.Internals.Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim);

            Application.AccentColor = Color.FromRgba(50, 79, 133, 255);

#if __MOBILE__
            Device.SetIdiom(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone);
            Device.SetFlowDirection(UIApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection());
#else
            if (!IsInitialized)
            {
                // Only need to do this once
                // Subscribe to notifications in OS Theme changes
                NSDistributedNotificationCenter.GetDefaultCenter().AddObserver((NSString)"AppleInterfaceThemeChangedNotification", (n) =>
                {
                    var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");

                    var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua);
                    NSApplication.SharedApplication.Appearance = aquaAppearance;

                    Application.Current?.TriggerThemeChanged(new AppThemeChangedEventArgs(interfaceStyle == "Dark" ? OSAppTheme.Dark : OSAppTheme.Light));
                });
            }

            Device.SetIdiom(TargetIdiom.Desktop);
            Device.SetFlowDirection(NSApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection());

            if (IsMojaveOrNewer)
            {
                var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");
                var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua);
                NSApplication.SharedApplication.Appearance = aquaAppearance;
            }
#endif
            var platformServices = new IOSPlatformServices();

            Device.PlatformServices = platformServices;

#if __MOBILE__
            Device.PlatformInvalidator = platformServices;
#endif
            if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true)
            {
                RegisterCompatRenderers();
            }

            ExpressionSearch.Default = new iOSExpressionSearch();

            IsInitialized = true;
        }
Example #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.nsForm = NSObject.FromObject(this);

            this.texter = new PlatformTexter();
            fonts       = new Dictionary <float, NSFont>();
            fontsFixed  = new Dictionary <float, NSFont>();

            // Register this Gui for platform-independent access via interface KGuiControl
            KGui.Register(this);

            // Register this Gui for platform-independent access via interface KControls
            macControls = new MacControls();                        // set up platform-specific gui controls
            KGui.Register(new KControls(macControls));              // bind actions to them (non-platform specific)

            leftPanelClicker.Activated  += (object sender, EventArgs e) => { KGui.kControls.CloseOpenMenu(); };
            rightPanelClicker.Activated += (object sender, EventArgs e) => { KGui.kControls.CloseOpenMenu(); };

            // Text Areas

            inputTextView.alwaysDisableIBeamCursor              = false; // disable only when menus are up
            outputTextView.alwaysDisableIBeamCursor             = true;
            (textInput.DocumentView as AppKit.NSTextView).Font  = GetFont(12.0F, true);
            (textOutput.DocumentView as AppKit.NSTextView).Font = GetFont(12.0F, true);

            // Device

            { NSBox x = deviceBox; NSDeviceView y = kaemikaDevice; }  // just checking: these are the Outlets from Main.storyboard through XCode

            // Score

            { NSBox x = scoreBox; NSScoreView y = kaemikaScore; }  // just checking: these are the Outlets from Main.storyboard through XCode

            // Chart

            { NSChartView x = kaemikaChart; } // just checking: this is the Outlet from Main.storyboard through XCode

            SetChartTooltip("", new CGPoint(0, 0), new CGRect(0, 0, 0, 0));

            // Legend

            { NSBox x = legendFlyoutBox; NSGridView y = legendFlyoutMenu; } // just checking: these are the Outlets from Main.storyboard through XCode

            // Saved state

            macControls.RestorePreferences(); //needs kControls initialized
            GuiRestoreInput();

            // Dark Mode Detection

            var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");

            MacControls.darkMode = interfaceStyle == "Dark";
            MacControls.SwitchMode();

            NSDistributedNotificationCenter.GetDefaultCenter().
            AddObserver(this,
                        new ObjCRuntime.Selector("themeChanged:"),
                        new NSString("AppleInterfaceThemeChangedNotification"),
                        null);

            // Keyboard Events
            // https://stackoverflow.com/questions/32446978/swift-capture-keydown-from-nsviewcontroller
            // list of keycodes:
            // https://stackoverflow.com/questions/3202629/where-can-i-find-a-list-of-mac-virtual-key-codes

            // for modifier keys
            NSEvent.AddLocalMonitorForEventsMatchingMask(NSEventMask.FlagsChanged,
                                                         (NSEvent e) => { try { if (MyModifiersChanged(e))
                                                                                {
                                                                                    return(null);
                                                                                }
                                                                                else
                                                                                {
                                                                                    return(e);
                                                                                } } catch { return(e); } });
            // for normal, unmodified, keys
            //NSEvent.AddLocalMonitorForEventsMatchingMask(NSEventMask.KeyDown,
            //    (NSEvent e) => { try { if (MyKeyDown(e)) return null; else return e; } catch { return e; } });
        }
Example #5
0
 public SystemResPool()
 {
     NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSSystemColorsDidChangeNotification"), (obj) => { Invalidate(); });
     NSDistributedNotificationCenter.GetDefaultCenter().AddObserver(new NSString("AppleInterfaceThemeChangedNotification"), (obj) => { Invalidate(); });
 }