Form.cs 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004-2006 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. // NOT COMPLETE
  26. using System;
  27. using System.Drawing;
  28. using System.ComponentModel;
  29. using System.ComponentModel.Design;
  30. using System.ComponentModel.Design.Serialization;
  31. using System.Collections;
  32. using System.Runtime.InteropServices;
  33. using System.Threading;
  34. namespace System.Windows.Forms {
  35. [DesignerCategory("Form")]
  36. [DesignTimeVisible(false)]
  37. [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
  38. [DefaultEvent("Load")]
  39. #if NET_2_0
  40. [ClassInterface (ClassInterfaceType.AutoDispatch)]
  41. [InitializationEvent ("Load")]
  42. [ComVisible (true)]
  43. #endif
  44. [ToolboxItem(false)]
  45. public class Form : ContainerControl {
  46. #region Local Variables
  47. internal bool closing;
  48. FormBorderStyle form_border_style;
  49. private bool autoscale;
  50. private Size clientsize_set;
  51. private Size autoscale_base_size;
  52. private bool allow_transparency;
  53. private static Icon default_icon;
  54. internal bool is_modal;
  55. internal FormWindowState window_state;
  56. private bool control_box;
  57. private bool minimize_box;
  58. private bool maximize_box;
  59. private bool help_button;
  60. private bool show_in_taskbar;
  61. private bool topmost;
  62. private IButtonControl accept_button;
  63. private IButtonControl cancel_button;
  64. private DialogResult dialog_result;
  65. private FormStartPosition start_position;
  66. private Form owner;
  67. private Form.ControlCollection owned_forms;
  68. private MdiClient mdi_container;
  69. internal InternalWindowManager window_manager;
  70. private Form mdi_parent;
  71. private bool key_preview;
  72. private MainMenu menu;
  73. private Icon icon;
  74. private Size maximum_size;
  75. private Size minimum_size;
  76. private SizeGripStyle size_grip_style;
  77. private SizeGrip size_grip;
  78. private Rectangle maximized_bounds;
  79. private Rectangle default_maximized_bounds;
  80. private double opacity;
  81. internal ApplicationContext context;
  82. Color transparency_key;
  83. internal MenuTracker active_tracker;
  84. private bool is_loaded;
  85. internal bool is_changing_visible_state;
  86. internal bool has_been_visible;
  87. #if NET_2_0
  88. private MenuStrip main_menu_strip;
  89. private bool show_icon = true;
  90. private bool shown_raised; // The shown event is only raised once
  91. #endif
  92. #endregion // Local Variables
  93. #region Private & Internal Methods
  94. static Form ()
  95. {
  96. default_icon = Locale.GetResource("mono.ico") as Icon;
  97. }
  98. // warning: this is only hooked up when an mdi container is created.
  99. private void ControlAddedHandler (object sender, ControlEventArgs e)
  100. {
  101. if (mdi_container != null) {
  102. mdi_container.SendToBack ();
  103. }
  104. }
  105. // Convenience method for fire BOTH OnClosing and OnFormClosing events
  106. // Returns the value of Cancel, so true means the Close was cancelled,
  107. // and you shouldn't close the form.
  108. internal bool FireClosingEvents (CloseReason reason)
  109. {
  110. CancelEventArgs cea = new CancelEventArgs ();
  111. this.OnClosing (cea);
  112. #if NET_2_0
  113. FormClosingEventArgs fcea = new FormClosingEventArgs (reason, cea.Cancel);
  114. this.OnFormClosing (fcea);
  115. return fcea.Cancel;
  116. #else
  117. return cea.Cancel;
  118. #endif
  119. }
  120. private void SelectActiveControl ()
  121. {
  122. if (this.IsMdiContainer) {
  123. mdi_container.SendFocusToActiveChild ();
  124. return;
  125. }
  126. if (this.ActiveControl == null) {
  127. bool visible;
  128. // This visible hack is to work around CanSelect always being false if one of the parents
  129. // is not visible; and we by default create Form invisible...
  130. visible = this.is_visible;
  131. this.is_visible = true;
  132. if (SelectNextControl (this, true, true, true, true) == false) {
  133. Select (this);
  134. }
  135. this.is_visible = visible;
  136. } else {
  137. Select (ActiveControl);
  138. }
  139. }
  140. private new void UpdateSizeGripVisible ()
  141. {
  142. // Following link explains when to show size grip:
  143. // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=138687&SiteID=1
  144. // if SizeGripStyle.Auto, only shown if form is shown using ShowDialog and is sizable
  145. // if SizeGripStyle.Show, only shown if form is sizable
  146. bool show = false;
  147. switch (size_grip_style) {
  148. case SizeGripStyle.Auto:
  149. show = is_modal && (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
  150. break;
  151. case SizeGripStyle.Hide:
  152. show = false;
  153. break;
  154. case SizeGripStyle.Show:
  155. show = (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
  156. break;
  157. }
  158. if (!show) {
  159. if (size_grip != null && size_grip.Visible)
  160. size_grip.Visible = false;
  161. } else {
  162. if (size_grip == null) {
  163. size_grip = new SizeGrip (this);
  164. size_grip.Virtual = true;
  165. size_grip.FillBackground = false;
  166. }
  167. size_grip.Visible = true;
  168. }
  169. }
  170. internal void ChangingParent (Control new_parent)
  171. {
  172. if (IsMdiChild) {
  173. return;
  174. }
  175. if (new_parent == null) {
  176. window_manager = null;
  177. } else if (new_parent is MdiClient) {
  178. window_manager = new MdiWindowManager (this, (MdiClient) new_parent);
  179. } else {
  180. window_manager = new FormWindowManager (this);
  181. if (IsHandleCreated) {
  182. XplatUI.SetWindowStyle (Handle, CreateParams);
  183. }
  184. }
  185. if (window_manager != null) {
  186. window_manager.UpdateWindowState (window_state, window_state, true);
  187. }
  188. }
  189. #endregion // Private & Internal Methods
  190. #region Public Classes
  191. #if NET_2_0
  192. [ComVisible (false)]
  193. #endif
  194. public new class ControlCollection : Control.ControlCollection {
  195. Form form_owner;
  196. public ControlCollection(Form owner) : base(owner) {
  197. this.form_owner = owner;
  198. }
  199. public override void Add(Control value) {
  200. if (Contains (value))
  201. return;
  202. AddToList (value);
  203. ((Form)value).owner=form_owner;
  204. }
  205. public override void Remove(Control value) {
  206. ((Form)value).owner = null;
  207. base.Remove (value);
  208. }
  209. }
  210. #endregion // Public Classes
  211. #region Public Constructor & Destructor
  212. public Form ()
  213. {
  214. SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
  215. autoscale = true;
  216. autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
  217. allow_transparency = false;
  218. closing = false;
  219. is_modal = false;
  220. dialog_result = DialogResult.None;
  221. start_position = FormStartPosition.WindowsDefaultLocation;
  222. form_border_style = FormBorderStyle.Sizable;
  223. window_state = FormWindowState.Normal;
  224. key_preview = false;
  225. opacity = 1D;
  226. menu = null;
  227. icon = default_icon;
  228. minimum_size = Size.Empty;
  229. maximum_size = Size.Empty;
  230. clientsize_set = Size.Empty;
  231. control_box = true;
  232. minimize_box = true;
  233. maximize_box = true;
  234. help_button = false;
  235. show_in_taskbar = true;
  236. is_visible = false;
  237. is_toplevel = true;
  238. size_grip_style = SizeGripStyle.Auto;
  239. maximized_bounds = Rectangle.Empty;
  240. default_maximized_bounds = Rectangle.Empty;
  241. owned_forms = new Form.ControlCollection(this);
  242. transparency_key = Color.Empty;
  243. InternalClientSize = new Size (this.Width - (SystemInformation.FrameBorderSize.Width * 2), this.Height - (SystemInformation.FrameBorderSize.Height * 2) - SystemInformation.CaptionHeight);
  244. }
  245. #endregion // Public Constructor & Destructor
  246. #region Public Static Properties
  247. public static Form ActiveForm {
  248. get {
  249. Control active;
  250. active = FromHandle(XplatUI.GetActive());
  251. if (active != null) {
  252. if ( !(active is Form)) {
  253. Control parent;
  254. parent = active.Parent;
  255. while (parent != null) {
  256. if (parent is Form) {
  257. return (Form)parent;
  258. }
  259. parent = parent.Parent;
  260. }
  261. } else {
  262. return (Form)active;
  263. }
  264. }
  265. return null;
  266. }
  267. }
  268. #endregion // Public Static Properties
  269. #region Public Instance Properties
  270. [DefaultValue(null)]
  271. public IButtonControl AcceptButton {
  272. get {
  273. return accept_button;
  274. }
  275. set {
  276. accept_button = value;
  277. CheckAcceptButton();
  278. }
  279. }
  280. [Browsable(false)]
  281. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  282. public bool AllowTransparency {
  283. get {
  284. return allow_transparency;
  285. }
  286. set {
  287. if (value == allow_transparency) {
  288. return;
  289. }
  290. allow_transparency = value;
  291. if (value) {
  292. if (IsHandleCreated) {
  293. if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
  294. XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
  295. }
  296. } else {
  297. UpdateStyles(); // Remove the WS_EX_LAYERED style
  298. }
  299. }
  300. }
  301. }
  302. #if NET_2_0
  303. [Browsable (false)]
  304. [EditorBrowsable (EditorBrowsableState.Never)]
  305. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  306. [Obsolete ("This property has been deprecated in favor of AutoScaleMode.")]
  307. #else
  308. [DefaultValue(true)]
  309. #endif
  310. [MWFCategory("Layout")]
  311. public bool AutoScale {
  312. get {
  313. return autoscale;
  314. }
  315. set {
  316. autoscale = value;
  317. }
  318. }
  319. #if NET_2_0
  320. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  321. [EditorBrowsable(EditorBrowsableState.Never)]
  322. #else
  323. [EditorBrowsable(EditorBrowsableState.Advanced)]
  324. #endif
  325. [Localizable(true)]
  326. [Browsable(false)]
  327. public virtual Size AutoScaleBaseSize {
  328. get {
  329. return autoscale_base_size;
  330. }
  331. set {
  332. autoscale_base_size = value;
  333. }
  334. }
  335. [Localizable(true)]
  336. public override bool AutoScroll {
  337. get {
  338. return base.AutoScroll;
  339. }
  340. set {
  341. base.AutoScroll = value;
  342. }
  343. }
  344. public override Color BackColor {
  345. get {
  346. /* we don't let parents override our
  347. default background color for forms.
  348. this fixes the default color for mdi
  349. children. */
  350. if (background_color.IsEmpty)
  351. return DefaultBackColor;
  352. else
  353. return background_color;
  354. }
  355. set {
  356. base.BackColor = value;
  357. }
  358. }
  359. [DefaultValue(null)]
  360. public IButtonControl CancelButton {
  361. get {
  362. return cancel_button;
  363. }
  364. set {
  365. cancel_button = value;
  366. if (cancel_button != null && cancel_button.DialogResult == DialogResult.None)
  367. cancel_button.DialogResult = DialogResult.Cancel;
  368. }
  369. }
  370. // new property so we can change the DesignerSerializationVisibility
  371. [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
  372. [Localizable(true)]
  373. public new Size ClientSize {
  374. get { return base.ClientSize; }
  375. set { base.ClientSize = value; }
  376. }
  377. [DefaultValue(true)]
  378. [MWFCategory("Window Style")]
  379. public bool ControlBox {
  380. get {
  381. return control_box;
  382. }
  383. set {
  384. if (control_box != value) {
  385. control_box = value;
  386. UpdateStyles();
  387. }
  388. }
  389. }
  390. [Browsable(false)]
  391. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  392. public Rectangle DesktopBounds {
  393. get {
  394. return new Rectangle(Location, Size);
  395. }
  396. set {
  397. Bounds = value;
  398. }
  399. }
  400. [Browsable(false)]
  401. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  402. public Point DesktopLocation {
  403. get {
  404. return Location;
  405. }
  406. set {
  407. Location = value;
  408. }
  409. }
  410. [Browsable(false)]
  411. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  412. public DialogResult DialogResult {
  413. get {
  414. return dialog_result;
  415. }
  416. set {
  417. if (value < DialogResult.None || value > DialogResult.No)
  418. throw new InvalidEnumArgumentException ("value", (int) value,
  419. typeof (DialogResult));
  420. dialog_result = value;
  421. closing = (dialog_result != DialogResult.None && is_modal);
  422. }
  423. }
  424. [DefaultValue(FormBorderStyle.Sizable)]
  425. [DispId(-504)]
  426. [MWFCategory("Appearance")]
  427. public FormBorderStyle FormBorderStyle {
  428. get {
  429. return form_border_style;
  430. }
  431. set {
  432. form_border_style = value;
  433. if (window_manager == null) {
  434. if (IsHandleCreated) {
  435. XplatUI.SetBorderStyle(window.Handle, form_border_style);
  436. }
  437. } else {
  438. window_manager.UpdateBorderStyle (value);
  439. }
  440. Size current_client_size = ClientSize;
  441. if (this.IsHandleCreated) {
  442. UpdateStyles();
  443. this.Size = SizeFromClientSize (current_client_size);
  444. }
  445. }
  446. }
  447. [DefaultValue(false)]
  448. [MWFCategory("Window Style")]
  449. public bool HelpButton {
  450. get {
  451. return help_button;
  452. }
  453. set {
  454. if (help_button != value) {
  455. help_button = value;
  456. UpdateStyles();
  457. }
  458. }
  459. }
  460. [Localizable(true)]
  461. [AmbientValue(null)]
  462. [MWFCategory("Window Style")]
  463. public Icon Icon {
  464. get {
  465. return icon;
  466. }
  467. set {
  468. if (icon != value) {
  469. icon = value;
  470. if (IsHandleCreated) {
  471. XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
  472. }
  473. }
  474. }
  475. }
  476. [Browsable(false)]
  477. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  478. public bool IsMdiChild {
  479. get {
  480. return mdi_parent != null;
  481. }
  482. }
  483. [DefaultValue(false)]
  484. [MWFCategory("Window Style")]
  485. public bool IsMdiContainer {
  486. get {
  487. return mdi_container != null;
  488. }
  489. set {
  490. if (value && mdi_container == null) {
  491. mdi_container = new MdiClient ();
  492. Controls.Add(mdi_container);
  493. ControlAdded += new ControlEventHandler (ControlAddedHandler);
  494. mdi_container.SendToBack ();
  495. mdi_container.SetParentText (true);
  496. } else if (!value && mdi_container != null) {
  497. Controls.Remove(mdi_container);
  498. mdi_container = null;
  499. }
  500. }
  501. }
  502. [Browsable(false)]
  503. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  504. public Form ActiveMdiChild {
  505. get {
  506. if (!IsMdiContainer)
  507. return null;
  508. return (Form) mdi_container.ActiveMdiChild;
  509. }
  510. }
  511. [Browsable(false)]
  512. [EditorBrowsable(EditorBrowsableState.Advanced)]
  513. public bool IsRestrictedWindow {
  514. get {
  515. return false;
  516. }
  517. }
  518. [DefaultValue(false)]
  519. public bool KeyPreview {
  520. get {
  521. return key_preview;
  522. }
  523. set {
  524. key_preview = value;
  525. }
  526. }
  527. #if NET_2_0
  528. [DefaultValue (null)]
  529. [TypeConverter (typeof (ReferenceConverter))]
  530. public MenuStrip MainMenuStrip {
  531. get { return this.main_menu_strip; }
  532. set {
  533. if (this.main_menu_strip != value) {
  534. this.main_menu_strip = value;
  535. this.main_menu_strip.RefreshMdiItems ();
  536. }
  537. }
  538. }
  539. [EditorBrowsable (EditorBrowsableState.Never)]
  540. [Browsable (false)]
  541. public new Padding Margin {
  542. get { return base.Margin; }
  543. set { base.Margin = value; }
  544. }
  545. #endif
  546. [DefaultValue(true)]
  547. [MWFCategory("Window Style")]
  548. public bool MaximizeBox {
  549. get {
  550. return maximize_box;
  551. }
  552. set {
  553. if (maximize_box != value) {
  554. maximize_box = value;
  555. UpdateStyles();
  556. }
  557. }
  558. }
  559. [DefaultValue("{Width=0, Height=0}")]
  560. [Localizable(true)]
  561. [RefreshProperties(RefreshProperties.Repaint)]
  562. [MWFCategory("Layout")]
  563. public
  564. #if NET_2_0
  565. override
  566. #endif
  567. Size MaximumSize {
  568. get {
  569. return maximum_size;
  570. }
  571. set {
  572. if (maximum_size != value) {
  573. maximum_size = value;
  574. OnMaximumSizeChanged(EventArgs.Empty);
  575. if (IsHandleCreated) {
  576. XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
  577. }
  578. }
  579. }
  580. }
  581. [Browsable(false)]
  582. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  583. public Form[] MdiChildren {
  584. get {
  585. if (mdi_container != null)
  586. return mdi_container.MdiChildren;
  587. else
  588. return new Form[0];
  589. }
  590. }
  591. [Browsable(false)]
  592. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  593. public Form MdiParent {
  594. get {
  595. return mdi_parent;
  596. }
  597. set {
  598. if (value != null && !value.IsMdiContainer)
  599. throw new ArgumentException ("Form that was specified to be "
  600. + "the MdiParent for this form is not an MdiContainer.");
  601. if (mdi_parent != null) {
  602. mdi_parent.MdiContainer.Controls.Remove (this);
  603. }
  604. if (value != null) {
  605. mdi_parent = value;
  606. if (window_manager == null) {
  607. window_manager = new MdiWindowManager (this, mdi_parent.MdiContainer);
  608. }
  609. mdi_parent.MdiContainer.Controls.Add (this);
  610. mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
  611. if (IsHandleCreated)
  612. RecreateHandle ();
  613. } else if (mdi_parent != null) {
  614. mdi_parent = null;
  615. // Create a new window manager
  616. window_manager = null;
  617. FormBorderStyle = form_border_style;
  618. if (IsHandleCreated)
  619. RecreateHandle ();
  620. }
  621. }
  622. }
  623. internal MenuTracker ActiveTracker {
  624. get { return active_tracker; }
  625. set {
  626. if (value == active_tracker)
  627. return;
  628. Capture = value != null;
  629. active_tracker = value;
  630. }
  631. }
  632. internal MdiClient MdiContainer {
  633. get { return mdi_container; }
  634. }
  635. internal InternalWindowManager WindowManager {
  636. get { return window_manager; }
  637. }
  638. #if NET_2_0
  639. [Browsable (false)]
  640. [TypeConverter (typeof (ReferenceConverter))]
  641. #endif
  642. [DefaultValue(null)]
  643. [MWFCategory("Window Style")]
  644. public MainMenu Menu {
  645. get {
  646. return menu;
  647. }
  648. set {
  649. if (menu != value) {
  650. menu = value;
  651. if (menu != null && !IsMdiChild) {
  652. menu.SetForm (this);
  653. if (IsHandleCreated) {
  654. XplatUI.SetMenu (window.Handle, menu);
  655. }
  656. if (clientsize_set != Size.Empty) {
  657. SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
  658. } else {
  659. UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
  660. ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
  661. }
  662. } else
  663. UpdateBounds ();
  664. }
  665. }
  666. }
  667. [Browsable(false)]
  668. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  669. [EditorBrowsable(EditorBrowsableState.Advanced)]
  670. public MainMenu MergedMenu {
  671. get {
  672. if (!IsMdiChild || window_manager == null)
  673. return null;
  674. return ((MdiWindowManager) window_manager).MergedMenu;
  675. }
  676. }
  677. // This is the menu in display and being used because of merging this can
  678. // be different then the menu that is actually assosciated with the form
  679. internal MainMenu ActiveMenu {
  680. get {
  681. if (IsMdiChild)
  682. return null;
  683. if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
  684. ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
  685. MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
  686. return wm.MaximizedMenu;
  687. }
  688. Form amc = ActiveMdiChild;
  689. if (amc == null || amc.Menu == null)
  690. return menu;
  691. return amc.MergedMenu;
  692. }
  693. }
  694. internal MdiWindowManager ActiveMaximizedMdiChild {
  695. get {
  696. Form child = ActiveMdiChild;
  697. if (child == null)
  698. return null;
  699. if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
  700. return null;
  701. return (MdiWindowManager) child.WindowManager;
  702. }
  703. }
  704. [DefaultValue(true)]
  705. [MWFCategory("Window Style")]
  706. public bool MinimizeBox {
  707. get {
  708. return minimize_box;
  709. }
  710. set {
  711. if (minimize_box != value) {
  712. minimize_box = value;
  713. UpdateStyles();
  714. }
  715. }
  716. }
  717. #if !NET_2_0
  718. [DefaultValue("{Width=0, Height=0}")]
  719. #endif
  720. [Localizable(true)]
  721. [RefreshProperties(RefreshProperties.Repaint)]
  722. [MWFCategory("Layout")]
  723. public
  724. #if NET_2_0
  725. override
  726. #endif
  727. Size MinimumSize {
  728. get {
  729. return minimum_size;
  730. }
  731. set {
  732. if (minimum_size != value) {
  733. minimum_size = value;
  734. if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
  735. Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
  736. }
  737. OnMinimumSizeChanged(EventArgs.Empty);
  738. if (IsHandleCreated) {
  739. XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
  740. }
  741. }
  742. }
  743. }
  744. [Browsable(false)]
  745. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  746. public bool Modal {
  747. get {
  748. return is_modal;
  749. }
  750. }
  751. [DefaultValue(1D)]
  752. [TypeConverter(typeof(OpacityConverter))]
  753. [MWFCategory("Window Style")]
  754. public double Opacity {
  755. get {
  756. if (IsHandleCreated) {
  757. if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
  758. return XplatUI.GetWindowTransparency (Handle);
  759. }
  760. return opacity;
  761. }
  762. set {
  763. opacity = value;
  764. AllowTransparency = true;
  765. if (IsHandleCreated) {
  766. UpdateStyles();
  767. if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
  768. XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
  769. }
  770. }
  771. }
  772. [Browsable(false)]
  773. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  774. public Form[] OwnedForms {
  775. get {
  776. Form[] form_list;
  777. form_list = new Form[owned_forms.Count];
  778. for (int i=0; i<owned_forms.Count; i++) {
  779. form_list[i] = (Form)owned_forms[i];
  780. }
  781. return form_list;
  782. }
  783. }
  784. [Browsable(false)]
  785. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  786. public Form Owner {
  787. get {
  788. return owner;
  789. }
  790. set {
  791. if (owner != value) {
  792. if (owner != null) {
  793. owner.RemoveOwnedForm(this);
  794. }
  795. owner = value;
  796. if (owner != null)
  797. owner.AddOwnedForm(this);
  798. if (IsHandleCreated) {
  799. if (owner != null && owner.IsHandleCreated) {
  800. XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
  801. } else {
  802. XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
  803. }
  804. }
  805. }
  806. }
  807. }
  808. #if NET_2_0
  809. [DefaultValue (true)]
  810. public bool ShowIcon {
  811. get { return this.show_icon; }
  812. set {
  813. if (this.show_icon != value ) {
  814. this.show_icon = value;
  815. UpdateStyles ();
  816. XplatUI.SetIcon (this.Handle, value == true ? this.Icon : null);
  817. XplatUI.InvalidateNC (this.Handle);
  818. }
  819. }
  820. }
  821. #endif
  822. [DefaultValue(true)]
  823. [MWFCategory("Window Style")]
  824. public bool ShowInTaskbar {
  825. get {
  826. return show_in_taskbar;
  827. }
  828. set {
  829. if (show_in_taskbar != value) {
  830. show_in_taskbar = value;
  831. if (IsHandleCreated) {
  832. RecreateHandle();
  833. }
  834. UpdateStyles();
  835. }
  836. }
  837. }
  838. // new property so we can set the DesignerSerializationVisibility
  839. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  840. [Localizable(false)]
  841. public new Size Size {
  842. get { return base.Size; }
  843. set { base.Size = value; }
  844. }
  845. [DefaultValue(SizeGripStyle.Auto)]
  846. [MWFCategory("Window Style")]
  847. public SizeGripStyle SizeGripStyle {
  848. get {
  849. return size_grip_style;
  850. }
  851. set {
  852. size_grip_style = value;
  853. UpdateSizeGripVisible ();
  854. }
  855. }
  856. [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
  857. [Localizable(true)]
  858. [MWFCategory("Layout")]
  859. public FormStartPosition StartPosition {
  860. get {
  861. return start_position;
  862. }
  863. set {
  864. if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
  865. start_position = value;
  866. if (IsHandleCreated) {
  867. switch(start_position) {
  868. case FormStartPosition.CenterParent: {
  869. CenterToParent();
  870. break;
  871. }
  872. case FormStartPosition.CenterScreen: {
  873. CenterToScreen();
  874. break;
  875. }
  876. case FormStartPosition.Manual: {
  877. Left = CreateParams.X;
  878. Top = CreateParams.Y;
  879. break;
  880. }
  881. default: {
  882. break;
  883. }
  884. }
  885. }
  886. }
  887. }
  888. }
  889. // new property so we can set EditorBrowsable to never
  890. [Browsable(false)]
  891. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  892. [EditorBrowsable(EditorBrowsableState.Never)]
  893. public new int TabIndex {
  894. get { return base.TabIndex; }
  895. set { base.TabIndex = value; }
  896. }
  897. #if NET_2_0
  898. [Browsable(false)]
  899. [DefaultValue (true)]
  900. [DispIdAttribute (-516)]
  901. [EditorBrowsable(EditorBrowsableState.Never)]
  902. public new bool TabStop {
  903. get { return base.TabStop; }
  904. set { base.TabStop = value; }
  905. }
  906. #endif
  907. [Browsable(false)]
  908. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  909. [EditorBrowsable(EditorBrowsableState.Advanced)]
  910. public bool TopLevel {
  911. get {
  912. return GetTopLevel();
  913. }
  914. set {
  915. if (!value && IsMdiContainer)
  916. throw new ArgumentException ("MDI Container forms must be top level.");
  917. SetTopLevel(value);
  918. }
  919. }
  920. [DefaultValue(false)]
  921. [MWFCategory("Window Style")]
  922. public bool TopMost {
  923. get {
  924. return topmost;
  925. }
  926. set {
  927. if (topmost != value) {
  928. topmost = value;
  929. if (IsHandleCreated)
  930. XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
  931. }
  932. }
  933. }
  934. [MWFCategory("Window Style")]
  935. public Color TransparencyKey {
  936. get {
  937. return transparency_key;
  938. }
  939. set {
  940. transparency_key = value;
  941. AllowTransparency = true;
  942. UpdateStyles();
  943. if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
  944. XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
  945. }
  946. }
  947. [DefaultValue(FormWindowState.Normal)]
  948. [MWFCategory("Layout")]
  949. public FormWindowState WindowState {
  950. get {
  951. if (IsHandleCreated) {
  952. if (window_manager != null)
  953. return window_manager.GetWindowState ();
  954. FormWindowState new_state = XplatUI.GetWindowState(Handle);
  955. if (new_state != (FormWindowState)(-1))
  956. window_state = new_state;
  957. }
  958. return window_state;
  959. }
  960. set {
  961. FormWindowState old_state = window_state;
  962. window_state = value;
  963. if (IsHandleCreated) {
  964. if (window_manager != null) {
  965. window_manager.SetWindowState (old_state, value);
  966. return;
  967. }
  968. XplatUI.SetWindowState(Handle, value);
  969. }
  970. }
  971. }
  972. #endregion // Public Instance Properties
  973. #region Protected Instance Properties
  974. protected override CreateParams CreateParams {
  975. get {
  976. CreateParams cp = new CreateParams ();
  977. cp.Caption = Text;
  978. cp.ClassName = XplatUI.DefaultClassName;
  979. cp.ClassStyle = 0;
  980. cp.Style = 0;
  981. cp.ExStyle = 0;
  982. cp.Param = 0;
  983. cp.Parent = IntPtr.Zero;
  984. cp.menu = ActiveMenu;
  985. cp.control = this;
  986. if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild && Parent == null) {
  987. cp.X = unchecked ((int)0x80000000);
  988. cp.Y = unchecked ((int)0x80000000);
  989. } else {
  990. cp.X = Left;
  991. cp.Y = Top;
  992. }
  993. cp.Width = Width;
  994. cp.Height = Height;
  995. cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
  996. if (Parent != null) {
  997. cp.Parent = Parent.Handle;
  998. cp.Style |= (int) WindowStyles.WS_CHILD;
  999. }
  1000. if (IsMdiChild) {
  1001. cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
  1002. if (Parent != null) {
  1003. cp.Parent = Parent.Handle;
  1004. }
  1005. cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
  1006. switch (FormBorderStyle) {
  1007. case FormBorderStyle.None:
  1008. break;
  1009. case FormBorderStyle.FixedToolWindow:
  1010. case FormBorderStyle.SizableToolWindow:
  1011. cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
  1012. goto default;
  1013. default:
  1014. cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
  1015. break;
  1016. }
  1017. } else {
  1018. switch (FormBorderStyle) {
  1019. case FormBorderStyle.Fixed3D: {
  1020. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  1021. cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
  1022. break;
  1023. }
  1024. case FormBorderStyle.FixedDialog: {
  1025. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  1026. cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
  1027. break;
  1028. }
  1029. case FormBorderStyle.FixedSingle: {
  1030. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  1031. break;
  1032. }
  1033. case FormBorderStyle.FixedToolWindow: {
  1034. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  1035. cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
  1036. break;
  1037. }
  1038. case FormBorderStyle.Sizable: {
  1039. cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
  1040. break;
  1041. }
  1042. case FormBorderStyle.SizableToolWindow: {
  1043. cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
  1044. cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
  1045. break;
  1046. }
  1047. case FormBorderStyle.None: {
  1048. break;
  1049. }
  1050. }
  1051. }
  1052. switch(window_state) {
  1053. case FormWindowState.Maximized: {
  1054. cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
  1055. break;
  1056. }
  1057. case FormWindowState.Minimized: {
  1058. cp.Style |= (int)WindowStyles.WS_MINIMIZE;
  1059. break;
  1060. }
  1061. }
  1062. if (TopMost) {
  1063. cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
  1064. }
  1065. if (ShowInTaskbar) {
  1066. cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
  1067. }
  1068. if (MaximizeBox) {
  1069. cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
  1070. }
  1071. if (MinimizeBox) {
  1072. cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
  1073. }
  1074. if (ControlBox) {
  1075. cp.Style |= (int)WindowStyles.WS_SYSMENU;
  1076. }
  1077. #if NET_2_0
  1078. if (!this.show_icon) {
  1079. cp.ExStyle |= (int)WindowExStyles.WS_EX_DLGMODALFRAME;
  1080. }
  1081. #endif
  1082. if (HelpButton && !MaximizeBox && !MinimizeBox) {
  1083. cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
  1084. }
  1085. if (VisibleInternal)
  1086. cp.Style |= (int)WindowStyles.WS_VISIBLE;
  1087. if (opacity < 1.0 || TransparencyKey != Color.Empty) {
  1088. cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
  1089. }
  1090. if (!is_enabled && context == null) {
  1091. cp.Style |= (int)(WindowStyles.WS_DISABLED);
  1092. }
  1093. return cp;
  1094. }
  1095. }
  1096. protected override ImeMode DefaultImeMode {
  1097. get {
  1098. return ImeMode.NoControl;
  1099. }
  1100. }
  1101. protected override Size DefaultSize {
  1102. get {
  1103. return new Size (300, 300);
  1104. }
  1105. }
  1106. protected Rectangle MaximizedBounds {
  1107. get {
  1108. if (maximized_bounds != Rectangle.Empty) {
  1109. return maximized_bounds;
  1110. }
  1111. return default_maximized_bounds;
  1112. }
  1113. set {
  1114. maximized_bounds = value;
  1115. OnMaximizedBoundsChanged(EventArgs.Empty);
  1116. if (IsHandleCreated) {
  1117. XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
  1118. }
  1119. }
  1120. }
  1121. #if !NET_2_0
  1122. internal
  1123. #else
  1124. [MonoTODO ("Implemented for Win32, needs X11 implementation")]
  1125. protected
  1126. #endif
  1127. virtual bool ShowWithoutActivation {
  1128. get { return false; }
  1129. }
  1130. #endregion // Protected Instance Properties
  1131. #region Public Static Methods
  1132. #if NET_2_0
  1133. [EditorBrowsable(EditorBrowsableState.Never)]
  1134. [Obsolete ("This method has been deprecated. Use AutoScaleDimensions instead")]
  1135. #else
  1136. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1137. #endif
  1138. public static SizeF GetAutoScaleSize (Font font)
  1139. {
  1140. return XplatUI.GetAutoScaleSize(font);
  1141. }
  1142. #endregion // Public Static Methods
  1143. #region Public Instance Methods
  1144. internal SizeF GetAutoScaleSize (Graphics g, Font font)
  1145. {
  1146. //
  1147. // The following constants come from the dotnet mailing list
  1148. // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
  1149. //
  1150. // The magic number is "Its almost the length
  1151. // of the string with a smattering added in
  1152. // for compat with earlier code".
  1153. //
  1154. string magic_string = "The quick brown fox jumped over the lazy dog.";
  1155. double magic_number = 44.549996948242189;
  1156. float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
  1157. return new SizeF (width, font.Height);
  1158. }
  1159. public void Activate ()
  1160. {
  1161. Form active;
  1162. // The docs say activate only activates if our app is already active
  1163. if (IsHandleCreated) {
  1164. if (IsMdiChild) {
  1165. MdiParent.ActivateMdiChild (this);
  1166. } else if (IsMdiContainer) {
  1167. mdi_container.SendFocusToActiveChild ();
  1168. } else {
  1169. active = ActiveForm;
  1170. if ((active != null) && (this != active)) {
  1171. XplatUI.Activate(window.Handle);
  1172. }
  1173. }
  1174. }
  1175. }
  1176. public void AddOwnedForm(Form ownedForm) {
  1177. if (!owned_forms.Contains(ownedForm)) {
  1178. owned_forms.Add(ownedForm);
  1179. }
  1180. ownedForm.Owner = this;
  1181. }
  1182. public void Close () {
  1183. if (IsDisposed)
  1184. return;
  1185. if (!is_visible)
  1186. return;
  1187. XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
  1188. }
  1189. public void LayoutMdi(MdiLayout value) {
  1190. if (mdi_container != null) {
  1191. mdi_container.LayoutMdi(value);
  1192. }
  1193. }
  1194. public void RemoveOwnedForm(Form ownedForm) {
  1195. owned_forms.Remove(ownedForm);
  1196. }
  1197. public void SetDesktopBounds(int x, int y, int width, int height) {
  1198. DesktopBounds = new Rectangle(x, y, width, height);
  1199. }
  1200. public void SetDesktopLocation(int x, int y) {
  1201. DesktopLocation = new Point(x, y);
  1202. }
  1203. #if NET_2_0
  1204. public void Show (IWin32Window owner)
  1205. {
  1206. if (owner == null)
  1207. this.Owner = null;
  1208. else
  1209. this.Owner = Control.FromHandle (owner.Handle).TopLevelControl as Form;
  1210. if (owner == this)
  1211. throw new InvalidOperationException ("The 'owner' cannot be the form being shown.");
  1212. base.Show ();
  1213. }
  1214. #endif
  1215. public DialogResult ShowDialog() {
  1216. return ShowDialog(this.owner);
  1217. }
  1218. public DialogResult ShowDialog(IWin32Window ownerWin32) {
  1219. Rectangle area;
  1220. bool confined;
  1221. IntPtr capture_window;
  1222. owner = null;
  1223. if (ownerWin32 != null) {
  1224. Control c = Control.FromHandle (ownerWin32.Handle);
  1225. if (c != null)
  1226. owner = c.TopLevelControl as Form;
  1227. }
  1228. if (owner == this) {
  1229. throw new ArgumentException ("Forms cannot own themselves or their owners.", "owner");
  1230. }
  1231. if (is_modal) {
  1232. throw new InvalidOperationException ("The form is already displayed as a modal dialog.");
  1233. }
  1234. if (Visible) {
  1235. throw new InvalidOperationException ("Forms that are already "
  1236. + " visible cannot be displayed as a modal dialog. Set the"
  1237. + " form's visible property to false before calling"
  1238. + " ShowDialog.");
  1239. }
  1240. if (!Enabled) {
  1241. throw new InvalidOperationException ("Forms that are not enabled"
  1242. + " cannot be displayed as a modal dialog. Set the form's"
  1243. + " enabled property to true before calling ShowDialog.");
  1244. }
  1245. if (TopLevelControl != this) {
  1246. throw new InvalidOperationException ("Forms that are not top level"
  1247. + " forms cannot be displayed as a modal dialog. Remove the"
  1248. + " form from any parent form before calling ShowDialog.");
  1249. }
  1250. #if broken
  1251. // Can't do this, will screw us in the modal loop
  1252. form_parent_window.Parent = this.owner;
  1253. #endif
  1254. // Release any captures
  1255. XplatUI.GrabInfo(out capture_window, out confined, out area);
  1256. if (capture_window != IntPtr.Zero) {
  1257. XplatUI.UngrabWindow(capture_window);
  1258. }
  1259. #if not
  1260. // Commented out; we instead let the Visible=true inside the runloop create the control
  1261. // otherwise setting DialogResult inside any of the events that are triggered by the
  1262. // create will not actually cause the form to not be displayed.
  1263. // Leaving this comment here in case there was an actual purpose to creating the control
  1264. // in here.
  1265. if (!IsHandleCreated) {
  1266. CreateControl();
  1267. }
  1268. #endif
  1269. Application.RunLoop(true, new ApplicationContext(this));
  1270. if (owner != null) {
  1271. // Cannot use Activate(), it has a check for the current active window...
  1272. XplatUI.Activate(owner.window.Handle);
  1273. }
  1274. if (DialogResult != DialogResult.None) {
  1275. return DialogResult;
  1276. }
  1277. DialogResult = DialogResult.Cancel;
  1278. return DialogResult.Cancel;
  1279. }
  1280. public override string ToString() {
  1281. return GetType().FullName.ToString() + ", Text: " + Text;
  1282. }
  1283. #endregion // Public Instance Methods
  1284. #region Protected Instance Methods
  1285. protected void ActivateMdiChild(Form form) {
  1286. if (!IsMdiContainer)
  1287. return;
  1288. mdi_container.ActivateChild (form);
  1289. OnMdiChildActivate(EventArgs.Empty);
  1290. }
  1291. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1292. protected override void AdjustFormScrollbars(bool displayScrollbars) {
  1293. base.AdjustFormScrollbars (displayScrollbars);
  1294. }
  1295. #if NET_2_0
  1296. [EditorBrowsable(EditorBrowsableState.Never)]
  1297. [Obsolete ("This method has been deprecated")] // XXX what to use instead?
  1298. #else
  1299. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1300. #endif
  1301. protected void ApplyAutoScaling()
  1302. {
  1303. SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
  1304. Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
  1305. float dx;
  1306. float dy;
  1307. if (current_size == autoscale_base_size)
  1308. return;
  1309. if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
  1310. return;
  1311. }
  1312. //
  1313. // I tried applying the Fudge height factor from:
  1314. // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
  1315. // but it makes things larger without looking better.
  1316. //
  1317. if (current_size_f.Width != AutoScaleBaseSize.Width) {
  1318. dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
  1319. } else {
  1320. dx = 1;
  1321. }
  1322. if (current_size_f.Height != AutoScaleBaseSize.Height) {
  1323. dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
  1324. } else {
  1325. dy = 1;
  1326. }
  1327. Scale (dx, dy);
  1328. AutoScaleBaseSize = current_size;
  1329. }
  1330. protected void CenterToParent() {
  1331. Control ctl;
  1332. int w;
  1333. int h;
  1334. if (Width > 0) {
  1335. w = Width;
  1336. } else {
  1337. w = DefaultSize.Width;
  1338. }
  1339. if (Height > 0) {
  1340. h = Height;
  1341. } else {
  1342. h = DefaultSize.Height;
  1343. }
  1344. ctl = null;
  1345. if (Parent != null) {
  1346. ctl = Parent;
  1347. } else if (owner != null) {
  1348. ctl = owner;
  1349. }
  1350. if (owner != null) {
  1351. this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
  1352. }
  1353. }
  1354. protected void CenterToScreen() {
  1355. Size DisplaySize;
  1356. int w;
  1357. int h;
  1358. if (Width > 0) {
  1359. w = Width;
  1360. } else {
  1361. w = DefaultSize.Width;
  1362. }
  1363. if (Height > 0) {
  1364. h = Height;
  1365. } else {
  1366. h = DefaultSize.Height;
  1367. }
  1368. XplatUI.GetDisplaySize(out DisplaySize);
  1369. this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
  1370. }
  1371. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1372. protected override Control.ControlCollection CreateControlsInstance() {
  1373. return base.CreateControlsInstance ();
  1374. }
  1375. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1376. protected override void CreateHandle() {
  1377. base.CreateHandle ();
  1378. if (!IsHandleCreated) {
  1379. return;
  1380. }
  1381. Application.AddForm (this);
  1382. UpdateBounds();
  1383. if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
  1384. if (allow_transparency) {
  1385. XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
  1386. }
  1387. }
  1388. XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
  1389. if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
  1390. XplatUI.SetIcon(window.Handle, icon);
  1391. }
  1392. if ((owner != null) && (owner.IsHandleCreated)) {
  1393. XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
  1394. }
  1395. for (int i = 0; i < owned_forms.Count; i++) {
  1396. if (owned_forms[i].IsHandleCreated)
  1397. XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
  1398. }
  1399. if (window_manager != null) {
  1400. if (window_state != FormWindowState.Normal) {
  1401. window_manager.SetWindowState (FormWindowState.Normal, window_state);
  1402. }
  1403. XplatUI.RequestNCRecalc (window.Handle);
  1404. }
  1405. }
  1406. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1407. protected override void DefWndProc(ref Message m) {
  1408. base.DefWndProc (ref m);
  1409. }
  1410. protected override void Dispose(bool disposing)
  1411. {
  1412. for (int i = 0; i < owned_forms.Count; i++)
  1413. ((Form)owned_forms[i]).Owner = null;
  1414. owned_forms.Clear ();
  1415. base.Dispose (disposing);
  1416. Application.RemoveForm (this);
  1417. }
  1418. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1419. protected virtual void OnActivated(EventArgs e)
  1420. {
  1421. EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
  1422. if (eh != null)
  1423. eh (this, e);
  1424. }
  1425. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1426. protected virtual void OnClosed(EventArgs e) {
  1427. EventHandler eh = (EventHandler)(Events [ClosedEvent]);
  1428. if (eh != null)
  1429. eh (this, e);
  1430. }
  1431. // Consider calling FireClosingEvents instead of calling this directly.
  1432. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1433. protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
  1434. CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
  1435. if (eh != null)
  1436. eh (this, e);
  1437. }
  1438. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1439. protected override void OnCreateControl() {
  1440. base.OnCreateControl ();
  1441. if (menu != null) {
  1442. XplatUI.SetMenu(window.Handle, menu);
  1443. }
  1444. OnLoad(EventArgs.Empty);
  1445. // Send initial location
  1446. OnLocationChanged(EventArgs.Empty);
  1447. if (IsMdiContainer) {
  1448. mdi_container.LayoutMdi (MdiLayout.Cascade);
  1449. }
  1450. }
  1451. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1452. protected virtual void OnDeactivate(EventArgs e) {
  1453. EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
  1454. if (eh != null)
  1455. eh (this, e);
  1456. }
  1457. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1458. protected override void OnFontChanged(EventArgs e) {
  1459. base.OnFontChanged (e);
  1460. }
  1461. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1462. protected override void OnHandleCreated(EventArgs e) {
  1463. XplatUI.SetBorderStyle(window.Handle, form_border_style);
  1464. base.OnHandleCreated (e);
  1465. }
  1466. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1467. protected override void OnHandleDestroyed(EventArgs e) {
  1468. base.OnHandleDestroyed (e);
  1469. }
  1470. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1471. protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
  1472. InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
  1473. if (eh != null)
  1474. eh (this, e);
  1475. }
  1476. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1477. protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
  1478. InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
  1479. if (eh != null)
  1480. eh (this, e);
  1481. }
  1482. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1483. protected virtual void OnLoad(EventArgs e) {
  1484. if (AutoScale){
  1485. ApplyAutoScaling ();
  1486. AutoScale = false;
  1487. }
  1488. EventHandler eh = (EventHandler)(Events [LoadEvent]);
  1489. if (eh != null)
  1490. eh (this, e);
  1491. if (!IsMdiChild) {
  1492. switch (StartPosition) {
  1493. case FormStartPosition.CenterScreen:
  1494. this.CenterToScreen();
  1495. break;
  1496. case FormStartPosition.CenterParent:
  1497. this.CenterToParent ();
  1498. break;
  1499. case FormStartPosition.Manual:
  1500. Left = CreateParams.X;
  1501. Top = CreateParams.Y;
  1502. break;
  1503. }
  1504. }
  1505. is_loaded = true;
  1506. }
  1507. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1508. protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
  1509. EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
  1510. if (eh != null)
  1511. eh (this, e);
  1512. }
  1513. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1514. protected virtual void OnMaximumSizeChanged(EventArgs e) {
  1515. EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
  1516. if (eh != null)
  1517. eh (this, e);
  1518. }
  1519. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1520. protected virtual void OnMdiChildActivate(EventArgs e) {
  1521. EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
  1522. if (eh != null)
  1523. eh (this, e);
  1524. }
  1525. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1526. protected virtual void OnMenuComplete(EventArgs e) {
  1527. EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
  1528. if (eh != null)
  1529. eh (this, e);
  1530. }
  1531. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1532. protected virtual void OnMenuStart(EventArgs e) {
  1533. EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
  1534. if (eh != null)
  1535. eh (this, e);
  1536. }
  1537. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1538. protected virtual void OnMinimumSizeChanged(EventArgs e) {
  1539. EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
  1540. if (eh != null)
  1541. eh (this, e);
  1542. }
  1543. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1544. protected override void OnPaint (PaintEventArgs pevent) {
  1545. base.OnPaint (pevent);
  1546. if (size_grip != null) {
  1547. size_grip.HandlePaint (this, pevent);
  1548. }
  1549. }
  1550. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1551. protected override void OnResize(EventArgs e) {
  1552. base.OnResize(e);
  1553. }
  1554. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1555. protected override void OnStyleChanged(EventArgs e) {
  1556. base.OnStyleChanged (e);
  1557. }
  1558. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1559. protected override void OnTextChanged(EventArgs e) {
  1560. base.OnTextChanged (e);
  1561. if (mdi_container != null)
  1562. mdi_container.SetParentText(true);
  1563. }
  1564. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1565. protected override void OnVisibleChanged(EventArgs e) {
  1566. base.OnVisibleChanged (e);
  1567. if (Visible) {
  1568. if (window_manager != null)
  1569. window_manager.SetWindowState (WindowState, WindowState);
  1570. }
  1571. }
  1572. protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
  1573. if (base.ProcessCmdKey (ref msg, keyData)) {
  1574. return true;
  1575. }
  1576. // Give our menu a shot
  1577. if (ActiveMenu != null) {
  1578. return ActiveMenu.ProcessCmdKey(ref msg, keyData);
  1579. }
  1580. if (IsMdiChild) {
  1581. switch (keyData)
  1582. {
  1583. case Keys.Control | Keys.F4:
  1584. case Keys.Control | Keys.Shift | Keys.F4:
  1585. Close ();
  1586. return true;
  1587. case Keys.Control | Keys.Tab:
  1588. case Keys.Control | Keys.F6:
  1589. MdiParent.MdiContainer.ActivateNextChild ();
  1590. return true;
  1591. case Keys.Control | Keys.Shift | Keys.Tab:
  1592. case Keys.Control | Keys.Shift | Keys.F6:
  1593. MdiParent.MdiContainer.ActivatePreviousChild ();
  1594. return true;
  1595. }
  1596. }
  1597. return false;
  1598. }
  1599. // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
  1600. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1601. protected override bool ProcessDialogChar(char charCode) {
  1602. return base.ProcessDialogChar (charCode);
  1603. }
  1604. protected override bool ProcessDialogKey(Keys keyData) {
  1605. if ((keyData & Keys.Modifiers) == 0) {
  1606. if (keyData == Keys.Enter) {
  1607. IntPtr window = XplatUI.GetFocus ();
  1608. Control c = Control.FromHandle (window);
  1609. if (c is Button && c.FindForm () == this) {
  1610. ((Button)c).PerformClick ();
  1611. return true;
  1612. }
  1613. else if (accept_button != null) {
  1614. accept_button.PerformClick();
  1615. return true;
  1616. }
  1617. } else if (keyData == Keys.Escape && cancel_button != null) {
  1618. cancel_button.PerformClick();
  1619. return true;
  1620. }
  1621. }
  1622. return base.ProcessDialogKey(keyData);
  1623. }
  1624. protected override bool ProcessKeyPreview(ref Message msg) {
  1625. if (key_preview) {
  1626. if (ProcessKeyEventArgs(ref msg)) {
  1627. return true;
  1628. }
  1629. }
  1630. return base.ProcessKeyPreview (ref msg);
  1631. }
  1632. protected override bool ProcessTabKey(bool forward) {
  1633. return SelectNextControl(ActiveControl, forward, true, true, true);
  1634. }
  1635. #if NET_2_0
  1636. [EditorBrowsable(EditorBrowsableState.Never)]
  1637. #else
  1638. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1639. #endif
  1640. protected override void ScaleCore(float dx, float dy) {
  1641. try {
  1642. SuspendLayout();
  1643. // We can't scale max or min windows
  1644. if (WindowState == FormWindowState.Normal) {
  1645. // We cannot call base since base also adjusts X/Y, but
  1646. // a form is toplevel and doesn't move
  1647. Size size;
  1648. size = ClientSize;
  1649. if (!GetStyle(ControlStyles.FixedWidth)) {
  1650. size.Width = (int)(size.Width * dx);
  1651. }
  1652. if (!GetStyle(ControlStyles.FixedHeight)) {
  1653. size.Height = (int)(size.Height * dy);
  1654. }
  1655. ClientSize = size;
  1656. }
  1657. /* Now scale our children */
  1658. Control [] controls = Controls.GetAllControls ();
  1659. for (int i=0; i < controls.Length; i++) {
  1660. controls[i].Scale(dx, dy);
  1661. }
  1662. }
  1663. finally {
  1664. ResumeLayout();
  1665. }
  1666. }
  1667. protected override void Select(bool directed, bool forward) {
  1668. Form parent;
  1669. if (directed) {
  1670. base.SelectNextControl(null, forward, true, true, true);
  1671. }
  1672. parent = this.ParentForm;
  1673. if (parent != null) {
  1674. parent.ActiveControl = this;
  1675. }
  1676. Activate();
  1677. }
  1678. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1679. protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  1680. base.SetBoundsCore (x, y, width, height, specified);
  1681. }
  1682. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1683. protected override void SetClientSizeCore(int x, int y) {
  1684. if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
  1685. x = minimum_size.Width;
  1686. } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
  1687. x = maximum_size.Width;
  1688. }
  1689. if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
  1690. y = minimum_size.Height;
  1691. } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
  1692. y = maximum_size.Height;
  1693. }
  1694. Rectangle ClientRect = new Rectangle(0, 0, x, y);
  1695. Rectangle WindowRect;
  1696. CreateParams cp = this.CreateParams;
  1697. clientsize_set = new Size(x, y);
  1698. if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
  1699. SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
  1700. }
  1701. }
  1702. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1703. protected override void SetVisibleCore(bool value)
  1704. {
  1705. is_changing_visible_state = true;
  1706. has_been_visible = value || has_been_visible;
  1707. base.SetVisibleCore (value);
  1708. is_changing_visible_state = false;
  1709. #if NET_2_0
  1710. // Shown event is only called once, the first time the form is made visible
  1711. if (value && !shown_raised) {
  1712. this.OnShown (EventArgs.Empty);
  1713. shown_raised = true;
  1714. }
  1715. #endif
  1716. }
  1717. protected override void UpdateDefaultButton() {
  1718. base.UpdateDefaultButton ();
  1719. }
  1720. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1721. protected override void WndProc(ref Message m) {
  1722. #if debug
  1723. Console.WriteLine(DateTime.Now.ToLongTimeString () + " Form {0} ({2}) received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString (), Text);
  1724. #endif
  1725. if (window_manager != null && window_manager.WndProc (ref m)) {
  1726. return;
  1727. }
  1728. switch((Msg)m.Msg) {
  1729. case Msg.WM_DESTROY: {
  1730. base.WndProc(ref m);
  1731. if (!RecreatingHandle) {
  1732. this.closing = true;
  1733. }
  1734. return;
  1735. }
  1736. case Msg.WM_CLOSE: {
  1737. Form act = Form.ActiveForm;
  1738. // Don't close this form if there's another modal form visible.
  1739. if (act != null && act != this && act.Modal == true) {
  1740. // Check if any of the parents up the tree is the modal form,
  1741. // in which case we can still close this form.
  1742. Control current = this;
  1743. while (current != null && current.Parent != act) {
  1744. current = current.Parent;
  1745. }
  1746. if (current == null || current.Parent != act) {
  1747. return;
  1748. }
  1749. }
  1750. if (mdi_container != null) {
  1751. foreach (Form mdi_child in mdi_container.MdiChildren) {
  1752. mdi_child.FireClosingEvents (CloseReason.MdiFormClosing);
  1753. }
  1754. }
  1755. if (!is_modal) {
  1756. if (!FireClosingEvents (CloseReason.UserClosing)) {
  1757. OnClosed (EventArgs.Empty);
  1758. #if NET_2_0
  1759. OnFormClosed (new FormClosedEventArgs (CloseReason.UserClosing));
  1760. #endif
  1761. closing = true;
  1762. Dispose ();
  1763. }
  1764. else {
  1765. closing = false;
  1766. }
  1767. } else {
  1768. if (FireClosingEvents (CloseReason.UserClosing)) {
  1769. DialogResult = DialogResult.None;
  1770. closing = false;
  1771. }
  1772. else {
  1773. OnClosed (EventArgs.Empty);
  1774. #if NET_2_0
  1775. OnFormClosed (new FormClosedEventArgs (CloseReason.UserClosing));
  1776. #endif
  1777. closing = true;
  1778. Hide ();
  1779. }
  1780. }
  1781. return;
  1782. }
  1783. case Msg.WM_WINDOWPOSCHANGED: {
  1784. if (WindowState != FormWindowState.Minimized) {
  1785. base.WndProc(ref m);
  1786. }
  1787. return;
  1788. }
  1789. #if NET_2_0
  1790. case Msg.WM_SYSCOMMAND: {
  1791. // Let *Strips know the app's title bar was clicked
  1792. if (XplatUI.IsEnabled (Handle))
  1793. ToolStripManager.FireAppClicked ();
  1794. base.WndProc(ref m);
  1795. break;
  1796. }
  1797. #endif
  1798. case Msg.WM_ACTIVATE: {
  1799. if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
  1800. if (is_loaded) {
  1801. SelectActiveControl ();
  1802. if (ActiveControl != null && !ActiveControl.Focused)
  1803. SendControlFocus (ActiveControl);
  1804. }
  1805. OnActivated(EventArgs.Empty);
  1806. } else {
  1807. OnDeactivate(EventArgs.Empty);
  1808. }
  1809. return;
  1810. }
  1811. case Msg.WM_KILLFOCUS: {
  1812. base.WndProc(ref m);
  1813. return;
  1814. }
  1815. case Msg.WM_SETFOCUS: {
  1816. if (ActiveControl != null && ActiveControl != this) {
  1817. ActiveControl.Focus();
  1818. return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
  1819. }
  1820. if (IsMdiContainer) {
  1821. mdi_container.SendFocusToActiveChild ();
  1822. return;
  1823. }
  1824. base.WndProc(ref m);
  1825. return;
  1826. }
  1827. // Menu drawing
  1828. case Msg.WM_NCHITTEST: {
  1829. if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
  1830. int x = LowOrder ((int)m.LParam.ToInt32 ());
  1831. int y = HighOrder ((int)m.LParam.ToInt32 ());
  1832. XplatUI.ScreenToMenu (ActiveMenu.Wnd.window.Handle, ref x, ref y);
  1833. // If point is under menu return HTMENU, it prevents Win32 to return HTMOVE.
  1834. if ((x > 0) && (y > 0) && (x < ActiveMenu.Rect.Width) && (y < ActiveMenu.Rect.Height)) {
  1835. m.Result = new IntPtr ((int)HitTest.HTMENU);
  1836. return;
  1837. }
  1838. }
  1839. base.WndProc (ref m);
  1840. return;
  1841. }
  1842. case Msg.WM_NCLBUTTONDOWN: {
  1843. if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
  1844. ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
  1845. }
  1846. if (ActiveMaximizedMdiChild != null) {
  1847. if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
  1848. LowOrder ((int) m.LParam.ToInt32 ()),
  1849. HighOrder ((int) m.LParam.ToInt32 ()))) {
  1850. // Don't let base process this message, otherwise we won't
  1851. // get a WM_NCLBUTTONUP.
  1852. return;
  1853. }
  1854. }
  1855. base.WndProc(ref m);
  1856. return;
  1857. }
  1858. case Msg.WM_NCLBUTTONUP: {
  1859. if (ActiveMaximizedMdiChild != null) {
  1860. ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
  1861. LowOrder ((int)m.LParam.ToInt32 ()),
  1862. HighOrder ((int)m.LParam.ToInt32 ()));
  1863. }
  1864. base.WndProc (ref m);
  1865. return;
  1866. }
  1867. case Msg.WM_NCMOUSELEAVE: {
  1868. if (ActiveMaximizedMdiChild != null) {
  1869. ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
  1870. LowOrder((int)m.LParam.ToInt32()),
  1871. HighOrder((int)m.LParam.ToInt32()));
  1872. }
  1873. base.WndProc(ref m);
  1874. return;
  1875. }
  1876. case Msg.WM_NCMOUSEMOVE: {
  1877. if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
  1878. ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
  1879. }
  1880. if (ActiveMaximizedMdiChild != null) {
  1881. XplatUI.RequestAdditionalWM_NCMessages (Handle, false, true);
  1882. ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
  1883. LowOrder ((int)m.LParam.ToInt32 ()),
  1884. HighOrder ((int)m.LParam.ToInt32 ()));
  1885. }
  1886. base.WndProc(ref m);
  1887. return;
  1888. }
  1889. case Msg.WM_NCPAINT: {
  1890. if (ActiveMenu != null) {
  1891. PaintEventArgs pe;
  1892. Point pnt;
  1893. pe = XplatUI.PaintEventStart(Handle, false);
  1894. pnt = XplatUI.GetMenuOrigin(window.Handle);
  1895. // The entire menu has to be in the clip rectangle because the
  1896. // control buttons are right-aligned and otherwise they would
  1897. // stay painted when the window gets resized.
  1898. Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
  1899. clip = Rectangle.Union(clip, pe.ClipRectangle);
  1900. pe.SetClip(clip);
  1901. pe.Graphics.SetClip(clip);
  1902. ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
  1903. if (ActiveMaximizedMdiChild != null) {
  1904. ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
  1905. }
  1906. XplatUI.PaintEventEnd(Handle, false);
  1907. }
  1908. base.WndProc(ref m);
  1909. return;
  1910. }
  1911. case Msg.WM_NCCALCSIZE: {
  1912. XplatUIWin32.NCCALCSIZE_PARAMS ncp;
  1913. if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
  1914. ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
  1915. // Adjust for menu
  1916. ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ClientSize.Width);
  1917. Marshal.StructureToPtr(ncp, m.LParam, true);
  1918. }
  1919. DefWndProc(ref m);
  1920. break;
  1921. }
  1922. case Msg.WM_MOUSEMOVE: {
  1923. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  1924. MouseEventArgs args;
  1925. args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1926. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
  1927. active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
  1928. break;
  1929. }
  1930. base.WndProc(ref m);
  1931. break;
  1932. }
  1933. case Msg.WM_LBUTTONDOWN:
  1934. case Msg.WM_MBUTTONDOWN:
  1935. case Msg.WM_RBUTTONDOWN: {
  1936. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  1937. MouseEventArgs args;
  1938. args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1939. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
  1940. active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
  1941. return;
  1942. }
  1943. #if NET_2_0
  1944. ToolStripManager.FireAppClicked ();
  1945. #endif
  1946. base.WndProc (ref m);
  1947. return;
  1948. }
  1949. case Msg.WM_LBUTTONUP:
  1950. case Msg.WM_MBUTTONUP:
  1951. case Msg.WM_RBUTTONUP: {
  1952. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  1953. MouseEventArgs args;
  1954. MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
  1955. // We add in the button that was released (not sent in WParam)
  1956. switch((Msg)m.Msg) {
  1957. case Msg.WM_LBUTTONUP:
  1958. mb |= MouseButtons.Left;
  1959. break;
  1960. case Msg.WM_MBUTTONUP:
  1961. mb |= MouseButtons.Middle;
  1962. break;
  1963. case Msg.WM_RBUTTONUP:
  1964. mb |= MouseButtons.Right;
  1965. break;
  1966. }
  1967. args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
  1968. active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
  1969. mouse_clicks = 1;
  1970. return;
  1971. }
  1972. base.WndProc(ref m);
  1973. return;
  1974. }
  1975. case Msg.WM_GETMINMAXINFO: {
  1976. MINMAXINFO mmi;
  1977. if (m.LParam != IntPtr.Zero) {
  1978. mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
  1979. default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
  1980. if (maximized_bounds != Rectangle.Empty) {
  1981. mmi.ptMaxPosition.x = maximized_bounds.Left;
  1982. mmi.ptMaxPosition.y = maximized_bounds.Top;
  1983. mmi.ptMaxSize.x = maximized_bounds.Width;
  1984. mmi.ptMaxSize.y = maximized_bounds.Height;
  1985. }
  1986. if (minimum_size != Size.Empty) {
  1987. mmi.ptMinTrackSize.x = minimum_size.Width;
  1988. mmi.ptMinTrackSize.y = minimum_size.Height;
  1989. }
  1990. if (maximum_size != Size.Empty) {
  1991. mmi.ptMaxTrackSize.x = maximum_size.Width;
  1992. mmi.ptMaxTrackSize.y = maximum_size.Height;
  1993. }
  1994. Marshal.StructureToPtr(mmi, m.LParam, false);
  1995. }
  1996. break;
  1997. }
  1998. #if NET_2_0
  1999. case Msg.WM_MOUSEACTIVATE: {
  2000. // Let *Strips know the form or another control has been clicked
  2001. if (XplatUI.IsEnabled (Handle))
  2002. ToolStripManager.FireAppClicked ();
  2003. base.WndProc (ref m);
  2004. break;
  2005. }
  2006. case Msg.WM_ACTIVATEAPP: {
  2007. // Let *Strips know the app lost focus
  2008. if (m.WParam == (IntPtr)0)
  2009. if (XplatUI.IsEnabled (Handle))
  2010. ToolStripManager.FireAppFocusChanged (this);
  2011. base.WndProc (ref m);
  2012. break;
  2013. }
  2014. #endif
  2015. default: {
  2016. base.WndProc (ref m);
  2017. break;
  2018. }
  2019. }
  2020. }
  2021. #endregion // Protected Instance Methods
  2022. internal override void FireEnter ()
  2023. {
  2024. // do nothing - forms don't generate OnEnter
  2025. }
  2026. internal override void FireLeave ()
  2027. {
  2028. // do nothing - forms don't generate OnLeave
  2029. }
  2030. internal void RemoveWindowManager ()
  2031. {
  2032. window_manager = null;
  2033. }
  2034. internal override void CheckAcceptButton()
  2035. {
  2036. if (accept_button != null) {
  2037. Button a_button = accept_button as Button;
  2038. if (ActiveControl == a_button)
  2039. return;
  2040. if (ActiveControl is Button) {
  2041. a_button.paint_as_acceptbutton = false;
  2042. a_button.Redraw();
  2043. return;
  2044. } else {
  2045. a_button.paint_as_acceptbutton = true;
  2046. a_button.Redraw();
  2047. }
  2048. }
  2049. }
  2050. internal override bool ActivateOnShow { get { return !this.ShowWithoutActivation; } }
  2051. #region Events
  2052. static object ActivatedEvent = new object ();
  2053. static object ClosedEvent = new object ();
  2054. static object ClosingEvent = new object ();
  2055. static object DeactivateEvent = new object ();
  2056. static object InputLanguageChangedEvent = new object ();
  2057. static object InputLanguageChangingEvent = new object ();
  2058. static object LoadEvent = new object ();
  2059. static object MaximizedBoundsChangedEvent = new object ();
  2060. static object MaximumSizeChangedEvent = new object ();
  2061. static object MdiChildActivateEvent = new object ();
  2062. static object MenuCompleteEvent = new object ();
  2063. static object MenuStartEvent = new object ();
  2064. static object MinimumSizeChangedEvent = new object ();
  2065. public event EventHandler Activated {
  2066. add { Events.AddHandler (ActivatedEvent, value); }
  2067. remove { Events.RemoveHandler (ActivatedEvent, value); }
  2068. }
  2069. #if NET_2_0
  2070. [Browsable (false)]
  2071. [EditorBrowsable (EditorBrowsableState.Never)]
  2072. #endif
  2073. public event EventHandler Closed {
  2074. add { Events.AddHandler (ClosedEvent, value); }
  2075. remove { Events.RemoveHandler (ClosedEvent, value); }
  2076. }
  2077. #if NET_2_0
  2078. [Browsable (false)]
  2079. [EditorBrowsable (EditorBrowsableState.Never)]
  2080. #endif
  2081. public event CancelEventHandler Closing {
  2082. add { Events.AddHandler (ClosingEvent, value); }
  2083. remove { Events.RemoveHandler (ClosingEvent, value); }
  2084. }
  2085. public event EventHandler Deactivate {
  2086. add { Events.AddHandler (DeactivateEvent, value); }
  2087. remove { Events.RemoveHandler (DeactivateEvent, value); }
  2088. }
  2089. public event InputLanguageChangedEventHandler InputLanguageChanged {
  2090. add { Events.AddHandler (InputLanguageChangedEvent, value); }
  2091. remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
  2092. }
  2093. public event InputLanguageChangingEventHandler InputLanguageChanging {
  2094. add { Events.AddHandler (InputLanguageChangingEvent, value); }
  2095. remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
  2096. }
  2097. public event EventHandler Load {
  2098. add { Events.AddHandler (LoadEvent, value); }
  2099. remove { Events.RemoveHandler (LoadEvent, value); }
  2100. }
  2101. public event EventHandler MaximizedBoundsChanged {
  2102. add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
  2103. remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
  2104. }
  2105. public event EventHandler MaximumSizeChanged {
  2106. add { Events.AddHandler (MaximumSizeChangedEvent, value); }
  2107. remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
  2108. }
  2109. public event EventHandler MdiChildActivate {
  2110. add { Events.AddHandler (MdiChildActivateEvent, value); }
  2111. remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
  2112. }
  2113. #if NET_2_0
  2114. [Browsable (false)]
  2115. #endif
  2116. public event EventHandler MenuComplete {
  2117. add { Events.AddHandler (MenuCompleteEvent, value); }
  2118. remove { Events.RemoveHandler (MenuCompleteEvent, value); }
  2119. }
  2120. #if NET_2_0
  2121. [Browsable (false)]
  2122. #endif
  2123. public event EventHandler MenuStart {
  2124. add { Events.AddHandler (MenuStartEvent, value); }
  2125. remove { Events.RemoveHandler (MenuStartEvent, value); }
  2126. }
  2127. public event EventHandler MinimumSizeChanged {
  2128. add { Events.AddHandler (MinimumSizeChangedEvent, value); }
  2129. remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
  2130. }
  2131. [Browsable(false)]
  2132. [EditorBrowsable(EditorBrowsableState.Never)]
  2133. public new event EventHandler TabIndexChanged {
  2134. add { base.TabIndexChanged += value; }
  2135. remove { base.TabIndexChanged -= value; }
  2136. }
  2137. #endregion // Events
  2138. #if NET_2_0
  2139. [SettingsBindable (true)]
  2140. public override string Text {
  2141. get {
  2142. return base.Text;
  2143. }
  2144. set {
  2145. base.Text = value;
  2146. }
  2147. }
  2148. [SettingsBindable (true)]
  2149. public new Point Location {
  2150. get {
  2151. return base.Location;
  2152. }
  2153. set {
  2154. base.Location = value;
  2155. }
  2156. }
  2157. static object FormClosingEvent = new object ();
  2158. static object FormClosedEvent = new object ();
  2159. static object HelpButtonClickedEvent = new object ();
  2160. static object ResizeEndEvent = new object ();
  2161. static object ResizeBeginEvent = new object ();
  2162. static object RightToLeftLayoutChangedEvent = new object ();
  2163. static object ShownEvent = new object ();
  2164. [Browsable (true)]
  2165. [EditorBrowsable (EditorBrowsableState.Always)]
  2166. public new event EventHandler AutoSizeChanged {
  2167. add { base.AutoSizeChanged += value; }
  2168. remove { base.AutoSizeChanged -= value; }
  2169. }
  2170. [Browsable (true)]
  2171. [EditorBrowsable (EditorBrowsableState.Always)]
  2172. public new event EventHandler AutoValidateChanged {
  2173. add { base.AutoValidateChanged += value; }
  2174. remove { base.AutoValidateChanged -= value; }
  2175. }
  2176. public event FormClosingEventHandler FormClosing {
  2177. add { Events.AddHandler (FormClosingEvent, value); }
  2178. remove { Events.RemoveHandler (FormClosingEvent, value); }
  2179. }
  2180. public event FormClosedEventHandler FormClosed {
  2181. add { Events.AddHandler (FormClosedEvent, value); }
  2182. remove { Events.RemoveHandler (FormClosedEvent, value); }
  2183. }
  2184. [Browsable (true)]
  2185. [EditorBrowsable (EditorBrowsableState.Always)]
  2186. public event CancelEventHandler HelpButtonClicked {
  2187. add { Events.AddHandler (HelpButtonClickedEvent, value); }
  2188. remove { Events.RemoveHandler (HelpButtonClickedEvent, value); }
  2189. }
  2190. [Browsable (false)]
  2191. [EditorBrowsable (EditorBrowsableState.Never)]
  2192. public new event EventHandler MarginChanged {
  2193. add { base.MarginChanged += value; }
  2194. remove { base.MarginChanged -= value; }
  2195. }
  2196. public event EventHandler RightToLeftLayoutChanged {
  2197. add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
  2198. remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
  2199. }
  2200. public event EventHandler ResizeBegin {
  2201. add { Events.AddHandler (ResizeBeginEvent, value); }
  2202. remove { Events.RemoveHandler (ResizeBeginEvent, value); }
  2203. }
  2204. public event EventHandler ResizeEnd {
  2205. add { Events.AddHandler (ResizeEndEvent, value); }
  2206. remove { Events.RemoveHandler (ResizeEndEvent, value); }
  2207. }
  2208. public event EventHandler Shown {
  2209. add { Events.AddHandler (ShownEvent, value); }
  2210. remove { Events.RemoveHandler (ShownEvent, value); }
  2211. }
  2212. [Browsable (false)]
  2213. [EditorBrowsable (EditorBrowsableState.Never)]
  2214. public new event EventHandler TabStopChanged {
  2215. add { base.TabStopChanged += value; }
  2216. remove { base.TabStopChanged -= value; }
  2217. }
  2218. protected override void OnBackgroundImageChanged (EventArgs e)
  2219. {
  2220. base.OnBackgroundImageChanged (e);
  2221. }
  2222. protected override void OnBackgroundImageLayoutChanged (EventArgs e)
  2223. {
  2224. base.OnBackgroundImageLayoutChanged (e);
  2225. }
  2226. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2227. protected override void OnEnabledChanged (EventArgs e)
  2228. {
  2229. base.OnEnabledChanged (e);
  2230. }
  2231. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2232. protected override void OnEnter (EventArgs e)
  2233. {
  2234. base.OnEnter (e);
  2235. }
  2236. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2237. protected virtual void OnFormClosed (FormClosedEventArgs e) {
  2238. FormClosedEventHandler eh = (FormClosedEventHandler)(Events[FormClosedEvent]);
  2239. if (eh != null)
  2240. eh (this, e);
  2241. }
  2242. // Consider calling FireClosingEvents instead of calling this directly.
  2243. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2244. protected virtual void OnFormClosing (FormClosingEventArgs e)
  2245. {
  2246. FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);
  2247. if (eh != null)
  2248. eh (this, e);
  2249. }
  2250. [MonoTODO ("Not hooked up to event")]
  2251. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2252. protected virtual void OnHelpButtonClicked (CancelEventArgs e)
  2253. {
  2254. CancelEventHandler eh = (CancelEventHandler)(Events[HelpButtonClickedEvent]);
  2255. if (eh != null)
  2256. eh (this, e);
  2257. }
  2258. protected override void OnLayout (LayoutEventArgs levent)
  2259. {
  2260. base.OnLayout (levent);
  2261. }
  2262. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2263. protected virtual void OnResizeBegin (EventArgs e)
  2264. {
  2265. EventHandler eh = (EventHandler) (Events [ResizeBeginEvent]);
  2266. if (eh != null)
  2267. eh (this, e);
  2268. }
  2269. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2270. protected virtual void OnResizeEnd (EventArgs e)
  2271. {
  2272. EventHandler eh = (EventHandler) (Events [ResizeEndEvent]);
  2273. if (eh != null)
  2274. eh (this, e);
  2275. }
  2276. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2277. protected virtual void OnShown (EventArgs e)
  2278. {
  2279. EventHandler eh = (EventHandler) (Events [ShownEvent]);
  2280. if (eh != null)
  2281. eh (this, e);
  2282. }
  2283. #endif
  2284. }
  2285. }