void ServerOpts2::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: Add your message handler code here and/or call default int OldScrollPos = GetScrollPos(SB_VERT); CScrollBar* pLScrollBar = GetScrollBarCtrl(SB_VERT); int Min, Max; GetScrollRange(SB_VERT, &Min, &Max); RECT WindowRect; GetClientRect(&WindowRect); long WindowHeight = WindowRect.bottom - WindowRect.top; long PageSize = WindowHeight; long LineSize = PageSize/10; switch (nSBCode) { case SB_TOP : // Scroll to top. { SetScrollPos(SB_VERT, Min, TRUE); ScrollWindow(0, Min - OldScrollPos); }break; case SB_BOTTOM : //Scroll to bottom. { SetScrollPos(SB_VERT, Max, TRUE); ScrollWindow(0, Max - OldScrollPos); }break; case SB_LINEDOWN : // Scroll one line down. { if (OldScrollPos < Max) { SetScrollPos(SB_VERT, OldScrollPos+LineSize, TRUE); ScrollWindow(0, -LineSize); }; };break; case SB_LINEUP : // Scroll one line up. { if (OldScrollPos > Min) { SetScrollPos(SB_VERT, OldScrollPos-LineSize, TRUE); ScrollWindow(0, LineSize); } }break; case SB_PAGEDOWN : // Scroll one page down. { int NewPos = OldScrollPos + PageSize; if (NewPos > Max) NewPos = Max; SetScrollPos(SB_VERT, NewPos, TRUE); ScrollWindow(0, OldScrollPos - NewPos); }break; case SB_PAGEUP : // Scroll one page up. { int NewPos = OldScrollPos - PageSize; if (NewPos < Min) NewPos = Min; SetScrollPos(SB_VERT, NewPos, TRUE); ScrollWindow(0, OldScrollPos - NewPos); }break; case SB_THUMBPOSITION : // Scroll to the absolute position. The current position is provided in nPos. // { // }break; case SB_THUMBTRACK : // Drag scroll box to specified position. The current position is provided in nPos. { ScrollWindow(0, OldScrollPos - nPos); SetScrollPos(SB_VERT, nPos, TRUE); }break; case SB_ENDSCROLL :// End scroll. { }break; }; CSubDlg::OnVScroll(nSBCode, nPos, pScrollBar); }
void CGroupsUI::DoEvent(TEventUI& event) { if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) { if (m_pParent != NULL) m_pParent->DoEvent(event); else CVerticalLayoutUI::DoEvent(event); return; } if (event.Type == UIEVENT_TIMER && event.wParam == SCROLL_TIMERID) { if (delay_left_ > 0) { --delay_left_; SIZE sz = GetScrollPos(); LONG lDeltaY = (LONG)(CalculateDelay((double)delay_left_ / delay_number_) * delay_deltaY_); if ((lDeltaY > 0 && sz.cy != 0) || (lDeltaY < 0 && sz.cy != GetScrollRange().cy )) { sz.cy -= lDeltaY; SetScrollPos(sz); return; } } delay_deltaY_ = 0; delay_number_ = 0; delay_left_ = 0; m_pManager->KillTimer(this, SCROLL_TIMERID); return; } if (event.Type == UIEVENT_SCROLLWHEEL) { LONG lDeltaY = 0; if (delay_number_ > 0) lDeltaY = (LONG)(CalculateDelay((double)delay_left_ / delay_number_) * delay_deltaY_); switch (LOWORD(event.wParam)) { case SB_LINEUP: if (delay_deltaY_ >= 0) delay_deltaY_ = lDeltaY + 8; else delay_deltaY_ = lDeltaY + 12; break; case SB_LINEDOWN: if (delay_deltaY_ <= 0) delay_deltaY_ = lDeltaY - 8; else delay_deltaY_ = lDeltaY - 12; break; } if (delay_deltaY_ > 100) delay_deltaY_ = 100; else if (delay_deltaY_ < -100) delay_deltaY_ = -100; delay_number_ = (DWORD)sqrt((double)abs(delay_deltaY_)) * 5; delay_left_ = delay_number_; m_pManager->SetTimer(this, SCROLL_TIMERID, 20U); return; } CListUI::DoEvent(event); }
/* some tests designed to show that Horizontal and Vertical * window scroll bar info are not created independently */ static void scrollbar_test_default( DWORD style) { INT min, max, ret; DWORD winstyle; HWND hwnd; SCROLLINFO si = { sizeof( SCROLLINFO), SIF_TRACKPOS }; hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style, 0, 0, 10, 10, 0, 0, 0, NULL); assert( hwnd != 0); ret = GetScrollRange( hwnd, SB_VERT, &min, &max); ok( ret || broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n"); /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */ if( !( style & ( WS_VSCROLL | WS_HSCROLL))) ok( min == 0 && max == 0, "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style); else todo_wine ok(( min == 0 && max == 100) || broken( min == 0 && max == 0), /* Win 9x/ME */ "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style); ret = GetScrollRange( hwnd, SB_HORZ, &min, &max); ok( ret || broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n"); /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */ if( !( style & ( WS_VSCROLL | WS_HSCROLL))) ok( min == 0 && max == 0, "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style); else todo_wine ok(( min == 0 && max == 100) || broken( min == 0 && max == 0), /* Win 9x/ME */ "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style); /* test GetScrollInfo, vist for vertical SB */ ret = GetScrollInfo( hwnd, SB_VERT, &si); /* should fail if no H or V scroll bar styles are present. Succeed otherwise */ if( !( style & ( WS_VSCROLL | WS_HSCROLL))) ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style); else todo_wine ok( ret || broken( !ret), /* Win 9x/ME */ "GetScrollInfo failed unexpectedly. Style is %08x\n", style); /* Same for Horizontal SB */ ret = GetScrollInfo( hwnd, SB_HORZ, &si); /* should fail if no H or V scroll bar styles are present. Succeed otherwise */ if( !( style & ( WS_VSCROLL | WS_HSCROLL))) ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style); else todo_wine ok( ret || broken( !ret), /* Win 9x/ME */ "GetScrollInfo failed unexpectedly. Style is %08x\n", style); /* now set the Vertical Scroll range to something that could be the default value it * already has */; ret = SetScrollRange( hwnd, SB_VERT, 0, 100, FALSE); ok( ret, "SetScrollRange failed.\n"); /* and request the Horizontal range */ ret = GetScrollRange( hwnd, SB_HORZ, &min, &max); ok( ret, "GetScrollRange failed.\n"); /* now the range should be 0,100 in ALL cases */ ok( min == 0 && max == 100, "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style); /* See what is different now for GetScrollRange */ ret = GetScrollInfo( hwnd, SB_HORZ, &si); /* should succeed in ALL cases */ ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style); ret = GetScrollInfo( hwnd, SB_VERT, &si); /* should succeed in ALL cases */ ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style); /* report the windows style */ winstyle = GetWindowLongA( hwnd, GWL_STYLE ); /* WS_VSCROLL added to the window style */ if( !(style & WS_VSCROLL)) { if (bThemeActive || style != WS_HSCROLL) todo_wine ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_VSCROLL), "unexpected style change %8lx expected %8lx\n", (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_VSCROLL); else ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style || broken((winstyle & (WS_HSCROLL|WS_VSCROLL)) == (WS_HSCROLL|WS_VSCROLL)), /* Win 9x/ME */ "unexpected style change %8lx expected %8x\n", (winstyle & (WS_HSCROLL|WS_VSCROLL)), style); } /* do the test again with H and V reversed. * Start with a clean window */ DestroyWindow( hwnd); hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style, 0, 0, 10, 10, 0, 0, 0, NULL); assert( hwnd != 0); /* Set Horizontal Scroll range to something that could be the default value it * already has */; ret = SetScrollRange( hwnd, SB_HORZ, 0, 100, FALSE); ok( ret, "SetScrollRange failed.\n"); /* and request the Vertical range */ ret = GetScrollRange( hwnd, SB_VERT, &min, &max); ok( ret, "GetScrollRange failed.\n"); /* now the range should be 0,100 in ALL cases */ ok( min == 0 && max == 100, "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style); /* See what is different now for GetScrollRange */ ret = GetScrollInfo( hwnd, SB_HORZ, &si); /* should succeed in ALL cases */ ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style); ret = GetScrollInfo( hwnd, SB_VERT, &si); /* should succeed in ALL cases */ ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style); /* report the windows style */ winstyle = GetWindowLongA( hwnd, GWL_STYLE ); /* WS_HSCROLL added to the window style */ if( !(style & WS_HSCROLL)) { if (bThemeActive || style != WS_VSCROLL) todo_wine ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_HSCROLL), "unexpected style change %8lx expected %8lx\n", (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_HSCROLL); else ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style || broken((winstyle & (WS_HSCROLL|WS_VSCROLL)) == (WS_HSCROLL|WS_VSCROLL)), /* Win 9x/ME */ "unexpected style change %8lx expected %8x\n", (winstyle & (WS_HSCROLL|WS_VSCROLL)), style); } /* Slightly change the test to use SetScrollInfo * Start with a clean window */ DestroyWindow( hwnd); hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style, 0, 0, 10, 10, 0, 0, 0, NULL); assert( hwnd != 0); /* set Horizontal position with SetScrollInfo */ si.nPos = 0; si.nMin = 11; si.nMax = 22; si.fMask |= SIF_RANGE; ret = SetScrollInfo( hwnd, SB_HORZ, &si, FALSE); ok( ret, "SetScrollInfo failed. Style is %08x\n", style); /* and request the Vertical range */ ret = GetScrollRange( hwnd, SB_VERT, &min, &max); ok( ret, "GetScrollRange failed.\n"); /* now the range should be 0,100 in ALL cases */ ok( min == 0 && max == 100, "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style); /* See what is different now for GetScrollRange */ ret = GetScrollInfo( hwnd, SB_HORZ, &si); /* should succeed in ALL cases */ ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style); ret = GetScrollInfo( hwnd, SB_VERT, &si); /* should succeed in ALL cases */ ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style); /* also test if the window scroll bars are enabled */ ret = EnableScrollBar( hwnd, SB_VERT, ESB_ENABLE_BOTH); ok( !ret, "Vertical window scroll bar was not enabled\n"); ret = EnableScrollBar( hwnd, SB_HORZ, ESB_ENABLE_BOTH); ok( !ret, "Horizontal window scroll bar was not enabled\n"); DestroyWindow( hwnd); /* finally, check if adding a WS_[HV]SColl style of a window makes the scroll info * available */ if( style & (WS_HSCROLL | WS_VSCROLL)) return;/* only test if not yet set */ /* Start with a clean window */ DestroyWindow( hwnd); hwnd = CreateWindowExA( 0, "static", "", WS_POPUP , 0, 0, 10, 10, 0, 0, 0, NULL); assert( hwnd != 0); ret = GetScrollInfo( hwnd, SB_VERT, &si); /* should fail */ ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style); /* add scroll styles */ winstyle = GetWindowLongA( hwnd, GWL_STYLE ); SetWindowLongW( hwnd, GWL_STYLE, winstyle | WS_VSCROLL | WS_HSCROLL); ret = GetScrollInfo( hwnd, SB_VERT, &si); /* should still fail */ ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style); /* clean up */ DestroyWindow( hwnd); }
/* WM_VSCROLL message processing */ void window::WMVScroll(HWND &hwnd, UINT &message, WPARAM &wParam, LPARAM &lParam) { int k, /* Counter */ cur_pos, /* Current scroll position */ new_pos, /* New scroll position */ num_str_to_end; char buf[8]; VEC2 range; GetScrollRange(hwnd, SB_VERT, &range.x, &range.y); new_pos = cur_pos = GetScrollPos(hwnd, SB_VERT); switch(LOWORD(wParam)) { case SB_LINEUP: if (new_pos > 0) { new_pos = cur_pos - 1; txt -= vert_scrlb_step; } break; case SB_LINEDOWN: if (new_pos < range.y) { new_pos = cur_pos + 1; txt += vert_scrlb_step; } break; case SB_PAGEUP: num_str_to_end = cur_pos * vert_scrlb_step; if (num_str_to_end > 0) { if (num_str_to_end > 2 * client_field.y) { txt -= client_field.y; new_pos -= client_field.y / vert_scrlb_step; } else { txt -= num_str_to_end; new_pos -= num_str_to_end / vert_scrlb_step; } } break; case SB_PAGEDOWN: num_str_to_end = (txt.num_of_str - cur_pos * vert_scrlb_step)/1; if (num_str_to_end > client_field.y) { if (num_str_to_end > 2 * client_field.y) { txt += client_field.y; new_pos += client_field.y / vert_scrlb_step; } else { txt += abs(client_field.y - num_str_to_end); new_pos += abs(client_field.y - num_str_to_end) / vert_scrlb_step; } } break; case SB_THUMBTRACK: new_pos = HIWORD(wParam); if ((k = new_pos - cur_pos) > 0) txt += abs(k) * vert_scrlb_step; else if (k < 0) txt -= abs(k) * vert_scrlb_step; break; } sprintf(buf, "%i %%", (int)(cur_pos * 1.0 / range.y * 100)); SendMessage(hStatWnd, SB_SETTEXT, (WPARAM)1,(LPARAM)buf); if (cur_pos != new_pos) { SetScrollPos(hwnd, SB_VERT, new_pos, TRUE); InvalidateRect(hwnd, NULL, TRUE); } } /* End of 'window::WMVScroll' function */
static void fillListBox(HWND hWnd, LPSTR lpszDir) { HWND hWndLB = GetDlgItem(hWnd, ID_LIST_DIR); HWND hWndTempLB = GetDlgItem(hWnd, ID_LISTTEMP_DIR); HWND hWndEdit = GetDlgItem(hWnd, ID_EDIT_DIR); if((hWndLB == NULL) || (lpszDir == NULL)) return; int iLastChar = lstrlen(lpszDir); if(lpszDir[iLastChar - 1] == '\\') lpszDir[iLastChar - 1] = '\0'; SetWindowRedraw(hWndLB, FALSE); ListBox_ResetContent(hWndLB); ListBox_ResetContent(hWndTempLB); LPSTR lpszLast; lpszLast = CharLower(lpszDir); SetWindowText(hWndLB, lpszDir); char szDir[_MAX_DIR]; char szFullDir[_MAX_DIR]; sprintf(szFullDir, "%s", lpszDir); sprintf(szDir, "%s\\*.*", lpszDir); BOOL bFirst = TRUE; char ch; int index; while (TRUE) { LPSTR lpsz; if((lpszDir[0] == '\\') && (lpszDir[1] == '\\') && bFirst) lpsz = strchr(lpszLast + lstrlen(szUNCRoot), '\\'); else lpsz = strchr(lpszLast, '\\'); if(lpsz != NULL) { if (bFirst) ch = *(++lpsz); else ch = *lpsz; *lpsz = 0; } else { //If we're looking at a drive only, then append a backslash if (lpszLast == lpszDir && bFirst) lstrcat(lpszLast, "\\"); } //Add the drive string--includes the last one where lpsz == NULL index = ListBox_AddString(hWndLB, lpszLast); UINT i = (NULL != lpsz) ? ID_ICON_FOLDEROPEN : ID_ICON_OPENSELECT; ListBox_SetItemData(hWndLB, index, MAKELONG(index, i)); if(NULL == lpsz) break; //Restore last character. *lpsz = ch; lpsz += (bFirst) ? 0 : 1; bFirst=FALSE; lpszLast = lpsz; } int indent = index + 1; //Get available directories fillTempLBWithDirs(hWndTempLB, lpszDir); int itemCount = ListBox_GetCount(hWndTempLB); int i=0; for (i = 0; i < itemCount; i++) { index = ListBox_GetText(hWndTempLB, i, lpszDir); //Skip directories beginning with . (skipping . and ..) if(lpszDir[1] == '.') continue; //Remove the ending ']' iLastChar = lstrlen(lpszDir); lpszDir[iLastChar - 1] = '\0'; //Add the string to the real directory list. index = ListBox_AddString(hWndLB, lpszDir + 1); ListBox_SetItemData(hWndLB, index, MAKELONG(indent, ID_ICON_FOLDERCLOSED)); } //Force a listbox repaint. SetWindowRedraw(hWndLB, TRUE); InvalidateRect(hWndLB, NULL, TRUE); if(szFullDir[lstrlen(szFullDir) - 1] == ':') lstrcat(szFullDir, "\\"); Edit_SetText(hWndEdit, szFullDir); GetScrollRange(hWndLB, SB_VERT, (LPINT)&i, (LPINT)&index); if(!(i == 0 && index == 0)) ListBox_SetTopIndex(hWndLB, max((int)(index - 2), 0)); ListBox_SetCurSel(hWndLB, indent - 1); }
/*********************************************************************** * FlatSB_GetScrollRange (COMCTL32.@) * * See GetScrollRange. */ BOOL WINAPI FlatSB_GetScrollRange(HWND hwnd, int nBar, LPINT min, LPINT max) { return GetScrollRange(hwnd, nBar, min, max); }
void CContainerUI::EndRight() { SIZE sz = GetScrollPos(); sz.cx = GetScrollRange().cx; SetScrollPos(sz); }
LRESULT CDocWindow::OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { UINT ScrollCode = LOWORD(wParam); UINT TrackCode = HIWORD(wParam); // SB_LINERIGHT, SB_LINEDOWN Scrolls one line right/down // SB_LINELEFT, SB_LINEUP Scrolls one line up/left // SB_PAGERIGHT, SB_PAGEDOWN Scrolls one page right/down // SB_PAGELEFT, SB_PAGEUP Scrolls one page left/up // SB_LEFT, SB_TOP Scrolls to the start // SB_RIGHT, SB_BOTTOM Scrolls to the end // SB_ENDSCROLL Ends scroll // SB_THUMBPOSITION The user has dragged the scroll box (thumb) and released the mouse button // The high-order word indicates the position of the scroll box at the end of the drag operation // SB_THUMBTRACK The user is dragging the scroll box // This message is sent repeatedly until the user releases the mouse button // The high-order word indicates the position that the scroll box has been dragged to int nMin = 0; int nMax = 0; if (uMsg == WM_HSCROLL) { GetScrollRange(SB_HORZ, &nMin, &nMax); int nPage = GetScrollPage(SB_HORZ); int nPos = GetScrollPos(SB_HORZ); switch (ScrollCode) { case SB_LINERIGHT: case SB_LINELEFT: { if (SB_LINERIGHT == ScrollCode) nPos += 100; else nPos -= 100; break; } case SB_PAGERIGHT: case SB_PAGELEFT: { if (SB_PAGERIGHT == ScrollCode) nPos += nPage; else nPos -= nPage; break; } case SB_RIGHT: case SB_LEFT: { if (SB_RIGHT == ScrollCode) nPos = nMax; else nPos = nMin; break; } case SB_THUMBTRACK: case SB_THUMBPOSITION: { nPos = TrackCode; break; } default: return S_OK; } if (nPos > nMax + 1 - nPage) nPos = nMax + 1 - nPage; if (nPos < nMin) nPos = nMin; SetScrollPos(SB_HORZ, nPos, true); } else if (uMsg == WM_VSCROLL) { GetScrollRange(SB_VERT, &nMin, &nMax); int nPage = GetScrollPage(SB_VERT); int nPos = GetScrollPos(SB_VERT); switch (ScrollCode) { case SB_LINEDOWN: case SB_LINEUP: { if (SB_LINEDOWN == ScrollCode) nPos += 100; else nPos -= 100; break; } case SB_PAGEDOWN: case SB_PAGEUP: { if (SB_PAGEDOWN == ScrollCode) nPos += nPage; else nPos -= nPage; break; } case SB_BOTTOM: case SB_TOP: { if (SB_BOTTOM == ScrollCode) nPos = nMax; else nPos = nMin; break; } case SB_THUMBTRACK: case SB_THUMBPOSITION: { nPos = TrackCode; break; } default: return S_OK; } if (nPos > nMax + 1 - nPage) nPos = nMax + 1 - nPage; if (nPos < nMin) nPos = nMin; SetScrollPos(SB_VERT, nPos, true); } SetupPageView(false/*bSetScrollbars*/); return S_OK; }
void CAutoScrollView::AutoScroll(UINT nRefMessage) { MSG msg; // dummmy message structure to process incoming // messages while autoscrolling. CPoint ptScrollPos, // Current scroll position - logical units ptDevScrollPos, // Current scroll position - device units ptCursorPos; // Current mouse cursor position CRect rc; // Client area long dx, dy; // Scrolling increment SIZE sizeTotal, // CScrollView scroll data sizePage, sizeLine; int nMapMode, // Mapping mode nMapFactor, // Accounts for mapping mode xMin, xMax, yMin, yMax; // Scroll range if (!m_bAutoScroll) return; msg.message = 0; // forces at least one loop. SetCapture(); GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine); // We keep track of the scroll range because CScrollView::ScrollToPosition always // try to scroll even if the scroll limit has been reached. This results in screen // flickering when ScrollWindow is called. GetScrollRange(SB_HORZ, &xMin, &xMax); GetScrollRange(SB_VERT, &yMin, &yMax); // Process all messages until the relevant mouse button // has been released. nRefMessage depends on which button // has been used to trigger autoscrolling. // while (msg.message != nRefMessage) BOOL bSawRefMessage = FALSE; while (!bSawRefMessage) { // Process incoming messages until autoscroll button is released // You cannot peek here because it may process an invalidate // due to the scrolling. /* if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } */ ptScrollPos = GetScrollPosition(); ptDevScrollPos = GetDeviceScrollPosition(); GetCursorPos(&ptCursorPos); ScreenToClient(&ptCursorPos); GetClientRect(&rc); dx = 0L; dy = 0L; if ((ptCursorPos.y < 0) && (ptDevScrollPos.y != yMin)) // Cursor is above client area dy = min(-sizeLine.cy, max(-sizePage.cy, (ptCursorPos.y/10) * sizeLine.cy)); else if ((ptCursorPos.y > rc.bottom) && (ptDevScrollPos.y != yMax)) // Cursor is below client area dy = max(sizeLine.cy, min(sizePage.cy, ((ptCursorPos.y - rc.bottom)/10) * sizeLine.cy)); // otherwise we can't scroll anyway if ((ptCursorPos.x < 0) && (ptDevScrollPos.x != xMin)) // Cursor is on the left of the client area dx = min(-sizeLine.cx, max(-sizePage.cx, (ptCursorPos.x/10) * sizeLine.cx)); else if ((ptCursorPos.x > rc.right) && (ptDevScrollPos.x != xMax)) // Cursor is on the right of the client area dx = max(sizeLine.cx, min(sizePage.cx, ((ptCursorPos.x - rc.right)/10) * sizeLine.cx)); // otherwise we can't scroll anyway // if mouse cursor is dragging outside the client area, scrolling occurs if ((dx != 0) || (dy != 0)) { // Flip the Y coordinate if we're not in MM_TEXT nMapFactor = (nMapMode == MM_TEXT) ? 1 : -1; ptScrollPos.y += (int) dy * nMapFactor; ptScrollPos.x += (int) dx; m_bIsScrolling = TRUE; OnAutoScroll(ptCursorPos, TRUE); ScrollToPosition(ptScrollPos); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); // if (msg.message == nRefMessage) break; if (msg.message == nRefMessage) bSawRefMessage = TRUE; } // if (!bSawRefMessage) OnAutoScroll(ptCursorPos, FALSE); } else { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); // if (msg.message == nRefMessage) break; if (msg.message == nRefMessage) bSawRefMessage = TRUE; } m_bIsScrolling = FALSE; } } ReleaseCapture(); m_bIsScrolling = FALSE; }
LRESULT CALLBACK ScrollWndProc ( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { Gwidget_t *widget, *child; WINDOWPOS *wpos; PIXpoint_t po; RECT r; int dummy, dx, dy, wi; if (Gnocallbacks || !(widget = findwidget (hwnd, G_SCROLLWIDGET))) return (DefWindowProc(hwnd, message, wparam, lparam)); switch (message) { case WM_WINDOWPOSCHANGED: wpos = (WINDOWPOS *) lparam; if (!(wpos->flags & SWP_NOSIZE)) handleresize (widget); break; case WM_HSCROLL: case WM_VSCROLL: for (wi = 0; wi < Gwidgetn; wi++) { child = &Gwidgets[wi]; if (child->inuse && child->pwi == widget - &Gwidgets[0]) break; } if (wi == Gwidgetn) return (DefWindowProc(hwnd, message, wparam, lparam)); GetClientRect (widget->w, &r); GetScrollRange (widget->w, SB_HORZ, &dummy, &dx); GetScrollRange (widget->w, SB_VERT, &dummy, &dy); po.x = GetScrollPos (widget->w, SB_HORZ); po.y = GetScrollPos (widget->w, SB_VERT); switch (message) { case WM_HSCROLL: switch (LOWORD (wparam)) { case SB_BOTTOM: po.x = dx; break; case SB_LINEDOWN: po.x += 10; break; case SB_LINEUP: po.x -= 10; break; case SB_PAGEDOWN: po.x += (r.right - r.left); break; case SB_PAGEUP: po.x -= (r.right - r.left); break; case SB_THUMBPOSITION: po.x = HIWORD (wparam); break; case SB_THUMBTRACK: po.x = HIWORD (wparam); break; case SB_TOP: po.x = 0; break; } po.x = min (po.x, dx); po.x = max (po.x, 0); SetScrollPos (widget->w, SB_HORZ, po.x, TRUE); SetWindowPos ( child->w, (HWND) NULL, -po.x, -po.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); break; case WM_VSCROLL: switch (LOWORD (wparam)) { case SB_BOTTOM: po.y = dy; break; case SB_LINEDOWN: po.y += 10; break; case SB_LINEUP: po.y -= 10; break; case SB_PAGEDOWN: po.y += (r.bottom - r.top); break; case SB_PAGEUP: po.y -= (r.bottom - r.top); break; case SB_THUMBPOSITION: po.y = HIWORD (wparam); break; case SB_THUMBTRACK: po.y = HIWORD (wparam); break; case SB_TOP: po.y = 0; break; } po.y = min (po.y, dy); po.y = max (po.y, 0); SetScrollPos (widget->w, SB_VERT, po.y, TRUE); SetWindowPos ( child->w, (HWND) NULL, -po.x, -po.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); break; } break; default: return (DefWindowProc (hwnd, message, wparam, lparam)); } return 0; }
BOOL CALLBACK PaletteDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { BOOL msgProcessed; RECT r; HWND hCtrl; msgProcessed = FALSE; switch (message) { case WM_INITDIALOG: GetWindowRect(hDlg, &r); r.left = (GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2; r.top = (GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2; SetWindowPos(hDlg, NULL, r.left,r.top,0,0, SWP_NOSIZE | SWP_NOZORDER); hCtrl = GetDlgItem(hDlg, IDC_SC_TRANSLUCENCY); SetScrollRange(hCtrl, SB_CTL, 0, pal->getMaxTranslucent(), TRUE); SetScrollPos(hCtrl, SB_CTL, pal->getTransLevel(), TRUE); hCtrl = GetDlgItem(hDlg, IDC_SC_HAZE); SetScrollRange(hCtrl, SB_CTL, 0, pal->getMaxHaze(), TRUE); SetScrollPos(hCtrl, SB_CTL, pal->getHazeIndex(), TRUE); hCtrl = GetDlgItem(hDlg, IDC_SC_SHADE); SetScrollRange(hCtrl, SB_CTL, 0, pal->getMaxShade(), TRUE); SetScrollPos(hCtrl, SB_CTL, curShadeIndex, TRUE); msgProcessed = TRUE; break; case WM_COMMAND: switch(LOWORD(wParam)) { /* case IDCANCEL: case IDM_PUSHOK: EndDialog(hDlg, wParam); msgProcessed = TRUE; break; */ default: break; } break; case WM_HSCROLL: int shift; int newPos; switch(LOWORD(wParam)) { case SB_PAGELEFT: case SB_LINELEFT: shift = -1; break; case SB_PAGERIGHT: case SB_LINERIGHT: shift = 1; break; case SB_THUMBTRACK: case SB_THUMBPOSITION: shift = 0; newPos = HIWORD(wParam); break; default: return 1; } hCtrl = (HWND) LOWORD(lParam); long ctrlIdx; ctrlIdx = GetWindowLong(hCtrl, GWL_ID); if(shift) { int min, max; newPos = GetScrollPos(hCtrl, SB_CTL); newPos += shift; GetScrollRange(hCtrl, SB_CTL, &min, &max); if(newPos < min) newPos = min; else if(newPos > max) newPos = max; } SetScrollPos(hCtrl, SB_CTL, newPos, TRUE); switch(ctrlIdx) { case IDC_SC_TRANSLUCENCY: hCtrl = GetDlgItem(hDlg, IDC_SC_TRANSLUCENCY); pal->setTransLevel(GetScrollPos(hCtrl, SB_CTL)); break; case IDC_SC_HAZE: break; case IDC_SC_SHADE: break; } Redraw(); return 0; case WM_CLOSE: DestroyWindow(hDlg); paletteWindow = 0; break; } return (msgProcessed); }
void LVLBox_OnHScroll ( HWND hWnd, int iCode, int iPos ) { RECT rc; int iminPos; int imaxPos; int iPageSize; int iLineSize; UINT uStyleMask; HGLOBAL hRsrc = ( HGLOBAL )NULL; LISTVIEWDATA* pthis = ( LISTVIEWDATA* )NULL; BOOL bRedraw = FALSE; hRsrc = LView_IGetResource ( hWnd, &pthis ); assert ( hRsrc ); GetScrollRange ( hWnd, SB_HORZ, &iminPos, &imaxPos ); GetClientRect ( hWnd, &rc ); if ( ( uStyleMask = pthis->uStyles & LVS_TYPEMASK ) == LVS_LIST ) { iLineSize = 1; iPageSize = 2; } else { iLineSize = 8; iPageSize = ( rc.right - rc.left ) / iLineSize; } switch ( iCode ) { case SB_LINELEFT: if ( pthis->psLBox.ptOrg.x > 0 ) { iLineSize = 0 - iLineSize; bRedraw = TRUE; } break; case SB_LINERIGHT: if ( pthis->psLBox.ptOrg.x + iLineSize > imaxPos ) iLineSize = imaxPos - pthis->psLBox.ptOrg.x; if ( iLineSize > 0 ) bRedraw = TRUE; break; case SB_PAGEUP: if ( pthis->psLBox.ptOrg.x > 0 ) { iLineSize = 0 - iPageSize; bRedraw = TRUE; } break; case SB_PAGEDOWN: if ( pthis->psLBox.ptOrg.x + iPageSize > imaxPos ) iPageSize = imaxPos - pthis->psLBox.ptOrg.x; if ( iPageSize > 0 ) { iLineSize = iPageSize; bRedraw = TRUE; } break; case SB_THUMBPOSITION: case SB_THUMBTRACK: pthis->psLBox.ptOrg.x = iPos; iLineSize = 0; bRedraw = TRUE; break; } if ( bRedraw ) LView_OnScroll ( hWnd, pthis, iLineSize, 0 ); LView_IReleaseResource ( hRsrc, pthis ); }
void LVLBox_OnVScroll ( HWND hWnd, int iCode, int iPos ) { RECT rc; int iminPos; int imaxPos; int iPageSize; int iLineSize; UINT uStyleMask; HGLOBAL hRsrc = ( HGLOBAL )NULL; LISTVIEWDATA* pthis = ( LISTVIEWDATA* )NULL; BOOL bRedraw = FALSE; hRsrc = LView_IGetResource ( hWnd, &pthis ); assert ( hRsrc ); uStyleMask = pthis->uStyles & LVS_TYPEMASK; GetScrollRange ( hWnd, SB_VERT, &iminPos, &imaxPos ); GetClientRect ( hWnd, &rc ); iLineSize = pthis->psLBox.ItmHeight; iPageSize = rc.bottom / pthis->psLBox.ItmHeight; switch ( iCode ) { case SB_LINEUP: if ( pthis->psLBox.ptOrg.y > 0 ) { iLineSize = 0 - pthis->psLBox.ItmHeight; if ( uStyleMask == LVS_REPORT || uStyleMask == LVS_LIST ) iLineSize = -1; bRedraw = TRUE; } break; case SB_LINEDOWN: if ( pthis->psLBox.ptOrg.y + iLineSize > imaxPos ) iLineSize = imaxPos - pthis->psLBox.ptOrg.y; if ( iLineSize > 0 ) { if ( uStyleMask == LVS_REPORT || uStyleMask == LVS_LIST ) iLineSize = 1; bRedraw = TRUE; } break; case SB_PAGEUP: if ( pthis->psLBox.ptOrg.y > 0 ) { pthis->psLBox.lTopIndx -= iPageSize; if ( pthis->psLBox.lTopIndx < 0 ) pthis->psLBox.lTopIndx = 0; iLineSize = 0 - iPageSize; bRedraw = TRUE; } break; case SB_PAGEDOWN: if ( pthis->psLBox.ptOrg.y + iPageSize <= imaxPos ) iPageSize = imaxPos - pthis->psLBox.ptOrg.y; if ( iPageSize > 0 ) { pthis->psLBox.lTopIndx += iPageSize; if ( pthis->psLBox.lTopIndx >= pthis->psLBox.lCount - iPageSize ) pthis->psLBox.lTopIndx = pthis->psLBox.lCount - iPageSize; if ( pthis->psLBox.lTopIndx < 0 ) pthis->psLBox.lTopIndx = 0; iLineSize = iPageSize; bRedraw = TRUE; } break; case SB_THUMBPOSITION: case SB_THUMBTRACK: pthis->psLBox.lTopIndx = iPos; iLineSize = 0; bRedraw = TRUE; break; } if ( bRedraw ) LView_OnScroll ( hWnd, pthis, 0, iLineSize ); LView_IReleaseResource ( hRsrc, pthis ); }
LOCAL BOOL Palette_HandleScroll( HWND hWindow, BOOL fVScroll, UINT code, int pos) /************************************************************************/ { int Value, Position, MinPos, MaxPos, xChipSize, yChipSize; int Type, iRows, iCols, iRowIncr, iColIncr, iStart; RECT ClientRect; LPPALETTE lpPalette; // get pointer to palette information lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE); if (!lpPalette || !lpPalette->iColors) return(FALSE); if ( fVScroll ) { if ( !PaletteVertical() ) return( FALSE ); Type = SB_VERT; } else { if ( PaletteVertical() ) return( FALSE ); Type = SB_HORZ; } Value = Position = GetScrollPos(hWindow, Type); GetScrollRange(hWindow, Type, &MinPos, &MaxPos); GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart); switch (code) { case SB_LINEUP: Value -= 1; break; case SB_LINEDOWN: Value += 1; break; case SB_PAGEUP: if (Type == SB_VERT) Value -= (iRows-1); else Value -= (iCols-1); Value = bound(Value, MinPos, MaxPos); break; case SB_PAGEDOWN: if (Type == SB_VERT) Value += (iRows-1); else Value += (iCols-1); Value = bound(Value, MinPos, MaxPos); break; case SB_THUMBPOSITION: case SB_THUMBTRACK: Value = pos; break; } if ( Value == Position || Value < MinPos || Value > MaxPos) return(FALSE); SetScrollPos(hWindow, Type, Value, YES); GetChipSize(&xChipSize, &yChipSize); Value -= Position; Value = -Value; ClientRect.bottom++; ClientRect.right++; if (Type == SB_VERT) { // xChipSize--; Value = (Value * xChipSize); } else { // yChipSize--; Value = (Value * yChipSize); } if (Type == SB_VERT) ScrollWindow( hWindow, 0, Value, &ClientRect, &ClientRect ); else ScrollWindow( hWindow, Value, 0, &ClientRect, &ClientRect ); return(TRUE); }
long CALLBACK EXPORT ConsoleFunc(HWND hwnd,unsigned message,WPARAM wParam, LPARAM lParam) { CONSOLE *con; PAINTSTRUCT ps; RECT rect; switch (message) { case WM_CHAR: if ((con=Hwnd2Console(hwnd))!=NULL) { /* store in a key queue */ if ((con->keyq_end+1)%KEYQUEUE_SIZE==con->keyq_start) { MessageBeep(MB_OK); break; } /* if */ con->keyqueue[con->keyq_end]=(short)wParam; con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE; } /* if */ break; case WM_CREATE: /* The "hwnd" member of the CONSOLE structure has not yet been set, which * means that Hwnd2Console() cannot work on the real "hwnd". There should * at every instant be only one CONSOLE structure with a NULL handle, * however. */ if ((con=Hwnd2Console(NULL))!=NULL) { con->hwnd=hwnd; SetConsoleFont(con,con->cheight); GetWindowRect(hwnd, &rect); SetRect(&rect,rect.left,rect.top, rect.left+con->cwidth*con->columns, rect.top+con->cheight*con->winlines); AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE); if (con->winlines<con->lines) rect.right+=GetSystemMetrics(SM_CXVSCROLL); ClampToScreen(&rect); SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top, SWP_NOZORDER); } /* if */ break; case WM_DESTROY: if ((con=Hwnd2Console(hwnd))!=NULL) DoDeleteConsole(con); break; case WM_GETMINMAXINFO: if ((con=Hwnd2Console(hwnd))!=NULL) { MINMAXINFO FAR *lpmmi=(MINMAXINFO FAR*)lParam; int rx,ry,hsize,vsize; GetClientRect(hwnd,&rect); rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0; ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0; hsize= (ry>0) ? GetSystemMetrics(SM_CXVSCROLL) : 0; vsize= (rx>0) ? GetSystemMetrics(SM_CYHSCROLL) : 0; SetRect(&rect,0,0,con->cwidth*con->columns+hsize,con->cheight*con->lines+vsize); AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE); lpmmi->ptMaxTrackSize.x=rect.right-rect.left; lpmmi->ptMaxTrackSize.y=rect.bottom-rect.top; lpmmi->ptMaxSize=lpmmi->ptMaxTrackSize; } /* if */ break; case WM_SYSKEYDOWN: case WM_KEYDOWN: if ((con=Hwnd2Console(hwnd))!=NULL) { TCHAR str[20]; int i; str[0]=__T('\0'); switch (LOWORD(wParam)) { case VK_F1: case VK_F2: case VK_F3: case VK_F4: case VK_F5: case VK_F6: case VK_F7: case VK_F8: case VK_F9: case VK_F10: case VK_F11: case VK_F12: if (LOWORD(wParam)<=VK_F5) _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F1+11); else if (LOWORD(wParam)==VK_F10) _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F6+17); else _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F11+23); break; case VK_ADD: case VK_SUBTRACT: /* check Ctrl key */ if ((GetKeyState(VK_CONTROL) & 0x8000)!=0) { POINT pt; int newheight=con->cheight; int oldheight=newheight; int incr= (LOWORD(wParam)==VK_SUBTRACT) ? -1 : 1; do { newheight+=incr; /* make a new font, re-create a caret and redraw everything */ SetConsoleFont(con,newheight); } while (newheight>5 && (oldheight==con->cheight || con->hfont==NULL)); if (con->hfont==NULL) /* reset to original on failure */ SetConsoleFont(con,oldheight); GetClientRect(hwnd,&rect); DestroyCaret(); CreateCaret(hwnd,NULL,con->cwidth,2); RefreshCaretPos(con); /* redraw the window */ InvalidateRect(hwnd,NULL,TRUE); /* resize the window */ SetRect(&rect,0,0,con->cwidth*con->columns,con->cheight*con->winlines); AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE); pt.x=pt.y=0; ClientToScreen(hwnd,&pt); OffsetRect(&rect,pt.x,pt.y); ClampToScreen(&rect); SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top, SWP_NOZORDER); } /* if */ break; case VK_UP: _tcscpy(str,__T("\033[A")); break; case VK_DOWN: _tcscpy(str,__T("\033[B")); break; case VK_RIGHT: _tcscpy(str,__T("\033[C")); break; case VK_LEFT: _tcscpy(str,__T("\033[D")); break; case VK_HOME: _tcscpy(str,__T("\033[1~")); break; case VK_END: _tcscpy(str,__T("\033[4~")); break; case VK_INSERT: _tcscpy(str,__T("\033[2~")); break; case VK_DELETE: _tcscpy(str,__T("\033[3~")); break; case VK_PRIOR: /* PageUp */ _tcscpy(str,__T("\033[5~")); break; case VK_NEXT: /* PageDown */ _tcscpy(str,__T("\033[6~")); break; default: return DefWindowProc(hwnd,message,wParam,lParam); } /* switch */ for (i=0; str[i]!=__T('\0'); i++) { if ((con->keyq_end+1)%KEYQUEUE_SIZE!=con->keyq_start) { con->keyqueue[con->keyq_end]=(short)str[i]; con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE; } /* if */ } /* for */ } /* if */ break; case WM_KILLFOCUS: HideCaret(hwnd); DestroyCaret(); break; case WM_SETFOCUS: if ((con=Hwnd2Console(hwnd))!=NULL) { CreateCaret(hwnd,NULL,con->cwidth,2); RefreshCaretPos(con); ShowCaret(hwnd); } /* if */ break; case WM_LBUTTONDOWN: SetFocus(hwnd); break; case WM_PAINT: HideCaret(hwnd); BeginPaint(hwnd, &ps); if ((con=Hwnd2Console(hwnd))!=NULL && con->buffer!=NULL) { TCHAR *string; string=malloc(con->columns*sizeof(TCHAR)); if (string!=NULL) { int l,c,bpos,start; TCHAR attr; HFONT hfontOrg; int scrollx=GetScrollPos(hwnd,SB_HORZ); int scrolly=GetScrollPos(hwnd,SB_VERT); GetClientRect(hwnd,&rect); hfontOrg=SelectObject(ps.hdc,con->hfont); SetBkMode(ps.hdc,OPAQUE); for (l=0; l<con->lines; l++) { bpos=l*con->columns*2; c=0; while (c<con->columns) { /* find stretches with the same attribute */ attr=con->buffer[bpos+1]; start=c; while (c<con->columns && con->buffer[bpos+1]==attr) { assert(c-start>=0); assert(c-start<con->columns); string[c-start]=con->buffer[bpos]; c++; bpos+=2; } /* if */ SetTextAttribute(ps.hdc,attr); TextOut(ps.hdc,start*con->cwidth-scrollx,l*con->cheight-scrolly,string,c-start); } /* while */ } /* for */ SelectObject(ps.hdc,hfontOrg); free(string); } /* if */ } /* if */ EndPaint(hwnd, &ps); ShowCaret(hwnd); break; case WM_SIZE: if ((con=Hwnd2Console(hwnd))!=NULL) { int rx,ry; /* add/remove/recalculate scroll bars */ GetClientRect(hwnd,&rect); rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0; ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0; /* adjust scrolling position, if necessary */ if (GetScrollPos(hwnd,SB_HORZ)>=rx) { SetScrollPos(hwnd,SB_HORZ,rx,FALSE); InvalidateRect(hwnd,NULL,FALSE); } /* if */ if (GetScrollPos(hwnd,SB_VERT)>=ry) { SetScrollPos(hwnd,SB_VERT,ry,FALSE); InvalidateRect(hwnd,NULL,FALSE); } /* if */ SetScrollRange(hwnd,SB_HORZ,0,rx,TRUE); SetScrollRange(hwnd,SB_VERT,0,ry,TRUE); } /* if */ break; case WM_HSCROLL: if ((con=Hwnd2Console(hwnd))!=NULL) { int scrollx=GetScrollPos(hwnd,SB_HORZ); int oldpos=scrollx; int min,max; GetScrollRange(hwnd,SB_HORZ,&min,&max); switch (LOWORD(wParam)) { case SB_TOP: scrollx=min; break; case SB_BOTTOM: scrollx=max; break; case SB_LINELEFT: scrollx=(scrollx>min) ? scrollx-1 : min; break; case SB_LINERIGHT: scrollx=(scrollx<max) ? scrollx+1 : max; break; case SB_PAGELEFT: scrollx=(scrollx>min) ? scrollx-50 : min; break; case SB_PAGERIGHT: scrollx=(scrollx<max) ? scrollx+50 : max; break; case SB_THUMBTRACK: scrollx=(int)HIWORD(wParam); break; } /* switch */ if (oldpos!=scrollx) { SetScrollPos(hwnd,SB_HORZ,scrollx,TRUE); InvalidateRect(hwnd,NULL,FALSE); RefreshCaretPos(con); } /* if */ } /* if */ break; case WM_VSCROLL: if ((con=Hwnd2Console(hwnd))!=NULL) { int scrolly=GetScrollPos(hwnd,SB_VERT); int oldpos=scrolly; int min,max; GetScrollRange(hwnd,SB_VERT,&min,&max); switch (LOWORD(wParam)) { case SB_TOP: scrolly=min; break; case SB_BOTTOM: scrolly=max; break; case SB_LINELEFT: scrolly=(scrolly>min) ? scrolly-1 : min; break; case SB_LINERIGHT: scrolly=(scrolly<max) ? scrolly+1 : max; break; case SB_PAGELEFT: scrolly=(scrolly>min) ? scrolly-50 : min; break; case SB_PAGERIGHT: scrolly=(scrolly<max) ? scrolly+50 : max; break; case SB_THUMBTRACK: scrolly=(int)HIWORD(wParam); break; } /* switch */ if (oldpos!=scrolly) { SetScrollPos(hwnd,SB_VERT,scrolly,TRUE); InvalidateRect(hwnd,NULL,FALSE); RefreshCaretPos(con); } /* if */ } /* if */ break; default: return DefWindowProc(hwnd,message,wParam,lParam); } /* switch */ return 0L; }
void CContainerUI::EndDown() { SIZE sz = GetScrollPos(); sz.cy = GetScrollRange().cy; SetScrollPos(sz); }
void GetUserCmd ( WORD wParam, /* Key Code */ BOOL ScreenOnly, /* Send to Screen and or Command Buffer */ int InputSize) /* Number of characters send to screen only */ { extern int HorizScroll; /* Automatic Scrolling Enabled/Disabled */ switch (wParam) { extern SCREEN WinDialog; extern int UserInput; /*------------------+ | Handle Back Space | +------------------*/ case VK_BACK: { /*-----------------------------------------------+ | Init Values when sending to the command buffer | +-----------------------------------------------*/ if (! ScreenOnly) { HorizScroll = 1; if (GetCommandString() != NULL) { InputSize = strlen(GetCommandString()); } else { InputSize = 0; } } if (InputSize > 0 ) { int size; if (Terminal[WinDialog.LastLine] != NULL) { size = strlen(Terminal[WinDialog.LastLine]); } else { size = 0; } if (!ScreenOnly) ExpandCommandString ('\b'); if (size > 0) Terminal[WinDialog.LastLine][size - 1] = '\0'; else { int min, max; extern int OldLine; if ( Terminal[WinDialog.LastLine] != NULL ) { free(Terminal[WinDialog.LastLine]); Terminal[WinDialog.LastLine] = NULL; } WinDialog.LastLine --; OldLine --; if ( WinDialog.LastLine < 0 ) WinDialog.LastLine = DIALOG_SIZE; GetScrollRange (WinDialog.hWnd, SB_VERT, &min, &max); if ( WinDialog.NoLines < max && max < DIALOG_SIZE ) { SetScrollRange ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines, max-1, FALSE ); SetScrollPos ( WinDialog.hWnd, SB_VERT, max-1, FALSE ); } InvalidateRect ( WinDialog.hWnd, NULL, TRUE ); } SendToScreen(); } break; } /*--------------------------+ | Remove Special Keys (ALT) | +--------------------------*/ case '\f': case VK_MENU: break; /*----------------+ | Handle Tab Keys | +----------------*/ case '\t': { if ( !ScreenOnly) { if ( GetCommandString() == NULL) SetCommandString(" "); else AppendCommandString(" "); } PrintCLIPS ("stdout", " " ); break; } /*---------------------+ | Return / Newline Key | +---------------------*/ case '\r': case '\n': { wParam = (int)'\n'; if (GetScrollPos (WinDialog.hWnd, SB_HORZ) != 0) { SetScrollPos ( WinDialog.hWnd, SB_HORZ, 0, TRUE ); InvalidateRect(WinDialog.hWnd, NULL, FALSE); SendMessage ( WinDialog.hWnd, WM_PAINT, 0, 0 ); } } /*---------------------+ | All other characters | +---------------------*/ default: { char text[2]; text[0] = (char) wParam; text[1] = '\0'; if(isprint ( text[0]) || isspace (text[0])) { /*----------------------------+ | Add to CLIPS Command Buffer | +----------------------------*/ if (!ScreenOnly) { if ( GetCommandString() == NULL) SetCommandString(text); else AppendCommandString(text); } PrintCLIPS ("stdout", text ); } break; } } HorizScroll = 0; }
BOOL CALLBACK DlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static BOOL bShutOff, bClosing ; static HWAVEOUT hWaveOut ; static HWND hwndScroll ; static int iFreq = FREQ_INIT ; static PBYTE pBuffer1, pBuffer2 ; static PWAVEHDR pWaveHdr1, pWaveHdr2 ; static WAVEFORMATEX waveformat ; int iDummy ; switch (message) { case WM_INITDIALOG: hwndScroll = GetDlgItem (hwnd, IDC_SCROLL) ; SetScrollRange (hwndScroll, SB_CTL, FREQ_MIN, FREQ_MAX, FALSE) ; SetScrollPos (hwndScroll, SB_CTL, FREQ_INIT, TRUE) ; SetDlgItemInt (hwnd, IDC_TEXT, FREQ_INIT, FALSE) ; return TRUE ; case WM_HSCROLL: switch (LOWORD (wParam)) { case SB_LINELEFT: iFreq -= 1 ; break ; case SB_LINERIGHT: iFreq += 1 ; break ; case SB_PAGELEFT: iFreq /= 2 ; break ; case SB_PAGERIGHT: iFreq *= 2 ; break ; case SB_THUMBTRACK: iFreq = HIWORD (wParam) ; break ; case SB_TOP: GetScrollRange (hwndScroll, SB_CTL, &iFreq, &iDummy) ; break ; case SB_BOTTOM: GetScrollRange (hwndScroll, SB_CTL, &iDummy, &iFreq) ; break ; } iFreq = max (FREQ_MIN, min (FREQ_MAX, iFreq)) ; SetScrollPos (hwndScroll, SB_CTL, iFreq, TRUE) ; SetDlgItemInt (hwnd, IDC_TEXT, iFreq, FALSE) ; return TRUE ; case WM_COMMAND: switch (LOWORD (wParam)) { case IDC_ONOFF: // If turning on waveform, hWaveOut is NULL if (hWaveOut == NULL) { // Allocate memory for 2 headers and 2 buffers pWaveHdr1 = malloc (sizeof (WAVEHDR)) ; pWaveHdr2 = malloc (sizeof (WAVEHDR)) ; pBuffer1 = malloc (OUT_BUFFER_SIZE) ; pBuffer2 = malloc (OUT_BUFFER_SIZE) ; if (!pWaveHdr1 || !pWaveHdr2 || !pBuffer1 || !pBuffer2) { if (!pWaveHdr1) free (pWaveHdr1) ; if (!pWaveHdr2) free (pWaveHdr2) ; if (!pBuffer1) free (pBuffer1) ; if (!pBuffer2) free (pBuffer2) ; MessageBeep (MB_ICONEXCLAMATION) ; MessageBox (hwnd, TEXT ("Error allocating memory!"), szAppName, MB_ICONEXCLAMATION | MB_OK) ; return TRUE ; } // Variable to indicate Off button pressed bShutOff = FALSE ; // Open waveform audio for output waveformat.wFormatTag = WAVE_FORMAT_PCM ; waveformat.nChannels = 1 ; waveformat.nSamplesPerSec = SAMPLE_RATE ; waveformat.nAvgBytesPerSec = SAMPLE_RATE ; waveformat.nBlockAlign = 1 ; waveformat.wBitsPerSample = 8 ; waveformat.cbSize = 0 ; if (waveOutOpen (&hWaveOut, WAVE_MAPPER, &waveformat, (DWORD) hwnd, 0, CALLBACK_WINDOW) != MMSYSERR_NOERROR) { free (pWaveHdr1) ; free (pWaveHdr2) ; free (pBuffer1) ; free (pBuffer2) ; hWaveOut = NULL ; MessageBeep (MB_ICONEXCLAMATION) ; MessageBox (hwnd, TEXT ("Error opening waveform audio device!"), szAppName, MB_ICONEXCLAMATION | MB_OK) ; return TRUE ; } // Set up headers and prepare them pWaveHdr1->lpData = pBuffer1 ; pWaveHdr1->dwBufferLength = OUT_BUFFER_SIZE ; pWaveHdr1->dwBytesRecorded = 0 ; pWaveHdr1->dwUser = 0 ; pWaveHdr1->dwFlags = 0 ; pWaveHdr1->dwLoops = 1 ; pWaveHdr1->lpNext = NULL ; pWaveHdr1->reserved = 0 ; waveOutPrepareHeader (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ; pWaveHdr2->lpData = pBuffer2 ; pWaveHdr2->dwBufferLength = OUT_BUFFER_SIZE ; pWaveHdr2->dwBytesRecorded = 0 ; pWaveHdr2->dwUser = 0 ; pWaveHdr2->dwFlags = 0 ; pWaveHdr2->dwLoops = 1 ; pWaveHdr2->lpNext = NULL ; pWaveHdr2->reserved = 0 ; waveOutPrepareHeader (hWaveOut, pWaveHdr2, sizeof (WAVEHDR)) ; } // If turning off waveform, reset waveform audio else { bShutOff = TRUE ; waveOutReset (hWaveOut) ; } return TRUE ; } break ; // Message generated from waveOutOpen call case MM_WOM_OPEN: SetDlgItemText (hwnd, IDC_ONOFF, TEXT ("Turn Off")) ; // Send two buffers to waveform output device FillBuffer (pBuffer1, iFreq) ; waveOutWrite (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ; FillBuffer (pBuffer2, iFreq) ; waveOutWrite (hWaveOut, pWaveHdr2, sizeof (WAVEHDR)) ; return TRUE ; // Message generated when a buffer is finished case MM_WOM_DONE: if (bShutOff) { waveOutClose (hWaveOut) ; return TRUE ; } // Fill and send out a new buffer FillBuffer (((PWAVEHDR) lParam)->lpData, iFreq) ; waveOutWrite (hWaveOut, (PWAVEHDR) lParam, sizeof (WAVEHDR)) ; return TRUE ; case MM_WOM_CLOSE: waveOutUnprepareHeader (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ; waveOutUnprepareHeader (hWaveOut, pWaveHdr2, sizeof (WAVEHDR)) ; free (pWaveHdr1) ; free (pWaveHdr2) ; free (pBuffer1) ; free (pBuffer2) ; hWaveOut = NULL ; SetDlgItemText (hwnd, IDC_ONOFF, TEXT ("Turn On")) ; if (bClosing) EndDialog (hwnd, 0) ; return TRUE ; case WM_SYSCOMMAND: switch (wParam) { case SC_CLOSE: if (hWaveOut != NULL) { bShutOff = TRUE ; bClosing = TRUE ; waveOutReset (hWaveOut) ; } else EndDialog (hwnd, 0) ; return TRUE ; } break ; } return FALSE ; }