1 /* 2 * Copyright 2017 Chris Young <chris@unsatisfactorysoftware.co.uk> 3 * 4 * This file is part of NetSurf, http://www.netsurf-browser.org/ 5 * 6 * NetSurf is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; version 2 of the License. 9 * 10 * NetSurf is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef AMIGA_COREWINDOW_H 20 #define AMIGA_COREWINDOW_H 21 22 #include "netsurf/core_window.h" 23 24 #include "amiga/gui.h" /* need to know the size of ami_generic_window :( */ 25 #include "amiga/plotters.h" 26 27 /** 28 * BOOPSI objects 29 */ 30 31 enum { 32 GID_CW_WIN = 0, /* window object */ 33 GID_CW_MAIN, /* root layout object */ 34 GID_CW_DRAW, /* drawing area (space.gadget) */ 35 GID_CW_HSCROLL, /* horizontal scroller */ 36 GID_CW_VSCROLL, /* vertical scroller */ 37 GID_CW_HSCROLLLAYOUT, /* horizontal scroller container*/ 38 GID_CW_VSCROLLLAYOUT, /* vertical scroller container */ 39 GID_CW_LAST 40 }; 41 42 /** 43 * Amiga core window state 44 */ 45 struct ami_corewindow { 46 /* 47 * Any variables common to any frontend window would go here. 48 * e.g. drawing area handles, toolkit pointers or other state 49 */ 50 struct ami_generic_window w; 51 struct Window *win; 52 Object *objects[GID_CW_LAST]; 53 54 struct Hook idcmp_hook; 55 struct timeval lastclick; 56 57 int mouse_x_click; 58 int mouse_y_click; 59 int mouse_state; 60 61 bool dragging; 62 int drag_x_start; 63 int drag_y_start; 64 65 bool close_window; // set to true to close the window during event loop 66 67 APTR deferred_rects_pool; 68 struct MinList *deferred_rects; 69 70 /** keep track of the scrollbar type we're using */ 71 bool in_border_scroll; 72 bool scroll_x_visible; 73 bool scroll_y_visible; 74 75 /** window title, must be allocated wth ami_utf8 function */ 76 char *wintitle; 77 78 /** stuff for our off-screen render bitmap */ 79 struct gui_globals *gg; 80 struct MinList *shared_pens; 81 82 /** drag status set by core */ 83 core_window_drag_status drag_status; 84 85 /** table of callbacks for core window operations */ 86 struct core_window_callback_table *cb_table; 87 88 /** 89 * callback to draw on drawable area of Amiga core window 90 * 91 * \param ami_cw The Amiga core window structure. 92 * \param x Plot origin (X) 93 * \param r Plot origin (Y) 94 * \param r The rectangle of the window that needs updating. 95 * \param ctx Redraw context 96 * \return NSERROR_OK on success otherwise apropriate error code 97 */ 98 nserror (*draw)(struct ami_corewindow *ami_cw, int x, int y, struct rect *r, 99 struct redraw_context *ctx); 100 101 /** 102 * callback for keypress on Amiga core window 103 * 104 * \param ami_cw The Amiga core window structure. 105 * \param nskey The netsurf key code. 106 * \return NSERROR_OK if key processed, 107 * NSERROR_NOT_IMPLEMENTED if key not processed 108 * otherwise apropriate error code 109 */ 110 nserror (*key)(struct ami_corewindow *ami_cw, uint32_t nskey); 111 112 /** 113 * callback for mouse event on Amiga core window 114 * 115 * \param ami_cw The Amiga core window structure. 116 * \param mouse_state mouse state 117 * \param x location of event 118 * \param y location of event 119 * \return NSERROR_OK on sucess otherwise apropriate error code. 120 */ 121 nserror (*mouse)(struct ami_corewindow *ami_cw, browser_mouse_state mouse_state, int x, int y); 122 123 /** 124 * callback for unknown events on Amiga core window 125 * eg. buttons in the ssl cert window 126 * (result & WMHI_CLASSMASK) gives the class of event (eg. WMHI_GADGETUP) 127 * (result & WMHI_GADGETMASK) gives the gadget ID (eg. GID_SSLCERT_ACCEPT) 128 * 129 * \param ami_cw The Amiga core window structure. 130 * \param result event as returned by RA_HandleInput() 131 * \return TRUE if window closed during event processing 132 */ 133 BOOL (*event)(struct ami_corewindow *ami_cw, ULONG result); 134 135 /** 136 * callback for drag end on Amiga core window 137 * ie. a drag *from* this window to a different window 138 * 139 * \param ami_cw The Amiga core window structure. 140 * \param x mouse x position **in screen co-ordinates** 141 * \param y mouse y position **in screen co-ordinates** 142 * \return NSERROR_OK on success otherwise apropriate error code 143 */ 144 nserror (*drag_end)(struct ami_corewindow *ami_cw, int x, int y); 145 146 /** 147 * callback for icon drop on Amiga core window 148 * ie. a drag has ended *above* this window 149 * \todo this may not be very flexible but serves our current purposes 150 * 151 * \param ami_cw The Amiga core window structure. 152 * \param url url of dropped icon 153 * \param title title of dropped icon 154 * \param x mouse x position **in screen co-ordinates** 155 * \param y mouse y position **in screen co-ordinates** 156 * \return NSERROR_OK on success otherwise apropriate error code 157 */ 158 nserror (*icon_drop)(struct ami_corewindow *ami_cw, struct nsurl *url, const char *title, int x, int y); 159 160 /** 161 * callback to close an Amiga core window 162 * 163 * \param ami_cw The Amiga core window structure. 164 */ 165 void (*close)(struct ami_corewindow *ami_cw); 166 167 }; 168 169 /** 170 * initialise elements of Amiga core window. 171 * 172 * As a pre-requisite the draw, key and mouse callbacks must be defined 173 * 174 * \param ami_cw An Amiga core window structure to initialise 175 * \return NSERROR_OK on successful initialisation otherwise error code. 176 */ 177 nserror ami_corewindow_init(struct ami_corewindow *ami_cw); 178 179 /** 180 * finalise elements of Amiga core window. 181 * 182 * \param ami_cw An Amiga core window structure to finialise 183 * \return NSERROR_OK on successful finalisation otherwise error code. 184 */ 185 nserror ami_corewindow_fini(struct ami_corewindow *ami_cw); 186 187 #endif 188 189