window.h
branchcustombridgeheads
changeset 5623 ef2a8a524a95
parent 5268 cbff87066429
equal deleted inserted replaced
5622:2f0cb276d32a 5623:ef2a8a524a95
    84 } FrameFlags;
    84 } FrameFlags;
    85 
    85 
    86 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags);
    86 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags);
    87 
    87 
    88 enum WindowEventCodes {
    88 enum WindowEventCodes {
    89 	WE_CLICK               =  0,
    89 	WE_CREATE,
    90 	WE_PAINT               =  1,
    90 	WE_DESTROY,
    91 	WE_MOUSELOOP           =  2,
    91 	WE_PAINT,
    92 	WE_TICK                =  3,
    92 	WE_KEYPRESS,
    93 	WE_4                   =  4,
    93 	WE_CLICK,
    94 	WE_TIMEOUT             =  5,
    94 	WE_RCLICK,
    95 	WE_PLACE_OBJ           =  6,
    95 	WE_MOUSEOVER,
    96 	WE_ABORT_PLACE_OBJ     =  7,
    96 	WE_MOUSELOOP,
    97 	WE_DESTROY             =  8,
    97 	WE_MOUSEWHEEL,
    98 	WE_ON_EDIT_TEXT        =  9,
    98 	WE_TICK,
    99 	WE_POPUPMENU_SELECT    = 10,
    99 	WE_4,
   100 	WE_POPUPMENU_OVER      = 11,
   100 	WE_TIMEOUT,
   101 	WE_DRAGDROP            = 12,
   101 	WE_PLACE_OBJ,
   102 	WE_PLACE_DRAG          = 13,
   102 	WE_ABORT_PLACE_OBJ,
   103 	WE_PLACE_MOUSEUP       = 14,
   103 	WE_ON_EDIT_TEXT,
   104 	WE_PLACE_PRESIZE       = 15,
   104 	WE_ON_EDIT_TEXT_CANCEL,
   105 	WE_DROPDOWN_SELECT     = 16,
   105 	WE_POPUPMENU_SELECT,
   106 	WE_RCLICK              = 17,
   106 	WE_POPUPMENU_OVER,
   107 	WE_KEYPRESS            = 18,
   107 	WE_DRAGDROP,
   108 	WE_CREATE              = 19,
   108 	WE_PLACE_DRAG,
   109 	WE_MOUSEOVER           = 20,
   109 	WE_PLACE_MOUSEUP,
   110 	WE_ON_EDIT_TEXT_CANCEL = 21,
   110 	WE_PLACE_PRESIZE,
   111 	WE_RESIZE              = 22,
   111 	WE_DROPDOWN_SELECT,
   112 	WE_MESSAGE             = 23,
   112 	WE_RESIZE,
   113 	WE_SCROLL              = 24,
   113 	WE_MESSAGE,
   114 	WE_MOUSEWHEEL          = 25,
   114 	WE_SCROLL,
   115 	WE_INVALIDATE_DATA     = 26,
   115 	WE_INVALIDATE_DATA,
   116 };
   116 };
   117 
   117 
   118 struct WindowEvent {
   118 struct WindowEvent {
   119 	byte event;
   119 	byte event;
   120 	union {
   120 	union {
   261 	uint32 flags;
   261 	uint32 flags;
   262 	const Widget *widgets;
   262 	const Widget *widgets;
   263 	WindowProc *proc;
   263 	WindowProc *proc;
   264 } WindowDesc;
   264 } WindowDesc;
   265 
   265 
   266 enum {
   266 enum WindowDefaultFlag {
   267 	WDF_STD_TOOLTIPS    =  1, /* use standard routine when displaying tooltips */
   267 	WDF_STD_TOOLTIPS    =   1, /* use standard routine when displaying tooltips */
   268 	WDF_DEF_WIDGET      =  2, /* default widget control for some widgets in the on click event */
   268 	WDF_DEF_WIDGET      =   2, /* default widget control for some widgets in the on click event */
   269 	WDF_STD_BTN         =  4, /* default handling for close and drag widgets (widget no 0 and 1) */
   269 	WDF_STD_BTN         =   4, /* default handling for close and drag widgets (widget no 0 and 1) */
   270 
   270 
   271 	WDF_UNCLICK_BUTTONS = 16, /* Unclick buttons when the window event times out */
   271 	WDF_UNCLICK_BUTTONS =  16, /* Unclick buttons when the window event times out */
   272 	WDF_STICKY_BUTTON   = 32, /* Set window to sticky mode; they are not closed unless closed with 'X' (widget 2) */
   272 	WDF_STICKY_BUTTON   =  32, /* Set window to sticky mode; they are not closed unless closed with 'X' (widget 2) */
   273 	WDF_RESIZABLE       = 64, /* A window can be resized */
   273 	WDF_RESIZABLE       =  64, /* A window can be resized */
       
   274 	WDF_MODAL           = 128, /* The window is a modal child of some other window, meaning the parent is 'inactive' */
   274 };
   275 };
   275 
   276 
   276 /* can be used as x or y coordinates to cause a specific placement */
   277 /* can be used as x or y coordinates to cause a specific placement */
   277 enum {
   278 enum WindowDefaultPosition {
   278 	WDP_AUTO      = -1, ///< Find a place automatically
   279 	WDP_AUTO      = -1, ///< Find a place automatically
   279 	WDP_CENTER    = -2, ///< Center the window (left/right or top/bottom)
   280 	WDP_CENTER    = -2, ///< Center the window (left/right or top/bottom)
   280 	WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar
   281 	WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar
   281 	WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar
   282 	WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar
   282 };
   283 };
   283 
   284 
   284 typedef struct Textbuf {
   285 typedef struct Textbuf {
   285 	char *buf;                  /* buffer in which text is saved */
   286 	char *buf;                  /* buffer in which text is saved */
   286 	uint16 maxlength, maxwidth; /* the maximum size of the buffer. Maxwidth specifies screensize in pixels */
   287 	uint16 maxlength, maxwidth; /* the maximum size of the buffer. Maxwidth specifies screensize in pixels, maxlength is in bytes */
   287 	uint16 length, width;       /* the current size of the string. Width specifies screensize in pixels */
   288 	uint16 length, width;       /* the current size of the string. Width specifies screensize in pixels, length is in bytes */
   288 	bool caret;                 /* is the caret ("_") visible or not */
   289 	bool caret;                 /* is the caret ("_") visible or not */
   289 	uint16 caretpos;            /* the current position of the caret in the buffer */
   290 	uint16 caretpos;            /* the current position of the caret in the buffer, in bytes */
   290 	uint16 caretxoffs;          /* the current position of the caret in pixels */
   291 	uint16 caretxoffs;          /* the current position of the caret in pixels */
   291 } Textbuf;
   292 } Textbuf;
   292 
   293 
   293 #define WP(ptr,str) (*(str*)(ptr)->custom)
   294 #define WP(ptr,str) (*(str*)(ptr)->custom)
   294 /* You cannot 100% reliably calculate the biggest custom struct as
   295 /* You cannot 100% reliably calculate the biggest custom struct as
   333 	Widget *widget;
   334 	Widget *widget;
   334 	uint widget_count;
   335 	uint widget_count;
   335 	uint32 desc_flags;
   336 	uint32 desc_flags;
   336 
   337 
   337 	WindowMessage message;
   338 	WindowMessage message;
       
   339 	Window *parent;
   338 	byte custom[WINDOW_CUSTOM_SIZE];
   340 	byte custom[WINDOW_CUSTOM_SIZE];
   339 };
   341 };
   340 
   342 
   341 typedef struct querystr_d {
   343 typedef struct querystr_d {
   342 	StringID caption;
   344 	StringID caption;
   343 	WindowClass wnd_class;
       
   344 	WindowNumber wnd_num;
       
   345 	Textbuf text;
   345 	Textbuf text;
   346 	const char *orig;
   346 	const char *orig;
   347 	CharSetFilter afilter;
   347 	CharSetFilter afilter;
       
   348 	bool handled;
   348 } querystr_d;
   349 } querystr_d;
   349 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d));
   350 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d));
   350 
       
   351 typedef struct query_d {
       
   352 	StringID caption;
       
   353 	StringID message;
       
   354 	WindowClass wnd_class;
       
   355 	WindowNumber wnd_num;
       
   356 	void (*ok_cancel_callback)(bool ok_clicked);
       
   357 	bool calledback;
       
   358 } query_d;
       
   359 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(query_d));
       
   360 
   351 
   361 typedef struct {
   352 typedef struct {
   362 	byte item_count;      /* follow_vehicle */
   353 	byte item_count;      /* follow_vehicle */
   363 	byte sel_index;       /* scrollpos_x */
   354 	byte sel_index;       /* scrollpos_x */
   364 	byte main_button;     /* scrollpos_y */
   355 	byte main_button;     /* scrollpos_y */
   595 	WF_STICKY            = 1 <<  9,
   586 	WF_STICKY            = 1 <<  9,
   596 
   587 
   597 	WF_DISABLE_VP_SCROLL = 1 << 10,
   588 	WF_DISABLE_VP_SCROLL = 1 << 10,
   598 
   589 
   599 	WF_WHITE_BORDER_ONE  = 1 << 11,
   590 	WF_WHITE_BORDER_ONE  = 1 << 11,
   600 	WF_WHITE_BORDER_MASK = 3 << 11,
   591 	WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE,
   601 	WF_SCROLL2           = 1 << 13,
   592 	WF_SCROLL2           = 1 << 13,
   602 };
   593 };
   603 
   594 
   604 /* window.c */
   595 /* window.c */
   605 void CallWindowEventNP(Window *w, int event);
   596 void CallWindowEventNP(Window *w, int event);