2 * Interface code to SCROLLBAR widget
4 * Copyright Martin Ayotte, 1993
12 static char Copyright
[] = "Copyright Martin Ayotte, 1993";
14 #include <X11/Intrinsic.h>
15 #include <X11/StringDefs.h>
23 LPHEADSCROLL
ScrollBarGetWindowAndStorage(HWND hwnd
, WND
**wndPtr
);
24 LPHEADSCROLL
ScrollBarGetStorageHeader(HWND hwnd
);
25 void StdDrawScrollBar(HWND hwnd
);
26 int CreateScrollBarStruct(HWND hwnd
);
29 void SCROLLBAR_CreateScrollBar(LPSTR className
, LPSTR scrollLabel
, HWND hwnd
)
31 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
32 WND
*parentPtr
= WIN_FindWndPtr(wndPtr
->hwndParent
);
36 #ifdef DEBUG_SCROLLBAR
37 printf("scroll: label = %s, x = %d, y = %d\n", scrollLabel
,
38 wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
);
39 printf(" width = %d, height = %d\n",
40 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
,
41 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
);
47 style
= wndPtr
->dwStyle
& 0x0000FFFF;
49 if ((style & SBS_NOTIFY) == SBS_NOTIFY)
51 sprintf(widgetName
, "%s%d", className
, wndPtr
->wIDmenu
);
52 wndPtr
->winWidget
= XtVaCreateManagedWidget(widgetName
,
55 XtNx
, wndPtr
->rectClient
.left
,
56 XtNy
, wndPtr
->rectClient
.top
,
57 XtNwidth
, wndPtr
->rectClient
.right
-
58 wndPtr
->rectClient
.left
,
59 XtNheight
, wndPtr
->rectClient
.bottom
-
60 wndPtr
->rectClient
.top
,
63 GlobalUnlock(wndPtr
->hwndParent
);
68 /***********************************************************************
69 * WIDGETS_ScrollBarWndProc
71 LONG
SCROLLBAR_ScrollBarWndProc( HWND hwnd
, WORD message
,
72 WORD wParam
, LONG lParam
)
83 CreateScrollBarStruct(hwnd
);
85 printf("ScrollBar Creation up=%X down=%X!\n", lphs
->hWndUp
, lphs
->hWndDown
);
89 lphs
= ScrollBarGetStorageHeader(hwnd
);
90 DestroyWindow(lphs
->hWndUp
);
91 DestroyWindow(lphs
->hWndDown
);
93 printf("ScrollBar WM_DESTROY !\n");
98 printf("ScrollBar WM_COMMAND wParam=%X lParam=%lX !\n", wParam
, lParam
);
100 lphs
= ScrollBarGetWindowAndStorage(hwnd
, &wndPtr
);
101 if (HIWORD(lParam
) != BN_CLICKED
) return 0;
102 if (LOWORD(lParam
) == lphs
->hWndUp
)
103 SendMessage(wndPtr
->hwndParent
, lphs
->Direction
,
104 SB_LINEUP
, MAKELONG(0, hwnd
));
105 if (LOWORD(lParam
) == lphs
->hWndDown
)
106 SendMessage(wndPtr
->hwndParent
, lphs
->Direction
,
107 SB_LINEDOWN
, MAKELONG(0, hwnd
));
111 lphs
= ScrollBarGetWindowAndStorage(hwnd
, &wndPtr
);
112 GetClientRect(hwnd
, &rect
);
113 if (lphs
->Direction
== WM_VSCROLL
) {
116 printf("WM_LBUTTONDOWN y=%d cur+right=%d %d\n",
117 y
, lphs
->CurPix
+ rect
.right
, lphs
->CurPix
+ (rect
.right
<< 1));
119 if (y
< (lphs
->CurPix
+ rect
.right
))
120 SendMessage(wndPtr
->hwndParent
, lphs
->Direction
,
121 SB_PAGEUP
, MAKELONG(0, hwnd
));
122 if (y
> (lphs
->CurPix
+ (rect
.right
<< 1)))
123 SendMessage(wndPtr
->hwndParent
, lphs
->Direction
,
124 SB_PAGEDOWN
, MAKELONG(0, hwnd
));
125 if ((y
> (lphs
->CurPix
+ rect
.right
)) &&
126 (y
< (lphs
->CurPix
+ (rect
.right
<< 1)))) {
127 lphs
->ThumbActive
= TRUE
;
129 printf("THUMB DOWN !\n");
136 printf("WM_LBUTTONDOWN x=%d Cur+bottom=%d %d\n",
137 x
, lphs
->CurPix
+ rect
.bottom
, lphs
->CurPix
+ (rect
.bottom
<< 1));
139 if (x
< (lphs
->CurPix
+ rect
.bottom
))
140 SendMessage(wndPtr
->hwndParent
, lphs
->Direction
,
141 SB_PAGEUP
, MAKELONG(0, hwnd
));
142 if (x
> (lphs
->CurPix
+ (rect
.bottom
<< 1)))
143 SendMessage(wndPtr
->hwndParent
, lphs
->Direction
,
144 SB_PAGEDOWN
, MAKELONG(0, hwnd
));
145 if ((x
> (lphs
->CurPix
+ rect
.bottom
)) &&
146 (x
< (lphs
->CurPix
+ (rect
.bottom
<< 1)))) {
147 lphs
->ThumbActive
= TRUE
;
149 printf("THUMB DOWN !\n");
155 lphs
->ThumbActive
= FALSE
;
159 printf("ScrollBar WM_KEYDOWN wParam %X!\n", wParam
);
162 StdDrawScrollBar(hwnd
);
165 if ((wParam
& MK_LBUTTON
) != 0) {
166 lphs
= ScrollBarGetWindowAndStorage(hwnd
, &wndPtr
);
167 if (lphs
->ThumbActive
== 0) break;
168 GetClientRect(hwnd
, &rect
);
169 if (lphs
->Direction
== WM_VSCROLL
)
170 y
= HIWORD(lParam
) - rect
.right
- (rect
.right
>> 1);
172 y
= LOWORD(lParam
) - rect
.bottom
- (rect
.bottom
>> 1);
173 x
= (y
* (lphs
->MaxVal
- lphs
->MinVal
) /
174 lphs
->MaxPix
) + lphs
->MinVal
;
176 printf("WM_MOUSEMOVE val=%d pix=%d\n", x
, y
);
178 SendMessage(wndPtr
->hwndParent
, lphs
->Direction
,
179 SB_THUMBTRACK
, MAKELONG(x
, hwnd
));
183 return DefWindowProc( hwnd
, message
, wParam
, lParam
);
190 LPHEADSCROLL
ScrollBarGetWindowAndStorage(HWND hwnd
, WND
**wndPtr
)
194 *(wndPtr
) = Ptr
= WIN_FindWndPtr(hwnd
);
195 lphs
= *((LPHEADSCROLL
*)&Ptr
->wExtra
[1]);
200 LPHEADSCROLL
ScrollBarGetStorageHeader(HWND hwnd
)
204 wndPtr
= WIN_FindWndPtr(hwnd
);
205 lphs
= *((LPHEADSCROLL
*)&wndPtr
->wExtra
[1]);
210 void StdDrawScrollBar(HWND hwnd
)
219 hdc
= BeginPaint( hwnd
, &ps
);
220 hBrush
= SendMessage(GetParent(hwnd
), WM_CTLCOLOR
, (WORD
)hdc
,
221 MAKELONG(hwnd
, CTLCOLOR_SCROLLBAR
));
222 if (hBrush
== (HBRUSH
)NULL
) hBrush
= GetStockObject(LTGRAY_BRUSH
);
223 lphs
= ScrollBarGetStorageHeader(hwnd
);
224 if (lphs
== NULL
) goto EndOfPaint
;
225 GetClientRect(hwnd
, &rect
);
226 w
= rect
.right
- rect
.left
;
227 h
= rect
.bottom
- rect
.top
;
228 if (lphs
->Direction
== WM_VSCROLL
) {
236 FillRect(hdc
, &rect
, hBrush
);
237 if (lphs
->Direction
== WM_VSCROLL
)
238 SetRect(&rect
, 0, lphs
->CurPix
+ w
,
239 w
, lphs
->CurPix
+ (w
<< 1));
241 SetRect(&rect
, lphs
->CurPix
+ h
,
242 0, lphs
->CurPix
+ (h
<< 1), h
);
243 FrameRect(hdc
, &rect
, GetStockObject(BLACK_BRUSH
));
244 InflateRect(&rect
, -1, -1);
245 FillRect(hdc
, &rect
, GetStockObject(LTGRAY_BRUSH
));
246 DrawReliefRect(hdc
, rect
, 2, 0);
247 InflateRect(&rect
, -3, -3);
248 DrawReliefRect(hdc
, rect
, 1, 1);
250 EndPaint( hwnd
, &ps
);
251 InvalidateRect(lphs
->hWndUp
, NULL
, TRUE
);
252 UpdateWindow(lphs
->hWndUp
);
253 InvalidateRect(lphs
->hWndDown
, NULL
, TRUE
);
254 UpdateWindow(lphs
->hWndDown
);
259 int CreateScrollBarStruct(HWND hwnd
)
265 wndPtr
= WIN_FindWndPtr(hwnd
);
266 lphs
= (LPHEADSCROLL
)malloc(sizeof(HEADSCROLL
));
267 *((LPHEADSCROLL
*)&wndPtr
->wExtra
[1]) = lphs
;
273 width
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
274 height
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
275 lphs
= ScrollBarGetStorageHeader(hwnd
);
276 if (lphs
== NULL
) return 0;
279 lphs
->MaxPix
= height
- 3 * width
;
280 lphs
->Direction
= WM_VSCROLL
;
281 lphs
->hWndUp
= CreateWindow("BUTTON", "",
282 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
283 0, 0, width
, width
, hwnd
, 1, wndPtr
->hInstance
, 0L);
284 lphs
->hWndDown
= CreateWindow("BUTTON", "",
285 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
286 0, height
- width
, width
, width
, hwnd
, 2,
287 wndPtr
->hInstance
, 0L);
291 lphs
->MaxPix
= width
- 3 * height
;
292 lphs
->Direction
= WM_HSCROLL
;
293 lphs
->hWndUp
= CreateWindow("BUTTON", "",
294 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
295 0, 0, height
, height
, hwnd
, 0, wndPtr
->hInstance
, 0L);
296 lphs
->hWndDown
= CreateWindow("BUTTON", "",
297 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
298 width
- height
, 0, height
, height
, hwnd
, 0,
299 wndPtr
->hInstance
, 0L);
301 if (lphs
->MaxPix
< 1) lphs
->MaxPix
= 1;
307 int GetScrollPos(HWND hwnd
, int nBar
)
310 lphs
= ScrollBarGetStorageHeader(hwnd
);
311 if (lphs
== NULL
) return;
317 void GetScrollRange(HWND hwnd
, int nBar
, LPINT lpMin
, LPINT lpMax
)
320 lphs
= ScrollBarGetStorageHeader(hwnd
);
321 if (lphs
== NULL
) return;
322 *lpMin
= lphs
->MinVal
;
323 *lpMax
= lphs
->MaxVal
;
328 int SetScrollPos(HWND hwnd
, int nBar
, int nPos
, BOOL bRedraw
)
332 lphs
= ScrollBarGetStorageHeader(hwnd
);
333 if (lphs
== NULL
) return;
335 lphs
->CurVal
= (short)nPos
;
336 if (lphs
->MaxVal
!= lphs
->MinVal
)
337 lphs
->CurPix
= lphs
->MaxPix
* (abs((short)nPos
) - abs(lphs
->MinVal
)) /
338 (abs(lphs
->MaxVal
) - abs(lphs
->MinVal
));
339 if (lphs
->CurPix
> lphs
->MaxPix
) lphs
->CurPix
= lphs
->MaxPix
;
341 printf("SetScrollPos val=%d pixval=%d pixmax%d\n",
342 (short)nPos
, lphs
->CurPix
, lphs
->MaxPix
);
343 printf("SetScrollPos min=%d max=%d\n",
344 lphs
->MinVal
, lphs
->MaxVal
);
347 InvalidateRect(hwnd
, NULL
, TRUE
);
355 void SetScrollRange(HWND hwnd
, int nBar
, int MinPos
, int MaxPos
, BOOL bRedraw
)
358 lphs
= ScrollBarGetStorageHeader(hwnd
);
359 if (lphs
== NULL
) return;
360 lphs
->MinVal
= (short)MinPos
;
361 lphs
->MaxVal
= (short)MaxPos
;
362 if (lphs
->MaxVal
!= lphs
->MinVal
)
363 lphs
->CurPix
= abs(lphs
->MaxVal
) *
364 (abs(lphs
->CurVal
) - abs(lphs
->MinVal
)) /
365 (abs(lphs
->MaxVal
) - abs(lphs
->MinVal
));
366 if (lphs
->CurPix
> lphs
->MaxPix
) lphs
->CurPix
= lphs
->MaxPix
;
368 printf("SetScrollRange min=%d max=%d\n", lphs
->MinVal
, lphs
->MaxVal
);
371 InvalidateRect(hwnd
, NULL
, TRUE
);