NetSurf
wimputils.h
Go to the documentation of this file.
1/*
2 * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
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/** \file
20 * A collection of grubby utilities for working with OSLib's wimp API.
21 */
22
23#ifndef riscos_wimputils_h_
24#define riscos_wimputils_h_
25
26#include <oslib/wimp.h>
27#include <oslib/wimpreadsysinfo.h>
28
29#include "utils/log.h"
30
31/* Magical union to permit aliasing of wimp_window_state and wimp_open
32 * Do not use this directly. Use the macros, instead. */
33typedef union window_open_state {
34 wimp_window_state state;
35 wimp_open open;
37
38/* Convert a pointer to a wimp_window_state into a pointer to a wimp_open */
39#define PTR_WIMP_OPEN(pstate) ((wimp_open *) (window_open_state *) (pstate))
40
41/* Similarly for wimp_message_list */
42typedef struct ns_wimp_message_list {
43 /* Nasty hack to ensure that we have at least one field in the struct */
44 int first;
45 int rest[];
47
48typedef union message_list {
49 wimp_message_list wimp;
52
53#define PTR_WIMP_MESSAGE_LIST(l) ((wimp_message_list *) (message_list *) (l))
54
55/* Also for VDU variable lists */
56typedef struct ns_os_vdu_var_list {
57 os_vdu_var first;
58 os_vdu_var rest[];
60
61typedef union vdu_var_list {
62 os_vdu_var_list os;
65
66#define PTR_OS_VDU_VAR_LIST(l) ((os_vdu_var_list *) (vdu_var_list *) (l))
67
68/**
69 * Check whether the OS supports text selection in writiable icons.
70 *
71 * \return true if text-selection is supported, false otherwise.
72 */
73static inline bool ns_wimp_has_text_selection(void)
74{
75 wimp_colour bg;
76 wimp_colour fg;
77 os_error *error;
78 wimpreadsysinfotextselection_flags flags;
79
80 error = xwimpreadsysinfo_text_selection(&bg, &fg, &flags);
81 if (error) {
82 NSLOG(netsurf, WARNING,
83 "xwimpreadsysinfo_text_selection: 0x%x: %s",
84 error->errnum, error->errmess);
85 return false;
86 }
87
88 return (flags & wimpreadsysinfotextselectionflags_ENABLED);
89}
90
91#endif
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
os_vdu_var first
Definition: wimputils.h:57
os_vdu_var rest[]
Definition: wimputils.h:58
wimp_message_list wimp
Definition: wimputils.h:49
ns_wimp_message_list ns
Definition: wimputils.h:50
os_vdu_var_list os
Definition: wimputils.h:62
ns_os_vdu_var_list ns
Definition: wimputils.h:63
wimp_open open
Definition: wimputils.h:35
wimp_window_state state
Definition: wimputils.h:34
union window_open_state window_open_state
static bool ns_wimp_has_text_selection(void)
Check whether the OS supports text selection in writiable icons.
Definition: wimputils.h:73
struct ns_os_vdu_var_list ns_os_vdu_var_list
union vdu_var_list vdu_var_list
struct ns_wimp_message_list ns_wimp_message_list
union message_list message_list