Esempio n. 1
0
        public void TestStaticCreation()
        {
			NSArray constraints;
			NSDictionary views;
			
			NSView view = new NSView(new NSRect(0, 0, 512, 512));
			NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button1);
			button1.Release();
			NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button2);
			button2.Release();
			
			views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"button2", null);
            constraints = NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views);
            Check(constraints);
			
			view.Release();
        }
Esempio n. 2
0
        public void TestExceptions()
        {
			NSDictionary views;
			
			NSView view = new NSView(new NSRect(0, 0, 512, 512));
			NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button1);
			button1.Release();
			NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button2);
			button2.Release();
			
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, null);
			});
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", null);
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views);
			});
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"dummy", null);
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("V|[button1]-[button2]|", 0, null, views);
			});
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"dummy", null);
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("V:|[button1(>30)]|", 0, null, views);
			});
			
			view.Release();
        }
Esempio n. 3
0
        public void TestPriority()
        {
			NSLayoutConstraint constraint;
			NSArray constraints;
			NSDictionary views;
			NSLayoutPriority priority;
			
			NSView view = new NSView(new NSRect(0, 0, 512, 512));
			NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button1);
			button1.Release();
			NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button2);
			button2.Release();
			
			views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"button2", null);
            constraints = NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views);
            Check(constraints);

			constraint = constraints.LastObject.CastTo<NSLayoutConstraint>();
            Check(constraint);
			
			constraint.Priority = NSLayoutPriority.NSLayoutPriorityRequired;
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityRequired, priority, "Priorities should be equal");
			
			constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 1.5);
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 1, priority, "Priorities should be equal");
			
			constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 45.23);
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 45, priority, "Priorities should be equal");
			
			constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 45.75);
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 45, priority, "Priorities should be equal");
			
			view.Release();
        }
Esempio n. 4
0
        public OptionDialogMonobjc(IList <IOptionPage> aOptionPages)
        {
            // create a list of option pages
            iPages = new List <OptionPageMonobjc>();

            NSRect windowRect     = new NSRect(0, 0, kWidth, kHeight);
            float  division       = kWidth / 4;
            NSRect scrollViewRect = new NSRect(kPadding, kPadding, division - (kPadding * 2), kHeight - (kPadding * 2));
            NSRect pageRect       = new NSRect(division + kPadding, kPadding, kWidth - division - (kPadding * 2), kHeight - (kPadding * 2));

            foreach (IOptionPage page in aOptionPages)
            {
                iPages.Add(new OptionPageMonobjc(page, pageRect));
            }

            // create main window for the dialog
            iWindow = new NSWindow(windowRect,
                                   NSWindowStyleMasks.NSClosableWindowMask |
                                   NSWindowStyleMasks.NSTitledWindowMask,
                                   NSBackingStoreType.NSBackingStoreBuffered,
                                   false);
            iWindow.Title = NSString.StringWithUTF8String("User Options");
            iWindow.SetDelegate(d =>
            {
                d.WindowShouldClose += delegate(Id aSender) { return(true); };
                d.WindowWillClose   += delegate(NSNotification aNotification) { NSApplication.NSApp.AbortModal(); };
            });
            iWindow.IsReleasedWhenClosed = false;

            // create a view for the window content
            NSView view = new NSView();

            iWindow.ContentView = view;

            iOptionsContainer       = new NSView();
            iOptionsContainer.Frame = new NSRect(view.Frame.origin.x, view.Frame.origin.y, view.Frame.Width, view.Frame.Height);

            NSScrollView scrollView = new NSScrollView();

            scrollView.HasVerticalScroller   = true;
            scrollView.HasHorizontalScroller = true;
            scrollView.AutohidesScrollers    = true;

            NSTableColumn tableColumn = new NSTableColumn();

            tableColumn.ResizingMask = NSTableColumnResizingMasks.NSTableColumnAutoresizingMask | NSTableColumnResizingMasks.NSTableColumnUserResizingMask;
            tableColumn.IsEditable   = false;

            iTableDelegate   = new OptionDialogMonobjcDelegate(iPages);
            iTableDataSource = new OptionDialogMonobjcDataSource(iPages);

            iTableDelegate.EventSelectedPage += EventSelectedPageHandler;

            iTableView            = new NSTableView();
            iTableView.DataSource = iTableDataSource;
            iTableView.HeaderView = null;
            iTableView.UsesAlternatingRowBackgroundColors = true;
            iTableView.AddTableColumn(tableColumn);
            iTableView.Delegate                = iTableDelegate;
            iTableView.AllowsEmptySelection    = false;
            iTableView.AllowsMultipleSelection = false;

            scrollView.Frame  = scrollViewRect;
            iTableView.Frame  = scrollView.ContentView.Bounds;
            tableColumn.Width = iTableView.Bounds.Width - 3;

            scrollView.DocumentView = iTableView;

            view.AddSubview(iOptionsContainer);
            iOptionsContainer.AddSubview(scrollView);

            iTableView.ReloadData();

            // view have been added to the window so they can be released
            view.Release();
            tableColumn.Release();
            scrollView.Release();
        }