コード例 #1
0
void KrEventManager::RemoveListener( KrWidget* widget )
{
    int i = keyListeners.Find( widget ); //maks
    if ( i >= 0 && i == keyFocus) //maks: Only remove the focus if the widget has the focus (solve focus bug in Math for Kids.ged)
    {
        keyFocus = -1;
        FocusState(false);
    }

    keyListeners.FindAndDelete( widget );
    mouseListeners.FindAndDelete( widget );
    selectListeners.FindAndDelete( widget );

    for( i=0; i<accelListeners.Count(); ++i )
    {
        if ( accelListeners[i].target == widget )
        {
            accelListeners.Remove( i );
            //break; //maks
        }
    }

    if ( mouseFocus == widget )
    {
        mouseFocus = 0;
    }
}
コード例 #2
0
NS_IMETHODIMP
nsHTMLTextAreaElement::Select()
{
  // XXX Bug?  We have to give the input focus before contents can be
  // selected

  FocusTristate state = FocusState();
  if (state == eUnfocusable) {
    return NS_OK;
  }

  nsIFocusManager* fm = nsFocusManager::GetFocusManager();

  nsCOMPtr<nsPresContext> presContext = GetPresContext();
  if (state == eInactiveWindow) {
    if (fm)
      fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
    SelectAll(presContext);
    return NS_OK;
  }

  nsEventStatus status = nsEventStatus_eIgnore;
  nsGUIEvent event(PR_TRUE, NS_FORM_SELECTED, nsnull);
  // XXXbz nsHTMLInputElement guards against this reentering; shouldn't we?
  nsEventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
                              &event, nsnull, &status);

  // If the DOM event was not canceled (e.g. by a JS event handler
  // returning false)
  if (status == nsEventStatus_eIgnore) {
    if (fm) {
      fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);

      // ensure that the element is actually focused
      nsCOMPtr<nsIDOMElement> focusedElement;
      fm->GetFocusedElement(getter_AddRefs(focusedElement));
      if (SameCOMIdentity(static_cast<nsIDOMNode*>(this), focusedElement)) {
        // Now Select all the text!
        SelectAll(presContext);
      }
    }
  }

  return NS_OK;
}
コード例 #3
0
void KrEventManager::ChangeKeyFocus( int newFocus )
{
    if ( newFocus >= (int) keyListeners.Count() )
        newFocus -= (int) keyListeners.Count();

    if ( keyListeners.Count() > 0 )
    {
        if ( newFocus != keyFocus )
        {
            if ( GlInRange( keyFocus, (int) 0, int( keyListeners.Count() - 1 ) ) )
                keyListeners[ keyFocus ]->KeyFocus( false );
            if ( GlInRange( newFocus, (int) 0, int( keyListeners.Count() - 1 ) ) )
                keyListeners[ newFocus ]->KeyFocus( true );
            keyFocus = newFocus;
            newListnerFocus = true; //maks
        }
    }
    else
    {
        keyFocus = -1;
    }

    FocusState(keyFocus != -1);
}
コード例 #4
0
void KrEventManager::HandleEvent( const SDL_Event& event, KrEngine* engine )
{
    if ( event.type == SDL_KEYDOWN && keyFocus >= 0) //maks
    {
        //	- the tab key changes key focus.
        //	- accelerators are checked
        //	- keys passed through to the handler.

#ifdef DEBUG
        GLOUTPUT( "KeyDown mod=%d sym=%d, unicode=%d, name=%s\n", event.key.keysym.mod, event.key.keysym.sym, event.key.keysym.unicode, SDL_GetKeyName(event.key.keysym.sym)); //maks
#endif

        if (    event.key.keysym.sym == SDLK_TAB
                && keyListeners.Count() > 1 )
        {
            if ( event.key.keysym.mod & KMOD_SHIFT )
                ChangeKeyFocus( keyFocus + keyListeners.Count() - 1 );
            else
                ChangeKeyFocus( keyFocus + 1 );
            return;
        }

        for( int i=0; i<accelListeners.Count(); ++i )
        {
            int sym = accelListeners[i].keysym;
            int mod = accelListeners[i].keymod;

            if (    event.key.keysym.sym == sym &&
                    event.key.keysym.mod & mod &&
                    keyListeners.Count() &&
                    accelListeners[i].target == keyListeners[ keyFocus ]) //maks: send accelerators for key focus owners
            {
                accelListeners[i].target->Accelerate( true, mod, sym ); //maks
                return;
            }
        }

        if ( keyListeners.Count() > 0 )
        {
            keyFocus = GlClamp( keyFocus, 0, int( keyListeners.Count()-1 ) );
            KrWidget* widget = keyListeners[ keyFocus ];

            // Go up the chain until handled.
            while( widget && !widget->KeyEvent( event ) )
            {
                widget = widget->ParentWidget();
            }
        }
    }
    else if ( event.type == SDL_KEYUP )
    {
        // - only accelerates key up
        for( int i=0; i<accelListeners.Count(); ++i )
        {
            if (    event.key.keysym.sym == accelListeners[i].keysym &&
                    event.key.keysym.mod & accelListeners[i].keymod &&
                    keyFocus >= 0 &&
                    keyListeners.Count() &&
                    accelListeners[i].target == keyListeners[ keyFocus ]) //maks
            {
                accelListeners[i].target->Accelerate( false, event.key.keysym.mod, event.key.keysym.sym ); //maks
                return;
            }
        }

        //Send shift key up
        if ( keyListeners.Count() > 0 && (event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT))
        {
            keyFocus = GlClamp( keyFocus, 0, int( keyListeners.Count()-1 ) );
            KrWidget* widget = keyListeners[ keyFocus ];

            // Go up the chain until handled.
            while( widget && !widget->KeyEvent( event ) )
            {
                widget = widget->ParentWidget();
            }
        }
    }
    else if ( event.type == SDL_MOUSEMOTION )
    {
        GlDynArray<KrImage*> hitArray;
        KrWidget* hit = 0;
        //int window = engine->GetWindowFromPoint( event.motion.x, event.motion.y );

        KrVector2T< GlFixed > object;

#ifndef _WIN32_WCE
        if(mouseDown && mouseFocus) //maks
        {
            //Don't change the focus if mouse button is down
            //Don't works on Pocket PC. In input.ged don't close the SIP keyboard (only send keyFocus = true)

            hit = mouseFocus;
            hit->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );
        }
        else
#endif
        {
            engine->Tree()->HitTest( event.motion.x, event.motion.y,
                                     KrImageTree::ALWAYS_INSIDE_BOX, //| GET_ALL_HITS,
                                     &hitArray/*,
				&window*/ );


            for( int i=0; i<hitArray.Count(); ++i )
            {
                KrImNode* parent = hitArray[i]->Parent();
                while( parent )
                {
                    if ( parent->ToWidget() )
                    {
                        hit = parent->ToWidget();
                        hit->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );
                        break;
                    }
                    parent = parent->Parent();
                }
            }
        }

        // 1) Something has the focus. Nothing had it before.
        // 2) Something has the focus, something else had it before.
        // 3) Something loses the focus.
        // 5) The thing with focus gets a move.
        if ( hit && !mouseFocus )
        {
            mouseFocus = hit;
            mouseFocus->MouseIn( mouseDown, true );
            mouseFocus->MouseMove( mouseDown, object.x.ToIntRound(), object.y.ToIntRound() );
        }
        else if ( hit && mouseFocus && mouseFocus != hit )
        {
            mouseFocus->MouseIn( mouseDown, false );
            mouseFocus = hit;
            mouseFocus->MouseIn( mouseDown, true );
            mouseFocus->MouseMove( mouseDown, object.x.ToIntRound(), object.y.ToIntRound() );
        }
        else if ( !hit && mouseFocus )
        {
            mouseFocus->MouseIn( mouseDown, false );
            mouseFocus = hit;
        }
        else if ( hit && hit == mouseFocus )
        {
            GLASSERT( hit == mouseFocus );
            mouseFocus->MouseMove( mouseDown, object.x.ToIntRound(), object.y.ToIntRound() );
        }
        else if ( !hit && !mouseFocus )
        {
            // nothing to do
        }
        else
        {
            GLASSERT( 0 );
        }

    }
    else if ( event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP )
    {
        if ( event.button.button == SDL_BUTTON_LEFT )
        {
            bool down = event.button.state != 0;	// & SDL_BUTTON_LMASK;
            if ( down != mouseDown )
            {
                mouseDown = down;
                if ( mouseFocus )
                {
                    int window = engine->GetWindowFromPoint( event.motion.x, event.motion.y );
                    KrVector2T< GlFixed > object;
                    mouseFocus->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );

                    mouseFocus->MouseClick( mouseDown ? KrWidget::LEFT_DOWN : KrWidget::LEFT_UP,
                                            object.x.ToIntRound(),
                                            object.y.ToIntRound() );
                }
                else //maks
                {
                    if(
                        keyFocus >= 0 && keyFocus < keyListeners.Count() &&
                        !newListnerFocus //maks: Only remove the focus if the widget don't has changed the focus in this cycle (solve focus bug in Math for Kids.ged)
                    )
                    {
                        keyListeners[ keyFocus ]->KeyFocus( false );
                        keyFocus = -1;
                        FocusState(false);
                    }
                }
            }
        }
        else if ( event.button.button == SDL_BUTTON_RIGHT ) //maks
        {
            bool down = event.button.state != 0;
            if ( down != mouseDown )
            {
                mouseDown = down;
                if ( mouseFocus )
                {
                    int window = engine->GetWindowFromPoint( event.motion.x, event.motion.y );
                    KrVector2T< GlFixed > object;
                    mouseFocus->ScreenToObject( event.motion.x, event.motion.y, &object/*, window*/ );

                    mouseFocus->MouseClick( mouseDown ? KrWidget::RIGHT_DOWN : KrWidget::RIGHT_UP,
                                            object.x.ToIntRound(),
                                            object.y.ToIntRound() );
                }
            }
        }
    }

    newListnerFocus = false; //maks
}