140 cr.cpMin = lCurPos; 141 cr.cpMax = lCurPos; 142 EditSetSel(cr); 143 } 144 145 /* 146 * Cleanup the state variables when left mouse button is released. 147 * These state variables are designed to reflect the selection state 148 * while the left mouse button is pressed and be set to -1 otherwise. 149 */ 150 SetStartSelectionPos(-1); 151 SetEndSelectionPos(-1); 152 SetLastSelectionPos(-1); 153 154 delete msg; 155 return mrConsume; 156 } else if (msg->message == WM_MOUSEMOVE && (msg->wParam & MK_LBUTTON)) { 157 158 /* 159 * We consume WM_MOUSEMOVE while the left mouse button is pressed, 160 * so we have to simulate autoscrolling when mouse is moved outside 161 * of the client area. 162 */ 163 POINT p; 164 RECT r; 165 BOOL bScrollLeft = FALSE; 166 BOOL bScrollRight = FALSE; 167 BOOL bScrollUp = FALSE; 168 BOOL bScrollDown = FALSE; 169 170 p.x = msg->pt.x; 171 p.y = msg->pt.y; 172 VERIFY(::GetClientRect(GetHWnd(), &r)); 173 174 if (p.x < 0) { 175 bScrollLeft = TRUE; 176 p.x = 0; 177 } else if (p.x > r.right) { 178 bScrollRight = TRUE; 179 p.x = r.right - 1; 180 } 181 LONG lCurPos = EditGetCharFromPos(p); 182 183 if (GetStartSelectionPos() != -1 && 184 GetEndSelectionPos() != -1 && 185 lCurPos != GetLastSelectionPos()) { 186 187 CHARRANGE cr; 188 189 SetLastSelectionPos(lCurPos); 190 191 cr.cpMin = GetStartSelectionPos(); 192 cr.cpMax = GetLastSelectionPos(); 193 194 EditSetSel(cr); 195 } 196 197 if (bScrollLeft == TRUE || bScrollRight == TRUE) { 198 SCROLLINFO si; 199 memset(&si, 0, sizeof(si)); 200 si.cbSize = sizeof(si); 201 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; 202 203 SendMessage(EM_SHOWSCROLLBAR, SB_HORZ, TRUE); 204 VERIFY(::GetScrollInfo(GetHWnd(), SB_HORZ, &si)); 205 SendMessage(EM_SHOWSCROLLBAR, SB_HORZ, FALSE); 206 207 if (bScrollLeft == TRUE) { 208 si.nPos = si.nPos - si.nPage / 2; 209 si.nPos = max(si.nMin, si.nPos); 210 } else if (bScrollRight == TRUE) { 211 si.nPos = si.nPos + si.nPage / 2; 212 si.nPos = min(si.nPos, si.nMax); 213 } 214 /* 215 * Okay to use 16-bit position since RichEdit control adjusts 216 * its scrollbars so that their range is always 16-bit. 217 */ 218 DASSERT(abs(si.nPos) < 0x8000); 219 SendMessage(WM_HSCROLL, 220 MAKEWPARAM(SB_THUMBPOSITION, LOWORD(si.nPos))); 221 } 222 delete msg; 223 return mrConsume; 224 } else if (msg->message == WM_KEYDOWN) { 225 UINT virtualKey = (UINT) msg->wParam; 226 227 switch(virtualKey){ 228 case VK_RETURN: 229 case VK_UP: 230 case VK_DOWN: 231 case VK_LEFT: 232 case VK_RIGHT: 233 case VK_DELETE: 234 case VK_BACK: 235 SystemParametersInfo(SPI_GETBEEP, 0, &systemBeeperEnabled, 0); 236 if(systemBeeperEnabled){ 237 // disable system beeper for the RICHEDIT control to be compatible 238 // with the EDIT control behaviour 239 SystemParametersInfo(SPI_SETBEEP, 0, NULL, 0); 240 } | 140 cr.cpMin = lCurPos; 141 cr.cpMax = lCurPos; 142 EditSetSel(cr); 143 } 144 145 /* 146 * Cleanup the state variables when left mouse button is released. 147 * These state variables are designed to reflect the selection state 148 * while the left mouse button is pressed and be set to -1 otherwise. 149 */ 150 SetStartSelectionPos(-1); 151 SetEndSelectionPos(-1); 152 SetLastSelectionPos(-1); 153 154 delete msg; 155 return mrConsume; 156 } else if (msg->message == WM_MOUSEMOVE && (msg->wParam & MK_LBUTTON)) { 157 158 /* 159 * We consume WM_MOUSEMOVE while the left mouse button is pressed, 160 * so we have to simulate selection autoscrolling when mouse is moved 161 * outside of the client area. 162 */ 163 POINT p; 164 p.x = msg->pt.x; 165 p.y = msg->pt.y; 166 LONG lCurPos = EditGetCharFromPos(p); 167 168 if (GetStartSelectionPos() != -1 && 169 GetEndSelectionPos() != -1 && 170 lCurPos != GetLastSelectionPos()) { 171 172 CHARRANGE cr; 173 174 SetLastSelectionPos(lCurPos); 175 176 cr.cpMin = GetStartSelectionPos(); 177 cr.cpMax = GetLastSelectionPos(); 178 179 EditSetSel(cr); 180 } 181 delete msg; 182 return mrConsume; 183 } else if (msg->message == WM_KEYDOWN) { 184 UINT virtualKey = (UINT) msg->wParam; 185 186 switch(virtualKey){ 187 case VK_RETURN: 188 case VK_UP: 189 case VK_DOWN: 190 case VK_LEFT: 191 case VK_RIGHT: 192 case VK_DELETE: 193 case VK_BACK: 194 SystemParametersInfo(SPI_GETBEEP, 0, &systemBeeperEnabled, 0); 195 if(systemBeeperEnabled){ 196 // disable system beeper for the RICHEDIT control to be compatible 197 // with the EDIT control behaviour 198 SystemParametersInfo(SPI_SETBEEP, 0, NULL, 0); 199 } |