Changeset - r8018:0bb6be7b55d7
[Not reviewed]
master
0 8 0
belugas - 17 years ago 2007-12-06 02:31:47
belugas@openttd.org
(svn r11578) -Codechange: Introduce the window default flag WDF_TEXTENTRY which specifies that the window holding it is actually one that enables an edit box.
Use this flag when dispatching a key event instead of using some hard coded window IDs.
This should ease a little bit the creation of new edit aware windows.
8 files changed with 14 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/console.cpp
Show inline comments
 
@@ -193,25 +193,25 @@ static void IConsoleWndProc(Window *w, W
 
			break;
 
		}
 
	}
 
}
 

	
 
static const Widget _iconsole_window_widgets[] = {
 
	{WIDGETS_END}
 
};
 

	
 
static const WindowDesc _iconsole_window_desc = {
 
	0, 0, 2, 2, 2, 2,
 
	WC_CONSOLE, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_TEXTENTRY,
 
	_iconsole_window_widgets,
 
	IConsoleWndProc,
 
};
 

	
 
void IConsoleInit()
 
{
 
	extern const char _openttd_revision[];
 
	_iconsole_output_file = NULL;
 
	_icolour_def  =  1;
 
	_icolour_err  =  3;
 
	_icolour_warn = 13;
 
	_icolour_dbg  =  5;
src/genworld_gui.cpp
Show inline comments
 
@@ -503,33 +503,33 @@ static void GenerateLandscapeWndProc(Win
 
			}
 

	
 
			SetWindowDirty(w);
 
		}
 
		break;
 
	}
 
	}
 
}
 

	
 
static const WindowDesc _generate_landscape_desc = {
 
	WDP_CENTER, WDP_CENTER, 338, 268, 338, 268,
 
	WC_GENERATE_LANDSCAPE, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_TEXTENTRY,
 
	_generate_landscape_widgets,
 
	GenerateLandscapeWndProc,
 
};
 

	
 
static const WindowDesc _heightmap_load_desc = {
 
	WDP_CENTER, WDP_CENTER, 338, 236, 338, 236,
 
	WC_GENERATE_LANDSCAPE, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_TEXTENTRY,
 
	_heightmap_load_widgets,
 
	GenerateLandscapeWndProc,
 
};
 

	
 
static void _ShowGenerateLandscape(glwp_modes mode)
 
{
 
	uint x = 0;
 
	uint y = 0;
 

	
 
	DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
 

	
 
	/* Always give a new seed if not editor */
 
@@ -736,25 +736,25 @@ static const Widget _create_scenario_wid
 
{      WWT_PANEL, RESIZE_NONE, 12, 228, 314, 113, 124, 0x0,                     STR_NULL},
 
{     WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 113, 124, SPR_ARROW_UP,            STR_029F_MOVE_THE_STARTING_DATE},
 

	
 
{     WWT_IMGBTN, RESIZE_NONE, 12, 282, 293, 131, 142, SPR_ARROW_DOWN,          STR_FLAT_WORLD_HEIGHT_DOWN},
 
{      WWT_PANEL, RESIZE_NONE, 12, 294, 314, 131, 142, 0x0,                     STR_NULL},
 
{     WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 131, 142, SPR_ARROW_UP,            STR_FLAT_WORLD_HEIGHT_UP},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _create_scenario_desc = {
 
	WDP_CENTER, WDP_CENTER, 338, 170, 338, 170,
 
	WC_GENERATE_LANDSCAPE, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_TEXTENTRY,
 
	_create_scenario_widgets,
 
	CreateScenarioWndProc,
 
};
 

	
 
void ShowCreateScenario()
 
{
 
	DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
 
	AllocateWindowDescFront(&_create_scenario_desc, GLWP_SCENARIO);
 
}
 

	
 

	
 
static const Widget _show_terrain_progress_widgets[] = {
src/misc_gui.cpp
Show inline comments
 
@@ -1171,25 +1171,25 @@ static const Widget _query_string_widget
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,        STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   259,     0,    13, STR_012D,        STR_NULL},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   259,    14,    29, 0x0,             STR_NULL},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   257,    16,    27, 0x0,             STR_NULL},
 
