1 /*
2  * Copyright (c) 1997 - 2003 Hansj�rg Malthaner
3  *
4  * This file is part of the Simutrans project under the artistic license.
5  * (see license.txt)
6  */
7 
8 /*
9  * The function implements a WindowManager 'Object'
10  */
11 
12 #ifndef simwin_h
13 #define simwin_h
14 
15 #include <stddef.h> // for ptrdiff_t
16 
17 #include "../simtypes.h"
18 #include "../simconst.h"
19 
20 class karte_t;
21 class scr_coord;
22 class loadsave_t;
23 class gui_frame_t;
24 class gui_component_t;
25 struct event_t;
26 
27 /* Types for the window */
28 enum wintype {
29 	w_info         = 1, // A info window
30 	w_do_not_delete= 2, // A window whose GUI object should not be deleted on close
31 	w_no_overlap   = 4, // try to place it below a previous window with the same flag
32 	w_time_delete  = 8  // deletion after MESG_WAIT has elapsed
33 };
34 ENUM_BITSET(wintype)
35 
36 
37 enum magic_numbers {
38 	magic_none = -1,
39 	magic_reserved = 0,
40 
41 	// from here on, delete second 'new'-ed object in create_win
42 	magic_settings_frame_t,
43 	magic_sprachengui_t,
44 	magic_themes,
45 	magic_welt_gui_t,
46 	magic_climate,
47 	magic_reliefmap,
48 	magic_farbengui_t,
49 	magic_color_gui_t,
50 	magic_ki_kontroll_t,
51 	magic_optionen_gui_t,
52 	magic_sound_kontroll_t,
53 	magic_load_t,
54 	magic_save_t,
55 	magic_UNUSED_railtools,
56 	magic_UNUSED_monorailtools,
57 	magic_UNUSED_tramtools, // Dario: Tramway
58 	magic_UNUSED_roadtools,
59 	magic_UNUSED_shiptools,
60 	magic_UNUSED_airtools,
61 	magic_UNUSED_specialtools,
62 	magic_UNUSED_listtools,
63 	magic_UNUSED_edittools,
64 	magic_UNUSED_slopetools,
65 	magic_halt_list_t,
66 	magic_UNUSED_label_frame,
67 	magic_city_info_t,
68 	magic_citylist_frame_t,
69 	magic_mainhelp,
70 	// player dependent stuff => 16 times present
71 	magic_finances_t,
72 	magic_convoi_list=magic_finances_t+MAX_PLAYER_COUNT,
73 	magic_convoi_list_filter=magic_convoi_list+MAX_PLAYER_COUNT,
74 	magic_line_list=magic_convoi_list_filter+MAX_PLAYER_COUNT,
75 	magic_halt_list=magic_line_list+MAX_PLAYER_COUNT,
76 	magic_line_management_t=magic_halt_list+MAX_PLAYER_COUNT,
77 	magic_ai_options_t=magic_line_management_t+MAX_PLAYER_COUNT,
78 	magic_ai_selector=magic_ai_options_t+MAX_PLAYER_COUNT,
79 	magic_pwd_t=magic_ai_selector+MAX_PLAYER_COUNT,
80 	magic_jump=magic_pwd_t+MAX_PLAYER_COUNT,
81 	magic_headquarter = magic_jump + MAX_PLAYER_COUNT,
82 	// normal stuff
83 	magic_curiositylist,
84 	magic_factorylist,
85 	magic_goodslist,
86 	magic_messageframe,
87 	magic_message_options,
88 	magic_scenario_frame,
89 	magic_scenario_info,
90 	magic_edit_factory,
91 	magic_edit_attraction,
92 	magic_edit_house,
93 	magic_edit_tree,
94 	magic_bigger_map,
95 	magic_labellist,
96 	magic_station_building_select,
97 	magic_server_frame_t,
98 	magic_pakset_info_t,
99 	magic_schedule_rdwr_dummy,	// only used to save/load schedules
100 	magic_line_schedule_rdwr_dummy,	// only used to save/load line schedules
101 	magic_motd,
102 	magic_factory_info, // only used to load/save
103 	magic_font,
104 	// magic numbers with big jumps between them
105 	magic_convoi_info,
106 	magic_UNUSED_convoi_detail=magic_convoi_info+65536, // unused range
107 	magic_halt_info=magic_UNUSED_convoi_detail +65536,
108 	magic_UNUSED_halt_detail=magic_halt_info+65536, // unused range
109 	magic_toolbar=magic_UNUSED_halt_detail+65536,
110 	magic_script_error=magic_toolbar+256,
111 	magic_haltlist_filter,
112 	magic_depot, // only used to load/save
113 	magic_max
114 };
115 
116 // Holding time for auto-closing windows
117 #define MESG_WAIT 80
118 
119 void init_map_win();
120 
121 // windows with a valid id can be saved and restored
122 void rdwr_all_win(loadsave_t *file);
123 
124 // save windowsizes in settings
125 void rdwr_win_settings(loadsave_t *file);
126 
127 int create_win(gui_frame_t*, wintype, ptrdiff_t magic);
128 int create_win(int x, int y, gui_frame_t*, wintype, ptrdiff_t magic);
129 
130 bool check_pos_win(event_t*);
131 
132 bool win_is_open(gui_frame_t *ig );
133 
134 
135 scr_coord const& win_get_pos(gui_frame_t const*);
136 void win_set_pos(gui_frame_t *ig, int x, int y);
137 
138 gui_frame_t *win_get_top();
139 
140 // Knightly : returns the focused component of the top window
141 gui_component_t *win_get_focus();
142 
143 int win_get_open_count();
144 
145 // returns the window (if open) otherwise zero
146 gui_frame_t *win_get_magic(ptrdiff_t magic);
147 
148 // sets the magic of a gui_frame_t (needed during reload of windows)
149 bool win_set_magic( gui_frame_t *gui, ptrdiff_t magic );
150 
151 /**
152  * Checks if a window is a top level window
153  *
154  * @author Hj. Malthaner
155  */
156 bool win_is_top(const gui_frame_t *ig);
157 
158 
159 // return true if actually window was destroyed (or marked for destruction)
160 bool destroy_win(const gui_frame_t *ig);
161 bool destroy_win(const ptrdiff_t magic);
162 
163 void destroy_all_win(bool destroy_sticky);
164 
165 bool top_win(const gui_frame_t *ig, bool keep_rollup=false  );
166 void display_all_win();
167 void win_rotate90( sint16 new_size );
168 void move_win(int win);
169 
170 void win_display_flush(double konto); // draw the frame and all windows
171 
172 uint16 win_get_statusbar_height();
173 
174 void win_poll_event(event_t*);
175 
176 bool win_change_zoom_factor(bool magnify);
177 
178 /**
179  * Sets the world this window manager is attached to.
180  */
181 void win_set_world(karte_t *world);
182 
183 /**
184  * Forces the redraw of the world on next frame.
185  */
186 void win_redraw_world();
187 
188 /**
189  * Loads new font. Notifies gui's, world.
190  */
191 void win_load_font(const char *fname, uint16 fontsize);
192 
193 /**
194  * Sets the tooltip to display.
195  * @param owner : owner==NULL disables timing (initial delay and visible duration)
196  * @author Hj. Malthaner, Knightly
197  */
198 void win_set_tooltip(int xpos, int ypos, const char *text, const void *const owner = 0, const void *const group = 0);
199 
200 /**
201  * Sets a static tooltip that follows the mouse
202  * *MUST* be explicitly unset!
203  * @author Hj. Malthaner
204  */
205 void win_set_static_tooltip(const char *text);
206 
207 #endif
208