1 /* 2 * Copyright (C) 1997-2009, Michael Jennings 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to 6 * deal in the Software without restriction, including without limitation the 7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 * sell copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies of the Software, its documentation and marketing & publicity 13 * materials, and acknowledgment shall be given in the documentation, materials 14 * and software packages that this Software was used. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef _BUTTONS_H 25 # define _BUTTONS_H 26 27 # include <X11/Xfuncproto.h> 28 # include "actions.h" 29 # include "events.h" 30 # include "menus.h" 31 32 /************ Macros and Definitions ************/ 33 #define BBAR_DOCKED_TOP (1 << 0) 34 #define BBAR_DOCKED_BOTTOM (1 << 1) 35 #define BBAR_DOCKED (BBAR_DOCKED_TOP | BBAR_DOCKED_BOTTOM) 36 #define BBAR_UNDOCKED (~BBAR_DOCKED) 37 #define BBAR_VISIBLE (1 << 2) 38 39 #define bbar_is_docked(bbar) (bbar->state & BBAR_DOCKED) 40 #define bbar_is_top_docked(bbar) (bbar->state & BBAR_DOCKED_TOP) 41 #define bbar_is_bottom_docked(bbar) (bbar->state & BBAR_DOCKED_BOTTOM) 42 #define bbar_set_docked(bbar, d) do {bbar->state &= ~BBAR_DOCKED; bbar->state |= (d);} while (0) 43 #define bbar_redock(bbar) bbar_dock(bbar, bbar_is_docked(bbar)); 44 #define bbar_is_visible(bbar) (bbar->state & BBAR_VISIBLE) 45 #define bbar_set_visible(bbar, v) ((v) ? (bbar->state |= BBAR_VISIBLE) : (bbar->state &= ~BBAR_VISIBLE)) 46 #define bbar_get_width(bbar) (bbar->w) 47 #define bbar_get_height(bbar) (bbar->h) 48 #ifdef __GNUC__ 49 # define bbar_total_height() __extension__ ({__typeof__(bbar_total_h) bth = (bbar_total_h != -1) ? (bbar_total_h) : (bbar_calc_total_height()); \ 50 D_BBAR(("bbar_total_height() returning %d\n", bth)); bth;}) 51 # define bbar_reset_total_height() __extension__ ({D_BBAR(("bbar_reset_total_height()\n")); bbar_total_h = -1; bbar_total_h;}) 52 #else 53 # define bbar_total_height() ((bbar_total_h != -1) ? (bbar_total_h) : (bbar_calc_total_height())) 54 # define bbar_reset_total_height() (bbar_total_h = -1) 55 #endif 56 57 #define FOREACH_BUTTONBAR(x) do {buttonbar_t *bbar; for (bbar = buttonbar; bbar; bbar = bbar->next) { x } } while (0) 58 59 /************ Structures ************/ 60 typedef struct button_struct { 61 simage_t *icon; 62 action_type_t type; 63 union { 64 menu_t *menu; 65 char *script; 66 char *string; 67 } action; 68 char *text; 69 unsigned short len; 70 unsigned short x, y, w, h; 71 unsigned short text_x, text_y; 72 unsigned short icon_x, icon_y, icon_w, icon_h; 73 #ifdef ESCREEN 74 int flags; 75 #endif 76 struct button_struct *next; 77 } button_t; 78 79 typedef struct buttonbar_struct { 80 Window win; 81 Pixmap bg; 82 unsigned short x, y, w, h; 83 GC gc; 84 unsigned char state; 85 XFontStruct *font; 86 #ifdef MULTI_CHARSET 87 XFontSet fontset; 88 #endif 89 unsigned short fwidth, fheight; 90 event_dispatcher_data_t event_data; 91 unsigned char image_state; 92 button_t *buttons, *rbuttons, *current; 93 struct buttonbar_struct *next; 94 } buttonbar_t; 95 96 /************ Variables ************/ 97 extern buttonbar_t *buttonbar; 98 extern long bbar_total_h; 99 #ifdef ESCREEN 100 extern button_t *drag; 101 #endif 102 103 /************ Function Prototypes ************/ 104 _XFUNCPROTOBEGIN 105 106 extern buttonbar_t *bbar_create(void); 107 extern void bbar_free(buttonbar_t *); 108 extern void bbar_init(buttonbar_t *, int); 109 extern void bbar_event_init_dispatcher(void); 110 extern unsigned char bbar_handle_enter_notify(event_t *); 111 extern unsigned char bbar_handle_leave_notify(event_t *); 112 extern unsigned char bbar_handle_button_press(event_t *); 113 extern unsigned char bbar_handle_button_release(event_t *); 114 extern unsigned char bbar_handle_motion_notify(event_t *); 115 extern unsigned char bbar_dispatch_event(event_t *); 116 extern buttonbar_t *find_bbar_by_window(Window); 117 extern void bbar_add(buttonbar_t *bbar); 118 extern unsigned short bbar_calc_height(buttonbar_t *bbar); 119 extern void bbar_calc_button_sizes(buttonbar_t *bbar); 120 extern void bbar_calc_button_positions(buttonbar_t *bbar); 121 extern void button_calc_size(buttonbar_t *bbar, button_t *button); 122 extern void button_calc_rel_coords(buttonbar_t *bbar, button_t *button); 123 extern void bbar_add_button(buttonbar_t *bbar, button_t *button); 124 extern void bbar_add_rbutton(buttonbar_t *bbar, button_t *button); 125 extern unsigned char bbar_set_font(buttonbar_t *bbar, const char *fontname); 126 extern button_t *find_button_by_text(buttonbar_t *bbar, char *text); 127 extern button_t *find_button_by_index(buttonbar_t *bbar, long); 128 extern button_t *find_button_by_coords(buttonbar_t *bbar, int x, int y); 129 extern button_t *button_create(char *text); 130 extern void button_free(button_t *); 131 extern unsigned char button_set_text(button_t *button, const char *text); 132 extern unsigned char button_set_icon(button_t *button, simage_t *icon); 133 extern unsigned char button_set_action(button_t *button, action_type_t type, char *action); 134 extern void bbar_select_button(buttonbar_t *bbar, button_t *button); 135 extern void bbar_deselect_button(buttonbar_t *bbar, button_t *button); 136 extern void bbar_click_button(buttonbar_t *bbar, button_t *button); 137 extern void button_check_action(buttonbar_t *bbar, button_t *button, unsigned char press, Time t); 138 extern unsigned char bbar_show(buttonbar_t *bbar, unsigned char visible); 139 extern void bbar_show_all(signed char visible); 140 extern void bbar_resize(buttonbar_t *bbar, int w); 141 extern void bbar_resize_all(int width); 142 extern void bbar_dock(buttonbar_t *bbar, unsigned char dock); 143 extern void bbar_draw(buttonbar_t *bbar, unsigned char image_state, unsigned char force_modes); 144 extern void bbar_draw_all(unsigned char image_state, unsigned char force_modes); 145 extern void bbar_calc_positions(void); 146 extern unsigned long bbar_calc_total_height(void); 147 extern unsigned long bbar_calc_docked_height(unsigned char); 148 extern void bbar_redraw(buttonbar_t *bbar); 149 extern buttonbar_t *bbar_insert_button(buttonbar_t *bbar, button_t *button, int after, int addright); 150 151 _XFUNCPROTOEND 152 153 #endif /* _BUTTONS_H */ 154