void ModalLayer::_onMsg( const Msg_p& _pMsg ) { Layer::_onMsg(_pMsg); if( !m_modalHooks.isEmpty() && _findWidget( _pMsg->pointerPos(), WG_SEARCH_ACTION_TARGET ) == this ) { switch( _pMsg->type() ) { case WG_MSG_MOUSE_PRESS: { MouseButtonMsg_p pMsg = MouseButtonMsg::cast(_pMsg); Base::msgRouter()->post( new ModalBlockedPressMsg( pMsg->button(), this) ); } break; case WG_MSG_MOUSE_RELEASE: { MouseButtonMsg_p pMsg = MouseButtonMsg::cast(_pMsg); Base::msgRouter()->post( new ModalBlockedPressMsg( pMsg->button(), this) ); } break; case WG_MSG_MOUSE_MOVE: { Base::msgRouter()->post( new ModalMoveOutsideMsg(this) ); } break; } } }
void MsgRouter::_dispatchQueued() { while( !m_msgQueue.empty() ) { Msg_p pMsg = m_msgQueue.front(); m_insertPos = m_msgQueue.begin()+1; // Insert position set to right after current event. do { if( pMsg->hasCopyTo() ) pMsg->getCopyTo()->receive( pMsg ); if( pMsg->hasSource() ) _dispatchToSourceRoutes( pMsg ); _dispatchToTypeRoutes( pMsg ); _broadcast( pMsg ); } while( pMsg->doRepost() ); m_msgQueue.pop_front(); } m_insertPos = m_msgQueue.begin(); // Insert position set right to start. }
void Menubar::_receive( const Msg_p& pMsg ) { Widget::_receive(pMsg); switch( pMsg->type() ) { case MsgType::MouseMove: case MsgType::MousePress: { Coord pos = InputMsg::cast(pMsg)->pointerPos() - globalPos(); uint32_t item = _getItemAtAbsPos( pos.x, pos.y ); if( item && !m_items.get(item-1)->m_bEnabled ) item = 0; // Item is disabled and can't be marked. if(m_markedItem != item) { m_markedItem = item; _requestRender(); } // If a menu entry already is selected we should // switch to the new marked one. if( m_selectedItem ) { if( m_markedItem && m_selectedItem != m_markedItem ) { _closeMenu( m_selectedItem ); _openMenu( m_markedItem ); } } // If this was a press, we need to select the item and open the menu. //TODO: A click on an already open entry should close the menu. if( item && pMsg->type()== MsgType::MousePress ) { _openMenu( item ); } } case MsgType::MouseLeave: m_markedItem = 0; _requestRender(); break; } }
bool MsgFilter::_filterType( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) return true; return false; }
void TextEditor::_receive( const Msg_p& pMsg ) { MsgType type = pMsg->type(); Widget::_receive( pMsg ); m_text.receive( pMsg ); }
string MsgLogger::_formatCopyTo( const Msg_p& _pMsg ) const { std::string out; if( _pMsg->hasCopyTo() ) { char temp[64]; Receiver * pCopyTo = _pMsg->getCopyTo().rawPtr(); const char * pType = pCopyTo->className(); sprintf( temp, " copyTo=%p (%s)", pCopyTo, pType ); out = temp; } return out; }
void MsgRouter::_dispatchToSourceRoutes( const Msg_p& pMsg ) { Object * pSource = pMsg->sourceRawPtr(); if( pSource ) { auto it = m_sourceRoutes.find(Object_wp(pSource)); if( it != m_sourceRoutes.end() ) { Route * pRoute = it->second.first(); while( pRoute ) { if( pRoute->m_filter == MsgType::Dummy || pRoute->m_filter == pMsg->type() ) pRoute->dispatch( pMsg ); pRoute = pRoute->next(); } } } }
bool MsgFilter::_filterWheelRollMsgs( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) { int chr = WheelRollMsg::cast(pMsg)->wheel(); if( chr == filter.m_data1 ) return true; } return false; }
bool MsgFilter::_filterNativeKeyMsgs( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) { KeyMsg_p p = KeyMsg::cast(pMsg); if( p->nativeKeyCode() == filter.m_data1 ) return true; } return false; }
bool MsgFilter::_filterCharacterMsgs( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) { int chr = CharacterMsg::cast(pMsg)->character(); if( chr == filter.m_data1 ) return true; } return false; }
bool MsgFilter::_filterItemToggleMsgs( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) { int itemId = ItemToggleMsg::cast(pMsg)->itemId(); if( itemId == filter.m_data1 ) return true; } return false; }
string MsgLogger::_formatSource( const Msg_p& _pMsg ) const { std::string out; if( _pMsg->sourceRawPtr() ) { char temp[64]; Object * pObject = _pMsg->sourceRawPtr(); static const char def_type[] = "deleted"; const char * pType = def_type; if( pObject ) pType = pObject->className(); sprintf( temp, " source=%p (%s)", pObject, pType ); out = temp; } return out; }
bool MsgFilter::_filterItemMousePressMsgs( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) { ItemMousePressMsg_p pMsg = ItemMousePressMsg::cast(pMsg); if( (filter.m_data1 == -1 || pMsg->itemId() == filter.m_data1) || (filter.m_data2 == -1 || pMsg->button() == filter.m_data2) ) return true; } return false; }
void InputHandler::receive( const Msg_p& pMsg ) { if( pMsg->type() == MsgType::Tick ) { int64_t timestamp = TickMsg::cast(pMsg)->timestamp(); _handleButtonRepeats( timestamp ); _handleKeyRepeats( timestamp ); m_timeStamp = timestamp; } }
void MsgRouter::_dispatchToTypeRoutes( const Msg_p& pMsg ) { auto it = m_typeRoutes.find(pMsg->type()); if( it != m_typeRoutes.end() ) { Route * pRoute = it->second.first(); while( pRoute ) { pRoute->dispatch( pMsg ); pRoute = pRoute->next(); } } }
void MsgRouter::_finalizeMsg( const Msg_p& pMsg ) { // Fill in missing information in the event-class. pMsg->m_timestamp = m_time; pMsg->m_modKeys = m_modKeys; // Only global POINTER_ENTER & POINTER_MOVE events have these members // set, the rest needs to have them filled in. if( pMsg->hasCopyTo() || (pMsg->type() != WG_MSG_MOUSE_MOVE && pMsg->type() != WG_MSG_MOUSE_ENTER) ) { pMsg->m_pointerPos = m_pointerPos; } // Msg specific finalizations switch( pMsg->type() ) { // Key events need translation of keycodes. case WG_MSG_KEY_PRESS: case WG_MSG_KEY_RELEASE: case WG_MSG_KEY_REPEAT: { KeyMsg* p = static_cast<KeyMsg*>(pMsg.rawPtr()); p->m_translatedKeyCode = Base::translateKey(p->m_nativeKeyCode); } break; default: break; } }
bool MsgFilter::_filterMouseButtonMsgs( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) { if( filter.m_data1 == 0 ) return true; else { MouseButtonMsg_p p = MouseButtonMsg::cast(pMsg); if( p->button() == filter.m_data1 ) return true; } } return false; }
bool MsgFilter::_filterKeyMsgs( const Msg_p& pMsg, const MsgFilter& filter ) { if( pMsg->type() == filter.msgType() ) { if( filter.m_data1 == 0 ) return true; else { KeyMsg_p p = KeyMsg::cast(pMsg); if( p->translatedKeyCode() == filter.m_data1 ) return true; } } return false; }
void AnimPlayer::_onMsg( const Msg_p& pMsg ) { Widget::_onMsg( pMsg ); switch( pMsg->type() ) { case WG_MSG_TICK: { if( !m_pAnim || !m_state.isEnabled() ) return; m_playPos += TickMsg::cast(pMsg)->millisec() * m_speed; _playPosUpdated(); } break; } }
void cbDragWidget( const Msg_p& _pMsg, const Object_p& pObject ) { Widget_p pWidget = Widget::cast(pObject); if( _pMsg->type() != WG_MSG_MOUSE_DRAG || !pWidget->parent() ) return; const MouseDragMsg_p pMsg = MouseDragMsg::cast(_pMsg); Coord dragDistance = pMsg->draggedTotal(); Coord ofs = dragStartPos + dragDistance; // printf( "AccDistance: %d, %d\n", dragDistance.x, dragDistance.y ); printf( "ofs: %d, %d start: %d %d distance: %d, %d\n", ofs.x, ofs.y, dragStartPos.x, dragStartPos.y, dragDistance.x, dragDistance.y ); FlexHook_p pHook = FlexHook::cast(pWidget->hook()); pHook->setOfs(dragStartPos+dragDistance); }
void cbMoveResize( const Msg_p& _pMsg, const Object_p& _pWidget ) { static Coord posAtPress[MouseButton_Max]; auto pWidget = Widget::cast(_pWidget); FlexHook_p pHook = FlexHook::cast(pWidget->hook()); switch( _pMsg->type() ) { case MsgType::MousePress: { auto pMsg = MousePressMsg::cast(_pMsg); posAtPress[(int)pMsg->button()] = pWidget->pos(); } break; case MsgType::MouseDrag: { auto pMsg = MouseDragMsg::cast(_pMsg); if( pMsg->button() == MouseButton::Right ) { pHook->setSize( pHook->size() + pMsg->draggedNow().toSize() ); } else if( pMsg->button() == MouseButton::Middle ) { pHook->setOfs( posAtPress[(int)MouseButton::Middle] + pMsg->draggedTotal() ); } } break; case MsgType::MouseRelease: break; default: break; } }
void FpsDisplay::_onMsg( const Msg_p& pMsg ) { Widget::_onMsg(pMsg); switch( pMsg->type() ) { case WG_MSG_TICK: { // Update tick buffer m_tickBufferOfs = (++m_tickBufferOfs) % TICK_BUFFER; int msDiff = TickMsg::cast(pMsg)->millisec(); if( msDiff > 0 ) m_pTickBuffer[m_tickBufferOfs] = msDiff; else m_pTickBuffer[m_tickBufferOfs] = 1; // Update valueTexts from tick-buffer const int cCurrentFrames = 10; int currOfs = ((int)m_tickBufferOfs) - cCurrentFrames; if( currOfs < 0 ) currOfs += TICK_BUFFER; int currTotal = 0; for( int i = 0 ; i < cCurrentFrames ; i++ ) { currTotal += m_pTickBuffer[currOfs++]; currOfs %= TICK_BUFFER; } float fpsCurrent = 1000.f / (currTotal / (float) cCurrentFrames); //____ int avg = 0; for( int i = 0 ; i < TICK_BUFFER ; i++ ) avg += m_pTickBuffer[i]; float fpsAvg = 1000.f / (((float)avg)/TICK_BUFFER); //____ int min = 1000000000; for( int i = 0 ; i < TICK_BUFFER ; i++ ) if( min > m_pTickBuffer[i] ) min = m_pTickBuffer[i]; float fpsMax = 1000.f / min; //____ int max = 0; for( int i = 0 ; i < TICK_BUFFER ; i++ ) if( max < m_pTickBuffer[i] ) max = m_pTickBuffer[i]; float fpsMin = 1000.f / max; //____ char temp[100]; sprintf( temp, "%.2f/n%.2f/n%.2f/n%.2f/n", fpsCurrent, fpsMin, fpsAvg, fpsMax ); m_valuesText.set(temp); _requestRender(); } default: break; } }
void LegacyTextEditor::_onMsg( const Msg_p& pMsg ) { Widget::_onMsg(pMsg); MsgType type = pMsg->type(); if( type == MsgType::Tick ) { if( isSelectable() && m_state.isFocused() ) { m_text.incTime( TickMsg::cast(pMsg)->timediff() ); _requestRender(); //TODO: Should only render the cursor and selection! } return; } if( m_state.isFocused() && (type == MsgType::MousePress || type == MsgType::MouseDrag) && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) { MouseButtonMsg_p p = MouseButtonMsg::cast(pMsg); ModifierKeys modKeys = p->modKeys(); Coord pointerPos = p->pointerPos(); if( isSelectable() && (modKeys & MODKEY_SHIFT) ) { m_text.setSelectionMode(true); } m_text.cursorGotoCoord( pointerPos, globalGeo() ); if(isSelectable() && type == MsgType::MousePress && !(modKeys & MODKEY_SHIFT)) { m_text.clearSelection(); m_text.setSelectionMode(true); } } else if( type == MsgType::MouseRelease ) { if(m_state.isFocused() && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left) m_text.setSelectionMode(false); } else if( !m_state.isFocused() && isEditable() && type == MsgType::MousePress && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) { grabFocus(); } if( type == MsgType::TextInput ) { if( isEditable() ) { String text = TextInputMsg::cast(pMsg)->text(); for( int i = 0 ; i < text.length() ; i++ ) { unsigned short chr = text.chars()[i].getGlyph(); if( chr >= 32 && chr != 127) { _insertCharAtCursor(chr); } else if( chr == 13 ) { _insertCharAtCursor('\n'); } else if( chr == '\t' && m_bTabLock ) { _insertCharAtCursor( '\t' ); } } } } if( type == MsgType::KeyRelease ) { switch( KeyMsg::cast(pMsg)->translatedKeyCode() ) { case Key::Shift: if(!Base::inputHandler()->isButtonPressed(MouseButton::Left)) m_text.setSelectionMode(false); break; } } if( (type == MsgType::KeyPress || type == MsgType::KeyRepeat) && isEditable() ) { KeyMsg_p p = KeyMsg::cast(pMsg); ModifierKeys modKeys = p->modKeys(); switch( p->translatedKeyCode() ) { case Key::Left: if( modKeys & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( modKeys & MODKEY_CTRL ) m_text.gotoPrevWord(); else m_text.goLeft(); break; case Key::Right: if( modKeys & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( modKeys & MODKEY_CTRL ) m_text.gotoNextWord(); else m_text.goRight(); break; case Key::Up: if( modKeys & MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.cursorGoUp( 1, globalGeo() ); break; case Key::Down: if( modKeys & MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.cursorGoDown( 1, globalGeo() ); break; case Key::Backspace: if(m_text.hasSelection()) m_text.delSelection(); else if( modKeys & MODKEY_CTRL ) m_text.delPrevWord(); else m_text.delPrevChar(); break; case Key::Delete: if(m_text.hasSelection()) m_text.delSelection(); else if( modKeys & MODKEY_CTRL ) m_text.delNextWord(); else m_text.delNextChar(); break; case Key::Home: if( modKeys & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( modKeys & MODKEY_CTRL ) m_text.goBot(); else m_text.goBol(); break; case Key::End: if( modKeys & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( modKeys & MODKEY_CTRL ) m_text.goEot(); else m_text.goEol(); break; default: break; } } // Let text object handle its actions. /* bool bChanged = m_text.onAction( action, button_key, globalGeo(), Coord(info.x, info.y) ); if( bChanged ) RequestRender(); */ // Swallow message depending on rules. if( pMsg->isMouseButtonMsg() && isSelectable() ) { if( MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) pMsg->swallow(); } else if( pMsg->isKeyMsg() && isEditable() ) { Key key = KeyMsg::cast(pMsg)->translatedKeyCode(); if( KeyMsg::cast(pMsg)->isMovementKey() == true || key == Key::Delete || key == Key::Backspace || key == Key::Return || (key == Key::Tab && m_bTabLock) ) pMsg->swallow(); //TODO: Would be good if we didn't forward any character-creating keys either... } else if( type == MsgType::TextInput ) pMsg->swallow(); }
void LineEditor::_receive( const Msg_p& pMsg ) { Widget::_receive(pMsg); MsgRouter_p pHandler = Base::msgRouter(); MsgType event = pMsg->type(); if( event == MsgType::Tick ) { if( _isSelectable() && m_state.isFocused() ) { m_text.incTime( TickMsg::cast(pMsg)->timediff() ); _requestRender(); //TODO: Should only render the cursor and selection! } return; } if( (event == MsgType::MousePress || event == MsgType::MouseDrag) && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) { MouseButtonMsg_p pButtonMsg = MouseButtonMsg::cast(pMsg); if( !m_state.isFocused() ) grabFocus(); if( m_state.isFocused() ) { if( _isSelectable() && (pButtonMsg->modKeys() & MODKEY_SHIFT) ) { m_text.setSelectionMode(true); } Coord ofs = pButtonMsg->pointerPos() - globalPos(); int x = ofs.x + m_viewOfs; int y = 0; if( m_bPasswordMode ) { TextAttr attr; m_text.getBaseAttr( attr ); Pen pen; pen.setAttributes( attr ); pen.setChar(m_pwGlyph); pen.advancePos(); int spacing = pen.getPosX(); int height = pen.getLineSpacing(); int line = y/height; int col = (x+spacing/2)/spacing; if(col < 0) { col = 0; line = 0; } m_text.gotoSoftPos(line,col); } else { m_text.cursorGotoCoord( Coord(x, 0), Rect(0,0,1000000,1000000) ); } if(_isSelectable() && event == MsgType::MousePress && !(pButtonMsg->modKeys() & MODKEY_SHIFT)) { m_text.clearSelection(); m_text.setSelectionMode(true); } } _adjustViewOfs(); } if( event == MsgType::MouseRelease ) { if( m_state.isFocused() && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) m_text.setSelectionMode(false); } if( event == MsgType::TextInput ) { String str = TextInputMsg::cast(pMsg)->text(); if( _isEditable() && m_state.isFocused() ) { if(m_text.hasSelection()) m_text.delSelection(); m_text.setSelectionMode(false); bool bModified = false; for( int i = 0 ; i < str.length() ; i++ ) { unsigned short ch = str.chars()[i].getGlyph(); if( ch >= 32 && ch != 127 ) { if( m_text.putChar( ch ) ) bModified = true; } } if( bModified ) { if( pHandler ) pHandler->post( new TextEditMsg(text.ptr(),false) ); _adjustViewOfs(); } } } if( event == MsgType::KeyRelease && m_state.isFocused() ) { Key key = KeyMsg::cast(pMsg)->translatedKeyCode(); switch( key ) { case Key::Shift: if(!Base::inputHandler()->isButtonPressed(MouseButton::Left)) m_text.setSelectionMode(false); break; } } if( (event == MsgType::KeyPress || event == MsgType::KeyRepeat) && _isEditable() && m_state.isFocused() ) { KeyMsg_p pKeyMsg = KeyMsg::cast(pMsg); Key key = pKeyMsg->translatedKeyCode(); switch( key ) { case Key::Left: if( pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( pKeyMsg->modKeys() & MODKEY_CTRL ) { if( m_bPasswordMode ) m_text.goBol(); else m_text.gotoPrevWord(); } else { m_text.goLeft(); } break; case Key::Right: if( pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( pKeyMsg->modKeys() & MODKEY_CTRL ) { if( m_bPasswordMode ) m_text.goEol(); else m_text.gotoNextWord(); } else { m_text.goRight(); } break; case Key::Backspace: { if(m_text.hasSelection()) m_text.delSelection(); else if( (pKeyMsg->modKeys() & MODKEY_CTRL) && !m_bPasswordMode) m_text.delPrevWord(); else m_text.delPrevChar(); if( pHandler ) pHandler->post( new TextEditMsg(text.ptr(),false) ); break; } case Key::Delete: { if(m_text.hasSelection()) m_text.delSelection(); else if( (pKeyMsg->modKeys() & MODKEY_CTRL) && !m_bPasswordMode) m_text.delNextWord(); else m_text.delNextChar(); if( pHandler ) pHandler->post( new TextEditMsg(text.ptr(),false) ); break; } case Key::Home: /* * I am not sure if this is the proper way to this, but in my opinion, the default * "actions" has to be separated from any modifier key action combination */ switch( pKeyMsg->modKeys() ) { case MODKEY_CTRL: break; default: // no modifier key was pressed if(pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.goBol(); break; } break; case Key::End: /* * I am not sure if this is the proper way to this, but in my opinion, the default * "actions" has to be separated from any modifier key action combination */ switch( pKeyMsg->modKeys() ) { case MODKEY_CTRL: break; default: // no modifier key was pressed if( pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.goEol(); break; } break; default: break; } _adjustViewOfs(); } // Swallow message depending on rules. if( pMsg->isMouseButtreceive() ) { if( MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) pMsg->swallow(); } else if( pMsg->isKeyMsg() ) { Key key = KeyMsg::cast(pMsg)->translatedKeyCode(); if( KeyMsg::cast(pMsg)->isMovementKey() == true || key == Key::Delete || key == Key::Backspace ) pMsg->swallow(); //TODO: Would be good if we didn't forward any character-creating keys either... } }
void MsgLogger::receive( const Msg_p& _pMsg ) { if( m_msgFilter[(int)_pMsg->type()] == false ) return; string source; string copyTo; char params[256]; params[0] = 0; // Msg specific parameters switch( _pMsg->type() ) { case MsgType::Dummy: break; case MsgType::Tick: sprintf( params, " millisec=%d", TickMsg::cast(_pMsg)->timediff() ); break; case MsgType::PointerChange: sprintf( params, " style=%s", _formatPointerStyle( PointerChangeMsg::cast(_pMsg)).c_str() ); break; case MsgType::MouseEnter: break; case MsgType::MouseMove: break; case MsgType::MouseLeave: break; case MsgType::MousePress: sprintf( params, " button=%s", _formatMouseButton(MousePressMsg::cast(_pMsg)->button()).c_str() ); break; case MsgType::MouseRepeat: sprintf( params, " button=%s", _formatMouseButton(MouseRepeatMsg::cast(_pMsg)->button()).c_str() ); break; case MsgType::MouseDrag: { MouseDragMsg_p pMsg = MouseDragMsg::cast(_pMsg); Coord now = pMsg->currPos(); Coord prev = pMsg->prevPos(); Coord start = pMsg->startPos(); Coord dragNow = pMsg->draggedNow(); Coord dragTotal=pMsg->draggedTotal(); sprintf( params, " button=%s position(start=%d,%d prev=%d,%d now=%d,%d) dragged(now=%d,%d total=%d,%d)", _formatMouseButton(pMsg->button()).c_str(), start.x, start.y, prev.x, prev.y, now.x, now.y, dragNow.x, dragNow.y, dragTotal.x, dragTotal.y ); break; } case MsgType::MouseRelease: { MouseReleaseMsg_p pMsg = MouseReleaseMsg::cast(_pMsg); const static char outside[] = "outside"; const static char inside[] = "inside"; const char * pPress = outside; const char * pRelease = outside; if( pMsg->releaseInside() ) pRelease = inside; sprintf( params, " button=%s release=%s", _formatMouseButton(pMsg->button()).c_str(), pRelease ); break; } case MsgType::MouseClick: sprintf( params, " button=%s", _formatMouseButton(MouseClickMsg::cast(_pMsg)->button()).c_str() ); break; case MsgType::MouseDoubleClick: sprintf( params, " button=%s", _formatMouseButton(MouseDoubleClickMsg::cast(_pMsg)->button()).c_str() ); break; case MsgType::KeyPress: { KeyPressMsg_p pMsg = KeyPressMsg::cast(_pMsg); sprintf( params, " wg_keycode=%d native_keycode=%d", pMsg->translatedKeyCode(), pMsg->nativeKeyCode() ); break; } case MsgType::KeyRepeat: { KeyRepeatMsg_p pMsg = KeyRepeatMsg::cast(_pMsg); sprintf( params, " wg_keycode=%d native_keycode=%d", pMsg->translatedKeyCode(), pMsg->nativeKeyCode() ); break; } case MsgType::KeyRelease: { KeyReleaseMsg_p pMsg = KeyReleaseMsg::cast(_pMsg); sprintf( params, " wg_keycode=%d native_keycode=%d", pMsg->translatedKeyCode(), pMsg->nativeKeyCode() ); break; } case MsgType::TextInput: sprintf( params, " chars=%s", TextInputMsg::cast(_pMsg)->text().chars() ); break; case MsgType::EditCommand: sprintf( params, " cmd=%s", _formatEditCommand(EditCommandMsg::cast(_pMsg)->command()).c_str() ); break; case MsgType::WheelRoll: { WheelRollMsg_p pMsg = WheelRollMsg::cast(_pMsg); sprintf( params, "wheel=%d distance=(%d,%d)", pMsg->wheel(), pMsg->distance().x, pMsg->distance().y ); break; } case MsgType::Select: break; case MsgType::Toggle: sprintf( params, " set=%d", (int) (ToggleMsg::cast(_pMsg)->isSet()) ); break; case MsgType::ValueUpdate: { ValueUpdateMsg_p pMsg = ValueUpdateMsg::cast(_pMsg); sprintf( params, " value=%ld fraction=%f", pMsg->value(), pMsg->fraction() ); break; } case MsgType::RangeUpdate: { RangeUpdateMsg_p pMsg = RangeUpdateMsg::cast(_pMsg); sprintf( params, " offset=%d length=%d fracOfs=%f fracLen=%f final=%s", pMsg->offset(), pMsg->length(), pMsg->fracOffset(), pMsg->fracLength(), pMsg->isFinal()?"true":"false" ); break; } case MsgType::TextEdit: { TextEditMsg_p pMsg = TextEditMsg::cast(_pMsg); break; } case MsgType::ItemToggle: { ItemToggleMsg_p pMsg = ItemToggleMsg::cast(_pMsg); sprintf( params, " set=%s id=%d object=%p", pMsg->isSet()?"true":"false", pMsg->itemId(), pMsg->itemObject().rawPtr() ); break; } case MsgType::ItemMousePress: { ItemMousePressMsg_p pMsg = ItemMousePressMsg::cast(_pMsg); sprintf( params, " id=%d mouseButton=%s", pMsg->itemId(), _formatMouseButton(pMsg->button()).c_str() ); break; } case MsgType::ItemsSelect: { ItemsSelectMsg_p pMsg = ItemsSelectMsg::cast(_pMsg); sprintf( params, " nbItems=%d", pMsg->nbItems() ); break; } case MsgType::ItemsUnselect: { ItemsUnselectMsg_p pMsg = ItemsUnselectMsg::cast(_pMsg); sprintf( params, " nbItems=%d", pMsg->nbItems() ); break; } case MsgType::LinkMouseEnter: case MsgType::LinkMouseLeave: case MsgType::LinkSelect: { LinkMsg_p pMsg = LinkMsg::cast(_pMsg); sprintf( params, " link=%p string=\"%s\"", pMsg->link().rawPtr(), pMsg->link()->link().c_str() ); break; } case MsgType::LinkMousePress: case MsgType::LinkMouseRepeat: case MsgType::LinkMouseRelease: case MsgType::LinkMouseClick: case MsgType::LinkMouseDoubleClick: { LinkMouseButtonMsg_p pMsg = LinkMouseButtonMsg::cast(_pMsg); sprintf( params, " link=%p button=%s", pMsg->link().rawPtr(), _formatMouseButton(pMsg->button()).c_str() ); break; } case MsgType::ModalMoveOutside: break; case MsgType::ModalBlockedPress: sprintf( params, " button=%s", _formatMouseButton(ModalBlockedPressMsg::cast(_pMsg)->button()).c_str() ); break; case MsgType::ModalBlockedRelease: sprintf( params, " button=%s", _formatMouseButton(ModalBlockedReleaseMsg::cast(_pMsg)->button()).c_str() ); break; default: break; }; source = _formatSource( _pMsg ); copyTo = _formatCopyTo( _pMsg ); string timestamp; string modkeys; string pointerPos; if( _pMsg->isInstanceOf( InputMsg::CLASSNAME ) ) { InputMsg_p p = InputMsg::cast(_pMsg); timestamp = _formatTimestamp( p->timestamp() ); modkeys = _formatModkeys( p ); pointerPos = _formatPointerPos( p ); } m_out << " - " << _pMsg->className() << " - " << source << copyTo << pointerPos << modkeys << params; m_out << std::endl; }
void TestWidget::_receive( const Msg_p& pMsg ) { switch( pMsg->type() ) { case MsgType::Tick: { const TickMsg_p pTick = TickMsg::cast(pMsg); Rect area( 0,0, size() ); if( !m_bPointsInitialized ) { for( int i = 0 ; i < 2 ; i+=2 ) { Coord& c = m_coord[i]; c.x = 0; c.y = 0; c = m_coord[i+1]; c.x = 100000; c.y = 100000; } m_bPointsInitialized = true; } for( int i = 0 ; i < 2 ; i++ ) { Coord& c = m_coord[i]; if( c.x < area.x ) c.x = area.x; if( c.y < area.y ) c.y = area.y; if( c.x > area.x + area.w ) c.x = area.x + area.w; if( c.y > area.y + area.h ) c.y = area.y + area.h; if( (c.y == area.y) && (c.x < area.x + area.w) ) c.x++; else if( (c.x == area.x + area.w) && (c.y < area.y + area.h) ) c.y++; else if( (c.y == area.y + area.h) && (c.x > area.x) ) c.x--; else c.y--; } _requestRender(); } break; default: break; } }
void Button::_receive( const Msg_p& _pMsg ) { State state = m_state; MsgRouter_p pHandler = Base::msgRouter(); switch( _pMsg->type() ) { case MsgType::KeyPress: if( KeyPressMsg::cast(_pMsg)->translatedKeyCode() == Key::Return ) { m_bReturnPressed = true; _pMsg->swallow(); } break; case MsgType::KeyRepeat: if( KeyRepeatMsg::cast(_pMsg)->translatedKeyCode() == Key::Return ) _pMsg->swallow(); break; case MsgType::KeyRelease: if( KeyReleaseMsg::cast(_pMsg)->translatedKeyCode() == Key::Return ) { m_bReturnPressed = false; pHandler->post( new SelectMsg(this) ); _pMsg->swallow(); } break; case MsgType::MouseEnter: state.setHovered(true); break; case MsgType::MouseLeave: state.setHovered(false); break; case MsgType::MousePress: if( MousePressMsg::cast(_pMsg)->button() == MouseButton::Left ) { m_bPressed = true; _pMsg->swallow(); } break; case MsgType::MouseRelease: if( MouseReleaseMsg::cast(_pMsg)->button() == MouseButton::Left ) { m_bPressed = false; _pMsg->swallow(); } break; case MsgType::MouseClick: if( MouseClickMsg::cast(_pMsg)->button() == MouseButton::Left ) { pHandler->post( new SelectMsg(this) ); _pMsg->swallow(); } break; case MsgType::MouseDoubleClick: case MsgType::MouseRepeat: case MsgType::MouseDrag: if( MouseButtonMsg::cast(_pMsg)->button() == MouseButton::Left ) _pMsg->swallow(); break; case MsgType::FocusGained: state.setFocused(true); break; case MsgType::FocusLost: state.setFocused(false); m_bReturnPressed = false; m_bPressed = false; break; default: break; } if( m_bReturnPressed || (m_bPressed && (m_bDownOutside || state.isHovered() )) ) state.setPressed(true); else state.setPressed(false); if( state != m_state ) _setState(state); }