コード例 #1
0
		public override void ViewDidLoad ()
		{
			View = new NSView (new RectangleF (0, 0, 320, 400));
			base.ViewDidLoad ();

			var textEditFirst = new NSTextField(new System.Drawing.RectangleF(0,0,320,40));
			View.AddSubview (textEditFirst);
			var textEditSecond = new NSTextField(new System.Drawing.RectangleF(0,50,320,40));
			View.AddSubview(textEditSecond);
			var slider = new NSSlider(new System.Drawing.RectangleF(0,150,320,40));
			slider.MinValue = 0;
			slider.MaxValue = 100;
			slider.IntValue = 23;
			View.AddSubview(slider);
			var labelFull = new NSTextField(new System.Drawing.RectangleF(0,100,320,40));
			labelFull.Editable = false;
			labelFull.Bordered = false;
			labelFull.AllowsEditingTextAttributes = false;
			labelFull.DrawsBackground = false;
			View.AddSubview (labelFull);
			var sw = new NSButton(new RectangleF(0,200,320,40));
			sw.SetButtonType (NSButtonType.Switch);
			View.AddSubview (sw);
			//sw.AddObserver()

			var set = this.CreateBindingSet<SecondViewController, SecondViewModel> ();
			set.Bind (textEditFirst).For(v => v.StringValue).To (vm => vm.FirstName);
			set.Bind (textEditSecond).For(v => v.StringValue).To (vm => vm.LastName);
			set.Bind (labelFull).Described("SliderValue + ' ' + OnOffValue").For("StringValue");	
			set.Bind (slider).For("IntValue").To (vm => vm.SliderValue);
			set.Bind (sw).For(c => c.State).To (vm => vm.OnOffValue);


			set.Apply ();
		}
コード例 #2
0
		public ICredentials GetCredentials (Uri uri, IWebProxy proxy, CredentialType credentialType, ICredentials existingCredentials, bool retrying)
		{
			bool result = false;
			DispatchService.GuiSyncDispatch (() => {
				using (var ns = new NSAutoreleasePool ()) {
					var message = string.Format ("{0} needs {1} credentials to access {2}.", BrandingService.ApplicationName, 
					                             credentialType == CredentialType.ProxyCredentials ? "proxy" : "request", uri.Host);

					NSAlert alert = NSAlert.WithMessage ("Credentials Required", "OK", "Cancel", null, message);
					alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;

					NSView view = new NSView (new RectangleF (0, 0, 313, 91));

					var creds = Utility.GetCredentialsForUriFromICredentials (uri, existingCredentials);

					var usernameLabel = new NSTextField (new RectangleF (17, 55, 71, 17)) {
						Identifier = "usernameLabel",
						StringValue = "Username:"******"Password:",
						Alignment = NSTextAlignment.Right,
						Editable = false,
						Bordered = false,
						DrawsBackground = false,
						Bezeled = false,
						Selectable = false,
					};
					view.AddSubview (passwordLabel);

					var passwordInput = new NSSecureTextField (new RectangleF (93, 20, 200, 22));
					passwordInput.StringValue = creds != null ? creds.Password : string.Empty;
					view.AddSubview (passwordInput);

					alert.AccessoryView = view;
					result = alert.RunModal () == 1;

					username = usernameInput.StringValue;
					password = passwordInput.StringValue;
				}
			});

			return result ? new NetworkCredential (username, password) : null;
		}
