Ticket #4536: skins: add root variant of julia256 skin.
[midnight-commander.git] / src / filemanager / panel.h
blob0496f43966d48b88968dbd9655f39533373554b4
1 /** \file panel.h
2 * \brief Header: defines WPanel structure
3 */
5 #ifndef MC__PANEL_H
6 #define MC__PANEL_H
8 #include <inttypes.h> /* uintmax_t */
9 #include <limits.h> /* MB_LEN_MAX */
11 #include "lib/global.h" /* gboolean */
12 #include "lib/fs.h" /* MC_MAXPATHLEN */
13 #include "lib/strutil.h"
14 #include "lib/widget.h" /* Widget */
15 #include "lib/filehighlight.h"
16 #include "lib/file-entry.h"
18 #include "dir.h" /* dir_list */
20 /*** typedefs(not structures) and defined constants **********************************************/
22 #define PANEL(x) ((WPanel *)(x))
23 #define DEFAULT_USER_FORMAT "half type name | size | perm"
25 #define LIST_FORMATS 4
27 #define UP_KEEPSEL ((char *) -1)
29 /*** enums ***************************************************************************************/
31 typedef enum
33 list_full, /* Name, size, perm/date */
34 list_brief, /* Name */
35 list_long, /* Like ls -l */
36 list_user /* User defined */
37 } list_format_t;
39 typedef enum
41 frame_full, /* full screen frame */
42 frame_half /* half screen frame */
43 } panel_display_t;
45 typedef enum
47 UP_OPTIMIZE = 0,
48 UP_RELOAD = 1,
49 UP_ONLY_CURRENT = 2
50 } panel_update_flags_t;
52 /* run mode and params */
53 enum cd_enum
55 cd_parse_command,
56 cd_exact
59 /*** structures declarations (and typedefs of structures)*****************************************/
61 typedef struct panel_field_struct
63 const char *id;
64 int min_size;
65 gboolean expands;
66 align_crt_t default_just;
67 const char *hotkey;
68 const char *title_hotkey;
69 gboolean is_user_choice;
70 gboolean use_in_user_format;
71 const char *(*string_fn) (file_entry_t *, int);
72 GCompareFunc sort_routine; /* used by mouse_sort_col() */
73 } panel_field_t;
75 typedef struct
77 dir_list list;
78 vfs_path_t *root_vpath;
79 } panelized_descr_t;
81 typedef struct
83 Widget widget;
85 char *name; /* The panel name */
87 panel_display_t frame_size; /* half or full frame */
89 gboolean active; /* If panel is currently selected */
90 gboolean dirty; /* Should we redisplay the panel? */
92 gboolean is_panelized; /* Panelization: special mode, can't reload the file list */
93 panelized_descr_t *panelized_descr; /* Panelization descriptor */
95 #ifdef HAVE_CHARSET
96 int codepage; /* Panel codepage */
97 #endif
99 dir_list dir; /* Directory contents */
100 struct stat dir_stat; /* Stat of current dir: used by execute () */
102 vfs_path_t *cwd_vpath; /* Current Working Directory */
103 vfs_path_t *lwd_vpath; /* Last Working Directory */
105 list_format_t list_format; /* Listing type */
106 GSList *format; /* Display format */
107 char *user_format; /* User format */
108 int list_cols; /* Number of file list columns */
109 int brief_cols; /* Number of columns in case of list_brief format */
110 /* sort */
111 dir_sort_options_t sort_info;
112 const panel_field_t *sort_field;
114 int marked; /* Count of marked files */
115 int dirs_marked; /* Count of marked directories */
116 uintmax_t total; /* Bytes in marked files */
118 int top; /* The file shown on the top of the panel */
119 int current; /* Index to the currently selected file */
121 GSList *status_format; /* Mini status format */
122 gboolean user_mini_status; /* Is user_status_format used */
123 char *user_status_format[LIST_FORMATS]; /* User format for status line */
125 file_filter_t filter; /* File name filter */
127 struct
129 char *name; /* Directory history name for history file */
130 GList *list; /* Directory history */
131 GList *current; /* Pointer to the current history item */
132 } dir_history;
134 struct
136 gboolean active;
137 GString *buffer;
138 GString *prev_buffer;
139 char ch[MB_LEN_MAX]; /* Buffer for multi-byte character */
140 int chpoint; /* Point after last characters in @ch */
141 } quick_search;
143 int content_shift; /* Number of characters of filename need to skip from left side. */
144 int max_shift; /* Max shift for visible part of current panel */
145 } WPanel;
147 /*** global variables defined in .c file *********************************************************/
149 extern hook_t *select_file_hook;
151 extern mc_fhl_t *mc_filehighlight;
153 /*** declarations of public functions ************************************************************/
155 WPanel *panel_sized_empty_new (const char *panel_name, const WRect * r);
156 WPanel *panel_sized_with_dir_new (const char *panel_name, const WRect * r,
157 const vfs_path_t * vpath);
159 void panel_clean_dir (WPanel * panel);
161 void panel_reload (WPanel * panel);
162 void panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order);
163 void panel_re_sort (WPanel * panel);
165 #ifdef HAVE_CHARSET
166 void panel_change_encoding (WPanel * panel);
167 vfs_path_t *remove_encoding_from_path (const vfs_path_t * vpath);
168 #endif
170 void update_panels (panel_update_flags_t flags, const char *current_file);
171 int set_panel_formats (WPanel * p);
173 void panel_set_filter (WPanel * panel, const file_filter_t * filter);
175 void panel_set_current_by_name (WPanel * panel, const char *name);
177 void unmark_files (WPanel * panel);
178 void select_item (WPanel * panel);
180 void recalculate_panel_summary (WPanel * panel);
181 void file_mark (WPanel * panel, int idx, int val);
182 void do_file_mark (WPanel * panel, int idx, int val);
184 gboolean panel_do_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
185 gboolean panel_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
187 gsize panel_get_num_of_sortable_fields (void);
188 char **panel_get_sortable_fields (gsize * array_size);
189 const panel_field_t *panel_get_field_by_id (const char *name);
190 const panel_field_t *panel_get_field_by_title (const char *name);
191 const panel_field_t *panel_get_field_by_title_hotkey (const char *name);
192 gsize panel_get_num_of_user_possible_fields (void);
193 char **panel_get_user_possible_fields (gsize * array_size);
194 void panel_set_cwd (WPanel * panel, const vfs_path_t * vpath);
195 void panel_set_lwd (WPanel * panel, const vfs_path_t * vpath);
197 void panel_panelize_cd (void);
198 void panel_panelize_change_root (WPanel * panel, const vfs_path_t * new_root);
199 void panel_panelize_absolutize_if_needed (WPanel * panel);
200 void panel_panelize_save (WPanel * panel);
202 void panel_init (void);
203 void panel_deinit (void);
205 /* --------------------------------------------------------------------------------------------- */
206 /*** inline functions ****************************************************************************/
207 /* --------------------------------------------------------------------------------------------- */
209 * Empty panel creation.
211 * @param panel_name name of panel for setup retrieving
213 * @return new instance of WPanel
216 static inline WPanel *
217 panel_empty_new (const char *panel_name)
219 /* Unknown sizes of the panel at startup */
220 WRect r = { 0, 0, 1, 1 };
222 return panel_sized_empty_new (panel_name, &r);
225 /* --------------------------------------------------------------------------------------------- */
227 * Panel creation for specified directory.
229 * @param panel_name name of panel for setup retrieving
230 * @param vpath working panel directory. If NULL then current directory is used
232 * @return new instance of WPanel
235 static inline WPanel *
236 panel_with_dir_new (const char *panel_name, const vfs_path_t * vpath)
238 /* Unknown sizes of the panel at startup */
239 WRect r = { 0, 0, 1, 1 };
241 return panel_sized_with_dir_new (panel_name, &r, vpath);
245 /* --------------------------------------------------------------------------------------------- */
247 * Panel creation.
249 * @param panel_name name of panel for setup retrieving
251 * @return new instance of WPanel
254 static inline WPanel *
255 panel_new (const char *panel_name)
257 return panel_with_dir_new (panel_name, NULL);
260 /* --------------------------------------------------------------------------------------------- */
262 * Panel creation with specified size.
264 * @param panel_name name of panel for setup retrieving
265 * @param r panel area
267 * @return new instance of WPanel
270 static inline WPanel *
271 panel_sized_new (const char *panel_name, const WRect * r)
273 return panel_sized_with_dir_new (panel_name, r, NULL);
276 /* --------------------------------------------------------------------------------------------- */
278 static inline file_entry_t *
279 panel_current_entry (const WPanel * panel)
281 return &(panel->dir.list[panel->current]);
284 /* --------------------------------------------------------------------------------------------- */
286 #endif /* MC__PANEL_H */