Exemple #1
0
unsigned int GRadio::process_key (GMessage& msg)
{
	if(focus && focus->message(msg))
		return 1;
	switch (msg.param)
	{
	case KEY_RIGHT:
	case KEY_DOWN:
		if(focus)
		{
			GObject* last = last_available();
			if(last && last == focus)
			{
				focus->clr_flag(GO_FLG_SELECTED);								//if there is not next child, clears the SELECTED flag from the current focus
				break;
			}
		}
		return focus_on_next();
//		if (focus)
//		{
//			if (focus->nextObj)
//			{
//				if(focus->nextObj->get_focus())									//sets the focus on the next child
//					return 1;
//			}
//			else
//			{
//				focus->clr_flag(GO_FLG_SELECTED);								//if there is not next child, clears the SELECTED flag from the current focus
//			}
//		}
//		else
//		{
//			if (children &&	children->get_focus())											//if there isn't focus, sets the focus on the first child
//				return 1;
//		}
//		break;
	case KEY_LEFT:
	case KEY_UP:
		if(focus)
		{
			GObject* first = first_available();
			if(first && first == focus)
			{
				focus->clr_flag(GO_FLG_SELECTED);								//if there is not next child, clears the SELECTED flag from the current focus
				break;
			}
		}
		return focus_on_previous();
//		if (children)
//		{
//			if (focus == children)
//			{
//				focus->clr_flag(GO_FLG_SELECTED);							//if the first child is focused, clears the SELECTED flag from it
//				return 0;
//			}
//			GObject* tmp = children;
//			while (tmp->nextObj && tmp->nextObj != focus)
//				tmp = tmp->nextObj;											//sets the focus on the child before the previous focus
//			if(tmp->get_focus())
//				return 1;
//		}
		break;
	default:
		break;
	}
	return 0;
}
Exemple #2
0
unsigned int GMsgBox::process_key (GMessage& msg)
{
	unsigned int param;
	unsigned int res=0;
	GObject* tmp = focus;

	if(GWindow::process_key(msg))
		return 1;

	if( !text_box )
		return 0;

	switch (msg.param)
	{
	case KEY_RIGHT:
		if(focus)
		{
			if(focus->rect.y1 <= rect.y1)
			{
				if(text_box == focus || title_box == focus)
					break;	// It's a message or title_box, do nothing
				if(focus != last_available()) // It's not a last button
					res = focus_on_next();
				if(res)
					default_button = focus->id;
			}
			move(0,0);
		}
		break;

	case KEY_DOWN:
		if(focus)
		{
			if(focus->rect.y1 <= rect.y1)
			{
				if(focus == title_box)
				{
					// try to move on the text
					res = text_box->get_focus();
					if(!res)
					{
						// all text is visible, try buttons
						res = SelectDefaultButton(text_box->nextObj);
						if(!res)
						{
							// without buttons, do nothing
							break;
						}
					}
				}
				else
				{
					if(text_box == focus)
					{	// move on the buttons
						res = SelectDefaultButton(text_box->nextObj);
						if(!res)
						{
							// without buttons, try title
							if(title_box)
							{
								res = title_box->get_focus();
								if(!res)
								{
									// all text is visible and no buttons, scroll to title
									focus = title_box;
									focus->flags |= GO_FLG_ENABLED;
									move(0,0);
									focus->flags &= ~GO_FLG_ENABLED;
									focus = tmp;
									break;
								}
							}
						}
					}
					else
					{
						// at buttons
						if(title_box && title_box->rect.y0 <= rect.y0) // title not full visible
						{
							// try title
							res = title_box->get_focus();
							if(!res)
							{
								// all text visible and has a title
								focus = title_box;
								focus->flags |= GO_FLG_ENABLED;
								move(0,0);
								focus->flags &= ~GO_FLG_ENABLED;
								focus = tmp;
								break;
							}
						}
						else
						{
							res = text_box->get_focus();
							if(!res)
							{
								// all text visible and no title
								focus = text_box;
								focus->flags |= GO_FLG_ENABLED;
								move(0,0);
								focus->flags &= ~GO_FLG_ENABLED;
								focus = tmp;
								break;
							}
						}
					}
				}
			}
			move(0,0);
		}
		break;

	case KEY_LEFT:
		if(focus)
		{
			if(focus->rect.y1 <= rect.y1)
			{
				if(text_box == focus || title_box == focus) // It's a message, do nothing
					break;
				if(text_box->nextObj != focus) // It's not a first button
					res =  focus_on_previous();
				if(res)
					default_button = focus->id;
			}
			move(0,0);
		}
		break;

	case KEY_UP:
		if(focus)
		{
			if(focus->rect.y1 <= rect.y1)
			{
				if(focus == title_box)
				{
					// at the title
					// try to go on the buttons
					res = SelectDefaultButton(text_box->nextObj);
					if(!res)
					{
						// box without buttons.
						res = text_box->get_focus();
						if(!res)
						{
							// the whole message is visible on the screen
							// do nothing
							break;
						}
					}
				}
				else
				{
					if(focus == text_box)
					{
						// at the text
						// text can be scrolled, try to select title
						if(title_box)
						{
							res = title_box->get_focus();
							if(!res)
							{
								// try to go on buttons
								res = SelectDefaultButton(text_box->nextObj);
								if(!res)
								{
									// box with text only
								}
							}
						}
						else
						{
							//box without title, we are at text. try to select buttons
							res = SelectDefaultButton(text_box->nextObj);
							if(!res)
							{
								// box with text only and all text is visible
								break;
							}
						}
					}
					else
					{
						// at the button
						res = text_box->get_focus();
						if(!res)
						{
							// all text is visible
							if(title_box)
							{
								// has a title, move to it
								res = title_box->get_focus();
								if(!res)
								{
									focus = title_box;
									focus->flags |= GO_FLG_ENABLED;
									move(0,0);
									focus->flags &= ~GO_FLG_ENABLED;
									focus = tmp;
									break;
								}
							}
							else
								break;
						}
					}
				}
			}
			move(0,0);
		}
		break;

	case KEY_OK:
		if (!(type & (MBF_LAST_BTN-1)) || (type & ((MBF_LAST_BTN-1))) == MBF_OK )
		{
			notify_message(WM_CLOSE, GO_IDOK, this);
			return 1;
		}
		break;

	case KEY_CANCEL:
		switch((type&(MBF_LAST_BTN-1)))
		{
		case 0: // no buttons
			param = GO_EXIT;
		case MB_OKCANCEL:
		case MB_RETRYCANCEL:
		case MB_YESNOCANCEL:
			param = GO_IDCANCEL;
			break;
		case MB_YESNO:
			param = GO_IDNO;
			break;
		default:
			return 0;
		}
		notify_message(WM_CLOSE, param, this);
		return 1;
		break;

	default:
		return 0;
	}

	return res;
}