コード例 #3
0
		static ICredentials GetCredentialsFromUser (Uri uri, IWebProxy proxy, CredentialType credentialType)
		{
			NetworkCredential result = null;

			DispatchService.GuiSyncDispatch (() => {

				using (var ns = new NSAutoreleasePool ()) {
					var message = credentialType == CredentialType.ProxyCredentials
						? GettextCatalog.GetString (
							"{0} needs credentials to access the proxy server {1}.",
							BrandingService.ApplicationName,
							uri.Host
						)
						: GettextCatalog.GetString (
							"{0} needs credentials to access {1}.",
							BrandingService.ApplicationName,
							uri.Host
						);

					var alert = NSAlert.WithMessage (
						GettextCatalog.GetString ("Credentials Required"),
						GettextCatalog.GetString ("OK"),
						GettextCatalog.GetString ("Cancel"),
						null,
						message
					);

					alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;

					var view = new NSView (new RectangleF (0, 0, 313, 91));

					var usernameLabel = new NSTextField (new RectangleF (17, 55, 71, 17)) {
						Identifier = "usernameLabel",
						StringValue = "Username:"******"Password:",
						Alignment = NSTextAlignment.Right,
						Editable = false,
						Bordered = false,
						DrawsBackground = false,
						Bezeled = false,
						Selectable = false,
					};
					view.AddSubview (passwordLabel);

					var passwordInput = new NSSecureTextField (new RectangleF (93, 20, 200, 22));
					view.AddSubview (passwordInput);

					alert.AccessoryView = view;

					if (alert.RunModal () != 1)
						return;

					var username = usernameInput.StringValue;
					var password = passwordInput.StringValue;
					result = new NetworkCredential (username, password);
				}
			});

			// store the obtained credentials in the keychain
			// but don't store for the root url since it may have other credentials
			if (result != null)
				Keychain.AddInternetPassword (uri, result.UserName, result.Password);

			return result;
		}
コード例 #4
0
ファイル: AlertDialogBackend.cs プロジェクト: akrisiun/xwt
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.MessageText = message.Text ?? String.Empty;
            this.InformativeText = message.SecondaryText ?? String.Empty;

            if (message.Icon != null)
                Icon = message.Icon.ToImageDescription (Context).ToNSImage ();

            var sortedButtons = new Command [message.Buttons.Count];
            var j = 0;
            if (message.DefaultButton >= 0) {
                sortedButtons [0] = message.Buttons [message.DefaultButton];
                this.AddButton (message.Buttons [message.DefaultButton].Label);
                j = 1;
            }
            for (var i = 0; i < message.Buttons.Count; i++) {
                if (i == message.DefaultButton)
                    continue;
                sortedButtons [j++] = message.Buttons [i];
                this.AddButton (message.Buttons [i].Label);
            }
            for (var i = 0; i < sortedButtons.Length; i++) {
                if (sortedButtons [i].Icon != null) {
                    Buttons [i].Image = sortedButtons [i].Icon.WithSize (IconSize.Small).ToImageDescription (Context).ToNSImage ();
                    Buttons [i].ImagePosition = NSCellImagePosition.ImageLeft;
                }
            }

            if (message.AllowApplyToAll) {
                ShowsSuppressionButton = true;
                SuppressionButton.State = NSCellStateValue.Off;
                SuppressionButton.Activated += (sender, e) => ApplyToAll = SuppressionButton.State == NSCellStateValue.On;
            }

            if (message.Options.Count > 0) {
                AccessoryView = new NSView ();
                var optionsSize = new CGSize (0, 3);

                foreach (var op in message.Options) {
                    var chk = new NSButton ();
                    chk.SetButtonType (NSButtonType.Switch);
                    chk.Title = op.Text;
                    chk.State = op.Value ? NSCellStateValue.On : NSCellStateValue.Off;
                    chk.Activated += (sender, e) => message.SetOptionValue (op.Id, chk.State == NSCellStateValue.On);

                    chk.SizeToFit ();
                    chk.Frame = new CGRect (new CGPoint (0, optionsSize.Height), chk.FittingSize);

                    optionsSize.Height += chk.FittingSize.Height + 6;
                    optionsSize.Width = (float) Math.Max (optionsSize.Width, chk.FittingSize.Width);

                    AccessoryView.AddSubview (chk);
                    chk.NeedsDisplay = true;
                }

                AccessoryView.SetFrameSize (optionsSize);
            }

            var win = Toolkit.CurrentEngine.GetNativeWindow (transientFor) as NSWindow;
            if (win != null)
                return sortedButtons [(int)this.RunSheetModal (win) - 1000];
            return sortedButtons [(int)this.RunModal () - 1000];
        }
