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/] [winsbar.2] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Copyright (c) 2000 Greg Haerr 
3
 * Portions Copyright (c) 1999, 2000, Wei Yongming.
4
 * jmt: scrollbar thumb ported
5
 *
6
 * Microwindows win32 NonClient Scrollbars
7
 */
8
#define MWINCLUDECOLORS//jmt: for color macros
9
#include "windows.h"
10
#include "wintern.h"
11
#include "wintools.h"
12
#include 
13
#include 
14
#include //printf
15
/* scrollbar status/positions*/
16
#define SBS_UNKNOWN             0x0000
17
#define SBS_LEFTARROW           0x0001
18
#define SBS_RIGHTARROW          0x0002
19
#define SBS_LEFTSPACE           0x0004
20
#define SBS_RIGHTSPACE          0x0008
21
#define SBS_HORZTHUMB           0x0010
22
#define SBS_UPARROW             0x0020
23
#define SBS_DOWNARROW           0x0040
24
#define SBS_UPSPACE             0x0080
25
#define SBS_DOWNSPACE           0x0100
26
#define SBS_VERTTHUMB           0x0200
27
#define SBS_MASK                0x03ff
28
#define SBS_DISABLED            0x4000
29
#define SBS_HIDE                0x8000
30
 
31
#define HSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_HSCROLL)
32
#define VSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_VSCROLL)
33
 
34
//#
35
 
36
/****************************** Drawing Helpers *******************************/
37
static void
38
Draw3DUpFrame(HDC hDC, int l, int t, int r, int b)
39
{
40
        RECT    rc;
41
        HBRUSH  hbr;
42
 
43
        SetRect(&rc, l, t, r, b);
44
        Draw3dBox(hDC, rc.left, rc.top,
45
                rc.right-rc.left, rc.bottom-rc.top,
46
                GetSysColor(COLOR_3DLIGHT),
47
                GetSysColor(COLOR_WINDOWFRAME));
48
        InflateRect(&rc, -1, -1);
49
        Draw3dBox(hDC, rc.left, rc.top,
50
                rc.right-rc.left, rc.bottom-rc.top,
51
                GetSysColor(COLOR_BTNHIGHLIGHT),
52
                GetSysColor(COLOR_BTNSHADOW));
53
        InflateRect(&rc, -1, -1);
54
 
55
        hbr = CreateSolidBrush(LTGRAY);
56
        FillRect(hDC, &rc, hbr);
57
        DeleteObject(hbr);
58
}
59
 
60
 
61
/*
62
 * Adjust client area smaller if scrollbars visible.
63
 * Also, compute the NC hittest regions for the scrollbars.
64
 */
65
void
66
MwAdjustNCScrollbars(HWND hwnd)
67
{
68
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
69
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
70
 
71
        if (vertbar) {
72
                hwnd->clirect.right -= mwSYSMETRICS_CXVSCROLL;
73
                if (horzbar)
74
                        hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
75
                hwnd->vscroll.rc.left = hwnd->clirect.right;
76
                hwnd->vscroll.rc.right = hwnd->clirect.right +
77
                        mwSYSMETRICS_CXVSCROLL;
78
                hwnd->vscroll.rc.top = hwnd->clirect.top;
79
                hwnd->vscroll.rc.bottom = hwnd->clirect.bottom;
80
        } else
81
                SetRectEmpty(&hwnd->vscroll.rc);
82
        if (horzbar) {
83
                if (!vertbar)
84
                        hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
85
                hwnd->hscroll.rc.top = hwnd->clirect.bottom;
86
                hwnd->hscroll.rc.bottom = hwnd->clirect.bottom +
87
                        mwSYSMETRICS_CYHSCROLL;
88
                hwnd->hscroll.rc.left = hwnd->clirect.left;
89
                hwnd->hscroll.rc.right = hwnd->clirect.right;
90
        } else
91
                SetRectEmpty(&hwnd->hscroll.rc);
92
}
93
 
