Example #1
0
        /* ~Ihandle()
         * {
         *   Dispose(false);
         * }*/

        public static IntPtr GetCHandle(IupHandle from)
        {
            if (from == null)
            {
                return(IntPtr.Zero);
            }
            return(from.Handle);
        }
Example #2
0
        public static IupHandle Canvas(string action = null)
        {
            IupHandle res = IupHandle.Create(NativeIUPGL.IupGLCanvas(action));

            if (res == null)
            {
                throw new Exception("Failed to create OpenGL canvas, was IupGL Open():ed correctly?");
            }
            return(res);
        }
Example #3
0
        public override bool Equals(object obj)
        {
            IupHandle h = obj as IupHandle;

            if (h != null)
            {
                return(Handle.Equals(h.Handle));
            }
            else
            {
                return(base.Equals(obj));
            }
        }
Example #4
0
        public IntPtr MarshalManagedToNative(object managedObj)
        {
            if (managedObj == null)
            {
                return(IntPtr.Zero);
            }

            IupHandle ih = managedObj as IupHandle;

            if (ih == null)
            {
                throw new ArgumentException("managedObj", "Can only marshal type of Tecgraf.IupHandle");
            }

            return(IupHandle.GetCHandle(ih));
        }
Example #5
0
        public string[] GetAllAttributes(IupHandle ih)
        {
            IntPtr zero      = IntPtr.Zero;
            int    numattrib = NativeIUP.IupGetAllAttributes(Handle, ref zero, 0);

            IntPtr[] atts = new IntPtr[numattrib];

            if (numattrib == 0)
            {
                return(new string[0]);
            }
            numattrib = NativeIUP.IupGetAllAttributes(Handle, ref atts[0], numattrib);
            string[] res = new string[numattrib];

            for (int l = 0; l < atts.Length; l++)
            {
                res[l] = UTF8ToStr(atts[l]);
            }

            return(res);
        }
Example #6
0
        /// <summary>
        /// Shows a text input dialog to the user. Maximum length of entered text is 10000 characters.
        /// </summary>
        /// <param name="title">Text in the dialogs title bar.</param>
        /// <param name="text">The initial text of dialog. Can be null for empty string.</param>
        /// <returns>True if successful or false on cancel.</returns>
        public static bool GetText(string title, ref string text)
        {
            IntPtr cstring = IntPtr.Zero;

            try
            {
                // According to manual 10240 characters maximum+2 extra for zero term safety etc.
                cstring = Marshal.AllocHGlobal(10242);

                int cnt = 0;
                if (text != null)
                {
                    byte[] utfcode = Encoding.UTF8.GetBytes(text);

                    if (utfcode.Length > 10240)
                    {
                        Array.Resize <byte>(ref utfcode, 10240);
                    }

                    cnt = utfcode.Length;
                    Marshal.Copy(utfcode, 0, cstring, cnt);
                }

                Marshal.WriteByte(cstring, cnt, 0);

                if (NativeIUP.IupGetText(title, cstring) != 0)
                {
                    text = IupHandle.UTF8ToStr(cstring);
                    return(true);
                }

                return(false);
            }
            finally {
                if (cstring != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(cstring);
                }
            }
        }
Example #7
0
        private void RecursiveUnmapCallbacks(IupHandle Handle)
        {
            if (Handle == null)
            {
                return;
            }
            IupHandle ih = Handle;

            int ch = ih.GetChildCount();

            for (int ci = 0; ci < ch; ci++)
            {
                RecursiveUnmapCallbacks(ih.GetChild(ci));
            }



            if (CallbackMap.ContainsKey(Handle.Handle))
            {
                CallbackMap.Remove(Handle.Handle);
            }
        }
Example #8
0
        public static IupHandle ImageFromResource(Assembly asm, string resname)
        {
            //try to get resource with the actual name
            Stream stream = asm.GetManifestResourceStream(resname);

            if (stream == null)
            {
                //get resource with some random namspace ending with the given name
                //this is good for Visual Studio express users, where resources are auto prefixed
                string upname = "." + resname.ToUpperInvariant();
                foreach (string s in asm.GetManifestResourceNames())
                {
                    if (s.ToUpper().EndsWith(upname))
                    {
                        stream = asm.GetManifestResourceStream(s);
                    }
                }
            }

            if (stream == null)
            {
                throw new Exception("Resource " + resname + " not found in assembly " + asm.ToString());
            }

            IupHandle res = null;

            try
            {
                res = ImageFromStream(stream);
            }
            finally
            {
                stream.Close();
            }

            return(res);
        }
