Subversion Repositories Kolibri OS

Rev

Rev 9930 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9930 Rev 9941
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2010-2023. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
7
 
8
$Revision: 9930 $
-
 
9
 
-
 
10
include 'mousepointer.inc'
8
$Revision: 9941 $
11
 
9
 
12
;================================
10
;================================
13
;/////// public functions ///////
11
;/////// public functions ///////
14
;================================
12
;================================
15
 
13
 
16
mouse.LEFT_BUTTON_FLAG   = 0001b
14
mouse.LEFT_BUTTON_FLAG   = 0001b
17
mouse.RIGHT_BUTTON_FLAG  = 0010b
15
mouse.RIGHT_BUTTON_FLAG  = 0010b
18
mouse.MIDDLE_BUTTON_FLAG = 0100b
16
mouse.MIDDLE_BUTTON_FLAG = 0100b
19
 
17
 
20
mouse.BUTTONS_MASK = \
18
mouse.BUTTONS_MASK = \
21
  mouse.LEFT_BUTTON_FLAG or \
19
  mouse.LEFT_BUTTON_FLAG or \
22
  mouse.RIGHT_BUTTON_FLAG or \
20
  mouse.RIGHT_BUTTON_FLAG or \
23
  mouse.MIDDLE_BUTTON_FLAG
21
  mouse.MIDDLE_BUTTON_FLAG
24
 
22
 
25
mouse.WINDOW_RESIZE_N_FLAG = 000001b
23
mouse.WINDOW_RESIZE_N_FLAG = 000001b
26
mouse.WINDOW_RESIZE_W_FLAG = 000010b
24
mouse.WINDOW_RESIZE_W_FLAG = 000010b
27
mouse.WINDOW_RESIZE_S_FLAG = 000100b
25
mouse.WINDOW_RESIZE_S_FLAG = 000100b
28
mouse.WINDOW_RESIZE_E_FLAG = 001000b
26
mouse.WINDOW_RESIZE_E_FLAG = 001000b
29
mouse.WINDOW_MOVE_FLAG     = 010000b
27
mouse.WINDOW_MOVE_FLAG     = 010000b
30
 
28
 
31
mouse.WINDOW_RESIZE_SW_FLAG = \
29
mouse.WINDOW_RESIZE_SW_FLAG = \
32
  mouse.WINDOW_RESIZE_S_FLAG or \
30
  mouse.WINDOW_RESIZE_S_FLAG or \
33
  mouse.WINDOW_RESIZE_W_FLAG
31
  mouse.WINDOW_RESIZE_W_FLAG
34
mouse.WINDOW_RESIZE_SE_FLAG = \
32
mouse.WINDOW_RESIZE_SE_FLAG = \
35
  mouse.WINDOW_RESIZE_S_FLAG or \
33
  mouse.WINDOW_RESIZE_S_FLAG or \
36
  mouse.WINDOW_RESIZE_E_FLAG
34
  mouse.WINDOW_RESIZE_E_FLAG
37
 
35
 
38
align 4
36
align 4
39
;-----------------------------------------------------------------
37
;-----------------------------------------------------------------
40
mouse_check_events:
38
mouse_check_events:
41
; Check if mouse buttons state or cursor position has changed
39
; Check if mouse buttons state or cursor position has changed
42
        push    eax ebx
40
        push    eax ebx
43
        mov     al, [BTN_DOWN]
41
        mov     al, [BTN_DOWN]
44
        mov     bl, [mouse.state.buttons]
42
        mov     bl, [mouse.state.buttons]
45
        and     al, mouse.BUTTONS_MASK
43
        and     al, mouse.BUTTONS_MASK
46
        mov     cl, al
44
        mov     cl, al
47
        xchg    cl, [mouse.state.buttons]
45
        xchg    cl, [mouse.state.buttons]
48
        xor     bl, al
46
        xor     bl, al
49
        push    eax ebx
47
        push    eax ebx
50
 
48
 
51
        ; did any mouse button changed its state?
49
        ; did any mouse button changed its state?
52
        or      bl, bl
50
        or      bl, bl
53
        jz      .check_position
51
        jz      .check_position
54
 
52
 
55
        ; yes it did, is that the first button of all pressed down?
53
        ; yes it did, is that the first button of all pressed down?
56
        or      cl, cl
54
        or      cl, cl
57
        jnz     .check_buttons_released
55
        jnz     .check_buttons_released
58
 
56
 
59
        ; yes it is, activate window user is pointing at, if needed
57
        ; yes it is, activate window user is pointing at, if needed
60
        call    mouse._.activate_sys_window_under_cursor
58
        call    mouse._.activate_sys_window_under_cursor
61
 
59
 
62
        ; is there any system button under cursor?
60
        ; is there any system button under cursor?
63
        call    mouse._.find_sys_button_under_cursor
61
        call    mouse._.find_sys_button_under_cursor
64
        or      eax, eax
62
        or      eax, eax
65
        jz      .check_buttons_released
63
        jz      .check_buttons_released
66
 
64
 
67
        ; yes there is, activate it and exit
65
        ; yes there is, activate it and exit
68
        mov     [mouse.active_sys_button.pbid], eax
66
        mov     [mouse.active_sys_button.pbid], eax
69
        mov     [mouse.active_sys_button.coord], ebx
67
        mov     [mouse.active_sys_button.coord], ebx
70
        mov     cl, [mouse.state.buttons]
68
        mov     cl, [mouse.state.buttons]
71
        mov     [mouse.active_sys_button.buttons], cl
69
        mov     [mouse.active_sys_button.buttons], cl
72
        call    sys_button_activate_handler
70
        call    sys_button_activate_handler
73
        jmp     .exit
71
        jmp     .exit
74
 
72
 
75
  .check_buttons_released:
73
  .check_buttons_released:
76
        cmp     [mouse.state.buttons], 0
74
        cmp     [mouse.state.buttons], 0
77
        jnz     .buttons_changed
75
        jnz     .buttons_changed
78
 
76
 
79
        ; did we press some button earlier?
77
        ; did we press some button earlier?
80
        cmp     [mouse.active_sys_button.pbid], 0
78
        cmp     [mouse.active_sys_button.pbid], 0
81
        je      .buttons_changed
79
        je      .buttons_changed
82
 
80
 
83
        ; yes we did, deactivate it
81
        ; yes we did, deactivate it
84
        xor     eax, eax
82
        xor     eax, eax
85
        xchg    eax, [mouse.active_sys_button.pbid]
83
        xchg    eax, [mouse.active_sys_button.pbid]
86
        mov     ebx, [mouse.active_sys_button.coord]
84
        mov     ebx, [mouse.active_sys_button.coord]
87
        mov     cl, [mouse.active_sys_button.buttons]
85
        mov     cl, [mouse.active_sys_button.buttons]
88
        push    eax ebx
86
        push    eax ebx
89
        call    sys_button_deactivate_handler
87
        call    sys_button_deactivate_handler
90
        pop     edx ecx
88
        pop     edx ecx
91
 
89
 
92
        ; is the button under cursor the one we deactivated?
90
        ; is the button under cursor the one we deactivated?
93
        call    mouse._.find_sys_button_under_cursor
91
        call    mouse._.find_sys_button_under_cursor
94
        cmp     eax, ecx
92
        cmp     eax, ecx
95
        jne     .exit
93
        jne     .exit
96
        cmp     ebx, edx
94
        cmp     ebx, edx
97
        jne     .exit
95
        jne     .exit
98
 
96
 
99
        ; yes it is, perform associated action
97
        ; yes it is, perform associated action
100
        mov     cl, [mouse.active_sys_button.buttons]
98
        mov     cl, [mouse.active_sys_button.buttons]
101
        call    sys_button_perform_handler
99
        call    sys_button_perform_handler
102
        jmp     .exit
100
        jmp     .exit
103
 
101
 
104
  .buttons_changed:
102
  .buttons_changed:
105
        test    byte[esp], mouse.LEFT_BUTTON_FLAG
103
        test    byte[esp], mouse.LEFT_BUTTON_FLAG
106
        jz      @f
104
        jz      @f
107
        mov     eax, [esp + 4]
105
        mov     eax, [esp + 4]
108
        call    .call_left_button_handler
106
        call    .call_left_button_handler
109
 
107
 
110
    @@:
108
    @@:
111
        test    byte[esp], mouse.RIGHT_BUTTON_FLAG
