~ubuntu-branches/ubuntu/raring/vice/raring

1.1.1 by Zed Pobre
Import upstream version 1.14
1
/*
2
 * mousedrv.c - Mouse handling for OS/2
3
 *
4
 * Written by
5
 *  Thomas Bretz <tbretz@uni-sw.gwdg.de>
6
 *
7
 * This file is part of VICE, the Versatile Commodore Emulator.
8
 * See README for copyright notice.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  (at your option) any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program; if not, write to the Free Software
22
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
 *
24
 */
25
1.1.5 by Laszlo Boszormenyi (GCS)
Import upstream version 1.22
26
#include "vice.h"
27
1.1.1 by Zed Pobre
Import upstream version 1.14
28
#define INCL_WININPUT
29
#define INCL_WINPOINTERS
30
31
#include "mouse.h"
32
#include "mousedrv.h"
33
#include "fullscr.h"
34
#include "cmdline.h"
35
#include "resources.h"
1.2.2 by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg
36
#include "translate.h"
1.1.1 by Zed Pobre
Import upstream version 1.14
37
38
static int hide_mouseptr;
39
static int visible=TRUE;
40
static SHORT _mouse_x, _mouse_y; // [-32768, 32768]
41
42
/* ----------------------------------------------------------- */
43
44
void mousedrv_mouse_changed(void)
45
{
1.1.2 by Zed Pobre
Import upstream version 1.16
46
    /* -- FIXME: rash while startup --
47
     mouse_button_left(0);
48
     mouse_button_right(0);
49
     */
1.1.1 by Zed Pobre
Import upstream version 1.14
50
}
51
1.1.5 by Laszlo Boszormenyi (GCS)
Import upstream version 1.22
52
static int set_hide_mouseptr(int val, void *param)
1.1.1 by Zed Pobre
Import upstream version 1.14
53
{
1.1.5 by Laszlo Boszormenyi (GCS)
Import upstream version 1.22
54
    hide_mouseptr = val;
55
1.1.1 by Zed Pobre
Import upstream version 1.14
56
    if (!hide_mouseptr && !visible && !FullscreenIsNow())
57
    { // do we have to show the ptr again?
58
        WinSetCapture(HWND_DESKTOP, NULLHANDLE);
59
        WinShowPointer(HWND_DESKTOP, TRUE);
60
        visible=TRUE;
61
    }
62
    return 0;
63
}
64
1.1.5 by Laszlo Boszormenyi (GCS)
Import upstream version 1.22
65
static const resource_int_t resources_int[] = {
66
    { "HideMousePtr", 0, RES_EVENT_NO, NULL,
67
      &hide_mouseptr, set_hide_mouseptr, NULL },
1.1.1 by Zed Pobre
Import upstream version 1.14
68
    { NULL }
69
};
70
71
int mousedrv_resources_init(void)
72
{
1.1.5 by Laszlo Boszormenyi (GCS)
Import upstream version 1.22
73
    return resources_register_int(resources_int);
1.1.1 by Zed Pobre
Import upstream version 1.14
74
}
75
76
/* ----------------------------------------------------------- */
77
78
static const cmdline_option_t cmdline_options[] = {
1.2.2 by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg
79
    { "-hidemouseptr", SET_RESOURCE, 0,
80
      NULL, NULL, "HideMousePtr", (resource_value_t) 1,
81
      USE_PARAM_STRING, USE_DESCRIPTION_ID,
82
      IDCLS_UNUSED, IDCLS_UNUSED,
83
      NULL, "Enable hiding of mouse pointer inside the window" },
84
    { "+hidemouseptr", SET_RESOURCE, 0,
85
      NULL, NULL, "HideMousePtr", (resource_value_t) 0,
86
      USE_PARAM_STRING, USE_DESCRIPTION_ID,
87
      IDCLS_UNUSED, IDCLS_UNUSED,
88
      NULL, "Disable hiding of mouse pointer inside the window" },
1.1.1 by Zed Pobre
Import upstream version 1.14
89
    { NULL }
90
};
91
92
int mousedrv_cmdline_options_init(void)
93
{
94
    return cmdline_register_options(cmdline_options);
95
}
96
97
void mousedrv_init(void)
98
{
99
}
100
101
const int mouse_step = 15;
102
103
extern int stretch;  // video.c
104
105
inline BYTE mousedrv_get_x(void)
106
{
107
    static SHORT last_mouse_x=0;
108
109
    const SHORT diff = last_mouse_x - _mouse_x;
110
111
    /*
112
     * The problem is that if you click somewhere and your pointer
113
     * is outside the window you would click something at the desktop
114
     *
115
     * POINTL ptl;
116
     * APIRET rc=WinQueryPointerPos(HWND_DESKTOP, &ptl);
117
     * _mouse_x = ptl.x;
118
     *
119
     */
120
121
    if (diff > mouse_step)
122
        last_mouse_x -= mouse_step;
123
    else
124
        if(diff < -mouse_step)
125
            last_mouse_x += mouse_step;
126
        else
127
            last_mouse_x = _mouse_x;
128
129
    return ((last_mouse_x/stretch)
130
#ifndef __XVIC_
131
             <<1
132
#endif
133
            )&0x7e;
134
}
135
136
inline BYTE mousedrv_get_y(void)
137
{
138
    static SHORT last_mouse_y=0;
139
140
    const SHORT diff = last_mouse_y - _mouse_y;
141
142
    /*
143
     * The problem is that if you click somewhere and your pointer
144
     * is outside the window you would click something at the desktop
145
     *
146
     * POINTL ptl;
147
     * APIRET rc=WinQueryPointerPos(HWND_DESKTOP, &ptl);
148
     * _mouse_y = ptl.y;
149
     *
150
     */
151
152
    if (diff > mouse_step)
153
        last_mouse_y -= mouse_step;
154
    else
155
        if(diff < -mouse_step)
156
            last_mouse_y += mouse_step;
157
        else
158
            last_mouse_y = _mouse_y;
159
160
    return ((last_mouse_y/stretch)<<1)&0x7e;
161
}
162
163
/* ----------------- OS/2 specific ------------------------- */
164
165
void mouse_button(HWND hwnd, ULONG msg, MPARAM mp1)
166
{
167
    if (!_mouse_enabled)
168
        return;
169
170
    switch (msg)
171
    {
172
    case WM_MOUSEMOVE:
173
        _mouse_x = SHORT1FROMMP(mp1);
174
        _mouse_y = SHORT2FROMMP(mp1);
175
        {
176
            SWP swp;
177
            WinQueryWindowPos(hwnd, &swp);
178
            //
179
            // check whether the pointer is outside or inside the window
180
            //
181
182
            if (FullscreenIsNow())
183
                visible=TRUE;
184
185
            if (_mouse_x>=0 && _mouse_x<swp.cx &&
186
                _mouse_y>=0 && _mouse_y<swp.cy)
187
            {
188
                //
189
                // FIXME: Don't capture the mouse pointer if it is in front
190
                // of a client dialog!
191
                //
192
                if (WinQueryCapture(HWND_DESKTOP)!=hwnd && hide_mouseptr && !FullscreenIsNow())
193
                    WinSetCapture(HWND_DESKTOP, hwnd);
194
195
                if (visible && /*_mouse_enabled &&*/ hide_mouseptr &&
196
                    !FullscreenIsNow())
197
                {
198
                    WinShowPointer(HWND_DESKTOP, FALSE);
199
                    visible=FALSE;
200
                }
201
            }
202
            else
203
            {
204
                if (WinQueryCapture(HWND_DESKTOP)==hwnd && !FullscreenIsNow())
205
                    WinSetCapture(HWND_DESKTOP, NULLHANDLE);
206
207
                if (!visible && !FullscreenIsNow())
208
                {
209
                    WinShowPointer(HWND_DESKTOP, TRUE);
210
                    visible=TRUE;
211
                }
212
213
                //
214
                // don't use 'outside'-values which appears one times
215
                // if the mouse pointer leaves the window
216
                //
217
                if (_mouse_x<0) _mouse_x=0;
218
                else
219
                    if (_mouse_x>=swp.cx)
220
                        _mouse_x=swp.cx-1;
221
222
                if (_mouse_y<0) _mouse_y=0;
223
                else
224
                    if (_mouse_y>=swp.cy)
225
                        _mouse_y=swp.cy-1;
226
            }
227
        }
228
        return;
229
    case WM_BUTTON1DOWN:
230
        mouse_button_left(1);
231
        return;
232
    case WM_BUTTON1UP:
233
        mouse_button_left(0);
234
        return;
235
    case WM_BUTTON2DOWN:
236
        mouse_button_right(1);
237
        return;
238
    case WM_BUTTON2UP:
239
        mouse_button_right(0);
240
        return;
241
    }
242
}
243