void WgMenubar::_menuClosed( WgMenuBarItem * pItem ) { m_selectedItem = 0; _requestRender(); }
void FpsDisplay::_onFieldResize( Field * pField ) { _requestResize(); _requestRender(); }
void WgTablist::SetTabExpandMode( TabExpandMode mode ) { m_tabExpandMode = mode; _resizeTabs(); _requestRender(); }
void LineEditor::_requestRender( Item * pItem ) { _requestRender(); }
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; } }
bool WgTablePanel::SortRows( int column, bool bAscend, int prio ) { if( column >= m_nColumns || prio > c_nSortColumns ) return false; int i = 0; while( i < c_nSortColumns-1 ) { if( m_sortStack[i].column == column ) break; i++; } while( i > prio ) { m_sortStack[i] = m_sortStack[i-1]; i--; } m_sortStack[i].column = column; m_sortStack[i].bAscend = bAscend; if( prio == m_clickSortPrio ) { m_lastSortColumn = column; m_lastSortColumnAscendStatus = bAscend; } // From old SortItems()... WgTableRow * pRow = m_rows.First(); int nRows = 1; while( pRow ) { WgTableRow * pNext = pRow->Next(); if( nRows >= 2 ) { WgTableRow* pFirst = m_rows.First(); WgTableRow* pLast = pRow; bool bFirst = false; if( CompareRows( pRow, pFirst ) < 0 ) bFirst = true; if( !m_bSortAscend ) bFirst = !bFirst; if( bFirst ) m_rows.PushFront( pRow ); else pRow->_moveBefore(_findRowInsertSpot( pFirst, pLast, pRow, m_nRows )); } nRows++; pRow = pNext; } _requestRender(); return true; }
bool WgPopupHook::_updateGeo() { // Get size of parent and correct launcherGeo WgRect parentSize = m_pParent->Size(); // WgRect geo(0,0,WgSize::Min(_widget()->PreferredSize(),WgSize::Min(m_maxSize,parentSize))); switch( m_attachPoint ) { case WG_NORTHEAST: // Right side of launcherGeo, going down. { geo.x = m_launcherGeo.Right(); geo.y = m_launcherGeo.Top(); break; } case WG_SOUTHEAST: // Right side of launcherGeo, going up. { geo.x = m_launcherGeo.Right(); geo.y = m_launcherGeo.Bottom() - geo.h; break; } case WG_NORTHWEST: // Left-aligned above launcher. { geo.x = m_launcherGeo.Left(); geo.y = m_launcherGeo.Top() - geo.h; break; } case WG_SOUTHWEST: // Left-aligned below launcher. { geo.x = m_launcherGeo.Left(); geo.y = m_launcherGeo.Bottom(); break; } case WG_EAST: // Centered left of launcherGeo. { geo.x = m_launcherGeo.Left() - geo.w; geo.y = m_launcherGeo.Top() + m_launcherGeo.h/2 - geo.h/2; break; } case WG_NORTH: // Centered above launcherGeo. { geo.x = m_launcherGeo.Left() + m_launcherGeo.w/2 + geo.w/2; geo.y = m_launcherGeo.Top() - geo.h; break; } case WG_WEST: // Centered right of launcherGeo. { geo.x = m_launcherGeo.Right(); geo.y = m_launcherGeo.Top() + m_launcherGeo.h/2 - geo.h/2; break; } case WG_SOUTH: // Centered below launcherGeo. { geo.x = m_launcherGeo.Left() + m_launcherGeo.w/2 + geo.w/2; geo.y = m_launcherGeo.Bottom(); break; } } // Adjust geometry to fit inside parent. if( geo.Right() > parentSize.w ) { if( geo.Left() == m_launcherGeo.Right() ) { if( m_launcherGeo.Left() > parentSize.w - m_launcherGeo.Right() ) { geo.x = m_launcherGeo.Left() - geo.w; if( geo.x < 0 ) { geo.x = 0; geo.w = m_launcherGeo.Left(); } } else geo.w = parentSize.w - geo.x; } else geo.x = parentSize.w - geo.w; } if( geo.Left() < 0 ) { if( geo.Right() == m_launcherGeo.Left() ) { if( m_launcherGeo.Left() < parentSize.w - m_launcherGeo.Right() ) { geo.x = m_launcherGeo.Right(); if( geo.Right() > parentSize.w ) geo.w = parentSize.w - geo.x; } else { geo.x = 0; geo.w = m_launcherGeo.Left(); } } else geo.x = 0; } if( geo.Bottom() > parentSize.h ) { if( geo.Top() == m_launcherGeo.Bottom() ) { if( m_launcherGeo.Top() > parentSize.h - m_launcherGeo.Bottom() ) { geo.y = m_launcherGeo.Top() - geo.h; if( geo.y < 0 ) { geo.y = 0; geo.h = m_launcherGeo.Top(); } } else geo.h = parentSize.h - geo.y; } else geo.y = parentSize.h - geo.h; } if( geo.Top() < 0 ) { if( geo.Bottom() == m_launcherGeo.Top() ) { if( m_launcherGeo.Top() < parentSize.h - m_launcherGeo.Bottom() ) { geo.y = m_launcherGeo.Bottom(); if( geo.Bottom() > parentSize.h ) geo.h = parentSize.h - geo.y; } else { geo.y = 0; geo.h = m_launcherGeo.Bottom(); } } else geo.y = 0; } // Update geometry if it has changed. if( geo != m_geo ) { _requestRender(); m_geo = geo; _requestRender(); return true; } else return false; }
void WgStackPanel::_onWidgetsReordered() { _requestRender(); }
void WgStackPanel::_refreshAllWidgets() { _refreshPreferredSize(); _adaptChildrenToSize(); _requestRender(); }
void WgMenu::_itemModified() { _adjustSize(); _requestRender(); }
void WgMenu::_onEvent( const WgEventPtr& pEvent, WgEventHandler * pHandler ) { // TODO: Not handle or swallow key-events if some modifier keys are pressed. WgCoord mousePos = pEvent->PointerPos(); switch( pEvent->Type() ) { case WG_EVENT_TICK: { if( m_selectorCountdown > 0 ) { WgTickEventPtr pTick = WgTickEvent::Cast(pEvent); m_selectorCountdown -= pTick->Millisec(); if( m_selectorCountdown < 0 ) { m_selectorCountdown = 0; m_nSelectorKeys = 0; } } return; } case WG_EVENT_MOUSE_LEAVE: { // Unmark any selected item unless it is a submenu... WgMenuItem * pOldItem = m_items.Get(m_markedItem-1); if( pOldItem && pOldItem->GetType() != SUBMENU ) { m_markedItem = 0; _requestRender(); } } break; case WG_EVENT_MOUSE_ENTER: case WG_EVENT_MOUSE_MOVE: { WgMenuItem * pItem = _getItemAtPos( mousePos.x, mousePos.y ); Uint32 markedItem = 0; if( pItem ) { if( pItem->GetType() != SEPARATOR ) { if( ((WgMenuEntry*)pItem)->IsEnabled() ) markedItem = pItem->Index()+1; } } if( m_markedItem != markedItem ) { // Mark and request render m_markedItem = markedItem; _requestRender(); // Open/close submenus depending on what item we have marked. if( pItem && pItem->GetType() == SUBMENU ) { WgMenuSubMenu * pSubMenu = (WgMenuSubMenu*) pItem; if( pSubMenu != m_pOpenSubMenu ) { if( m_pOpenSubMenu ) _closeSubMenu( m_pOpenSubMenu ); _openSubMenu( pSubMenu ); } } else if( m_pOpenSubMenu ) { _closeSubMenu( m_pOpenSubMenu ); } } } break; case WG_EVENT_MOUSE_RELEASE: { WgMenuItem * pItem = _getItemAtPos( mousePos.x, mousePos.y ); if( pItem ) SelectItem(pItem); } break; case WG_EVENT_WHEEL_ROLL: { WgWheelRollEventPtr pEv = WgWheelRollEvent::Cast(pEvent); if( pEv->Wheel() == 1 ) { int distance = pEv->Distance(); _setViewOfs( m_contentOfs - m_entryHeight*distance ); _updateScrollbar( _getHandlePosition(), _getHandleSize() ); } } case WG_EVENT_CHARACTER: { Uint16 chr = WgCharacterEvent::Cast(pEvent)->Char(); if( chr != 0 ) { m_selectorCountdown = c_selectorCountdownStart; if( m_nSelectorKeys < c_maxSelectorKeys ) { m_selectorKeys[m_nSelectorKeys++] = towlower( chr ); _markFirstFilteredEntry(); } } } break; case WG_EVENT_KEY_PRESS: case WG_EVENT_KEY_REPEAT: { WgMenuItem * pItem = 0; if( m_markedItem != 0 ) pItem = m_items.Get( m_markedItem-1 ); int key = WgKeyEvent::Cast(pEvent)->TranslatedKeyCode(); switch( key ) { case WG_KEY_ESCAPE: if( m_pOpenSubMenu ) { _closeSubMenu( m_pOpenSubMenu ); } break; case WG_KEY_LEFT: if( m_pOpenSubMenu ) { _closeSubMenu( m_pOpenSubMenu ); } break; case WG_KEY_RIGHT: if( pItem ) { if( pItem->GetType() == SUBMENU ) { _openSubMenu( (WgMenuSubMenu*) pItem ); } } break; case WG_KEY_RETURN: if( pItem ) { if( pItem->GetType() == SUBMENU ) _openSubMenu( (WgMenuSubMenu*) pItem ); else { SelectItem(pItem); pItem = 0; // So we won't mark an item in the closed menu. } } break; case WG_KEY_UP: if( pItem ) { pItem = pItem->Prev(); while( pItem != 0 && (pItem->GetType() == SEPARATOR || !pItem->IsVisible() ) ) pItem = pItem->Prev(); } break; case WG_KEY_DOWN: if( pItem ) pItem = pItem->Next(); else pItem = m_items.First(); while( pItem != 0 && (pItem->GetType() == SEPARATOR || !pItem->IsVisible() ) ) pItem = pItem->Next(); break; case WG_KEY_HOME: pItem = m_items.First(); while( pItem != 0 && (pItem->GetType() == SEPARATOR || !pItem->IsVisible() ) ) pItem = pItem->Next(); break; case WG_KEY_END: pItem = m_items.Last(); while( pItem != 0 && (pItem->GetType() == SEPARATOR || !pItem->IsVisible() )) pItem = pItem->Prev(); break; case WG_KEY_PAGE_UP: { int viewHeight = _getViewSize(); int distance = m_entryHeight; while( pItem != 0 && distance < viewHeight ) { if( pItem->IsVisible() ) { if( pItem->GetType() == SEPARATOR ) distance += m_sepHeight; else distance += m_entryHeight; } pItem = pItem->Prev(); } if( !pItem ) { pItem = m_items.First(); while( pItem != 0 && (pItem->GetType() == SEPARATOR || !pItem->IsVisible() )) pItem = pItem->Next(); } break; } case WG_KEY_PAGE_DOWN: { int viewHeight = _getViewSize(); int distance = m_entryHeight; while( pItem != 0 && distance < viewHeight ) { if( pItem->IsVisible() ) { if( pItem->GetType() == SEPARATOR ) distance += m_sepHeight; else distance += m_entryHeight; } pItem = pItem->Next(); } if( !pItem ) { pItem = m_items.Last(); while( pItem != 0 && (pItem->GetType() == SEPARATOR || !pItem->IsVisible() )) pItem = pItem->Next(); } break; } } if( pItem ) { Uint32 markedItem = pItem->Index()+1; if( markedItem != m_markedItem ) { m_markedItem = markedItem; _scrollItemIntoView(pItem); _requestRender(); } } } break; default: break; } // Forward event depending on rules. if( pEvent->IsMouseButtonEvent() && WgMouseButtonEvent::Cast(pEvent)->Button() == WG_BUTTON_LEFT ) pHandler->SwallowEvent(pEvent); else if( pEvent->IsKeyEvent() ) { int key = WgKeyEvent::Cast(pEvent)->TranslatedKeyCode(); if( key == WG_KEY_RIGHT || key == WG_KEY_RETURN || key == WG_KEY_UP || key == WG_KEY_DOWN && key == WG_KEY_HOME || key == WG_KEY_END || key == WG_KEY_PAGE_UP || key == WG_KEY_PAGE_DOWN && key == WG_KEY_ESCAPE || key == WG_KEY_LEFT ) pHandler->SwallowEvent(pEvent); } else if( pEvent->Type() == WG_EVENT_CHARACTER || pEvent->Type() == WG_EVENT_WHEEL_ROLL ) pHandler->SwallowEvent(pEvent); }
void WgPackList::_onRequestRender( WgPackListHook * pHook ) { WgRect geo; _getChildGeo(geo, pHook); _requestRender(geo); }
void WgPackList::_onEvent( const WgEventPtr& _pEvent, WgEventHandler * pHandler ) { WgState oldState = m_state; switch( _pEvent->Type() ) { case WG_EVENT_MOUSE_MOVE: { WgMouseMoveEventPtr pEvent = WgMouseMoveEvent::Cast(_pEvent); WgCoord ofs = ToLocal(pEvent->PointerGlobalPos()); WgRect headerGeo = _headerGeo(); bool bHeaderHovered = headerGeo.Contains(ofs) && (!pHandler->IsAnyMouseButtonPressed() || (pHandler->IsMouseButtonPressed(WG_BUTTON_LEFT) && m_header.m_bPressed)); if( bHeaderHovered != m_header.m_state.IsHovered() ) { m_header.m_state.SetHovered(bHeaderHovered); _requestRender( headerGeo ); } WgList::_onEvent( _pEvent, pHandler ); break; } case WG_EVENT_MOUSE_LEAVE: { WgMouseLeaveEventPtr pEvent = WgMouseLeaveEvent::Cast(_pEvent); if( pEvent->Widget() == this && m_header.m_state.IsHovered() ) { m_header.m_state.SetPressed(false); m_header.m_state.SetHovered(false); _requestRender( _headerGeo() ); } WgList::_onEvent( _pEvent, pHandler ); break; } case WG_EVENT_MOUSE_PRESS: { WgMousePressEventPtr pEvent = WgMousePressEvent::Cast(_pEvent); WgCoord ofs = ToLocal(pEvent->PointerGlobalPos()); WgRect headerGeo = _headerGeo(); if(pEvent->Button() == WG_BUTTON_LEFT && headerGeo.Contains(ofs)) { m_header.m_bPressed = true; m_header.m_state.SetPressed(true); _requestRender( headerGeo ); pHandler->SwallowEvent( pEvent ); } else WgList::_onEvent( _pEvent, pHandler ); break; } case WG_EVENT_MOUSE_DRAG: { WgMouseDragEventPtr pEvent = WgMouseDragEvent::Cast(_pEvent); if( m_header.m_bPressed ) { WgCoord ofs = ToLocal(pEvent->PointerGlobalPos()); WgRect headerGeo = _headerGeo(); bool bHeaderHovered = headerGeo.Contains(ofs); if( bHeaderHovered != m_header.m_state.IsHovered() ) { m_header.m_state.SetHovered(bHeaderHovered); m_header.m_state.SetPressed(bHeaderHovered); _requestRender( headerGeo ); } pHandler->SwallowEvent(pEvent); } else WgList::_onEvent( _pEvent, pHandler ); break; } case WG_EVENT_MOUSE_RELEASE: { WgMouseReleaseEventPtr pEvent = WgMouseReleaseEvent::Cast(_pEvent); if(pEvent->Button() == WG_BUTTON_LEFT && m_header.m_bPressed ) { m_header.m_bPressed = false; m_header.m_state.SetPressed(false); WgRect headerGeo = _headerGeo(); _requestRender( headerGeo ); WgCoord ofs = ToLocal(pEvent->PointerGlobalPos()); if( headerGeo.Contains(ofs) ) { if( m_sortOrder == WG_SORT_ASCENDING ) m_sortOrder = WG_SORT_DESCENDING; else m_sortOrder = WG_SORT_ASCENDING; _sortEntries(); } pHandler->SwallowEvent(pEvent); } else WgList::_onEvent( _pEvent, pHandler ); break; } case WG_EVENT_KEY_PRESS: { if( m_selectMode == WG_SELECT_NONE ) break; int keyCode = WgKeyPressEvent::Cast(_pEvent)->TranslatedKeyCode(); WgModifierKeys modKeys = WgKeyPressEvent::Cast(_pEvent)->ModKeys(); if( (m_bHorizontal && (keyCode == WG_KEY_LEFT || keyCode == WG_KEY_RIGHT)) || (!m_bHorizontal && (keyCode == WG_KEY_UP || keyCode == WG_KEY_DOWN || keyCode == WG_KEY_PAGE_UP || keyCode == WG_KEY_PAGE_DOWN)) || keyCode == WG_KEY_HOME || keyCode == WG_KEY_END || (m_selectMode == WG_SELECT_FLIP && keyCode == WG_KEY_SPACE ) ) pHandler->SwallowEvent(_pEvent); WgList::_onEvent( _pEvent, pHandler ); break; } case WG_EVENT_KEY_REPEAT: case WG_EVENT_KEY_RELEASE: { if( m_selectMode == WG_SELECT_NONE ) break; int keyCode = WgKeyEvent::Cast(_pEvent)->TranslatedKeyCode(); WgModifierKeys modKeys = WgKeyEvent::Cast(_pEvent)->ModKeys(); if( (m_bHorizontal && (keyCode == WG_KEY_LEFT || keyCode == WG_KEY_RIGHT)) || (!m_bHorizontal && (keyCode == WG_KEY_UP || keyCode == WG_KEY_DOWN || keyCode == WG_KEY_PAGE_UP || keyCode == WG_KEY_PAGE_DOWN)) || keyCode == WG_KEY_HOME || keyCode == WG_KEY_END || (m_selectMode == WG_SELECT_FLIP && keyCode == WG_KEY_SPACE ) ) pHandler->SwallowEvent(_pEvent); WgList::_onEvent( _pEvent, pHandler ); break; } default: WgList::_onEvent(_pEvent, pHandler); return; } if( m_state != oldState ) _onStateChanged(oldState); }
void WgSimpleVolumeMeter::_onNewSize( const WgSize& size ) { _updateSectionPixelHeight(); _requestRender(); }
void LegacyTextEditor::_onFieldDirty( Field * pField, const Rect& rect ) { _requestRender(); }
bool SplitPanel::_updateGeo(int handleMovement) { Rect geo = m_size; Rect contentGeo = m_pSkin ? m_pSkin->contentRect(geo, m_state) : geo; Rect firstChildGeo; Rect secondChildGeo; Rect handleGeo; // Calculate new lengths using broker int handleThickness = _handleThickness(); int totalLength = (m_bHorizontal ? contentGeo.w : contentGeo.h) - handleThickness; int firstChildLength; int secondChildLength; if (m_brokerFunc) firstChildLength = m_brokerFunc(m_firstChild.pWidget, m_secondChild.pWidget, totalLength, m_splitFactor, handleMovement); else firstChildLength = _defaultBroker(m_firstChild.pWidget, m_secondChild.pWidget, totalLength, m_splitFactor, handleMovement); secondChildLength = totalLength - firstChildLength; // Update lengthFraction if we had handle movement if (handleMovement ) m_splitFactor = (firstChildLength+0.5f) / totalLength; // Update geo rectangles if( m_bHorizontal ) { firstChildGeo = Rect(contentGeo.x, contentGeo.y, firstChildLength, contentGeo.h); secondChildGeo = Rect(contentGeo.x + contentGeo.w - secondChildLength, contentGeo.y, secondChildLength, contentGeo.h); handleGeo = Rect(contentGeo.x + firstChildLength, contentGeo.y, handleThickness, contentGeo.h ); } else { firstChildGeo = Rect(contentGeo.x, contentGeo.y, contentGeo.w, firstChildLength); secondChildGeo = Rect(contentGeo.x, contentGeo.y + contentGeo.h - secondChildLength, contentGeo.w, secondChildLength); handleGeo = Rect(contentGeo.x, contentGeo.y + firstChildLength, contentGeo.w, handleThickness); } // Request render and set sizes if (handleGeo != m_handleGeo || firstChildGeo != m_firstChild.geo || secondChildGeo != m_secondChild.geo) { _requestRender(contentGeo); m_firstChild.geo = firstChildGeo; if( m_firstChild.pWidget ) m_firstChild.pWidget->_setSize(firstChildGeo); m_secondChild.geo = secondChildGeo; if (m_secondChild.pWidget) m_secondChild.pWidget->_setSize(secondChildGeo); m_handleGeo = handleGeo; return true; } return false; }
void LegacyTextEditor::_onFieldResize( Field * pField ) { m_bResetCursorOnFocus = true; _requestResize(); _requestRender(); }
void SplitPanel::_refresh() { _updateGeo(); _requestRender(); }
bool WgTablePanel::SetHeaderTextprop( const WgTextpropPtr& pProp ) { m_pHeaderProps = pProp; _requestRender(); return true; }
void SplitPanel::_receive(Msg * pMsg) { //TODO: Implement!!! State handleState = m_handleState; switch (pMsg->type()) { case MsgType::MouseEnter: case MsgType::MouseMove: { if (m_handleState.isPressed()) return; Coord pos = InputMsg::cast(pMsg)->pointerPos() - globalPos(); bool bHovered = m_handleGeo.contains(pos); handleState.setHovered(bHovered); break; } case MsgType::MouseLeave: { // Unhover handle unless it is pressed if (!handleState.isPressed()) handleState.setHovered(false); break; } case MsgType::MousePress: { auto p = MouseButtonMsg::cast(pMsg); if (p->button() != MouseButton::Left) return; Coord pos = p->pointerPos() - globalPos(); if (m_handleGeo.contains(pos)) { m_handlePressOfs = m_bHorizontal ? pos.x - m_handleGeo.x : pos.y - m_handleGeo.y; handleState.setPressed(true); pMsg->swallow(); } break; } case MsgType::MouseRelease: { auto p = MouseButtonMsg::cast(pMsg); if (p->button() != MouseButton::Left) return; if (handleState.isPressed() ) { handleState.setPressed(false); pMsg->swallow(); } break; } case MsgType::MouseDrag: { auto p = MouseButtonMsg::cast(pMsg); if (p->button() != MouseButton::Left) return; if (handleState.isPressed()) { Coord pos = p->pointerPos() - globalPos(); int diff = (m_bHorizontal ? pos.x - m_handleGeo.x : pos.y - m_handleGeo.y) - m_handlePressOfs; _updateGeo(diff); pMsg->swallow(); } break; } default: break; } if (handleState != m_handleState && m_pHandleSkin) { if (!m_pHandleSkin->isStateIdentical(handleState, m_handleState)) _requestRender(m_handleGeo); m_handleState = handleState; } }
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 SplitPanel::_childRequestRender(Slot * pSlot) { _requestRender(static_cast<SplitPanelSlot*>(pSlot)->geo); }
void LineEditor::_requestRender( Item * pItem, const Rect& rect ) { _requestRender(); }
void SplitPanel::_childRequestRender(Slot * pSlot, const Rect& rect) { _requestRender(rect + static_cast<SplitPanelSlot*>(pSlot)->geo.pos()); }
void FpsDisplay::_onFieldDirty( Field * pField ) { _requestRender(); }
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 WgTablist::_onEvent( const WgEventPtr& _pEvent, WgEventHandler * pHandler ) { WgWidget::_onEvent(_pEvent,pHandler); switch( _pEvent->Type() ) { case WG_EVENT_TICK: { WgTickEventPtr pEvent = WgTickEvent::Cast(_pEvent); m_alertModeCnt -= pEvent->Millisec(); if( m_alertModeCnt <= 0 ) { m_bAlertOn = !m_bAlertOn; m_alertModeCnt = m_alertRate; // This is right, we want it to stay in the new mode at least one frame. // Check if we have to render something... WgTab * pTab = m_tabs.First(); while( pTab ) { if( pTab->m_bAlert && pTab->m_bVisible ) { _requestRender(); // Somewhat stupid to render all tabs though... break; } pTab = pTab->Next(); } } break; } case WG_EVENT_MOUSE_PRESS: { WgMouseButtonEventPtr pEvent = WgMouseButtonEvent::Cast(_pEvent); WgCoord pos = pEvent->PointerPos(); WgTab * pTab = _pos2Tab( pos.x, pos.y ); if( pTab && pTab != m_pTabSelected ) { if( pEvent->Button() == WG_BUTTON_LEFT ) SelectTab(pTab->m_id); pHandler->QueueEvent( new WgItemMousePressEvent(this, pTab->m_id, WgObjectPtr(), pEvent->Button()) ); } } break; case WG_EVENT_MOUSE_ENTER: case WG_EVENT_MOUSE_MOVE: { WgCoord pos = _pEvent->PointerPos(); WgTab * pTab = _pos2Tab( pos.x, pos.y ); if( pTab != m_pTabMarked ) { m_pTabMarked = pTab; _requestRender(); } } break; case WG_EVENT_MOUSE_LEAVE: if( m_pTabMarked ) { m_pTabMarked = 0; _requestRender(); } break; default: break; } // Swallow event depending on rules. if( _pEvent->IsMouseButtonEvent() && WgMouseButtonEvent::Cast(_pEvent)->Button() == WG_BUTTON_LEFT ) pHandler->SwallowEvent(_pEvent); }
void LegacyTextEditor::_onFieldDirty( Field * pField ) { _requestRender(); }
void WgTablist::SetTabCompressMode( TabCompressMode mode ) { m_tabCompressMode = mode; _resizeTabs(); _requestRender(); }
void WgMenubar::_menuOpened( WgMenuBarItem * pItem ) { Uint32 item = pItem->Index()+1; m_selectedItem = item; _requestRender(); }