2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_GTKUTIL_CURSOR_H )
23 #define INCLUDED_GTKUTIL_CURSOR_H
26 #include <uilib/uilib.h>
28 #include "debugging/debugging.h"
30 typedef struct _GdkCursor GdkCursor;
31 typedef struct _GdkEventMotion GdkEventMotion;
33 GdkCursor* create_blank_cursor();
34 void set_cursor( ui::Widget widget, GdkCursorType cursor_type );
35 void blank_cursor( ui::Widget widget );
36 void default_cursor( ui::Widget widget );
37 void Sys_GetCursorPos( ui::Widget widget, int *x, int *y );
38 void Sys_SetCursorPos( ui::Widget widget, int x, int y );
43 typedef void ( *MotionFunction )( gdouble x, gdouble y, guint state, void* data );
44 MotionFunction m_function;
50 static gboolean deferred( DeferredMotion* self ){
52 self->m_function( self->m_x, self->m_y, self->m_state, self->m_data );
56 DeferredMotion( MotionFunction function, void* data ) : m_handler( 0 ), m_function( function ), m_data( data ){
58 void motion( gdouble x, gdouble y, guint state ){
62 if ( m_handler == 0 ) {
63 m_handler = g_idle_add( (GSourceFunc)deferred, this );
66 static gboolean gtk_motion( ui::Widget widget, GdkEventMotion *event, DeferredMotion* self );
69 class DeferredMotionDelta
73 guint m_motion_handler;
74 typedef void ( *MotionDeltaFunction )( int x, int y, void* data );
75 MotionDeltaFunction m_function;
78 static gboolean deferred_motion( gpointer data ){
79 reinterpret_cast<DeferredMotionDelta*>( data )->m_function(
80 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_x,
81 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_y,
82 reinterpret_cast<DeferredMotionDelta*>( data )->m_data
84 reinterpret_cast<DeferredMotionDelta*>( data )->m_motion_handler = 0;
85 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_x = 0;
86 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_y = 0;
90 DeferredMotionDelta( MotionDeltaFunction function, void* data ) : m_delta_x( 0 ), m_delta_y( 0 ), m_motion_handler( 0 ), m_function( function ), m_data( data ){
93 if ( m_motion_handler != 0 ) {
94 g_source_remove( m_motion_handler );
95 deferred_motion( this );
98 void motion_delta( int x, int y, unsigned int state ){
101 if ( m_motion_handler == 0 ) {
102 m_motion_handler = g_idle_add( deferred_motion, this );
109 unsigned int handle_motion;
110 int recorded_x, recorded_y, last_x, last_y;
111 typedef void ( *MotionDeltaFunction )( int x, int y, unsigned int state, void* data );
112 MotionDeltaFunction m_function;
115 FreezePointer() : handle_motion( 0 ), m_function( 0 ), m_data( 0 ){
117 static gboolean motion_delta( ui::Widget widget, GdkEventMotion *event, FreezePointer* self );
119 void freeze_pointer( ui::Widget widget, MotionDeltaFunction function, void* data );
121 void unfreeze_pointer( ui::Widget widget );