~ubuntu-branches/ubuntu/quantal/vice/quantal

« back to all changes in this revision

Viewing changes to src/arch/os2/mousedrv.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-03-27 13:06:04 UTC
  • mfrom: (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050327130604-zodmv0i60dbbmcik
Tags: 1.16-3
Apply patch from Andreas Jochens <aj@andaco.de> to correct building on
AMD64 and GCC 4.x (closes: #300936)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
26
#define INCL_WININPUT
 
27
#define INCL_WINPOINTERS
 
28
 
 
29
#include "mouse.h"
 
30
#include "mousedrv.h"
 
31
#include "fullscr.h"
 
32
#include "cmdline.h"
 
33
#include "resources.h"
 
34
 
 
35
 
 
36
static int hide_mouseptr;
 
37
static int visible=TRUE;
 
38
static SHORT _mouse_x, _mouse_y; // [-32768, 32768]
 
39
 
 
40
/* ----------------------------------------------------------- */
 
41
 
 
42
void mousedrv_mouse_changed(void)
 
43
{
 
44
    /* -- FIXME: rash while startup --
 
45
     mouse_button_left(0);
 
46
     mouse_button_right(0);
 
47
     */
 
48
}
 
49
 
 
50
static int set_hide_mouseptr(resource_value_t v, void *param)
 
51
{
 
52
    hide_mouseptr = (int) v;
 
53
    if (!hide_mouseptr && !visible && !FullscreenIsNow())
 
54
    { // do we have to show the ptr again?
 
55
        WinSetCapture(HWND_DESKTOP, NULLHANDLE);
 
56
        WinShowPointer(HWND_DESKTOP, TRUE);
 
57
        visible=TRUE;
 
58
    }
 
59
    return 0;
 
60
}
 
61
 
 
62
static const resource_t resources[] = {
 
63
    { "HideMousePtr", RES_INTEGER, (resource_value_t)0,
 
64
      (void *)&hide_mouseptr, set_hide_mouseptr, NULL },
 
65
    { NULL }
 
66
};
 
67
 
 
68
int mousedrv_resources_init(void)
 
69
{
 
70
    return resources_register(resources);
 
71
}
 
72
 
 
73
/* ----------------------------------------------------------- */
 
74
 
 
75
static const cmdline_option_t cmdline_options[] = {
 
76
    { "-hidemouseptr", SET_RESOURCE, 0, NULL, NULL,
 
77
      "HideMousePtr", (resource_value_t) 1, NULL,
 
78
      "Enable hiding of mouse pointer inside the window" },
 
79
    { "+hidemouseptr", SET_RESOURCE, 0, NULL, NULL,
 
80
      "HideMousePtr", (resource_value_t) 0, NULL,
 
81
      "Disable hiding of mouse pointer inside the window" },
 
82
    { NULL }
 
83
};
 
84
 
 
85
int mousedrv_cmdline_options_init(void)
 
86
{
 
87
    return cmdline_register_options(cmdline_options);
 
88
}
 
89
 
 
90
void mousedrv_init(void)
 
91
{
 
92
}
 
93
 
 
94
const int mouse_step = 15;
 
95
 
 
96
extern int stretch;  // video.c
 
97
 
 
98
inline BYTE mousedrv_get_x(void)
 
99
{
 
100
    static SHORT last_mouse_x=0;
 
101
 
 
102
    const SHORT diff = last_mouse_x - _mouse_x;
 
103
 
 
104
    /*
 
105
     * The problem is that if you click somewhere and your pointer
 
106
     * is outside the window you would click something at the desktop
 
107
     *
 
108
     * POINTL ptl;
 
109
     * APIRET rc=WinQueryPointerPos(HWND_DESKTOP, &ptl);
 
110
     * _mouse_x = ptl.x;
 
111
     *
 
112
     */
 
113
 
 
114
    if (diff > mouse_step)
 
115
        last_mouse_x -= mouse_step;
 
116
    else
 
117
        if(diff < -mouse_step)
 
118
            last_mouse_x += mouse_step;
 
119
        else
 
120
            last_mouse_x = _mouse_x;
 
121
 
 
122
    return ((last_mouse_x/stretch)
 
123
#ifndef __XVIC_
 
124
             <<1
 
125
#endif
 
126
            )&0x7e;
 
127
}
 
128
 
 
129
inline BYTE mousedrv_get_y(void)
 
130
{
 
131
    static SHORT last_mouse_y=0;
 
132
 
 
133
    const SHORT diff = last_mouse_y - _mouse_y;
 
134
 
 
135
    /*
 
136
     * The problem is that if you click somewhere and your pointer
 
137
     * is outside the window you would click something at the desktop
 
138
     *
 
139
     * POINTL ptl;
 
140
     * APIRET rc=WinQueryPointerPos(HWND_DESKTOP, &ptl);
 
141
     * _mouse_y = ptl.y;
 
142
     *
 
143
     */
 
144
 
 
145
    if (diff > mouse_step)
 
146
        last_mouse_y -= mouse_step;
 
147
    else
 
148
        if(diff < -mouse_step)
 
149
            last_mouse_y += mouse_step;
 
150
        else
 
151
            last_mouse_y = _mouse_y;
 
152
 
 
153
    return ((last_mouse_y/stretch)<<1)&0x7e;
 
154
}
 
155
 
 
156
/* ----------------- OS/2 specific ------------------------- */
 
157
 
 
158
void mouse_button(HWND hwnd, ULONG msg, MPARAM mp1)
 
159
{
 
160
    if (!_mouse_enabled)
 
161
        return;
 
162
 
 
163
    switch (msg)
 
164
    {
 
165
    case WM_MOUSEMOVE:
 
166
        _mouse_x = SHORT1FROMMP(mp1);
 
167
        _mouse_y = SHORT2FROMMP(mp1);
 
168
        {
 
169
            SWP swp;
 
170
            WinQueryWindowPos(hwnd, &swp);
 
171
            //
 
172
            // check whether the pointer is outside or inside the window
 
173
            //
 
174
 
 
175
            if (FullscreenIsNow())
 
176
                visible=TRUE;
 
177
 
 
178
            if (_mouse_x>=0 && _mouse_x<swp.cx &&
 
179
                _mouse_y>=0 && _mouse_y<swp.cy)
 
180
            {
 
181
                //
 
182
                // FIXME: Don't capture the mouse pointer if it is in front
 
183
                // of a client dialog!
 
184
                //
 
185
                if (WinQueryCapture(HWND_DESKTOP)!=hwnd && hide_mouseptr && !FullscreenIsNow())
 
186
                    WinSetCapture(HWND_DESKTOP, hwnd);
 
187
 
 
188
                if (visible && /*_mouse_enabled &&*/ hide_mouseptr &&
 
189
                    !FullscreenIsNow())
 
190
                {
 
191
                    WinShowPointer(HWND_DESKTOP, FALSE);
 
192
                    visible=FALSE;
 
193
                }
 
194
            }
 
195
            else
 
196
            {
 
197
                if (WinQueryCapture(HWND_DESKTOP)==hwnd && !FullscreenIsNow())
 
198
                    WinSetCapture(HWND_DESKTOP, NULLHANDLE);
 
199
 
 
200
                if (!visible && !FullscreenIsNow())
 
201
                {
 
202
                    WinShowPointer(HWND_DESKTOP, TRUE);
 
203
                    visible=TRUE;
 
204
                }
 
205
 
 
206
                //
 
207
                // don't use 'outside'-values which appears one times
 
208
                // if the mouse pointer leaves the window
 
209
                //
 
210
                if (_mouse_x<0) _mouse_x=0;
 
211
                else
 
212
                    if (_mouse_x>=swp.cx)
 
213
                        _mouse_x=swp.cx-1;
 
214
 
 
215
                if (_mouse_y<0) _mouse_y=0;
 
216
                else
 
217
                    if (_mouse_y>=swp.cy)
 
218
                        _mouse_y=swp.cy-1;
 
219
            }
 
220
        }
 
221
        return;
 
222
    case WM_BUTTON1DOWN:
 
223
        mouse_button_left(1);
 
224
        return;
 
225
    case WM_BUTTON1UP:
 
226
        mouse_button_left(0);
 
227
        return;
 
228
    case WM_BUTTON2DOWN:
 
229
        mouse_button_right(1);
 
230
        return;
 
231
    case WM_BUTTON2UP:
 
232
        mouse_button_right(0);
 
233
        return;
 
234
    }
 
235
}
 
236