94
static int
95
wndGetBorder(HWND hwnd)
96
{
97
        if (hwnd->style & WS_BORDER)  {
98
                if ((hwnd->style & WS_CAPTION) == WS_CAPTION)
99
                        return mwSYSMETRICS_CXFRAME;
100
                return mwSYSMETRICS_CXBORDER;
101
        }
102
        return 0;
103
}
104
 
105
static BOOL
106
wndGetVScrollBarRect (HWND hwnd, RECT* rcVBar)
107
{
108
    if (hwnd->style & WS_VSCROLL) {
109
        rcVBar->left = hwnd->winrect.right - mwSYSMETRICS_CXVSCROLL
110
                        - wndGetBorder (hwnd);
111
        rcVBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
112
        rcVBar->top  = hwnd->clirect.top;
113
        rcVBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
114
 
115
        if (hwnd->style & WS_HSCROLL && !(hwnd->hscroll.status & SBS_HIDE))
116
            rcVBar->bottom -= mwSYSMETRICS_CYHSCROLL;
117
 
118
        return TRUE;
119
    }
120
 
121
    return FALSE;
122
}
123
 
124
static BOOL
125
wndGetHScrollBarRect (HWND hwnd, RECT* rcHBar)
126
{
127
    if (hwnd->style & WS_HSCROLL) {
128
        rcHBar->top = hwnd->winrect.bottom - mwSYSMETRICS_CYHSCROLL
129
                        - wndGetBorder (hwnd);
130
        rcHBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
131
        rcHBar->left  = hwnd->clirect.left;
132
        rcHBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
133
 
134
        if (hwnd->style & WS_VSCROLL && !(hwnd->vscroll.status & SBS_HIDE))
135
            rcHBar->right -= mwSYSMETRICS_CXVSCROLL;
136
 
137
        return TRUE;
138
    }
139
 
140
    return FALSE;
141
}
142
 