{    WWT_TEXTBTN,   RESIZE_NONE,    14,     0,   129,    30,    41, STR_012E_CANCEL, STR_NULL},
 
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   130,   259,    30,    41, STR_012F_OK,     STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _query_string_desc = {
 
	190, 219, 260, 42, 260, 42,
 
	WC_QUERY_STRING, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_TEXTENTRY,
 
	_query_string_widgets,
 
	QueryStringWndProc
 
};
 

	
 
static char _edit_str_buf[64];
 

	
 
/** Show a query popup window with a textbox in it.
 
 * @param str StringID for the text shown in the textbox
 
 * @param caption StringID of text shown in caption of querywindow
 
 * @param maxlen maximum length in characters allowed. If bit 12 is set we
 
 * will not check the resulting string against to original string to return success
 
 * @param maxwidth maximum width in pixels allowed
 
@@ -1639,33 +1639,33 @@ static void SaveLoadDlgWndProc(Window *w
 
			w->widget[12].left  += diff;
 
			w->widget[12].right += e->we.sizing.diff.x;
 
		}
 

	
 
		w->vscroll.cap += e->we.sizing.diff.y / 10;
 
		} break;
 
	}
 
}
 

	
 
static const WindowDesc _load_dialog_desc = {
 
	WDP_CENTER, WDP_CENTER, 257, 154, 257, 294,
 
	WC_SAVELOAD, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE | WDF_TEXTENTRY,
 
	_load_dialog_widgets,
 
	SaveLoadDlgWndProc,
 
};
 

	
 
static const WindowDesc _save_dialog_desc = {
 
	WDP_CENTER, WDP_CENTER, 257, 180, 257, 320,
 
	WC_SAVELOAD, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE | WDF_TEXTENTRY,
 
	_save_dialog_widgets,
 
	SaveLoadDlgWndProc,
 
};
 

	
 
void ShowSaveLoadDialog(int mode)
 
{
 
	static const StringID saveload_captions[] = {
 
		STR_4001_LOAD_GAME,
 
		STR_0298_LOAD_SCENARIO,
 
		STR_4000_SAVE_GAME,
 
		STR_0299_SAVE_SCENARIO,
 
		STR_4011_LOAD_HEIGHTMAP,
src/network/network_gui.cpp
Show inline comments
 
@@ -1843,25 +1843,25 @@ static void ChatWindowWndProc(Window *w,
 

	
 
static const Widget _chat_window_widgets[] = {
 
{   WWT_CLOSEBOX, RESIZE_NONE,  14,   0,  10,  0, 13, STR_00C5,         STR_018B_CLOSE_WINDOW},
 
{      WWT_PANEL, RESIZE_RIGHT, 14,  11, 319,  0, 13, 0x0,              STR_NULL}, // background
 
{      WWT_PANEL, RESIZE_RIGHT, 14,  75, 257,  1, 12, 0x0,              STR_NULL}, // text box
 
{ WWT_PUSHTXTBTN, RESIZE_LR,    14, 258, 319,  1, 12, STR_NETWORK_SEND, STR_NULL}, // send button
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _chat_window_desc = {
 
	WDP_CENTER, -26, 320, 14, 640, 14, // x, y, width, height
 
	WC_SEND_NETWORK_MSG, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_TEXTENTRY,
 
	_chat_window_widgets,
 
	ChatWindowWndProc
 
};
 

	
 
void ShowNetworkChatQueryWindow(DestType type, int dest)
 
{
 
	Window *w;
 

	
 
	DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
 

	
 
	_edit_str_buf[0] = '\0';
 
	_chat_tab_completion_active = false;
 
@@ -1942,25 +1942,25 @@ static const Widget _ncp_window_widgets[
 
{      WWT_PANEL, RESIZE_NONE, 14,   0, 299, 14, 50, 0x0,                               STR_NULL},
 
{       WWT_TEXT, RESIZE_NONE, 14,   5, 100, 19, 30, STR_COMPANY_PASSWORD,              STR_NULL},
 
{      WWT_PANEL, RESIZE_NONE, 14, 101, 294, 19, 30, 0x0,                               STR_NULL},
 
{    WWT_TEXTBTN, RESIZE_NONE, 14, 101, 294, 35, 46, STR_MAKE_DEFAULT_COMPANY_PASSWORD, STR_MAKE_DEFAULT_COMPANY_PASSWORD_TIP},
 
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14,   0, 149, 51, 62, STR_012E_CANCEL,                   STR_COMPANY_PASSWORD_CANCEL},
 
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 150, 299, 51, 62, STR_012F_OK,                       STR_COMPANY_PASSWORD_OK},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _ncp_window_desc = {
 
	WDP_AUTO, WDP_AUTO, 300, 63, 300, 63,
 
	WC_COMPANY_PASSWORD_WINDOW, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_TEXTENTRY,
 
	_ncp_window_widgets,
 
	NetworkCompanyPasswordWindowWndProc
 
};
 

	
 
void ShowNetworkCompanyPasswordWindow()
 
{
 
	DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
 

	
 
	_edit_str_buf[0] = '\0';
 
	Window *w = AllocateWindowDesc(&_ncp_window_desc);
 
	WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL;
 
	InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_buf, min(lengthof(_network_default_company_pass), lengthof(_edit_str_buf)), 0);
src/newgrf_gui.cpp
Show inline comments
 
@@ -226,25 +226,25 @@ static const Widget _newgrf_add_dlg_widg
 
{      WWT_PANEL,     RESIZE_RTB, 14,   0, 306, 122, 224, 0x0,                     STR_NULL },
 

	
 
{ WWT_PUSHTXTBTN,     RESIZE_RTB, 14,   0, 146, 225, 236, STR_NEWGRF_ADD_FILE,     STR_NEWGRF_ADD_FILE_TIP },
 
{ WWT_PUSHTXTBTN,    RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP },
 
{  WWT_RESIZEBOX,    RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0,                     STR_RESIZE_BUTTON },
 
{   WIDGETS_END },
 
};
 

	
 

	
 
static const WindowDesc _newgrf_add_dlg_desc = {
 
	WDP_CENTER, WDP_CENTER, 307, 237, 307, 337,
 
	WC_SAVELOAD, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE | WDF_TEXTENTRY,
 
	_newgrf_add_dlg_widgets,
 
	NewGRFAddDlgWndProc,
 
};
 

	
 

	
 
/* 'NewGRF Settings' dialogue */
 
