5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33
public class Dialog: Window
35
DialogButtonCollection commands;
36
Command resultCommand;
41
commands = new DialogButtonCollection ((WindowBackendHost)BackendHost);
44
protected new class WindowBackendHost: Window.WindowBackendHost, ICollectionListener, IDialogEventSink
46
new Dialog Parent { get { return (Dialog) base.Parent; } }
48
public virtual void ItemAdded (object collection, object item)
50
if (collection == Parent.commands) {
51
((DialogButton)item).ParentDialog = Parent;
52
Parent.Backend.SetButtons (Parent.commands);
56
public virtual void ItemRemoved (object collection, object item)
58
if (collection == Parent.commands) {
59
((DialogButton)item).ParentDialog = null;
60
Parent.Backend.SetButtons (Parent.commands);
64
public void OnDialogButtonClicked (DialogButton btn)
67
if (btn.Command != null)
68
Parent.OnCommandActivated (btn.Command);
72
protected override BackendHost CreateBackendHost ()
74
return new WindowBackendHost ();
77
IDialogBackend Backend {
78
get { return (IDialogBackend) BackendHost.Backend; }
81
public DialogButtonCollection Buttons {
82
get { return commands; }
85
protected virtual void OnCommandActivated (Command cmd)
95
public Command Run (WindowFrame parent)
97
Toolkit.InvokePlatformCode (delegate {
98
Backend.RunLoop ((IWindowFrameBackend) WidgetRegistry.GetBackend (parent));
100
return resultCommand;
103
public void Respond (Command cmd)
112
public void EnableCommand (Command cmd)
114
var btn = Buttons.GetCommandButton (cmd);
116
btn.Sensitive = true;
119
public void DisableCommand (Command cmd)
121
var btn = Buttons.GetCommandButton (cmd);
123
btn.Sensitive = false;
126
public void ShowCommand (Command cmd)
128
var btn = Buttons.GetCommandButton (cmd);
133
public void HideCommand (Command cmd)
135
var btn = Buttons.GetCommandButton (cmd);
140
internal void UpdateButton (DialogButton btn)
142
Backend.UpdateButton (btn);
146
public class DialogButton
152
bool sensitive = true;
153
internal Dialog ParentDialog;
155
public DialogButton (string label)
160
public DialogButton (string label, Command cmd)
166
public DialogButton (string label, Image icon)
172
public DialogButton (string label, Image icon, Command cmd)
179
public DialogButton (Command cmd)
184
public Command Command {
185
get { return command; }
188
public string Label {
193
return command.Label;
198
ParentDialog.UpdateButton (this);
210
ParentDialog.UpdateButton (this);
214
public bool Visible {
215
get { return visible; }
218
ParentDialog.UpdateButton (this);
222
public bool Sensitive {
223
get { return sensitive; }
226
ParentDialog.UpdateButton (this);
230
internal void RaiseClicked ()
233
Clicked (this, EventArgs.Empty);
236
public event EventHandler Clicked;