109
        test    byte[esp], mouse.RIGHT_BUTTON_FLAG
112
        jz      @f
110
        jz      @f
113
        mov     eax, [esp + 4]
111
        mov     eax, [esp + 4]
114
        call    .call_right_button_handler
112
        call    .call_right_button_handler
115
 
113
 
116
    @@:
114
    @@:
117
        test    byte[esp], mouse.MIDDLE_BUTTON_FLAG
115
        test    byte[esp], mouse.MIDDLE_BUTTON_FLAG
118
        jz      .check_position
116
        jz      .check_position
119
        mov     eax, [esp + 4]
117
        mov     eax, [esp + 4]
120
        call    .call_middle_button_handler
118
        call    .call_middle_button_handler
121
 
119
 
122
  .check_position:
120
  .check_position:
123
        movzx   eax, word[MOUSE_X]
121
        movzx   eax, word[MOUSE_X]
124
        movzx   ebx, word[MOUSE_Y]
122
        movzx   ebx, word[MOUSE_Y]
125
        cmp     eax, [mouse.state.pos.x]
123
        cmp     eax, [mouse.state.pos.x]
126
        jne     .position_changed
124
        jne     .position_changed
127
        cmp     ebx, [mouse.state.pos.y]
125
        cmp     ebx, [mouse.state.pos.y]
128
        je      .exit
126
        je      .exit
129
 
127
 
130
  .position_changed:
128
  .position_changed:
131
        xchg    eax, [mouse.state.pos.x]
129
        xchg    eax, [mouse.state.pos.x]
132
        xchg    ebx, [mouse.state.pos.y]
130
        xchg    ebx, [mouse.state.pos.y]
133
 
131
 
134
        call    mouse._.move_handler
132
        call    mouse._.move_handler
135
 
133
 
136
  .exit:
134
  .exit:
137
        add     esp, 8
135
        add     esp, 8
138
        pop     ebx eax
136
        pop     ebx eax
139
        ret
137
        ret
140
 
138
 
141
  .call_left_button_handler:
139
  .call_left_button_handler:
142
        test    eax, mouse.LEFT_BUTTON_FLAG
140
        test    eax, mouse.LEFT_BUTTON_FLAG
143
        jnz     mouse._.left_button_press_handler
141
        jnz     mouse._.left_button_press_handler
144
        jmp     mouse._.left_button_release_handler
142
        jmp     mouse._.left_button_release_handler
145
 
143
 
146
  .call_right_button_handler:
144
  .call_right_button_handler:
147
        test    eax, mouse.RIGHT_BUTTON_FLAG
145
        test    eax, mouse.RIGHT_BUTTON_FLAG
148
        jnz     mouse._.right_button_press_handler
146
        jnz     mouse._.right_button_press_handler
149
        jmp     mouse._.right_button_release_handler
147
        jmp     mouse._.right_button_release_handler
150
 
148
 
151
  .call_middle_button_handler:
149
  .call_middle_button_handler:
152
        test    eax, mouse.MIDDLE_BUTTON_FLAG
150
        test    eax, mouse.MIDDLE_BUTTON_FLAG
153
        jnz     mouse._.middle_button_press_handler
151
        jnz     mouse._.middle_button_press_handler
154
        jmp     mouse._.middle_button_release_handler
152
        jmp     mouse._.middle_button_release_handler
155
 
153
 
156
;===============================
154
;===============================
157
;////// private functions //////
155
;////// private functions //////
158
;===============================
156
;===============================
159
 
157
 
160
uglobal
158
uglobal
161
  mouse.state:
159
  mouse.state:
162
    .pos     POINT
160
    .pos     POINT
163
    .buttons db ?
161
    .buttons db ?
164
 
162
 
165
; NOTE: since there's no unique and lifetime-constant button identifiers,
163
; NOTE: since there's no unique and lifetime-constant button identifiers,
166
; we are using two dwords to identify each of them:
164
; we are using two dwords to identify each of them:
167
;   * pbid - process slot (high 8 bits) and button id (low 24 bits) pack
165
;   * pbid - process slot (high 8 bits) and button id (low 24 bits) pack
168
;   * coord - left (high 16 bits) and top (low 16 bits) coordinates pack
166
;   * coord - left (high 16 bits) and top (low 16 bits) coordinates pack
169
  align 4
167
  align 4
170
  mouse.active_sys_button:
168
  mouse.active_sys_button:
171
    .pbid    dd ?
169
    .pbid    dd ?
172
    .coord   dd ?
170
    .coord   dd ?
173
    .buttons db ?
171
    .buttons db ?
174
 
172
 
175
  align 4
173
  align 4
176
  mouse.active_sys_window:
174
  mouse.active_sys_window:
177
    .pslot      dd ?
175
    .pslot      dd ?
178
    .old_box    BOX
176
    .old_box    BOX
179
    .new_box    BOX
177
    .new_box    BOX
180
    .delta      POINT
178
    .delta      POINT
181
    .last_ticks dd ?
179
    .last_ticks dd ?
182
    .action     db ?
180
    .action     db ?
183
endg
181
endg
184
 
182
 
185
iglobal
183
iglobal
186
        fl_moving db 0
184
        fl_moving db 0
187
        rb 3
185
        rb 3
188
endg
186
endg
189
 
187
 
190
align 4
188
align 4
191
;-----------------------------------------------------------------
189
;-----------------------------------------------------------------
192
mouse._.left_button_press_handler:
190
mouse._.left_button_press_handler:
193
; Called when left mouse button has been pressed down
191
; Called when left mouse button has been pressed down
194
        bts     word [BTN_DOWN], 8
192
        bts     word [BTN_DOWN], 8
195
        mov     eax, [timer_ticks]
193
        mov     eax, [timer_ticks]
196
        mov     ebx, eax
194
        mov     ebx, eax
197
        xchg    ebx, [mouse.active_sys_window.last_ticks]
195
        xchg    ebx, [mouse.active_sys_window.last_ticks]
198
        sub     eax, ebx
196
        sub     eax, ebx
199
        movzx   ebx, [mouse_doubleclick_delay]
197
        movzx   ebx, [mouse_doubleclick_delay]
200
        cmp     eax, ebx
198
        cmp     eax, ebx
201
        jg      @f
199
        jg      @f
202
        bts     dword [BTN_DOWN], 24
200
        bts     dword [BTN_DOWN], 24
203
@@:
201
@@:
204
        test    [mouse.state.buttons], not mouse.LEFT_BUTTON_FLAG
202
        test    [mouse.state.buttons], not mouse.LEFT_BUTTON_FLAG
205
        jnz     .exit
203
        jnz     .exit
206
 
204
 
207
        call    mouse._.find_sys_window_under_cursor
205
        call    mouse._.find_sys_window_under_cursor
208
        call    mouse._.check_sys_window_actions
206
        call    mouse._.check_sys_window_actions
209
        mov     [mouse.active_sys_window.action], al
207
        mov     [mouse.active_sys_window.action], al
210
        or      eax, eax
208
        or      eax, eax
211
        jz      .exit
209
        jz      .exit
212
 
210
 
213
        xchg    eax, edx
211
        xchg    eax, edx
214
        test    dl, mouse.WINDOW_MOVE_FLAG
212
        test    dl, mouse.WINDOW_MOVE_FLAG
215
        jz      @f
213
        jz      @f
216
 
214
 
217
        bt      dword [BTN_DOWN], 24
215
        bt      dword [BTN_DOWN], 24
218
        jnc     @f
216
        jnc     @f
219
 
217
 
220
        mov     [mouse.active_sys_window.last_ticks], 0
218
        mov     [mouse.active_sys_window.last_ticks], 0
221
        call    sys_window_maximize_handler
219
        call    sys_window_maximize_handler
222
        jmp     .exit
220
        jmp     .exit
223
 
221
 
224
    @@:
222
    @@:
225
        test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
223
        test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
226
        jnz     .exit
224
        jnz     .exit
227
        mov     [mouse.active_sys_window.pslot], esi
225
        mov     [mouse.active_sys_window.pslot], esi
228
        lea     eax, [edi + WDATA.box]
226
        lea     eax, [edi + WDATA.box]
229
        mov     ebx, mouse.active_sys_window.old_box
227
        mov     ebx, mouse.active_sys_window.old_box
230
        mov     ecx, sizeof.BOX
228
        mov     ecx, sizeof.BOX
