comparison win/dw.c @ 841:9be19dbd2ff4

Basic handling for the scrolled widget. Scrollbox now works on Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 29 Mar 2011 22:20:45 +0000
parents ccfa5173659f
children 89dd3e442e7e
comparison
equal deleted inserted replaced
840:2967934fb587 841:9be19dbd2ff4
1367 (width + vectorx) - 20, height + vectory, FALSE); 1367 (width + vectorx) - 20, height + vectory, FALSE);
1368 } 1368 }
1369 } 1369 }
1370 else if(strncmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0) 1370 else if(strncmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0)
1371 { 1371 {
1372 /* Then try the bottom or right box */ 1372 /* Handle special case of scrollbox */
1373 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1373 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
1374 int cx = width + vectorx; 1374 int cx = width + vectorx;
1375 int cy = height + vectory; 1375 int cy = height + vectory;
1376 int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0; 1376 int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0;
1377 Box *thisbox = (Box *)GetWindowLongPtr(cinfo->combo, GWLP_USERDATA); 1377 Box *thisbox = (Box *)GetWindowLongPtr(cinfo->combo, GWLP_USERDATA);
1378 SCROLLINFO hsi, vsi;
1378 RECT rect; 1379 RECT rect;
1379 1380
1381 vsi.cbSize = hsi.cbSize = sizeof(SCROLLINFO);
1382 vsi.fMask = hsi.fMask = SIF_POS;
1383
1384 /* Save the current scroll positions */
1385 GetScrollInfo(handle, SB_HORZ, &hsi);
1386 GetScrollInfo(handle, SB_VERT, &vsi);
1387
1380 /* Position the scrollbox */ 1388 /* Position the scrollbox */
1381 MoveWindow(handle, currentx + pad, currenty + pad, cx, cy, FALSE); 1389 MoveWindow(handle, currentx + pad, currenty + pad, cx, cy, FALSE);
1382 1390
1383 GetClientRect(handle, &rect); 1391 GetClientRect(handle, &rect);
1384 cx = rect.right; 1392 cx = rect.right;
1396 { 1404 {
1397 cy = usedy; 1405 cy = usedy;
1398 } 1406 }
1399 1407
1400 /* Position the scrolled box */ 1408 /* Position the scrolled box */
1401 MoveWindow(cinfo->combo, 0, 0, cx, cy, FALSE); 1409 vsi.fMask = hsi.fMask = SIF_POS | SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL;
1410 vsi.nMin = hsi.nMin = vsi.nMax = hsi.nMax = 0;
1411 if(rect.bottom < usedy)
1412 {
1413 vsi.nMax = usedy;
1414 vsi.nPage = rect.bottom;
1415 if(vsi.nPos > vsi.nMax)
1416 {
1417 vsi.nPos = vsi.nMax;
1418 }
1419 }
1420 if(rect.right < usedx)
1421 {
1422 hsi.nMax = usedx;
1423 hsi.nPage = rect.right;
1424 if(hsi.nPos > hsi.nMax)
1425 {
1426 hsi.nPos = hsi.nMax;
1427 }
1428 }
1429 MoveWindow(cinfo->combo, -hsi.nPos, -vsi.nPos, cx, cy, FALSE);
1430 SetScrollInfo(handle, SB_HORZ, &hsi, TRUE);
1431 SetScrollInfo(handle, SB_VERT, &vsi, TRUE);
1402 1432
1403 /* Layout the content of the scrollbox */ 1433 /* Layout the content of the scrollbox */
1404 _do_resize(thisbox, cx, cy); 1434 _do_resize(thisbox, cx, cy);
1405 } 1435 }
1406 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) 1436 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
1512 } 1542 }
1513 1543
1514 int _HandleScroller(HWND handle, int bar, int pos, int which) 1544 int _HandleScroller(HWND handle, int bar, int pos, int which)
1515 { 1545 {
1516 SCROLLINFO si; 1546 SCROLLINFO si;
1517 #ifndef SCROLLBOX_DEBUG
1518 char lasterror[257];
1519 #endif
1520 1547
1521 ZeroMemory( &si, sizeof(si) ); 1548 ZeroMemory( &si, sizeof(si) );
1522 si.cbSize = sizeof(SCROLLINFO); 1549 si.cbSize = sizeof(SCROLLINFO);
1523 si.fMask = SIF_ALL; 1550 si.fMask = SIF_ALL;
1524 1551
1525 SendMessage(handle, SBM_GETSCROLLINFO, 0, (LPARAM)&si); 1552 SendMessage(handle, SBM_GETSCROLLINFO, 0, (LPARAM)&si);
1526 #ifndef SCROLLBOX_DEBUG
1527 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), lasterror, 256, NULL);
1528 _dw_log( "Error from SendMessage in _HandleScroller: Handle %x Bar %s(%d) Which %d: %s", handle, (bar==SB_HORZ)?"HORZ" : "VERT", bar, which,lasterror );
1529 #endif
1530 1553
1531 ZeroMemory( &si, sizeof(si) ); 1554 ZeroMemory( &si, sizeof(si) );
1532 si.cbSize = sizeof(SCROLLINFO); 1555 si.cbSize = sizeof(SCROLLINFO);
1533 si.fMask = SIF_ALL; 1556 si.fMask = SIF_ALL;
1534 #ifndef SCROLLBOX_DEBUG
1535 GetScrollInfo( handle, bar, &si );
1536 _dw_log( "Error from GetScrollInfo in _HandleScroller: Handle %x Bar %s(%d) Which %d: %s", handle, (bar==SB_HORZ)?"HORZ" : "VERT", bar, which,lasterror );
1537 #endif
1538 1557
1539 switch(which) 1558 switch(which)
1540 { 1559 {
1541 case SB_THUMBTRACK: 1560 case SB_THUMBTRACK:
1542 return pos; 1561 return pos;
3213 /* This handles any activity on the scrollbox */ 3232 /* This handles any activity on the scrollbox */
3214 BOOL CALLBACK _scrollwndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) 3233 BOOL CALLBACK _scrollwndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2)
3215 { 3234 {
3216 switch (msg) 3235 switch (msg)
3217 { 3236 {
3218 case WM_HSCROLL: 3237 case WM_HSCROLL:
3219 case WM_VSCROLL: 3238 case WM_VSCROLL:
3220 { 3239 {
3221 HWND handle = (HWND)mp2; 3240 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
3222 } 3241 SCROLLINFO hsi, vsi, *si = &hsi;
3223 break; 3242 int bar = SB_HORZ;
3243 int which = LOWORD(mp1);
3244
3245 vsi.cbSize = hsi.cbSize = sizeof(SCROLLINFO);
3246 vsi.fMask = hsi.fMask = SIF_POS | SIF_RANGE;
3247
3248 /* Save the current scroll positions */
3249 GetScrollInfo(hwnd, SB_HORZ, &hsi);
3250 GetScrollInfo(hwnd, SB_VERT, &vsi);
3251
3252 if(msg == WM_VSCROLL)
3253 {
3254 bar = SB_VERT;
3255 si = &vsi;
3256 }
3257
3258 switch(which)
3259 {
3260 case SB_THUMBTRACK:
3261 si->nPos = HIWORD(mp1);
3262 break;
3263 /*case SB_PAGEDOWN:*/
3264 case SB_PAGELEFT:
3265 si->nPos = si->nPos - si->nPage;
3266 if(si->nPos < 0)
3267 si->nPos = 0;
3268 break;
3269 /*case SB_PAGEUP:*/
3270 case SB_PAGERIGHT:
3271 si->nPos = si->nPos + si->nPage;
3272 if(si->nPos > (si->nMax - si->nPage) + 1)
3273 si->nPos = (si->nMax - si->nPage) + 1;
3274 break;
3275 /*case SB_LINEDOWN:*/
3276 case SB_LINELEFT:
3277 si->nPos = si->nPos - 1;
3278 if(si->nPos < si->nMin)
3279 si->nPos = si->nMin;
3280 break;
3281 /*case SB_LINEUP:*/
3282 case SB_LINERIGHT:
3283 si->nPos = si->nPos + 1;
3284 if(si->nPos > (si->nMax - si->nPage) + 1)
3285 si->nPos = (si->nMax - si->nPage) + 1;
3286 break;
3287 }
3288
3289 /* Position the scrolled box */
3290 vsi.fMask = hsi.fMask = SIF_POS | SIF_DISABLENOSCROLL;
3291 SetWindowPos(cinfo->combo, 0, -hsi.nPos, -vsi.nPos, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
3292 SetScrollInfo(hwnd, bar, si, TRUE);
3293 }
3294 break;
3224 } 3295 }
3225 return DefWindowProc(hwnd, msg, mp1, mp2); 3296 return DefWindowProc(hwnd, msg, mp1, mp2);
3226 } 3297 }
3227 3298
3228 /* This handles any activity on the splitbars (sizers) */ 3299 /* This handles any activity on the splitbars (sizers) */