Ejemplo n.º 1
0
		// Works around BXC #3801 - Managed Container subclasses are incorrectly resurrected, then leak.
		// It does this by registering an alternative callback for gtksharp_container_override_forall, which
		// ignores callbacks if the wrapper no longer exists. This means that the objects no longer enter a
		// finalized->release->dispose->re-wrap resurrection cycle.
		// We use a dynamic method to access internal/private GTK# API in a performant way without having to track
		// per-instance delegates.
		public static void FixContainerLeak (Gtk.Container c)
		{
			if (containerLeakFixed) {
				return;
			}
			FixContainerLeak (c.GetType ());
		}
Ejemplo n.º 2
0
        internal static void RegisterActions(Gtk.Widget source, params Gtk.Action[] actions)
        {
            if(_actions == null)
                _actions = new Dictionary<ResourceManager, List<Gtk.Action>>();

            var sourceType = source.GetType();
            var baseName = string.Format("xCom.CamManager.Resources.{0}Strings", sourceType.Name);
            var rm = new ResourceManager(baseName, sourceType.Assembly);

            _actions.Add(rm, new List<Gtk.Action>(actions));
        }
Ejemplo n.º 3
0
        internal static void RegisterWidgets(Gtk.Widget source, params Gtk.Widget[] widgets)
        {
            if(_widgets == null)
                _widgets = new Dictionary<ResourceManager, List<Gtk.Widget>>();

            var sourceType = source.GetType();
            var baseName = string.Format("xCom.CamManager.Resources.{0}Strings", sourceType.Name);
            var rm = new ResourceManager(baseName, sourceType.Assembly);

            if(source is Gtk.Dialog)
            {
                if(widgets == null)
                    widgets = new Gtk.Widget[] { };

                var widgetsAsList = widgets.ToList();
                widgetsAsList.Add(source);
                widgets = widgetsAsList.ToArray();
            }

            _widgets.Add(rm, new List<Gtk.Widget>(widgets));
        }