143
void
144
MwPaintNCScrollbars(HWND hwnd, HDC hdc)
145
{
146
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
147
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
148
        BOOL    fGotDC = FALSE;
149
        RECT    rc,rc2;
150
 
151
        POINT   p3[3];
152
        int     shrink=2;
153
 
154
        int start = 0;
155
        RECT rcHBar, rcVBar;
156
 
157
 
158
        if (!hdc && (horzbar || vertbar)) {
159
                hdc = GetWindowDC(hwnd);
160
                fGotDC = TRUE;
161
        }
162
 
163
        if (horzbar && vertbar) {
164
                rc.left = hwnd->clirect.right;
165
                rc.top = hwnd->clirect.bottom;
166
                rc.right = rc.left + mwSYSMETRICS_CXVSCROLL;
167
                rc.bottom = rc.top + mwSYSMETRICS_CYHSCROLL;
168
                FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
169
        }
170
        if (vertbar) {
171
                rc = hwnd->vscroll.rc;
172
 
173
                /* bkgnd */
174
                FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
175
 
176
                /* up */
177
                Draw3dUpDownState(hdc, rc.left, rc.top,
178
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
179
                        hwnd->vscroll.status & SBS_UPARROW);
180
                /* down */
181
                Draw3dUpDownState(hdc, rc.left,rc.bottom-mwSYSMETRICS_CYHSCROLL,
182
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
183
                        hwnd->vscroll.status & SBS_DOWNARROW);
184
#if 1//jmt: draw arrows
185
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
186
                /* up */
187
                p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
188
                p3[0].y= rc.top + 2 + shrink;
189
                p3[1].x= rc.left + 2 + shrink - 1;
190
                p3[1].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
191
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
192
                p3[2].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
193
                Polygon(hdc,p3,3);
194
                /* down */
195
                p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
196
                p3[0].y= rc.bottom - 4 - shrink;
197
                p3[1].x= rc.left + 2 + shrink - 1;
198
                p3[1].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
199
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
200
                p3[2].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
201
                Polygon(hdc,p3,3);
202
#endif
203
#if 1
204
                // draw moving bar
205
 
206
                wndGetVScrollBarRect (hwnd, &rcVBar);
207
                rcVBar.left -- ;
208
                rcVBar.right -- ;
209
 
210
                start = rcVBar.top + mwSYSMETRICS_CYVSCROLL + hwnd->vscroll.barStart;
211
 
212
                if (start + hwnd->vscroll.barLen > rcVBar.bottom)
213
                        start = rcVBar.bottom - hwnd->vscroll.barLen;
214
 
215
                if (hwnd->vscroll.barLen == 0)
216
                        hwnd->vscroll.barLen=rc.bottom-rc.top-(mwSYSMETRICS_CYVSCROLL*2);
217
 
218
                /* bkgnd */
219
                rc2.left=rc.left; rc2.right=rc.right/*-1*/;
220
                rc2.top=rc.top+mwSYSMETRICS_CYHSCROLL;
221
                rc2.bottom=start;
222
                if (rc2.bottom>rc2.top)
223
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
224
 
225
                rc2.top=start+hwnd->vscroll.barLen;
226
                rc2.bottom=rc.bottom-mwSYSMETRICS_CYHSCROLL;
227
                if (rc2.bottom>rc2.top)
228
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
229
 
230
                Draw3DUpFrame (hdc, rcVBar.left, start, rcVBar.right,
231
                        start + hwnd->vscroll.barLen);
232
#if 0
233
                printf("barv:(l,t,r,b):(%d,%d,%d,%d)\n",
234
                        rcVBar.left, start, rcVBar.right,
235
                        start + hwnd->vscroll.barLen);
236
#endif
237
#endif
238
        }
239
        if (horzbar) {
240
                rc = hwnd->hscroll.rc;
241
 
242
                /* bkgnd */
243
                FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
244
 
245
                /* left */
246
                Draw3dUpDownState(hdc, rc.left, rc.top,
247
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
248
                        hwnd->hscroll.status & SBS_LEFTARROW);
249
                /* right */
250
                Draw3dUpDownState(hdc, rc.right-mwSYSMETRICS_CXVSCROLL, rc.top,
251
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
252
                        hwnd->hscroll.status & SBS_RIGHTARROW);
253
#if 1//jmt: draw arrows
254
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
255
                /* left */
256
                p3[0].x= rc.left + 2 + shrink;
257
                p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
258
                p3[1].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink ;
259
                p3[1].y= rc.top + 2 + shrink;
260
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
261
                p3[2].y= rc.bottom - 4 - shrink + 1;
262
                Polygon(hdc,p3,3);
263
                /* right */
264
                p3[0].x= rc.right - 4 - shrink;
265
                p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
266
                p3[1].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink ;
267
                p3[1].y= rc.top + 2 + shrink;
268
                p3[2].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink;
269
                p3[2].y= rc.bottom - 4 - shrink + 1;
270
                Polygon(hdc,p3,3);
271
#endif
272
#if 1
273
                // draw moving bar.
274
 
275
                wndGetHScrollBarRect (hwnd, &rcHBar);
276
                rcHBar.top -- ;
277
                rcHBar.bottom -- ;
278
 
279
                start = rcHBar.left + mwSYSMETRICS_CXHSCROLL + hwnd->hscroll.barStart;
280
 
281
                if (start + hwnd->hscroll.barLen > rcHBar.right)
282
                        start = rcHBar.right - hwnd->hscroll.barLen;
283
 
284
                if (hwnd->hscroll.barLen == 0)
285
                        hwnd->hscroll.barLen=rc.right-rc.left-(mwSYSMETRICS_CXHSCROLL*2);
286
 
287
                /* bkgnd */
288
                rc2.top=rc.top; rc2.bottom=rc.bottom/*-1*/;
289
                rc2.left=rc.left+mwSYSMETRICS_CXVSCROLL;
290
                rc2.right=start;
291
                if (rc2.right>rc2.left)
292
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
293
 
294
                rc2.left=start+hwnd->hscroll.barLen;
295
                rc2.right=rc.right-mwSYSMETRICS_CXVSCROLL;
296
                if (rc2.right>rc2.left)
297
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
298
 
299
                Draw3DUpFrame (hdc, start, rcHBar.top, start + hwnd->hscroll.barLen,
300
                        rcHBar.bottom);
301
#if 0
302
                printf("barh:(l,t,r,b):(%d,%d,%d,%d)\n",
303
                        start, rcHBar.top, start + hwnd->hscroll.barLen,
304
                        rcHBar.bottom);
305
#endif
306
#endif
307
        }
308
 
309
        if (fGotDC)
310
                ReleaseDC(hwnd, hdc);
311
}
312
 
