Subversion Repositories Kolibri OS

Rev

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

Rev 4446 Rev 5061
1
#include 
1
#include 
2
#include 
2
#include 
3
#include 
3
#include 
4
#include 
4
#include 
5
#include "winlib.h"
5
#include "winlib.h"
6
 
6
 
7
#define DBG(format,...)
7
#define DBG(format,...)
8
 
8
 
9
int draw_frame(window_t *win);
9
int draw_frame(window_t *win);
10
static int draw_window(window_t *win);
10
static int draw_window(window_t *win);
11
 
11
 
12
uint32_t main_cursor;
12
uint32_t main_cursor;
13
uint32_t cursor_ns;
13
uint32_t cursor_ns;
14
uint32_t cursor_we;
14
uint32_t cursor_we;
15
uint32_t cursor_nwse;
15
uint32_t cursor_nwse;
16
uint32_t cursor_nesw;
16
uint32_t cursor_nesw;
17
 
17
 
18
int win_font;
18
int win_font;
19
 
19
 
20
static window_t Window;
20
static window_t Window;
21
 
21
 
22
static pos_t    old_pos;
22
static pos_t    old_pos;
23
 
23
 
24
ctrl_t  *mouse_capture = NULL;
24
ctrl_t  *mouse_capture = NULL;
25
 
25
 
26
static link_t    timers;
26
static link_t    timers;
27
static uint32_t  realtime;
27
static uint32_t  realtime;
28
static uint32_t  wait_time;
28
static uint32_t  wait_time;
29
static uint32_t  exp_time;
29
static uint32_t  exp_time;
30
 
30
 
31
static int need_update;
31
static int need_update;
32
 
32
 
33
#define LOAD_FROM_MEM                1
33
#define LOAD_FROM_MEM                1
34
 
34
 
35
 
35
 
36
void adjust_frame(window_t *win);
36
void adjust_frame(window_t *win);
37
 
37
 
38
//#include "timer.h"
38
//#include "timer.h"
39
ctrl_t *win_get_child(window_t *win, int x, int y)
39
ctrl_t *win_get_child(window_t *win, int x, int y)
40
{
40
{
41
    ctrl_t *child = NULL;
41
    ctrl_t *child = NULL;
42
 
42
 
43
    if( win )
43
    if( win )
44
    {
44
    {
45
        if(pt_in_rect(&win->client, x, y))
45
        if(pt_in_rect(&win->client, x, y))
46
        {
46
        {
47
            ctrl_t *tmp = (ctrl_t*)win->child.next;
47
            ctrl_t *tmp = (ctrl_t*)win->child.next;
48
 
48
 
49
            while( &tmp->link != &win->child )
49
            while( &tmp->link != &win->child )
50
            {
50
            {
51
                if(pt_in_rect(&tmp->rc, x, y))
51
                if(pt_in_rect(&tmp->rc, x, y))
52
                {
52
                {
53
                    child = get_child(tmp, x, y);
53
                    child = get_child(tmp, x, y);
54
                    return child == NULL ? tmp : child;
54
                    return child == NULL ? tmp : child;
55
                };
55
                };
56
                tmp = (ctrl_t*)tmp->link.next;
56
                tmp = (ctrl_t*)tmp->link.next;
57
            };
57
            };
58
        }
58
        }
59
        else child = (ctrl_t*)(&win->frame);
59
        else child = (ctrl_t*)(&win->frame);
60
    };
60
    };
61
    return child;
61
    return child;
62
};
62
};
63
 
63
 
64
 
64
 
65
void init_frame(window_t *win);
65
void init_frame(window_t *win);
66
 
66
 
67
window_t *create_window(char *caption, int style, int x, int y,
67
window_t *create_window(char *caption, int style, int x, int y,
68
                          int w, int h, handler_t handler)
68
                          int w, int h, handler_t handler)