Example #9
0
        private static IntPtr[] PtrArrayOf(params IupHandle[] h)
        {
            if (h == null)
            {
                return(null);
            }

            IntPtr[] res = new IntPtr[h.Length + 1];  //one extra element for zero termination
            int      c   = 0;

            foreach (IupHandle ih in h)
            {
                if (ih != null)
                {
                    res[c++] = IupHandle.GetCHandle(ih);
                }
                else
                {
                    res[c++] = IntPtr.Zero;
                }
            }
            res[c] = IntPtr.Zero; //zero terminate array
            return(res);
        }
Example #10
0
 public static IupHandle LayoutDialog(IupHandle dialog)
 {
     return(IupHandle.Create(NativeIUP.IupLayoutDialog(IupHandle.GetCHandle(dialog))));
 }
Example #11
0
 public static IupHandle Val(bool horizontal)
 {
     return(IupHandle.Create(NativeIUP.IupVal(horizontal ? "HORIZONTAL" : "VERTICAL")));
 }
Example #12
0
 public static IupHandle IupProgressDlg()
 {
     return(IupHandle.Create(NativeIUP.IupProgressDlg()));
 }
Example #13
0
 public static IupHandle FontDlg()
 {
     return(IupHandle.Create(NativeIUP.IupFontDlg()));
 }
Example #14
0
 public static IupHandle Link(string url, string title)
 {
     return(IupHandle.Create(NativeIUP.IupLink(url, title)));
 }
Example #15
0
 public static IupHandle Toggle(string title, string action = null)
 {
     return(IupHandle.Create(NativeIUP.IupToggle(title, action)));
 }
Example #16
0
 internal static string UTF8ToStr(IntPtr ptr)
 {
     //Just a shortcut!
     return(IupHandle.UTF8ToStr(ptr));
 }
Example #17
0
 public static int TreeGetId(IupHandle ih_tree, IntPtr userid)
 {
     return(NativeIUP.IupTreeGetId(IupHandle.GetCHandle(ih_tree), userid));
 }
Example #18
0
 public static IupHandle Tabs(params IupHandle[] children)
 {
     return(IupHandle.Create(NativeIUP.IupTabsv(PtrArrayOf(children))));
 }
Example #19
0
 public static bool TreeSetUserId(IupHandle ih_tree, int id, IntPtr userid)
 {
     return(NativeIUP.IupTreeSetUserId(IupHandle.GetCHandle(ih_tree), id, userid) != 0);
 }
Example #20
0
 public static int ConvertXYToPos(IupHandle ih, int x, int y)
 {
     return(NativeIUP.IupConvertXYToPos(IupHandle.GetCHandle(ih), x, y));
 }
Example #21
0
 public static void TextConvertPosToLinCol(IupHandle ih, int pos, out int lin, out int col)
 {
     NativeIUP.IupTextConvertPosToLinCol(IupHandle.GetCHandle(ih), pos, out lin, out col);
 }
Example #22
0
 public static void TextConvertLinColToPos(IupHandle ih, int lin, int col, out int pos)
 {
     NativeIUP.IupTextConvertLinColToPos(IupHandle.GetCHandle(ih), lin, col, out pos);
 }
Example #23
0
 public static bool SaveImageAsText(IupHandle ih, string filename, SaveImageFormat format, string name)
 {
     return(NativeIUP.IupSaveImageAsText(IupHandle.GetCHandle(ih), filename, format.ToString().ToUpper(), name) != 0);
 }
Example #24
0
 public static IupHandle ElementPropertiesDialog(IupHandle element)
 {
     return(IupHandle.Create(NativeIUP.IupElementPropertiesDialog(IupHandle.GetCHandle(element))));
 }
Example #25
0
 public static void TreeSetAttributeHandle(IupHandle ih, string name, int id, IupHandle ih_named)
 {
     NativeIUP.IupTreeSetAttributeHandle(IupHandle.GetCHandle(ih), name, id, IupHandle.GetCHandle(ih_named));
 }
Example #26
0
 public static IupHandle MessageDlg()
 {
     return(IupHandle.Create(NativeIUP.IupMessageDlg()));
 }
Example #27
0
 public static IupHandle Clipboard()
 {
     return(IupHandle.Create(NativeIUP.IupClipboard()));
 }
Example #28
0
 public static IupHandle ColorDlg()
 {
     return(IupHandle.Create(NativeIUP.IupColorDlg()));
 }
Example #29
0
 public static IntPtr TreeGetUserId(IupHandle ih_tree, int id)
 {
     return(NativeIUP.IupTreeGetUserId(IupHandle.GetCHandle(ih_tree), id));
 }
Example #30
0
 public static IupHandle Tree()
 {
     return(IupHandle.Create(NativeIUP.IupTree()));
 }