void TrackPanel::OnMouseEvent(wxMouseEvent& event) { if (event.m_x < view->labelWidth) { // Group panel stuff if (event.ButtonDClick()) view->DClickLabel(event); else if (event.ButtonDown()) view->ClickLabel(event); else if (event.ButtonUp()) SetCursor(*mainCursor); } else { if (event.ButtonDown()) { CaptureMouse(); if (event.ControlDown()) SetCursor(*dragCursor); view->ClickTrack(event); } else if (event.Dragging()) view->DragTrack(event); else if (event.ButtonUp()) { ReleaseMouse(); SetCursor(*mainCursor); view->ButtonUpTrack(); } else if (event.Moving()) { view->TrackSetCursor(event); } } }
void kwxLinearReg::OnMouse(wxMouseEvent& event) { if (m_iStato == 0 && event.Entering()) //dentro nel controllo m_iStato = ENTERED ; else if (m_iStato >= ENTERED && event.Leaving()) //fuori dal controllo m_iStato = LEFT ; else if (m_iStato == ENTERED && event.GetWheelRotation()) // process wheel event { //SetValue(m_iRealVal + (event.GetWheelRotation() * (m_iMax-m_iMin)/kwxLinearReg::MOUSE_STEP / event.GetWheelDelta()) ); SetValue(m_iRealVal + ( m_iBigStep * event.GetWheelRotation() / event.GetWheelDelta()) ); vSendEvent(); // send event return; } else if (m_iStato == ENTERED && event.ButtonDClick()) // process double click { // wxLogTrace("Mouse Premuto") ; m_mousePosition = event.GetPosition(); if( (m_iSnapRange<1) && (m_iStyle & STYLE_SNAP_DOUBLE_CLK) ){ // if no snapping was set.. vSetSnap2Tags(true); // ..snap to next tag. DrawPosition() ; vSetSnap2Tags(false); return; } DrawPosition() ; } else if (m_iStato == ENTERED && event.LeftDown()) //click o inizio trascinamento { // wxLogTrace("Mouse Premuto") ; m_iStato = DRAGED ; if( (m_bEditing) ){ // if control is currently in edit mode if(m_cCurrentRect.Contains(m_mousePosition)){ // mouse click was within text sourrounding rectangle m_bEditing = false; // exit edit mode m_iCaretPosition = 0; // reset edit caret position SetValue(iConvert(m_strCurrent)); Refresh() ; vSendEvent() ; return; } } m_mousePosition = event.GetPosition(); DrawPosition() ; } else if (m_iStato == DRAGED && event.LeftIsDown()) //trascinamento { // wxLogTrace("Mouse trascinato") ; m_mousePosition = event.GetPosition(); DrawPosition() ; } else if (m_iStato == DRAGED && event.LeftUp()) //fine trascinamento o rilascio click { // wxLogTrace("Mouse rilasciato") ; m_iStato = ENTERED ; } event.Skip(false);// }
void wxWebView::OnMouseEvents(wxMouseEvent& event) { event.Skip(); if (!m_impl->page) return; WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; wxPoint globalPoint = ClientToScreen(event.GetPosition()); wxEventType type = event.GetEventType(); if (type == wxEVT_MOUSEWHEEL) { if (m_mouseWheelZooms && event.ControlDown() && !event.AltDown() && !event.ShiftDown()) { if (event.GetWheelRotation() < 0) DecreaseTextSize(); else if (event.GetWheelRotation() > 0) IncreaseTextSize(); } else { WebCore::PlatformWheelEvent wkEvent(event, globalPoint); frame->eventHandler()->handleWheelEvent(wkEvent); } return; } int clickCount = event.ButtonDClick() ? 2 : 1; if (clickCount == 1 && m_impl->tripleClickTimer.IsRunning()) { wxPoint diff(event.GetPosition() - m_impl->tripleClickPos); if (abs(diff.x) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_X) && abs(diff.y) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_Y)) { clickCount = 3; } } else if (clickCount == 2) { m_impl->tripleClickTimer.Start(getDoubleClickTime(), false); m_impl->tripleClickPos = event.GetPosition(); } WebCore::PlatformMouseEvent wkEvent(event, globalPoint, clickCount); if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN || type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK) { frame->eventHandler()->handleMousePressEvent(wkEvent); if (!HasCapture()) CaptureMouse(); } else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP) { frame->eventHandler()->handleMouseReleaseEvent(wkEvent); while (HasCapture()) ReleaseMouse(); } else if (type == wxEVT_MOTION || type == wxEVT_ENTER_WINDOW || type == wxEVT_LEAVE_WINDOW) frame->eventHandler()->mouseMoved(wkEvent); }
void ToolBarMiniFrame::OnMouseEvent(wxMouseEvent& evt) { //The following is prototype code for allowing a double-click //close the toolbar. Commented out in lieu of a close button //that is being tested. #if 0 if(evt.ButtonDClick(1)) { AudacityProject * p = GetActiveProject(); ToolBar* tb = ToolBarFrame::GetToolBar(); ToolBarStub *tbs= tb->GetToolBarStub(); p->FloatToolBar(tbs); } #endif }
PlatformMouseEvent::PlatformMouseEvent(const wxMouseEvent& event, const wxPoint& globalPoint) : m_position(event.GetPosition()) , m_globalPosition(globalPoint) , m_shiftKey(event.ShiftDown()) , m_ctrlKey(event.CmdDown()) , m_altKey(event.AltDown()) , m_metaKey(event.MetaDown()) // FIXME: We'll have to test other browsers { wxEventType type = event.GetEventType(); m_eventType = MouseEventMoved; if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN) m_eventType = MouseEventPressed; else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP || type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK) m_eventType = MouseEventReleased; else if (type == wxEVT_MOTION) m_eventType = MouseEventMoved; if (event.Button(wxMOUSE_BTN_LEFT)) m_button = LeftButton; else if (event.Button(wxMOUSE_BTN_RIGHT)) m_button = RightButton; else if (event.Button(wxMOUSE_BTN_MIDDLE)) m_button = MiddleButton; else if (!m_eventType == MouseEventMoved) ASSERT_NOT_REACHED(); if (m_eventType == MouseEventMoved) m_clickCount = 0; else m_clickCount = event.ButtonDClick() ? 2 : 1; m_timestamp = WebCore::currentTime(); }
void view::on_mouse_event(wxMouseEvent& evt) { wxPoint pos = evt.GetPosition(); rtransform(pos.x, pos.y); ptr<visual> processor = get_mouse_processor(m_mouse_processor, this, m_doc->get_objects(), pos); long flag = 0; if (evt.LeftIsDown()) flag |= flag_left_button; if (evt.RightIsDown()) flag |= flag_right_button; if (evt.MiddleIsDown()) flag |= flag_middle_button; if (m_mouse_last_processor != processor) { processor->on_mouse_move_in(pos.x, pos.y, flag); if (m_mouse_last_processor != nullptr) m_mouse_last_processor->on_mouse_move_out(pos.x, pos.y, flag); } if (evt.GetWheelDelta() != 0) { int ds = evt.GetWheelDelta() / evt.GetWheelRotation(); processor->on_mouse_wheel(pos.x, pos.y, ds, flag); } else if (evt.Moving() || evt.Dragging()) { processor->on_mouse_move(pos.x, pos.y, flag); } else if (evt.ButtonDown()) { processor->on_mouse_down(pos.x, pos.y, flag); } else if (evt.ButtonUp()) { processor->on_mouse_up(pos.x, pos.y, flag); change_select(processor); } else if (evt.ButtonDClick()) { processor->on_mouse_dclick(pos.x, pos.y, flag); } m_mouse_last_processor = processor; refresh(); }
/* TextureEditorPanel::onTexCanvasMouseEvent * Called on any mouse event within the texture canvas *******************************************************************/ void TextureEditorPanel::onTexCanvasMouseEvent(wxMouseEvent& e) { // Get mouse position relative to texture point2_t pos = tex_canvas->screenToTexPosition(e.GetX(), e.GetY()); // Get patch that the mouse is over (if any) int patch = tex_canvas->patchAt(pos.x, pos.y); // LEFT DOUBLE CLICK if (e.ButtonDClick(wxMOUSE_BTN_LEFT)) { replacePatch(); } // LEFT MOUSE DOWN else if (e.LeftDown()) { // If not dragging if (e.ShiftDown()) { // Shift is down, add to selection if (patch >= 0) list_patches->selectItem(patch); } else if (e.ControlDown()) { // Control is down, remove from selection if (patch >= 0) list_patches->deSelectItem(patch); } else { // Clear selection only if patch clicked was not already selected if (!tex_canvas->patchSelected(patch)) list_patches->clearSelection(); // Select patch if (patch >= 0) list_patches->selectItem(patch); } } // LEFT MOUSE UP else if (e.LeftUp()) { // Hide texture grid tex_canvas->showGrid(false); // If mouse up over an already-selected patch, and shift/ctrl aren't down, // select only that patch (this mimics 'normal' drag-and-drop/selection behaviour) if (!e.ShiftDown() && !e.ControlDown() && tex_canvas->patchSelected(patch) && !tex_canvas->isDragging()) { list_patches->clearSelection(); list_patches->selectItem(patch); } // Redraw texture canvas tex_canvas->redraw(false); updateTextureControls(); } // RIGHT MOUSE UP else if (e.RightUp()) { // Create context menu wxMenu popup; theApp->getAction("txed_patch_add")->addToMenu(&popup, true); theApp->getAction("txed_patch_remove")->addToMenu(&popup, true); theApp->getAction("txed_patch_replace")->addToMenu(&popup, true); theApp->getAction("txed_patch_back")->addToMenu(&popup, true); theApp->getAction("txed_patch_forward")->addToMenu(&popup, true); theApp->getAction("txed_patch_duplicate")->addToMenu(&popup, true); hack_nodrag = true; PopupMenu(&popup); } // MOUSE DRAGGING else if (e.Dragging()) { // Drag selected patches if left button is down and any patch is selected if (hack_nodrag) hack_nodrag = false; else if (e.LeftIsDown()) { if (list_patches->GetSelectedItemCount() > 0) { // Get drag amount according to texture point2_t tex_cur = tex_canvas->screenToTexPosition(e.GetX(), e.GetY()); point2_t tex_prev = tex_canvas->screenToTexPosition(tex_canvas->getMousePrevPos().x, tex_canvas->getMousePrevPos().y); point2_t diff = tex_cur - tex_prev; // Move any selected patches wxArrayInt selected_patches = list_patches->selectedItems(); for (size_t a = 0; a < selected_patches.size(); a++) { CTPatch* patch = tex_current->getPatch(selected_patches[a]); if (!patch) continue; int16_t cx = patch->xOffset(); int16_t cy = patch->yOffset(); patch->setOffsetX(cx + diff.x); patch->setOffsetY(cy + diff.y); tex_modified = true; } // Refresh texture canvas tex_canvas->showGrid(true); tex_canvas->redraw(false); } else if (tex_current && tex_current->isExtended() && tex_canvas->getViewType() > 0) { // Get drag amount according to texture point2_t tex_cur = tex_canvas->screenToTexPosition(e.GetX(), e.GetY()); point2_t tex_prev = tex_canvas->screenToTexPosition(tex_canvas->getMousePrevPos().x, tex_canvas->getMousePrevPos().y); point2_t diff = tex_cur - tex_prev; // Modify offsets tex_current->setOffsetX(tex_current->getOffsetX() - diff.x); tex_current->setOffsetY(tex_current->getOffsetY() - diff.y); tex_modified = true; // Refresh texture canvas tex_canvas->redraw(false); } } } e.Skip(); }
void AButton::OnMouseEvent(wxMouseEvent & event) { wxSize clientSize = GetClientSize(); AButtonState prevState = GetState(); if (event.Entering()) { // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed // to make it pop up when we want it. auto text = GetToolTipText(); UnsetToolTip(); SetToolTip(text); mCursorIsInWindow = true; } else if (event.Leaving()) mCursorIsInWindow = false; else mCursorIsInWindow = (event.m_x >= 0 && event.m_y >= 0 && event.m_x < clientSize.x && event.m_y < clientSize.y); if (mEnabled && event.IsButton()) { if (event.ButtonIsDown(wxMOUSE_BTN_ANY)) { mIsClicking = true; if (event.ButtonDClick()) mIsDoubleClicked = true; if( !HasCapture() ) CaptureMouse(); } else if (mIsClicking) { mIsClicking = false; if (HasCapture()) ReleaseMouse(); if (mCursorIsInWindow && (mToggle || !mButtonIsDown)) { if (mToggle) mButtonIsDown = !mButtonIsDown; else mButtonIsDown = true; mWasShiftDown = event.ShiftDown(); mWasControlDown = event.ControlDown(); Click(); } } } // Only redraw and change tooltips if the state has changed. AButtonState newState = GetState(); if (newState != prevState) { Refresh(false); if (mCursorIsInWindow) UpdateStatus(); else { GetActiveProject()->TP_DisplayStatusMessage(wxT("")); } } else event.Skip(); }
void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) { int localbutt = 0; BASE_SCREEN* screen = GetScreen(); if( !screen ) return; /* Adjust value to filter mouse displacement before consider the drag * mouse is really a drag command, not just a movement while click */ #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 if( event.Leaving() ) m_canStartBlock = -1; if( !IsMouseCaptured() ) // No mouse capture in progress. SetAutoPanRequest( false ); if( GetParent()->IsActive() ) SetFocus(); else return; if( !event.IsButton() && !event.Moving() && !event.Dragging() ) return; if( event.RightDown() ) { OnRightClick( event ); return; } if( m_ignoreMouseEvents ) return; if( event.LeftDown() ) localbutt = GR_M_LEFT_DOWN; if( event.ButtonDClick( 1 ) ) localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK; if( event.MiddleDown() ) localbutt = GR_M_MIDDLE_DOWN; INSTALL_UNBUFFERED_DC( DC, this ); DC.SetBackground( *wxBLACK_BRUSH ); // Compute the cursor position in drawing (logical) units. GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) ); int kbstat = 0; if( event.ShiftDown() ) kbstat |= GR_KB_SHIFT; if( event.ControlDown() ) kbstat |= GR_KB_CTRL; if( event.AltDown() ) kbstat |= GR_KB_ALT; // Calling Double Click and Click functions : if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { if( m_ClickTimer ) { m_ClickTimer->Stop(); wxDELETE( m_ClickTimer ); } GetParent()->OnLeftDClick( &DC, GetParent()->RefPos( true ) ); // inhibit a response to the mouse left button release, // because we have a double click, and we do not want a new // OnLeftClick command at end of this Double Click m_ignoreNextLeftButtonRelease = true; } else if( event.LeftUp() ) { // A block command is in progress: a left up is the end of block // or this is the end of a double click, already seen // Note also m_ignoreNextLeftButtonRelease can be set by // the call to OnLeftClick(), so do not change it after calling OnLeftClick bool ignoreEvt = m_ignoreNextLeftButtonRelease; m_ignoreNextLeftButtonRelease = false; if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt ) { EDA_ITEM* item = screen->GetCurItem(); m_CursorClickPos = GetParent()->RefPos( true ); // If we have an item already selected, or we are using a tool, // we won't use the disambiguation menu so process the click immediately if( ( item && item->GetFlags() ) || GetParent()->GetToolId() != ID_NO_TOOL_SELECTED ) GetParent()->OnLeftClick( &DC, m_CursorClickPos ); else { wxDELETE( m_ClickTimer ); m_ClickTimer = new wxTimer(this, ID_MOUSE_DOUBLECLICK); m_ClickTimer->StartOnce( m_doubleClickInterval ); } } } else if( !event.LeftIsDown() ) { /* be sure there is a response to a left button release command * even when a LeftUp event is not seen. This happens when a * double click opens a dialog box, and the release mouse button * is made when the dialog box is opened. */ m_ignoreNextLeftButtonRelease = false; } if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) ) { m_PanStartCenter = GetParent()->GetScrollCenterPosition(); m_PanStartEventPosition = event.GetPosition(); INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOff( &dc ); SetCursor( wxCURSOR_SIZING ); } if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) ) { INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOn( &dc ); SetCursor( (wxStockCursor) m_currentCursor ); } if( event.MiddleIsDown() ) { wxPoint currentPosition = event.GetPosition(); double scale = GetParent()->GetScreen()->GetScalingFactor(); int x = m_PanStartCenter.x + KiROUND( (double) ( m_PanStartEventPosition.x - currentPosition.x ) / scale ); int y = m_PanStartCenter.y + KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale ); GetParent()->RedrawScreen( wxPoint( x, y ), false ); } // Calling the general function on mouse changes (and pseudo key commands) GetParent()->GeneralControl( &DC, event.GetLogicalPosition( DC ), 0 ); /*******************************/ /* Control of block commands : */ /*******************************/ // Command block can't start if mouse is dragging a new panel static EDA_DRAW_PANEL* lastPanel; if( lastPanel != this ) { m_minDragEventCount = 0; m_canStartBlock = -1; } /* A new command block can start after a release buttons * and if the drag is enough * This is to avoid a false start block when a dialog box is dismissed, * or when changing panels in hierarchy navigation * or when clicking while and moving mouse */ if( !event.LeftIsDown() && !event.MiddleIsDown() ) { m_minDragEventCount = 0; m_canStartBlock = 0; /* Remember the last cursor position when a drag mouse starts * this is the last position ** before ** clicking a button * this is useful to start a block command from the point where the * mouse was clicked first * (a filter creates a delay for the real block command start, and * we must remember this point) */ m_CursorStartPos = GetParent()->GetCrossHairPosition(); } if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) ) { if( !screen->IsBlockActive() ) { screen->m_BlockLocate.SetOrigin( m_CursorStartPos ); } if( event.LeftDown() ) { if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { SetAutoPanRequest( false ); GetParent()->HandleBlockPlace( &DC ); m_ignoreNextLeftButtonRelease = true; } } else if( ( m_canStartBlock >= 0 ) && event.LeftIsDown() && !IsMouseCaptured() ) { // Mouse is dragging: if no block in progress, start a block command. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK ) { // Start a block command int cmd_type = kbstat; // A block command is started if the drag is enough. A small // drag is ignored (it is certainly a little mouse move when // clicking) not really a drag mouse if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND ) m_minDragEventCount++; else { auto cmd = (GetParent()->GetToolId() == ID_ZOOM_SELECTION) ? BLOCK_ZOOM : 0; if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos, cmd ) ) { // should not occur: error GetParent()->DisplayToolMsg( wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) ); } else { SetAutoPanRequest( true ); SetCursor( wxCURSOR_SIZING ); } } } } if( event.ButtonUp( wxMOUSE_BTN_LEFT ) ) { /* Release the mouse button: end of block. * The command can finish (DELETE) or have a next command (MOVE, * COPY). However the block command is canceled if the block * size is small because a block command filtering is already * made, this case happens, but only when the on grid cursor has * not moved. */ #define BLOCK_MINSIZE_LIMIT 1 bool BlockIsSmall = ( std::abs( screen->m_BlockLocate.GetWidth() ) < BLOCK_MINSIZE_LIMIT ) && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT ); if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall ) { if( m_endMouseCaptureCallback ) { m_endMouseCaptureCallback( this, &DC ); SetAutoPanRequest( false ); } SetCursor( (wxStockCursor) m_currentCursor ); } else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END ) { SetAutoPanRequest( false ); GetParent()->HandleBlockEnd( &DC ); SetCursor( (wxStockCursor) m_currentCursor ); if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { SetAutoPanRequest( true ); SetCursor( wxCURSOR_HAND ); } } } } // End of block command on a double click // To avoid an unwanted block move command if the mouse is moved while double clicking if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { if( !screen->IsBlockActive() && IsMouseCaptured() ) { m_endMouseCaptureCallback( this, &DC ); } } lastPanel = this; #ifdef __WXGTK3__ // Screen has to be updated on every operation, otherwise the cursor leaves a trail (when xor // operation is changed to copy) or is not updated at all. Refresh(); #endif }
bool wxStdScrollBarInputHandler::HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { // is this a click event from an acceptable button? int btn = event.GetButton(); if ( btn == wxMOUSE_BTN_LEFT ) { // determine which part of the window mouse is in wxScrollBar *scrollbar = wxStaticCast(consumer->GetInputWindow(), wxScrollBar); wxHitTest ht = scrollbar->HitTestBar(event.GetPosition()); // when the mouse is pressed on any scrollbar element, we capture it // and hold capture until the same mouse button is released if ( event.ButtonDown() || event.ButtonDClick() ) { if ( !m_winCapture ) { m_btnCapture = btn; m_winCapture = consumer->GetInputWindow(); m_winCapture->CaptureMouse(); // generate the command bool hasAction = true; wxControlAction action; switch ( ht ) { case wxHT_SCROLLBAR_ARROW_LINE_1: action = wxACTION_SCROLL_LINE_UP; break; case wxHT_SCROLLBAR_ARROW_LINE_2: action = wxACTION_SCROLL_LINE_DOWN; break; case wxHT_SCROLLBAR_BAR_1: action = wxACTION_SCROLL_PAGE_UP; m_ptStartScrolling = event.GetPosition(); break; case wxHT_SCROLLBAR_BAR_2: action = wxACTION_SCROLL_PAGE_DOWN; m_ptStartScrolling = event.GetPosition(); break; case wxHT_SCROLLBAR_THUMB: consumer->PerformAction(wxACTION_SCROLL_THUMB_DRAG); m_ofsMouse = GetMouseCoord(scrollbar, event) - scrollbar->ScrollbarToPixel(); // fall through: there is no immediate action default: hasAction = false; } // remove highlighting Highlight(scrollbar, false); m_htLast = ht; // and press the arrow or highlight thumb now instead if ( m_htLast == wxHT_SCROLLBAR_THUMB ) Highlight(scrollbar, true); else Press(scrollbar, true); // start dragging if ( hasAction ) { m_timerScroll = new wxScrollBarTimer(this, action, scrollbar); m_timerScroll->StartAutoScroll(); } //else: no (immediate) action } //else: mouse already captured, nothing to do } // release mouse if the *same* button went up else if ( btn == m_btnCapture ) { if ( m_winCapture ) { StopScrolling(scrollbar); // if we were dragging the thumb, send the last event if ( m_htLast == wxHT_SCROLLBAR_THUMB ) { scrollbar->PerformAction(wxACTION_SCROLL_THUMB_RELEASE); } m_htLast = ht; Highlight(scrollbar, true); } else { // this is not supposed to happen as the button can't go up // without going down previously and then we'd have // m_winCapture by now wxFAIL_MSG( wxT("logic error in mouse capturing code") ); } } } return wxStdInputHandler::HandleMouse(consumer, event); }
void WinEDA_DrawPanel::OnMouseEvent(wxMouseEvent& event) /*******************************************************/ // Called when the canvas receives a mouse event. // { int localrealbutt = 0, localbutt = 0, localkey = 0; BASE_SCREEN * screen = GetScreen(); static WinEDA_DrawPanel * LastPanel; if ( event.Leaving() || event.Entering() ) { m_CanStartBlock = -1; } if (GetScreen()->ManageCurseur == NULL ) // Pas de commande en cours m_AutoPAN_Request = FALSE; if ( m_Parent->m_FrameIsActive ) SetFocus(); else return; // Mouse Wheel is a zoom command: if ( event.m_wheelRotation ) { // This is a zoom in ou out command if ( event.GetWheelRotation() > 0 ) localkey = WXK_F1; else localkey = WXK_F2; } if( !event.IsButton() && !event.Moving() && !event.Dragging() && ! localkey ) { return; } if( event.RightDown() ) { OnRightClick(event); return; } if ( m_IgnoreMouseEvents ) return; if( event.LeftIsDown() ) localrealbutt |= GR_M_LEFT_DOWN; if( event.MiddleIsDown() ) localrealbutt |= GR_M_MIDDLE_DOWN; if( event.LeftDown()) localbutt = GR_M_LEFT_DOWN; if( event.ButtonDClick(1)) localbutt = GR_M_LEFT_DOWN|GR_M_DCLICK; if( event.MiddleDown()) localbutt = GR_M_MIDDLE_DOWN; if( event.ButtonDClick(2)) {}; // Unused localrealbutt |= localbutt; /* compensation defaut wxGTK */ screen->m_MousePosition = CalcAbsolutePosition(wxPoint(event.GetX(), event.GetY())); wxClientDC DC(this); int kbstat = 0; DC.SetBackground(*wxBLACK_BRUSH ); PrepareGraphicContext(&DC); g_KeyPressed = localkey; if( event.ShiftDown() ) kbstat |= GR_KB_SHIFT; if( event.ControlDown() ) kbstat |= GR_KB_CTRL; if( event.AltDown() ) kbstat |= GR_KB_ALT; g_MouseOldButtons = localrealbutt; // Appel des fonctions liées au Double Click ou au Click if( localbutt == (int)(GR_M_LEFT_DOWN|GR_M_DCLICK) ) m_Parent->OnLeftDClick(&DC, screen->m_MousePosition); else if ( event.LeftDown() ) m_Parent->OnLeftClick(&DC, screen->m_MousePosition); if( event.ButtonUp(2) && (screen->BlockLocate.m_State == STATE_NO_BLOCK) ) { // The middle button has been relached, with no block command: // We use it for a zoom center command g_KeyPressed = localkey = WXK_F4; } /* Appel de la fonction generale de gestion des mouvements souris et commandes clavier */ m_Parent->GeneralControle(&DC, screen->m_MousePosition); /*******************************/ /* Control of block commands : */ /*******************************/ // Command block can't start if mouse is dragging a new panel if (LastPanel != this ) m_CanStartBlock = -1; // A new command block can start after a release buttons // Avoid a false start block when a dialog bos is demiss, // or when changing panels in hierachy navigation if ( !event.LeftIsDown() && !event.MiddleIsDown()) { m_CanStartBlock = 0; } if( m_Block_Enable && !(localbutt & GR_M_DCLICK) ) { if ( (screen->BlockLocate.m_Command == BLOCK_IDLE) || (screen->BlockLocate.m_State == STATE_NO_BLOCK)) { m_CursorStartPos = screen->m_Curseur; screen->BlockLocate.SetOrigin(m_CursorStartPos); } if ( event.LeftDown() || event.MiddleDown() ) { m_CursorStartPos = screen->m_Curseur; if ( screen->BlockLocate.m_State == STATE_BLOCK_MOVE ) { m_AutoPAN_Request = FALSE; m_Parent->HandleBlockPlace(&DC); } } else if( (m_CanStartBlock >= 0 ) && ( event.LeftIsDown() || event.MiddleIsDown() ) && screen->ManageCurseur == NULL && screen->ForceCloseManageCurseur == NULL ) { if ( screen->BlockLocate.m_State == STATE_NO_BLOCK ) { int cmd_type = kbstat; if ( event.MiddleIsDown() ) cmd_type |= MOUSE_MIDDLE; if ( ! m_Parent->HandleBlockBegin(&DC, cmd_type, m_CursorStartPos) ) { // error m_Parent->DisplayToolMsg( wxT("WinEDA_DrawPanel::OnMouseEvent() Block Error") ); } else { m_AutoPAN_Request = TRUE; SetCursor(m_PanelCursor = wxCURSOR_SIZING); } } } if( event.ButtonUp(1) || event.ButtonUp(2) ) { /* Relachement du bouton: fin de delimitation de block. La commande peut etre terminee (DELETE) ou continuer par le placement du block ainsi delimite (MOVE, COPY). Cependant bloc est annule si sa taille est trop petite*/ bool BlockIsSmall = ( ABS(screen->BlockLocate.GetWidth()/GetZoom()) < 3) && ( ABS(screen->BlockLocate.GetHeight()/GetZoom()) < 3); if ( (screen->BlockLocate.m_State != STATE_NO_BLOCK) && BlockIsSmall ) { if( GetScreen()->ForceCloseManageCurseur ) { GetScreen()->ForceCloseManageCurseur(m_Parent, &DC); m_AutoPAN_Request = FALSE; } SetCursor(m_PanelCursor = m_PanelDefaultCursor); } else if ( screen->BlockLocate.m_State == STATE_BLOCK_END ) { m_AutoPAN_Request = FALSE; m_Parent->HandleBlockEnd(&DC); SetCursor(m_PanelCursor = m_PanelDefaultCursor); if ( screen->BlockLocate.m_State == STATE_BLOCK_MOVE ) { m_AutoPAN_Request = TRUE; SetCursor(m_PanelCursor = wxCURSOR_HAND); } } } } // Arret de block sur un double click ( qui peut provoquer un move block // si on déplace la souris dans ce double click if ( localbutt == (int)(GR_M_LEFT_DOWN|GR_M_DCLICK) ) { if ( screen->BlockLocate.m_Command != BLOCK_IDLE ) { if( GetScreen()->ForceCloseManageCurseur ) { GetScreen()->ForceCloseManageCurseur(m_Parent, &DC); m_AutoPAN_Request = FALSE; } } } #if 0 wxString msg_debug; msg_debug.Printf(" block state %d, cmd %d", screen->BlockLocate.m_State, screen->BlockLocate.m_Command); m_Parent->PrintMsg(msg_debug); #endif LastPanel = this; m_Parent->SetToolbars(); }
void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) { // do this in advance to allow simply returning if we're not interested, // we'll undo it if we do handle the event below mevent.Skip(); // account for the control displacement const int xPhysical = mevent.GetX(); const int xLogical = xPhysical - m_scrollOffset; // first deal with the [continuation of any] dragging operations in // progress if ( IsResizing() ) { if ( mevent.LeftUp() ) EndResizing(xPhysical); else // update the live separator position StartOrContinueResizing(m_colBeingResized, xPhysical); return; } if ( IsReordering() ) { if ( !mevent.LeftUp() ) { // update the column position UpdateReorderingMarker(xPhysical); return; } // finish reordering and continue to generate a click event below if we // didn't really reorder anything if ( EndReordering(xPhysical) ) return; } // find if the event is over a column at all bool onSeparator; const unsigned col = mevent.Leaving() ? (onSeparator = false, COL_NONE) : FindColumnAtPoint(xLogical, &onSeparator); // update the highlighted column if it changed if ( col != m_hover ) { const unsigned hoverOld = m_hover; m_hover = col; RefreshColIfNotNone(hoverOld); RefreshColIfNotNone(m_hover); } // update mouse cursor as it moves around if ( mevent.Moving() ) { SetCursor(onSeparator ? wxCursor(wxCURSOR_SIZEWE) : wxNullCursor); return; } // all the other events only make sense when they happen over a column if ( col == COL_NONE ) return; // enter various dragging modes on left mouse press if ( mevent.LeftDown() ) { if ( onSeparator ) { // start resizing the column wxASSERT_MSG( !IsResizing(), "reentering column resize mode?" ); StartOrContinueResizing(col, xPhysical); } else // on column itself { // start dragging the column wxASSERT_MSG( !IsReordering(), "reentering column move mode?" ); StartReordering(col, xPhysical); } return; } // determine the type of header event corresponding to click events wxEventType evtType = wxEVT_NULL; const bool click = mevent.ButtonUp(), dblclk = mevent.ButtonDClick(); if ( click || dblclk ) { switch ( mevent.GetButton() ) { case wxMOUSE_BTN_LEFT: // treat left double clicks on separator specially if ( onSeparator && dblclk ) { evtType = wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; } else // not double click on separator { evtType = click ? wxEVT_COMMAND_HEADER_CLICK : wxEVT_COMMAND_HEADER_DCLICK; } break; case wxMOUSE_BTN_RIGHT: evtType = click ? wxEVT_COMMAND_HEADER_RIGHT_CLICK : wxEVT_COMMAND_HEADER_RIGHT_DCLICK; break; case wxMOUSE_BTN_MIDDLE: evtType = click ? wxEVT_COMMAND_HEADER_MIDDLE_CLICK : wxEVT_COMMAND_HEADER_MIDDLE_DCLICK; break; default: // ignore clicks from other mouse buttons ; } } if ( evtType == wxEVT_NULL ) return; wxHeaderCtrlEvent event(evtType, GetId()); event.SetEventObject(this); event.SetColumn(col); if ( GetEventHandler()->ProcessEvent(event) ) mevent.Skip(false); }
void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) { int localrealbutt = 0, localbutt = 0; BASE_SCREEN* screen = GetScreen(); if( !screen ) return; /* Adjust value to filter mouse displacement before consider the drag * mouse is really a drag command, not just a movement while click */ #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 if( event.Leaving() ) m_canStartBlock = -1; if( !IsMouseCaptured() ) // No mouse capture in progress. m_requestAutoPan = false; if( GetParent()->IsActive() ) SetFocus(); else return; if( !event.IsButton() && !event.Moving() && !event.Dragging() ) return; if( event.RightDown() ) { OnRightClick( event ); return; } if( m_ignoreMouseEvents ) return; if( event.LeftIsDown() ) localrealbutt |= GR_M_LEFT_DOWN; if( event.MiddleIsDown() ) localrealbutt |= GR_M_MIDDLE_DOWN; if( event.LeftDown() ) localbutt = GR_M_LEFT_DOWN; if( event.ButtonDClick( 1 ) ) localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK; if( event.MiddleDown() ) localbutt = GR_M_MIDDLE_DOWN; localrealbutt |= localbutt; // compensation default wxGTK INSTALL_UNBUFFERED_DC( DC, this ); DC.SetBackground( *wxBLACK_BRUSH ); // Compute the cursor position in drawing (logical) units. GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) ); int kbstat = 0; if( event.ShiftDown() ) kbstat |= GR_KB_SHIFT; if( event.ControlDown() ) kbstat |= GR_KB_CTRL; if( event.AltDown() ) kbstat |= GR_KB_ALT; // Calling Double Click and Click functions : if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { GetParent()->OnLeftDClick( &DC, GetParent()->RefPos( true ) ); // inhibit a response to the mouse left button release, // because we have a double click, and we do not want a new // OnLeftClick command at end of this Double Click m_ignoreNextLeftButtonRelease = true; } else if( event.LeftUp() ) { // A block command is in progress: a left up is the end of block // or this is the end of a double click, already seen // Note also m_ignoreNextLeftButtonRelease can be set by // the call to OnLeftClick(), so do not change it after calling OnLeftClick bool ignoreEvt = m_ignoreNextLeftButtonRelease; m_ignoreNextLeftButtonRelease = false; if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt ) GetParent()->OnLeftClick( &DC, GetParent()->RefPos( true ) ); } else if( !event.LeftIsDown() ) { /* be sure there is a response to a left button release command * even when a LeftUp event is not seen. This happens when a * double click opens a dialog box, and the release mouse button * is made when the dialog box is opened. */ m_ignoreNextLeftButtonRelease = false; } if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) && m_enableMiddleButtonPan ) { if( m_panScrollbarLimits ) { int ppux, ppuy; GetScrollPixelsPerUnit( &ppux, &ppuy ); GetViewStart( &m_PanStartCenter.x, &m_PanStartCenter.y ); m_PanStartCenter.x *= ppux; m_PanStartCenter.y *= ppuy; } else m_PanStartCenter = GetParent()->GetScrollCenterPosition(); m_PanStartEventPosition = event.GetPosition(); INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOff( &dc ); } if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) && m_enableMiddleButtonPan ) { INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOn( &dc ); } if( event.MiddleIsDown() && m_enableMiddleButtonPan ) { wxPoint currentPosition = event.GetPosition(); if( m_panScrollbarLimits ) { int x, y; int tmpX, tmpY; int ppux, ppuy; int maxX, maxY; int vsizeX, vsizeY; int csizeX, csizeY; GetViewStart( &tmpX, &tmpY ); GetScrollPixelsPerUnit( &ppux, &ppuy ); GetVirtualSize( &vsizeX, &vsizeY ); GetClientSize( &csizeX, &csizeY ); maxX = vsizeX - csizeX; maxY = vsizeY - csizeY; x = m_PanStartCenter.x + m_PanStartEventPosition.x - currentPosition.x; y = m_PanStartCenter.y + m_PanStartEventPosition.y - currentPosition.y; bool shouldMoveCursor = false; if( x < 0 ) { currentPosition.x += x; x = 0; shouldMoveCursor = true; } if( y < 0 ) { currentPosition.y += y; y = 0; shouldMoveCursor = true; } if( x > maxX ) { currentPosition.x += ( x - maxX ); x = maxX; shouldMoveCursor = true; } if( y > maxY ) { currentPosition.y += ( y - maxY ); y = maxY; shouldMoveCursor = true; } if( shouldMoveCursor ) WarpPointer( currentPosition.x, currentPosition.y ); Scroll( x/ppux, y/ppuy ); double scale = GetParent()->GetScreen()->GetScalingFactor(); wxPoint center = GetParent()->GetScrollCenterPosition(); center.x += KiROUND( (double) ( x - tmpX ) / scale ) / ppux; center.y += KiROUND( (double) ( y - tmpY ) / scale ) / ppuy; GetParent()->SetScrollCenterPosition( center ); Refresh(); Update(); } else { double scale = GetParent()->GetScreen()->GetScalingFactor(); int x = m_PanStartCenter.x + KiROUND( (double) ( m_PanStartEventPosition.x - currentPosition.x ) / scale ); int y = m_PanStartCenter.y + KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale ); GetParent()->RedrawScreen( wxPoint( x, y ), false ); } } if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) && !m_enableMiddleButtonPan && (screen->m_BlockLocate.GetState() == STATE_NO_BLOCK) ) { // The middle button has been released, with no block command: // We use it for a zoom center at cursor position command wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER ); cmd.SetEventObject( this ); GetEventHandler()->ProcessEvent( cmd ); } // Calling the general function on mouse changes (and pseudo key commands) GetParent()->GeneralControl( &DC, event.GetLogicalPosition( DC ), 0 ); /*******************************/ /* Control of block commands : */ /*******************************/ // Command block can't start if mouse is dragging a new panel static EDA_DRAW_PANEL* lastPanel; if( lastPanel != this ) { m_minDragEventCount = 0; m_canStartBlock = -1; } /* A new command block can start after a release buttons * and if the drag is enough * This is to avoid a false start block when a dialog box is dismissed, * or when changing panels in hierarchy navigation * or when clicking while and moving mouse */ if( !event.LeftIsDown() && !event.MiddleIsDown() ) { m_minDragEventCount = 0; m_canStartBlock = 0; /* Remember the last cursor position when a drag mouse starts * this is the last position ** before ** clicking a button * this is useful to start a block command from the point where the * mouse was clicked first * (a filter creates a delay for the real block command start, and * we must remember this point) */ m_CursorStartPos = GetParent()->GetCrossHairPosition(); } if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) ) { if( !screen->IsBlockActive() ) { screen->m_BlockLocate.SetOrigin( m_CursorStartPos ); } if( event.LeftDown() || ( !m_enableMiddleButtonPan && event.MiddleDown() ) ) { if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { m_requestAutoPan = false; GetParent()->HandleBlockPlace( &DC ); m_ignoreNextLeftButtonRelease = true; } } else if( ( m_canStartBlock >= 0 ) && ( event.LeftIsDown() || ( !m_enableMiddleButtonPan && event.MiddleIsDown() ) ) && !IsMouseCaptured() ) { // Mouse is dragging: if no block in progress, start a block command. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK ) { // Start a block command int cmd_type = kbstat; if( !m_enableMiddleButtonPan && event.MiddleIsDown() ) cmd_type |= MOUSE_MIDDLE; // A block command is started if the drag is enough. A small // drag is ignored (it is certainly a little mouse move when // clicking) not really a drag mouse if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND ) m_minDragEventCount++; else { if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) ) { // should not occur: error GetParent()->DisplayToolMsg( wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) ); } else { m_requestAutoPan = true; SetCursor( wxCURSOR_SIZING ); } } } } if( event.ButtonUp( wxMOUSE_BTN_LEFT ) || ( !m_enableMiddleButtonPan && event.ButtonUp( wxMOUSE_BTN_MIDDLE ) ) ) { /* Release the mouse button: end of block. * The command can finish (DELETE) or have a next command (MOVE, * COPY). However the block command is canceled if the block * size is small because a block command filtering is already * made, this case happens, but only when the on grid cursor has * not moved. */ #define BLOCK_MINSIZE_LIMIT 1 bool BlockIsSmall = ( std::abs( screen->m_BlockLocate.GetWidth() ) < BLOCK_MINSIZE_LIMIT ) && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT ); if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall ) { if( m_endMouseCaptureCallback ) { m_endMouseCaptureCallback( this, &DC ); m_requestAutoPan = false; } SetCursor( (wxStockCursor) m_currentCursor ); } else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END ) { m_requestAutoPan = false; GetParent()->HandleBlockEnd( &DC ); SetCursor( (wxStockCursor) m_currentCursor ); if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { m_requestAutoPan = true; SetCursor( wxCURSOR_HAND ); } } } } // End of block command on a double click // To avoid an unwanted block move command if the mouse is moved while double clicking if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { if( !screen->IsBlockActive() && IsMouseCaptured() ) { m_endMouseCaptureCallback( this, &DC ); } } #if 0 wxString msg_debug; msg_debug.Printf( " block state %d, cmd %d", screen->m_BlockLocate.GetState(), screen->m_BlockLocate.GetCommand() ); GetParent()->PrintMsg( msg_debug ); #endif lastPanel = this; }
void wxWebView::OnMouseEvents(wxMouseEvent& event) { event.Skip(); if (!m_impl->page) return; WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; wxPoint globalPoint = ClientToScreen(event.GetPosition()); wxEventType type = event.GetEventType(); if (type == wxEVT_MOUSEWHEEL) { if (m_mouseWheelZooms && event.ControlDown() && !event.AltDown() && !event.ShiftDown()) { if (event.GetWheelRotation() < 0) DecreaseTextSize(); else if (event.GetWheelRotation() > 0) IncreaseTextSize(); } else { WebCore::PlatformWheelEvent wkEvent(event, globalPoint); frame->eventHandler()->handleWheelEvent(wkEvent); } return; } // If an event, such as a right-click event, leads to a focus change (e.g. it // raises a dialog), WebKit never gets the mouse up event and never relinquishes // mouse capture. This leads to WebKit handling mouse events, such as modifying // the selection, while other controls or top level windows have the focus. // I'm not sure if this is the right place to handle this, but I can't seem to // find a precedent on how to handle this in other ports. if (wxWindow::FindFocus() != this) { while (HasCapture()) ReleaseMouse(); frame->eventHandler()->setMousePressed(false); return; } int clickCount = event.ButtonDClick() ? 2 : 1; if (clickCount == 1 && m_impl->tripleClickTimer.IsRunning()) { wxPoint diff(event.GetPosition() - m_impl->tripleClickPos); if (abs(diff.x) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_X) && abs(diff.y) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_Y)) { clickCount = 3; } } else if (clickCount == 2) { m_impl->tripleClickTimer.Start(getDoubleClickTime(), false); m_impl->tripleClickPos = event.GetPosition(); } WebCore::PlatformMouseEvent wkEvent(event, globalPoint, clickCount); if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN || type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK) { frame->eventHandler()->handleMousePressEvent(wkEvent); if (!HasCapture()) CaptureMouse(); } else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP) { frame->eventHandler()->handleMouseReleaseEvent(wkEvent); while (HasCapture()) ReleaseMouse(); } else if (type == wxEVT_MOTION || type == wxEVT_ENTER_WINDOW || type == wxEVT_LEAVE_WINDOW) frame->eventHandler()->mouseMoved(wkEvent); }
void SliderBar::OnMouseEvents (wxMouseEvent &ev) { if (!IsEnabled()) { ev.Skip(); return; } if (ev.Entering() && !_dragging) { _barbrush.SetColour(_overbarcolor); do_redraw(); } else if (ev.Leaving() && !_dragging) { _barbrush.SetColour(_barcolor); do_redraw(); } if (ev.Dragging() && _dragging) { int delta = ev.GetX() - _last_x; float fdelta = delta * _val_scale; if (ev.ControlDown()) { fdelta *= 0.5f; if (ev.ShiftDown()) { fdelta *= 0.5f; } } float newval = _value + fdelta; //cerr << "dragging: " << ev.GetX() << " " << delta << " " << fdelta << " " << newval << endl; if (_snap_mode == IntegerSnap) { newval = nearbyintf (newval); } newval = max (min (newval, _upper_bound), _lower_bound); if (newval != _value) { _value = newval; value_changed (get_value()); // emit update_value_str(); do_redraw(); //cerr << "new val is: " << _value << endl; _last_x = ev.GetX(); } } else if (ev.Moving()) { // do nothing } else if (ev.GetEventType() == wxEVT_MOUSEWHEEL) { float fscale = 0.02f * (ev.ControlDown() ? 0.5f: 1.0f); float newval; if (_snap_mode == IntegerSnap) { newval = _value + ((ev.GetWheelRotation() > 0) ? 1 : -1); } else { if (ev.GetWheelRotation() > 0) { newval = _value + (_upper_bound - _lower_bound) * fscale; } else { newval = _value - (_upper_bound - _lower_bound) * fscale; } } if (_snap_mode == IntegerSnap) { newval = nearbyintf (newval); } newval = max (min (newval, _upper_bound), _lower_bound); _value = newval; value_changed (get_value()); // emit update_value_str(); do_redraw(); } else if (ev.RightDown()) { this->PopupMenu ( _popup_menu, ev.GetX(), ev.GetY()); } else if (ev.RightUp()) { //this->PopupMenu ( _popup_menu, ev.GetX(), ev.GetY()); } else if (ev.ButtonDown()) { CaptureMouse(); _dragging = true; _last_x = ev.GetX(); pressed(); // emit if (ev.MiddleDown() && !ev.ControlDown()) { // set immediately float newval = (ev.GetX() * _val_scale) + _lower_bound; if (_snap_mode == IntegerSnap) { newval = nearbyintf (newval); } _value = newval; value_changed (get_value()); // emit update_value_str(); do_redraw(); } else if (ev.LeftDown() && ev.ShiftDown()) { // set to default _value = max (min (_default_val, _upper_bound), _lower_bound); value_changed(get_value()); update_value_str(); do_redraw(); } } else if (ev.ButtonUp()) { _dragging = false; ReleaseMouse(); if (_use_pending) { // This didn't really work //if (_pending_val != _value) { // _value = _pending_val; // update_value_str(); //} _use_pending = false; } if (ev.GetX() >= _width || ev.GetX() < 0 || ev.GetY() < 0 || ev.GetY() > _height) { _barbrush.SetColour(_barcolor); do_redraw(); } else { _barbrush.SetColour(_overbarcolor); do_redraw(); } if (ev.MiddleUp() && ev.ControlDown()) { // binding click bind_request(); // emit } released(); // emit } else if (ev.ButtonDClick()) { // this got annoying //show_text_ctrl (); } else { ev.Skip(); } }
void LWSlider::OnMouseEvent(wxMouseEvent & event) { if (event.Entering()) { #if wxUSE_TOOLTIPS // Not available in wxX11 // Display the tooltip in the status bar if (mParent->GetToolTip()) { wxString tip = mParent->GetToolTip()->GetTip(); GetActiveProject()->TP_DisplayStatusMessage(tip); Refresh(); } #endif } else if (event.Leaving()) { GetActiveProject()->TP_DisplayStatusMessage(wxT("")); Refresh(); } // Events other than mouse-overs are ignored when we are disabled if (!mEnabled) return; float prevValue = mCurrentValue; // Figure out the thumb position wxRect r; if (mOrientation == wxHORIZONTAL) { r.x = mLeft + ValueToPosition(mCurrentValue); r.y = mTop + (mCenterY - (mThumbHeight / 2)); } else { r.x = mLeft + (mCenterX - (mThumbWidth / 2)); r.y = mTop + ValueToPosition(mCurrentValue); } r.width = mThumbWidth; r.height = mThumbHeight; wxRect tolerantThumbRect = r; tolerantThumbRect.Inflate(3, 3); // Should probably use a right click instead/also if( event.ButtonDClick() && mPopup ) { //On a double-click, we should pop up a dialog. DoShowDialog(mParent->ClientToScreen(wxPoint(event.m_x,event.m_y))); } else if( event.ButtonDown() ) { if( mDefaultShortcut && event.CmdDown() ) { mCurrentValue = mDefaultValue; } if( event.RightDown() ) { mParent->SetFocus(); } // Thumb clicked? // // Do not change position until first drag. This helps // with unintended value changes. if( tolerantThumbRect.Contains( event.GetPosition() ) ) { // Remember mouse position and current value mClickPos = (mOrientation == wxHORIZONTAL) ? event.m_x : event.m_y; mClickValue = mCurrentValue; mIsDragging = true; } // Clicked to set location? else { mCurrentValue = ClickPositionToValue( (mOrientation == wxHORIZONTAL) ? event.m_x : event.m_y, event.ShiftDown()); } mParent->CaptureMouse(); // wxSetCursor(wxCURSOR_BLANK); ((TipPanel*)LWSlider::sharedTipPanel)->SetTargetParent(mParent); FormatPopWin(); SetPopWinPosition(); LWSlider::sharedTipPanel->Show(); //hide mouseover tooltip wxToolTip::Enable(false); } else if( event.ButtonUp() ) { mIsDragging = false; if (mParent->HasCapture()) mParent->ReleaseMouse(); LWSlider::sharedTipPanel->Hide(); //restore normal tooltip behavor for mouseovers wxToolTip::Enable(true); // wxSetCursor(wxNullCursor); } else if (event.Dragging() && mIsDragging) { if (mOrientation == wxHORIZONTAL) { if (event.m_y < (r.y - 2 * r.height) || event.m_y > (r.y + 3 * r.height)) { // If the mouse y coordinate is relatively far from the slider, // snap back to the original position mCurrentValue = mClickValue; } else { // Otherwise, move the slider to the right position based // on the mouse position mCurrentValue = DragPositionToValue(event.m_x, event.ShiftDown()); } } else // (mOrientation == wxVERTICAL) { if (event.m_x < (r.x - 2 * r.width) || event.m_x > (r.x + 3 * r.width)) { // If the mouse x coordinate is relatively far from the slider, // snap back to the original position mCurrentValue = mClickValue; } else { // Otherwise, move the slider to the right position based // on the mouse position mCurrentValue = DragPositionToValue(event.m_y, event.ShiftDown()); } } } else if( event.m_wheelRotation != 0 ) { //Calculate the number of steps in a given direction this event //represents (allows for two or more clicks on a single event.) double steps = event.m_wheelRotation / (event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0); if( steps < 0.0 ) { Decrease( (float)-steps ); } else { Increase( (float)steps ); } SendUpdate( mCurrentValue ); } if( prevValue != mCurrentValue ) SendUpdate( mCurrentValue ); }
int bmx_wxmouseevent_buttondclick(wxMouseEvent & event, int but) { return static_cast<int>(event.ButtonDClick(but)); }