1 #ifndef __al_included_allegro_aintern_native_dialog_h 2 #define __al_included_allegro_aintern_native_dialog_h 3 4 #include "allegro5/internal/aintern_list.h" 5 #include "allegro5/internal/aintern_vector.h" 6 #include "allegro5/internal/aintern_native_dialog_cfg.h" 7 8 typedef struct ALLEGRO_NATIVE_DIALOG ALLEGRO_NATIVE_DIALOG; 9 10 /* We could use different structs for the different dialogs. But why 11 * bother. 12 */ 13 struct ALLEGRO_NATIVE_DIALOG 14 { 15 ALLEGRO_USTR *title; 16 int flags; 17 18 /* Only used by file chooser. */ 19 ALLEGRO_PATH *fc_initial_path; 20 size_t fc_path_count; 21 ALLEGRO_PATH **fc_paths; 22 ALLEGRO_USTR *fc_patterns; 23 24 /* Only used by message box. */ 25 ALLEGRO_USTR *mb_heading; 26 ALLEGRO_USTR *mb_text; 27 ALLEGRO_USTR *mb_buttons; 28 int mb_pressed_button; 29 30 /* Only used by text log. */ 31 ALLEGRO_THREAD *tl_thread; 32 ALLEGRO_COND *tl_text_cond; 33 ALLEGRO_MUTEX *tl_text_mutex; 34 ALLEGRO_USTR *tl_pending_text; 35 bool tl_init_error; 36 bool tl_done; 37 bool tl_have_pending; 38 ALLEGRO_EVENT_SOURCE tl_events; 39 void *tl_textview; 40 41 /* Only used by platform implementations. */ 42 bool is_active; 43 void *window; 44 void *async_queue; 45 46 _AL_LIST_ITEM *dtor_item; 47 }; 48 49 extern bool _al_init_native_dialog_addon(void); 50 extern void _al_shutdown_native_dialog_addon(void); 51 extern bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display, 52 ALLEGRO_NATIVE_DIALOG *fd); 53 extern int _al_show_native_message_box(ALLEGRO_DISPLAY *display, 54 ALLEGRO_NATIVE_DIALOG *fd); 55 extern bool _al_open_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog); 56 extern void _al_close_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog); 57 extern void _al_append_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog); 58 59 typedef struct ALLEGRO_MENU_ITEM ALLEGRO_MENU_ITEM; 60 61 struct ALLEGRO_MENU_ITEM 62 { 63 ALLEGRO_MENU *parent; 64 ALLEGRO_MENU *popup; 65 ALLEGRO_USTR *caption; 66 ALLEGRO_BITMAP *icon; 67 68 /* This id is unique. */ 69 uint16_t unique_id; 70 /* This id is user provided, can be not unique. */ 71 uint16_t id; 72 73 int flags; 74 void *extra1, *extra2; 75 }; 76 77 /* _AL_MENU_ID keeps track of menu / id pairs to help determine which 78 * menu belongs to an id. 79 */ 80 typedef struct _AL_MENU_ID _AL_MENU_ID; 81 82 struct _AL_MENU_ID 83 { 84 ALLEGRO_MENU *menu; 85 uint16_t unique_id; 86 uint16_t id; 87 }; 88 89 struct ALLEGRO_MENU 90 { 91 ALLEGRO_EVENT_SOURCE es; 92 ALLEGRO_DISPLAY *display; 93 ALLEGRO_MENU_ITEM *parent; 94 _AL_VECTOR items; 95 96 bool is_event_source; 97 bool is_popup_menu; 98 99 void *extra1; 100 }; 101 102 /* Platform implementation must call this when a menu item is clicked. 103 * display: the display associated with the menu 104 * unique_id: the unique id associated with the menu item 105 * 106 * The function will find the appropriate ALLEGRO_MENU and emit the event. 107 */ 108 extern bool _al_emit_menu_event(ALLEGRO_DISPLAY *display, uint16_t unique_id); 109 110 extern bool _al_walk_over_menu(ALLEGRO_MENU *menu, bool (*proc) 111 (ALLEGRO_MENU *menu, ALLEGRO_MENU_ITEM *item, int index, void *extra), 112 void *extra); 113 _AL_MENU_ID *_al_find_parent_menu_by_id(ALLEGRO_DISPLAY *display, uint16_t unique_id); 114 bool _al_find_menu_item_unique(ALLEGRO_MENU *haystack, uint16_t unique_id, ALLEGRO_MENU **menu, 115 int *index); 116 117 /* Platform Specific Functions 118 * --------------------------- 119 * Each of these should return true if successful. If at all possible, they 120 * should all be implemented and always return true (if menus are implemented 121 * at all). All of the parameters will be valid. 122 */ 123 124 extern bool _al_init_menu(ALLEGRO_MENU *menu); 125 extern bool _al_init_popup_menu(ALLEGRO_MENU *menu); 126 extern bool _al_destroy_menu(ALLEGRO_MENU *menu); 127 128 /* The "int i" parameter represents the indexed location of the item in the 129 * item->parent->items vector. This should map up identically to what is displayed 130 * within the platform menu... However, if there are silent entries (e.g., on OS X), 131 * the index may not represent what is seen on screen. If such discrepencies exist, 132 * then the platform imlpementation must compensate accordingly. */ 133 134 extern bool _al_insert_menu_item_at(ALLEGRO_MENU_ITEM *item, int i); 135 extern bool _al_destroy_menu_item_at(ALLEGRO_MENU_ITEM *item, int i); 136 extern bool _al_update_menu_item_at(ALLEGRO_MENU_ITEM *item, int i); 137 138 extern bool _al_show_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu); 139 extern bool _al_hide_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu); 140 extern bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu); 141 142 /* Returns the height of the display taken up by the menu, so we can resize 143 * the display to compensate. Windows only at the moment.*/ 144 extern int _al_get_menu_display_height(void); 145 146 #endif 147