FINAL CUT
fwidget_flags.h
1 /***********************************************************************
2 * fwidget_flags.h - Struct to store widget properties in flags (⚑) *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2022-2026 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * 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 *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 
24 #ifndef FWIDGET_FLAGS_H
25 #define FWIDGET_FLAGS_H
26 
27 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
28  #error "Only <final/final.h> can be included directly."
29 #endif
30 
31 #include "final/ftypes.h"
32 
33 namespace finalcut
34 {
35 
36 namespace internal
37 {
38 
39 template<typename T>
40 inline auto checkBits (const T& subset, const T& superset) -> bool
41 {
42  static_assert( sizeof(T) == sizeof(uInt16), "Must be a 16-bit struct" );
43  uInt16 a{};
44  uInt16 b{};
45  std::memcpy(&a, &subset, sizeof(T));
46  std::memcpy(&b, &superset, sizeof(T));
47 
48  // All bits from 'a' must be present in 'b'
49  return (a & b) == a;
50 }
51 
52 }
53 
55 {
56  uInt16 active : 1;
57  uInt16 scrollable : 1;
58  uInt16 resizable : 1;
59  uInt16 minimizable : 1;
60  uInt16 flat : 1;
61  uInt16 no_border : 1;
62  uInt16 no_underline : 1;
63  uInt16 ignore_padding : 1;
64  uInt16 : 8; // padding bits
65 };
66 
68 {
69  uInt16 visible : 1;
70  uInt16 hidden : 1;
71  uInt16 shown : 1;
72  uInt16 modal : 1;
73  uInt16 always_on_top : 1;
74  uInt16 visible_cursor : 1;
75  uInt16 initialize_layout : 1;
76  uInt16 : 9; // padding bits
77 };
78 
80 {
81  uInt16 focus : 1;
82  uInt16 focusable : 1;
83  uInt16 : 14; // padding bits
84 };
85 
87 {
88  uInt16 shadow : 1;
89  uInt16 trans_shadow : 1;
90  uInt16 : 14; // padding bits
91 };
92 
94 {
95  uInt16 window_widget : 1;
96  uInt16 dialog_widget : 1;
97  uInt16 menu_widget : 1;
98  uInt16 : 13; // padding bits
99 };
100 
101 // Main struct, which contains all the data
103 {
104  FWidgetFeature feature;
105  FWidgetVisibility visibility;
106  FWidgetFocus focus;
107  FWidgetShadow shadow;
108  FWidgetType type;
109 };
110 
111 inline auto containsFWidgetFlags ( const FWidgetFlags& subset
112  , const FWidgetFlags& superset ) -> bool
113 {
114  return internal::checkBits (subset.feature, superset.feature)
115  && internal::checkBits (subset.visibility, superset.visibility)
116  && internal::checkBits (subset.focus, superset.focus)
117  && internal::checkBits (subset.shadow, superset.shadow)
118  && internal::checkBits (subset.type, superset.type);
119 }
120 
121 } // namespace finalcut
122 
123 #endif // FWIDGET_FLAGS_H
Definition: fwidget_flags.h:102
Definition: fwidget_flags.h:93
Definition: fwidget_flags.h:67
Definition: fwidget_flags.h:54
Definition: fwidget_flags.h:79
Definition: class_template.cpp:25
Definition: fwidget_flags.h:86