Form.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  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. [ToolboxItem(false)]
  40. public class Form : ContainerControl {
  41. #region Local Variables
  42. internal bool closing;
  43. FormBorderStyle form_border_style;
  44. private bool autoscale;
  45. private Size clientsize_set;
  46. private Size autoscale_base_size;
  47. private bool allow_transparency;
  48. private static Icon default_icon;
  49. internal bool is_modal;
  50. internal FormWindowState window_state;
  51. private bool control_box;
  52. private bool minimize_box;
  53. private bool maximize_box;
  54. private bool help_button;
  55. private bool show_in_taskbar;
  56. private bool topmost;
  57. private IButtonControl accept_button;
  58. private IButtonControl cancel_button;
  59. private DialogResult dialog_result;
  60. private FormStartPosition start_position;
  61. private Form owner;
  62. private Form.ControlCollection owned_forms;
  63. private MdiClient mdi_container;
  64. internal InternalWindowManager window_manager;
  65. private Form mdi_parent;
  66. private bool key_preview;
  67. private MainMenu menu;
  68. private Icon icon;
  69. private Size maximum_size;
  70. private Size minimum_size;
  71. private SizeGripStyle size_grip_style;
  72. private Rectangle maximized_bounds;
  73. private Rectangle default_maximized_bounds;
  74. private double opacity;
  75. internal ApplicationContext context;
  76. Color transparency_key;
  77. internal MenuTracker active_tracker;
  78. private bool is_loaded;
  79. internal bool is_changing_visible_state;
  80. internal bool has_been_visible;
  81. #endregion // Local Variables
  82. #region Private & Internal Methods
  83. static Form ()
  84. {
  85. default_icon = Locale.GetResource("mono.ico") as Icon;
  86. }
  87. // warning: this is only hooked up when an mdi container is created.
  88. private void ControlAddedHandler (object sender, ControlEventArgs e)
  89. {
  90. if (mdi_container != null) {
  91. mdi_container.SendToBack ();
  92. }
  93. }
  94. private void SelectActiveControl ()
  95. {
  96. if (this.IsMdiContainer)
  97. return;
  98. if (this.ActiveControl == null) {
  99. bool visible;
  100. // This visible hack is to work around CanSelect always being false if one of the parents
  101. // is not visible; and we by default create Form invisible...
  102. visible = this.is_visible;
  103. this.is_visible = true;
  104. if (SelectNextControl (this, true, true, true, true) == false) {
  105. Select (this);
  106. }
  107. this.is_visible = visible;
  108. } else {
  109. Select (ActiveControl);
  110. }
  111. }
  112. #endregion // Private & Internal Methods
  113. #region Public Classes
  114. public new class ControlCollection : Control.ControlCollection {
  115. Form form_owner;
  116. public ControlCollection(Form owner) : base(owner) {
  117. this.form_owner = owner;
  118. }
  119. public override void Add(Control value) {
  120. if (Contains (value))
  121. return;
  122. AddToList (value);
  123. ((Form)value).owner=form_owner;
  124. }
  125. public override void Remove(Control value) {
  126. ((Form)value).owner = null;
  127. base.Remove (value);
  128. }
  129. }
  130. #endregion // Public Classes
  131. #region Public Constructor & Destructor
  132. public Form ()
  133. {
  134. SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
  135. autoscale = true;
  136. autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
  137. allow_transparency = false;
  138. closing = false;
  139. is_modal = false;
  140. dialog_result = DialogResult.None;
  141. start_position = FormStartPosition.WindowsDefaultLocation;
  142. form_border_style = FormBorderStyle.Sizable;
  143. window_state = FormWindowState.Normal;
  144. key_preview = false;
  145. opacity = 1D;
  146. menu = null;
  147. icon = default_icon;
  148. minimum_size = Size.Empty;
  149. maximum_size = Size.Empty;
  150. clientsize_set = Size.Empty;
  151. control_box = true;
  152. minimize_box = true;
  153. maximize_box = true;
  154. help_button = false;
  155. show_in_taskbar = true;
  156. is_visible = false;
  157. is_toplevel = true;
  158. size_grip_style = SizeGripStyle.Auto;
  159. maximized_bounds = Rectangle.Empty;
  160. default_maximized_bounds = Rectangle.Empty;
  161. owned_forms = new Form.ControlCollection(this);
  162. transparency_key = Color.Empty;
  163. // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
  164. UpdateBounds();
  165. }
  166. #endregion // Public Constructor & Destructor
  167. #region Public Static Properties
  168. public static Form ActiveForm {
  169. get {
  170. Control active;
  171. active = FromHandle(XplatUI.GetActive());
  172. if (active != null) {
  173. if ( !(active is Form)) {
  174. Control parent;
  175. parent = active.Parent;
  176. while (parent != null) {
  177. if (parent is Form) {
  178. return (Form)parent;
  179. }
  180. parent = parent.Parent;
  181. }
  182. } else {
  183. return (Form)active;
  184. }
  185. }
  186. return null;
  187. }
  188. }
  189. #endregion // Public Static Properties
  190. #region Public Instance Properties
  191. [DefaultValue(null)]
  192. public IButtonControl AcceptButton {
  193. get {
  194. return accept_button;
  195. }
  196. set {
  197. accept_button = value;
  198. CheckAcceptButton();
  199. }
  200. }
  201. [Browsable(false)]
  202. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  203. public bool AllowTransparency {
  204. get {
  205. return allow_transparency;
  206. }
  207. set {
  208. if (value == allow_transparency) {
  209. return;
  210. }
  211. allow_transparency = value;
  212. if (value) {
  213. if (IsHandleCreated) {
  214. if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
  215. XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
  216. }
  217. } else {
  218. UpdateStyles(); // Remove the WS_EX_LAYERED style
  219. }
  220. }
  221. }
  222. }
  223. #if NET_2_0
  224. #else
  225. [DefaultValue(true)]
  226. #endif
  227. [MWFCategory("Layout")]
  228. public bool AutoScale {
  229. get {
  230. return autoscale;
  231. }
  232. set {
  233. autoscale = value;
  234. }
  235. }
  236. [Localizable(true)]
  237. [Browsable(false)]
  238. [EditorBrowsable(EditorBrowsableState.Advanced)]
  239. public virtual Size AutoScaleBaseSize {
  240. get {
  241. return autoscale_base_size;
  242. }
  243. set {
  244. autoscale_base_size = value;
  245. }
  246. }
  247. [Localizable(true)]
  248. public override bool AutoScroll {
  249. get {
  250. return base.AutoScroll;
  251. }
  252. set {
  253. base.AutoScroll = value;
  254. }
  255. }
  256. public override Color BackColor {
  257. get {
  258. /* we don't let parents override our
  259. default background color for forms.
  260. this fixes the default color for mdi
  261. children. */
  262. if (background_color.IsEmpty)
  263. return DefaultBackColor;
  264. else
  265. return background_color;
  266. }
  267. set {
  268. base.BackColor = value;
  269. }
  270. }
  271. [DefaultValue(null)]
  272. public IButtonControl CancelButton {
  273. get {
  274. return cancel_button;
  275. }
  276. set {
  277. cancel_button = value;
  278. if (cancel_button.DialogResult == DialogResult.None)
  279. cancel_button.DialogResult = DialogResult.Cancel;
  280. }
  281. }
  282. // new property so we can change the DesignerSerializationVisibility
  283. [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
  284. [Localizable(true)]
  285. public new Size ClientSize {
  286. get { return base.ClientSize; }
  287. set { base.ClientSize = value; }
  288. }
  289. [DefaultValue(true)]
  290. [MWFCategory("Window Style")]
  291. public bool ControlBox {
  292. get {
  293. return control_box;
  294. }
  295. set {
  296. if (control_box != value) {
  297. control_box = value;
  298. UpdateStyles();
  299. }
  300. }
  301. }
  302. [Browsable(false)]
  303. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  304. public Rectangle DesktopBounds {
  305. get {
  306. return new Rectangle(Location, Size);
  307. }
  308. set {
  309. Bounds = value;
  310. }
  311. }
  312. [Browsable(false)]
  313. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  314. public Point DesktopLocation {
  315. get {
  316. return Location;
  317. }
  318. set {
  319. Location = value;
  320. }
  321. }
  322. [Browsable(false)]
  323. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  324. public DialogResult DialogResult {
  325. get {
  326. return dialog_result;
  327. }
  328. set {
  329. if (value < DialogResult.None || value > DialogResult.No)
  330. throw new InvalidEnumArgumentException ("value", (int) value,
  331. typeof (DialogResult));
  332. dialog_result = value;
  333. closing = (dialog_result != DialogResult.None && is_modal);
  334. }
  335. }
  336. [DefaultValue(FormBorderStyle.Sizable)]
  337. [DispId(-504)]
  338. [MWFCategory("Appearance")]
  339. public FormBorderStyle FormBorderStyle {
  340. get {
  341. return form_border_style;
  342. }
  343. set {
  344. form_border_style = value;
  345. if (window_manager == null) {
  346. if (IsHandleCreated) {
  347. XplatUI.SetBorderStyle(window.Handle, form_border_style);
  348. }
  349. } else {
  350. window_manager.UpdateBorderStyle (value);
  351. }
  352. UpdateStyles();
  353. }
  354. }
  355. [DefaultValue(false)]
  356. [MWFCategory("Window Style")]
  357. public bool HelpButton {
  358. get {
  359. return help_button;
  360. }
  361. set {
  362. if (help_button != value) {
  363. help_button = value;
  364. UpdateStyles();
  365. }
  366. }
  367. }
  368. [Localizable(true)]
  369. [AmbientValue(null)]
  370. [MWFCategory("Window Style")]
  371. public Icon Icon {
  372. get {
  373. return icon;
  374. }
  375. set {
  376. if (icon != value) {
  377. icon = value;
  378. if (IsHandleCreated) {
  379. XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
  380. }
  381. }
  382. }
  383. }
  384. [Browsable(false)]
  385. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  386. public bool IsMdiChild {
  387. get {
  388. return mdi_parent != null;
  389. }
  390. }
  391. [DefaultValue(false)]
  392. [MWFCategory("Window Style")]
  393. public bool IsMdiContainer {
  394. get {
  395. return mdi_container != null;
  396. }
  397. set {
  398. if (value && mdi_container == null) {
  399. mdi_container = new MdiClient ();
  400. Controls.Add(mdi_container);
  401. ControlAdded += new ControlEventHandler (ControlAddedHandler);
  402. mdi_container.SendToBack ();
  403. mdi_container.SetParentText (true);
  404. } else if (!value && mdi_container != null) {
  405. Controls.Remove(mdi_container);
  406. mdi_container = null;
  407. }
  408. }
  409. }
  410. [Browsable(false)]
  411. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  412. public Form ActiveMdiChild {
  413. get {
  414. if (!IsMdiContainer)
  415. return null;
  416. return (Form) mdi_container.ActiveMdiChild;
  417. }
  418. }
  419. [Browsable(false)]
  420. [EditorBrowsable(EditorBrowsableState.Advanced)]
  421. public bool IsRestrictedWindow {
  422. get {
  423. return false;
  424. }
  425. }
  426. [DefaultValue(false)]
  427. public bool KeyPreview {
  428. get {
  429. return key_preview;
  430. }
  431. set {
  432. key_preview = value;
  433. }
  434. }
  435. [DefaultValue(true)]
  436. [MWFCategory("Window Style")]
  437. public bool MaximizeBox {
  438. get {
  439. return maximize_box;
  440. }
  441. set {
  442. if (maximize_box != value) {
  443. maximize_box = value;
  444. if (IsHandleCreated) {
  445. RecreateHandle();
  446. }
  447. UpdateStyles();
  448. }
  449. }
  450. }
  451. [DefaultValue("{Width=0, Height=0}")]
  452. [Localizable(true)]
  453. [RefreshProperties(RefreshProperties.Repaint)]
  454. [MWFCategory("Layout")]
  455. public
  456. #if NET_2_0
  457. override
  458. #endif
  459. Size MaximumSize {
  460. get {
  461. return maximum_size;
  462. }
  463. set {
  464. if (maximum_size != value) {
  465. maximum_size = value;
  466. OnMaximumSizeChanged(EventArgs.Empty);
  467. if (IsHandleCreated) {
  468. XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
  469. }
  470. }
  471. }
  472. }
  473. [Browsable(false)]
  474. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  475. public Form[] MdiChildren {
  476. get {
  477. if (mdi_container != null)
  478. return mdi_container.MdiChildren;
  479. else
  480. return new Form[0];
  481. }
  482. }
  483. [Browsable(false)]
  484. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  485. public Form MdiParent {
  486. get {
  487. return mdi_parent;
  488. }
  489. set {
  490. if (value != null && !value.IsMdiContainer)
  491. throw new ArgumentException ();
  492. if (mdi_parent != null) {
  493. mdi_parent.MdiContainer.Controls.Remove (this);
  494. }
  495. if (value != null) {
  496. mdi_parent = value;
  497. window_manager = new MdiWindowManager (this,
  498. mdi_parent.MdiContainer);
  499. mdi_parent.MdiContainer.Controls.Add (this);
  500. mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
  501. RecreateHandle ();
  502. } else if (mdi_parent != null) {
  503. mdi_parent = null;
  504. // Create a new window manager
  505. window_manager = null;
  506. FormBorderStyle = form_border_style;
  507. RecreateHandle ();
  508. }
  509. }
  510. }
  511. internal MenuTracker ActiveTracker {
  512. get { return active_tracker; }
  513. set {
  514. if (value == active_tracker)
  515. return;
  516. Capture = value != null;
  517. active_tracker = value;
  518. }
  519. }
  520. internal MdiClient MdiContainer {
  521. get { return mdi_container; }
  522. }
  523. internal InternalWindowManager WindowManager {
  524. get { return window_manager; }
  525. }
  526. [DefaultValue(null)]
  527. [MWFCategory("Window Style")]
  528. public MainMenu Menu {
  529. get {
  530. return menu;
  531. }
  532. set {
  533. if (menu != value) {
  534. menu = value;
  535. if (menu != null && !IsMdiChild) {
  536. menu.SetForm (this);
  537. if (IsHandleCreated) {
  538. XplatUI.SetMenu (window.Handle, menu);
  539. }
  540. if (clientsize_set != Size.Empty) {
  541. SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
  542. } else {
  543. UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
  544. ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
  545. }
  546. } else
  547. UpdateBounds ();
  548. }
  549. }
  550. }
  551. [Browsable(false)]
  552. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  553. [EditorBrowsable(EditorBrowsableState.Advanced)]
  554. public MainMenu MergedMenu {
  555. get {
  556. if (!IsMdiChild || window_manager == null)
  557. return null;
  558. return ((MdiWindowManager) window_manager).MergedMenu;
  559. }
  560. }
  561. // This is the menu in display and being used because of merging this can
  562. // be different then the menu that is actually assosciated with the form
  563. internal MainMenu ActiveMenu {
  564. get {
  565. if (IsMdiChild)
  566. return null;
  567. if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
  568. ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
  569. MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
  570. return wm.MaximizedMenu;
  571. }
  572. Form amc = ActiveMdiChild;
  573. if (amc == null || amc.Menu == null)
  574. return menu;
  575. return amc.MergedMenu;
  576. }
  577. }
  578. internal MdiWindowManager ActiveMaximizedMdiChild {
  579. get {
  580. Form child = ActiveMdiChild;
  581. if (child == null)
  582. return null;
  583. if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
  584. return null;
  585. return (MdiWindowManager) child.WindowManager;
  586. }
  587. }
  588. [DefaultValue(true)]
  589. [MWFCategory("Window Style")]
  590. public bool MinimizeBox {
  591. get {
  592. return minimize_box;
  593. }
  594. set {
  595. if (minimize_box != value) {
  596. minimize_box = value;
  597. if (IsHandleCreated) {
  598. RecreateHandle();
  599. }
  600. UpdateStyles();
  601. }
  602. }
  603. }
  604. #if !NET_2_0
  605. [DefaultValue("{Width=0, Height=0}")]
  606. #endif
  607. [Localizable(true)]
  608. [RefreshProperties(RefreshProperties.Repaint)]
  609. [MWFCategory("Layout")]
  610. public
  611. #if NET_2_0
  612. override
  613. #endif
  614. Size MinimumSize {
  615. get {
  616. return minimum_size;
  617. }
  618. set {
  619. if (minimum_size != value) {
  620. minimum_size = value;
  621. if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
  622. Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
  623. }
  624. OnMinimumSizeChanged(EventArgs.Empty);
  625. if (IsHandleCreated) {
  626. XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
  627. }
  628. }
  629. }
  630. }
  631. [Browsable(false)]
  632. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  633. public bool Modal {
  634. get {
  635. return is_modal;
  636. }
  637. }
  638. [DefaultValue(1D)]
  639. [TypeConverter(typeof(OpacityConverter))]
  640. [MWFCategory("Window Style")]
  641. public double Opacity {
  642. get {
  643. if (IsHandleCreated) {
  644. if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
  645. return XplatUI.GetWindowTransparency (Handle);
  646. }
  647. return opacity;
  648. }
  649. set {
  650. opacity = value;
  651. AllowTransparency = true;
  652. if (IsHandleCreated) {
  653. UpdateStyles();
  654. if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
  655. XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
  656. }
  657. }
  658. }
  659. [Browsable(false)]
  660. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  661. public Form[] OwnedForms {
  662. get {
  663. Form[] form_list;
  664. form_list = new Form[owned_forms.Count];
  665. for (int i=0; i<owned_forms.Count; i++) {
  666. form_list[i] = (Form)owned_forms[i];
  667. }
  668. return form_list;
  669. }
  670. }
  671. [Browsable(false)]
  672. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  673. public Form Owner {
  674. get {
  675. return owner;
  676. }
  677. set {
  678. if (owner != value) {
  679. if (owner != null) {
  680. owner.RemoveOwnedForm(this);
  681. }
  682. owner = value;
  683. if (owner != null)
  684. owner.AddOwnedForm(this);
  685. if (IsHandleCreated) {
  686. if (owner != null && owner.IsHandleCreated) {
  687. XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
  688. } else {
  689. XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
  690. }
  691. }
  692. }
  693. }
  694. }
  695. [DefaultValue(true)]
  696. [MWFCategory("Window Style")]
  697. public bool ShowInTaskbar {
  698. get {
  699. return show_in_taskbar;
  700. }
  701. set {
  702. if (show_in_taskbar != value) {
  703. show_in_taskbar = value;
  704. if (IsHandleCreated) {
  705. RecreateHandle();
  706. }
  707. UpdateStyles();
  708. }
  709. }
  710. }
  711. // new property so we can set the DesignerSerializationVisibility
  712. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  713. [Localizable(false)]
  714. public new Size Size {
  715. get { return base.Size; }
  716. set { base.Size = value; }
  717. }
  718. [MonoTODO("Trigger something when GripStyle is set")]
  719. [DefaultValue(SizeGripStyle.Auto)]
  720. [MWFCategory("Window Style")]
  721. public SizeGripStyle SizeGripStyle {
  722. get {
  723. return size_grip_style;
  724. }
  725. set {
  726. size_grip_style = value;
  727. }
  728. }
  729. [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
  730. [Localizable(true)]
  731. [MWFCategory("Layout")]
  732. public FormStartPosition StartPosition {
  733. get {
  734. return start_position;
  735. }
  736. set {
  737. if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
  738. start_position = value;
  739. if (IsHandleCreated) {
  740. switch(start_position) {
  741. case FormStartPosition.CenterParent: {
  742. CenterToParent();
  743. break;
  744. }
  745. case FormStartPosition.CenterScreen: {
  746. CenterToScreen();
  747. break;
  748. }
  749. case FormStartPosition.Manual: {
  750. Left = CreateParams.X;
  751. Top = CreateParams.Y;
  752. break;
  753. }
  754. default: {
  755. break;
  756. }
  757. }
  758. }
  759. }
  760. }
  761. }
  762. // new property so we can set EditorBrowsable to never
  763. [Browsable(false)]
  764. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  765. [EditorBrowsable(EditorBrowsableState.Never)]
  766. public new int TabIndex {
  767. get { return base.TabIndex; }
  768. set { base.TabIndex = value; }
  769. }
  770. [Browsable(false)]
  771. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  772. [EditorBrowsable(EditorBrowsableState.Advanced)]
  773. public bool TopLevel {
  774. get {
  775. return GetTopLevel();
  776. }
  777. set {
  778. if (!value && IsMdiContainer)
  779. throw new ArgumentException ("MDI Container forms must be top level.");
  780. SetTopLevel(value);
  781. }
  782. }
  783. [DefaultValue(false)]
  784. [MWFCategory("Window Style")]
  785. public bool TopMost {
  786. get {
  787. return topmost;
  788. }
  789. set {
  790. if (topmost != value) {
  791. topmost = value;
  792. if (IsHandleCreated)
  793. XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
  794. }
  795. }
  796. }
  797. [MWFCategory("Window Style")]
  798. public Color TransparencyKey {
  799. get {
  800. return transparency_key;
  801. }
  802. set {
  803. transparency_key = value;
  804. AllowTransparency = true;
  805. UpdateStyles();
  806. if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
  807. XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
  808. }
  809. }
  810. [DefaultValue(FormWindowState.Normal)]
  811. [MWFCategory("Layout")]
  812. public FormWindowState WindowState {
  813. get {
  814. if (IsHandleCreated) {
  815. if (window_manager != null)
  816. return window_manager.GetWindowState ();
  817. FormWindowState new_state = XplatUI.GetWindowState(Handle);
  818. if (new_state != (FormWindowState)(-1))
  819. window_state = new_state;
  820. }
  821. return window_state;
  822. }
  823. set {
  824. FormWindowState old_state = window_state;
  825. window_state = value;
  826. if (IsHandleCreated) {
  827. if (window_manager != null) {
  828. window_manager.SetWindowState (old_state, value);
  829. return;
  830. }
  831. XplatUI.SetWindowState(Handle, value);
  832. }
  833. }
  834. }
  835. #endregion // Public Instance Properties
  836. #region Protected Instance Properties
  837. protected override CreateParams CreateParams {
  838. get {
  839. CreateParams cp = new CreateParams ();
  840. cp.Caption = Text;
  841. cp.ClassName = XplatUI.DefaultClassName;
  842. cp.ClassStyle = 0;
  843. cp.Style = 0;
  844. cp.ExStyle = 0;
  845. cp.Param = 0;
  846. cp.Parent = IntPtr.Zero;
  847. cp.menu = ActiveMenu;
  848. if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
  849. cp.X = unchecked((int)0x80000000);
  850. cp.Y = unchecked((int)0x80000000);
  851. } else {
  852. cp.X = Left;
  853. cp.Y = Top;
  854. }
  855. cp.Width = Width;
  856. cp.Height = Height;
  857. cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
  858. if (IsMdiChild) {
  859. cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
  860. if (Parent != null) {
  861. cp.Parent = Parent.Handle;
  862. }
  863. cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
  864. switch (FormBorderStyle) {
  865. case FormBorderStyle.None:
  866. break;
  867. case FormBorderStyle.FixedToolWindow:
  868. case FormBorderStyle.SizableToolWindow:
  869. cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
  870. goto default;
  871. default:
  872. cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
  873. break;
  874. }
  875. } else {
  876. switch (FormBorderStyle) {
  877. case FormBorderStyle.Fixed3D: {
  878. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  879. cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
  880. break;
  881. }
  882. case FormBorderStyle.FixedDialog: {
  883. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  884. cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
  885. break;
  886. }
  887. case FormBorderStyle.FixedSingle: {
  888. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  889. break;
  890. }
  891. case FormBorderStyle.FixedToolWindow: {
  892. cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
  893. cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
  894. break;
  895. }
  896. case FormBorderStyle.Sizable: {
  897. cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
  898. break;
  899. }
  900. case FormBorderStyle.SizableToolWindow: {
  901. cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
  902. cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
  903. break;
  904. }
  905. case FormBorderStyle.None: {
  906. break;
  907. }
  908. }
  909. }
  910. switch(window_state) {
  911. case FormWindowState.Maximized: {
  912. cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
  913. break;
  914. }
  915. case FormWindowState.Minimized: {
  916. cp.Style |= (int)WindowStyles.WS_MINIMIZE;
  917. break;
  918. }
  919. }
  920. if (TopMost) {
  921. cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
  922. }
  923. if (ShowInTaskbar) {
  924. cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
  925. }
  926. if (MaximizeBox) {
  927. cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
  928. }
  929. if (MinimizeBox) {
  930. cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
  931. }
  932. if (ControlBox) {
  933. cp.Style |= (int)WindowStyles.WS_SYSMENU;
  934. }
  935. if (HelpButton && !MaximizeBox && !MinimizeBox) {
  936. cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
  937. }
  938. if (Visible)
  939. cp.Style |= (int)WindowStyles.WS_VISIBLE;
  940. if (Opacity < 1.0 || TransparencyKey != Color.Empty) {
  941. cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
  942. }
  943. if (!is_enabled && context == null) {
  944. cp.Style |= (int)(WindowStyles.WS_DISABLED);
  945. }
  946. return cp;
  947. }
  948. }
  949. protected override ImeMode DefaultImeMode {
  950. get {
  951. return ImeMode.NoControl;
  952. }
  953. }
  954. protected override Size DefaultSize {
  955. get {
  956. return new Size (300, 300);
  957. }
  958. }
  959. protected Rectangle MaximizedBounds {
  960. get {
  961. if (maximized_bounds != Rectangle.Empty) {
  962. return maximized_bounds;
  963. }
  964. return default_maximized_bounds;
  965. }
  966. set {
  967. maximized_bounds = value;
  968. OnMaximizedBoundsChanged(EventArgs.Empty);
  969. if (IsHandleCreated) {
  970. XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
  971. }
  972. }
  973. }
  974. #endregion // Protected Instance Properties
  975. #region Public Static Methods
  976. [EditorBrowsable(EditorBrowsableState.Advanced)]
  977. public static SizeF GetAutoScaleSize (Font font)
  978. {
  979. return XplatUI.GetAutoScaleSize(font);
  980. }
  981. #endregion // Public Static Methods
  982. #region Public Instance Methods
  983. internal SizeF GetAutoScaleSize (Graphics g, Font font)
  984. {
  985. //
  986. // The following constants come from the dotnet mailing list
  987. // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
  988. //
  989. // The magic number is "Its almost the length
  990. // of the string with a smattering added in
  991. // for compat with earlier code".
  992. //
  993. string magic_string = "The quick brown fox jumped over the lazy dog.";
  994. double magic_number = 44.549996948242189;
  995. float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
  996. return new SizeF (width, font.Height);
  997. }
  998. public void Activate() {
  999. Form active;
  1000. // The docs say activate only activates if our app is already active
  1001. if (IsHandleCreated) {
  1002. if (IsMdiChild) {
  1003. MdiParent.ActivateMdiChild (this);
  1004. } else {
  1005. active = ActiveForm;
  1006. if ((active != null) && (this != active)) {
  1007. XplatUI.Activate(window.Handle);
  1008. }
  1009. }
  1010. }
  1011. }
  1012. public void AddOwnedForm(Form ownedForm) {
  1013. if (!owned_forms.Contains(ownedForm)) {
  1014. owned_forms.Add(ownedForm);
  1015. }
  1016. ownedForm.Owner = this;
  1017. }
  1018. public void Close () {
  1019. if (IsDisposed)
  1020. return;
  1021. if (!is_visible)
  1022. return;
  1023. #if NET_2_0
  1024. FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
  1025. OnFormClosing (ce);
  1026. if (ce.Cancel)
  1027. return;
  1028. #endif
  1029. XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
  1030. }
  1031. public void LayoutMdi(MdiLayout value) {
  1032. if (mdi_container != null) {
  1033. mdi_container.LayoutMdi(value);
  1034. }
  1035. }
  1036. public void RemoveOwnedForm(Form ownedForm) {
  1037. owned_forms.Remove(ownedForm);
  1038. }
  1039. public void SetDesktopBounds(int x, int y, int width, int height) {
  1040. DesktopBounds = new Rectangle(x, y, width, height);
  1041. }
  1042. public void SetDesktopLocation(int x, int y) {
  1043. DesktopLocation = new Point(x, y);
  1044. }
  1045. public DialogResult ShowDialog() {
  1046. return ShowDialog(this.owner);
  1047. }
  1048. public DialogResult ShowDialog(IWin32Window ownerWin32) {
  1049. Rectangle area;
  1050. bool confined;
  1051. IntPtr capture_window;
  1052. owner = null;
  1053. if (ownerWin32 != null) {
  1054. Control c = Control.FromHandle (ownerWin32.Handle);
  1055. if (c != null)
  1056. owner = c.TopLevelControl as Form;
  1057. }
  1058. if (owner == this) {
  1059. throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
  1060. }
  1061. if (is_modal) {
  1062. throw new InvalidOperationException("The form is already displayed as a modal dialog.");
  1063. }
  1064. if (Visible) {
  1065. throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
  1066. }
  1067. if (!Enabled) {
  1068. throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
  1069. }
  1070. if (TopLevelControl != this) {
  1071. throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
  1072. }
  1073. #if broken
  1074. // Can't do this, will screw us in the modal loop
  1075. form_parent_window.Parent = this.owner;
  1076. #endif
  1077. // Release any captures
  1078. XplatUI.GrabInfo(out capture_window, out confined, out area);
  1079. if (capture_window != IntPtr.Zero) {
  1080. XplatUI.UngrabWindow(capture_window);
  1081. }
  1082. #if not
  1083. // Commented out; we instead let the Visible=true inside the runloop create the control
  1084. // otherwise setting DialogResult inside any of the events that are triggered by the
  1085. // create will not actually cause the form to not be displayed.
  1086. // Leaving this comment here in case there was an actual purpose to creating the control
  1087. // in here.
  1088. if (!IsHandleCreated) {
  1089. CreateControl();
  1090. }
  1091. #endif
  1092. Application.RunLoop(true, new ApplicationContext(this));
  1093. if (owner != null) {
  1094. // Cannot use Activate(), it has a check for the current active window...
  1095. XplatUI.Activate(owner.window.Handle);
  1096. }
  1097. if (DialogResult != DialogResult.None) {
  1098. return DialogResult;
  1099. }
  1100. DialogResult = DialogResult.Cancel;
  1101. return DialogResult.Cancel;
  1102. }
  1103. public override string ToString() {
  1104. return GetType().FullName.ToString() + ", Text: " + Text;
  1105. }
  1106. #endregion // Public Instance Methods
  1107. #region Protected Instance Methods
  1108. protected void ActivateMdiChild(Form form) {
  1109. if (!IsMdiContainer)
  1110. return;
  1111. mdi_container.ActivateChild (form);
  1112. OnMdiChildActivate(EventArgs.Empty);
  1113. }
  1114. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1115. protected override void AdjustFormScrollbars(bool displayScrollbars) {
  1116. base.AdjustFormScrollbars (displayScrollbars);
  1117. }
  1118. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1119. protected void ApplyAutoScaling()
  1120. {
  1121. SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
  1122. Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
  1123. float dx;
  1124. float dy;
  1125. if (current_size == autoscale_base_size)
  1126. return;
  1127. if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
  1128. return;
  1129. }
  1130. //
  1131. // I tried applying the Fudge height factor from:
  1132. // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
  1133. // but it makes things larger without looking better.
  1134. //
  1135. if (current_size_f.Width != AutoScaleBaseSize.Width) {
  1136. dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
  1137. } else {
  1138. dx = 1;
  1139. }
  1140. if (current_size_f.Height != AutoScaleBaseSize.Height) {
  1141. dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
  1142. } else {
  1143. dy = 1;
  1144. }
  1145. Scale (dx, dy);
  1146. AutoScaleBaseSize = current_size;
  1147. }
  1148. protected void CenterToParent() {
  1149. Control ctl;
  1150. int w;
  1151. int h;
  1152. if (Width > 0) {
  1153. w = Width;
  1154. } else {
  1155. w = DefaultSize.Width;
  1156. }
  1157. if (Height > 0) {
  1158. h = Height;
  1159. } else {
  1160. h = DefaultSize.Height;
  1161. }
  1162. ctl = null;
  1163. if (Parent != null) {
  1164. ctl = Parent;
  1165. } else if (owner != null) {
  1166. ctl = owner;
  1167. }
  1168. if (owner != null) {
  1169. this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
  1170. }
  1171. }
  1172. protected void CenterToScreen() {
  1173. Size DisplaySize;
  1174. int w;
  1175. int h;
  1176. if (Width > 0) {
  1177. w = Width;
  1178. } else {
  1179. w = DefaultSize.Width;
  1180. }
  1181. if (Height > 0) {
  1182. h = Height;
  1183. } else {
  1184. h = DefaultSize.Height;
  1185. }
  1186. XplatUI.GetDisplaySize(out DisplaySize);
  1187. this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
  1188. }
  1189. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1190. protected override Control.ControlCollection CreateControlsInstance() {
  1191. return base.CreateControlsInstance ();
  1192. }
  1193. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1194. protected override void CreateHandle() {
  1195. base.CreateHandle ();
  1196. Application.AddForm (this);
  1197. UpdateBounds();
  1198. if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
  1199. if (allow_transparency) {
  1200. XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
  1201. }
  1202. }
  1203. XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
  1204. if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
  1205. XplatUI.SetIcon(window.Handle, icon);
  1206. }
  1207. if ((owner != null) && (owner.IsHandleCreated)) {
  1208. XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
  1209. }
  1210. for (int i = 0; i < owned_forms.Count; i++) {
  1211. if (owned_forms[i].IsHandleCreated)
  1212. XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
  1213. }
  1214. if (window_manager != null && window_state != FormWindowState.Normal) {
  1215. window_manager.SetWindowState (FormWindowState.Normal, window_state);
  1216. }
  1217. }
  1218. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1219. protected override void DefWndProc(ref Message m) {
  1220. base.DefWndProc (ref m);
  1221. }
  1222. protected override void Dispose(bool disposing)
  1223. {
  1224. for (int i = 0; i < owned_forms.Count; i++)
  1225. ((Form)owned_forms[i]).Owner = null;
  1226. owned_forms.Clear ();
  1227. base.Dispose (disposing);
  1228. Application.RemoveForm (this);
  1229. }
  1230. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1231. protected virtual void OnActivated(EventArgs e)
  1232. {
  1233. if (is_loaded)
  1234. SelectActiveControl ();
  1235. EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
  1236. if (eh != null)
  1237. eh (this, e);
  1238. }
  1239. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1240. protected virtual void OnClosed(EventArgs e) {
  1241. EventHandler eh = (EventHandler)(Events [ClosedEvent]);
  1242. if (eh != null)
  1243. eh (this, e);
  1244. }
  1245. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1246. protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
  1247. CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
  1248. if (eh != null)
  1249. eh (this, e);
  1250. }
  1251. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1252. protected override void OnCreateControl() {
  1253. base.OnCreateControl ();
  1254. if (menu != null) {
  1255. XplatUI.SetMenu(window.Handle, menu);
  1256. }
  1257. OnLoad(EventArgs.Empty);
  1258. SelectActiveControl ();
  1259. // Send initial location
  1260. OnLocationChanged(EventArgs.Empty);
  1261. if (IsMdiContainer) {
  1262. mdi_container.LayoutMdi (MdiLayout.Cascade);
  1263. }
  1264. }
  1265. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1266. protected virtual void OnDeactivate(EventArgs e) {
  1267. EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
  1268. if (eh != null)
  1269. eh (this, e);
  1270. }
  1271. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1272. protected override void OnFontChanged(EventArgs e) {
  1273. base.OnFontChanged (e);
  1274. }
  1275. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1276. protected override void OnHandleCreated(EventArgs e) {
  1277. XplatUI.SetBorderStyle(window.Handle, form_border_style);
  1278. base.OnHandleCreated (e);
  1279. }
  1280. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1281. protected override void OnHandleDestroyed(EventArgs e) {
  1282. base.OnHandleDestroyed (e);
  1283. }
  1284. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1285. protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
  1286. InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
  1287. if (eh != null)
  1288. eh (this, e);
  1289. }
  1290. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1291. protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
  1292. InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
  1293. if (eh != null)
  1294. eh (this, e);
  1295. }
  1296. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1297. protected virtual void OnLoad(EventArgs e) {
  1298. if (AutoScale){
  1299. ApplyAutoScaling ();
  1300. AutoScale = false;
  1301. }
  1302. EventHandler eh = (EventHandler)(Events [LoadEvent]);
  1303. if (eh != null)
  1304. eh (this, e);
  1305. if (!IsMdiChild) {
  1306. switch (StartPosition) {
  1307. case FormStartPosition.CenterScreen:
  1308. this.CenterToScreen();
  1309. break;
  1310. case FormStartPosition.CenterParent:
  1311. this.CenterToParent ();
  1312. break;
  1313. case FormStartPosition.Manual:
  1314. Left = CreateParams.X;
  1315. Top = CreateParams.Y;
  1316. break;
  1317. }
  1318. }
  1319. is_loaded = true;
  1320. }
  1321. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1322. protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
  1323. EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
  1324. if (eh != null)
  1325. eh (this, e);
  1326. }
  1327. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1328. protected virtual void OnMaximumSizeChanged(EventArgs e) {
  1329. EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
  1330. if (eh != null)
  1331. eh (this, e);
  1332. }
  1333. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1334. protected virtual void OnMdiChildActivate(EventArgs e) {
  1335. EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
  1336. if (eh != null)
  1337. eh (this, e);
  1338. }
  1339. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1340. protected virtual void OnMenuComplete(EventArgs e) {
  1341. EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
  1342. if (eh != null)
  1343. eh (this, e);
  1344. }
  1345. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1346. protected virtual void OnMenuStart(EventArgs e) {
  1347. EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
  1348. if (eh != null)
  1349. eh (this, e);
  1350. }
  1351. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1352. protected virtual void OnMinimumSizeChanged(EventArgs e) {
  1353. EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
  1354. if (eh != null)
  1355. eh (this, e);
  1356. }
  1357. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1358. protected override void OnPaint (PaintEventArgs pevent) {
  1359. base.OnPaint (pevent);
  1360. }
  1361. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1362. protected override void OnResize(EventArgs e) {
  1363. base.OnResize(e);
  1364. if (this.IsMdiChild && ParentForm != null) {
  1365. ParentForm.PerformLayout();
  1366. ParentForm.Size = ParentForm.Size;
  1367. }
  1368. }
  1369. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1370. protected override void OnStyleChanged(EventArgs e) {
  1371. base.OnStyleChanged (e);
  1372. }
  1373. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1374. protected override void OnTextChanged(EventArgs e) {
  1375. base.OnTextChanged (e);
  1376. if (mdi_container != null)
  1377. mdi_container.SetParentText(true);
  1378. }
  1379. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1380. protected override void OnVisibleChanged(EventArgs e) {
  1381. base.OnVisibleChanged (e);
  1382. if (Visible) {
  1383. if (window_manager != null)
  1384. window_manager.SetWindowState (WindowState, WindowState);
  1385. }
  1386. }
  1387. protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
  1388. if (base.ProcessCmdKey (ref msg, keyData)) {
  1389. return true;
  1390. }
  1391. // Give our menu a shot
  1392. if (ActiveMenu != null) {
  1393. return ActiveMenu.ProcessCmdKey(ref msg, keyData);
  1394. }
  1395. return false;
  1396. }
  1397. // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
  1398. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1399. protected override bool ProcessDialogChar(char charCode) {
  1400. return base.ProcessDialogChar (charCode);
  1401. }
  1402. protected override bool ProcessDialogKey(Keys keyData) {
  1403. if ((keyData & Keys.Modifiers) == 0) {
  1404. if (keyData == Keys.Enter) {
  1405. IntPtr window = XplatUI.GetFocus ();
  1406. Control c = Control.FromHandle (window);
  1407. if (c is Button && c.FindForm () == this) {
  1408. ((Button)c).PerformClick ();
  1409. return true;
  1410. }
  1411. else if (accept_button != null) {
  1412. accept_button.PerformClick();
  1413. return true;
  1414. }
  1415. } else if (keyData == Keys.Escape && cancel_button != null) {
  1416. cancel_button.PerformClick();
  1417. return true;
  1418. }
  1419. }
  1420. return base.ProcessDialogKey(keyData);
  1421. }
  1422. protected override bool ProcessKeyPreview(ref Message msg) {
  1423. if (key_preview) {
  1424. if (ProcessKeyEventArgs(ref msg)) {
  1425. return true;
  1426. }
  1427. }
  1428. return base.ProcessKeyPreview (ref msg);
  1429. }
  1430. protected override bool ProcessTabKey(bool forward) {
  1431. return SelectNextControl(ActiveControl, forward, true, true, true);
  1432. }
  1433. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1434. protected override void ScaleCore(float dx, float dy) {
  1435. try {
  1436. SuspendLayout();
  1437. // We can't scale max or min windows
  1438. if (WindowState == FormWindowState.Normal) {
  1439. // We cannot call base since base also adjusts X/Y, but
  1440. // a form is toplevel and doesn't move
  1441. Size size;
  1442. size = ClientSize;
  1443. if (!GetStyle(ControlStyles.FixedWidth)) {
  1444. size.Width = (int)(size.Width * dx);
  1445. }
  1446. if (!GetStyle(ControlStyles.FixedHeight)) {
  1447. size.Height = (int)(size.Height * dy);
  1448. }
  1449. ClientSize = size;
  1450. }
  1451. /* Now scale our children */
  1452. Control [] controls = Controls.GetAllControls ();
  1453. for (int i=0; i < controls.Length; i++) {
  1454. controls[i].Scale(dx, dy);
  1455. }
  1456. }
  1457. finally {
  1458. ResumeLayout();
  1459. }
  1460. }
  1461. protected override void Select(bool directed, bool forward) {
  1462. Form parent;
  1463. if (directed) {
  1464. base.SelectNextControl(null, forward, true, true, true);
  1465. }
  1466. parent = this.ParentForm;
  1467. if (parent != null) {
  1468. parent.ActiveControl = this;
  1469. }
  1470. Activate();
  1471. }
  1472. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1473. protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  1474. base.SetBoundsCore (x, y, width, height, specified);
  1475. }
  1476. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1477. protected override void SetClientSizeCore(int x, int y) {
  1478. if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
  1479. x = minimum_size.Width;
  1480. } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
  1481. x = maximum_size.Width;
  1482. }
  1483. if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
  1484. y = minimum_size.Height;
  1485. } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
  1486. y = maximum_size.Height;
  1487. }
  1488. Rectangle ClientRect = new Rectangle(0, 0, x, y);
  1489. Rectangle WindowRect;
  1490. CreateParams cp = this.CreateParams;
  1491. clientsize_set = new Size(x, y);
  1492. if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
  1493. SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
  1494. }
  1495. }
  1496. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1497. protected override void SetVisibleCore(bool value) {
  1498. is_changing_visible_state = true;
  1499. has_been_visible = value || has_been_visible;
  1500. base.SetVisibleCore (value);
  1501. is_changing_visible_state = false;
  1502. }
  1503. protected override void UpdateDefaultButton() {
  1504. base.UpdateDefaultButton ();
  1505. }
  1506. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1507. protected override void WndProc(ref Message m) {
  1508. if (window_manager != null && window_manager.HandleMessage (ref m)) {
  1509. return;
  1510. }
  1511. switch((Msg)m.Msg) {
  1512. case Msg.WM_DESTROY: {
  1513. base.WndProc(ref m);
  1514. if (!RecreatingHandle) {
  1515. this.closing = true;
  1516. }
  1517. return;
  1518. }
  1519. case Msg.WM_CLOSE_INTERNAL: {
  1520. DestroyHandle();
  1521. break;
  1522. }
  1523. case Msg.WM_CLOSE: {
  1524. Form act = Form.ActiveForm;
  1525. if (act != null && act != this && act.Modal == true) {
  1526. return;
  1527. }
  1528. CancelEventArgs args = new CancelEventArgs ();
  1529. if (mdi_container != null) {
  1530. foreach (Form mdi_child in mdi_container.MdiChildren) {
  1531. mdi_child.OnClosing (args);
  1532. }
  1533. }
  1534. if (!is_modal) {
  1535. OnClosing (args);
  1536. if (!args.Cancel) {
  1537. OnClosed (EventArgs.Empty);
  1538. closing = true;
  1539. }
  1540. Dispose ();
  1541. } else {
  1542. OnClosing (args);
  1543. if (args.Cancel) {
  1544. DialogResult = DialogResult.None;
  1545. closing = false;
  1546. } else {
  1547. OnClosed (EventArgs.Empty);
  1548. closing = true;
  1549. Hide ();
  1550. }
  1551. }
  1552. return;
  1553. }
  1554. case Msg.WM_WINDOWPOSCHANGED: {
  1555. if (WindowState != FormWindowState.Minimized) {
  1556. base.WndProc(ref m);
  1557. }
  1558. return;
  1559. }
  1560. #if NET_2_0
  1561. case Msg.WM_SYSCOMMAND: {
  1562. // Let *Strips know the app's title bar was clicked
  1563. if (XplatUI.IsEnabled (Handle))
  1564. ToolStripManager.FireAppClicked ();
  1565. base.WndProc(ref m);
  1566. break;
  1567. }
  1568. #endif
  1569. case Msg.WM_ACTIVATE: {
  1570. if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
  1571. OnActivated(EventArgs.Empty);
  1572. } else {
  1573. OnDeactivate(EventArgs.Empty);
  1574. }
  1575. return;
  1576. }
  1577. case Msg.WM_KILLFOCUS: {
  1578. base.WndProc(ref m);
  1579. return;
  1580. }
  1581. case Msg.WM_SETFOCUS: {
  1582. if (ActiveControl != null && ActiveControl != this) {
  1583. ActiveControl.Focus();
  1584. return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
  1585. }
  1586. base.WndProc(ref m);
  1587. return;
  1588. }
  1589. // Menu drawing
  1590. case Msg.WM_NCLBUTTONDOWN: {
  1591. if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
  1592. ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
  1593. }
  1594. if (ActiveMaximizedMdiChild != null) {
  1595. if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
  1596. LowOrder ((int) m.LParam.ToInt32 ()),
  1597. HighOrder ((int) m.LParam.ToInt32 ()))) {
  1598. // Don't let base process this message, otherwise we won't
  1599. // get a WM_NCLBUTTONUP.
  1600. return;
  1601. }
  1602. }
  1603. base.WndProc(ref m);
  1604. return;
  1605. }
  1606. case Msg.WM_NCLBUTTONUP: {
  1607. if (ActiveMaximizedMdiChild != null) {
  1608. ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
  1609. LowOrder ((int)m.LParam.ToInt32 ()),
  1610. HighOrder ((int)m.LParam.ToInt32 ()));
  1611. }
  1612. base.WndProc (ref m);
  1613. return;
  1614. }
  1615. case Msg.WM_NCMOUSELEAVE: {
  1616. if (ActiveMaximizedMdiChild != null) {
  1617. ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
  1618. LowOrder((int)m.LParam.ToInt32()),
  1619. HighOrder((int)m.LParam.ToInt32()));
  1620. }
  1621. base.WndProc(ref m);
  1622. return;
  1623. }
  1624. case Msg.WM_NCMOUSEMOVE: {
  1625. if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
  1626. ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
  1627. }
  1628. if (ActiveMaximizedMdiChild != null) {
  1629. ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
  1630. LowOrder ((int)m.LParam.ToInt32 ()),
  1631. HighOrder ((int)m.LParam.ToInt32 ()));
  1632. }
  1633. base.WndProc(ref m);
  1634. return;
  1635. }
  1636. case Msg.WM_NCPAINT: {
  1637. if (ActiveMenu != null) {
  1638. PaintEventArgs pe;
  1639. Point pnt;
  1640. pe = XplatUI.PaintEventStart(Handle, false);
  1641. pnt = XplatUI.GetMenuOrigin(window.Handle);
  1642. // The entire menu has to be in the clip rectangle because the
  1643. // control buttons are right-aligned and otherwise they would
  1644. // stay painted when the window gets resized.
  1645. Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
  1646. clip = Rectangle.Union(clip, pe.ClipRectangle);
  1647. pe.SetClip(clip);
  1648. pe.Graphics.SetClip(clip);
  1649. ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
  1650. if (ActiveMaximizedMdiChild != null) {
  1651. ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
  1652. }
  1653. XplatUI.PaintEventEnd(Handle, false);
  1654. }
  1655. base.WndProc(ref m);
  1656. return;
  1657. }
  1658. case Msg.WM_NCCALCSIZE: {
  1659. XplatUIWin32.NCCALCSIZE_PARAMS ncp;
  1660. if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
  1661. ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
  1662. // Adjust for menu
  1663. ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
  1664. Marshal.StructureToPtr(ncp, m.LParam, true);
  1665. }
  1666. DefWndProc(ref m);
  1667. break;
  1668. }
  1669. case Msg.WM_MOUSEMOVE: {
  1670. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  1671. MouseEventArgs args;
  1672. args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1673. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
  1674. active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
  1675. break;
  1676. }
  1677. base.WndProc(ref m);
  1678. break;
  1679. }
  1680. case Msg.WM_LBUTTONDOWN:
  1681. case Msg.WM_MBUTTONDOWN:
  1682. case Msg.WM_RBUTTONDOWN: {
  1683. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  1684. MouseEventArgs args;
  1685. args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1686. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
  1687. active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
  1688. return;
  1689. }
  1690. base.WndProc(ref m);
  1691. return;
  1692. }
  1693. case Msg.WM_LBUTTONUP:
  1694. case Msg.WM_MBUTTONUP:
  1695. case Msg.WM_RBUTTONUP: {
  1696. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  1697. MouseEventArgs args;
  1698. MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
  1699. // We add in the button that was released (not sent in WParam)
  1700. switch((Msg)m.Msg) {
  1701. case Msg.WM_LBUTTONUP:
  1702. mb |= MouseButtons.Left;
  1703. break;
  1704. case Msg.WM_MBUTTONUP:
  1705. mb |= MouseButtons.Middle;
  1706. break;
  1707. case Msg.WM_RBUTTONUP:
  1708. mb |= MouseButtons.Right;
  1709. break;
  1710. }
  1711. args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
  1712. active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
  1713. mouse_clicks = 1;
  1714. return;
  1715. }
  1716. base.WndProc(ref m);
  1717. return;
  1718. }
  1719. case Msg.WM_GETMINMAXINFO: {
  1720. MINMAXINFO mmi;
  1721. if (m.LParam != IntPtr.Zero) {
  1722. mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
  1723. default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
  1724. if (maximized_bounds != Rectangle.Empty) {
  1725. mmi.ptMaxPosition.x = maximized_bounds.Left;
  1726. mmi.ptMaxPosition.y = maximized_bounds.Top;
  1727. mmi.ptMaxSize.x = maximized_bounds.Width;
  1728. mmi.ptMaxSize.y = maximized_bounds.Height;
  1729. }
  1730. if (minimum_size != Size.Empty) {
  1731. mmi.ptMinTrackSize.x = minimum_size.Width;
  1732. mmi.ptMinTrackSize.y = minimum_size.Height;
  1733. }
  1734. if (maximum_size != Size.Empty) {
  1735. mmi.ptMaxTrackSize.x = maximum_size.Width;
  1736. mmi.ptMaxTrackSize.y = maximum_size.Height;
  1737. }
  1738. Marshal.StructureToPtr(mmi, m.LParam, false);
  1739. }
  1740. break;
  1741. }
  1742. #if NET_2_0
  1743. case Msg.WM_MOUSEACTIVATE: {
  1744. // Let *Strips know the form or another control has been clicked
  1745. if (XplatUI.IsEnabled (Handle))
  1746. ToolStripManager.FireAppClicked ();
  1747. base.WndProc (ref m);
  1748. break;
  1749. }
  1750. case Msg.WM_ACTIVATEAPP: {
  1751. // Let *Strips know the app lost focus
  1752. if (m.WParam == (IntPtr)0)
  1753. if (XplatUI.IsEnabled (Handle))
  1754. ToolStripManager.FireAppFocusChanged (this);
  1755. base.WndProc (ref m);
  1756. break;
  1757. }
  1758. #endif
  1759. default: {
  1760. base.WndProc (ref m);
  1761. break;
  1762. }
  1763. }
  1764. }
  1765. #endregion // Protected Instance Methods
  1766. internal void RemoveWindowManager ()
  1767. {
  1768. window_manager = null;
  1769. }
  1770. internal override void CheckAcceptButton()
  1771. {
  1772. if (accept_button != null) {
  1773. Button a_button = accept_button as Button;
  1774. if (ActiveControl == a_button)
  1775. return;
  1776. if (ActiveControl is Button) {
  1777. a_button.paint_as_acceptbutton = false;
  1778. a_button.Redraw();
  1779. return;
  1780. } else {
  1781. a_button.paint_as_acceptbutton = true;
  1782. a_button.Redraw();
  1783. }
  1784. }
  1785. }
  1786. #region Events
  1787. static object ActivatedEvent = new object ();
  1788. static object ClosedEvent = new object ();
  1789. static object ClosingEvent = new object ();
  1790. static object DeactivateEvent = new object ();
  1791. static object InputLanguageChangedEvent = new object ();
  1792. static object InputLanguageChangingEvent = new object ();
  1793. static object LoadEvent = new object ();
  1794. static object MaximizedBoundsChangedEvent = new object ();
  1795. static object MaximumSizeChangedEvent = new object ();
  1796. static object MdiChildActivateEvent = new object ();
  1797. static object MenuCompleteEvent = new object ();
  1798. static object MenuStartEvent = new object ();
  1799. static object MinimumSizeChangedEvent = new object ();
  1800. public event EventHandler Activated {
  1801. add { Events.AddHandler (ActivatedEvent, value); }
  1802. remove { Events.RemoveHandler (ActivatedEvent, value); }
  1803. }
  1804. public event EventHandler Closed {
  1805. add { Events.AddHandler (ClosedEvent, value); }
  1806. remove { Events.RemoveHandler (ClosedEvent, value); }
  1807. }
  1808. public event CancelEventHandler Closing {
  1809. add { Events.AddHandler (ClosingEvent, value); }
  1810. remove { Events.RemoveHandler (ClosingEvent, value); }
  1811. }
  1812. public event EventHandler Deactivate {
  1813. add { Events.AddHandler (DeactivateEvent, value); }
  1814. remove { Events.RemoveHandler (DeactivateEvent, value); }
  1815. }
  1816. public event InputLanguageChangedEventHandler InputLanguageChanged {
  1817. add { Events.AddHandler (InputLanguageChangedEvent, value); }
  1818. remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
  1819. }
  1820. public event InputLanguageChangingEventHandler InputLanguageChanging {
  1821. add { Events.AddHandler (InputLanguageChangingEvent, value); }
  1822. remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
  1823. }
  1824. public event EventHandler Load {
  1825. add { Events.AddHandler (LoadEvent, value); }
  1826. remove { Events.RemoveHandler (LoadEvent, value); }
  1827. }
  1828. public event EventHandler MaximizedBoundsChanged {
  1829. add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
  1830. remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
  1831. }
  1832. public event EventHandler MaximumSizeChanged {
  1833. add { Events.AddHandler (MaximumSizeChangedEvent, value); }
  1834. remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
  1835. }
  1836. public event EventHandler MdiChildActivate {
  1837. add { Events.AddHandler (MdiChildActivateEvent, value); }
  1838. remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
  1839. }
  1840. public event EventHandler MenuComplete {
  1841. add { Events.AddHandler (MenuCompleteEvent, value); }
  1842. remove { Events.RemoveHandler (MenuCompleteEvent, value); }
  1843. }
  1844. public event EventHandler MenuStart {
  1845. add { Events.AddHandler (MenuStartEvent, value); }
  1846. remove { Events.RemoveHandler (MenuStartEvent, value); }
  1847. }
  1848. public event EventHandler MinimumSizeChanged {
  1849. add { Events.AddHandler (MinimumSizeChangedEvent, value); }
  1850. remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
  1851. }
  1852. [Browsable(false)]
  1853. [EditorBrowsable(EditorBrowsableState.Never)]
  1854. public new event EventHandler TabIndexChanged {
  1855. add { base.TabIndexChanged += value; }
  1856. remove { base.TabIndexChanged -= value; }
  1857. }
  1858. #endregion // Events
  1859. #if NET_2_0
  1860. public override string Text {
  1861. get {
  1862. return base.Text;
  1863. }
  1864. set {
  1865. base.Text = value;
  1866. }
  1867. }
  1868. public new Point Location {
  1869. get {
  1870. return base.Location;
  1871. }
  1872. set {
  1873. base.Location = value;
  1874. }
  1875. }
  1876. static object FormClosingEvent = new object ();
  1877. static object FormClosedEvent = new object ();
  1878. public event FormClosingEventHandler FormClosing {
  1879. add { Events.AddHandler (FormClosingEvent, value); }
  1880. remove { Events.RemoveHandler (FormClosingEvent, value); }
  1881. }
  1882. public event FormClosedEventHandler FormClosed {
  1883. add { Events.AddHandler (FormClosedEvent, value); }
  1884. remove { Events.RemoveHandler (FormClosedEvent, value); }
  1885. }
  1886. protected virtual void OnFormClosing (FormClosingEventArgs e)
  1887. {
  1888. FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);
  1889. if (eh != null)
  1890. eh (this, e);
  1891. }
  1892. #endif
  1893. }
  1894. }