Пример #1
0
void
JXTabGroup::HandleMouseHere
	(
	const JPoint&			pt,
	const JXKeyModifiers&	modifiers
	)
{
	JIndex i;
	JRect r;
	JBoolean found = FindTab(pt, &i, &r);

	if (found && i != itsMouseIndex)
		{
		itsMouseIndex = i;
		Refresh();
		}
	else if (!found && itsMouseIndex > 0)
		{
		HandleMouseLeave();
		}
}
Пример #2
0
void Widget::HandleEvent( const sf::Event& event ) {
	if( !IsVisible() ) {
		return;
	}

	// Set widget active in context.
	Context::Get().SetActiveWidget( shared_from_this() );

	Container::Ptr parent( m_parent.lock() );

	switch( event.Type ) {
		case sf::Event::MouseMoved:
			// Check if pointer inside of widget's allocation.
			if( GetAllocation().Contains( static_cast<float>( event.MouseMove.X ), static_cast<float>( event.MouseMove.Y ) ) ) {
				// Check for enter event.
				if( m_mouse_in == false ) {
					m_mouse_in = true;
					OnMouseEnter();
					HandleMouseEnter( event.MouseMove.X, event.MouseMove.Y );
				}

				OnMouseMove();
			}
			else if( m_mouse_in == true ) { // Check for leave event.
				m_mouse_in = false;
				OnMouseLeave();
				HandleMouseLeave( event.MouseMove.X, event.MouseMove.Y );
			}

			HandleMouseMoveEvent( event.MouseMove.X, event.MouseMove.Y );
			break;

		case sf::Event::MouseButtonPressed:
			// If a mouse button has already been pressed for this widget, drop further
			// presses. This maybe needs changing, but up to now, I can't think of any
			// cases where it would be useful to have such a functionality.
			if( m_mouse_button_down == -1 ) {
				if( m_mouse_in ) {
					m_mouse_button_down = event.MouseButton.Button;

					HandleMouseButtonEvent( event.MouseButton.Button, true, event.MouseButton.X, event.MouseButton.Y );
					OnMouseButtonPress();
				}
			}

			break;

		case sf::Event::MouseButtonReleased:
			// Only process when mouse button has been clicked inside the widget before.
			if( m_mouse_button_down == event.MouseButton.Button ) {
				m_mouse_button_down = -1;

				// When released inside the widget, the event can be considered a click.
				if( m_mouse_in ) {
					HandleMouseClick( event.MouseButton.Button, event.MouseButton.X, event.MouseButton.Y );
				}

				OnMouseButtonRelease();
			}

			HandleMouseButtonEvent( event.MouseButton.Button, false, event.MouseButton.X, event.MouseButton.Y );
			break;

		case sf::Event::KeyPressed:
			if( GetState() == Active ) {
				// TODO: Delegate event too when widget's not active?
				HandleKeyEvent( event.Key.Code, true );
				OnKeyPress();
			}

			break;

		case sf::Event::KeyReleased:
			if( GetState() == Active ) {
				// TODO: Delegate event too when widget's not active?
				HandleKeyEvent( event.Key.Code, false );
				OnKeyRelease();
			}
			break;

		case sf::Event::TextEntered:
			if( GetState() == Active ) {
				// TODO: Delegate event too when widget's not active?
				HandleTextEvent( event.Text.Unicode );
				OnText();
			}
			break;

		default:
			break;
	}
}
Пример #3
0
void Widget::HandleEvent( const sf::Event& event ) {
	if( !IsGloballyVisible() ) {
		return;
	}

	// Ignore the event if widget is insensitive
	if ( GetState() == State::INSENSITIVE ) {
		return;
	}

	// Ignore the event if another widget is active.
	if( !IsActiveWidget() && !IsActiveWidget( PtrConst() ) ) {
		return;
	}

	// Ignore the event if another widget is modal.
	if( HasModal() && !IsModal() ) {
		return;
	}

	// Set widget active in context.
	Context::Get().SetActiveWidget( shared_from_this() );

	auto parent = m_parent.lock();

	auto emit_leave = false;
	auto emit_enter = false;
	auto emit_move = false;
	auto emit_left_click = false;
	auto emit_right_click = false;

	try {
		switch( event.type ) {
			case sf::Event::MouseLeft:
				if( IsMouseInWidget() ) {
					SetMouseInWidget( false );

					HandleMouseLeave( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );

					emit_leave = true;
				}

				HandleMouseMoveEvent( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );

				SetMouseButtonDown();
				HandleMouseButtonEvent( sf::Mouse::Left, false, std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
				HandleMouseButtonEvent( sf::Mouse::Right, false, std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );

				if( emit_leave ) {
					GetSignals().Emit( OnMouseLeave );
				}

				break;

			case sf::Event::MouseMoved:
				// Check if pointer inside of widget's allocation.
				if( GetAllocation().contains( static_cast<float>( event.mouseMove.x ), static_cast<float>( event.mouseMove.y ) ) ) {
					// Check for enter event.
					if( !IsMouseInWidget() ) {
						SetMouseInWidget( true );

						emit_enter = true;

						HandleMouseEnter( event.mouseMove.x, event.mouseMove.y );
					}

					emit_move = true;
				}
				else if( IsMouseInWidget() ) { // Check for leave event.
					SetMouseInWidget( false );

					emit_leave = true;

					HandleMouseLeave( event.mouseMove.x, event.mouseMove.y );
				}

				HandleMouseMoveEvent( event.mouseMove.x, event.mouseMove.y );

				if( emit_move ) {
					if( emit_enter ) {
						GetSignals().Emit( OnMouseEnter );
					}

					GetSignals().Emit( OnMouseMove );
				}
				else if( emit_leave ) {
					GetSignals().Emit( OnMouseLeave );
				}

				break;

			case sf::Event::MouseButtonPressed:
				if( !IsMouseButtonDown() && IsMouseInWidget() ) {
					SetMouseButtonDown( event.mouseButton.button );
				}

				HandleMouseButtonEvent( event.mouseButton.button, true, event.mouseButton.x, event.mouseButton.y );

				if( IsMouseInWidget() ) {
					if( event.mouseButton.button == sf::Mouse::Left ) {
						GetSignals().Emit( OnMouseLeftPress );
					}
					else if( event.mouseButton.button == sf::Mouse::Right ) {
						GetSignals().Emit( OnMouseRightPress );
					}
				}

				break;

			case sf::Event::MouseButtonReleased:
				// Only process as a click when mouse button has been pressed inside the widget before.
				if( IsMouseButtonDown( event.mouseButton.button ) ) {
					SetMouseButtonDown();

					// When released inside the widget, the event can be considered a click.
					if( IsMouseInWidget() ) {
						HandleMouseClick( event.mouseButton.button, event.mouseButton.x, event.mouseButton.y );

						if( event.mouseButton.button == sf::Mouse::Left ) {
							emit_left_click = true;
						}
						else if( event.mouseButton.button == sf::Mouse::Right ) {
							emit_right_click = true;
						}
					}
				}

				HandleMouseButtonEvent( event.mouseButton.button, false, event.mouseButton.x, event.mouseButton.y );

				if( emit_left_click ) {
					GetSignals().Emit( OnLeftClick );
				}
				else if( emit_right_click ) {
					GetSignals().Emit( OnRightClick );
				}

				if( IsMouseInWidget() ) {
					if( event.mouseButton.button == sf::Mouse::Left ) {
						GetSignals().Emit( OnMouseLeftRelease );
					}
					else if( event.mouseButton.button == sf::Mouse::Right ) {
						GetSignals().Emit( OnMouseRightRelease );
					}
				}

				break;

			case sf::Event::KeyPressed:
				if( HasFocus() ) {
					// TODO: Delegate event too when widget's not active?
					HandleKeyEvent( event.key.code, true );
					GetSignals().Emit( OnKeyPress );
				}

				break;

			case sf::Event::KeyReleased:
				if( HasFocus() ) {
					// TODO: Delegate event too when widget's not active?
					HandleKeyEvent( event.key.code, false );
					GetSignals().Emit( OnKeyRelease );
				}
				break;

			case sf::Event::TextEntered:
				if( HasFocus() ) {
					// TODO: Delegate event too when widget's not active?
					HandleTextEvent( event.text.unicode );
					GetSignals().Emit( OnText );
				}
				break;

			default:
				break;
		}
	}
	catch( ... ) {
		SetState( State::NORMAL );
		throw;
	}
}
Пример #4
0
void Widget::HandleEvent( const sf::Event& event ) {
	if( !IsGloballyVisible() ) {
		return;
	}

	// Ignore the event if widget is insensitive
	if ( GetState() == INSENSITIVE ) {
		return;
	}

	// Ignore the event if another widget is active.
	if( !IsActiveWidget() && !IsActiveWidget( PtrConst() ) ) {
		return;
	}

	// Ignore the event if another widget is modal.
	if( HasModal() && !IsModal() ) {
		return;
	}

	// Set widget active in context.
	Context::Get().SetActiveWidget( shared_from_this() );

	Container::Ptr parent( m_parent.lock() );

	switch( event.type ) {
		case sf::Event::MouseMoved:
			// Check if pointer inside of widget's allocation.
			if( GetAllocation().contains( static_cast<float>( event.mouseMove.x ), static_cast<float>( event.mouseMove.y ) ) ) {
				// Check for enter event.
				if( !IsMouseInWidget() ) {
					// Flip the mouse_in bit.
					m_bitfield ^= static_cast<unsigned char>( 0x10 );

					GetSignals().Emit( OnMouseEnter );
					HandleMouseEnter( event.mouseMove.x, event.mouseMove.y );
				}

				GetSignals().Emit( OnMouseMove );
			}
			else if( IsMouseInWidget() ) { // Check for leave event.
				// Flip the mouse_in bit.
				m_bitfield ^= static_cast<unsigned char>( 0x10 );

				GetSignals().Emit( OnMouseLeave );
				HandleMouseLeave( event.mouseMove.x, event.mouseMove.y );
			}

			HandleMouseMoveEvent( event.mouseMove.x, event.mouseMove.y );
			break;

		case sf::Event::MouseButtonPressed:
			if( ( ( m_bitfield & static_cast<unsigned char>( 0xe0 ) ) == static_cast<unsigned char>( 0xe0 ) ) && IsMouseInWidget() ) {
				// Clear the mouse_button_down bits to 0s.
				m_bitfield &= static_cast<unsigned char>( 0x1f );

				// Set the mouse_button_down bits.
				m_bitfield |= static_cast<unsigned char>( event.mouseButton.button << 5 );
			}

			HandleMouseButtonEvent( event.mouseButton.button, true, event.mouseButton.x, event.mouseButton.y );

			if( IsMouseInWidget() ) {
				if( event.mouseButton.button == sf::Mouse::Left ) {
					GetSignals().Emit( OnMouseLeftPress );
				}
				else if( event.mouseButton.button == sf::Mouse::Right ) {
					GetSignals().Emit( OnMouseRightPress );
				}
			}

			break;

		case sf::Event::MouseButtonReleased:
			// Only process as a click when mouse button has been pressed inside the widget before.
			if( ( ( m_bitfield & 0xe0 ) >> 5 ) == event.mouseButton.button ) {
				// Set the mouse_button_down bits to 111 (none).
				m_bitfield |= static_cast<unsigned char>( 0xe0 );

				// When released inside the widget, the event can be considered a click.
				if( IsMouseInWidget() ) {
					HandleMouseClick( event.mouseButton.button, event.mouseButton.x, event.mouseButton.y );

					if( event.mouseButton.button == sf::Mouse::Left ) {
						GetSignals().Emit( OnLeftClick );
					}
					else if( event.mouseButton.button == sf::Mouse::Right ) {
						GetSignals().Emit( OnRightClick );
					}
				}
			}

			HandleMouseButtonEvent( event.mouseButton.button, false, event.mouseButton.x, event.mouseButton.y );

			if( IsMouseInWidget() ) {
				if( event.mouseButton.button == sf::Mouse::Left ) {
					GetSignals().Emit( OnMouseLeftRelease );
				}
				else if( event.mouseButton.button == sf::Mouse::Right ) {
					GetSignals().Emit( OnMouseRightRelease );
				}
			}

			break;

		case sf::Event::KeyPressed:
			if( HasFocus() ) {
				// TODO: Delegate event too when widget's not active?
				HandleKeyEvent( event.key.code, true );
				GetSignals().Emit( OnKeyPress );
			}

			break;

		case sf::Event::KeyReleased:
			if( HasFocus() ) {
				// TODO: Delegate event too when widget's not active?
				HandleKeyEvent( event.key.code, false );
				GetSignals().Emit( OnKeyRelease );
			}
			break;

		case sf::Event::TextEntered:
			if( HasFocus() ) {
				// TODO: Delegate event too when widget's not active?
				HandleTextEvent( event.text.unicode );
				GetSignals().Emit( OnText );
			}
			break;

		default:
			break;
	}
}
Пример #5
0
void TWindow::HandleEvent(XEvent& event)
{
	TPoint	mouse;
	const TPoint& scroll = GetScroll();
	
	switch (event.type)
	{
		case Expose:
		{
			TRect	r(event.xexpose.x, event.xexpose.y, event.xexpose.x + event.xexpose.width, event.xexpose.y + event.xexpose.height);

			if (fUpdateRegion)
				fUpdateRegion->Union(r);
			else
			{
				fUpdateRegion = new TRegion(r);
				fNextUpdate = sFirstUpdate;
				sFirstUpdate = this;
			}
				
//			if (event.xexpose.count == 0)
//				Update();
		
			break;
		}

		case KeyPress:
		case KeyRelease:
		{			
			TTopLevelWindow* topLevel = GetTopLevelWindow();
			if (topLevel)
				topLevel->DispatchKeyEvent(event);
			break;
		}		
		
		case ButtonPress:
			if (event.xbutton.button >= 1 && event.xbutton.button <= 3)
			{
				fCurrentEventTime = event.xbutton.time;
				mouse.Set(event.xbutton.x + scroll.h, event.xbutton.y + scroll.v);

				// check for multiple clicks
				TTime now = gApplication->GetCurrentTime();
				if (now - fLastClickTime < kDoubleClickTime && 
					abs(fLastClick.h - mouse.h) <= kDoubleClickDelta &&
					abs(fLastClick.v - mouse.v) <= kDoubleClickDelta)
					++fClickCount;
				else
					fClickCount = 1;

				fLastClick = mouse;
				fLastClickTime = now;

				if (IsTargetable() && event.xbutton.button != 2)
					RequestTarget();
				
				HandleMouseDown(mouse, (TMouseButton)event.xbutton.button, event.xbutton.state);
			}
			else if (event.xbutton.button == 4 || event.xbutton.button == 5)
			{
				HandleScrollWheel(event.xbutton.button == 5);
			}
			break;

		case ButtonRelease:
			if (event.xbutton.button >= 1 && event.xbutton.button <= 3)
			{
				fCurrentEventTime = event.xbutton.time;
				mouse.Set(event.xbutton.x + scroll.h, event.xbutton.y + scroll.v);
				HandleMouseUp(mouse, (TMouseButton)event.xbutton.button, event.xbutton.state);
			}
			break;

		case EnterNotify:
			fCurrentEventTime = event.xcrossing.time;
			mouse.Set(event.xcrossing.x + scroll.h, event.xcrossing.y + scroll.v);
			HandleMouseEnter(mouse, event.xcrossing.state);
			break;

		case LeaveNotify:
			fCurrentEventTime = event.xcrossing.time;
			mouse.Set(event.xcrossing.x + scroll.h, event.xcrossing.y + scroll.v);
			HandleMouseLeave(mouse, event.xcrossing.state);
			break;

		case MotionNotify:
		{
			// avoid getting too many MotionNotify events by ignoring them if we have more in the queue
			XEvent testEvent;
			if (XPending(sDisplay) > 0 && XCheckTypedWindowEvent(sDisplay, event.xany.window, MotionNotify, &testEvent))
				break;

			fLastMouseMovedLocation.Set(event.xmotion.x, event.xmotion.y);
			fLastMouseMovedModifiers = event.xmotion.state;
			fCurrentEventTime = event.xmotion.time;
			mouse.Set(event.xmotion.x + scroll.h, event.xmotion.y + scroll.v);
			HandleMouseMoved(mouse, event.xmotion.state);
			break;
		}

		case FocusIn:
		{
			if (event.xfocus.detail == NotifyAncestor ||  
				event.xfocus.detail == NotifyInferior ||
				event.xfocus.detail == NotifyNonlinear ||
				event.xfocus.detail == NotifyNonlinearVirtual)
			{
				if (event.xfocus.mode != NotifyGrab &&
					event.xfocus.mode != NotifyUngrab)	// these events confuse XIM, according to gdk comment
				{
					TTopLevelWindow* topLevel = GetTopLevelWindow();
					if (topLevel)
						topLevel->GotFocus(this);
					break;
				}
			}
		}
			
		case FocusOut:
		{
			if (event.xfocus.detail == NotifyAncestor ||  
				event.xfocus.detail == NotifyInferior ||
				event.xfocus.detail == NotifyNonlinear ||
				event.xfocus.detail == NotifyNonlinearVirtual)
			{
				if (event.xfocus.mode != NotifyGrab &&
					event.xfocus.mode != NotifyUngrab)	// these events confuse XIM, according to gdk comment
				{
					TTopLevelWindow* topLevel = GetTopLevelWindow();
					if (topLevel)
						topLevel->LostFocus(this);
					break;
				}
			}
		}	
				
		case KeymapNotify:
//			printf("KeymapNotify\n");
			break;
			
		case GraphicsExpose:
//			printf("GraphicsExpose\n");
			break;
			
		case NoExpose:
//mgl why are we getting these when drawing scrollbars?
//			printf("NoExpose\n");
			break;
			
		case VisibilityNotify:
			fObscured = (event.xvisibility.state != VisibilityUnobscured);
			break;
			
		case CreateNotify:
			printf("CreateNotify\n");
			break;
			
		case DestroyNotify:
			printf("DestroyNotify\n");
			break;
			
		case MapNotify:
			DoMapped(true);
			break;

		case UnmapNotify:
			DoMapped(false);
			break;
			
		case MapRequest:
			printf("MapRequest\n");
			break;
			
		case ReparentNotify:
//			printf("ReparentNotify\n");
			break;
			
		case ConfigureNotify:
		{
			// we manage child window notification ourselves
			if (fParent == NULL)
			{
				TRect oldBounds(fBounds);
				fBounds.Set(event.xconfigure.x, event.xconfigure.y, 
							event.xconfigure.x + event.xconfigure.width,
							event.xconfigure.y + event.xconfigure.height);
	
				NotifyBoundsChanged(oldBounds);
			}
			break;
		}
			
		case ConfigureRequest:
			printf("ConfigureRequest\n");
			break;
			
		case GravityNotify:
			printf("GravityNotify\n");
			break;
			
		case ResizeRequest:
			printf("ResizeRequest\n");
			break;
			
		case CirculateNotify:
			printf("CirculateNotify\n");
			break;
			
		case CirculateRequest:
			printf("CirculateRequest\n");
			break;
			
		case PropertyNotify:
			printf("PropertyNotify\n");
			break;
			
		case SelectionClear:
		{
			if (fIsSelectionOwner)
			{
				LostSelectionOwnership();
				fIsSelectionOwner = false;
			}
			break;
		}
			
		case SelectionRequest:
		{
			XSelectionEvent response;

			response.type = SelectionNotify;
			response.display = event.xselectionrequest.display;
			response.requestor = event.xselectionrequest.requestor;
			response.selection = event.xselectionrequest.selection;
			response.target = event.xselectionrequest.target;
			response.property = event.xselectionrequest.property;
			response.time = event.xselectionrequest.time;
			
			Atom	targetAtom = XInternAtom(event.xselectionrequest.display, "TARGETS", false);
			
			if (event.xselectionrequest.target == targetAtom)
			{
				Atom				targets[] = { XA_STRING };
				int					result;
				
				result = XChangeProperty(event.xselectionrequest.display,
										 event.xselectionrequest.requestor,
										 event.xselectionrequest.property,
										 event.xselectionrequest.target,
										 8,
										 PropModeReplace,
										 (const unsigned char*)targets,
										 sizeof(targets));
							   
				if (result == BadAlloc || result == BadAtom || result == BadMatch || result == BadValue || result == BadWindow)
					printf ("SelectionRequest - XChangeProperty failed: %d\n", result);
				
				response.send_event = true;
			}
			else
			{
				unsigned char* data;
				uint32 length;
				Atom type = event.xselectionrequest.target;
				if (response.selection == XA_PRIMARY && RequestSelectionData(type, data, length))
				{
					response.target = type;
					XChangeProperty(response.display, response.requestor, event.xselectionrequest.property, type, 
									8, PropModeReplace, data, length);
					free(data);
				}
				else
					response.property = None;
			}

			XSendEvent(sDisplay, response.requestor, false, NoEventMask, (XEvent *)&response);	
			break;
		}
			
		case SelectionNotify:
		{
			if (event.xselection.property != None)
			{
				Atom type;
				unsigned long items, length, remaining;
				int actualFormat;
				unsigned char*	data;

				// first compute the length
				XGetWindowProperty(sDisplay, fWindow, event.xselection.property, 0, 0, false, AnyPropertyType,
								&type, &actualFormat, &items, &length, &data);
				if (data)
					XFree(data);

				// now get the data
				XGetWindowProperty(sDisplay, fWindow, event.xselection.property, 0, length, true, AnyPropertyType,
								&type, &actualFormat, &items, &remaining, &data);
				ASSERT(remaining == 0);

				ReceiveSelectionData(type, data, length);
				XFree(data);
			}			
			
			break;
		}
			
		case ColormapNotify:
			printf("ColormapNotify\n");
			break;
			
		case ClientMessage:
			if ((Atom)event.xclient.data.l[0] == sDeleteWindowAtom)
			{
				Close();
			}
			else if ((Atom)event.xclient.data.l[0] == sTakeFocusAtom)
			{
/*				TTopLevelWindow* topLevel = GetTopLevelWindow();
				ASSERT(topLevel == this);
				topLevel->TakeFocus();
*/				
			}
			else
				printf("unknown ClientMessage\n");
			break;
			
		case MappingNotify:
			printf("MappingNotify\n");
			break;
			
		default:
			break;
	}
}