OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [mwin/] [winlib/] [scrlbar.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
3
 * Portions Copyright (c) 1999, 2000, Wei Yongming.
4
 * jmt: scrollbar thumb ported
5
 *
6
 * Microwindows win32 Scrollbars control
7
 */
8
#include <stdio.h>
9
#include <stdlib.h>
10
#include <string.h>
11
#define MWINCLUDECOLORS /* jmt: for color macros */
12
#include "windows.h"
13
#include "wintern.h"
14
#include "wintools.h"
15
 
16
/* scrollbar status/positions*/
17
#define SBS_UNKNOWN             0x0000
18
#define SBS_LEFTARROW           0x0001
19
#define SBS_RIGHTARROW          0x0002
20
#define SBS_LEFTSPACE           0x0004
21
#define SBS_RIGHTSPACE          0x0008
22
#define SBS_HORZTHUMB           0x0010
23
#define SBS_UPARROW             0x0020
24
#define SBS_DOWNARROW           0x0040
25
#define SBS_UPSPACE             0x0080
26
#define SBS_DOWNSPACE           0x0100
27
#define SBS_VERTTHUMB           0x0200
28
#define SBS_MASK                0x03ff
29
#define SBS_DISABLED            0x4000
30
#define SBS_HIDE                0x8000
31
 
32
 
33
#define MWM_DEFBARLEN   18
34
#define MWM_MINBARLEN   8
35
 
36
static LRESULT CALLBACK
37
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
38
 
39
 
40
int WINAPI MwRegisterScrollbarControl(HINSTANCE hInstance)
41
{
42
        WNDCLASS        wc;
43
 
44
        wc.style        = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_GLOBALCLASS;
45
        wc.lpfnWndProc  = (WNDPROC)ScrollbarControlProc;
46
        wc.cbClsExtra   = 0;
47
        wc.cbWndExtra   = 0;
48
        wc.hInstance    = hInstance;
49
        wc.hIcon        = NULL;
50
        wc.hCursor      = 0; /*LoadCursor(NULL, IDC_ARROW);*/
51
        wc.hbrBackground= GetStockObject(WHITE_BRUSH);
52
        wc.lpszMenuName = NULL;
53
        wc.lpszClassName= "SCROLLBAR";
54
 
55
        return RegisterClass(&wc);
56
}
57
 
58
static DWORD GetWindowStyle (HWND hwnd)
59
{
60
        return hwnd->style;
61
}
62
 
63
static int
64
wndGetBorder(HWND hwnd)
65
{
66
        if (hwnd->style & WS_BORDER)  {
67
                if ((hwnd->style & WS_CAPTION) == WS_CAPTION)
68
                        return mwSYSMETRICS_CXFRAME;
69
                return mwSYSMETRICS_CXBORDER;
70
        }
71
        return 0;
72
}
73
 
74
static BOOL
75
wndGetVScrollBarRect (HWND hwnd, RECT* rcVBar)
76
{
77
        int cx,cy; RECT rc;
78
        MWSCROLLBARINFO* pData;
79
 
80
        pData = (MWSCROLLBARINFO *)hwnd->userdata;
81
        rc = hwnd->winrect;
82
        cx=rc.right-rc.left;
83
        cy=rc.bottom-rc.top;
84
 
85
        rcVBar->left = hwnd->winrect.right - cx
86
                - wndGetBorder (hwnd);
87
        rcVBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
88
        rcVBar->top  = hwnd->winrect.top;
89
        rcVBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
90
 
91
        return TRUE;
92
}
93
 
94
static BOOL
95
wndGetHScrollBarRect (HWND hwnd, RECT* rcHBar)
96
{
97
        int cx,cy; RECT rc;
98
        MWSCROLLBARINFO* pData;
99
 
100
        pData = (MWSCROLLBARINFO *)hwnd->userdata;
101
        rc = hwnd->winrect;
102
        cx=rc.right-rc.left;
103
        cy=rc.bottom-rc.top;
104
 
105
        rcHBar->top = hwnd->winrect.bottom - cy
106
                        - wndGetBorder (hwnd);
107
        rcHBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
108
        rcHBar->left  = hwnd->winrect.left;
109
        rcHBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
110
 
111
        return TRUE;
112
}
113
 
114
void
115
MwPaintScrollbars(HWND hwnd, HDC hdc, DWORD style)
116
{
117
        BOOL    vertbar = (style==SBS_VERT);
118
        BOOL    horzbar = (style==SBS_HORZ);
119
        BOOL    fGotDC = FALSE;
120
        RECT    rc,rc2;
121
 
122
        POINT   p3[3];
123
        int     shrink=2;
124
 
125
        int start = 0;
126
        RECT rcHBar, rcVBar;
127
 
128
        int cx,cy;
129
        MWSCROLLBARINFO* pData;
130
 
131
        pData = (MWSCROLLBARINFO *)hwnd->userdata;
132
        rc = hwnd->winrect;
133
        cx=rc.right-rc.left;
134
        cy=rc.bottom-rc.top;
135
 
136
        if (!hdc && (horzbar || vertbar)) {
137
                hdc = GetWindowDC(hwnd);
138
                fGotDC = TRUE;
139
        }
140
 
141
        if (vertbar) {
142
 
143
#if 1
144
                /* bkgnd */
145
                rc2.left=rc.left; rc2.right=rc2.left+ cx;
146
                rc2.top=rc.top;
147
                rc2.bottom=rc2.top+ cx;
148
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
149
                rc2.top=rc.bottom- cx;
150
                rc2.bottom=rc2.top+ cx;
151
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
152
#endif
153
                /* up */
154
                Draw3dUpDownState(hdc, rc.left, rc.top,
155
                        cx, cx,
156
                        pData->status & SBS_UPARROW);
157
                /* down */
158
                Draw3dUpDownState(hdc, rc.left,rc.bottom-cx,
159
                        cx, cx,
160
                        pData->status & SBS_DOWNARROW);
161
/* jmt: draw arrows */
162
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
163
                /* up */
164
                p3[0].x= rc.left + (cx/2) - 1;
165
                p3[0].y= rc.top + 2 + shrink;
166
                p3[1].x= rc.left + 2 + shrink - 1;
167
                p3[1].y= rc.top + (cx-4) - shrink;
168
                p3[2].x= rc.left + (cx-4) - shrink;
169
                p3[2].y= rc.top + (cx-4) - shrink;
170
                Polygon(hdc,p3,3);
171
                /* down */
172
                p3[0].x= rc.left + (cx/2) - 1;
173
                p3[0].y= rc.bottom - 4 - shrink;
174
                p3[1].x= rc.left + 2 + shrink - 1;
175
                p3[1].y= rc.bottom-cx + 2 + shrink;
176
                p3[2].x= rc.left + (cx-4) - shrink;
177
                p3[2].y= rc.bottom-cx + 2 + shrink;
178
                Polygon(hdc,p3,3);
179
 
180
                /* draw moving bar */
181
 
182
                wndGetVScrollBarRect (hwnd, &rcVBar);
183
                rcVBar.left -- ;
184
                /*rcVBar.right -- ;*/
185
 
186
                start = rcVBar.top + cx + pData->barStart;
187
 
188
                if (start + pData->barLen > rcVBar.bottom)
189
                        start = rcVBar.bottom - pData->barLen;
190
 
191
                if (pData->barLen == 0)
192
                        pData->barLen=rc.bottom-rc.top-(cx*2);
193
 
194
                /* bkgnd */
195
                rc2.left=rc.left; rc2.right=rc.right/*-1*/;
196
                rc2.top=rc.top+cx;
197
                rc2.bottom=start;
198
                if (rc2.bottom>rc2.top)
199
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
200
 
201
                rc2.top=start+pData->barLen;
202
                rc2.bottom=rc.bottom-cx;
203
                if (rc2.bottom>rc2.top)
204
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
205
 
206
                Draw3dUpFrame (hdc, rcVBar.left, start, rcVBar.right,
207
                        start + pData->barLen);
208
                /*printf("barv:(l,t,r,b):(%d,%d,%d,%d)\n",
209
                        rcVBar.left, start, rcVBar.right,
210
                        start + pData->barLen);*/
211
 
212
        }
213
        if (horzbar) {
214
#if 1
215
                /* bkgnd */
216
                rc2.top=rc.top; rc2.bottom=rc2.top+ cy;
217
                rc2.left=rc.left;
218
                rc2.right=rc2.left+ cy;
219
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
220
                rc2.left=rc.right- cy;
221
                rc2.right=rc2.left+ cy;
222
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
223
#endif
224
                /* left */
225
                Draw3dUpDownState(hdc, rc.left, rc.top,
226
                        cy, cy,
227
                        pData->status & SBS_LEFTARROW);
228
                /* right */
229
                Draw3dUpDownState(hdc, rc.right-cy, rc.top,
230
                        cy, cy,
231
                        pData->status & SBS_RIGHTARROW);
232
/* jmt: draw arrows */
233
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
234
                /* left */
235
                p3[0].x= rc.left + 2 + shrink;
236
                p3[0].y= rc.top + (cy/2) ;
237
                p3[1].x= rc.left + (cy-4) - shrink ;
238
                p3[1].y= rc.top + 2 + shrink;
239
                p3[2].x= rc.left + (cy-4) - shrink;
240
                p3[2].y= rc.bottom - 4 - shrink + 1;
241
                Polygon(hdc,p3,3);
242
                /* right */
243
                p3[0].x= rc.right - 4 - shrink;
244
                p3[0].y= rc.top + (cy/2) ;
245
                p3[1].x= rc.right-cy + 2 + shrink ;
246
                p3[1].y= rc.top + 2 + shrink;
247
                p3[2].x= rc.right-cy + 2 + shrink;
248
                p3[2].y= rc.bottom - 4 - shrink + 1;
249
                Polygon(hdc,p3,3);
250
 
251
                /* draw moving bar. */
252
 
253
                wndGetHScrollBarRect (hwnd, &rcHBar);
254
                rcHBar.top -- ;
255
                /*rcHBar.bottom -- ;*/
256
 
257
                start = rcHBar.left + cy + pData->barStart;
258
 
259
                if (start + pData->barLen > rcHBar.right)
260
                        start = rcHBar.right - pData->barLen;
261
 
262
                if (pData->barLen == 0)
263
                        pData->barLen=rc.right-rc.left-(cy*2);
264
 
265
                /* bkgnd */
266
                rc2.top=rc.top; rc2.bottom=rc.bottom/*-1*/;
267
                rc2.left=rc.left+cy;
268
                rc2.right=start;
269
                if (rc2.right>rc2.left)
270
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
271
 
272
                rc2.left=start+pData->barLen;
273
                rc2.right=rc.right-cy;
274
                if (rc2.right>rc2.left)
275
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
276
 
277
                Draw3dUpFrame (hdc, start, rcHBar.top, start + pData->barLen,
278
                        rcHBar.bottom);
279
                /*printf("barh:(l,t,r,b):(%d,%d,%d,%d)\n",
280
                        start, rcHBar.top, start + pData->barLen,
281
                        rcHBar.bottom);*/
282
        }
283
 
284
        if (fGotDC)
285
                ReleaseDC(hwnd, hdc);
286
}
287
 
288
/* handle a non-client message for a scrollbar*/
289
void
290
MwHandleMessageScrollbar(HWND hwnd, WPARAM hitcode, LPARAM lParam, UINT msg, DWORD style)
291
{
292
        int     pos = SBS_UNKNOWN;
293
        BOOL    vertbar = (style==SBS_VERT);
294
        BOOL    horzbar = (style==SBS_HORZ);
295
        int *   pStat;
296
        POINT   pt;
297
        RECT    rc;
298
 
299
        static BOOL bDraw;
300
 
301
        static int downPos = SBS_UNKNOWN;
302
        static int sbCode;
303
        int newThumbPos;
304
 
305
        int itemMoveable,itemCount,itemVisible,moveRange;       /* jmt:2k0819 */
306
        int moveTop,moveBottom,moveLeft,moveRight;      /* jmt:2k0819 */
307
 
308
        int cx,cy;
309
        MWSCROLLBARINFO* pData;
310
 
311
        pData = (MWSCROLLBARINFO *)hwnd->userdata;
312
        rc = hwnd->winrect;
313
        cx=rc.right-rc.left;
314
        cy=rc.bottom-rc.top;
315
 
316
        POINTSTOPOINT(pt, lParam);
317
        for (;;) {      /* use for() to allow break statement*/
318
                if (vertbar)
319
                {
320
                        pStat = &pData->status;
321
                        rc = hwnd->winrect;
322
                        rc.bottom = rc.top + cx;
323
                        if (PtInRect(&rc, pt))
324
                        {
325
                                pos = SBS_UPARROW;
326
                                break;
327
                        }
328
                        rc.bottom = hwnd->winrect.bottom;
329
                        rc.top = rc.bottom - cx;
330
                        if (PtInRect(&rc, pt))
331
                        {
332
                                pos = SBS_DOWNARROW;
333
                                break;
334
                        }
335
                        pos = SBS_VERTTHUMB;
336
                } else if (horzbar)
337
                {
338
                        pStat = &pData->status;
339
                        rc = hwnd->winrect;
340
                        rc.right = rc.left + cy;
341
                        if (PtInRect(&rc, pt)) {
342
                                pos = SBS_LEFTARROW;
343
                                break;
344
                        }
345
                        rc.right = hwnd->winrect.right;
346
                        rc.left = rc.right - cy;
347
                        if (PtInRect(&rc, pt)) {
348
                                pos = SBS_RIGHTARROW;
349
                                break;
350
                        }
351
                        pos = SBS_HORZTHUMB;
352
                } else
353
                        return;
354
                break;
355
        }
356
 
357
        if (pos == SBS_UNKNOWN)
358
                return;
359
 
360
        *pStat &= ~SBS_MASK;            /* remove stray mouse states*/
361
 
362
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)
363
                *pStat |= pos;
364
        else *pStat &= ~pos;
365
 
366
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)
367
                bDraw=TRUE;
