Esempio n. 1
0
        public OptionListMonobjc(NSRect aRect, Option aOption)
            : base(aOption)
        {
            iList       = new List <string>(StringListConverter.StringToList(iOption.Value));
            iDataSource = new OptionListMonobjcDataSource();
            iDataSource.SetList(iList);

            iView = new NSView();

            iButtonAdd            = new NSButton();
            iButtonAdd.BezelStyle = NSBezelStyle.NSRoundedBezelStyle;
            iButtonAdd.Title      = new NSString("Add");
            iButtonAdd.SizeToFit();

            iButtonAdd.ActionEvent += ActionEventAdd;

            iButtonRemove            = new NSButton();
            iButtonRemove.BezelStyle = NSBezelStyle.NSRoundedBezelStyle;
            iButtonRemove.SetTitleWithMnemonic(new NSString("Remove"));
            iButtonRemove.SizeToFit();
            float height = 100 + iButtonAdd.Frame.Height;

            iButtonRemove.ActionEvent += ActionEventRemove;

            iView.Frame = new NSRect(aRect.MinX, aRect.MinY - height, aRect.Width, 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;

            iTableView            = new NSTableView();
            iTableView.DataSource = iDataSource;
            iTableView.HeaderView = null;
            iTableView.UsesAlternatingRowBackgroundColors = true;
            iTableView.AddTableColumn(tableColumn);

            scrollView.Frame  = new NSRect(0, height - 100, aRect.Width, 100);
            iTableView.Frame  = scrollView.ContentView.Bounds;
            tableColumn.Width = iTableView.Bounds.Width - 3;

            scrollView.DocumentView = iTableView;

            iButtonAdd.Frame    = new NSRect(iView.Frame.Width - iButtonAdd.Frame.Width - iButtonRemove.Frame.Width, scrollView.Frame.MinY - iButtonAdd.Frame.Height, iButtonAdd.Frame.Width, iButtonAdd.Frame.Height);
            iButtonRemove.Frame = new NSRect(iView.Frame.Width - iButtonRemove.Frame.Width, scrollView.Frame.MinY - iButtonRemove.Frame.Height, iButtonRemove.Frame.Width, iButtonRemove.Frame.Height);

            iView.AddSubview(scrollView);
            iView.AddSubview(iButtonAdd);
            iView.AddSubview(iButtonRemove);

            iTableView.ReloadData();
        }
Esempio n. 2
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();
        }