• LRN's avatar
    GDK W32: New cursor class · d8da6d38
    LRN authored
    Instead of now-unused GdkWin32Cursor class (a subclass of GdkCursor),
    add a stand-alone GdkWin32HCursor class that is a wrapper around
    HCURSOR handle.
    On creation it's given a display instance, a HCURSOR handle and a boolean
    that indicates whether the HCURSOR handle can or cannot be destroyed
    (this depends on how the handle was obtained).
    That information is stored in a hash table inside the GdkWin32Display
    singleton, each entry of that table has reference count.
    When the GdkWin32HCursor object is finalized, it reduces the reference
    count on the table entry in the GdkWin32Display. When it's created,
    it either adds such an entry or refs an existing one.
    This way two pieces of code (or the same piece of code called
    multiple times) that independently obtain the same HCURSOR from the OS
    will get to different GdkWin32HCursor instances, but GdkWin32Display
    will know that both use the same handle.
    Once the reference count reaches 0 on the table entry, it is freed
    and the handle (if destroyable) is put on the destruction list,
    and an idle destruction function is queued.
    If the same handle is once again registered for use before the
    idle destructior is invoked (this happens, for example, when
    an old cursor is destroyed and then replaced with a new one),
    the handle gets removed from the destruction list.
    The destructor just calls DestroyCursor() on each handle, calling
    SetCursor(NULL) before doing that when the handle is in use.
    This ensures that SetCursor(NULL) (which will cause cursor to disappear,
    which is bad by itself, and which will also cause flickering if the
    cursor is set to a non-NULL again shortly afterward)
    is almost never called, unless GTK messes up and keeps using a cursor
    beyond its lifetime.
    This scheme also ensures that non-destructable cursors are not destroyed.
    It's also possible to call _gdk_win32_display_hcursor_ref()
    and _gdk_win32_display_hcursor_unref() manually instead of creating
    GdkWin32HCursor objects, but that is not recommended.