368
 
369
        if (bDraw)
370
                MwPaintScrollbars(hwnd, NULL,style);
371
 
372
        if (pos == SBS_UPARROW || pos == SBS_LEFTARROW) /* jmt:2k0820 */
373
        {
374
                if (pData->curPos != pData->minPos)
375
                        sbCode = SB_LINEUP;
376
        }
377
        else if (pos == SBS_DOWNARROW || pos == SBS_RIGHTARROW) /* jmt:2k0820 */
378
        {
379
                if (pData->curPos != pData->maxPos)
380
                        sbCode = SB_LINEDOWN;
381
        }
382
        else if (pos == SBS_VERTTHUMB || pos == SBS_HORZTHUMB)
383
        {
384
                sbCode = SB_THUMBTRACK;
385
        }
386
 
387
        switch(msg)
388
        {
389
        case WM_NCLBUTTONDOWN:
390
        case WM_NCLBUTTONDBLCLK:
391
            downPos = pos;
392
        break;
393
 
394
        case WM_NCMOUSEMOVE:
395
            if (vertbar)
396
            {
397
                if (sbCode == SB_THUMBTRACK && downPos == SBS_VERTTHUMB)
398
                {
399
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
400
 
401
                        rc = hwnd->winrect;
402
                        moveTop = rc.top + cx;
403
                        moveBottom = hwnd->winrect.bottom - cx;
404
                        moveRange = moveBottom - moveTop;
405
 
406
                        itemCount = pData->maxPos - pData->minPos + 1;
407
                        itemVisible = pData->pageStep;
408
                        itemMoveable = itemCount - itemVisible + 1;
409
 
410
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
411
                        printf("((%d-%d)*%d)/%d=%d\n",
412
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
413
 
414
                        if ( newThumbPos >= pData->minPos &&
415
                             newThumbPos <= pData->maxPos)
416
                        {
417
                                SendMessage (hwnd,
418
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
419
 
420
                                SendMessage (GetParent(hwnd),
421
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
422
                        }
423
                        break;
424
                }
425
            }
426
            if (horzbar)
427
            {
428
                if (sbCode == SB_THUMBTRACK && downPos == SBS_HORZTHUMB)
429
                {
430
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
431
 
432
                        rc = hwnd->winrect;
433
                        moveLeft = rc.left + cy;
434
                        moveRight = hwnd->winrect.right - cy;
435
                        moveRange = moveRight - moveLeft;
436
 
437
                        itemCount = pData->maxPos - pData->minPos + 1;
438
                        itemVisible = pData->pageStep;
439
                        itemMoveable = itemCount - itemVisible + 1;
440
 
441
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
442
                        printf("((%d-%d)*%d)/%d=%d\n",
443
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
444
 
445
                        if ( newThumbPos >= pData->minPos &&
446
                             newThumbPos <= pData->maxPos)
447
                        {
448
                                SendMessage (hwnd,
449
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
450
 
451
                                SendMessage (GetParent(hwnd),
452
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
453
                        }
454
                        break;
455
                }
456
             }
457
        break;
458
 
459
        case WM_NCLBUTTONUP:
460
            bDraw=FALSE;
461
            downPos = SBS_UNKNOWN;
462
 
463
            if (sbCode==SB_THUMBTRACK)
464
            {
465
                    if (vertbar)
466
                    {
467
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
468
 
469
                        rc = hwnd->winrect;
470
                        moveTop = rc.top + cx;
471
                        moveBottom = hwnd->winrect.bottom - cx;
472
                        moveRange = moveBottom - moveTop;
473
 
474
                        itemCount = pData->maxPos - pData->minPos + 1;
475
                        itemVisible = pData->pageStep;
476
                        itemMoveable = itemCount - itemVisible + 1;
477
 
478
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
479
                        printf("((%d-%d)*%d)/%d=%d\n",
480
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
481
 
482
                        if ( newThumbPos >= pData->minPos &&
483
                             newThumbPos <= pData->maxPos)
484
                        {
485
                                SendMessage (hwnd,
486
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
487
 
488
                                SendMessage (GetParent(hwnd),
489
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
490
                        }
491
                        break;  /* case */
492
                    }
493
                    if (horzbar)
494
                    {
495
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
496
 
497
                        rc = hwnd->winrect;
498
                        moveLeft = rc.left + cy;
499
                        moveRight = hwnd->winrect.right - cy;
500
                        moveRange = moveRight - moveLeft;
501
 
502
                        itemCount = pData->maxPos - pData->minPos + 1;
503
                        itemVisible = pData->pageStep;
504
                        itemMoveable = itemCount - itemVisible + 1;
505
 
506
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
507
                        printf("((%d-%d)*%d)/%d=%d\n",
508
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
509
 
510
                        if ( newThumbPos >= pData->minPos &&
511
                             newThumbPos <= pData->maxPos)
512
                        {
513
                            SendMessage (hwnd,
514
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
515
 
516
                            SendMessage (GetParent(hwnd),
517
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
518
                        }
519
                        break;  /* case */
520
                    }
521
            }
522
            else
523
            {
524
                if (vertbar)
525
                {
526
                        SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
527
                        SendMessage (GetParent(hwnd), WM_VSCROLL, sbCode, 0);
528
                }
529
                if (horzbar)
530
                {
531
                        SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
532
                        SendMessage (GetParent(hwnd), WM_HSCROLL, sbCode, 0);
533
                }
534
            }
535
        break;
536
        }
537
}
538
 
539
 
540
static BOOL
541
PtInRect2(const RECT *lprc, int x, int y)
542
{
543
        POINT   p;
544
 
545
        p.x = x;
546
        p.y = y;
547
        return PtInRect(lprc, p);
548
}
549
 
550
static void
551
wndScrollBarPos (HWND hwnd, BOOL bIsHBar, RECT* rcBar)  /* jmt: 2k0820 */
552
{
553
    UINT moveRange;
554
    PMWSCROLLBARINFO pSBar;
555
    int cx,cy;
556
    RECT rc;
557
 
558
    rc = hwnd->winrect;
559
    cx=rc.right-rc.left;
560
    cy=rc.bottom-rc.top;
561
    pSBar = (MWSCROLLBARINFO *)hwnd->userdata;
562
 
563
    if (pSBar->minPos == pSBar->maxPos) {
564
        pSBar->status |= SBS_HIDE;
565
        return;
566
    }
567
 
568
    if (bIsHBar)
569
        moveRange = (rcBar->right - rcBar->left) - (cy << 1);
570
    else
571
        moveRange = (rcBar->bottom - rcBar->top) - (cx << 1);
572
 
573
 
574
    if (pSBar->pageStep == 0)
575
    {
576
        pSBar->barLen = MWM_DEFBARLEN;
577
 
578
        if (pSBar->barLen > moveRange)
579
            pSBar->barLen = MWM_MINBARLEN;
580
    }
581
    else
582
    {
583
        pSBar->barLen = moveRange * pSBar->pageStep /
584
              (pSBar->maxPos - pSBar->minPos + 1);
585
        if (pSBar->barLen < MWM_MINBARLEN)
586
            pSBar->barLen = MWM_MINBARLEN;
587
    }
588
 
589
    pSBar->barStart = moveRange * (pSBar->curPos - pSBar->minPos) /
590
       (pSBar->maxPos - pSBar->minPos + 1);
591
 
592
 
593
    if (pSBar->barStart + pSBar->barLen > moveRange)
594
        pSBar->barStart = moveRange - pSBar->barLen;
595
 
596
 
597
    if (pSBar->barStart < 0)
598
        pSBar->barStart = 0;
599
}
600
 
601
static PMWSCROLLBARINFO wndGetScrollBar (HWND pWin)     /* jmt: 2k0820 */
602
{
603
        MWSCROLLBARINFO* pData;
604
 
605
        pData = (MWSCROLLBARINFO *)pWin->userdata;
606
 
607
        if (!strcmp(pWin->pClass->lpszClassName,"SCROLLBAR"))
608
                return pData;
609
        else
610
                return NULL;
611
}
612
 
613
BOOL EnableScrollBarEx (HWND hWnd, int iSBar, BOOL bEnable)     /* jmt: iSBar not used */
614
{
615
    PMWSCROLLBARINFO pSBar;
616
    HWND pWin;
617
    BOOL bPrevState;
618
    RECT rcBar;
619
 
620
    DWORD dwStyle;      /* jmt:2k0820 */
621
 
622
    pWin = (HWND)hWnd;
623
 
624
    if ( !(pSBar = wndGetScrollBar (pWin)) )
625
        return FALSE;
626
 
627
    bPrevState = !(pSBar->status & SBS_DISABLED);
628
 
629
    if (bEnable && !bPrevState)
630
        pSBar->status &= ~SBS_DISABLED;
631
    else if (!bEnable && bPrevState)
632
        pSBar->status |= SBS_DISABLED;
633
    else
634
        return FALSE;
635
 
636
    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);   /* jmt: 2k0820 */
637
 
638
    if (dwStyle == SBS_VERT)
639
    {
640
        wndGetVScrollBarRect (pWin, &rcBar);
641
        rcBar.left --;
642
        rcBar.right --;
643
    }
644
    else
645
    {
646
        wndGetHScrollBarRect (pWin, &rcBar);
647
        rcBar.top  --;
648
        rcBar.bottom --;
649
    }
650
#if 0
651
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
652
#else
653
    MwPaintScrollbars(hWnd,NULL,dwStyle);       /* a must */
654
#endif
655
 
656
    return TRUE;
657
}
658
 
659
BOOL GetScrollPosEx (HWND hWnd, int iSBar, int* pPos)   /* jmt: iSBar not used */
660
{
661
    PMWSCROLLBARINFO pSBar;
662
    HWND pWin;
663
 
664
    pWin = (HWND)hWnd;
665
 
666
    if ( !(pSBar = wndGetScrollBar (pWin)) )
667
        return FALSE;
668
 
669
    *pPos = pSBar->curPos;
670
    return TRUE;
671
}
672
 
673
BOOL GetScrollRangeEx (HWND hWnd, int iSBar, int* pMinPos, int* pMaxPos)        /* jmt: iSBar not used */
674
{
675
    PMWSCROLLBARINFO pSBar;
676
    HWND pWin;
677
 
678
    pWin = (HWND)hWnd;
679
 
680
    if ( !(pSBar = wndGetScrollBar (pWin)) )
681
        return FALSE;
682
 
683
    *pMinPos = pSBar->minPos;
684
    *pMaxPos = pSBar->maxPos;
685
    return TRUE;
686
}
687
 
688
BOOL SetScrollPosEx (HWND hWnd, int iSBar, int iNewPos) /* jmt: iSBar not used */
689
{
690
    PMWSCROLLBARINFO pSBar;
691
    HWND pWin;
692
    RECT rcBar;
693
 
694
    DWORD dwStyle;      /* jmt:2k0820 */
695
 
696
    pWin = (HWND)hWnd;
697
 
698
    if ( !(pSBar = wndGetScrollBar (pWin)) )
699
        return FALSE;
700
 
701
    if (iNewPos < pSBar->minPos)
702
        pSBar->curPos = pSBar->minPos;
703
    else
704
        pSBar->curPos = iNewPos;
705
 
706
    {
707
        int max = pSBar->maxPos;
708
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
709
 
710
        if (pSBar->curPos > max)
711
            pSBar->curPos = max;
712
    }
713
 
714
    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);   /* jmt: 2k0820 */
715
 
716
    if (dwStyle == SBS_VERT)
717
    {
718
        wndGetVScrollBarRect (pWin, &rcBar);
719
        rcBar.left --;
720
        rcBar.right --;
721
    }
722
    else
723
    {
724
        wndGetHScrollBarRect (pWin, &rcBar);
725
        rcBar.top  --;
726
        rcBar.bottom --;
727
    }
728
 
729
    wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
730
 
731
#if 0
732
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
733
#else
734
    MwPaintScrollbars(hWnd,NULL,dwStyle);       /* a must */
735
#endif
736
    return TRUE;
737
}
738
 
739
BOOL SetScrollRangeEx (HWND hWnd, int iSBar, int iMinPos, int iMaxPos)  /* jmt: iSBar not used */
740
{
741
    PMWSCROLLBARINFO pSBar;
742
    HWND pWin;
743
    RECT rcBar;
744
 
745
    DWORD dwStyle;      /* jmt:2k0820 */
746
 
747
    pWin = (HWND)hWnd;
748
 
749
    if ( !(pSBar = wndGetScrollBar (pWin)) )
750
        return FALSE;
751
 
752
    pSBar->minPos = (iMinPos < iMaxPos)?iMinPos:iMaxPos;
753
    pSBar->maxPos = (iMinPos > iMaxPos)?iMinPos:iMaxPos;
754
 
755
    /* validate parameters. */
756
    if (pSBar->curPos < pSBar->minPos)
757
        pSBar->curPos = pSBar->minPos;
758
 
759
    if (pSBar->pageStep <= 0)
760
        pSBar->pageStep = 0;
761
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
762
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
763
 
764
    {
765
        int max = pSBar->maxPos;
766
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
767
 
768
        if (pSBar->curPos > max)
769
            pSBar->curPos = max;
770
    }
771
 
772
    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);   /* jmt: 2k0820 */
773
 
774
    if (dwStyle == SBS_VERT)
775
    {
776
        wndGetVScrollBarRect (pWin, &rcBar);
777
        rcBar.left --;
778
        rcBar.right --;
779
    }
780
    else
781
    {
782
        wndGetHScrollBarRect (pWin, &rcBar);
783
        rcBar.top  --;
784
        rcBar.bottom --;
785
    }
786
    wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
787
 
788
#if 0
789
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
790
#else
791
    MwPaintScrollbars(hWnd,NULL,dwStyle);       /* a must */
792
#endif
793
 
794
    return TRUE;
795
}
796
 
797
BOOL SetScrollInfoEx (HWND hWnd, int iSBar,
798
                LPCSCROLLINFO lpsi, BOOL fRedraw)       /* jmt: iSBar not used */
799
{
800
    PMWSCROLLBARINFO pSBar;
801
    HWND pWin;
802
    RECT rcBar;
803
 
804
    DWORD dwStyle;      /* jmt:2k0820 */
805
 
806
    pWin = (HWND)hWnd;
807
 
808
    if ( !(pSBar = wndGetScrollBar (pWin)) )
809
        return FALSE;
810
 
811
    if( lpsi->fMask & SIF_RANGE )
812
    {
813
        pSBar->minPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMin:lpsi->nMax;
814
        pSBar->maxPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMax:lpsi->nMin;
815
    }
816
 
817
    if( lpsi->fMask & SIF_POS )
818
        pSBar->curPos = lpsi->nPos;
819
 
820
    if( lpsi->fMask & SIF_PAGE )
821
        pSBar->pageStep = lpsi->nPage;
822
 
823
    /* validate parameters. */
824
    if (pSBar->curPos < pSBar->minPos)
825
        pSBar->curPos = pSBar->minPos;
826
 
827
    if (pSBar->pageStep <= 0)
828
        pSBar->pageStep = 0;
829
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
830
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
831
 
832
    {
833
        int max = pSBar->maxPos;
834
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
835
 
836
        if (pSBar->curPos > max)
837
            pSBar->curPos = max;
838
    }
839
 
840
    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);   /* jmt: 2k0820 */
841
 
842
    if(fRedraw)
843
    {
844
        if (dwStyle == SBS_VERT)
845
        {
846
            wndGetVScrollBarRect (pWin, &rcBar);
847
            rcBar.left --;
848
            rcBar.right --;
849
        }
850
        else
851
        {
852
            wndGetHScrollBarRect (pWin, &rcBar);
853
            rcBar.top --;
854
            rcBar.bottom --;
855
        }
856
        wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
857
 
858
#if 0
859
        SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
860
#else
861
        MwPaintScrollbars(hWnd,NULL,dwStyle);   /* a must */
862
#endif
863
    }
864
 
865
    return TRUE;
866
}
867
 
868
BOOL GetScrollInfoEx(HWND hWnd, int iSBar, LPSCROLLINFO lpsi)   /* jmt: iSBar not used */
869
{
870
    PMWSCROLLBARINFO pSBar;
871
    HWND pWin;
872
 
873
    pWin = (HWND)hWnd;
874
 
875
    if ( !(pSBar = wndGetScrollBar (pWin)) )
876
        return FALSE;
877
 
878
    if( lpsi->fMask & SIF_RANGE )
879
    {
880
        lpsi->nMin = pSBar->minPos;
881
        lpsi->nMax = pSBar->maxPos;
882
    }
883
 
884
    if( lpsi->fMask & SIF_POS )
885
    {
886
        lpsi->nPos = pSBar->curPos;
887
    }
888
 
889
    if( lpsi->fMask & SIF_PAGE )
890
        lpsi->nPage = pSBar->pageStep;
891
 
892
    return TRUE;
893
}
894
 
895
BOOL ShowScrollBarEx (HWND hWnd, int iSBar, BOOL bShow) /* jmt: iSBar not used */
896
{
897
    PMWSCROLLBARINFO pSBar;
898
    HWND pWin;
899
    BOOL bPrevState;
900
    RECT rcBar;
901
 
902
    DWORD dwStyle;      /* jmt:2k0820 */
903
 
904
    pWin = (HWND)hWnd;
905
 
906
    if ( !(pSBar = wndGetScrollBar (pWin)) )
907
        return FALSE;
908
 
909
    bPrevState = !(pSBar->status & SBS_HIDE);
910
 
911
    if (bShow && !bPrevState)
912
        pSBar->status &= ~SBS_HIDE;
913
    else if (!bShow && bPrevState)
914
        pSBar->status |= SBS_HIDE;
915
    else
916
        return FALSE;
917
 
918
#if 0   /* fix: no WM_CHANGESIZE */
919
    SendMessage (hWnd, WM_CHANGESIZE, 0, 0);
920
#endif
921
 
922
    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);   /* jmt: 2k0820 */
923
 
924
    if (dwStyle == SBS_VERT)
925
        wndGetVScrollBarRect (pWin, &rcBar);
926
    else
927
        wndGetHScrollBarRect (pWin, &rcBar);
928
 
929
    {
930
        RECT rcWin, rcClient;
931
 
932
        memcpy (&rcWin, &pWin->winrect.left, sizeof (RECT));
933
 
934
        rcClient.left = 0;
935
        rcClient.top  = 0;
936
        rcClient.right = pWin->clirect.right - pWin->clirect.left;
937
        rcClient.bottom = pWin->clirect.bottom - pWin->clirect.top;
938
#if 0   /* fix: no WM_SIZECHANGED */
939
        SendMessage (hWnd, WM_SIZECHANGED,
940
            (WPARAM)&rcWin, (LPARAM)&rcClient);
941
#endif
942
    }
943
 
944
    if (bShow) {
945
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
946
    }
947
    else {
948
        rcBar.left -= pWin->clirect.left;
949
        rcBar.top  -= pWin->clirect.top;
950
        rcBar.right -= pWin->clirect.left;
951
        rcBar.bottom -= pWin->clirect.top;
952
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
953
        InvalidateRect (hWnd, &rcBar, TRUE);
954
    }
955
 
956
    return TRUE;
957
}
958
 
959
static void sbSetScrollInfo (HWND hwnd, PMWSCROLLBARINFO pData, BOOL fRedraw)   /* jmt:2k0820 */
960
{
961
    SCROLLINFO si;
962
 
963
    int itemCount,itemVisibles;
964
 
965
    itemCount = pData->maxPos - pData->minPos + 1;
966
    itemVisibles = pData->pageStep;
967
 
968
    if (itemVisibles >= itemCount)
969
    {
970
        SetScrollPosEx (hwnd, 0, 0);      /* jmt: arg2 not used */
971
        EnableScrollBarEx (hwnd, 0, FALSE);      /* jmt: arg2 not used */
972
        return;
973
    }
974
 
975
    si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
976
    si.nMax = itemCount - 1;
977
    si.nMin = 0;
978
 
979
    si.nPage = itemVisibles;    /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
980
 
981
    si.nPos = pData->curPos;
982
 
983
    SetScrollInfoEx (hwnd, 0, &si, fRedraw);     /* jmt: arg2 not used */
984
    EnableScrollBarEx (hwnd, 0, TRUE);   /* jmt: arg2 not used */
985
}
986
 
987
static LRESULT CALLBACK
988
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)    /* jmt:2k0820 */
989
{
990
        DWORD dwStyle;
991
        MWSCROLLBARINFO* pData;
992
 
993
        int moveRange;
994
        RECT rcBar;
995
 
996
        dwStyle = (GetWindowStyle (hwnd) & SBS_TYPEMASK);
997
        switch (message)
998
        {
999
        case WM_CREATE:
1000
                if (!(pData = malloc (sizeof (MWSCROLLBARINFO))))
1001
                {
1002
                        fprintf(stderr, "Create scroll bar control failure!\n");
1003
                        return -1;
1004
                }
1005
 
1006
                pData->minPos=0;           /* min value of scroll range.*/
1007
                /* max value of scroll range.*/
1008
                pData->maxPos=0;
1009
                if  (dwStyle==SBS_VERT)
1010
                        moveRange=((hwnd->winrect.bottom-hwnd->winrect.top)
1011
                                -((hwnd->winrect.right-hwnd->winrect.left)<<1));
1012
                else
1013
                        moveRange=((hwnd->winrect.right-hwnd->winrect.left)
1014
                                -((hwnd->winrect.bottom-hwnd->winrect.top)<<1));
1015
                if (moveRange > MWM_MINBARLEN)
1016
                {
1017
 
1018
 
1019
                        pData->maxPos=moveRange / MWM_MINBARLEN;
1020
                        if( (moveRange % MWM_MINBARLEN) )
1021
                                pData->maxPos++;
1022
                }
1023
                printf("maxPos=%d\n",pData->maxPos);
1024
 
1025
                pData->curPos=0;             /* current scroll pos.*/
1026
 
1027
                /* steps per page.*/
1028
                pData->pageStep=1;
1029
                if ( (pData->maxPos - 2) > 1)
1030
                        pData->pageStep = pData->maxPos - 2;
1031
                printf("pageStep=%d\n",pData->pageStep);
1032
 
1033
                pData->barStart=0;           /* start pixel of bar.*/
1034
                pData->barLen=MWM_MINBARLEN; /* length of bar.*/
1035
                pData->status=SBS_UNKNOWN;   /* status of scroll bar.*/
1036
#if 0   /* jmt: must handle WM_MOVE */
1037
                pData->rc=hwnd->winrect;   /* screen coordinates position*/
1038
#endif
1039
                hwnd->userdata = (DWORD)pData;
1040
 
1041
                if (dwStyle == SBS_VERT)
1042
                {
1043
                    wndGetVScrollBarRect (hwnd, &rcBar);
1044
                    rcBar.left --;
1045
                    rcBar.right --;
1046
                }
1047
                else
1048
                {
1049
                    wndGetHScrollBarRect (hwnd, &rcBar);
1050
                    rcBar.top --;
1051
                    rcBar.bottom --;
1052
                }
1053
                /* adjust pData->barLen */
1054
                wndScrollBarPos (hwnd, dwStyle == SBS_HORZ, &rcBar);
1055
 
1056
                break;
1057
 
1058
        case WM_DESTROY:
1059
                free ((void *)(hwnd->userdata));
1060
                break;
1061
 
1062
        case WM_PAINT:
1063
                MwPaintScrollbars(hwnd,NULL,dwStyle);
1064
                break;
1065
 
1066
        case WM_NCLBUTTONDOWN:
1067
        case WM_NCLBUTTONDBLCLK:
1068
        case WM_NCMOUSEMOVE:
1069
        case WM_NCLBUTTONUP:
1070
                MwHandleMessageScrollbar(hwnd, wParam, lParam, message, dwStyle);
1071
                break;
1072
 
1073
        case WM_HSCROLL:
1074
        case WM_VSCROLL:
1075
        {
1076
            int newTop,itemCount,itemVisibles;
1077
 
1078
            pData = (MWSCROLLBARINFO *)hwnd->userdata;
1079
            newTop = pData->curPos;
1080
            itemCount = pData->maxPos - pData->minPos + 1;
1081
            itemVisibles = pData->pageStep;
1082
 
1083
            switch(wParam)
1084
            {
1085
                case SB_LINEDOWN:
1086
#define ITEM_BOTTOM(x)  (x->curPos + itemVisibles - 1)
1087
                    if (ITEM_BOTTOM (pData) < (itemCount - 1 ))
1088
                    {
1089
                        newTop ++;
1090
                    }
1091
                break;
1092
 
1093
                case SB_LINEUP:
1094
                    if (pData->curPos > 0)
1095
                    {
1096
                        newTop --;
1097
                    }
1098
                break;
1099
 
1100
                case SB_PAGEDOWN:
1101
                    if ((pData->curPos + (itemVisibles << 1)) <=
1102
                            itemCount)
1103
                        newTop += itemVisibles;
1104
                    else
1105
                        newTop = itemCount - itemVisibles;
1106
 
1107
                    if (newTop < 0)
1108
                        return 0;
1109
 
1110
                break;
1111
 
1112
                case SB_PAGEUP:
1113
                    if (pData->curPos >= itemVisibles)
1114
                        newTop -= itemVisibles;
1115
                    else
1116
                        newTop = 0;
1117
 
1118
                break;
1119
 
1120
                case SB_THUMBTRACK:
1121
                    newTop = (int)lParam;
1122
                break;
1123
            }
1124
 
1125
            pData->curPos = newTop;
1126
 
1127
            SendMessage (hwnd, WM_PAINT, 0, 0);
1128
 
1129
            sbSetScrollInfo (hwnd, pData, TRUE);
1130
 
1131
            return 0;
1132
        }
1133
        break;
1134
 
1135
        default:
1136
                return DefWindowProc (hwnd, message, wParam, lParam);
1137
        }
1138
        return 0;
1139
}
1140
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.