231
        call    memmove
229
        call    memmove
232
        mov     ebx, mouse.active_sys_window.new_box
230
        mov     ebx, mouse.active_sys_window.new_box
233
        call    memmove
231
        call    memmove
234
        test    edx, mouse.WINDOW_MOVE_FLAG
232
        test    edx, mouse.WINDOW_MOVE_FLAG
235
        jz      @f
233
        jz      @f
236
 
234
 
237
        call    .calculate_n_delta
235
        call    .calculate_n_delta
238
        call    .calculate_w_delta
236
        call    .calculate_w_delta
239
        jmp     .call_window_handler
237
        jmp     .call_window_handler
240
 
238
 
241
    @@:
239
    @@:
242
        test    dl, mouse.WINDOW_RESIZE_W_FLAG
240
        test    dl, mouse.WINDOW_RESIZE_W_FLAG
243
        jz      @f
241
        jz      @f
244
        call    .calculate_w_delta
242
        call    .calculate_w_delta
245
 
243
 
246
    @@:
244
    @@:
247
        test    dl, mouse.WINDOW_RESIZE_S_FLAG
245
        test    dl, mouse.WINDOW_RESIZE_S_FLAG
248
        jz      @f
246
        jz      @f
249
        call    .calculate_s_delta
247
        call    .calculate_s_delta
250
 
248
 
251
    @@:
249
    @@:
252
        test    dl, mouse.WINDOW_RESIZE_E_FLAG
250
        test    dl, mouse.WINDOW_RESIZE_E_FLAG
253
        jz      .call_window_handler
251
        jz      .call_window_handler
254
        call    .calculate_e_delta
252
        call    .calculate_e_delta
255
 
253
 
256
  .call_window_handler:
254
  .call_window_handler:
257
  .exit:
255
  .exit:
258
        ret
256
        ret
259
 
257
 
260
  .calculate_n_delta:
258
  .calculate_n_delta:
261
        mov     eax, [mouse.state.pos.y]
259
        mov     eax, [mouse.state.pos.y]
262
        sub     eax, [mouse.active_sys_window.old_box.top]
260
        sub     eax, [mouse.active_sys_window.old_box.top]
263
        mov     [mouse.active_sys_window.delta.y], eax
261
        mov     [mouse.active_sys_window.delta.y], eax
264
        ret
262
        ret
265
 
263
 
266
  .calculate_w_delta:
264
  .calculate_w_delta:
267
        mov     eax, [mouse.state.pos.x]
265
        mov     eax, [mouse.state.pos.x]
268
        sub     eax, [mouse.active_sys_window.old_box.left]
266
        sub     eax, [mouse.active_sys_window.old_box.left]
269
        mov     [mouse.active_sys_window.delta.x], eax
267
        mov     [mouse.active_sys_window.delta.x], eax
270
        ret
268
        ret
271
 
269
 
272
  .calculate_s_delta:
270
  .calculate_s_delta:
273
        mov     eax, [mouse.active_sys_window.old_box.top]
271
        mov     eax, [mouse.active_sys_window.old_box.top]
274
        add     eax, [mouse.active_sys_window.old_box.height]
272
        add     eax, [mouse.active_sys_window.old_box.height]
275
        sub     eax, [mouse.state.pos.y]
273
        sub     eax, [mouse.state.pos.y]
276
        mov     [mouse.active_sys_window.delta.y], eax
274
        mov     [mouse.active_sys_window.delta.y], eax
277
        ret
275
        ret
278
 
276
 
279
  .calculate_e_delta:
277
  .calculate_e_delta:
280
        mov     eax, [mouse.active_sys_window.old_box.left]
278
        mov     eax, [mouse.active_sys_window.old_box.left]
281
        add     eax, [mouse.active_sys_window.old_box.width]
279
        add     eax, [mouse.active_sys_window.old_box.width]
282
        sub     eax, [mouse.state.pos.x]
280
        sub     eax, [mouse.state.pos.x]
283
        mov     [mouse.active_sys_window.delta.x], eax
281
        mov     [mouse.active_sys_window.delta.x], eax
284
        ret
282
        ret
285
 
283
 
286
align 4
284
align 4
287
;-----------------------------------------------------------------
285
;-----------------------------------------------------------------
288
mouse._.left_button_release_handler:
286
mouse._.left_button_release_handler:
289
; Called when left mouse button has been released
287
; Called when left mouse button has been released
290
        bts     dword [BTN_DOWN], 16
288
        bts     dword [BTN_DOWN], 16
291
        xor     esi, esi
289
        xor     esi, esi
292
        xchg    esi, [mouse.active_sys_window.pslot]
290
        xchg    esi, [mouse.active_sys_window.pslot]
293
        or      esi, esi
291
        or      esi, esi
294
        jz      .exit
292
        jz      .exit
295
 
293
 
296
        mov     eax, esi
294
        mov     eax, esi
297
        shl     eax, BSF sizeof.WDATA
295
        shl     eax, BSF sizeof.WDATA
298
        add     eax, window_data + WDATA.box
296
        add     eax, window_data + WDATA.box
299
        mov     ebx, mouse.active_sys_window.old_box
297
        mov     ebx, mouse.active_sys_window.old_box
300
        mov     ecx, sizeof.BOX
298
        mov     ecx, sizeof.BOX
301
        call    memmove
299
        call    memmove
302
 
300
 
303
        mov     eax, mouse.active_sys_window.old_box
301
        mov     eax, mouse.active_sys_window.old_box
304
        mov     ebx, mouse.active_sys_window.new_box
302
        mov     ebx, mouse.active_sys_window.new_box
305
        call    sys_window_end_moving_handler
303
        call    sys_window_end_moving_handler
306
 
304
 
307
  .exit:
305
  .exit:
308
        and     [mouse.active_sys_window.action], 0
306
        and     [mouse.active_sys_window.action], 0
309
        mov     [fl_moving], 0
307
        mov     [fl_moving], 0
310
        ret
308
        ret
311
 
309
 
312
mouse._.right_button_press_handler:
310
mouse._.right_button_press_handler:
313
        bts     word [BTN_DOWN], 9
311
        bts     word [BTN_DOWN], 9
314
        test    [mouse.state.buttons], not mouse.RIGHT_BUTTON_FLAG
312
        test    [mouse.state.buttons], not mouse.RIGHT_BUTTON_FLAG
315
        jnz     @f
313
        jnz     @f
316
        call    mouse._.find_sys_window_under_cursor
314
        call    mouse._.find_sys_window_under_cursor
317
        call    mouse._.check_sys_window_actions
315
        call    mouse._.check_sys_window_actions
318
        test    al, mouse.WINDOW_MOVE_FLAG
316
        test    al, mouse.WINDOW_MOVE_FLAG
319
        jz      @f
317
        jz      @f
320
        jmp     sys_window_rollup_handler
318
        jmp     sys_window_rollup_handler
321
 
319
 
322
mouse._.right_button_release_handler:
320
mouse._.right_button_release_handler:
323
        bts     dword [BTN_DOWN], 17
321
        bts     dword [BTN_DOWN], 17
324
@@:
322
@@:
325
        ret
323
        ret
326
 
324
 
327
mouse._.middle_button_press_handler:
325
mouse._.middle_button_press_handler:
328
        bts     word [BTN_DOWN], 10
326
        bts     word [BTN_DOWN], 10
329
        ret
327
        ret
330
 
328
 
331
mouse._.middle_button_release_handler:
329
mouse._.middle_button_release_handler:
332
        bts     dword [BTN_DOWN], 18
330
        bts     dword [BTN_DOWN], 18
333
        ret
331
        ret
334
 
332
 
335
align 4
333
align 4
336
;-----------------------------------------------------------------
334
;-----------------------------------------------------------------
337
mouse._.move_handler:
335
mouse._.move_handler:
338
; Called when cursor has been moved
336
; Called when cursor has been moved
339
;> eax = old x coord
337
;> eax = old x coord
340
;> ebx = old y coord
338
;> ebx = old y coord
341
        push    eax ebx
339
        push    eax ebx
342
 
340
 
343
        call    mouse._.find_sys_window_under_cursor
341
        call    mouse._.find_sys_window_under_cursor
344
        call    mouse._.check_sys_window_actions
342
        call    mouse._.check_sys_window_actions
345
 
343
 
346
        ; if now we are resizing the window, dont change the cursor
