private void SolveWindowPosition(Gtk.Window parent) { int x, y, cw, ch, pw, ph, px, py; PositionMode wp = (ShellObject as Window).PositionMode; //if center parent and parent is null, center screen instead if (parent == null && wp == PositionMode.CenterParent) { wp = PositionMode.CenterScreen; } switch (wp) { case PositionMode.Manual: //HACK: we have to move the window to the position it already is for some stupid gtk-reason //an GetPosition doesnt work (in windows at least) int wx, wy, w, h, d; window.GdkWindow.GetGeometry(out wx, out wy, out w, out h, out d); Margin m = GetDecorationSize(); window.Move(wx - m.Left, wy - m.Top); return; //done already case PositionMode.CenterParent: parent.GetSize(out pw, out ph); parent.GetPosition(out px, out py); window.GetSize(out cw, out ch); var c = window.WindowPosition; x = px + pw / 2 - cw / 2; y = py + ph / 2 - ch / 2; window.Move(x, y); break; case PositionMode.CenterScreen: Gdk.Screen scr = window.Screen; // ?? Gdk.Screen.Default window.GetSize(out cw, out ch); x = scr.Width / 2 - cw / 2; y = scr.Height / 2 - ch / 2; window.Move(x, y); break; case PositionMode.MouseCursor: Gdk.Screen scr2 = window.Screen; scr2.Display.GetPointer(out x, out y); window.Move(x, y); break; default: throw new Exception("GtkSharp driver does not know how to position screen at " + wp.ToString()); } }
/// <summary> /// Writes the configuration file for this application. /// </summary> /// <param name="window"> /// A <see cref="Gtk.Window"/> that is the main application's window /// </param> /// <param name="cfgFileName"> /// A <see cref="System.String"/> containing the name of the config file. /// </param> /// <param name="recentFiles"> /// A <see cref="System.Array"/> containing the recently used files. /// The first one, lastFiles[ 0 ] is the last file used by the application. /// </param> public static void WriteConfiguration(Gtk.Window window, string cfgFileName, string[] recentFiles) { int width; int height; string lastFile = ""; StringBuilder recentFilesLine = null; // Prepare window size window.GetSize(out width, out height); // Prepare last file name. It is the first of the recent files. if (recentFiles.Length > 0) { lastFile = recentFiles[0]; } // Prepare last files - first one is the current open if (recentFiles.Length > 1) { recentFilesLine = new StringBuilder(); for (int i = 1; i < recentFiles.Length; ++i) { recentFilesLine.Append(recentFiles[i]); recentFilesLine.Append(','); } // Remove last ',' recentFilesLine.Remove(recentFilesLine.Length - 1, 1); } // Write configuration try { var file = new StreamWriter(cfgFileName); // Write window size file.WriteLine("{0}={1}", EtqWidth, width); file.WriteLine("{0}={1}", EtqHeight, height); // Write last file name if (lastFile.Length > 0) { file.WriteLine("{0}={1}", EtqLastFile, lastFile); } // Write list of recent files if (recentFilesLine != null) { file.WriteLine("{0}={1}", EtqRecent, recentFilesLine.ToString()); } file.WriteLine(); file.Close(); } catch (Exception exc) { Util.MsgError(window, window.Title, exc.Message); } return; }
internal ProgressIndicatorOverlay(Gtk.Window owner) : base(Gtk.WindowType.Toplevel) { this.TransientFor = owner; int width, height; this.Build(); owner.GetSize(out width, out height); this.Resize(width, height); this.Opacity = 0.25; }
/// <summary>Centers a window relative to its parent.</summary> static void CenterWindow(Window childControl, Window parentControl) { Gtk.Window child = childControl; Gtk.Window parent = parentControl; child.Child.Show(); int w, h, winw, winh, x, y, winx, winy; child.GetSize(out w, out h); parent.GetSize(out winw, out winh); parent.GetPosition(out winx, out winy); x = Math.Max(0, (winw - w) / 2) + winx; y = Math.Max(0, (winh - h) / 2) + winy; child.Move(x, y); }
/// <summary>Handler called when the window is resized.</summary> /// <remarks>Sets the new size in GConf if keys are present.</remarks> private void OnSizeAllocated (object o, Gtk.SizeAllocatedArgs args) { if (!HasGConfSize()) { return; } int width, height; window.GetSize(out width, out height); Config.Set(gconf_key_width, width); Config.Set(gconf_key_height, height); }
public void Save() { if (window == null || !window.Visible || !window.IsMapped || window.GdkWindow == null) { return; } maximized = (window.GdkWindow.State & Gdk.WindowState.Maximized) != 0; window.GetPosition(out x, out y); window.GetSize(out width, out height); if (timer_id == 0) { timer_id = GLib.Timeout.Add(250, OnTimeout); } else { pending_changes = true; } }
/// <summary>Centers a window relative to its parent.</summary> static void CenterWindow(Window childControl, Window parentControl) { // TODO: support cross-toolkit centering if (!(parentControl.nativeWidget is Gtk.Window)) { // FIXME: center on screen if no Gtk parent given for a Gtk dialog if (childControl.nativeWidget is Gtk.Window gtkChild) { gtkChild.WindowPosition = Gtk.WindowPosition.Center; } return; } Gtk.Window child = childControl; Gtk.Window parent = parentControl; child.Child.Show(); int w, h, winw, winh, x, y, winx, winy; child.GetSize(out w, out h); parent.GetSize(out winw, out winh); parent.GetPosition(out winx, out winy); x = Math.Max(0, (winw - w) / 2) + winx; y = Math.Max(0, (winh - h) / 2) + winy; child.Move(x, y); }
void HandleWindowStateEvent(object o, Gtk.WindowStateEventArgs args) { if (args.Event.ChangedMask == Gdk.WindowState.Maximized) { Gtk.Window wndMax = (Gtk.Window)o; Gdk.Rectangle displayRect = wndMax.GdkWindow.FrameExtents; wndMax.Hide(); if (displayRect.Width == 200) { int w, h; wndMax.GetSize(out w, out h); System.Threading.Thread.Sleep(0); Gtk.Application.RunIteration(); displayRect = wndMax.GdkWindow.FrameExtents; } Gdk.Rectangle windowRect = Screen.GetMonitorGeometry(Screen.GetMonitorAtPoint(wndMax.Allocation.X, wndMax.Allocation.Y)); if (displayRect.Width == 200) { displayRect.Location = Gdk.Point.Zero; displayRect.Width = windowRect.Width; displayRect.Height = windowRect.Height - 32; } int xLoc = windowRect.Right - BackgroundBitmap.Width - 1; int yLoc = windowRect.Bottom - BackgroundBitmap.Height - 1; if (displayRect.Right < windowRect.Right) { xLoc = displayRect.Right - BackgroundBitmap.Width - 1; } else if (displayRect.Left > windowRect.Left) { xLoc = displayRect.Left + 1; } if (displayRect.Top > windowRect.Top) { yLoc = displayRect.Top + 1; } else if (displayRect.Bottom < windowRect.Bottom) { yLoc = displayRect.Bottom - BackgroundBitmap.Height - 1; } switch (taskbarState) { case TaskbarStates.hidden: if (timer != 0) { GLib.Source.Remove(timer); timer = 0; } taskbarState = TaskbarStates.appearing; Opacity = 0; this.WidthRequest = BackgroundBitmap.Width; this.HeightRequest = BackgroundBitmap.Height; this.Move(xLoc, yLoc); timer = GLib.Timeout.Add(nShowEvents, OnTimer); ShowAll(); Refresh(true); break; case TaskbarStates.appearing: Refresh(true); break; case TaskbarStates.visible: if (timer != 0) { GLib.Source.Remove(timer); timer = 0; } if (nVisibleEvents > 0) { timer = GLib.Timeout.Add(nVisibleEvents, OnTimer); } Refresh(true); break; case TaskbarStates.disappearing: if (timer != 0) { GLib.Source.Remove(timer); timer = 0; } taskbarState = TaskbarStates.visible; Opacity = 1; this.WidthRequest = BackgroundBitmap.Width; this.HeightRequest = BackgroundBitmap.Height; this.Move(xLoc, yLoc); if (nVisibleEvents > 0) { timer = GLib.Timeout.Add(nVisibleEvents, OnTimer); } Refresh(true); break; } } }
/// <summary> /// Reads a configuration file for this application. /// </summary> /// <param name="window"> /// A <see cref="Gtk.Window"/> that is the main window of the application. /// </param> /// <param name="cfgFileName"> /// A <see cref="System.String"/> the name of the configuration file. /// </param> /// <returns> /// A <see cref="System.Array"/> with the list of recently used files. /// </returns> public static string[] ReadConfiguration(Gtk.Window window, string cfgFileName) { string lastFileName = ""; string[] recentFiles = new string[] {}; List <string> files = null; int width; int height; StreamReader file = null; string line; window.GetSize(out width, out height); try { try { file = new StreamReader(cfgFileName); } catch (Exception) { return(null); } line = file.ReadLine(); while (!file.EndOfStream) { if (line.ToLower().StartsWith(EtqLastFile, StringComparison.InvariantCulture)) { int pos = line.IndexOf('='); if (pos > 0) { lastFileName = line.Substring(pos + 1).Trim(); } } else if (line.ToLower().StartsWith(EtqWidth, StringComparison.InvariantCulture)) { int pos = line.IndexOf('='); if (pos > 0) { width = System.Convert.ToInt32(line.Substring(pos + 1).Trim()); } } else if (line.ToLower().StartsWith(EtqHeight, StringComparison.InvariantCulture)) { int pos = line.IndexOf('='); if (pos > 0) { height = System.Convert.ToInt32(line.Substring(pos + 1).Trim()); } } else if (line.ToLower().StartsWith(EtqRecent, StringComparison.InvariantCulture)) { int pos = line.IndexOf('='); if (pos > 0) { recentFiles = line.Substring(pos + 1).Split(','); } } line = file.ReadLine(); } file.Close(); // Now apply cfg ApplyNewSize(window, width, height); // Create list of recent files, plus the last file files = new List <string>(); files.Add(lastFileName); foreach (var f in recentFiles) { files.Add(f); } return(files.ToArray()); } catch (Exception exc) { Util.MsgError(window, window.Title, exc.Message); } return(null); }
/// <summary> /// Saves the specified window state. /// </summary> /// <param name="targetWindow">The target window.</param> private void Save(Window targetWindow) { targetWindow.GetSize(out width, out height); }