Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Web.Mobile / UI / MobileControls / Design / Util / GenericUI.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="GenericUI.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 namespace System.Web.UI.Design.MobileControls.Util
8 {
9     using System;
10     using System.Collections;
11     using System.ComponentModel;
12     using System.Drawing;
13     using System.Diagnostics;
14     using System.Windows.Forms;
15     using System.Windows.Forms.Design;
16     using System.Text;
17
18     [
19         System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
20         Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
21     ]
22     [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
23     internal class GenericUI
24     {
25         // Internal type should not be instantiated.
26         private GenericUI() {
27         }
28
29         internal static readonly Bitmap SortDownIcon =
30             new Icon(typeof(MobileControlDesigner), "SortDown.ico").ToBitmap();
31
32         internal static readonly Bitmap SortUpIcon =
33             new Icon(typeof(MobileControlDesigner), "SortUp.ico").ToBitmap();
34         
35         internal static readonly Bitmap DeleteIcon =
36             new Icon(typeof(MobileControlDesigner), "Delete.ico").ToBitmap();
37         
38         internal static readonly Bitmap ErrorIcon = 
39             new Icon(typeof(MobileContainerDesigner), "Error.ico").ToBitmap();
40
41         internal static readonly Bitmap InfoIcon = 
42             new Icon(typeof(MobileContainerDesigner), "Info.ico").ToBitmap();
43
44         internal static void InitDialog(
45             Form dialog,
46             ISite site
47         ) {
48             dialog.FormBorderStyle = FormBorderStyle.FixedDialog;
49             dialog.Icon = null;
50             dialog.MaximizeBox = false;
51             dialog.MinimizeBox = false;
52             dialog.ShowInTaskbar = false;
53             dialog.StartPosition = FormStartPosition.CenterParent;
54             dialog.AutoScaleBaseSize = new Size(5, 14);
55             dialog.Font = GetVS7Font(site);
56         }
57
58         internal static Font GetVS7Font(ISite site)
59         {
60             System.Drawing.Font vsfont = Control.DefaultFont;
61             if (site != null)
62             {
63                 IUIService uiService = (IUIService) site.GetService(
64                     typeof(IUIService)
65                     );
66                 if (uiService != null)
67                 {
68                     vsfont = (Font) uiService.Styles["DialogFont"];
69                 }
70             }
71             return vsfont;
72         }    
73         
74         // This version of InitDialog() handles merged UIs
75         internal static int InitDialog(
76             Form dialog,
77             IDeviceSpecificDesigner designer,
78             int mergingContext
79         ) {
80             InitDialog(dialog, designer.UnderlyingControl.Site);
81             int tabOffset = 0;
82             designer.InitHeader(mergingContext);
83             Control header = designer.Header;
84             if (header != null)
85             {
86                 // (6, 5) = Windows standard positioning
87                 header.Location = new Point(6, 5);
88                 dialog.Controls.Add(header);
89                 // +6 = 6px space between header and first control
90                 dialog.Height += header.Height + 6;
91                 tabOffset = GenericUI.GetMaxContainedTabIndex(header);
92                 // Changing the header width is going to magically
93                 // cause everything to be repositioned vertically
94                 // -10 = 5px padding on each side of the client area
95                 header.Width = dialog.ClientSize.Width - 10;
96             }
97             return tabOffset;
98         }
99
100         internal static int GetMaxContainedTabIndex(Control control)
101         {
102             int maxTabIndex = control.TabIndex;
103             
104             foreach(Control child in control.Controls)
105             {
106                 int maxChildTabIndex = GetMaxContainedTabIndex(child);
107                 if(maxChildTabIndex > maxTabIndex)
108                 {
109                     maxTabIndex = maxChildTabIndex;
110                 }
111             }
112             return maxTabIndex;
113         }
114
115         internal static void ShowErrorMessage(String title, String message)
116         {
117             RTLAwareMessageBox.Show(
118                 null,
119                 message,
120                 title,
121                 MessageBoxButtons.OK,
122                 MessageBoxIcon.Error,
123                 MessageBoxDefaultButton.Button1,
124                 0
125             );
126         }
127
128         internal static String BuildCommaDelimitedList(ICollection stringList)
129         {
130             StringBuilder delimitedString = new StringBuilder();
131
132             foreach (String str in stringList)
133             {
134                 if(delimitedString.Length > 0)
135                 {
136                     delimitedString.Append(", ");
137                 }
138                 delimitedString.Append(str);
139             }
140             return delimitedString.ToString();
141         }
142
143         internal static void ShowWarningMessage(String title, String message)
144         {
145             RTLAwareMessageBox.Show(
146                 null,
147                 message,
148                 title,
149                 MessageBoxButtons.OK,
150                 MessageBoxIcon.Exclamation,
151                 MessageBoxDefaultButton.Button1,
152                 0
153             );
154         }
155         
156         internal static bool ConfirmYesNo(String title, String message)
157         {
158             DialogResult result = RTLAwareMessageBox.Show(
159                 null,
160                 message,
161                 title,
162                 MessageBoxButtons.YesNo,
163                 MessageBoxIcon.Exclamation,
164                 MessageBoxDefaultButton.Button1,
165                 0
166             );
167             return result == DialogResult.Yes;
168         }
169     }
170
171     // Copied from ndp\fx\src\Designer\[....]\System\[....]\Design\RTLAwareMessageBox.cs
172     [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
173     internal sealed class RTLAwareMessageBox {
174
175         // Private helper class shouldn't be instantiated.
176         private RTLAwareMessageBox() {
177         }
178
179         /// <include file='doc\MessageBox.uex' path='docs/doc[@for="MessageBox.Show6"]/*' />
180         /// <devdoc>
181         ///    <para>
182         ///       Displays a message box with specified text, caption, and style.
183         ///       Makes the dialog RTL if the resources for this dll have been localized to a RTL language.
184         ///    </para>
185         /// </devdoc>
186         public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon,
187                                         MessageBoxDefaultButton defaultButton, MessageBoxOptions options) {
188             if (RTLAwareMessageBox.IsRTLResources) {
189                 options |= (MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
190             }
191             return MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options);
192         }
193
194         /// <devdoc>
195         ///     Tells whether the current resources for this dll have been
196         ///     localized for a RTL language.
197         /// </devdoc>
198         public static bool IsRTLResources {
199             get {
200                 // Set RightToLeft mode based on resource file
201                 string rtlText = SR.GetString(SR.RTL);
202
203                 return !String.Equals(rtlText, "RTL_False", StringComparison.Ordinal);
204             }
205         }
206     }
207 }