69
{
69
{
70
    char proc_info[1024];
70
    char proc_info[1024];
71
    int stride;
71
    int stride;
72
 
72
 
73
//    __asm__ __volatile__("int3");
73
//    __asm__ __volatile__("int3");
74
 
74
 
75
 
75
 
76
//    ctx_t *ctx = &Window.client_ctx;
76
//    ctx_t *ctx = &Window.client_ctx;
77
 
77
 
78
    if(handler==0) return 0;
78
    if(handler==0) return 0;
79
 
79
 
80
    BeginDraw();
80
    BeginDraw();
81
    DrawWindow(x, y, w-1, h-1,
81
    DrawWindow(x, y, w-1, h-1,
82
               NULL,0,0x41);
82
               NULL,0,0x41);
83
    EndDraw();
83
    EndDraw();
84
 
84
 
85
    get_proc_info(proc_info);
85
    get_proc_info(proc_info);
86
 
86
 
87
    x = *(uint32_t*)(proc_info+34);
87
    x = *(uint32_t*)(proc_info+34);
88
    y = *(uint32_t*)(proc_info+38);
88
    y = *(uint32_t*)(proc_info+38);
89
    w = *(uint32_t*)(proc_info+42)+1;
89
    w = *(uint32_t*)(proc_info+42)+1;
90
    h = *(uint32_t*)(proc_info+46)+1;
90
    h = *(uint32_t*)(proc_info+46)+1;
91
 
91
 
92
    Window.handler = handler;
92
    Window.handler = handler;
93
 //   Window.ctx = ctx;
93
 //   Window.ctx = ctx;
94
 
94
 
95
    list_initialize(&Window.link);
95
    list_initialize(&Window.link);
96
    list_initialize(&Window.child);
96
    list_initialize(&Window.child);
97
 
97
 
98
 
98
 
99
//    Window.bitmap.width  = 1920;
99
//    Window.bitmap.width  = 1920;
100
//    Window.bitmap.height = 1080;
100
//    Window.bitmap.height = 1080;
101
//    Window.bitmap.flags  = 0;
101
//    Window.bitmap.flags  = 0;
102
 
102
 
103
 //   if( create_bitmap(&Window.bitmap) )
103
 //   if( create_bitmap(&Window.bitmap) )
104
 //   {
104
 //   {
105
 //       printf("not enough memory for window bitmap\n");
105
 //       printf("not enough memory for window bitmap\n");
106
 //       return 0;
106
 //       return 0;
107
  //  }
107
  //  }
108
 
108
 
109
 //   ctx->pixmap   = &Window.bitmap;
109
 //   ctx->pixmap   = &Window.bitmap;
110
 //   ctx->offset_x = 0;
110
 //   ctx->offset_x = 0;
111
 //   ctx->offset_y = 0;
111
 //   ctx->offset_y = 0;
112
 
112
 
113
    Window.rc.l = x;
113
    Window.rc.l = x;
114
    Window.rc.t = y;
114
    Window.rc.t = y;
115
    Window.rc.r = x + w;
115
    Window.rc.r = x + w;
116
    Window.rc.b = y + h;
116
    Window.rc.b = y + h;
117
 
117
 
118
    Window.w = w;
118
    Window.w = w;
119
    Window.h = h;
119
    Window.h = h;
120
 
120
 
121
    Window.caption_txt = caption;
121
    Window.caption_txt = caption;
122
    Window.style = style;
122
    Window.style = style;
123
 
123
 
124
    Window.child_over  = NULL;
124
    Window.child_over  = NULL;
125
    Window.child_focus = NULL;
125
    Window.child_focus = NULL;
126
 
126
 
127
    init_caption(&Window);
127
    init_caption(&Window);
128
    init_panel(&Window);
128
    init_panel(&Window);
129
    init_frame(&Window);
129
    init_frame(&Window);
130
    send_message((ctrl_t*)&Window, MSG_SIZE, 0, 0);
130
    send_message((ctrl_t*)&Window, MSG_SIZE, 0, 0);
131
    return &Window;
131
    return &Window;
132
};
132
};
133
 
133
 
134
 
134
 
