Ejemplo n.º 1
0
	/// Loads modal document from the URL.
	/// FIXME: move to window.
	void modal( const ASURL &location, int defaultCode = -1 )
	{
		WSWUI::NavigationStack *stack = UI_Main::Get()->getNavigator();

		// default return value when modal window is not closed via window.close()
		modalValue = defaultCode;
		if( stack == NULL || stack->isTopModal() ) {
			modalValue = defaultCode;
			return;
		}

		// suspend active context, we're going to resume it when 
		// the modal dialog is closed
		suspendActiveContext();

		if( suspendedContext ) {
			// attach itself as a listener of hide event so the context
			// can be resumed after the modal document is hidden
			WSWUI::Document *doc = stack->pushDocument( location.GetURL()->buffer, true, true );
			if( doc ) {
				attachedModalDocument = doc->getRocketDocument();
				attachedModalDocument->AddEventListener( "hide", this );
			}
		}
	}
Ejemplo n.º 2
0
	void historyBack( void ) const
	{
		WSWUI::NavigationStack *stack = UI_Main::Get()->getNavigator();
		if( stack != NULL && stack->hasAtLeastTwoDocuments() && !stack->isTopModal() ) {
			stack->popDocument();
		}
	}
Ejemplo n.º 3
0
	/// Closes the current document if there's more than one on the stack.
	/// Stores exit code to be passed to suspended context if modal.
	void close( int code = 0 )
	{
		WSWUI::NavigationStack *stack = UI_Main::Get()->getNavigator();
		if( stack == NULL ) {
			return;
		}

		ElementDocument *document = GetCurrentUIDocument();
		bool isModal = document->IsModal();

		// can't close if there's a modal dialog on top
		if( !isModal && stack->isTopModal() ) {
			return;
		}

		// so it's a top modal dialog or there's no modal dialog on stack at all
		if( isModal ) {
			modalValue = code;
			stack->popDocument();
		}
		else {
			// not really a modal window, clear the stack
			UI_Main::Get()->showUI( false );
		}
	}
Ejemplo n.º 4
0
	unsigned int historySize( void ) const
	{
		WSWUI::NavigationStack *stack = UI_Main::Get()->getNavigator();
		if( stack != NULL ) {
			return stack->getStackSize();
		}
		return 0;
	}
Ejemplo n.º 5
0
	/// Loads document from the passed URL.
	void open( const ASURL &location )
	{
		WSWUI::NavigationStack *stack = UI_Main::Get()->getNavigator();
		if( stack == NULL ) {
			return;
		}

		stack->pushDocument( location.GetURL()->buffer );
	}
Ejemplo n.º 6
0
	virtual void ProcessEvent( Event &event )
	{
		if( UI_Main::Get()->debugOn() ) {
			Com_Printf( "EventListener: Event %s, target %s, phase %i\n",
				event.GetType().CString(),
				event.GetTargetElement()->GetTagName().CString(),
				event.GetPhase() );
		}

		if( event.GetType() == "keydown" && 
			( event.GetPhase() == Rocket::Core::Event::PHASE_TARGET || event.GetPhase() == Rocket::Core::Event::PHASE_BUBBLE ) )
		{
			int key = event.GetParameter<int>( "key_identifier", 0 );
			ElementDocument *document = event.GetTargetElement()->GetOwnerDocument();
			WSWUI::Document *ui_document = static_cast<WSWUI::Document *>(document->GetScriptObject());
			WSWUI::NavigationStack *stack = ui_document ? ui_document->getStack() : NULL;

			if( key == Input::KI_ESCAPE ) {
				if( stack ) {
					if( stack->isTopModal() ) {
						// pop the top document
						stack->popDocument();
					}
					else if( stack->getContextId() == UI_CONTEXT_MAIN ) {
						// hide all documents
						UI_Main::Get()->showUI( false );
					}
				}
				event.StopPropagation();
			}
			else if( key == Rocket::Core::Input::KI_BROWSER_BACK || key == Rocket::Core::Input::KI_BACK ) {
				// act as history.back()
				if( stack && stack->hasAtLeastTwoDocuments() ) {
					stack->popDocument();
					event.StopPropagation();
				}
			}
		}
		else if( event.GetType() == "change" && ( event.GetPhase() == Rocket::Core::Event::PHASE_BUBBLE ) ) {
			bool linebreak = event.GetParameter<int>( "linebreak", 0 ) != 0;
			if( linebreak ) {
				// form submission
				String inputType;
				Element *target = event.GetTargetElement();
				Rocket::Controls::ElementFormControl *input = dynamic_cast<Rocket::Controls::ElementFormControl *>(target);

				if( event.GetPhase() != Rocket::Core::Event::PHASE_BUBBLE ) {
					return;
				}
				if( input == NULL ) {
					// not a form control
					return;
				}
				if( input->IsDisabled() ) {
					// skip disabled inputs
					return;
				}
				if( !input->IsSubmitted() ) {
					// this input field isn't submitted with the form
					return;
				}

				inputType = input->GetAttribute<String>( "type", "" );
				if( inputType != "text" && inputType != "password" ) {
					// not a text field
					return;
				}

				// find the parent form element
				Element *parent = target->GetParentNode();
				Rocket::Controls::ElementForm *form = NULL;
				while( parent ) {
					form = dynamic_cast<Rocket::Controls::ElementForm *>(parent);
					if( form != NULL ) {
						// not a form, go up the tree
						break;
					}
					parent = parent->GetParentNode();
				}

				if( form == NULL ) {
					if( UI_Main::Get()->debugOn() ) {
						Com_Printf( "EventListener: input element outside the form, what should I do?\n" );
					}
					return;
				}

				// find the submit element
				Element *submit = NULL;

				ElementList controls;
				parent->GetElementsByTagName( controls, "input" );
				for( size_t i = 0; i < controls.size(); i++ ) {
					Rocket::Controls::ElementFormControl *control =
						dynamic_cast< Rocket::Controls::ElementFormControl* >(controls[i]);

					if( !control ) {
						continue;
					}
					if( control->IsDisabled() ) {
						// skip disabled inputs
						continue;
					}

					String controlType = control->GetAttribute<String>( "type", "" );
					if( controlType != "submit" ) {
						// not a text field
						continue;
					}

					submit = controls[i];
					break;
				}

				if( submit == NULL ) {
					if( UI_Main::Get()->debugOn() ) {
						Com_Printf( "EventListener: form with no submit element, what should I do?\n" );
					}
					return;
				}

				// finally submit the form
				form->Submit( submit->GetAttribute< Rocket::Core::String >("name", ""), submit->GetAttribute< Rocket::Core::String >("value", "") );
			}
		}
	}