Changeset - r19780:e3df08729d5a
[Not reviewed]
master
0 4 0
frosch - 12 years ago 2012-11-13 21:47:13
frosch@openttd.org
(svn r24735) -Codechange: Move HandleEditBoxKey to Window class.
4 files changed with 43 insertions and 31 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -808,39 +808,12 @@ void QueryString::DrawEditBox(const Wind
 
		DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
 
	}
 

	
 
	_cur_dpi = old_dpi;
 
}
 

	
 
EventState QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
 
{
 
	EventState state = ES_NOT_HANDLED;
 
	switch (this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state)) {
 
		case HEBR_EDITING:
 
			this->OnEditboxChanged(wid);
 
			break;
 

	
 
		case HEBR_CONFIRM:
 
			if (this->ok_button >= 0) {
 
				this->OnClick(Point(), this->ok_button, 1);
 
			}
 
			break;
 

	
 
		case HEBR_CANCEL:
 
			if (this->cancel_button >= 0) {
 
				this->OnClick(Point(), this->cancel_button, 1);
 
			} else {
 
				this->UnfocusFocusedWidget();
 
			}
 
			break;
 

	
 
		default: break;
 
	}
 
	return state;
 
}
 

	
 
/** Class for the string query window. */
 
struct QueryStringWindow : public QueryStringBaseWindow
 
{
 
	QueryStringFlags flags; ///< Flags controlling behaviour of the window.
 

	
 
	QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, const WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
src/querystring_gui.h
Show inline comments
 
@@ -74,14 +74,12 @@ struct QueryStringBaseWindow : public Wi
 
	}
 

	
 
	~QueryStringBaseWindow()
 
	{
 
		free(this->edit_str_buf);
 
	}
 

	
 
	EventState HandleEditBoxKey(int wid, uint16 key, uint16 keycode);
 
};
 

	
 
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button);
 
void UpdateOSKOriginalText(const QueryStringBaseWindow *parent, int button);
 

	
 
#endif /* QUERYSTRING_GUI_H */
src/window.cpp
Show inline comments
 
@@ -2231,12 +2231,52 @@ static bool MaybeBringWindowToFront(Wind
 

	
 
	if (bring_to_front) BringWindowToFront(w);
 
	return true;
 
}
 

	
 
/**
 
 * Process keypress for editbox widget.
 
 * @param wid Editbox widget.
 
 * @param key     the Unicode value of the key.
 
 * @param keycode the untranslated key code including shift state.
 
 * @return #ES_HANDLED if the key press has been handled and no other
 
 *         window should receive the event.
 
 */
 
EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
 
{
 
	EventState state = ES_NOT_HANDLED;
 

	
 
	QueryString *query = dynamic_cast<QueryString*>(this);
 
	if (query == NULL) return state;
 

	
 
	switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
 
		case HEBR_EDITING:
 
			this->OnEditboxChanged(wid);
 
			break;
 

	
 
		case HEBR_CONFIRM:
 
			if (query->ok_button >= 0) {
 
				this->OnClick(Point(), query->ok_button, 1);
 
			}
 
			break;
 

	
 
		case HEBR_CANCEL:
 
			if (query->cancel_button >= 0) {
 
				this->OnClick(Point(), query->cancel_button, 1);
 
			} else {
 
				this->UnfocusFocusedWidget();
 
			}
 
			break;
 

	
 
		default: break;
 
	}
 

	
 
	return state;
 
}
 

	
 
/**
 
 * Handle keyboard input.
 
 * @param raw_key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
 
 */
 
void HandleKeypress(uint32 raw_key)
 
{
 
	/* World generation is multithreaded and messes with companies.
 
@@ -2264,14 +2304,13 @@ void HandleKeypress(uint32 raw_key)
 
	/* Check if the focused window has a focused editbox */
 
	if (EditBoxInGlobalFocus()) {
 
		/* All input will in this case go to the focused editbox */
 
		if (_focused_window->window_class == WC_CONSOLE) {
 
			if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
 
		} else {
 
			QueryStringBaseWindow *query = dynamic_cast<QueryStringBaseWindow*>(_focused_window);
 
			if (query != NULL && query->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
 
			if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
 
		}
 
	}
 

	
 
	/* Call the event, start with the uppermost window, but ignore the toolbar. */
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
src/window_gui.h
Show inline comments
 
@@ -455,12 +455,14 @@ public:
 
		return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
 
	}
 

	
 
	void UnfocusFocusedWidget();
 
	bool SetFocusedWidget(byte widget_index);
 

	
 
	EventState HandleEditBoxKey(int wid, uint16 key, uint16 keycode);
 

	
 
	void HandleButtonClick(byte widget);
 
	int GetRowFromWidget(int clickpos, int widget, int padding, int line_height = -1) const;
 

	
 
	void RaiseButtons(bool autoraise = false);
 
	void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
 
	void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
0 comments (0 inline, 0 general)