1 #ifndef AS_MOVERESIZE_H_HEADER_FILE_INCLUDED
2 #define AS_MOVERESIZE_H_HEADER_FILE_INCLUDED
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 
9 /****h* libAfterWidget/moveresize.h
10  * SYNOPSIS
11  * Protocols for interactive widget movement/sizing.
12  * DESCRIPTION
13  * Initiating widget/app calls :
14  * 		move_widget_interactively() or resize_widget_interactively()
15  * Those functions initialize ASMoveResizeData, register event handler
16  * with main widget's event handler and return pointer to the data.
17  *
18  * When interactive event loop neds to chage placement of widget -
19  * it calls method stored in data.
20  *
21  * When interactive action is complete or cancelled - another method is
22  * called pointer to which is stored in data, then data and loop
23  * unregister self from the main even handler.
24  *
25  * AvoidCover algorithm:
26  * When we are resizing - everything is nice and simple. At most 2 sides
27  * are allowed to move at any time - for each we check if we reached any
28  * AvoidCover gridline  - and if yes - we stop, and also we check if we
29  * reached attracting distance of any other gridline, and if so  - we
30  * snap to it.
31  *
32  * When we are moving - things get complicated, since we actually need to
33  * move past AvoidCover windows if user insistently drags the mouse over
34  * it. We are looking for point with x*x+y*y < dX*dX+dY*dY in one of the
35  * 4 possible quadrants( depending on move direction ). Then we nee to
36  * find such point that has lesser (x-Px)*(x-Px)+(y-Py)*(y-Py) where
37  * Px,Py are current position of pointer. This point should also be placed
38  * so that all the gridlines with negative gravity are avoided.
39  *
40  * SEE ALSO
41  * Structures :
42  * Functions :
43  * Other libAfterWidget modules :
44  * AUTHOR
45  * Sasha Vasko <sasha at aftercode dot net>
46  ******
47  */
48 
49 struct ASEvent;
50 struct ASOutlineSegment;
51 struct ASMoveResizeData;
52 struct ASGrid;
53 struct ASHints;
54 struct ASStatusHints;
55 
56 typedef struct MRRectangle { int x, y, width, height ; } MRRectangle ;
57 
58 typedef	void (*as_interactive_pointer_handler)  (struct ASMoveResizeData *data, int x, int y);
59 typedef	void (*as_interactive_apply_handler)    (struct ASMoveResizeData *data);
60 typedef void (*as_interactive_subwindow_handler)(struct ASMoveResizeData *data, struct ASEvent *event);
61 typedef	void (*as_interactive_complete_handler) (struct ASMoveResizeData *data, Bool cancelled);
62 typedef int  (*as_outline_handler)              (struct ASOutlineSegment *s,
63 												 struct MRRectangle *geom,
64 												 unsigned int scr_width,
65 												 unsigned int scr_height);
66 
67 extern Bool (*_as_grab_screen_func)( struct ScreenInfo *scr, Cursor cursor );
68 extern void (*_as_ungrab_screen_func) ();
69 
70 typedef struct ASOutlineSegment
71 {
72 	Window w ;
73 	int x, y;
74 	int size ;
75 	Bool vertical ;
76 }ASOutlineSegment;
77 
78 typedef struct ASHintWindow
79 {
80 	Window           w;
81 	ASCanvas        *canvas ;
82 	ASTBarData      *bar ;
83 	struct ScreenInfo 	*scr;
84 	struct MyLook   *look ;
85 }ASHintWindow;
86 
87 ASHintWindow *create_ashint_window( ScreenInfo *scr, 	struct MyLook *look, const char *hint );
88 void destroy_ashint_window( ASHintWindow **hw );
89 void update_ashint_text( ASHintWindow *hw, const char *new_text );
90 void update_ashint_geometry( ASHintWindow *hw, Bool force_redraw );
91 
92 typedef struct ASMoveResizeData
93 {
94 	/* mandatrory things : */
95 	struct ASWidget *parent;
96 	struct ASWidget *mr;
97 	struct ASFeel   *feel ;
98 	struct MyLook   *look ;
99 	as_interactive_apply_handler    apply_func;
100 	as_interactive_complete_handler complete_func;
101 	/* what leg ... err, side are we pulling on ??? ( see FR_* values) */
102 	int side ;
103 
104 	/* Internally managed things : */
105 	as_interactive_pointer_handler  pointer_func;
106 
107 	MRRectangle curr, last, start;
108 	int 			 bw ; /* bloody border width */
109 
110 	char 	   	    *geometry_string;
111 	struct ASHintWindow *geometry_display;
112 
113 	/* ratios to be applied to geometry before displaying : */
114 	unsigned int     geom_x_mult, geom_x_div ;
115 	unsigned int     geom_y_mult, geom_y_div ;
116 	int              geom_x_origin, geom_y_origin ;
117 
118 	int 			 origin_x, origin_y ;       /* parent's window root
119 												* coordinates */
120 	int 			 last_x, last_y ;
121 	int 			 lag_x, lag_y ;
122 
123 	ASOutlineSegment *outline;
124 	unsigned int	 pointer_state ;
125 	Time			 pointer_grab_time;
126 	Window           curr_subwindow;
127 
128 	/* Optional things : */
129 	as_interactive_subwindow_handler subwindow_func;
130 	Window           below_sibling ;          /* outline will be placed
131 											   * just below this sibling */
132 	struct ASGrid   *grid ;
133 	/* optional size constraints : */
134 	unsigned int min_width,  width_inc,  max_width, frame_width;
135 	unsigned int min_height, height_inc, max_height, frame_height;
136 
137 	Bool stop_on_button_press; /* when true operation will complete on ButtonPress event - not on ButtonRelease */
138 	Bool move_only ;
139 
140 	int title_north, title_west ;
141 }ASMoveResizeData;
142 
143 ASOutlineSegment *make_outline_segments( struct ASWidget *parent, struct MyLook *look );
144 void move_outline( ASMoveResizeData * data );
145 void destroy_outline_segments( ASOutlineSegment **psegments );
146 
147 ASMoveResizeData *
148 move_widget_interactively(struct ASWidget *parent,
149 						  struct ASWidget *mr,
150 						  struct ASEvent *trigger,
151 						  as_interactive_apply_handler    apply_func,
152 						  as_interactive_complete_handler complete_func );
153 ASMoveResizeData*
154 resize_widget_interactively( struct ASWidget *parent,
155 							 struct ASWidget *mr,
156 							 struct ASEvent *trigger,
157 							 as_interactive_apply_handler    apply_func,
158 							 as_interactive_complete_handler complete_func,
159 							 int side );
160 void set_moveresize_restrains( ASMoveResizeData *data, struct ASHints *hints, struct ASStatusHints *status );
161 void set_moveresize_aspect( ASMoveResizeData *data, int x_mult, int x_div, int y_mult, int y_div, int x_origin, int y_origin );
162 
163 
164 
165 Bool check_moveresize_event( struct ASEvent *event );
166 void complete_interactive_action( ASMoveResizeData *data, Bool cancel );
167 
168 
169 void move_func (struct ASMoveResizeData *data, int x, int y);
170 void resize_func (struct ASMoveResizeData *data, int x, int y);
171 
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 
178 #endif
179