[Gtk-sharp-list] Gdk.Key again

Charles Iliya Krempeaux charles@reptile.ca
18 Apr 2003 11:16:09 -0700


Hello,

OK, so what should we do about the Gdk.Key stuff.  On one hand, there
are a lot of entries there; and having an automated script generate
everything is desirable.

(One thing about the script though.  Currently, the script generates
the C# code.  I'd actually suggest that the script generate an
"api/???-api.xml" file instead.    Possibly even putting it in the
"gtk-api.xml" file.  There are facilities with in this file format
for enum's.  And this would fit in  better within the normal Gtk#
build process.)

Alternatively, since we do have the problem that any automated script
will likely not be able to generate CLS compliant code.  We may just
have to write our own Gdk.Key struct ourselves.  (And hope that the
GDK maintainers don't change any of the key codes.)

But anyways, as I mentioned in a previous e-mail, I suggest something
like this...

    public struct Key
    {
        private uint code;

        public Key(uint c)
        {
            this.code = c;
        }



        private static char[] char2key;
        static Key()
        {
            // Initialize "char2key" here with a table
            // that will convert a "char" to a "key" value.
        }



        static public bool operator == (Key left, char right)
        {
            return (left == char2key[right]);
        }

        static public bool operator != (Key left, char right)
        {
            return (left != char2key[right]);
        }

        static public bool operator == (char left, Key right)
        {
            return (char2key[left] == right);
        }

        static public bool operator != (char left, Key right)
        {
            return (char2key[left] != right);
        }



        static public readonly Key PageUp   = new Key(0xFF55);
        static public readonly Key PageDown = new Key(0xFF56);
        // Etc...

    } // struct Key

To make it so you can do stuff like...

    Key key;

    if ('a' == key) {
        // Do something.
    }

And for keys without a character representation (or for keys that
share character representations), you can do something like...

    Key key;

    if ('a' == Key.PageUp) {
        // Do something.
    }

If anyone thinks we should do something different, speak up please.
(Or else, I'll write it this way.)


See ya

-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting & Services    604-REPTILE    http://www.reptile.ca/