313
/* handle a non-client message for a scrollbar*/
314
void
315
MwHandleNCMessageScrollbar(HWND hwnd, WPARAM hitcode, LPARAM lParam, UINT msg/*BOOL fDown*/)
316
{
317
        int     pos = SBS_UNKNOWN;
318
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
319
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
320
        int *   pStat;
321
        POINT   pt;
322
        RECT    rc;
323
 
324
        static BOOL bDraw;
325
 
326
        static int downPos = SBS_UNKNOWN;//
327
        static int sbCode;
328
        int newThumbPos;
329
 
330
        int itemMoveable,itemCount,itemVisible,moveRange;//jmt:2k0819
331
        int moveTop,moveBottom,moveLeft,moveRight;//jmt:2k0819
332
 
333
        POINTSTOPOINT(pt, lParam);
334
        for (;;) {      /* use for() to allow break statement*/
335
                if (hitcode == HTVSCROLL && vertbar)
336
                {
337
                        pStat = &hwnd->vscroll.status;
338
                        rc = hwnd->vscroll.rc;
339
                        rc.bottom = rc.top + mwSYSMETRICS_CYVSCROLL;
340
                        if (PtInRect(&rc, pt))
341
                        {
342
                                pos = SBS_UPARROW;
343
                                break;
344
                        }
345
                        rc.bottom = hwnd->vscroll.rc.bottom;
346
                        rc.top = rc.bottom - mwSYSMETRICS_CYVSCROLL;
347
                        if (PtInRect(&rc, pt))
348
                        {
349
                                pos = SBS_DOWNARROW;
350
                                break;
351
                        }
352
                        pos = SBS_VERTTHUMB;
353
                } else if (hitcode == HTHSCROLL && horzbar)
354
                {
355
                        pStat = &hwnd->hscroll.status;
356
                        rc = hwnd->hscroll.rc;
357
                        rc.right = rc.left + mwSYSMETRICS_CXHSCROLL;
358
                        if (PtInRect(&rc, pt)) {
359
                                pos = SBS_LEFTARROW;
360
                                break;
361
                        }
362
                        rc.right = hwnd->hscroll.rc.right;
363
                        rc.left = rc.right - mwSYSMETRICS_CXHSCROLL;
364
                        if (PtInRect(&rc, pt)) {
365
                                pos = SBS_RIGHTARROW;
366
                                break;
367
                        }
368
                        pos = SBS_HORZTHUMB;
369
                } else
370
                        return;
371
                break;
372
        }
373
 
374
        if (pos == SBS_UNKNOWN)
375
                return;
376
 
377
        *pStat &= ~SBS_MASK;                /* remove stray mouse states*/
378
 
379
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)//jmt:2k0819
380
                *pStat |= pos;
381
        else *pStat &= ~pos;
382
 
383
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)//jmt:2k0819
384
                bDraw=TRUE;
385
 
386
        if (bDraw)
387
                MwPaintNCScrollbars(hwnd, NULL);
388
 
389
        if (pos == SBS_UPARROW || pos == SBS_LEFTARROW)//jmt:2k0820
390
        {
391
                if (hwnd->vscroll.curPos != hwnd->vscroll.minPos)
392
                        sbCode = SB_LINEUP;
393
        }
394
        else if (pos == SBS_DOWNARROW || pos == SBS_RIGHTARROW)//jmt:2k0820
395
        {
396
                if (hwnd->vscroll.curPos != hwnd->vscroll.maxPos)
397
                        sbCode = SB_LINEDOWN;
398
        }
399
        else if (pos == SBS_VERTTHUMB || pos == SBS_HORZTHUMB)//
400
        {
401
                sbCode = SB_THUMBTRACK;//
402
        }
403
 
404
        switch(msg)
