1 /* $OpenBSD: wsmoused.h,v 1.7 2006/12/02 18:16:14 miod Exp $ */
2 
3 /*
4  * Copyright (c) 2001 Jean-Baptiste Marchand, Julien Montagne and Jerome Verdon
5  *
6  * All rights reserved.
7  *
8  * This code is for mouse console support under the wscons console driver.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by
21  *	Hellmuth Michaelis, Brian Dunford-Shore, Joerg Wunsch, Scott Turner
22  *	and Charles Hannum.
23  * 4. The name authors may not be used to endorse or promote products
24  *    derived from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
27  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  *
38  */
39 
40 struct wsdisplay_softc;
41 
42 int wsmoused(struct wsdisplay_softc *, u_long, caddr_t, int,
43 		  struct proc *p);
44 
45 void motion_event(u_int, int);
46 void button_event(int, int);
47 int ctrl_event(u_int, int, struct wsdisplay_softc *, struct proc *);
48 
49 void mouse_moverel(char, char);
50 
51 void inverse_char(unsigned short c);
52 void inverse_region(unsigned short start, unsigned short end);
53 
54 unsigned char skip_spc_right(char);
55 unsigned char skip_spc_left(void);
56 unsigned char skip_char_right(unsigned short);
57 unsigned char skip_char_left(unsigned short);
58 unsigned char class_cmp(unsigned short, unsigned short);
59 
60 void mouse_copy_start(void);
61 void mouse_copy_word(void);
62 void mouse_copy_line(void);
63 void mouse_copy_end(void);
64 void mouse_copy_extend(void);
65 void mouse_copy_extend_char(void);
66 void mouse_copy_extend_word(void);
67 void mouse_copy_extend_line(void);
68 void mouse_hide(struct wsdisplay_softc *);
69 void mouse_copy_extend_after(void);
70 void remove_selection(struct wsdisplay_softc *);
71 void mouse_copy_selection(void);
72 void mouse_paste(void);
73 
74 void mouse_zaxis(int);
75 void allocate_copybuffer(struct wsdisplay_softc *);
76 void mouse_remove(struct wsdisplay_softc *);
77 void wsmoused_release(struct wsdisplay_softc *);
78 void wsmoused_wakeup(struct wsdisplay_softc *);
79 
80 extern char *Copybuffer; /* buffer that contains mouse selections */
81 extern u_int Copybuffer_size;
82 extern char Paste_avail; /* flag, to indicate whether a selection is in the
83 			 Copy buffer */
84 
85 #define NO_BORDER 0
86 #define BORDER 1
87 
88 #define WS_NCOLS(ws) ((ws)->scr_dconf->scrdata->ncols)
89 #define WS_NROWS(ws) ((ws)->scr_dconf->scrdata->nrows)
90 
91 #define MAXCOL (WS_NCOLS(sc->sc_focus) - 1)
92 #define MAXROW (WS_NROWS(sc->sc_focus) - 1)
93 
94 #define N_COLS 		(WS_NCOLS(sc->sc_focus))
95 #define N_ROWS 		(WS_NROWS(sc->sc_focus))
96 #define MOUSE 		(sc->sc_focus->mouse)
97 #define CURSOR 		(sc->sc_focus->cursor)
98 #define CPY_START	(sc->sc_focus->cpy_start)
99 #define CPY_END		(sc->sc_focus->cpy_end)
100 #define ORIG_START	(sc->sc_focus->orig_start)
101 #define ORIG_END	(sc->sc_focus->orig_end)
102 #define MOUSE_FLAGS	(sc->sc_focus->mouse_flags)
103 
104 #define XY_TO_POS(col, row) (((row) * N_COLS) + (col))
105 #define POS_TO_X(pos) ((pos) % (N_COLS))
106 #define POS_TO_Y(pos) ((pos) / (N_COLS))
107 
108 /* Shortcuts to the various display operations */
109 #define	GETCHAR(pos, cellp) \
110 	((*sc->sc_accessops->getchar) \
111 	    (sc->sc_accesscookie, (pos) / N_COLS, (pos) % N_COLS, cellp))
112 #define PUTCHAR(pos, uc, attr) \
113 	((*sc->sc_focus->scr_dconf->emulops->putchar) \
114 	    (sc->sc_focus->scr_dconf->emulcookie, ((pos) / N_COLS), \
115 	    ((pos) % N_COLS), (uc), (attr)))
116 
117 #define MOUSE_COPY_BUTTON 	0
118 #define MOUSE_PASTE_BUTTON 	1
119 #define MOUSE_EXTEND_BUTTON	2
120 
121 #define IS_ALPHANUM(c) ((c) != ' ')
122 #define IS_SPACE(c) ((c) == ' ')
123