135
int def_window_proc(ctrl_t  *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
135
int def_window_proc(ctrl_t  *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
136
{
136
{
137
    ctrl_t   *child;
137
    ctrl_t   *child;
138
 
138
 
139
    window_t  *win = (window_t*)ctrl;
139
    window_t  *win = (window_t*)ctrl;
140
 
140
 
141
    switch(msg)
141
    switch(msg)
142
    {
142
    {
143
        case MSG_PAINT:
143
        case MSG_PAINT:
144
            draw_window(win);
144
            draw_window(win);
145
            break;
145
            break;
146
 
146
 
147
        case 2:
147
        case 2:
148
            child  = (ctrl_t*)win->child.next;
148
            child  = (ctrl_t*)win->child.next;
149
            while( &child->link != &win->child)
149
            while( &child->link != &win->child)
150
            {
150
            {
151
                send_message(child, 2, arg1, arg2);
151
                send_message(child, 2, arg1, arg2);
152
                child = (ctrl_t*)child->link.next;
152
                child = (ctrl_t*)child->link.next;
153
            };
153
            };
154
            break;
154
            break;
155
 
155
 
156
        case MSG_MOUSEMOVE:
156
        case MSG_MOUSEMOVE:
157
            child = win_get_child(win, arg2 & 0xFFFF, (arg2>>16));
157
            child = win_get_child(win, arg2 & 0xFFFF, (arg2>>16));
158
            if( win->child_over )
158
            if( win->child_over )
159
            {
159
            {
160
                if(child == win->child_over)
160
                if(child == win->child_over)
161
                    send_message(child, msg, 0, arg2);
161
                    send_message(child, msg, 0, arg2);
162
                else
162
                else
163
                    send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
163
                    send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
164
            }
164
            }
165
            else if( child )
165
            else if( child )
166
                send_message(child, MSG_MOUSEENTER, 0, arg2);
166
                send_message(child, MSG_MOUSEENTER, 0, arg2);
167
 
167
 
168
            win->child_over = child;
168
            win->child_over = child;
169
            if( child )
169
            if( child )
170
                send_message(child,msg,0,arg2);
170
                send_message(child,msg,0,arg2);
171
            else if(main_cursor != 0)
171
            else if(main_cursor != 0)
172
            {
172
            {
173
                set_cursor(0);
173
                set_cursor(0);
174
                main_cursor = 0;
174
                main_cursor = 0;
175
            }
175
            }
176
            break;
176
            break;
177
 
177
 
178
        case MSG_SIZE:
178
        case MSG_SIZE:
179
            break;
179
            break;
180
 
180
 
181
        default:
181
        default:
182
            child = win_get_child(win, arg2 & 0xFFFF, (arg2>>16));
182
            child = win_get_child(win, arg2 & 0xFFFF, (arg2>>16));
183
            win->child_over = child;
183
            win->child_over = child;
184
            if(child) send_message(child, msg, 0, arg2);
184
            if(child) send_message(child, msg, 0, arg2);
185
    };
185
    };
186
 
186
 
187
    return 0;
187
    return 0;
188
}
188
}
189
 
189
 
190
static int draw_window(window_t *win)
190
static int draw_window(window_t *win)
191
{
191
{
192
    ctrl_t *child;
192
    ctrl_t *child;
193
    void   *ctx;
193
    void   *ctx;
194
    rect_t *rc = &win->client;
194
    rect_t *rc = &win->client;
195
 
195
 
196
    draw_caption(&win->caption);
196
    draw_caption(&win->caption);
197
    draw_panel(&win->panel);
197
    draw_panel(&win->panel);
198
    send_message(win, MSG_DRAW_CLIENT,0,0);
198
    send_message(win, MSG_DRAW_CLIENT,0,0);
199
 
199
 
200
//    draw_frame(win);
200
//    draw_frame(win);
201
 
201
 
202
//    child  = (ctrl_t*)win->child.next;
202
//    child  = (ctrl_t*)win->child.next;
203
 
203
 
204
//    while( &child->link != &win->child)
204
//    while( &child->link != &win->child)
205
//    {
205
//    {
206
//        send_message(child, 1, 0, 0);
206
//        send_message(child, 1, 0, 0);
207
//        child = (ctrl_t*)child->link.next;
207
//        child = (ctrl_t*)child->link.next;
208
//    };
208
//    };
209
 
209
 
210
    return 0;
210
    return 0;
211
};
211
};
212
 
212
 
213
void blit_client(window_t *win)
213
void blit_client(window_t *win)
214
{
214
{
215
    int w, h;
215
    int w, h;
216
 
216
 
217
    w = win->client.r - win->client.l;
217
    w = win->client.r - win->client.l;
218
    h = win->client.b - win->client.t;
218
    h = win->client.b - win->client.t;
219
 
219
 
220
    Blit(win->ctx->pixmap->data, win->client.l, win->client.t,
220
    Blit(win->ctx->pixmap->data, win->client.l, win->client.t,
221
         0, 0, w, h, w, h,win->ctx->pixmap->pitch);
221
         0, 0, w, h, w, h,win->ctx->pixmap->pitch);
222
};
222
};
223
 
223
 
224
 
224
 
225
int show_window(window_t *win, int state)
225
int show_window(window_t *win, int state)
226
{
226
{
227
    win->win_state = state;
227
    win->win_state = state;
228
 
228
 
229
    draw_window(win);
229
    draw_window(win);
230
 
230
 
231
    BeginDraw();
231
    BeginDraw();
232
    DrawWindow(win->rc.l, win->rc.t, win->w-1, win->h-1,
232
    DrawWindow(win->rc.l, win->rc.t, win->w-1, win->h-1,
233
               NULL,0,0x41);
233
               NULL,0,0x41);
234
    EndDraw();
234
    EndDraw();
235
 
235
 
236
    blit_caption(&win->caption);
236
    blit_caption(&win->caption);
237
    blit_panel(&win->panel);
237
    blit_panel(&win->panel);
238
//    blit_client(win);
238
//    blit_client(win);
239
    return 0;
239
    return 0;
240
}
240
}
241
 
241
 
242
void window_update_layout(window_t *win)
242
void window_update_layout(window_t *win)
243
{
243
{
244
    char proc_info[1024];
244
    char proc_info[1024];
245
 
245
 
246
    int new_w, new_h;
246
    int new_w, new_h;
247
    uint8_t  state;
247
    uint8_t  state;
248
 
248
 
249
    int winx, winy, winw, winh;
249
    int winx, winy, winw, winh;
250
 
250
 
251
//    __asm__ __volatile__("int3");
251
//    __asm__ __volatile__("int3");
252
 
252
 
253
    get_proc_info(proc_info);
253
    get_proc_info(proc_info);
254
 
254
 
255
    winx = *(uint32_t*)(proc_info+34);
255
    winx = *(uint32_t*)(proc_info+34);
256
    winy = *(uint32_t*)(proc_info+38);
256
    winy = *(uint32_t*)(proc_info+38);
257
    winw = *(uint32_t*)(proc_info+42)+1;
257
    winw = *(uint32_t*)(proc_info+42)+1;
258
    winh = *(uint32_t*)(proc_info+46)+1;
258
    winh = *(uint32_t*)(proc_info+46)+1;
259
 
259
 
260
    state  = *(uint8_t*)(proc_info+70);
260
    state  = *(uint8_t*)(proc_info+70);
261
 
261
 
262
    if(state & 2)
262
    if(state & 2)
263
    {   win->win_state = MINIMIZED;
263
    {   win->win_state = MINIMIZED;
264
        return;
264
        return;
265
    }
265
    }
266
    if(state & 4)
266
    if(state & 4)
267
    {
267
    {
268
        win->win_state = ROLLED;
268
        win->win_state = ROLLED;
269
        return;
269
        return;
270
    };
270
    };
271
 
271
 
272
    if(state & 1)
272
    if(state & 1)
273
        state = MAXIMIZED;
273
        state = MAXIMIZED;
274
    else
274
    else
275
        state = NORMAL;
275
        state = NORMAL;
276
 
276
 
277
    if( (winx != win->rc.l) || (winy != win->rc.t) )
277
    if( (winx != win->rc.l) || (winy != win->rc.t) )
278
    {
278
    {
279
        win->rc.l = winx;
279
        win->rc.l = winx;
280
        win->rc.t = winy;
280
        win->rc.t = winy;
281
        win->rc.r = winx + win->w;
281
        win->rc.r = winx + win->w;
282
        win->rc.b = winy + win->h;
282
        win->rc.b = winy + win->h;
283
    };
283
    };
284
 
284
 
285
//    if( winw  == win->w &&
285
//    if( winw  == win->w &&
286
//        winh  == win->h &&
286
//        winh  == win->h &&
287
//        state == win->win_state)
287
//        state == win->win_state)
288
//        return;
288
//        return;
289
 
289
 
290
    if(win->win_state != FULLSCREEN)
290
    if(win->win_state != FULLSCREEN)
291
        win->win_state = state;
291
        win->win_state = state;
292
 
292
 
293
#if 0
293
#if 0
294
    int old_size;
294
    int old_size;
295
    int new_size;
295
    int new_size;
296
    int pitch;
296
    int pitch;
297
 
297
 
298
 
298
 
299
    old_size = win->bitmap.pitch * win->bitmap.height;
299
    old_size = win->bitmap.pitch * win->bitmap.height;
300
    old_size = (old_size+4095) & ~4095;
300
    old_size = (old_size+4095) & ~4095;
301
 
301
 
302
    pitch = ALIGN(win->w*4, 16);
302
    pitch = ALIGN(win->w*4, 16);
303
 
303
 
304
    new_size = pitch * win->h;
304
    new_size = pitch * win->h;
305
    new_size = (new_size+4095) & ~4095;
305
    new_size = (new_size+4095) & ~4095;
306
 
306
 
307
    if( new_size < old_size)
307
    if( new_size < old_size)
308
        user_unmap(win->bitmap.data, new_size, old_size-new_size);
308
        user_unmap(win->bitmap.data, new_size, old_size-new_size);
309
 
309
 
310
    win->bitmap.width = win->w;
310
    win->bitmap.width = win->w;
311
    win->bitmap.pitch = pitch;
311
    win->bitmap.pitch = pitch;
312
#endif
312
#endif
313
 
313
 
314
    win->rc.r = winx + winw;
314
    win->rc.r = winx + winw;
315
    win->rc.b = winy + winh;
315
    win->rc.b = winy + winh;
316
    win->w = winw;
316
    win->w = winw;
317
    win->h = winh;
317
    win->h = winh;
318
 
318
 
319
    update_caption_size(win);
319
    update_caption_size(win);
320
    update_panel_size(win);
320
    update_panel_size(win);
321
    adjust_frame(win);
321
    adjust_frame(win);
322
 
322
 
323
    send_message((ctrl_t*)win, MSG_SIZE, 0, 0);
323
    send_message((ctrl_t*)win, MSG_SIZE, 0, 0);
324
    draw_window(win);
324
    draw_window(win);
325
};
325
};
326
 
326
 
327
 
327
 
328
int send_mouse_message(window_t *win, uint32_t msg)
328
int send_mouse_message(window_t *win, uint32_t msg)
329
{
329
{
330
    ctrl_t *child;
330
    ctrl_t *child;
331
 
331
 
332
    if(mouse_capture)
332
    if(mouse_capture)
333
        return send_message(mouse_capture, msg, 0, old_pos.val);
333
        return send_message(mouse_capture, msg, 0, old_pos.val);
334
 
334
 
335
    if(pt_in_rect(&win->client, old_pos.x, old_pos.y))
335
    if(pt_in_rect(&win->client, old_pos.x, old_pos.y))
336
        return send_message((ctrl_t*)win, msg, 0, old_pos.val);
336
        return send_message((ctrl_t*)win, msg, 0, old_pos.val);
337
 
337
 
338
    if(win->win_state == FULLSCREEN)
338
    if(win->win_state == FULLSCREEN)
339
        return 0;
339
        return 0;
340
 
340
 
341
    if(pt_in_rect(&win->caption.ctrl.rc, old_pos.x, old_pos.y))
341
    if(pt_in_rect(&win->caption.ctrl.rc, old_pos.x, old_pos.y))
342
    {
342
    {
343
        return send_message(&win->caption.ctrl, msg, 0, old_pos.val);
343
        return send_message(&win->caption.ctrl, msg, 0, old_pos.val);
344
    }
344
    }
345
 
345
 
346
    if(pt_in_rect(&win->panel.ctrl.rc, old_pos.x, old_pos.y))
346
    if(pt_in_rect(&win->panel.ctrl.rc, old_pos.x, old_pos.y))
347
    {
347
    {
348
//        old_pos.x-= win->panel.ctrl.rc.l;
348
//        old_pos.x-= win->panel.ctrl.rc.l;
349
//        old_pos.y-= win->panel.ctrl.rc.t;
349
//        old_pos.y-= win->panel.ctrl.rc.t;
350
        return send_message(&win->panel.ctrl, msg, 0, old_pos.val);
350
        return send_message(&win->panel.ctrl, msg, 0, old_pos.val);
351
    }
351
    }
352
 
352
 
353
 
353
 
354
    return send_message(&win->frame, msg, 0, old_pos .val);
354
    return send_message(&win->frame, msg, 0, old_pos .val);
355
 
355
 
356
//    if( ( old_pos.x < win->rc.r) && ( old_pos.y < win->rc.b))
356
//    if( ( old_pos.x < win->rc.r) && ( old_pos.y < win->rc.b))
357
//        send_message((ctrl_t*)win, msg, 0, old_pos.val);
357
//        send_message((ctrl_t*)win, msg, 0, old_pos.val);
358
};
358
};
359
 
359
 
360
void do_sys_draw(window_t *win)
360
void do_sys_draw(window_t *win)
361
{
361
{
362
//    printf("%s win:%x\n", __FUNCTION__, win);
362
//    printf("%s win:%x\n", __FUNCTION__, win);
363
 
363
 
364
    window_update_layout(win);
364
    window_update_layout(win);
365
 
365
 
366
    BeginDraw();
366
    BeginDraw();
367
    DrawWindow(0,0,0,0, NULL, 0x000000,0x41);
367
    DrawWindow(0,0,0,0, NULL, 0x000000,0x41);
368
//    DefineButton(15, 15, 0x00000001, 0);
368
//    DefineButton(15, 15, 0x00000001, 0);
369
    EndDraw();
369
    EndDraw();
370
 
370
 
371
    send_message((ctrl_t*)win, MSG_DRAW_CLIENT, 0, 0);
371
    send_message((ctrl_t*)win, MSG_DRAW_CLIENT, 0, 0);
372
 
372
 
373
    if(win->win_state == FULLSCREEN)
373
    if(win->win_state == FULLSCREEN)
374
    {
374
    {
375
        need_update=0;
375
        need_update=0;
376
        return;
376
        return;
377
    };
377
    };
378
 
378
 
379
    blit_caption(&win->caption);
379
    blit_caption(&win->caption);
380
    blit_panel(&win->panel);
380
    blit_panel(&win->panel);
381
 
381
 
382
//    blit_client(win);
382
//    blit_client(win);
383
    need_update=0;
383
    need_update=0;
384
};
384
};
385
 
385
 
386
static void do_sys_mouse(window_t *win)
386
static void do_sys_mouse(window_t *win)
387
{
387
{
388
    static uint32_t  mouse_click_time;
388
    static uint32_t  mouse_click_time;
389
    static int  mouse_action;
389
    static int  mouse_action;
390
    static int  old_buttons;
390
    static int  old_buttons;
391
    int         buttons;
391
    int         buttons;
392
    uint32_t    wheels;
392
    uint32_t    wheels;
393
    uint32_t    click_time;
393
    uint32_t    click_time;
394
    int         action;
394
    int         action;
395
 
395
 
396
    pos_t       pos;
396
    pos_t       pos;
397
 
397
 
398
    mouse_action = 0;
398
    mouse_action = 0;
399
    pos = get_mouse_pos();
399
    pos = GetMousePos(POS_WINDOW);
400
 
400
 
401
    if(pos.val != old_pos.val)
401
    if(pos.val != old_pos.val)
402
    {
402
    {
403
        mouse_action = 0x80000000;
403
        mouse_action = 0x80000000;
404
        old_pos = pos;
404
        old_pos = pos;
405
    };
405
    };
406
//    printf("pos x%d y%d\n", pos.x, pos.y);
406
//    printf("pos x%d y%d\n", pos.x, pos.y);
407
 
407
 
408
    buttons = get_mouse_buttons();
408
    buttons = GetMouseButtons();
409
    wheels = get_mouse_wheels();
409
    wheels = get_mouse_wheels();
410
 
410
 
411
    if( wheels & 0xFFFF){
411
    if( wheels & 0xFFFF){
412
        wheels = (short)wheels>0 ? MSG_WHEELDOWN : MSG_WHEELUP;
412
        wheels = (short)wheels>0 ? MSG_WHEELDOWN : MSG_WHEELUP;
413
        send_mouse_message(win, wheels);
413
        send_mouse_message(win, wheels);
414
    }
414
    }
415
 
415
 
416
    if((action = (buttons ^ old_buttons))!=0)
416
    if((action = (buttons ^ old_buttons))!=0)
417
    {
417
    {
418
        mouse_action|= action<<3;
418
        mouse_action|= action<<3;
419
        mouse_action|= buttons & ~old_buttons;
419
        mouse_action|= buttons & ~old_buttons;
420
    }
420
    }
421
    old_buttons = buttons;
421
    old_buttons = buttons;
422
 
422
 
423
    if(mouse_action & 0x80000000) {
423
    if(mouse_action & 0x80000000) {
424
        DBG("mouse move \n\r");
424
        DBG("mouse move \n\r");
425
        send_mouse_message(win, MSG_MOUSEMOVE);
425
        send_mouse_message(win, MSG_MOUSEMOVE);
426
    };
426
    };
427
 
427
 
428
    if(mouse_action & 0x09)
428
    if(mouse_action & 0x09)
429
    {
429
    {
430
        if((mouse_action & 0x09)==0x09)
430
        if((mouse_action & 0x09)==0x09)
431
        {
431
        {
432
//            printf("left button down x= %d y= %d\n\r", old_x.x, old_x.y);
432
//            printf("left button down x= %d y= %d\n\r", old_x.x, old_x.y);
433
            click_time = get_tick_count();
433
            click_time = get_tick_count();
434
            if(click_time < mouse_click_time+35) {
434
            if(click_time < mouse_click_time+35) {
435
                mouse_click_time = click_time;
435
                mouse_click_time = click_time;
436
                send_mouse_message(win,MSG_LBTNDBLCLK);
436
                send_mouse_message(win,MSG_LBTNDBLCLK);
437
            }
437
            }
438
            else {
438
            else {
439
              mouse_click_time = click_time;
439
              mouse_click_time = click_time;
440
              send_mouse_message(win,MSG_LBTNDOWN);
440
              send_mouse_message(win,MSG_LBTNDOWN);
441
            };
441
            };
442
        }
442
        }
443
        else {
443
        else {
444
//            printf("left button up \n\r");
444
//            printf("left button up \n\r");
445
            send_mouse_message(win,MSG_LBTNUP);
445
            send_mouse_message(win,MSG_LBTNUP);
446
        }
446
        }
447
    };
447
    };
448
 
448
 
449
    if(mouse_action & 0x12)
449
    if(mouse_action & 0x12)
450
    {
450
    {
451
        if((mouse_action & 0x12)==0x12) {
451
        if((mouse_action & 0x12)==0x12) {
452
            DBG("right button down \n\r");
452
            DBG("right button down \n\r");
453
            send_mouse_message(win,MSG_RBTNDOWN);
453
            send_mouse_message(win,MSG_RBTNDOWN);
454
        }
454
        }
455
        else {
455
        else {
456
            DBG("right button up \n\r");
456
            DBG("right button up \n\r");
457
            send_mouse_message(win,MSG_RBTNUP);
457
            send_mouse_message(win,MSG_RBTNUP);
458
        };
458
        };
459
    };
459
    };
460
    if(mouse_action & 0x24)
460
    if(mouse_action & 0x24)
461
    {
461
    {
462
        if((mouse_action & 0x24)==0x24){
462
        if((mouse_action & 0x24)==0x24){
463
            DBG("middle button down \n\r");
463
            DBG("middle button down \n\r");
464
            send_mouse_message(win,MSG_MBTNDOWN);
464
            send_mouse_message(win,MSG_MBTNDOWN);
465
        }
465
        }
466
        else {
466
        else {
467
            DBG("middle button up \n\r");
467
            DBG("middle button up \n\r");
468
            send_mouse_message(win,MSG_MBTNUP);
468
            send_mouse_message(win,MSG_MBTNUP);
469
        };
469
        };
470
    };
470
    };
471
 
471
 
472
 
472
 
473
};
473
};
474
 
474
 
475
 
475
 
476
void  run_window(window_t *win)
476
void  run_window(window_t *win)
477
{
477
{
478
    int ev;
478
    int ev;
479
    oskey_t   key;
479
    oskey_t   key;
480
 
480
 
481
//    buttons   = get_mouse_buttons();
481
//    buttons   = get_mouse_buttons();
482
//    wheels    = get_mouse_wheels();
482
//    wheels    = get_mouse_wheels();
483
    realtime  = get_tick_count();
483
    realtime  = get_tick_count();
484
    exp_time  = -1;
484
    exp_time  = -1;
485
 
485
 
486
    while(1)
486
    while(1)
487
    {
487
    {
488
        wait_time = exp_time - realtime;
488
        wait_time = exp_time - realtime;
489
 
489
 
490
        ev = wait_for_event(wait_time);
490
        ev = wait_for_event(wait_time);
491
 
491
 
492
        realtime = get_tick_count();
492
        realtime = get_tick_count();
493
 
493
 
494
//        if(exp_time < realtime)
494
//        if(exp_time < realtime)
495
//            exp_time = update_timers(realtime);
495
//            exp_time = update_timers(realtime);
496
 
496
 
497
        switch(ev)
497
        switch(ev)
498
        {
498
        {
499
            case MSG_PAINT:
499
            case MSG_PAINT:
500
                do_sys_draw(win);
500
                do_sys_draw(win);
501
                continue;
501
                continue;
502
 
502
 
503
            case 2:
503
            case 2:
504
                printf("key pressed\n");
504
                printf("key pressed\n");
505
                key = get_key();
505
                key = get_key();
506
                if( key.state == 0)
506
                if( key.state == 0)
507
                    send_message((ctrl_t*)win, ev, 0, key.code);
507
                    send_message((ctrl_t*)win, ev, 0, key.code);
508
                continue;
508
                continue;
509
 
509
 
510
            case 3:
510
            case 3:
511
                printf("Button pressed\n");
511
                printf("Button pressed\n");
512
                continue;
512
                continue;
513
 
513
 
514
            case 6:
514
            case 6:
515
                do_sys_mouse(win);
515
                do_sys_mouse(win);
516
                continue;
516
                continue;
517
 
517
 
518
            default:
518
            default:
519
                printf("event %d\n", ev);
519
                printf("event %d\n", ev);
520
                continue;
520
                continue;
521
        };
521
        };
522
    };
522
    };
523
}
523
}
524
 
524
 
525
void render_time(void *render);
525
void render_time(void *render);
526
 
526
 
527
void  run_render(window_t *win, void *render)
527
void  run_render(window_t *win, void *render)
528
{
528
{
529
    int ev;
529
    int ev;
530
    oskey_t   key;
530
    oskey_t   key;
531
    int button;
531
    int button;
532
 
532
 
533
    realtime  = get_tick_count();
533
    realtime  = get_tick_count();
534
    exp_time  = -1;
534
    exp_time  = -1;
535
 
535
 
536
    while(win->win_command != WIN_CLOSED)
536
    while(win->win_command != WIN_CLOSED)
537
    {
537
    {
538
        wait_time = exp_time - realtime;
538
        wait_time = exp_time - realtime;
539
 
539
 
540
        ev = check_os_event();
540
        ev = check_os_event();
541
 
541
 
542
        realtime = get_tick_count();
542
        realtime = get_tick_count();
543
 
543
 
544
//        if(exp_time < realtime)
544
//        if(exp_time < realtime)
545
//            exp_time = update_timers(realtime);
545
//            exp_time = update_timers(realtime);
546
 
546
 
547
        switch(ev)
547
        switch(ev)
548
        {
548
        {
549
            case MSG_PAINT:
549
            case MSG_PAINT:
550
                do_sys_draw(win);
550
                do_sys_draw(win);
551
                break;
551
                break;
552
 
552
 
553
            case 2:
553
            case 2:
554
                key = get_key();
554
                key = get_key();
555
                if( key.state == 0)
555
                if( key.state == 0)
556
                    send_message((ctrl_t*)win, ev, 0, key.code);
556
                    send_message((ctrl_t*)win, ev, 0, key.code);
557
                break;
557
                break;
558
 
558
 
559
            case 3:
559
            case 3:
560
                button = get_os_button();
560
                button = get_os_button();
561
                if(button == 1)
561
                if(button == 1)
562
                    win->win_command = WIN_CLOSED;
562
                    win->win_command = WIN_CLOSED;
563
                break;
563
                break;
564
 
564
 
565
            case 6:
565
            case 6:
566
                do_sys_mouse(win);
566
                do_sys_mouse(win);
567
                break;
567
                break;
568
 
568
 
569
            default:
569
            default:
570
                break;
570
                break;
571
        };
571
        };
572
 
572
 
573
        render_time(render);
573
        render_time(render);
574
    };
574
    };
575
};
575
};
576
 
576
 
577
 
577
 
578
 
578
 
579
extern unsigned char res_cursor_ns[];
579
extern unsigned char res_cursor_ns[];
580
extern unsigned char res_cursor_we[];
580
extern unsigned char res_cursor_we[];
581
extern unsigned char res_cursor_nwse[];
581
extern unsigned char res_cursor_nwse[];
582
extern unsigned char res_cursor_nesw[];
582
extern unsigned char res_cursor_nesw[];
583
 
583
 
584
int init_resources()
584
int init_resources()
585
{
585
{
586
    cursor_ns   = load_cursor(res_cursor_ns, LOAD_FROM_MEM);
586
    cursor_ns   = load_cursor(res_cursor_ns, LOAD_FROM_MEM);
587
    cursor_we   = load_cursor(res_cursor_we, LOAD_FROM_MEM);
587
    cursor_we   = load_cursor(res_cursor_we, LOAD_FROM_MEM);
588
    cursor_nwse = load_cursor(res_cursor_nwse, LOAD_FROM_MEM);
588
    cursor_nwse = load_cursor(res_cursor_nwse, LOAD_FROM_MEM);
589
    cursor_nesw = load_cursor(res_cursor_nesw, LOAD_FROM_MEM);
589
    cursor_nesw = load_cursor(res_cursor_nesw, LOAD_FROM_MEM);
590
 
590
 
591
    win_font =  init_fontlib();
591
    win_font =  init_fontlib();
592
 
592
 
593
    return 1;
593
    return 1;
594
}
594
}
595
 
595
 
596
int  fini_winlib()
596
int  fini_winlib()
597
{
597
{
598
    int ret;
598
    int ret;
599
 
599
 
600
    ret =  destroy_cursor(cursor_nesw);
600
    ret =  destroy_cursor(cursor_nesw);
601
    ret |= destroy_cursor(cursor_nwse);
601
    ret |= destroy_cursor(cursor_nwse);
602
    ret |= destroy_cursor(cursor_we);
602
    ret |= destroy_cursor(cursor_we);
603
    ret |= destroy_cursor(cursor_ns);
603
    ret |= destroy_cursor(cursor_ns);
604
 
604
 
605
    return ret;
605
    return ret;
606
};
606
};
607
 
607
 
608
 
608
 
609
 
609
 
610
void  init_winlib(void)
610
void  init_winlib(void)
611
{
611
{
612
    __asm__ __volatile__(
612
    __asm__ __volatile__(
613
    "int $0x40"
613
    "int $0x40"
614
    ::"a"(40), "b"(0xC0000027));
614
    ::"a"(40), "b"(0xC0000027));
615
    __asm__ __volatile__(
615
    __asm__ __volatile__(
616
    "int $0x40"
616
    "int $0x40"
617
    ::"a"(66), "b"(1),"c"(1));
617
    ::"a"(66), "b"(1),"c"(1));
618
 
618
 
619
    init_resources();
619
    init_resources();
620
    list_initialize(&timers);
620
    list_initialize(&timers);
621
};
621
};
622
 
622
 
623
//ctx_t *get_window_ctx()
623
//ctx_t *get_window_ctx()
624
//{
624
//{
625
//    return &Window.client_ctx;
625
//    return &Window.client_ctx;
626
//};
626
//};
627
 
627
 
628
void update_rect(ctrl_t *ctrl)
628
void update_rect(ctrl_t *ctrl)
629
{
629
{
630
    int ctx_w, ctx_h;
630
    int ctx_w, ctx_h;
631
    int src_x, src_y;
631
    int src_x, src_y;
632
 
632
 
633
    src_x = ctrl->rc.l - ctrl->ctx->offset_x;
633
    src_x = ctrl->rc.l - ctrl->ctx->offset_x;
634
    src_y = ctrl->rc.t - ctrl->ctx->offset_y;
634
    src_y = ctrl->rc.t - ctrl->ctx->offset_y;
635
 
635
 
636
    ctx_w = ctrl->parent->w;
636
    ctx_w = ctrl->parent->w;
637
    ctx_h = ctrl->parent->h;
637
    ctx_h = ctrl->parent->h;
638
 
638
 
639
    Blit(ctrl->ctx->pixmap->data, ctrl->rc.l, ctrl->rc.t, src_x, src_y,
639
    Blit(ctrl->ctx->pixmap->data, ctrl->rc.l, ctrl->rc.t, src_x, src_y,
640
         ctrl->w, ctrl->h, ctx_w, ctx_h, ctrl->ctx->pixmap->pitch);
640
         ctrl->w, ctrl->h, ctx_w, ctx_h, ctrl->ctx->pixmap->pitch);
641
 
641
 
642
//    need_update++;
642
//    need_update++;
643
};
643
};
644
 
644
 
645
 
645
 
646
void Blit(void *bitmap, int dst_x, int dst_y,
646
void Blit(void *bitmap, int dst_x, int dst_y,
647
                        int src_x, int src_y, int w, int h,
647
                        int src_x, int src_y, int w, int h,
648
                        int src_w, int src_h, int stride)
648
                        int src_w, int src_h, int stride)
649
{
649
{
650
    volatile struct blit_call bc;
650
    volatile struct blit_call bc;
651
 
651
 
652
    bc.dstx = dst_x;
652
    bc.dstx = dst_x;
653
    bc.dsty = dst_y;
653
    bc.dsty = dst_y;
654
    bc.w    = w;
654
    bc.w    = w;
655
    bc.h    = h;
655
    bc.h    = h;
656
    bc.srcx = src_x;
656
    bc.srcx = src_x;
657
    bc.srcy = src_y;
657
    bc.srcy = src_y;
658
    bc.srcw = src_w;
658
    bc.srcw = src_w;
659
    bc.srch = src_h;
659
    bc.srch = src_h;
660
    bc.stride = stride;
660
    bc.stride = stride;
661
    bc.bitmap = bitmap;
661
    bc.bitmap = bitmap;
662
 
662
 
663
    __asm__ __volatile__(
663
    __asm__ __volatile__(
664
    "int $0x40"
664
    "int $0x40"
665
    ::"a"(73),"b"(0x20),"c"(&bc.dstx));
665
    ::"a"(73),"b"(0x20),"c"(&bc.dstx));
666
 
666
 
667
};
667
};
668
 
668
 
669
ctrl_t *get_child(ctrl_t *ctrl, int x, int y)
669
ctrl_t *get_child(ctrl_t *ctrl, int x, int y)
670
{
670
{
671
    ctrl_t *child = NULL;
671
    ctrl_t *child = NULL;
672
 
672
 
673
    ctrl_t *tmp = (ctrl_t*)ctrl->child.next;
673
    ctrl_t *tmp = (ctrl_t*)ctrl->child.next;
674
 
674
 
675
    while( &tmp->link != &ctrl->child )
675
    while( &tmp->link != &ctrl->child )
676
    {
676
    {
677
        if(pt_in_rect(&tmp->rc, x, y))
677
        if(pt_in_rect(&tmp->rc, x, y))
678
        {
678
        {
679
            child = get_child(tmp, x, y);
679
            child = get_child(tmp, x, y);
680
            return child == NULL ? tmp : child;
680
            return child == NULL ? tmp : child;
681
        };
681
        };
682
        tmp = (ctrl_t*)tmp->link.next;
682
        tmp = (ctrl_t*)tmp->link.next;
683
    };
683
    };
684
    return child;
684
    return child;
685
};
685
};
686
 
686
 
687
ctrl_t *capture_mouse(ctrl_t *newm)
687
ctrl_t *capture_mouse(ctrl_t *newm)
688
{
688
{
689
    ctrl_t *old = mouse_capture;
689
    ctrl_t *old = mouse_capture;
690
 
690
 
691
    mouse_capture = newm;
691
    mouse_capture = newm;
692
 
692
 
693
    __asm__ __volatile__(
693
    __asm__ __volatile__(
694
    "int $0x40"
694
    "int $0x40"
695
    ::"a"(40), "b"(0x80000027));
695
    ::"a"(40), "b"(0x80000027));
696
 
696
 
697
    return old;
697
    return old;
698
}
698
}
699
 
699
 
700
void release_mouse(void)
700
void release_mouse(void)
701
{
701
{
702
    mouse_capture = NULL;
702
    mouse_capture = NULL;
703
    __asm__ __volatile__(
703
    __asm__ __volatile__(
704
    "int $0x40"
704
    "int $0x40"
705
    ::"a"(40), "b"(0xC0000027));
705
    ::"a"(40), "b"(0xC0000027));
706
}
706
}
707
>
707
>
708
>
708
>