405
        {
406
        case WM_NCLBUTTONDOWN:
407
        case WM_NCLBUTTONDBLCLK://jmt:2k0819
408
            downPos = pos;
409
        break;
410
 
411
        case WM_NCMOUSEMOVE://jmt:2k0819
412
            if (hitcode == HTVSCROLL && vertbar)
413
            {
414
                if (sbCode == SB_THUMBTRACK && downPos == SBS_VERTTHUMB)//
415
                {
416
                        //jmt(2k0819): new algorithm for SB_THUMBTRACK
417
 
418
                        rc = hwnd->vscroll.rc;
419
                        moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
420
                        moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
421
                        moveRange = moveBottom - moveTop;
422
 
423
                        itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
424
                        itemVisible = hwnd->vscroll.pageStep;
425
                        itemMoveable = itemCount - itemVisible + 1;
426
 
427
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
428
                        printf("((%d-%d)*%d)/%d=%d\n",
429
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
430
                        //#
431
 
432
                        if ( newThumbPos >= hwnd->vscroll.minPos &&
433
                             newThumbPos <= hwnd->vscroll.maxPos)
434
                                SendMessage (hwnd,
435
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
436
                        break;
437
                }
438
            }
439
 
440
            if (hitcode == HTHSCROLL && horzbar)
441
            {
442
                if (sbCode == SB_THUMBTRACK && downPos == SBS_HORZTHUMB)//
443
                {
444
                        //jmt(2k0819): new algorithm for SB_THUMBTRACK
445
 
446
                        rc = hwnd->hscroll.rc;
447
                        moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
448
                        moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
449
                        moveRange = moveRight - moveLeft;
450
 
451
                        itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
452
                        itemVisible = hwnd->hscroll.pageStep;
453
                        itemMoveable = itemCount - itemVisible + 1;
454
 
455
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
456
                        printf("((%d-%d)*%d)/%d=%d\n",
457
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
458
                        //#
459
 
460
                        if ( newThumbPos >= hwnd->hscroll.minPos &&
461
                             newThumbPos <= hwnd->hscroll.maxPos)
462
                                SendMessage (hwnd,
463
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
464
                        break;
465
                }
466
             }
467
 
468
        break;
469
 
470
        case WM_NCLBUTTONUP://jmt:2k0819
471
            bDraw=FALSE;
472
            downPos = SBS_UNKNOWN;//
473
 
474
            if (sbCode==SB_THUMBTRACK)
475
            {
476
                    if (hitcode == HTVSCROLL && vertbar)
477
                    {
478
                        //jmt(2k0819): new algorithm for SB_THUMBTRACK
479
 
480
                        rc = hwnd->vscroll.rc;
481
                        moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
482
                        moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
483
                        moveRange = moveBottom - moveTop;
484
 
485
                        itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
486
                        itemVisible = hwnd->vscroll.pageStep;
487
                        itemMoveable = itemCount - itemVisible + 1;
488
 
489
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
490
                        printf("((%d-%d)*%d)/%d=%d\n",
491
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
492
                        //#
493
                        if ( newThumbPos >= hwnd->vscroll.minPos &&
494
                             newThumbPos <= hwnd->vscroll.maxPos)
495
                                SendMessage (hwnd,
496
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
497
                        break;
498
                    }
499
 
500
                    if (hitcode == HTHSCROLL && horzbar)
501
                    {
502
                        //jmt(2k0819): new algorithm for SB_THUMBTRACK
503
 
504
                        rc = hwnd->hscroll.rc;
505
                        moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
506
                        moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
507
                        moveRange = moveRight - moveLeft;
508
 
509
                        itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
510
                        itemVisible = hwnd->hscroll.pageStep;
511
                        itemMoveable = itemCount - itemVisible + 1;
512
 
513
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
514
                        printf("((%d-%d)*%d)/%d=%d\n",
515
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
516
                        //#
517
 
518
                        if ( newThumbPos >= hwnd->hscroll.minPos &&
519
                             newThumbPos <= hwnd->hscroll.maxPos)
520
                                SendMessage (hwnd,
521
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
522
                        break;
523
                    }
524
             }
525
             else//jmt:2k0820
526
             {
527
                    if (hitcode == HTVSCROLL && vertbar)
528
                        SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
529
 
530
                    if (hitcode == HTHSCROLL && horzbar)
531
                        SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
532
             }
533
        break;
534
        }
535
 
536
}
537
 
538
 
539
static BOOL
540
PtInRect2(const RECT *lprc, int x, int y)
541
{
542
        POINT   p;
543
 
544
        p.x = x;
545
        p.y = y;
546
        return PtInRect(lprc, p);
547
}
548
 
549
#if 1//0000
550
 
551
 
552
static void
553
wndScrollBarPos (HWND hwnd, BOOL bIsHBar, RECT* rcBar)
554
{
555
    UINT moveRange;
556
    PMWSCROLLBARINFO pSBar;
557
 
558
    if (bIsHBar)
559
        pSBar = &hwnd->hscroll;
560
    else
561
        pSBar = &hwnd->vscroll;
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) - (mwSYSMETRICS_CXHSCROLL<<1);
570
    else
571
        moveRange = (rcBar->bottom - rcBar->top) - (mwSYSMETRICS_CYVSCROLL<<1);
572
 
573
#define MWM_DEFBARLEN   18//
574
#define MWM_MINBARLEN   8//
575
 
576
    if (pSBar->pageStep == 0)
577
    {
578
        pSBar->barLen = MWM_DEFBARLEN;
579
 
580
        if (pSBar->barLen > moveRange)
581
            pSBar->barLen = MWM_MINBARLEN;
582
    }
583
    else
584
    {
585
        pSBar->barLen = moveRange * pSBar->pageStep /
586
              (pSBar->maxPos - pSBar->minPos + 1);
587
        if (pSBar->barLen < MWM_MINBARLEN)
588
            pSBar->barLen = MWM_MINBARLEN;
589
    }
590
 
591
    pSBar->barStart = moveRange * (pSBar->curPos - pSBar->minPos) /
592
       (pSBar->maxPos - pSBar->minPos + 1);
593
 
594
 
595
    if (pSBar->barStart + pSBar->barLen > moveRange)
596
        pSBar->barStart = moveRange - pSBar->barLen;
597
 
598
 
599
    if (pSBar->barStart < 0)
600
        pSBar->barStart = 0;
601
}
602
 
603
static PMWSCROLLBARINFO wndGetScrollBar (HWND pWin, int iSBar)
604
{
605
    if (iSBar == SB_HORZ) {
606
        if (pWin->style & WS_HSCROLL)
607
            return &pWin->hscroll;
608
    }
609
    else if (iSBar == SB_VERT) {
610
        if (pWin->style & WS_VSCROLL)
611
            return &pWin->vscroll;
612
    }
613
 
614
    return NULL;
615
}
616
 
617
BOOL EnableScrollBar (HWND hWnd, int iSBar, BOOL bEnable)
618
{
619
    PMWSCROLLBARINFO pSBar;
620
    HWND pWin;
621
    BOOL bPrevState;
622
    RECT rcBar;
623
 
624
    pWin = (HWND)hWnd;
625
 
626
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )//ok
627
        return FALSE;
628
 
629
    bPrevState = !(pSBar->status & SBS_DISABLED);
630
 
631
    if (bEnable && !bPrevState)
632
        pSBar->status &= ~SBS_DISABLED;
633
    else if (!bEnable && bPrevState)
634
        pSBar->status |= SBS_DISABLED;
635
    else
636
        return FALSE;
637
 
638
    if (iSBar == SB_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
    MwPaintNCScrollbars(hWnd,NULL);//a must
654
#endif
655
 
656
    return TRUE;
657
}
658
 
659
BOOL  GetScrollPos (HWND hWnd, int iSBar, int* pPos)
660
{
661
    PMWSCROLLBARINFO pSBar;
662
    HWND pWin;
663
 
664
    pWin = (HWND)hWnd;
665
 
666
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
667
        return FALSE;
668
 
669
    *pPos = pSBar->curPos;
670
    return TRUE;
671
}
672
 
673
BOOL  GetScrollRange (HWND hWnd, int iSBar, int* pMinPos, int* pMaxPos)
674
{
675
    PMWSCROLLBARINFO pSBar;
676
    HWND pWin;
677
 
678
    pWin = (HWND)hWnd;
679
 
680
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
681
        return FALSE;
682
 
683
    *pMinPos = pSBar->minPos;
684
    *pMaxPos = pSBar->maxPos;
685
    return TRUE;
686
}
687
 
688
BOOL  SetScrollPos (HWND hWnd, int iSBar, int iNewPos)//ok
689
{
690
    PMWSCROLLBARINFO pSBar;
691
    HWND pWin;
692
    RECT rcBar;
693
 
694
    pWin = (HWND)hWnd;
695
 
696
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
697
        return FALSE;
698
 
699
    if (iNewPos < pSBar->minPos)
700
        pSBar->curPos = pSBar->minPos;
701
    else
702
        pSBar->curPos = iNewPos;
703
 
704
    {
705
        int max = pSBar->maxPos;
706
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
707
 
708
        if (pSBar->curPos > max)
709
            pSBar->curPos = max;
710
    }
711
 
712
    if (iSBar == SB_VERT)
713
    {
714
        wndGetVScrollBarRect (pWin, &rcBar);
715
        rcBar.left --;
716
        rcBar.right --;
717
    }
718
    else
719
    {
720
        wndGetHScrollBarRect (pWin, &rcBar);
721
        rcBar.top  --;
722
        rcBar.bottom --;
723
    }
724
 
725
    wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
726
 
727
#if 0
728
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
729
#else
730
    MwPaintNCScrollbars(hWnd,NULL);//a must
731
#endif
732
    return TRUE;
733
}
734
 
735
BOOL  SetScrollRange (HWND hWnd, int iSBar, int iMinPos, int iMaxPos)
736
{
737
    PMWSCROLLBARINFO pSBar;
738
    HWND pWin;
739
    RECT rcBar;
740
 
741
    pWin = (HWND)hWnd;
742
 
743
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
744
        return FALSE;
745
 
746
    pSBar->minPos = (iMinPos < iMaxPos)?iMinPos:iMaxPos;
747
    pSBar->maxPos = (iMinPos > iMaxPos)?iMinPos:iMaxPos;
748
 
749
    // validate parameters.
750
    if (pSBar->curPos < pSBar->minPos)
751
        pSBar->curPos = pSBar->minPos;
752
 
753
    if (pSBar->pageStep <= 0)
754
        pSBar->pageStep = 0;
755
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
756
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
757
 
758
    {
759
        int max = pSBar->maxPos;
760
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
761
 
762
        if (pSBar->curPos > max)
763
            pSBar->curPos = max;
764
    }
765
 
766
    if (iSBar == SB_VERT)
767
    {
768
        wndGetVScrollBarRect (pWin, &rcBar);
769
        rcBar.left --;
770
        rcBar.right --;
771
    }
772
    else
773
    {
774
        wndGetHScrollBarRect (pWin, &rcBar);
775
        rcBar.top  --;
776
        rcBar.bottom --;
777
    }
778
    wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
779
 
780
#if 0
781
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
782
#else
783
    MwPaintNCScrollbars(hWnd,NULL);//a must
784
#endif
785
 
786
    return TRUE;
787
}
788
 
789
BOOL  SetScrollInfo (HWND hWnd, int iSBar,
790
                LPCSCROLLINFO lpsi, BOOL fRedraw)//ok
791
{
792
    PMWSCROLLBARINFO pSBar;
793
    HWND pWin;
794
    RECT rcBar;
795
 
796
    pWin = (HWND)hWnd;
797
 
798
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
799
        return FALSE;
800
 
801
    if( lpsi->fMask & SIF_RANGE )
802
    {
803
        pSBar->minPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMin:lpsi->nMax;
804
        pSBar->maxPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMax:lpsi->nMin;
805
    }
806
 
807
    if( lpsi->fMask & SIF_POS )
808
        pSBar->curPos = lpsi->nPos;
809
 
810
    if( lpsi->fMask & SIF_PAGE )
811
        pSBar->pageStep = lpsi->nPage;
812
 
813
    // validate parameters.
814
    if (pSBar->curPos < pSBar->minPos)
815
        pSBar->curPos = pSBar->minPos;
816
 
817
    if (pSBar->pageStep <= 0)
818
        pSBar->pageStep = 0;
819
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
820
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
821
 
822
    {
823
        int max = pSBar->maxPos;
824
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
825
 
826
        if (pSBar->curPos > max)
827
            pSBar->curPos = max;
828
    }
829
 
830
    if(fRedraw)
831
    {
832
        if (iSBar == SB_VERT)
833
        {
834
            wndGetVScrollBarRect (pWin, &rcBar);
835
            rcBar.left --;
836
            rcBar.right --;
837
        }
838
        else
839
        {
840
            wndGetHScrollBarRect (pWin, &rcBar);
841
            rcBar.top --;
842
            rcBar.bottom --;
843
        }
844
        wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
845
 
846
#if 0
847
        SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
848
#else
849
        MwPaintNCScrollbars(hWnd,NULL);//a must
850
#endif
851
    }
852
 
853
    return TRUE;
854
}
855
 
856
BOOL  GetScrollInfo(HWND hWnd, int iSBar, LPSCROLLINFO lpsi)
857
{
858
    PMWSCROLLBARINFO pSBar;
859
    HWND pWin;
860
 
861
    pWin = (HWND)hWnd;
862
 
863
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
864
        return FALSE;
865
 
866
    if( lpsi->fMask & SIF_RANGE )
867
    {
868
        lpsi->nMin = pSBar->minPos;
869
        lpsi->nMax = pSBar->maxPos;
870
    }
871
 
872
    if( lpsi->fMask & SIF_POS )
873
    {
874
        lpsi->nPos = pSBar->curPos;
875
    }
876
 
877
    if( lpsi->fMask & SIF_PAGE )
878
        lpsi->nPage = pSBar->pageStep;
879
 
880
    return TRUE;
881
}
882
 
883
BOOL  ShowScrollBar (HWND hWnd, int iSBar, BOOL bShow)
884
{
885
    PMWSCROLLBARINFO pSBar;
886
    HWND pWin;
887
    BOOL bPrevState;
888
    RECT rcBar;
889
 
890
    pWin = (HWND)hWnd;
891
 
892
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
893
        return FALSE;
894
 
895
    bPrevState = !(pSBar->status & SBS_HIDE);
896
 
897
    if (bShow && !bPrevState)
898
        pSBar->status &= ~SBS_HIDE;
899
    else if (!bShow && bPrevState)
900
        pSBar->status |= SBS_HIDE;
901
    else
902
        return FALSE;
903
#if 0//fix: no WM_CHANGESIZE
904
    SendMessage (hWnd, WM_CHANGESIZE, 0, 0);
905
#endif
906
    if (iSBar == SB_VERT)
907
        wndGetVScrollBarRect (pWin, &rcBar);
908
    else
909
        wndGetHScrollBarRect (pWin, &rcBar);
910
 
911
    {
912
        RECT rcWin, rcClient;
913
 
914
        memcpy (&rcWin, &pWin->winrect.left, sizeof (RECT));
915
 
916
        rcClient.left = 0;
917
        rcClient.top  = 0;
918
        rcClient.right = pWin->clirect.right - pWin->clirect.left;
919
        rcClient.bottom = pWin->clirect.bottom - pWin->clirect.top;
920
#if 0//fix: no WM_SIZECHANGED
921
        SendMessage/*SendAsyncMessage*/ (hWnd, WM_SIZECHANGED,
922
            (WPARAM)&rcWin, (LPARAM)&rcClient);
923
#endif
924
    }
925
 
926
    if (bShow) {
927
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
928
    }
929
    else {
930
        rcBar.left -= pWin->clirect.left;
931
        rcBar.top  -= pWin->clirect.top;
932
        rcBar.right -= pWin->clirect.left;
933
        rcBar.bottom -= pWin->clirect.top;
934
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
935
        InvalidateRect (hWnd, &rcBar, TRUE);
936
    }
937
 
938
    return TRUE;
939
}
940
#endif

powered by: WebSVN 2.1.0

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