Ejemplo n.º 4
0
        internal static void UpdateCulture(Gtk.Widget source)
        {
            if(_widgets == null)
                _widgets = new Dictionary<ResourceManager, List<Gtk.Widget>>();

            var sourceType = source.GetType();
            var baseName = string.Format("xCom.CamManager.Resources.{0}Strings", sourceType.Name);

            foreach(var kvp in _widgets)
            {
                if(string.Compare(kvp.Key.BaseName.ToUpper(), baseName.ToUpper()) == 0)
                {
                    kvp.Value.ForEach(x => x.Translate(kvp.Key));
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        public void AttachToWidget(Gtk.Widget widget)
        {
            if (widget == null)
                throw new ArgumentNullException ("widget");

            int x, y;
            widget.GdkWindow.GetOrigin (out x, out y);

            if (widget.GetType() != typeof (Gtk.Window) || ! widget.GetType().IsSubclassOf(typeof (Gtk.Window))) {
                x += widget.Allocation.X;
                y += widget.Allocation.Y;
            }

            x += widget.Allocation.Width / 2;
            y += widget.Allocation.Height / 2;

            SetGeometryHints (widget.Screen, x, y);
        }
Ejemplo n.º 6
0
        void SendKeyEvent(Gtk.Widget target, uint keyval, Gdk.ModifierType state, Gdk.EventType eventType, string subWindow)
        {
            Gdk.KeymapKey[] keyms = Gdk.Keymap.Default.GetEntriesForKeyval (keyval);
            if (keyms.Length == 0)
                throw new Exception ("Keyval not found");

            Gdk.Window win;
            if (subWindow == null)
                win = target.GdkWindow;
            else
                win = (Gdk.Window) GetValue (target, target.GetType (), subWindow);

            var nativeEvent = new NativeEventKeyStruct {
                type = eventType,
                send_event = 1,
                window = win.Handle,
                state = (uint)state,
                keyval = keyval,
                group = (byte)keyms [0].Group,
                hardware_keycode = (ushort)keyms [0].Keycode,
                length = 0,
                time = Gtk.Global.CurrentEventTime
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc (nativeEvent);
            try {
                Gdk.EventHelper.Put (new Gdk.EventKey (ptr));
            } finally {
                Marshal.FreeHGlobal (ptr);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Localizes the widget.
        /// </summary>
        /// <param name="widget">Widget.</param>
        public static void LocalizeWidget(Gtk.Widget widget)
        {
            if (widget.GetType() == typeof(Gtk.Label))
            {
                Gtk.Label label = (Gtk.Label)widget;
                label.Text = Localize(label.Text);
            }

            if (widget.GetType() == typeof(Gtk.CheckButton))
            {
                Gtk.CheckButton checkButton = (Gtk.CheckButton)widget;
                checkButton.Label = Localize(checkButton.Label);
            }
            LocalizeWChildrens(widget);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Localizes the W childrens.
        /// </summary>
        /// <param name="widget">Widget.</param>
        public static void LocalizeWChildrens(Gtk.Widget widget)
        {
            if (widget.GetType() == typeof(Gtk.VBox))
            {
                foreach (Gtk.Widget ch in ((Gtk.VBox)widget).Children)
                {
                    LocalizeWidget(ch);
                }
            }

            if (widget.GetType() == typeof(Gtk.HBox))
            {
                foreach (Gtk.Widget ch in ((Gtk.HBox)widget).Children)
                {
                    LocalizeWidget(ch);
                }
            }

            if (widget.GetType() == typeof(Gtk.Table))
            {
                foreach (Gtk.Widget ch in ((Gtk.Table)widget).Children)
                {
                    LocalizeWidget(ch);
                }
            }
        }
Ejemplo n.º 9
0
        public void AttachToWidget(Gtk.Widget widget)
        {
            int x, y;

            widget.GdkWindow.GetOrigin (out x, out y);

            if (widget.GetType() != typeof (Gtk.Window) || ! widget.GetType().IsSubclassOf(typeof (Gtk.Window))) {
                x += widget.Allocation.X;
                y += widget.Allocation.Y;
            }

            x += widget.Allocation.Width / 2;
            y += widget.Allocation.Height / 2;

            SetGeometryHints (widget.Screen, x, y);
            attach_widget = widget;
            status_icon = null;
        }
 // special case: no fmt string arguments
 public static string FormatLocalizedWithPrefix(this string key, Gtk.Bin o)
 {
     return (o.GetType().Namespace+"."+key).FormatLocalized();
 }
 public static string FormatLocalizedWithPrefix(this string key, Gtk.Bin o, params object[] args)
 {
     return (o.GetType().Namespace+"."+key).FormatLocalized(args);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Sets the given control's text property.
        /// </summary>
        /// <param name="control">Control to set</param>
        /// <param name="tip">ToolTip control</param>
        /// <history>
        /// [Curtis_Beard]		07/31/2006	Created
        /// [Curtis_Beard]		11/06/2006	CHG: Use Gtk controls
        /// </history>
        public static void SetControlText(Gtk.Widget control, Gtk.Tooltips tip)
        {
            if (__RootNode != null)
             {
            string formName = "";
            XmlNode node = __RootNode.SelectSingleNode("screen[@name='" + formName + "']");
            XmlNode controlNode;

            if (node != null)
            {
               //node found, find control
               controlNode = node.SelectSingleNode("control[@name='" + control.Name + "']");

               if (controlNode != null)
               {
                  //found control node
                  string value = controlNode.Attributes["value"].Value;

                  //text
                  if (control.GetType() == typeof(Gtk.Label))
                  {
                     ((Gtk.Label)control).Text = value;
                  }
                  else if (control.GetType() == typeof(Gtk.Button))
                  {
                     ((Gtk.Button)control).Label = value;
                  }
                  else if (control.GetType() == typeof(Gtk.CheckButton))
                  {
                     ((Gtk.CheckButton)control).Label = value;
                  }
                  else if (control.GetType() == typeof(Gtk.Frame))
                  {
                     ((Gtk.Frame)control).Label = value;
                  }

                  //tooltip
                  if (tip != null && controlNode.Attributes["tooltip"] != null)
                     tip.SetTip(control, controlNode.Attributes["tooltip"].Value, string.Empty);
               }
            }
             }
        }