src/window.h
changeset 8602 9e75e594a068
parent 8601 6b2ddb5baade
child 8603 88c5ce6a5215
equal deleted inserted replaced
8601:6b2ddb5baade 8602:9e75e594a068
     1 /* $Id$ */
       
     2 
       
     3 /** @file window.h regroups declarations for all windowing system, as well as a few helper functions */
       
     4 
       
     5 #ifndef WINDOW_H
       
     6 #define WINDOW_H
       
     7 
       
     8 #include "macros.h"
       
     9 #include "string.h"
       
    10 #include "order.h"
       
    11 #include "rail_type.h"
       
    12 #include "road_type.h"
       
    13 #include "airport.h"
       
    14 #include "vehicle.h"
       
    15 #include "viewport.h"
       
    16 
       
    17 /**
       
    18  * The maximum number of windows that can be opened.
       
    19  */
       
    20 static const int MAX_NUMBER_OF_WINDOWS = 25;
       
    21 
       
    22 struct WindowEvent;
       
    23 
       
    24 typedef void WindowProc(Window *w, WindowEvent *e);
       
    25 
       
    26 /* How the resize system works:
       
    27     First, you need to add a WWT_RESIZEBOX to the widgets, and you need
       
    28      to add the flag WDF_RESIZABLE to the window. Now the window is ready
       
    29      to resize itself.
       
    30     As you may have noticed, all widgets have a RESIZE_XXX in their line.
       
    31      This lines controls how the widgets behave on resize. RESIZE_NONE means
       
    32      it doesn't do anything. Any other option let's one of the borders
       
    33      move with the changed width/height. So if a widget has
       
    34      RESIZE_RIGHT, and the window is made 5 pixels wider by the user,
       
    35      the right of the window will also be made 5 pixels wider.
       
    36     Now, what if you want to clamp a widget to the bottom? Give it the flag
       
    37      RESIZE_TB. This is RESIZE_TOP + RESIZE_BOTTOM. Now if the window gets
       
    38      5 pixels bigger, both the top and bottom gets 5 bigger, so the whole
       
    39      widgets moves downwards without resizing, and appears to be clamped
       
    40      to the bottom. Nice aint it?
       
    41    You should know one more thing about this system. Most windows can't
       
    42     handle an increase of 1 pixel. So there is a step function, which
       
    43     let the windowsize only be changed by X pixels. You configure this
       
    44     after making the window, like this:
       
    45       w->resize.step_height = 10;
       
    46     Now the window will only change in height in steps of 10.
       
    47    You can also give a minimum width and height. The default value is
       
    48     the default height/width of the window itself. You can change this
       
    49     AFTER window-creation, with:
       
    50      w->resize.width or w->resize.height.
       
    51    That was all.. good luck, and enjoy :) -- TrueLight */
       
    52 
       
    53 enum ResizeFlag {
       
    54 	RESIZE_NONE   = 0,  ///< no resize required
       
    55 
       
    56 	RESIZE_LEFT   = 1,  ///< left resize flag
       
    57 	RESIZE_RIGHT  = 2,  ///< rigth resize flag
       
    58 	RESIZE_TOP    = 4,  ///< top resize flag
       
    59 	RESIZE_BOTTOM = 8,  ///< bottom resize flag
       
    60 
       
    61 	RESIZE_LR     = RESIZE_LEFT  | RESIZE_RIGHT,   ///<  combination of left and right resize flags
       
    62 	RESIZE_RB     = RESIZE_RIGHT | RESIZE_BOTTOM,  ///<  combination of right and bottom resize flags
       
    63 	RESIZE_TB     = RESIZE_TOP   | RESIZE_BOTTOM,  ///<  combination of top and bottom resize flags
       
    64 	RESIZE_LRB    = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_BOTTOM, ///< combination of left, right and bottom resize flags
       
    65 	RESIZE_LRTB   = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_TOP | RESIZE_BOTTOM,  ///<  combination of all resize flags
       
    66 	RESIZE_RTB    = RESIZE_RIGHT | RESIZE_TOP    | RESIZE_BOTTOM, ///<  combination of right, top and bottom resize flag
       
    67 
       
    68 	/* The following flags are used by the system to specify what is disabled, hidden, or clicked
       
    69 	 * They are used in the same place as the above RESIZE_x flags, Widget visual_flags.
       
    70 	 * These states are used in exceptions. If nothing is specified, they will indicate
       
    71 	 * Enabled, visible or unclicked widgets*/
       
    72 	WIDG_DISABLED = 4,  ///< widget is greyed out, not available
       
    73 	WIDG_HIDDEN   = 5,  ///< widget is made invisible
       
    74 	WIDG_LOWERED  = 6,  ///< widget is paint lowered, a pressed button in fact
       
    75 };
       
    76 
       
    77 enum {
       
    78 	WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions
       
    79 };
       
    80 
       
    81 struct Widget {
       
    82 	byte type;                        ///< Widget type, see WindowWidgetTypes
       
    83 	byte display_flags;               ///< Resize direction, alignment, etc. during resizing, see ResizeFlags
       
    84 	byte color;                       ///< Widget colour, see docs/ottd-colourtext-palette.png
       
    85 	int16 left, right, top, bottom;   ///< The position offsets inside the window
       
    86 	uint16 data;                      ///< The String/Image or special code (list-matrixes) of a widget
       
    87 	StringID tooltips;                ///< Tooltips that are shown when rightclicking on a widget
       
    88 };
       
    89 
       
    90 enum FrameFlags {
       
    91 	FR_NONE         =  0,
       
    92 	FR_TRANSPARENT  =  1 << 0,  ///< Makes the background transparent if set
       
    93 	FR_BORDERONLY   =  1 << 4,  ///< Draw border only, no background
       
    94 	FR_LOWERED      =  1 << 5,  ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed)
       
    95 	FR_DARKENED     =  1 << 6,  ///< If set the background is darker, allows for lowered frames with normal background color when used with FR_LOWERED (ie. dropdown boxes)
       
    96 };
       
    97 
       
    98 DECLARE_ENUM_AS_BIT_SET(FrameFlags);
       
    99 
       
   100 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags);
       
   101 
       
   102 enum WindowEventCodes {
       
   103 	WE_CREATE,
       
   104 	WE_DESTROY,
       
   105 	WE_PAINT,
       
   106 	WE_KEYPRESS,
       
   107 	WE_CLICK,
       
   108 	WE_DOUBLE_CLICK,
       
   109 	WE_RCLICK,
       
   110 	WE_MOUSEOVER,
       
   111 	WE_MOUSELOOP,
       
   112 	WE_MOUSEWHEEL,
       
   113 	WE_TICK,
       
   114 	WE_4,
       
   115 	WE_TIMEOUT,
       
   116 	WE_PLACE_OBJ,
       
   117 	WE_ABORT_PLACE_OBJ,
       
   118 	WE_ON_EDIT_TEXT,
       
   119 	WE_ON_EDIT_TEXT_CANCEL,
       
   120 	WE_POPUPMENU_SELECT,
       
   121 	WE_POPUPMENU_OVER,
       
   122 	WE_DRAGDROP,
       
   123 	WE_PLACE_DRAG,
       
   124 	WE_PLACE_MOUSEUP,
       
   125 	WE_PLACE_PRESIZE,
       
   126 	WE_DROPDOWN_SELECT,
       
   127 	WE_RESIZE,
       
   128 	WE_MESSAGE,
       
   129 	WE_SCROLL,
       
   130 	WE_INVALIDATE_DATA,
       
   131 };
       
   132 
       
   133 struct WindowEvent {
       
   134 	byte event;
       
   135 	union {
       
   136 		struct {
       
   137 			void *data;
       
   138 		} create;
       
   139 
       
   140 		struct {
       
   141 			Point pt;
       
   142 			int widget;
       
   143 		} click;
       
   144 
       
   145 		struct {
       
   146 			Point pt;
       
   147 			TileIndex tile;
       
   148 			TileIndex starttile;
       
   149 			ViewportPlaceMethod select_method;
       
   150 			byte select_proc;
       
   151 		} place;
       
   152 
       
   153 		struct {
       
   154 			Point pt;
       
   155 			int widget;
       
   156 		} dragdrop;
       
   157 
       
   158 		struct {
       
   159 			Point size;
       
   160 			Point diff;
       
   161 		} sizing;
       
   162 
       
   163 		struct {
       
   164 			char *str;
       
   165 		} edittext;
       
   166 
       
   167 		struct {
       
   168 			Point pt;
       
   169 		} popupmenu;
       
   170 
       
   171 		struct {
       
   172 			int button;
       
   173 			int index;
       
   174 		} dropdown;
       
   175 
       
   176 		struct {
       
   177 			Point pt;
       
   178 			int widget;
       
   179 		} mouseover;
       
   180 
       
   181 		struct {
       
   182 			bool cont;      ///< continue the search? (default true)
       
   183 			uint16 key;     ///< 16-bit Unicode value of the key
       
   184 			uint16 keycode; ///< untranslated key (including shift-state)
       
   185 		} keypress;
       
   186 
       
   187 		struct {
       
   188 			int msg;      ///< message to be sent
       
   189 			int wparam;   ///< additional message-specific information
       
   190 			int lparam;   ///< additional message-specific information
       
   191 		} message;
       
   192 
       
   193 		struct {
       
   194 			Point delta;   ///< delta position against position of last call
       
   195 		} scroll;
       
   196 
       
   197 		struct {
       
   198 			int wheel;     ///< how much was 'wheel'd'
       
   199 		} wheel;
       
   200 	} we;
       
   201 };
       
   202 
       
   203 struct WindowDesc {
       
   204 	int16 left, top, minimum_width, minimum_height, default_width, default_height;
       
   205 	WindowClass cls;
       
   206 	WindowClass parent_cls;
       
   207 	uint32 flags;
       
   208 	const Widget *widgets;
       
   209 	WindowProc *proc;
       
   210 };
       
   211 
       
   212 enum WindowDefaultFlag {
       
   213 	WDF_STD_TOOLTIPS    =   1 << 0, ///< use standard routine when displaying tooltips
       
   214 	WDF_DEF_WIDGET      =   1 << 1, ///< default widget control for some widgets in the on click event
       
   215 	WDF_STD_BTN         =   1 << 2, ///< default handling for close and drag widgets (widget no 0 and 1)
       
   216 
       
   217 	WDF_UNCLICK_BUTTONS =   1 << 4, ///< Unclick buttons when the window event times out */
       
   218 	WDF_STICKY_BUTTON   =   1 << 5, ///< Set window to sticky mode; they are not closed unless closed with 'X' (widget 2)
       
   219 	WDF_RESIZABLE       =   1 << 6, ///< A window can be resized
       
   220 	WDF_MODAL           =   1 << 7, ///< The window is a modal child of some other window, meaning the parent is 'inactive'
       
   221 };
       
   222 
       
   223 /* can be used as x or y coordinates to cause a specific placement */
       
   224 enum WindowDefaultPosition {
       
   225 	WDP_AUTO      = -1, ///< Find a place automatically
       
   226 	WDP_CENTER    = -2, ///< Center the window (left/right or top/bottom)
       
   227 	WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar
       
   228 	WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar
       
   229 };
       
   230 
       
   231 struct Textbuf {
       
   232 	char *buf;                  ///< buffer in which text is saved
       
   233 	uint16 maxlength, maxwidth; ///< the maximum size of the buffer. Maxwidth specifies screensize in pixels, maxlength is in bytes
       
   234 	uint16 length, width;       ///< the current size of the string. Width specifies screensize in pixels, length is in bytes
       
   235 	bool caret;                 ///< is the caret ("_") visible or not
       
   236 	uint16 caretpos;            ///< the current position of the caret in the buffer, in bytes
       
   237 	uint16 caretxoffs;          ///< the current position of the caret in pixels
       
   238 };
       
   239 
       
   240 #define WP(ptr, str) (*(str*)(ptr)->custom)
       
   241 /* You cannot 100% reliably calculate the biggest custom struct as
       
   242  * the number of pointers in it and alignment will have a huge impact.
       
   243  * 96 is the largest window-size for 64-bit machines currently */
       
   244 #define WINDOW_CUSTOM_SIZE 96
       
   245 
       
   246 struct Scrollbar {
       
   247 	uint16 count, cap, pos;
       
   248 };
       
   249 
       
   250 struct ResizeInfo {
       
   251 	uint width; ///< Minimum width and height
       
   252 	uint height;
       
   253 	uint step_width; ///< In how big steps the width and height go
       
   254 	uint step_height;
       
   255 };
       
   256 
       
   257 struct WindowMessage {
       
   258 	int msg;
       
   259 	int wparam;
       
   260 	int lparam;
       
   261 };
       
   262 
       
   263 struct Window {
       
   264 	uint16 flags4;
       
   265 	WindowClass window_class;
       
   266 	WindowNumber window_number;
       
   267 
       
   268 	int left, top;
       
   269 	int width, height;
       
   270 
       
   271 	Scrollbar hscroll, vscroll, vscroll2;
       
   272 	ResizeInfo resize;
       
   273 
       
   274 	byte caption_color;
       
   275 
       
   276 	WindowProc *wndproc;
       
   277 	ViewPort *viewport;
       
   278 	const Widget *original_widget;
       
   279 	Widget *widget;
       
   280 	uint widget_count;
       
   281 	uint32 desc_flags;
       
   282 
       
   283 	WindowMessage message;
       
   284 	Window *parent;
       
   285 	byte custom[WINDOW_CUSTOM_SIZE];
       
   286 
       
   287 	void HandleButtonClick(byte widget);
       
   288 
       
   289 	void SetWidgetDisabledState(byte widget_index, bool disab_stat);
       
   290 	void DisableWidget(byte widget_index);
       
   291 	void EnableWidget(byte widget_index);
       
   292 	bool IsWidgetDisabled(byte widget_index) const;
       
   293 	void SetWidgetHiddenState(byte widget_index, bool hidden_stat);
       
   294 	void HideWidget(byte widget_index);
       
   295 	void ShowWidget(byte widget_index);
       
   296 	bool IsWidgetHidden(byte widget_index) const;
       
   297 	void SetWidgetLoweredState(byte widget_index, bool lowered_stat);
       
   298 	void ToggleWidgetLoweredState(byte widget_index);
       
   299 	void LowerWidget(byte widget_index);
       
   300 	void RaiseWidget(byte widget_index);
       
   301 	bool IsWidgetLowered(byte widget_index) const;
       
   302 
       
   303 	void RaiseButtons();
       
   304 	void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
       
   305 	void CDECL SetWidgetsHiddenState(bool hidden_stat, int widgets, ...);
       
   306 	void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
       
   307 	void InvalidateWidget(byte widget_index) const;
       
   308 };
       
   309 
       
   310 struct querystr_d {
       
   311 	StringID caption;
       
   312 	Textbuf text;
       
   313 	const char *orig;
       
   314 	CharSetFilter afilter;
       
   315 	bool handled;
       
   316 };
       
   317 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d));
       
   318 
       
   319 struct chatquerystr_d : public querystr_d {
       
   320 	int dest;
       
   321 };
       
   322 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(chatquerystr_d));
       
   323 
       
   324 struct menu_d {
       
   325 	byte item_count;      ///< follow_vehicle
       
   326 	byte sel_index;       ///< scrollpos_x
       
   327 	byte main_button;     ///< scrollpos_y
       
   328 	byte action_id;
       
   329 	StringID string_id;   ///< unk30
       
   330 	uint16 checked_items; ///< unk32
       
   331 	byte disabled_items;
       
   332 };
       
   333 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
       
   334 
       
   335 struct def_d {
       
   336 	int16 data_1, data_2, data_3;
       
   337 	int16 data_4, data_5;
       
   338 	bool close;
       
   339 	byte byte_1;
       
   340 };
       
   341 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));
       
   342 
       
   343 struct void_d {
       
   344 	void *data;
       
   345 };
       
   346 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(void_d));
       
   347 
       
   348 struct tree_d {
       
   349 	uint16 base;
       
   350 	uint16 count;
       
   351 };
       
   352 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d));
       
   353 
       
   354 struct tooltips_d {
       
   355 	StringID string_id;
       
   356 	byte paramcount;
       
   357 	uint64 params[5];
       
   358 };
       
   359 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
       
   360 
       
   361 struct buildvehicle_d {
       
   362 	VehicleType vehicle_type;
       
   363 	union {
       
   364 		RailTypeByte railtype;
       
   365 		AirportFTAClass::Flags flags;
       
   366 		RoadTypes roadtypes;
       
   367 	} filter;
       
   368 	byte sel_index;  ///< deprecated value, used for 'unified' ship and road
       
   369 	bool descending_sort_order;
       
   370 	byte sort_criteria;
       
   371 	bool regenerate_list;
       
   372 	EngineID sel_engine;
       
   373 	EngineID rename_engine;
       
   374 	EngineList eng_list;
       
   375 };
       
   376 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(buildvehicle_d));
       
   377 
       
   378 struct replaceveh_d {
       
   379 	byte sel_index[2];
       
   380 	EngineID sel_engine[2];
       
   381 	uint16 count[2];
       
   382 	bool wagon_btnstate; ///< true means engine is selected
       
   383 	EngineList list[2];
       
   384 	bool update_left;
       
   385 	bool update_right;
       
   386 	bool init_lists;
       
   387 	GroupID sel_group;
       
   388 };
       
   389 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d));
       
   390 
       
   391 struct depot_d {
       
   392 	VehicleID sel;
       
   393 	VehicleType type;
       
   394 	bool generate_list;
       
   395 	uint16 engine_list_length;
       
   396 	uint16 wagon_list_length;
       
   397 	uint16 engine_count;
       
   398 	uint16 wagon_count;
       
   399 	Vehicle **vehicle_list;
       
   400 	Vehicle **wagon_list;
       
   401 };
       
   402 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(depot_d));
       
   403 
       
   404 struct order_d {
       
   405 	int sel;
       
   406 };
       
   407 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(order_d));
       
   408 
       
   409 struct vehicledetails_d {
       
   410 	byte tab;
       
   411 };
       
   412 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehicledetails_d));
       
   413 
       
   414 struct smallmap_d {
       
   415 	int32 scroll_x;
       
   416 	int32 scroll_y;
       
   417 	int32 subscroll;
       
   418 };
       
   419 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(smallmap_d));
       
   420 
       
   421 /* player face selection window */
       
   422 struct facesel_d {
       
   423 	PlayerFace face; // player face bits
       
   424 	bool advanced;   // advance player face selection window
       
   425 };
       
   426 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(facesel_d));
       
   427 
       
   428 struct refit_d {
       
   429 	int sel;
       
   430 	struct RefitOption *cargo;
       
   431 	struct RefitList *list;
       
   432 	uint length;
       
   433 	VehicleOrderID order;
       
   434 };
       
   435 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d));
       
   436 
       
   437 struct vp_d {
       
   438 	VehicleID follow_vehicle;
       
   439 	int32 scrollpos_x;
       
   440 	int32 scrollpos_y;
       
   441 	int32 dest_scrollpos_x;
       
   442 	int32 dest_scrollpos_y;
       
   443 };
       
   444 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp_d));
       
   445 
       
   446 struct news_d {
       
   447 	uint16 follow_vehicle;
       
   448 	int32 scrollpos_x;
       
   449 	int32 scrollpos_y;
       
   450 	int32 dest_scrollpos_x;
       
   451 	int32 dest_scrollpos_y;
       
   452 	NewsItem *ni;
       
   453 };
       
   454 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(news_d));
       
   455 
       
   456 struct highscore_d {
       
   457 	uint32 background_img;
       
   458 	int8 rank;
       
   459 };
       
   460 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d));
       
   461 
       
   462 struct scroller_d {
       
   463 	int height;
       
   464 	uint16 counter;
       
   465 };
       
   466 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d));
       
   467 
       
   468 enum SortListFlags {
       
   469 	VL_NONE    = 0,      ///< no sort
       
   470 	VL_DESC    = 1 << 0, ///< sort descending or ascending
       
   471 	VL_RESORT  = 1 << 1, ///< instruct the code to resort the list in the next loop
       
   472 	VL_REBUILD = 1 << 2, ///< create sort-listing to use for qsort and friends
       
   473 	VL_END     = 1 << 3,
       
   474 };
       
   475 
       
   476 DECLARE_ENUM_AS_BIT_SET(SortListFlags);
       
   477 
       
   478 struct Listing {
       
   479 	bool order;    ///< Ascending/descending
       
   480 	byte criteria; ///< Sorting criteria
       
   481 };
       
   482 
       
   483 struct list_d {
       
   484 	uint16 list_length;  ///< length of the list being sorted
       
   485 	byte sort_type;      ///< what criteria to sort on
       
   486 	SortListFlags flags; ///< used to control sorting/resorting/etc.
       
   487 	uint16 resort_timer; ///< resort list after a given amount of ticks if set
       
   488 };
       
   489 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d));
       
   490 
       
   491 struct message_d {
       
   492 	int msg;
       
   493 	int wparam;
       
   494 	int lparam;
       
   495 };
       
   496 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(message_d));
       
   497 
       
   498 struct dropdown_d {
       
   499 	uint32 disabled_state;
       
   500 	uint32 hidden_state;
       
   501 	WindowClass parent_wnd_class;
       
   502 	WindowNumber parent_wnd_num;
       
   503 	byte parent_button;
       
   504 	byte num_items;
       
   505 	byte selected_index;
       
   506 	const StringID *items;
       
   507 	byte click_delay;
       
   508 	bool drag_mode;
       
   509 };
       
   510 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(dropdown_d));
       
   511 
       
   512 struct vehiclelist_d {
       
   513 	const Vehicle** sort_list;  // List of vehicles (sorted)
       
   514 	Listing *_sorting;          // pointer to the appropiate subcategory of _sorting
       
   515 	uint16 length_of_sort_list; // Keeps track of how many vehicle pointers sort list got space for
       
   516 	VehicleType vehicle_type;   // The vehicle type that is sorted
       
   517 	list_d l;                   // General list struct
       
   518 };
       
   519 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
       
   520 
       
   521 struct grouplist_d {
       
   522 	const Group **sort_list;
       
   523 	list_d l;                   // General list struct
       
   524 };
       
   525 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(grouplist_d));
       
   526 
       
   527 struct groupveh_d : vehiclelist_d {
       
   528 	GroupID group_sel;
       
   529 	VehicleID vehicle_sel;
       
   530 
       
   531 	grouplist_d gl;
       
   532 };
       
   533 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(groupveh_d));
       
   534 
       
   535 /****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/
       
   536 enum WindowWidgetBehaviours {
       
   537 	WWB_PUSHBUTTON  = 1 << 5,
       
   538 
       
   539 	WWB_MASK        = 0xE0,
       
   540 };
       
   541 
       
   542 
       
   543 enum WindowWidgetTypes {
       
   544 	WWT_EMPTY,
       
   545 
       
   546 	WWT_PANEL,      ///< simple depressed panel
       
   547 	WWT_INSET,      ///< pressed (inset) panel, most commonly used as combo box _text_ area
       
   548 	WWT_IMGBTN,     ///< button with image
       
   549 	WWT_IMGBTN_2,   ///< button with diff image when clicked
       
   550 
       
   551 	WWT_TEXTBTN,    ///< button with text
       
   552 	WWT_TEXTBTN_2,  ///< button with diff text when clicked
       
   553 	WWT_LABEL,      ///< centered label
       
   554 	WWT_TEXT,       ///< pure simple text
       
   555 	WWT_MATRIX,
       
   556 	WWT_SCROLLBAR,
       
   557 	WWT_FRAME,      ///< frame
       
   558 	WWT_CAPTION,
       
   559 
       
   560 	WWT_HSCROLLBAR,
       
   561 	WWT_STICKYBOX,
       
   562 	WWT_SCROLL2BAR, ///< 2nd vertical scrollbar
       
   563 	WWT_RESIZEBOX,
       
   564 	WWT_CLOSEBOX,
       
   565 	WWT_LAST,       ///< Last Item. use WIDGETS_END to fill up padding!!
       
   566 
       
   567 	WWT_MASK = 0x1F,
       
   568 
       
   569 	WWT_PUSHBTN     = WWT_PANEL   | WWB_PUSHBUTTON,
       
   570 	WWT_PUSHTXTBTN  = WWT_TEXTBTN | WWB_PUSHBUTTON,
       
   571 	WWT_PUSHIMGBTN  = WWT_IMGBTN  | WWB_PUSHBUTTON,
       
   572 };
       
   573 
       
   574 #define WIDGETS_END WWT_LAST,   RESIZE_NONE,     0,     0,     0,     0,     0, 0, STR_NULL
       
   575 
       
   576 enum WindowFlags {
       
   577 	WF_TIMEOUT_SHL       = 0,
       
   578 	WF_TIMEOUT_MASK      = 7,
       
   579 	WF_DRAGGING          = 1 <<  3,
       
   580 	WF_SCROLL_UP         = 1 <<  4,
       
   581 	WF_SCROLL_DOWN       = 1 <<  5,
       
   582 	WF_SCROLL_MIDDLE     = 1 <<  6,
       
   583 	WF_HSCROLL           = 1 <<  7,
       
   584 	WF_SIZING            = 1 <<  8,
       
   585 	WF_STICKY            = 1 <<  9,
       
   586 
       
   587 	WF_DISABLE_VP_SCROLL = 1 << 10,
       
   588 
       
   589 	WF_WHITE_BORDER_ONE  = 1 << 11,
       
   590 	WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE,
       
   591 	WF_SCROLL2           = 1 << 13,
       
   592 };
       
   593 
       
   594 /* window.cpp */
       
   595 void CallWindowEventNP(Window *w, int event);
       
   596 void CallWindowTickEvent();
       
   597 
       
   598 /**
       
   599  * Marks the window as dirty for repaint.
       
   600  *
       
   601  * @ingroup dirty
       
   602  */
       
   603 void SetWindowDirty(const Window *w);
       
   604 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam);
       
   605 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam);
       
   606 
       
   607 Window *FindWindowById(WindowClass cls, WindowNumber number);
       
   608 void DeleteWindow(Window *w);
       
   609 void DeletePlayerWindows(PlayerID pi);
       
   610 void ChangeWindowOwner(PlayerID old_player, PlayerID new_player);
       
   611 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
       
   612 Window *FindWindowFromPt(int x, int y);
       
   613 
       
   614 bool IsWindowOfPrototype(const Window *w, const Widget *widget);
       
   615 void AssignWidgetToWindow(Window *w, const Widget *widget);
       
   616 Window *AllocateWindow(
       
   617 							int x,
       
   618 							int y,
       
   619 							int width,
       
   620 							int height,
       
   621 							WindowProc *proc,
       
   622 							WindowClass cls,
       
   623 							const Widget *widget,
       
   624 							void *data = NULL);
       
   625 
       
   626 Window *AllocateWindowDesc(const WindowDesc *desc, void *data = NULL);
       
   627 Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data = NULL);
       
   628 
       
   629 void DrawWindowViewport(const Window *w);
       
   630 void ResizeWindow(Window *w, int x, int y);
       
   631 
       
   632 void InitWindowSystem();
       
   633 void UnInitWindowSystem();
       
   634 void ResetWindowSystem();
       
   635 int GetMenuItemIndex(const Window *w, int x, int y);
       
   636 void InputLoop();
       
   637 void InvalidateThisWindowData(Window *w);
       
   638 void InvalidateWindowData(WindowClass cls, WindowNumber number);
       
   639 void RelocateAllWindows(int neww, int newh);
       
   640 int PositionMainToolbar(Window *w);
       
   641 
       
   642 /* misc_gui.cpp */
       
   643 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[]);
       
   644 static inline void GuiShowTooltips(StringID str)
       
   645 {
       
   646 	GuiShowTooltipsWithArgs(str, 0, NULL);
       
   647 }
       
   648 
       
   649 /* widget.cpp */
       
   650 int GetWidgetFromPos(const Window *w, int x, int y);
       
   651 void DrawWindowWidgets(const Window *w);
       
   652 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask);
       
   653 
       
   654 
       
   655 Window *GetCallbackWnd();
       
   656 void DeleteNonVitalWindows();
       
   657 void DeleteAllNonVitalWindows();
       
   658 void HideVitalWindows();
       
   659 void ShowVitalWindows();
       
   660 Window **FindWindowZPosition(const Window *w);
       
   661 
       
   662 /* window.cpp */
       
   663 extern Window *_z_windows[];
       
   664 extern Window **_last_z_window;
       
   665 #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++)
       
   666 
       
   667 VARDEF Point _cursorpos_drag_start;
       
   668 
       
   669 VARDEF int _scrollbar_start_pos;
       
   670 VARDEF int _scrollbar_size;
       
   671 VARDEF byte _scroller_click_timeout;
       
   672 
       
   673 VARDEF bool _scrolling_scrollbar;
       
   674 VARDEF bool _scrolling_viewport;
       
   675 VARDEF bool _popup_menu_active;
       
   676 
       
   677 VARDEF byte _special_mouse_mode;
       
   678 enum SpecialMouseMode {
       
   679 	WSM_NONE     = 0,
       
   680 	WSM_DRAGDROP = 1,
       
   681 	WSM_SIZING   = 2,
       
   682 	WSM_PRESIZE  = 3,
       
   683 };
       
   684 
       
   685 void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y);
       
   686 
       
   687 /** Evenly distribute some widgets when resizing horizontally (often a button row)
       
   688  *  The widgets are presumed to be in a line and numberef from left to right (without gaps)
       
   689  * @param w widow to modify
       
   690  * @param left The leftmost widget to resize
       
   691  * @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT
       
   692  */
       
   693 void ResizeButtons(Window *w, byte left, byte right);
       
   694 
       
   695 
       
   696 /**
       
   697  * Sets the enabled/disabled status of a widget.
       
   698  * By default, widgets are enabled.
       
   699  * On certain conditions, they have to be disabled.
       
   700  * @param widget_index : index of this widget in the window
       
   701  * @param disab_stat : status to use ie: disabled = true, enabled = false
       
   702  */
       
   703 inline void Window::SetWidgetDisabledState(byte widget_index, bool disab_stat)
       
   704 {
       
   705 	assert(widget_index < this->widget_count);
       
   706 	SB(this->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat);
       
   707 }
       
   708 
       
   709 /**
       
   710  * Sets a widget to disabled.
       
   711  * @param widget_index : index of this widget in the window
       
   712  */
       
   713 inline void Window::DisableWidget(byte widget_index)
       
   714 {
       
   715 	SetWidgetDisabledState(widget_index, true);
       
   716 }
       
   717 
       
   718 /**
       
   719  * Sets a widget to Enabled.
       
   720  * @param widget_index : index of this widget in the window
       
   721  */
       
   722 inline void Window::EnableWidget(byte widget_index)
       
   723 {
       
   724 	SetWidgetDisabledState(widget_index, false);
       
   725 }
       
   726 
       
   727 /**
       
   728  * Gets the enabled/disabled status of a widget.
       
   729  * @param widget_index : index of this widget in the window
       
   730  * @return status of the widget ie: disabled = true, enabled = false
       
   731  */
       
   732 inline bool Window::IsWidgetDisabled(byte widget_index) const
       
   733 {
       
   734 	assert(widget_index < this->widget_count);
       
   735 	return HasBit(this->widget[widget_index].display_flags, WIDG_DISABLED);
       
   736 }
       
   737 
       
   738 /**
       
   739  * Sets the hidden/shown status of a widget.
       
   740  * By default, widgets are visible.
       
   741  * On certain conditions, they have to be hidden.
       
   742  * @param widget_index index of this widget in the window
       
   743  * @param hidden_stat status to use ie. hidden = true, visible = false
       
   744  */
       
   745 inline void Window::SetWidgetHiddenState(byte widget_index, bool hidden_stat)
       
   746 {
       
   747 	assert(widget_index < this->widget_count);
       
   748 	SB(this->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat);
       
   749 }
       
   750 
       
   751 /**
       
   752  * Sets a widget hidden.
       
   753  * @param widget_index : index of this widget in the window
       
   754  */
       
   755 inline void Window::HideWidget(byte widget_index)
       
   756 {
       
   757 	SetWidgetHiddenState(widget_index, true);
       
   758 }
       
   759 
       
   760 /**
       
   761  * Sets a widget visible.
       
   762  * @param widget_index : index of this widget in the window
       
   763  */
       
   764 inline void Window::ShowWidget(byte widget_index)
       
   765 {
       
   766 	SetWidgetHiddenState(widget_index, false);
       
   767 }
       
   768 
       
   769 /**
       
   770  * Gets the visibility of a widget.
       
   771  * @param widget_index : index of this widget in the window
       
   772  * @return status of the widget ie: hidden = true, visible = false
       
   773  */
       
   774 inline bool Window::IsWidgetHidden(byte widget_index) const
       
   775 {
       
   776 	assert(widget_index < this->widget_count);
       
   777 	return HasBit(this->widget[widget_index].display_flags, WIDG_HIDDEN);
       
   778 }
       
   779 
       
   780 /**
       
   781  * Sets the lowered/raised status of a widget.
       
   782  * @param widget_index : index of this widget in the window
       
   783  * @param lowered_stat : status to use ie: lowered = true, raised = false
       
   784  */
       
   785 inline void Window::SetWidgetLoweredState(byte widget_index, bool lowered_stat)
       
   786 {
       
   787 	assert(widget_index < this->widget_count);
       
   788 	SB(this->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat);
       
   789 }
       
   790 
       
   791 /**
       
   792  * Invert the lowered/raised  status of a widget.
       
   793  * @param widget_index : index of this widget in the window
       
   794  */
       
   795 inline void Window::ToggleWidgetLoweredState(byte widget_index)
       
   796 {
       
   797 	assert(widget_index < this->widget_count);
       
   798 	ToggleBit(this->widget[widget_index].display_flags, WIDG_LOWERED);
       
   799 }
       
   800 
       
   801 /**
       
   802  * Marks a widget as lowered.
       
   803  * @param widget_index : index of this widget in the window
       
   804  */
       
   805 inline void Window::LowerWidget(byte widget_index)
       
   806 {
       
   807 	SetWidgetLoweredState(widget_index, true);
       
   808 }
       
   809 
       
   810 /**
       
   811  * Marks a widget as raised.
       
   812  * @param widget_index : index of this widget in the window
       
   813  */
       
   814 inline void Window::RaiseWidget(byte widget_index)
       
   815 {
       
   816 	SetWidgetLoweredState(widget_index, false);
       
   817 }
       
   818 
       
   819 /**
       
   820  * Gets the lowered state of a widget.
       
   821  * @param widget_index : index of this widget in the window
       
   822  * @return status of the widget ie: lowered = true, raised= false
       
   823  */
       
   824 inline bool Window::IsWidgetLowered(byte widget_index) const
       
   825 {
       
   826 	assert(widget_index < this->widget_count);
       
   827 	return HasBit(this->widget[widget_index].display_flags, WIDG_LOWERED);
       
   828 }
       
   829 
       
   830 #endif /* WINDOW_H */