void Widget::SetState( State state ) { // Do nothing if state wouldn't change. if( GetState() == state ) { return; } auto old_state = GetState(); // Store the new state. m_state = state; auto emit_state_change = false; // If HandleStateChange() changed the state, do not call observer, will be // done from there too. if( GetState() != old_state ) { HandleStateChange( static_cast<State>( old_state ) ); emit_state_change = true; } if( state == State::ACTIVE ) { GrabFocus( shared_from_this() ); SetActiveWidget( shared_from_this() ); } else if( old_state == State::ACTIVE ) { SetActiveWidget( Ptr() ); } if( emit_state_change ) { GetSignals().Emit( OnStateChange ); } }
void Widget::SetState( State state ) { // Do nothing if state wouldn't change. if( GetState() == state ) { return; } unsigned char old_state( GetState() ); // Clear the state bits to 0s. m_bitfield &= static_cast<unsigned char>( 0xf1 ); // Store the new state. m_bitfield |= static_cast<unsigned char>( state << 1 ); // If HandleStateChange() changed the state, do not call observer, will be // done from there too. if( GetState() != old_state ) { HandleStateChange( static_cast<State>( old_state ) ); GetSignals().Emit( OnStateChange ); } if( state == ACTIVE ) { GrabFocus( shared_from_this() ); SetActiveWidget( shared_from_this() ); } else if( old_state == ACTIVE ) { SetActiveWidget( Ptr() ); } }
bool TextEntry::OnMouseDown(MouseButtonEvent *e) { m_clickout = RawEvents::onMouseDown.connect(sigc::mem_fun(this, &TextEntry::OnRawMouseDown)); GrabFocus(); m_justFocused = true; int i = Gui::Screen::PickCharacterInString(m_text, e->x - m_scroll, e->y, m_font); SetCursorPos(i); return false; }
TBool CapEopEntry::OnButtonPress(GdkEventButton* aEvent) { if (aEvent->button == 1) { if (aEvent->type == GDK_BUTTON_PRESS) { if (State() == GTK_STATE_ACTIVE) { SetState(GTK_STATE_NORMAL); SetEditable(ETrue); GrabFocus(); SelectRegion(0, GetTextLen()); } else { SetState(GTK_STATE_ACTIVE); } } } return EFalse; }
bool WgLineEditor::InsertCharAtCursor( Uint16 c ) { if( !_isEditable() ) return false; if( !m_state.IsFocused() ) if( !GrabFocus() ) return false; // Couldn't get input focus... if( !m_text.putChar( c ) ) return false; _queueEvent( new WgTextEditEvent(this,&text,false) ); _adjustViewOfs(); return true; }
int WgLineEditor::InsertTextAtCursor( const WgCharSeq& str ) { if( !_isEditable() ) return 0; if( !m_state.IsFocused() ) if( !GrabFocus() ) return 0; // Couldn't get input focus... int retVal = m_text.putText( str ); _queueEvent( new WgTextEditEvent(this,&text,false) ); _adjustViewOfs(); return retVal; }
void Widget::SetState( State state ) { // Do nothing if state wouldn't change. if( m_state == state ) { return; } State old_state( m_state ); m_state = state; // If HandleStateChange() changed the state, do not call observer, will be // done from there too. if( m_state != old_state ) { HandleStateChange( old_state ); OnStateChange(); } if( state == Active ) { GrabFocus( shared_from_this() ); } }
void Widget::GrabFocus() { GrabFocus( shared_from_this() ); }
extern Bool GetScreenData( NETFILE *fp) { char window[SIZE_NAME+1]; char widgetName[SIZE_LONGNAME+1]; PacketClass c; gboolean isdummy; unsigned char type; ENTER_FUNC; if (THISWINDOW(Session) != NULL) { g_free(THISWINDOW(Session)); } isdummy = FALSE; CheckScreens(fp,FALSE); GL_SendPacketClass(fp,GL_GetData); GL_SendInt(fp,0);/*get all data*/ if (fMlog) { MessageLog("===="); } while ((c = GL_RecvPacketClass(fp)) == GL_WindowName) { GL_RecvString(fp, sizeof(window), window); dbgprintf("[%s]\n",window); type = (unsigned char)GL_RecvInt(FPCOMM(Session)); if ( fMlog ) { switch (type) { case SCREEN_NEW_WINDOW: MessageLogPrintf("new window [%s]\n",window);break; case SCREEN_CHANGE_WINDOW: MessageLogPrintf("change window [%s]\n",window);break; case SCREEN_CURRENT_WINDOW: MessageLogPrintf("current window [%s]\n",window);break; case SCREEN_CLOSE_WINDOW: MessageLogPrintf("close window [%s]\n",window);break; case SCREEN_JOIN_WINDOW: MessageLogPrintf("join window [%s]\n",window);break; } } switch (type) { case SCREEN_NEW_WINDOW: case SCREEN_CHANGE_WINDOW: case SCREEN_CURRENT_WINDOW: if ((c = GL_RecvPacketClass(fp)) == GL_ScreenData) { THISWINDOW(Session) = strdup(window); RecvValue(fp,window); isdummy = window[0] == '_'; if (!isdummy) { ShowWindow(window); } UpdateWindow(window); ResetTimer(window); } if (type == SCREEN_CHANGE_WINDOW) { ResetScrolledWindow(window); } break; case SCREEN_CLOSE_WINDOW: CloseWindow(window); c = GL_RecvPacketClass(fp); break; default: CloseWindow(window); c = GL_RecvPacketClass(fp); break; } if ( c == GL_NOT ) { /* no screen data */ } else { /* fatal error */ } } if (c == GL_FocusName) { GL_RecvString(fp, sizeof(window), window); GL_RecvString(fp, sizeof(widgetName), widgetName); if (!isdummy) { GrabFocus(window, widgetName); } c = GL_RecvPacketClass(fp); } LEAVE_FUNC; return TRUE; }
void WgLineEditor::_onEvent( const WgEventPtr& pEvent, WgEventHandler * pHandler ) { WgWidget::_onEvent(pEvent,pHandler); WgEventType event = pEvent->Type(); if( event == WG_EVENT_TICK ) { if( _isSelectable() && m_state.IsFocused() ) { m_text.incTime( WgTickEvent::Cast(pEvent)->Millisec() ); _requestRender(); //TODO: Should only render the cursor and selection! } return; } if( (event == WG_EVENT_MOUSE_PRESS || event == WG_EVENT_MOUSE_DRAG) && WgMouseButtonEvent::Cast(pEvent)->Button() == WG_BUTTON_LEFT ) { if( !m_state.IsFocused() ) GrabFocus(); if( m_state.IsFocused() ) { if( _isSelectable() && (pEvent->ModKeys() & WG_MODKEY_SHIFT) ) { m_text.setSelectionMode(true); } WgCoord ofs = pEvent->PointerPos(); int x = ofs.x + m_viewOfs; int y = 0; if( m_bPasswordMode ) { WgTextAttr attr; m_text.GetBaseAttr( attr ); WgPen 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( WgCoord(x, 0), WgRect(0,0,1000000,1000000) ); } if(_isSelectable() && event == WG_EVENT_MOUSE_PRESS && !(pEvent->ModKeys() & WG_MODKEY_SHIFT)) { m_text.ClearSelection(); m_text.setSelectionMode(true); } } _adjustViewOfs(); } if( event == WG_EVENT_MOUSE_RELEASE ) { if( m_state.IsFocused() && WgMouseButtonEvent::Cast(pEvent)->Button() == WG_BUTTON_LEFT ) m_text.setSelectionMode(false); } if( event == WG_EVENT_CHARACTER ) { int ch = WgCharacterEvent::Cast(pEvent)->Char(); if( _isEditable() && m_state.IsFocused() && ch >= 32 && ch != 127) { if(m_text.hasSelection()) m_text.delSelection(); m_text.setSelectionMode(false); if( m_text.putChar( ch ) ) { if( pHandler ) pHandler->QueueEvent( new WgTextEditEvent(this,&text,false) ); _adjustViewOfs(); } } } if( event == WG_EVENT_KEY_RELEASE && m_state.IsFocused() ) { int key = WgKeyEvent::Cast(pEvent)->TranslatedKeyCode(); switch( key ) { case WG_KEY_SHIFT: if(!pHandler->IsMouseButtonPressed(1)) m_text.setSelectionMode(false); break; } } if( (event == WG_EVENT_KEY_PRESS || event == WG_EVENT_KEY_REPEAT) && _isEditable() && m_state.IsFocused() ) { int key = WgKeyEvent::Cast(pEvent)->TranslatedKeyCode(); switch( key ) { case WG_KEY_LEFT: if( pEvent->ModKeys() & WG_MODKEY_SHIFT ) m_text.setSelectionMode(true); if( pEvent->ModKeys() & WG_MODKEY_CTRL ) { if( m_bPasswordMode ) m_text.GoBOL(); else m_text.gotoPrevWord(); } else { m_text.goLeft(); } break; case WG_KEY_RIGHT: if( pEvent->ModKeys() & WG_MODKEY_SHIFT ) m_text.setSelectionMode(true); if( pEvent->ModKeys() & WG_MODKEY_CTRL ) { if( m_bPasswordMode ) m_text.GoEOL(); else m_text.gotoNextWord(); } else { m_text.goRight(); } break; case WG_KEY_BACKSPACE: { if(m_text.hasSelection()) m_text.delSelection(); else if( (pEvent->ModKeys() & WG_MODKEY_CTRL) && !m_bPasswordMode) m_text.delPrevWord(); else m_text.delPrevChar(); if( pHandler ) pHandler->QueueEvent( new WgTextEditEvent(this,&text,false) ); break; } case WG_KEY_DELETE: { if(m_text.hasSelection()) m_text.delSelection(); else if( (pEvent->ModKeys() & WG_MODKEY_CTRL) && !m_bPasswordMode) m_text.delNextWord(); else m_text.delNextChar(); if( pHandler ) pHandler->QueueEvent( new WgTextEditEvent(this,&text,false) ); break; } case WG_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( pEvent->ModKeys() ) { case WG_MODKEY_CTRL: break; default: // no modifier key was pressed if(pEvent->ModKeys() & WG_MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.GoBOL(); break; } break; case WG_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( pEvent->ModKeys() ) { case WG_MODKEY_CTRL: break; default: // no modifier key was pressed if( pEvent->ModKeys() & WG_MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.GoEOL(); break; } break; default: break; } _adjustViewOfs(); } // Forward event depending on rules. if( pEvent->IsMouseButtonEvent() ) { if( WgMouseButtonEvent::Cast(pEvent)->Button() == WG_BUTTON_LEFT ) pHandler->SwallowEvent(pEvent); } else if( pEvent->IsKeyEvent() ) { int key = WgKeyEvent::Cast(pEvent)->TranslatedKeyCode(); if( WgKeyEvent::Cast(pEvent)->IsMovementKey() == true || key == WG_KEY_DELETE || key == WG_KEY_BACKSPACE ) pHandler->SwallowEvent(pEvent); //TODO: Would be good if we didn't forward any character-creating keys either... } }