344
        ; if now we are resizing the window, dont change the cursor
347
        mov     bl, [mouse.active_sys_window.action]
345
        mov     bl, [mouse.active_sys_window.action]
348
        and     bl, mouse.WINDOW_RESIZE_S_FLAG or mouse.WINDOW_RESIZE_W_FLAG or mouse.WINDOW_RESIZE_E_FLAG
346
        and     bl, mouse.WINDOW_RESIZE_S_FLAG or mouse.WINDOW_RESIZE_W_FLAG or mouse.WINDOW_RESIZE_E_FLAG
349
        test    bl, bl
347
        test    bl, bl
350
        jnz     .end1
348
        jnz     .end1
351
 
349
 
352
        cmp     al, mouse.WINDOW_RESIZE_SW_FLAG
350
        cmp     al, mouse.WINDOW_RESIZE_SW_FLAG
353
        jne     .not_sw
351
        jne     .not_sw
354
        ; DEBUGF  1, "RESIZE SOUTH-WEST\n"
352
        ; DEBUGF  1, "RESIZE SOUTH-WEST\n"
355
 
353
 
356
        mov     eax, [def_cursor_dresize2]
354
        mov     eax, [def_cursor_dresize2]
357
 
355
 
358
        jmp     .set_resizing_cursor
356
        jmp     .set_resizing_cursor
359
.not_sw:
357
.not_sw:
360
        cmp     al, mouse.WINDOW_RESIZE_SE_FLAG
358
        cmp     al, mouse.WINDOW_RESIZE_SE_FLAG
361
        jne     .not_se
359
        jne     .not_se
362
        ; DEBUGF  1, "RESIZE SOUTH-EAST\n"
360
        ; DEBUGF  1, "RESIZE SOUTH-EAST\n"
363
 
361
 
364
        mov     eax, [def_cursor_dresize1]
362
        mov     eax, [def_cursor_dresize1]
365
 
363
 
366
        jmp     .set_resizing_cursor
364
        jmp     .set_resizing_cursor
367
.not_se:
365
.not_se:
368
        cmp     al, mouse.WINDOW_RESIZE_W_FLAG
366
        cmp     al, mouse.WINDOW_RESIZE_W_FLAG
369
        jne     .not_w
367
        jne     .not_w
370
        ; DEBUGF  1, "RESIZE WEST\n"
368
        ; DEBUGF  1, "RESIZE WEST\n"
371
 
369
 
372
        mov     eax, [def_cursor_hresize]
370
        mov     eax, [def_cursor_hresize]
373
 
371
 
374
        jmp     .set_resizing_cursor
372
        jmp     .set_resizing_cursor
375
.not_w:
373
.not_w:
376
        cmp     al, mouse.WINDOW_RESIZE_S_FLAG
374
        cmp     al, mouse.WINDOW_RESIZE_S_FLAG
377
        jne     .not_s
375
        jne     .not_s
378
        ; DEBUGF  1, "RESIZE SOUTH\n"
376
        ; DEBUGF  1, "RESIZE SOUTH\n"
379
 
377
 
380
        mov     eax, [def_cursor_vresize]
378
        mov     eax, [def_cursor_vresize]
381
 
379
 
382
        jmp     .set_resizing_cursor
380
        jmp     .set_resizing_cursor
383
.not_s:
381
.not_s:
384
        cmp     al, mouse.WINDOW_RESIZE_E_FLAG
382
        cmp     al, mouse.WINDOW_RESIZE_E_FLAG
385
        jne     .not_in_resize_area
383
        jne     .not_in_resize_area
386
        ; DEBUGF  1, "RESIZE EAST\n"
384
        ; DEBUGF  1, "RESIZE EAST\n"
387
 
385
 
388
        mov     eax, [def_cursor_hresize]
386
        mov     eax, [def_cursor_hresize]
389
 
387
 
390
.set_resizing_cursor:
388
.set_resizing_cursor:
391
        ; DEBUGF  1, ".set_resizing_cursor eax = %x\n", eax
389
        ; DEBUGF  1, ".set_resizing_cursor eax = %x\n", eax
392
        ; change cursor to resizing cursor
390
        ; change cursor to resizing cursor
393
        shl     esi, BSF sizeof.WDATA
391
        shl     esi, BSF sizeof.WDATA
394
        add     esi, window_data
392
        add     esi, window_data
395
        
393
        
396
        ; if resizing cursor we need (eax) isnt set already, set it
394
        ; if resizing cursor we need (eax) isnt set already, set it
397
        cmp     eax, [esi + WDATA.cursor]
395
        cmp     eax, [esi + WDATA.cursor]
398
        je      @f
396
        je      @f
399
        
397
        
400
        ; DEBUGF  1, "changing cursor to resizing\n"
398
        ; DEBUGF  1, "changing cursor to resizing\n"
401
        xchg    eax, [esi + WDATA.cursor] ; set resizing cursor, prev cursor goes to eax
399
        xchg    eax, [esi + WDATA.cursor] ; set resizing cursor, prev cursor goes to eax