コード例 #5
0
		internal static NSView LabelControl (string label, float controlWidth, NSControl control)
		{
			var view = new NSView (new RectangleF (0, 0, controlWidth, 28)) {
				AutoresizesSubviews = true,
				AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.MaxXMargin,
			};
			
			var text = new NSTextField (new RectangleF (0, 6, 100, 20)) {
				StringValue = label,
				DrawsBackground = false,
				Bordered = false,
				Editable = false,
				Selectable = false
			};
			text.SizeToFit ();
			float textWidth = text.Frame.Width;
			float textHeight = text.Frame.Height;
			
			control.SizeToFit ();
			var rect = control.Frame;
			float controlHeight = rect.Height;
			control.Frame = new RectangleF (textWidth + 5, 0, controlWidth, rect.Height);
			
			rect = view.Frame;
			rect.Width = control.Frame.Width + textWidth + 5;
			rect.Height = Math.Max (controlHeight, textHeight);
			view.Frame = rect;
			
			view.AddSubview (text);
			view.AddSubview (control);
			
			return view;
		}
コード例 #6
0
		public bool Run (ExceptionDialogData data)
		{
			using (var alert = new NSAlert { AlertStyle = NSAlertStyle.Critical }) {
				alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
				
				alert.MessageText = data.Title ?? GettextCatalog.GetString ("Error");
				
				if (!string.IsNullOrEmpty (data.Message)) {
					alert.InformativeText = data.Message;
				}

				List<AlertButton> buttons = null;
				if (data.Buttons != null && data.Buttons.Length > 0)
					buttons = data.Buttons.Reverse ().ToList ();

				if (buttons != null) {
					foreach (var button in buttons) {
						var label = button.Label;
						if (button.IsStockButton)
							label = Gtk.Stock.Lookup (label).Label;
						label = label.Replace ("_", "");

						//this message seems to be a standard Mac message since alert handles it specially
						if (button == AlertButton.CloseWithoutSave)
							label = GettextCatalog.GetString ("Don't Save");

						alert.AddButton (label);
					}
				}

				if (data.Exception != null) {
					var scrollSize = new SizeF (400, 130);
					float spacing = 4;
					
					string title = GettextCatalog.GetString ("View details");
					string altTitle = GettextCatalog.GetString ("Hide details");
					
					var buttonFrame = new RectangleF (0, 0, 0, 0);
					var button = new NSButton (buttonFrame) {
						BezelStyle = NSBezelStyle.Disclosure,
						Title = "",
						AlternateTitle = "",
					};
					button.SetButtonType (NSButtonType.OnOff);
					button.SizeToFit ();
					
					var label = new MDClickableLabel (title) {
						Alignment = NSTextAlignment.Left,
					};
					label.SizeToFit ();
					
					button.SetFrameSize (new SizeF (button.Frame.Width, Math.Max (button.Frame.Height, label.Frame.Height)));
					label.SetFrameOrigin (new PointF (button.Frame.Width + 5, button.Frame.Y));
					
					var text = new MyTextView (new RectangleF (0, 0, float.MaxValue, float.MaxValue)) {
						HorizontallyResizable = true,
					};
					text.TextContainer.ContainerSize = new SizeF (float.MaxValue, float.MaxValue);
					text.TextContainer.WidthTracksTextView = true;
					text.InsertText (new NSString (data.Exception.ToString ()));
					text.Editable = false;

					var scrollView = new NSScrollView (new RectangleF (PointF.Empty, SizeF.Empty)) {
						HasHorizontalScroller = true,
						HasVerticalScroller = true,
					};
					
					var accessory = new NSView (new RectangleF (0, 0, scrollSize.Width, button.Frame.Height));
					accessory.AddSubview (scrollView);
					accessory.AddSubview (button);
					accessory.AddSubview (label);
					
					alert.AccessoryView = accessory;
					
					button.Activated += delegate {
						float change;
						if (button.State == NSCellStateValue.On) {
							change = scrollSize.Height + spacing;
							label.StringValue = altTitle;
							scrollView.Hidden = false;
							scrollView.Frame = new RectangleF (PointF.Empty, scrollSize);
							scrollView.DocumentView = text;
						} else {
							change = -(scrollSize.Height + spacing);
							label.StringValue = title;
							scrollView.Hidden = true;
							scrollView.Frame = new RectangleF (PointF.Empty, SizeF.Empty);
						}
						var f = accessory.Frame;
						f.Height += change;
						accessory.Frame = f;
						var lf = label.Frame;
						lf.Y += change;
						label.Frame = lf;
						var bf = button.Frame;
						bf.Y += change;
						button.Frame = bf;
						label.SizeToFit ();
						var panel = (NSPanel) alert.Window;
						var pf = panel.Frame;
						pf.Height += change;
						pf.Y -= change;
						panel.SetFrame (pf, true, true);
						//unless we assign the icon again, it starts nesting old icon into the warning icon
						alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
						alert.Layout ();
					};
					label.OnMouseUp += (sender, e) => button.PerformClick (e.Event);
				}

				int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
				data.ResultButton = buttons != null ? buttons [result] : null;
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
コード例 #7
0
		public SelectEncodingPanel () : base ()	
		{
			var size = new SizeF (600, 400);
			float padding = 12;
			this.SetContentSize (size);
			
			var view = new NSView (new RectangleF (0, 0, size.Width, size.Height));
			var okButton = new NSButton () {
				Title = GettextCatalog.GetString ("OK"),
				Bordered = true,
				BezelStyle = NSBezelStyle.Rounded,
			};
			okButton.SetButtonType (NSButtonType.MomentaryPushIn);
			okButton.Activated += delegate {
				Dismiss (1);
			};
			this.DefaultButtonCell = okButton.Cell;
			
			var cancelButton = new NSButton () {
				Title = GettextCatalog.GetString ("Cancel"),
				Bordered = true,
				BezelStyle = NSBezelStyle.Rounded,
			};
			cancelButton.Activated += delegate {
				Dismiss (0);
			};
			var buttonBox = new MDBox (LayoutDirection.Horizontal, padding, 0) {
				new MDAlignment (cancelButton, true) { MinWidth = 96, MinHeight = 32 },
				new MDAlignment (okButton, true) { MinWidth = 96, MinHeight = 32 },
			};
			buttonBox.Layout ();
			var buttonView = buttonBox.View;
			var buttonRect = buttonView.Frame;
			buttonRect.Y = 12;
			buttonRect.X = size.Width - buttonRect.Width - padding;
			buttonView.Frame = buttonRect;
			view.AddSubview (buttonView);
			
			float buttonAreaTop = buttonRect.Height + padding * 2;
			
			var label = CreateLabel (GettextCatalog.GetString ("Available encodings:"));
			var labelSize = label.Frame.Size;
			float labelBottom = size.Height - 12 - labelSize.Height;
			label.Frame = new RectangleF (12, labelBottom, labelSize.Width, labelSize.Height);
			view.AddSubview (label);
			
			var moveButtonWidth = 32;
			var tableHeight = labelBottom - buttonAreaTop - padding;
			var tableWidth = size.Width / 2 - padding * 3 - moveButtonWidth + padding / 2;
			
			allTable = new NSTableView (new RectangleF (padding, buttonAreaTop, tableWidth, tableHeight));
			allTable.HeaderView = null;
			var allScroll = new NSScrollView (allTable.Frame) {
				BorderType = NSBorderType.BezelBorder,
				AutohidesScrollers = true,
				HasVerticalScroller = true,
				DocumentView = allTable,
			};
			view.AddSubview (allScroll);
			
			float center = (size.Width + padding) / 2;
			
			var selectedLabel = CreateLabel (GettextCatalog.GetString ("Encodings shown in menu:"));
			var selectedLabelSize = selectedLabel.Frame.Size;
			selectedLabel.Frame = new RectangleF (center, labelBottom, selectedLabelSize.Width, selectedLabelSize.Height);
			view.AddSubview (selectedLabel);
			
			selectedTable = new NSTableView (new RectangleF (center, buttonAreaTop, tableWidth, tableHeight));
			selectedTable.HeaderView = null;
			var selectedScroll = new NSScrollView (selectedTable.Frame) {
				BorderType = NSBorderType.BezelBorder,
				AutohidesScrollers = true,
				HasVerticalScroller = true,
				DocumentView = selectedTable,
			};
			view.AddSubview (selectedScroll);
			
			float buttonLevel = tableHeight / 2 + buttonAreaTop;
			
			var goRightImage = NSImage.ImageNamed ("NSGoRightTemplate");
			
			addButton = new NSButton (
				new RectangleF (tableWidth + padding * 2, buttonLevel + padding / 2,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2192",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = goRightImage
			};
			addButton.Activated += Add;
			view.AddSubview (addButton);
			
			removeButton = new NSButton (
				new RectangleF (tableWidth + padding * 2, buttonLevel - padding / 2 - moveButtonWidth,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2190",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = NSImage.ImageNamed ("NSGoLeftTemplate"),
			};
			removeButton.Activated += Remove;
			view.AddSubview (removeButton);
			
			upButton = new NSButton (
				new RectangleF (center + tableWidth + padding, buttonLevel + padding / 2,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2191",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = MakeRotatedCopy (goRightImage, 90),
			};
			upButton.Activated += MoveUp;
			view.AddSubview (upButton);
			
			downButton = new NSButton (
				new RectangleF (center + tableWidth + padding, buttonLevel - padding / 2 - moveButtonWidth,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2193",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = MakeRotatedCopy (goRightImage, -90),
			};
			downButton.Activated += MoveDown;
			view.AddSubview (downButton);
			
			var allColumn = new NSTableColumn () {
				DataCell = new NSTextFieldCell () { Wraps = true },
				Width = tableWidth
			};
			allTable.AddColumn (allColumn);
			allTable.DataSource = allSource = new EncodingSource (TextEncoding.SupportedEncodings);
			allTable.Delegate = new EncodingAllDelegate (this);
			
			var selectedColumn = new NSTableColumn () {
				DataCell = new NSTextFieldCell () { Wraps = true },
				Width = tableWidth
			};
			selectedTable.AddColumn (selectedColumn);
			selectedTable.DataSource = selectedSource = new EncodingSource (TextEncoding.ConversionEncodings);
			selectedTable.Delegate = new EncodingSelectedDelegate (this);
			
			UpdateButtons ();
			
			this.ContentView = view;
		}
コード例 #8
0
		public override void ViewDidLoad ()
		{
			View = new NSView(new RectangleF(0,100,320, 400));
			base.ViewDidLoad ();

			var textEditFirst = new NSTextField(new System.Drawing.RectangleF(10,0,320,40));
			View.AddSubview (textEditFirst);
			var textEditSecond = new NSTextField(new System.Drawing.RectangleF(10,50,320,40));
			View.AddSubview(textEditSecond);
			var labelFull = new NSTextField(new System.Drawing.RectangleF(10,100,320,40));
			View.AddSubview (labelFull);
			var bu = new NSButton (new RectangleF (0, 150, 320, 40));
			bu.Title = "Hello";
			View.AddSubview (bu);

			var set = this.CreateBindingSet<FirstViewController, FirstViewModel> ();
			set.Bind (textEditFirst).For(v => v.StringValue).To (vm => vm.FirstName);
			set.Bind (textEditSecond).For(v => v.StringValue).To (vm => vm.LastName);
			set.Bind (labelFull).For(v => v.StringValue).To (vm => vm.FullName);	
			set.Bind (bu).For("Activated").To ("GoCommand");
			set.Apply ();
		}
コード例 #9
0
ファイル: MacEngine.cs プロジェクト: pixelmeister/xwt
 public static void ReplaceChild(NSView cont, NSView oldView, NSView newView)
 {
     if (cont is IViewContainer) {
         ((IViewContainer)cont).ReplaceChild (oldView, newView);
     }
     else if (cont is NSView) {
         newView.Frame = oldView.Frame;
         oldView.RemoveFromSuperview ();
         newView.AddSubview (newView);
     }
 }