struct newgrf_d {
 
	GRFConfig **orig_list; ///< grf list the window is shown with
 
	GRFConfig **list;      ///< temporary grf list to which changes are made
 
	GRFConfig *sel;        ///< selected grf item
 
	bool editable;         ///< is the window editable
 
	bool show_params;      ///< are the grf-parameters shown in the info-panel
src/signs_gui.cpp
Show inline comments
 
@@ -289,25 +289,25 @@ static const Widget _query_sign_edit_wid
 
{  WWT_TEXTBTN, RESIZE_NONE,  14,   0,  60,  30,  41, STR_012F_OK,     STR_NULL },
 
{  WWT_TEXTBTN, RESIZE_NONE,  14,  61, 120,  30,  41, STR_012E_CANCEL, STR_NULL },
 
{  WWT_TEXTBTN, RESIZE_NONE,  14, 121, 180,  30,  41, STR_0290_DELETE, STR_NULL },
 
{    WWT_PANEL, RESIZE_NONE,  14, 181, 237,  30,  41, STR_NULL,        STR_NULL },
 
{  WWT_TEXTBTN, RESIZE_NONE,  14, 238, 248,  30,  41, STR_6819,        STR_PREVIOUS_SIGN_TOOLTIP },
 
{  WWT_TEXTBTN, RESIZE_NONE,  14, 249, 259,  30,  41, STR_681A,        STR_NEXT_SIGN_TOOLTIP },
 
{ WIDGETS_END },
 
};
 

	
 
static const WindowDesc _query_sign_edit_desc = {
 
	190, 170, 260, 42, 260, 42,
 
	WC_QUERY_STRING, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_TEXTENTRY,
 
	_query_sign_edit_widgets,
 
	QuerySignEditWndProc
 
};
 

	
 
void ShowRenameSignWindow(const Sign *si)
 
{
 
	Window *w;
 

	
 
	/* Delete all other edit windows and the save window */
 
	DeleteWindowById(WC_QUERY_STRING, 0);
 
	DeleteWindowById(WC_SAVELOAD, 0);
 

	
src/window.cpp
Show inline comments
 
@@ -1667,68 +1667,48 @@ void SendWindowMessageClass(WindowClass 
 
	FOR_ALL_WINDOWS(wz) {
 
		if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam);
 
	}
 
}
 

	
 