402
        ; save previous cursor (will be restored when we'll get out of the resizing area)
400
        ; save previous cursor (will be restored when we'll get out of the resizing area)
403
        ; if we change resizing cursor to resizing cursor then dont update previous cursor
401
        ; if we change resizing cursor to resizing cursor then dont update previous cursor
404
        cmp     eax, [def_cursor_hresize]
402
        cmp     eax, [def_cursor_hresize]
405
        je      @f
403
        je      @f
406
        cmp     eax, [def_cursor_vresize]
404
        cmp     eax, [def_cursor_vresize]
407
        je      @f
405
        je      @f
408
        cmp     eax, [def_cursor_dresize1]
406
        cmp     eax, [def_cursor_dresize1]
409
        je      @f
407
        je      @f
410
        cmp     eax, [def_cursor_dresize2]
408
        cmp     eax, [def_cursor_dresize2]
411
        je      @f
409
        je      @f
412
 
410
 
413
        mov     [esi + WDATA.temp_cursor], eax ; save prev cursor
411
        mov     [esi + WDATA.temp_cursor], eax ; save prev cursor
414
 
412
 
415
@@:
413
@@:
416
        jmp     .end1
414
        jmp     .end1
417
.not_in_resize_area:
415
.not_in_resize_area:
418
        ; DEBUGF  1, ".not_in_resize_area\n"
416
        ; DEBUGF  1, ".not_in_resize_area\n"
419
 
417
 
420
        shl     esi, BSF sizeof.WDATA
418
        shl     esi, BSF sizeof.WDATA
421
        add     esi, window_data
419
        add     esi, window_data
422
        mov     eax, [esi + WDATA.temp_cursor]
420
        mov     eax, [esi + WDATA.temp_cursor]
423
 
421
 
424
        test    eax, eax
422
        test    eax, eax
425
        jz      .end1
423
        jz      .end1
426
        
424
        
427
        ; restore prev cursor
425
        ; restore prev cursor
428
        mov     [esi + WDATA.temp_cursor], 0
426
        mov     [esi + WDATA.temp_cursor], 0
429
        mov     [esi + WDATA.cursor], eax
427
        mov     [esi + WDATA.cursor], eax
430
 
428
 
431
.end1:
429
.end1:
432
        pop     ebx eax
430
        pop     ebx eax
433
 
431
 
434
        cmp     [mouse.active_sys_button.pbid], 0
432
        cmp     [mouse.active_sys_button.pbid], 0
435
        jnz     .exit
433
        jnz     .exit
436
 
434
 
437
        mov     esi, [mouse.active_sys_window.pslot]
435
        mov     esi, [mouse.active_sys_window.pslot]
438
        or      esi, esi
436
        or      esi, esi
439
        jz      .exit
437
        jz      .exit
440
 
438
 
441
        mov     eax, mouse.active_sys_window.new_box
439
        mov     eax, mouse.active_sys_window.new_box
442
        mov     ebx, mouse.active_sys_window.old_box
440
        mov     ebx, mouse.active_sys_window.old_box
443
        mov     ecx, sizeof.BOX
441
        mov     ecx, sizeof.BOX
444
        call    memmove
442
        call    memmove
445
 
443
 
446
        mov     dl, [mouse.active_sys_window.action]
444
        mov     dl, [mouse.active_sys_window.action]
447
        test    dl, mouse.WINDOW_MOVE_FLAG
445
        test    dl, mouse.WINDOW_MOVE_FLAG
448
        jz      .check_resize_w
446
        jz      .check_resize_w
449
 
447
 
450
        mov     eax, [mouse.state.pos.x]
448
        mov     eax, [mouse.state.pos.x]
451
        sub     eax, [mouse.active_sys_window.delta.x]
449
        sub     eax, [mouse.active_sys_window.delta.x]
452
        mov     [mouse.active_sys_window.new_box.left], eax
450
        mov     [mouse.active_sys_window.new_box.left], eax
453
        mov     eax, [mouse.state.pos.y]
451
        mov     eax, [mouse.state.pos.y]
454
        sub     eax, [mouse.active_sys_window.delta.y]
452
        sub     eax, [mouse.active_sys_window.delta.y]
455
        mov     [mouse.active_sys_window.new_box.top], eax
453
        mov     [mouse.active_sys_window.new_box.top], eax
456
 
454
 
457
        mov     eax, [mouse.active_sys_window.new_box.left]
455
        mov     eax, [mouse.active_sys_window.new_box.left]
458
        or      eax, eax
456
        or      eax, eax
459
        jge     @f
457
        jge     @f
460
        xor     eax, eax
458
        xor     eax, eax
461
        mov     [mouse.active_sys_window.new_box.left], eax
459
        mov     [mouse.active_sys_window.new_box.left], eax
462
    @@:
460
    @@:
463
        add     eax, [mouse.active_sys_window.new_box.width]
461
        add     eax, [mouse.active_sys_window.new_box.width]
464
        cmp     eax, [_display.width]
462
        cmp     eax, [_display.width]
465
        jl      @f
463
        jl      @f
466
        sub     eax, [_display.width]
464
        sub     eax, [_display.width]
467
        inc     eax
465
        inc     eax
468
        sub     [mouse.active_sys_window.new_box.left], eax
466
        sub     [mouse.active_sys_window.new_box.left], eax
469
    @@:
467
    @@:
470
        mov     eax, [mouse.active_sys_window.new_box.top]
468
        mov     eax, [mouse.active_sys_window.new_box.top]
471
        or      eax, eax
469
        or      eax, eax
472
        jge     @f
470
        jge     @f
473
        xor     eax, eax
471
        xor     eax, eax
474
        mov     [mouse.active_sys_window.new_box.top], eax
472
        mov     [mouse.active_sys_window.new_box.top], eax
475
    @@:
473
    @@:
476
        add     eax, [mouse.active_sys_window.new_box.height]
474
        add     eax, [mouse.active_sys_window.new_box.height]
477
        cmp     eax, [_display.height]
475
        cmp     eax, [_display.height]
478
        jl      .call_window_handler
476
        jl      .call_window_handler
479
        sub     eax, [_display.height]
477
        sub     eax, [_display.height]
480
        inc     eax
478
        inc     eax
481
        sub     [mouse.active_sys_window.new_box.top], eax
479
        sub     [mouse.active_sys_window.new_box.top], eax
482
        jmp     .call_window_handler
480
        jmp     .call_window_handler
483
 
481
 
484
  .check_resize_w:
482
  .check_resize_w:
485
        test    dl, mouse.WINDOW_RESIZE_W_FLAG
483
        test    dl, mouse.WINDOW_RESIZE_W_FLAG
486
        jz      .check_resize_s
484
        jz      .check_resize_s
487
 
485
 
488
        mov     eax, [mouse.state.pos.x]
486
        mov     eax, [mouse.state.pos.x]
489
        sub     eax, [mouse.active_sys_window.delta.x]
487
        sub     eax, [mouse.active_sys_window.delta.x]
490
        mov     [mouse.active_sys_window.new_box.left], eax
488
        mov     [mouse.active_sys_window.new_box.left], eax
491
        sub     eax, [mouse.active_sys_window.old_box.left]
489
        sub     eax, [mouse.active_sys_window.old_box.left]
492
        sub     [mouse.active_sys_window.new_box.width], eax
490
        sub     [mouse.active_sys_window.new_box.width], eax
493
 
491
 
494
        mov     eax, [mouse.active_sys_window.new_box.width]
492
        mov     eax, [mouse.active_sys_window.new_box.width]
495
        sub     eax, 127
493
        sub     eax, 127
496
        jge     @f
494
        jge     @f
497
        add     [mouse.active_sys_window.new_box.left], eax
495
        add     [mouse.active_sys_window.new_box.left], eax
498
        mov     [mouse.active_sys_window.new_box.width], 127
496
        mov     [mouse.active_sys_window.new_box.width], 127
499
    @@:
497
    @@:
500
        mov     eax, [mouse.active_sys_window.new_box.left]
498
        mov     eax, [mouse.active_sys_window.new_box.left]
501
        or      eax, eax
499
        or      eax, eax
502
        jge     .check_resize_s
500
        jge     .check_resize_s
503
        add     [mouse.active_sys_window.new_box.width], eax
501
        add     [mouse.active_sys_window.new_box.width], eax
504
        xor     eax, eax
502
        xor     eax, eax
505
        mov     [mouse.active_sys_window.new_box.left], eax
503
        mov     [mouse.active_sys_window.new_box.left], eax
506
 
504
 
507
  .check_resize_s:
505
  .check_resize_s:
508
        test    dl, mouse.WINDOW_RESIZE_S_FLAG
506
        test    dl, mouse.WINDOW_RESIZE_S_FLAG
509
        jz      .check_resize_e
507
        jz      .check_resize_e
510
 
508
 
511
        mov     eax, [mouse.state.pos.y]
509
        mov     eax, [mouse.state.pos.y]
512
        add     eax, [mouse.active_sys_window.delta.y]
510
        add     eax, [mouse.active_sys_window.delta.y]
513
        sub     eax, [mouse.active_sys_window.old_box.top]
511
        sub     eax, [mouse.active_sys_window.old_box.top]
514
        mov     [mouse.active_sys_window.new_box.height], eax
512
        mov     [mouse.active_sys_window.new_box.height], eax
515
 
513
 
516
        push    eax
514
        push    eax
517
        mov     edi, esi
515
        mov     edi, esi
518
        shl     edi, BSF sizeof.WDATA
516
        shl     edi, BSF sizeof.WDATA
519
        add     edi, window_data
517
        add     edi, window_data
520
        call    window._.get_rolledup_height
518
        call    window._.get_rolledup_height
521
        mov     ecx, eax
519
        mov     ecx, eax
522
        pop     eax
520
        pop     eax
523
        mov     eax, [mouse.active_sys_window.new_box.height]
521
        mov     eax, [mouse.active_sys_window.new_box.height]
524
        cmp     eax, ecx
522
        cmp     eax, ecx
525
        jge     @f
523
        jge     @f
526
        mov     eax, ecx
524
        mov     eax, ecx
527
        mov     [mouse.active_sys_window.new_box.height], eax
525
        mov     [mouse.active_sys_window.new_box.height], eax
528
    @@:
526
    @@:
529
        add     eax, [mouse.active_sys_window.new_box.top]
527
        add     eax, [mouse.active_sys_window.new_box.top]
530
        cmp     eax, [_display.height]
528
        cmp     eax, [_display.height]
531
        jl      .check_resize_e
529
        jl      .check_resize_e
532
        sub     eax, [_display.height]
530
        sub     eax, [_display.height]
533
        neg     eax
531
        neg     eax
534
        add     [mouse.active_sys_window.new_box.height], eax
532
        add     [mouse.active_sys_window.new_box.height], eax
535
        mov     ecx, [_display.height]
533
        mov     ecx, [_display.height]
536
        cmp     ecx, eax
534
        cmp     ecx, eax
537
        jg      .check_resize_e
535
        jg      .check_resize_e
538
        mov     [mouse.active_sys_window.new_box.height], ecx
536
        mov     [mouse.active_sys_window.new_box.height], ecx
539
 
537
 
540
  .check_resize_e:
538
  .check_resize_e:
541
        test    dl, mouse.WINDOW_RESIZE_E_FLAG
539
        test    dl, mouse.WINDOW_RESIZE_E_FLAG
542
        jz      .call_window_handler
540
        jz      .call_window_handler
543
 
541
 
544
        mov     eax, [mouse.state.pos.x]
542
        mov     eax, [mouse.state.pos.x]
545
        add     eax, [mouse.active_sys_window.delta.x]
543
        add     eax, [mouse.active_sys_window.delta.x]
546
        sub     eax, [mouse.active_sys_window.old_box.left]
544
        sub     eax, [mouse.active_sys_window.old_box.left]
547
        mov     [mouse.active_sys_window.new_box.width], eax
545
        mov     [mouse.active_sys_window.new_box.width], eax
548
 
546
 
549
        mov     eax, [mouse.active_sys_window.new_box.width]
547
        mov     eax, [mouse.active_sys_window.new_box.width]
550
        cmp     eax, 127
548
        cmp     eax, 127
551
        jge     @f
549
        jge     @f
552
        mov     eax, 127
550
        mov     eax, 127
553
        mov     [mouse.active_sys_window.new_box.width], eax
551
        mov     [mouse.active_sys_window.new_box.width], eax
554
    @@:
552
    @@:
555
        add     eax, [mouse.active_sys_window.new_box.left]
553
        add     eax, [mouse.active_sys_window.new_box.left]
556
        cmp     eax, [_display.width]
554
        cmp     eax, [_display.width]
557
        jl      .call_window_handler
555
        jl      .call_window_handler
558
        sub     eax, [_display.width]
556
        sub     eax, [_display.width]
559
        neg     eax
557
        neg     eax
560
        add     [mouse.active_sys_window.new_box.width], eax
558
        add     [mouse.active_sys_window.new_box.width], eax
561
        mov     ecx, [_display.width]
559
        mov     ecx, [_display.width]
562
        cmp     ecx, eax
560
        cmp     ecx, eax
563
        jg      .call_window_handler
561
        jg      .call_window_handler
564
        mov     [mouse.active_sys_window.new_box.width], ecx
562
        mov     [mouse.active_sys_window.new_box.width], ecx
565
 
563
 
566
  .call_window_handler:
564
  .call_window_handler:
567
        mov     eax, mouse.active_sys_window.old_box
565
        mov     eax, mouse.active_sys_window.old_box
568
        mov     ebx, mouse.active_sys_window.new_box
566
        mov     ebx, mouse.active_sys_window.new_box
569
 
567
 
570
        push    esi
568
        push    esi
571
        mov     esi, mouse.active_sys_window.old_box
569
        mov     esi, mouse.active_sys_window.old_box
572
        mov     edi, mouse.active_sys_window.new_box
570
        mov     edi, mouse.active_sys_window.new_box
573
        mov     ecx, sizeof.BOX / 4
571
        mov     ecx, sizeof.BOX / 4
574
        repe
572
        repe
575
        cmpsd
573
        cmpsd
576
        pop     esi
574
        pop     esi
577
        je      .exit
575
        je      .exit
578
 
576
 
579
        test    [fl_moving], 1
577
        test    [fl_moving], 1
580
        jnz     @f
578
        jnz     @f
581
 
579
 
582
        mov     [fl_moving], 1
580
        mov     [fl_moving], 1
583
        push    edi
581
        push    edi
584
        mov     edi, esi
582
        mov     edi, esi
585
        shl     edi, BSF sizeof.WDATA
583
        shl     edi, BSF sizeof.WDATA
586
        add     edi, WDATA.box + window_data
584
        add     edi, WDATA.box + window_data
587
        call    window._.draw_negative_box
585
        call    window._.draw_negative_box
588
        pop     edi
586
        pop     edi
589
     @@:
587
     @@:
590
 
588
 
591
 
589
 
592
        mov     [mouse.active_sys_window.last_ticks], 0
590
        mov     [mouse.active_sys_window.last_ticks], 0
593
        call    sys_window_moving_handler
591
        call    sys_window_moving_handler
594
 
592
 
595
  .exit:
593
  .exit:
596
        ret
594
        ret
597
 
595
 
598
align 4
596
align 4
599
;-----------------------------------------------------------------
597
;-----------------------------------------------------------------
600
mouse._.find_sys_window_under_cursor:
598
mouse._.find_sys_window_under_cursor:
601
; Find system window object which is currently visible on screen
599
; Find system window object which is currently visible on screen
602
; and has mouse cursor within its bounds
600
; and has mouse cursor within its bounds
603
;< esi = process slot
601
;< esi = process slot
604
;< edi = pointer to WDATA struct
602
;< edi = pointer to WDATA struct
605
        mov     esi, [mouse.state.pos.y]
603
        mov     esi, [mouse.state.pos.y]
606
        mov     esi, [d_width_calc_area + esi*4]
604
        mov     esi, [d_width_calc_area + esi*4]
607
 
605
 
608
        add     esi, [_display.win_map]
606
        add     esi, [_display.win_map]
609
        add     esi, [mouse.state.pos.x]
607
        add     esi, [mouse.state.pos.x]
610
        movzx   esi, byte[esi]
608
        movzx   esi, byte[esi]
611
        mov     edi, esi
609
        mov     edi, esi
612
        shl     edi, BSF sizeof.WDATA
610
        shl     edi, BSF sizeof.WDATA
613
        add     edi, window_data
611
        add     edi, window_data
614
        ret
612
        ret
615
 
613
 
616
align 4
614
align 4
617
;-----------------------------------------------------------------
615
;-----------------------------------------------------------------
618
mouse._.activate_sys_window_under_cursor:
616
mouse._.activate_sys_window_under_cursor:
619
; activate and redraw window under cursor (if necessary)
617
; activate and redraw window under cursor (if necessary)
620
        call    mouse._.find_sys_window_under_cursor
618
        call    mouse._.find_sys_window_under_cursor
621
        movzx   esi, word[WIN_STACK + esi * 2]
619
        movzx   esi, word[WIN_STACK + esi * 2]
622
        lea     esi, [WIN_POS + esi * 2]
620
        lea     esi, [WIN_POS + esi * 2]
623
        jmp     waredraw
621
        jmp     waredraw
624
 
622
 
625
align 4
623
align 4
626
;-----------------------------------------------------------------
624
;-----------------------------------------------------------------
627
mouse._.find_sys_button_under_cursor:
625
mouse._.find_sys_button_under_cursor:
628
; Find system button object which is currently visible on screen
626
; Find system button object which is currently visible on screen
629
; and has mouse cursor within its bounds
627
; and has mouse cursor within its bounds
630
;< eax = pack[8(process slot), 24(button id)] or 0
628
;< eax = pack[8(process slot), 24(button id)] or 0
631
;< ebx = pack[16(button x coord), 16(button y coord)]
629
;< ebx = pack[16(button x coord), 16(button y coord)]
632
        push    ecx edx esi edi
630
        push    ecx edx esi edi
633
 
631
 
634
        call    mouse._.find_sys_window_under_cursor
632
        call    mouse._.find_sys_window_under_cursor
635
        mov     edx, esi
633
        mov     edx, esi
636
 
634
 
637
        ; check if any process button contains cursor
635
        ; check if any process button contains cursor
638
        mov     eax, [BTN_ADDR]
636
        mov     eax, [BTN_ADDR]
639
        mov     ecx, [eax]
637
        mov     ecx, [eax]
640
        imul    esi, ecx, sizeof.SYS_BUTTON
638
        imul    esi, ecx, sizeof.SYS_BUTTON
641
        add     esi, eax
639
        add     esi, eax
642
        inc     ecx
640
        inc     ecx
643
        add     esi, sizeof.SYS_BUTTON
641
        add     esi, sizeof.SYS_BUTTON
644
 
642
 
645
  .next_button:
643
  .next_button:
646
        dec     ecx
644
        dec     ecx
647
        jz      .not_found
645
        jz      .not_found
648
 
646
 
649
        add     esi, -sizeof.SYS_BUTTON
647
        add     esi, -sizeof.SYS_BUTTON
650
 
648
 
651
        ; does it belong to our process?
649
        ; does it belong to our process?
652
        cmp     dx, [esi + SYS_BUTTON.pslot]
650
        cmp     dx, [esi + SYS_BUTTON.pslot]
653
        jne     .next_button
651
        jne     .next_button
654
 
652
 
655
        ; does it contain cursor coordinates?
653
        ; does it contain cursor coordinates?
656
        mov     eax, [mouse.state.pos.x]
654
        mov     eax, [mouse.state.pos.x]
657
        sub     eax, [edi + WDATA.box.left]
655
        sub     eax, [edi + WDATA.box.left]
658
        sub     ax, [esi + SYS_BUTTON.left]
656
        sub     ax, [esi + SYS_BUTTON.left]
659
        jl      .next_button
657
        jl      .next_button
660
        sub     ax, [esi + SYS_BUTTON.width]
658
        sub     ax, [esi + SYS_BUTTON.width]
661
        jge     .next_button
659
        jge     .next_button
662
        mov     eax, [mouse.state.pos.y]
660
        mov     eax, [mouse.state.pos.y]
663
        sub     eax, [edi + WDATA.box.top]
661
        sub     eax, [edi + WDATA.box.top]
664
        sub     ax, [esi + SYS_BUTTON.top]
662
        sub     ax, [esi + SYS_BUTTON.top]
665
        jl      .next_button
663
        jl      .next_button
666
        sub     ax, [esi + SYS_BUTTON.height]
664
        sub     ax, [esi + SYS_BUTTON.height]
667
        jge     .next_button
665
        jge     .next_button
668
 
666
 
669
        ; okay, return it
667
        ; okay, return it
670
        shl     edx, 24
668
        shl     edx, 24
671
        mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
669
        mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
672
        mov     ax, [esi + SYS_BUTTON.id_lo]
670
        mov     ax, [esi + SYS_BUTTON.id_lo]
673
        and     eax, 0x0ffffff
671
        and     eax, 0x0ffffff
674
        or      eax, edx
672
        or      eax, edx
675
        mov     ebx, dword[esi + SYS_BUTTON.left - 2]
673
        mov     ebx, dword[esi + SYS_BUTTON.left - 2]
676
        mov     bx, [esi + SYS_BUTTON.top]
674
        mov     bx, [esi + SYS_BUTTON.top]
677
        jmp     .exit
675
        jmp     .exit
678
 
676
 
679
  .not_found:
677
  .not_found:
680
        xor     eax, eax
678
        xor     eax, eax
681
        xor     ebx, ebx
679
        xor     ebx, ebx
682
 
680
 
683
  .exit:
681
  .exit:
684
        pop     edi esi edx ecx
682
        pop     edi esi edx ecx
685
        ret
683
        ret
686
 
684
 
687
align 4
685
align 4
688
;-----------------------------------------------------------------
686
;-----------------------------------------------------------------
689
mouse._.check_sys_window_actions:
687
mouse._.check_sys_window_actions:
690
;< eax = action flags or 0
688
;< eax = action flags or 0
691
        ; is window movable?
689
        ; is window movable?
692
        test    byte[edi + WDATA.cl_titlebar + 3], 0x01
690
        test    byte[edi + WDATA.cl_titlebar + 3], 0x01
693
        jnz     .no_action
691
        jnz     .no_action
694
 
692
 
695
        mov     eax, [mouse.state.pos.x]
693
        mov     eax, [mouse.state.pos.x]
696
        mov     ebx, [mouse.state.pos.y]
694
        mov     ebx, [mouse.state.pos.y]
697
        sub     eax, [edi + WDATA.box.left]
695
        sub     eax, [edi + WDATA.box.left]
698
        sub     ebx, [edi + WDATA.box.top]
696
        sub     ebx, [edi + WDATA.box.top]
699
 
697
 
700
        ; is there a window titlebar under cursor?
698
        ; is there a window titlebar under cursor?
701
        push    eax
699
        push    eax
702
        call    window._.get_titlebar_height
700
        call    window._.get_titlebar_height
703
        cmp     ebx, eax
701
        cmp     ebx, eax
704
        pop     eax
702
        pop     eax
705
        jl      .move_action
703
        jl      .move_action
706
 
704
 
707
        ; no there isn't, can it be resized then?
705
        ; no there isn't, can it be resized then?
708
        mov     dl, [edi + WDATA.fl_wstyle]
706
        mov     dl, [edi + WDATA.fl_wstyle]
709
        and     dl, 0x0f
707
        and     dl, 0x0f
710
; NOTE: dangerous optimization, revise if window types changed
708
; NOTE: dangerous optimization, revise if window types changed
711
; this currently implies only types 2 and 3 could be resized
709
; this currently implies only types 2 and 3 could be resized
712
        test    dl, 2
710
        test    dl, 2
713
        jz      .no_action
711
        jz      .no_action
714
 
712
 
715
        mov     ecx, [edi + WDATA.box.width]
713
        mov     ecx, [edi + WDATA.box.width]
716
        add     ecx, -window.BORDER_SIZE
714
        add     ecx, -window.BORDER_SIZE
717
        mov     edx, [edi + WDATA.box.height]
715
        mov     edx, [edi + WDATA.box.height]
718
        add     edx, -window.BORDER_SIZE
716
        add     edx, -window.BORDER_SIZE
719
 
717
 
720
        ; is it rolled up?
718
        ; is it rolled up?
721
        test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP
719
        test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP
722
        jnz     .resize_w_or_e_action
720
        jnz     .resize_w_or_e_action
723
 
721
 
724
        cmp     eax, window.BORDER_SIZE
722
        cmp     eax, window.BORDER_SIZE
725
        jl      .resize_w_action
723
        jl      .resize_w_action
726
        cmp     eax, ecx
724
        cmp     eax, ecx
727
        jg      .resize_e_action
725
        jg      .resize_e_action
728
        cmp     ebx, edx
726
        cmp     ebx, edx
729
        jle     .no_action
727
        jle     .no_action
730
 
728
 
731
  .resize_s_action:
729
  .resize_s_action:
732
        cmp     eax, window.BORDER_SIZE + 10
730
        cmp     eax, window.BORDER_SIZE + 10
733
        jl      .resize_sw_action
731
        jl      .resize_sw_action
734
        add     ecx, -10
732
        add     ecx, -10
735
        cmp     eax, ecx
733
        cmp     eax, ecx
736
        jge     .resize_se_action
734
        jge     .resize_se_action
737
        mov     eax, mouse.WINDOW_RESIZE_S_FLAG
735
        mov     eax, mouse.WINDOW_RESIZE_S_FLAG
738
        jmp     .exit
736
        jmp     .exit
739
 
737
 
740
  .resize_w_or_e_action:
738
  .resize_w_or_e_action:
741
        cmp     eax, window.BORDER_SIZE + 10
739
        cmp     eax, window.BORDER_SIZE + 10
742
        jl      .resize_w_action.direct
740
        jl      .resize_w_action.direct
743
        add     ecx, -10
741
        add     ecx, -10
744
        cmp     eax, ecx
742
        cmp     eax, ecx
745
        jg      .resize_e_action.direct
743
        jg      .resize_e_action.direct
746
        jmp     .no_action
744
        jmp     .no_action
747
 
745
 
748
  .resize_w_action:
746
  .resize_w_action:
749
        add     edx, -10
747
        add     edx, -10
750
        cmp     ebx, edx
748
        cmp     ebx, edx
751
        jge     .resize_sw_action
749
        jge     .resize_sw_action
752
  .resize_w_action.direct:
750
  .resize_w_action.direct:
753
        mov     eax, mouse.WINDOW_RESIZE_W_FLAG
751
        mov     eax, mouse.WINDOW_RESIZE_W_FLAG
754
        jmp     .exit
752
        jmp     .exit
755
 
753
 
756
  .resize_e_action:
754
  .resize_e_action:
757
        add     edx, -10
755
        add     edx, -10
758
        cmp     ebx, edx
756
        cmp     ebx, edx
759
        jge     .resize_se_action
757
        jge     .resize_se_action
760
  .resize_e_action.direct:
758
  .resize_e_action.direct:
761
        mov     eax, mouse.WINDOW_RESIZE_E_FLAG
759
        mov     eax, mouse.WINDOW_RESIZE_E_FLAG
762
        jmp     .exit
760
        jmp     .exit
763
 
761
 
764
  .resize_sw_action:
762
  .resize_sw_action:
765
        mov     eax, mouse.WINDOW_RESIZE_SW_FLAG
763
        mov     eax, mouse.WINDOW_RESIZE_SW_FLAG
766
        jmp     .exit
764
        jmp     .exit
767
 
765
 
768
  .resize_se_action:
766
  .resize_se_action:
769
        mov     eax, mouse.WINDOW_RESIZE_SE_FLAG
767
        mov     eax, mouse.WINDOW_RESIZE_SE_FLAG
770
        jmp     .exit
768
        jmp     .exit
771
 
769
 
772
  .move_action:
770
  .move_action:
773
        mov     eax, mouse.WINDOW_MOVE_FLAG
771
        mov     eax, mouse.WINDOW_MOVE_FLAG
774
        jmp     .exit
772
        jmp     .exit
775
 
773
 
776
  .no_action:
774
  .no_action:
777
        xor     eax, eax
775
        xor     eax, eax
778
 
776
 
779
  .exit:
777
  .exit:
780
        ret
778
        ret
781
;-----------------------------------------------------------------------------
779
;-----------------------------------------------------------------------------
782
 
780
 
783
align 4
781
align 4
784
readmousepos:
782
readmousepos:
785
; eax=0 screen relative
783
; eax=0 screen relative
786
; eax=1 window relative
784
; eax=1 window relative
787
; eax=2 buttons pressed
785
; eax=2 buttons pressed
788
; eax=3 buttons pressed ext
786
; eax=3 buttons pressed ext
789
; eax=4 load cursor
787
; eax=4 load cursor
790
; eax=5 set cursor
788
; eax=5 set cursor
791
; eax=6 delete cursor
789
; eax=6 delete cursor
792
; eax=7 get mouse_z
790
; eax=7 get mouse_z
793
; eax=8 load cursor unicode
791
; eax=8 load cursor unicode
794
        cmp     ebx, 8
792
        cmp     ebx, 8
795
        ja      @f
793
        ja      @f
796
        jmp     dword[.mousefn+ebx*4]
794
        jmp     dword[.mousefn+ebx*4]
797
 
795
 
798
align 4
796
align 4
799
.mousefn:
797
.mousefn:
800
dd  .msscreen
798
dd  .msscreen
801
dd  .mswin
799
dd  .mswin
802
dd  .msbutton
800
dd  .msbutton
803
dd  .msbuttonExt
801
dd  .msbuttonExt
804
dd  .app_load_cursor
802
dd  .app_load_cursor
805
dd  .app_set_cursor
803
dd  .app_set_cursor
806
dd  .app_delete_cursor
804
dd  .app_delete_cursor
807
dd  .msz
805
dd  .msz
808
dd  .loadCursorUni
806
dd  .loadCursorUni
809
 
807
 
810
.msscreen:
808
.msscreen:
811
        mov     eax, [MOUSE_X]
809
        mov     eax, [MOUSE_X]
812
        shl     eax, 16
810
        shl     eax, 16
813
        mov     ax, [MOUSE_Y]
811
        mov     ax, [MOUSE_Y]
814
        mov     [esp + SYSCALL_STACK.eax], eax
812
        mov     [esp + SYSCALL_STACK.eax], eax
815
@@:
813
@@:
816
        ret
814
        ret
817
 
815
 
818
.mswin:
816
.mswin:
819
        mov     eax, [MOUSE_X]
817
        mov     eax, [MOUSE_X]
820
        shl     eax, 16
818
        shl     eax, 16
821
        mov     ax, [MOUSE_Y]
819
        mov     ax, [MOUSE_Y]
822
        mov     esi, [current_slot]
820
        mov     esi, [current_slot]
823
        mov     esi, [esi + APPDATA.window]
821
        mov     esi, [esi + APPDATA.window]
824
        mov     bx, word[esi + WDATA.box.left]
822
        mov     bx, word[esi + WDATA.box.left]
825
        shl     ebx, 16
823
        shl     ebx, 16
826
        mov     bx, word[esi + WDATA.box.top]
824
        mov     bx, word[esi + WDATA.box.top]
827
        sub     eax, ebx
825
        sub     eax, ebx
828
        sub     ax, word[esi + WDATA.clientbox.top]
826
        sub     ax, word[esi + WDATA.clientbox.top]
829
        rol     eax, 16
827
        rol     eax, 16
830
        sub     ax, word[esi + WDATA.clientbox.left]
828
        sub     ax, word[esi + WDATA.clientbox.left]
831
        rol     eax, 16
829
        rol     eax, 16
832
        mov     [esp + SYSCALL_STACK.eax], eax
830
        mov     [esp + SYSCALL_STACK.eax], eax
833
        ret
831
        ret
834
 
832
 
835
.msbutton:
833
.msbutton:
836
        movzx   eax, byte [BTN_DOWN]
834
        movzx   eax, byte [BTN_DOWN]
837
        mov     [esp + SYSCALL_STACK.eax], eax
835
        mov     [esp + SYSCALL_STACK.eax], eax
838
        ret
836
        ret
839
 
837
 
840
.msbuttonExt:
838
.msbuttonExt:
841
        mov     eax, [BTN_DOWN]
839
        mov     eax, [BTN_DOWN]
842
        mov     [esp + SYSCALL_STACK.eax], eax
840
        mov     [esp + SYSCALL_STACK.eax], eax
843
        ret
841
        ret
844
 
842
 
845
.app_load_cursor:
843
.app_load_cursor:
846
        cmp     ecx, OS_BASE
844
        cmp     ecx, OS_BASE
847
        jae     @f
845
        jae     @f
848
        stdcall load_cursor, ecx, edx
846
        stdcall load_cursor, ecx, edx
849
        mov     [esp + SYSCALL_STACK.eax], eax
847
        mov     [esp + SYSCALL_STACK.eax], eax
850
@@:
848
@@:
851
        ret
849
        ret
852
 
850
 
853
.loadCursorUni:
851
.loadCursorUni:
854
        cmp     ecx, OS_BASE
852
        cmp     ecx, OS_BASE
855
        jae     @b
853
        jae     @b
856
        push    ecx edx
854
        push    ecx edx
857
        stdcall kernel_alloc, maxPathLength
855
        stdcall kernel_alloc, maxPathLength
858
        mov     edi, eax
856
        mov     edi, eax
859
        pop     eax esi
857
        pop     eax esi
860
        push    edi
858
        push    edi
861
        call    getFullPath
859
        call    getFullPath
862
        pop     ebp
860
        pop     ebp
863
        test    eax, eax
861
        test    eax, eax
864
        jz      @f
862
        jz      @f
865
        stdcall load_cursor, ebp, LOAD_FROM_FILE
863
        stdcall load_cursor, ebp, LOAD_FROM_FILE
866
        mov     [esp + SYSCALL_STACK.eax], eax
864
        mov     [esp + SYSCALL_STACK.eax], eax
867
@@:
865
@@:
868
        stdcall kernel_free, ebp
866
        stdcall kernel_free, ebp
869
        ret
867
        ret
870
 
868
 
871
.app_set_cursor:
869
.app_set_cursor:
872
        stdcall set_cursor, ecx
870
        stdcall set_cursor, ecx
873
        mov     [esp + SYSCALL_STACK.eax], eax
871
        mov     [esp + SYSCALL_STACK.eax], eax
874
        ret
872
        ret
875
 
873
 
876
.app_delete_cursor:
874
.app_delete_cursor:
877
        stdcall delete_cursor, ecx
875
        stdcall delete_cursor, ecx
878
        mov     [esp + SYSCALL_STACK.eax], eax
876
        mov     [esp + SYSCALL_STACK.eax], eax
879
        ret
877
        ret
880
 
878
 
881
.msz:
879
.msz:
882
        mov     edi, [thread_count]
880
        mov     edi, [thread_count]
883
        movzx   edi, word [WIN_POS + edi*2]
881
        movzx   edi, word [WIN_POS + edi*2]
884
        cmp     edi, [current_slot_idx]
882
        cmp     edi, [current_slot_idx]
885
        jne     @f
883
        jne     @f
886
        mov     ax, [MOUSE_SCROLL_H]
884
        mov     ax, [MOUSE_SCROLL_H]
887
        shl     eax, 16
885
        shl     eax, 16
888
        mov     ax, [MOUSE_SCROLL_V]
886
        mov     ax, [MOUSE_SCROLL_V]
889
        mov     [esp + SYSCALL_STACK.eax], eax
887
        mov     [esp + SYSCALL_STACK.eax], eax
890
        and     [MOUSE_SCROLL_H], word 0
888
        and     [MOUSE_SCROLL_H], word 0
891
        and     [MOUSE_SCROLL_V], word 0
889
        and     [MOUSE_SCROLL_V], word 0
892
        ret
890
        ret
893
@@:
891
@@:
894
        and     [esp + SYSCALL_STACK.eax], dword 0
892
        and     [esp + SYSCALL_STACK.eax], dword 0
895
        ret
893
        ret