1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 16 июн. 2017 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef UI_WS_WS_H_
23 #define UI_WS_WS_H_
24 
25 #include <core/types.h>
26 #include <core/debug.h>
27 #include <core/status.h>
28 
29 // TODO: for release this code shoulde be deleted and defined in makefile
30 // OS-specific windowing system selection
31 #if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
32     #define USE_X11_DISPLAY
33 #elif defined(PLATFORM_WINDOWS)
34     #define USE_WINAPI_DISPLAY
35 #else
36     #error "Unsupported platform"
37 #endif
38 
39 #include <core/io/IInStream.h>
40 #include <core/io/IOutStream.h>
41 
42 namespace lsp
43 {
44     namespace ws
45     {
46         typedef uint32_t            ws_code_t;
47 
48         /** Mouse controller buttons
49          *
50          */
51         enum mcb_t
52         {
53             MCB_LEFT            = 0,
54             MCB_MIDDLE          = 1,
55             MCB_RIGHT           = 2,
56             MCB_BUTTON4         = 3,
57             MCB_BUTTON5         = 4,
58             MCB_BUTTON6         = 5,
59             MCB_BUTTON7         = 6,
60 
61             MCB_NONE            = 0xffff,
62         };
63 
64         /** Mouse controller flags
65          *
66          */
67         enum mcf_t
68         {
69             MCF_LEFT            = 1 << 0,
70             MCF_MIDDLE          = 1 << 1,
71             MCF_RIGHT           = 1 << 2,
72             MCF_BUTTON4         = 1 << 3,
73             MCF_BUTTON5         = 1 << 4,
74             MCF_BUTTON6         = 1 << 5,
75             MCF_BUTTON7         = 1 << 6,
76 
77             MCF_SHIFT           = 1 << 7,
78             MCF_LOCK            = 1 << 8,
79             MCF_CONTROL         = 1 << 9,
80 
81             MCF_ALT             = 1 << 10,
82             MCF_MOD2            = 1 << 11,
83             MCF_MOD3            = 1 << 12,
84             MCF_MOD4            = 1 << 13,
85             MCF_MOD5            = 1 << 14,
86 
87             MCF_SUPER           = 1 << 15,
88             MCF_HYPER           = 1 << 16,
89             MCF_META            = 1 << 17,
90             MCF_RELEASE         = 1 << 18,
91 
92             MCF_BTN_MASK        = MCF_LEFT | MCF_MIDDLE | MCF_RIGHT | MCF_BUTTON4 | MCF_BUTTON5 | MCF_BUTTON6 | MCF_BUTTON7
93         };
94 
95         /** Mouse scroll direction
96          *
97          */
98         enum mcd_t
99         {
100             MCD_UP              = 0,
101             MCD_DOWN            = 1,
102             MCD_LEFT            = 2,
103             MCD_RIGHT           = 3,
104             MCD_NONE            = 0xffff
105         };
106 
107         /**
108          * Different grab group types,
109          * sorted according to the priority of grab
110          * in ascending order
111          */
112         enum grab_t
113         {
114             GRAB_LOWEST,
115             GRAB_LOW,
116             GRAB_NORMAL,
117             GRAB_HIGH,
118             GRAB_HIGHEST,
119 
120             GRAB_DROPDOWN,                  // Dropdown list
121 
122             GRAB_MENU,                      // Simple menu
123             GRAB_EXTRA_MENU,                // Menu over menu
124 
125             __GRAB_TOTAL
126         };
127 
128         /** Event processing flags
129          *
130          */
131         enum event_flags_t
132         {
133             EVF_NONE            = 0,        // Nothing to do
134             EVF_HANDLED         = 1 << 0,   // Event has been processed
135             EVF_STOP            = 1 << 1,   // Stop further propagation of event to other elements
136             EVF_GRAB            = 1 << 2    // Grab all further events first
137         };
138 
139         /** Different drag actions
140          *
141          */
142         enum drag_t
143         {
144             DRAG_COPY           = 0,//!< DRAG_COPY
145             DRAG_MOVE           = 1,//!< DRAG_MOVE
146             DRAG_LINK           = 2,//!< DRAG_LINK
147             DRAG_ASK            = 3,//!< DRAG_ASK
148             DRAG_PRIVATE        = 4,//!< DRAG_PRIVATE
149             DRAG_DIRECT_SAVE    = 5 //!< DRAG_DIRECT_SAVE
150         };
151 
152         enum mouse_pointer_t
153         {
154             MP_NONE,
155             MP_ARROW,       // Standard arrow
156             MP_HAND,        // Hand pointer
157             MP_CROSS,       // Crosshair
158             MP_IBEAM,       // Text-editing I-beam
159             MP_DRAW,        // Drawing tool (pencil)
160             MP_PLUS,        // Plus
161             MP_SIZE_NESW,   // Sizing cursor oriented diagonally from northeast to southwest
162             MP_SIZE_NS,     // Sizing cursor oriented vertically
163             MP_SIZE_WE,     // Sizing cursor oriented horizontally
164             MP_SIZE_NWSE,   // Sizing cursor oriented diagonally from northwest to southeast
165             MP_UP_ARROW,    // Arrow pointing up
166             MP_HOURGLASS,   // Hourglass
167             MP_DRAG,        // Arrow with a blank page in the lower-right corner
168             MP_NO_DROP,     // Diagonal slash through a white circle
169             MP_DANGER,      // Danger cursor
170             MP_HSPLIT,      // Black double-vertical bar with arrows pointing right and left
171             MP_VSPLIT,      // Black double-horizontal bar with arrows pointing up and down
172             MP_MULTIDRAG,   // Arrow with three blank pages in the lower-right corner
173             MP_APP_START,   // Arrow combined with an hourglass
174             MP_HELP,        // Arrow next to a black question mark
175 
176             // Aliases
177             MP_SIZE         = MP_ARROW,
178             MP_DEFAULT      = MP_ARROW,
179             MP_TEXT         = MP_IBEAM,
180             MP_VSIZE        = MP_SIZE_NS,
181             MP_HSIZE        = MP_SIZE_WE,
182             MP_WAIT         = MP_HOURGLASS,
183             MP_ARROW_WAIT   = MP_APP_START,
184             MP_HYPERLINK    = MP_HAND,
185             MP_PENCIL       = MP_DRAW,
186             MP_TABLE_CELL   = MP_PLUS,
187 
188             // Boundaries
189             __MP_LAST       = MP_HELP,
190             __MP_COUNT      = __MP_LAST + 1
191         };
192 
193         enum ui_event_type_t
194         {
195             UIE_UNKNOWN,
196             UIE_KEY_DOWN,
197             UIE_KEY_UP,
198             UIE_MOUSE_DOWN,
199             UIE_MOUSE_UP,
200             UIE_MOUSE_MOVE,
201             UIE_MOUSE_SCROLL,
202             UIE_MOUSE_DBL_CLICK,
203             UIE_MOUSE_TRI_CLICK,
204             UIE_MOUSE_IN,
205             UIE_MOUSE_OUT,
206             UIE_REDRAW,
207             UIE_RENDER,
208             UIE_SIZE_REQUEST,
209             UIE_RESIZE,
210             UIE_SHOW,
211             UIE_HIDE,
212             UIE_CLOSE,
213             UIE_FOCUS_IN,
214             UIE_FOCUS_OUT,
215 
216             UIE_DRAG_ENTER,
217             UIE_DRAG_LEAVE,
218             UIE_DRAG_REQUEST,
219 
220             UIE_TOTAL,
221             UIE_FIRST = UIE_KEY_DOWN,
222             UIE_LAST = UIE_CLOSE,
223             UIE_END = UIE_UNKNOWN
224         };
225 
226         enum border_style_t
227         {
228             BS_DIALOG,              // Not sizable; no minimize/maximize menu
229             BS_SINGLE,              // Not sizable; minimize/maximize menu
230             BS_NONE,                // Not sizable; no visible border line
231             BS_POPUP,               // Popup window
232             BS_COMBO,               // Combo box window
233             BS_SIZEABLE
234         };
235 
236         enum window_action_t
237         {
238             WA_MOVE         = 1 << 0,
239             WA_RESIZE       = 1 << 1,
240             WA_MINIMIZE     = 1 << 2,
241             WA_MAXIMIZE     = 1 << 3,
242             WA_CLOSE        = 1 << 4,
243             WA_STICK        = 1 << 5,
244             WA_SHADE        = 1 << 6,
245             WA_FULLSCREEN   = 1 << 7,
246             WA_CHANGE_DESK  = 1 << 8,
247 
248             WA_ALL          = WA_MOVE | WA_RESIZE | WA_MINIMIZE | WA_MAXIMIZE | WA_CLOSE | WA_STICK | WA_SHADE | WA_FULLSCREEN | WA_CHANGE_DESK,
249             WA_NONE         = 0,
250             WA_SINGLE       = WA_MOVE | WA_STICK | WA_MINIMIZE | WA_SHADE | WA_CHANGE_DESK | WA_CLOSE,
251             WA_DIALOG       = WA_MOVE | WA_STICK | WA_SHADE,
252             WA_POPUP        = WA_NONE,
253             WA_COMBO        = WA_NONE,
254             WA_SIZABLE      = WA_ALL
255         };
256 
257         typedef uint64_t    ui_timestamp_t;
258 
259         typedef struct ws_event_t
260         {
261             size_t              nType;      // Type of event, see ui_event_type_t
262             ssize_t             nLeft;      // Left position of something
263             ssize_t             nTop;       // Top position of something
264             ssize_t             nWidth;     // Width of something
265             ssize_t             nHeight;    // Height of something
266             ws_code_t           nCode;      // Key code, button, scroll direction
267             size_t              nState;     // State
268             ui_timestamp_t      nTime;      // Event timestamp in milliseconds
269         } ws_event_t;
270 
271         typedef struct size_request_t
272         {
273             ssize_t             nMinWidth;
274             ssize_t             nMinHeight;
275             ssize_t             nMaxWidth;
276             ssize_t             nMaxHeight;
277         } size_request_t;
278 
279         typedef struct realize_t
280         {
281             ssize_t             nLeft;
282             ssize_t             nTop;
283             ssize_t             nWidth;
284             ssize_t             nHeight;
285         } realize_t;
286 
287         typedef struct padding_t
288         {
289             size_t              nLeft;
290             size_t              nRight;
291             size_t              nTop;
292             size_t              nBottom;
293         } padding_t;
294 
295         /** Event handler identifier
296          *
297          */
298         typedef ssize_t         ui_handler_id_t;
299 
300         enum surface_type_t
301         {
302             ST_UNKNOWN,
303             ST_IMAGE,
304             ST_XLIB,
305             ST_PROXY
306         };
307 
308         typedef struct font_parameters_t
309         {
310             float Ascent;       // The distance that the font extends above the baseline
311             float Descent;      // The distance that the font extends below the baseline
312             float Height;       // The recommended vertical distance between baselines when setting consecutive lines of text with the font
313             float MaxXAdvance;  // The maximum distance in the X direction that the origin is advanced for any glyph in the font
314             float MaxYAdvance;  // The maximum distance in the Y direction that the origin is advanced for any glyph in the font
315         } font_parameters_t;
316 
317         typedef struct text_parameters_t
318         {
319             float XBearing;     // The horizontal distance from the origin to the leftmost part of the glyphs as drawn
320             float YBearing;     // The vertical distance from the origin to the topmost part of the glyphs as drawn
321             float Width;        // Width of the glyphs as drawn
322             float Height;       // Height of the glyphs as drawn
323             float XAdvance;     // Distance to advance in the X direction after drawing these glyphs
324             float YAdvance;     // distance to advance in the Y direction after drawing these glyphs
325         } text_parameters_t;
326 
327         /** Corners to perform surface drawing
328          *
329          */
330         enum corner_t
331         {
332             CORNER_LEFT_TOP         = 1 << 0,                                                                       //!< CORNER_LEFT_TOP
333             CORNER_RIGHT_TOP        = 1 << 1,                                                                       //!< CORNER_RIGHT_TOP
334             CORNER_LEFT_BOTTOM      = 1 << 2,                                                                       //!< CORNER_LEFT_BOTTOM
335             CORNER_RIGHT_BOTTOM     = 1 << 3,                                                                       //!< CORNER_RIGHT_BOTTOM
336 
337             CORNERS_TOP             = CORNER_LEFT_TOP | CORNER_RIGHT_TOP,                                           //!< CORNERS_TOP
338             CORNERS_BOTTOM          = CORNER_LEFT_BOTTOM | CORNER_RIGHT_BOTTOM,                                     //!< CORNERS_BOTTOM
339             CORNERS_LEFT            = CORNER_LEFT_TOP | CORNER_LEFT_BOTTOM,                                         //!< CORNERS_LEFT
340             CORNERS_RIGHT           = CORNER_RIGHT_TOP | CORNER_RIGHT_BOTTOM,                                       //!< CORNERS_RIGHT
341             CORNERS_ALL             = CORNER_LEFT_TOP | CORNER_RIGHT_TOP | CORNER_LEFT_BOTTOM | CORNER_RIGHT_BOTTOM,//!< CORNERS_ALL
342             CORNERS_NONE            = 0                                                                             //!< CORNERS_NONE
343         };
344 
345         // Different kinds of clipboards
346         enum clipboard_id_t
347         {
348             CBUF_PRIMARY,
349             CBUF_SECONDARY,
350             CBUF_CLIPBOARD,
351 
352             _CBUF_TOTAL
353         };
354 
355         typedef struct clip_format_t
356         {
357             const char     *content_type;
358             const char     *charset;
359         } clip_format_t;
360 
361         /** timestamp type
362          *
363          */
364         typedef uint64_t    timestamp_t;
365 
366         /** Task handler
367          *
368          * @param time current time at which the timer was executed
369          * @param arg argument passed to task handler
370          * @return status of operation
371          */
372         typedef status_t    (* task_handler_t)(timestamp_t time, void *arg);
373 
374         /** Clipboard handler
375          *
376          * @param arg passed to the handler argument
377          * @param s status of operation
378          * @param is clipboard input stream object
379          * @return status of operation
380          */
381         typedef status_t    (* clipboard_handler_t)(void *arg, status_t s, io::IInStream *is);
382 
383         /** Display task identifier
384          *
385          */
386         typedef ssize_t     taskid_t;
387     }
388 }
389 
390 // Keycode definition
391 #include <ui/ws/keycodes.h>
392 
393 // Common definitions
394 #include <ui/ws/IDataSink.h>
395 #include <ui/ws/IDataSource.h>
396 #include <ui/ws/IEventHandler.h>
397 #include <ui/ws/ISurface.h>
398 #include <ui/ws/IDisplay.h>
399 #include <ui/ws/INativeWindow.h>
400 #include <ui/ws/IR3DBackend.h>
401 
402 #endif /* INCLUDE_UI_WS_WS_H_ */
403