/** Handle keyboard input.
 
 * @param key Lower 8 bits contain the ASCII character, the higher
 
 * 16 bits the keycode */
 
void HandleKeypress(uint32 key)
 
{
 
	Window* const *wz;
 
	WindowEvent e;
 
	/* Stores if a window with a textfield for typing is open
 
	 * If this is the case, keypress events are only passed to windows with text fields and
 
	 * to thein this main toolbar. */
 
	bool query_open = false;
 

	
 
	/*
 
	* During the generation of the world, there might be
 
	* another thread that is currently building for example
 
	* a road. To not interfere with those tasks, we should
 
	* NOT change the _current_player here.
 
	*
 
	* This is not necessary either, as the only events that
 
	* can be handled are the 'close application' events
 
	*/
 
	if (!IsGeneratingWorld()) _current_player = _local_player;
 

	
 
	/* Setup event */
 
	e.event = WE_KEYPRESS;
 
	e.we.keypress.key     = GB(key,  0, 16);
 
	e.we.keypress.keycode = GB(key, 16, 16);
 
	e.we.keypress.cont = true;
 

	
 
	/* check if we have a query string window open before allowing hotkeys */
 
	if (FindWindowById(WC_QUERY_STRING,            0) != NULL ||
 
			FindWindowById(WC_SEND_NETWORK_MSG,        0) != NULL ||
 
			FindWindowById(WC_GENERATE_LANDSCAPE,      0) != NULL ||
 
			FindWindowById(WC_CONSOLE,                 0) != NULL ||
 
			FindWindowById(WC_SAVELOAD,                0) != NULL ||
 
			FindWindowById(WC_COMPANY_PASSWORD_WINDOW, 0) != NULL) {
 
		query_open = true;
 
	}
 

	
 
	/* Call the event, start with the uppermost window. */
 
	for (wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 

	
 
		/* if a query window is open, only call the event for certain window types */
 
		if (query_open &&
 
				w->window_class != WC_QUERY_STRING &&
 
				w->window_class != WC_SEND_NETWORK_MSG &&
 
				w->window_class != WC_GENERATE_LANDSCAPE &&
 
				w->window_class != WC_CONSOLE &&
 
				w->window_class != WC_SAVELOAD &&
 
				w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
 
		/* Only call the event for the windows declared as been text entry enabled */
 
		if (!(w->desc_flags & WDF_TEXTENTRY)) {
 
			continue;
 
		}
 
		w->wndproc(w, &e);
 
		if (!e.we.keypress.cont) break;
 
	}
 

	
 
	if (e.we.keypress.cont) {
 
		Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
		/* When there is no toolbar w is null, check for that */
 
		if (w != NULL) w->wndproc(w, &e);
 
	}
 
}
src/window.h
Show inline comments
 
@@ -199,25 +199,25 @@ struct WindowDesc {
 
	int16 left, top, minimum_width, minimum_height, default_width, default_height;
 
	WindowClass cls;
 
	WindowClass parent_cls;
 
	uint32 flags;
 
	const Widget *widgets;
 
	WindowProc *proc;
 
};
 

	
 
enum WindowDefaultFlag {
 
	WDF_STD_TOOLTIPS    =   1 << 0, ///< use standard routine when displaying tooltips
 
	WDF_DEF_WIDGET      =   1 << 1, ///< default widget control for some widgets in the on click event
 
	WDF_STD_BTN         =   1 << 2, ///< default handling for close and drag widgets (widget no 0 and 1)
 

	
 
	WDF_TEXTENTRY       =   1 << 3, ///< This window is authorized to receive keyboard events
 
	WDF_UNCLICK_BUTTONS =   1 << 4, ///< Unclick buttons when the window event times out */
 
	WDF_STICKY_BUTTON   =   1 << 5, ///< Set window to sticky mode; they are not closed unless closed with 'X' (widget 2)
 
	WDF_RESIZABLE       =   1 << 6, ///< A window can be resized
 
	WDF_MODAL           =   1 << 7, ///< The window is a modal child of some other window, meaning the parent is 'inactive'
 
};
 

	
 
/* can be used as x or y coordinates to cause a specific placement */
 
enum WindowDefaultPosition {
 
	WDP_AUTO      = -1, ///< Find a place automatically
 
	WDP_CENTER    = -2, ///< Center the window (left/right or top/bottom)
 
	WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar
 
	WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar
0 comments (0 inline, 0 general)