ms_oforms/controls/form/mod.rs
1//! ## The `FromControl` binary format
2//!
3//! Excerpt from the docs:
4//!
5//! > All parent controls MUST contain a FormControl. The FormControl properties are persisted to a stream as specified in section 2.1.1.2. The name of this stream MUST be "f". An OleSiteConcrete is persisted in this stream for each embedded control, as specified by the FormControl in section 2.2.10.12. The FormControl can also contain a DesignExtender, as specified in section 2.2.10.11.
6
7#[allow(unused_imports)]
8use num_traits::{FromPrimitive, ToPrimitive};
9use crate::controls::ole_site_concrete::OleSiteConcrete;
10
11use crate::properties::types::{
12 font::GuidAndFont,
13 picture::GuidAndPicture,
14 color::OleColor,
15 SpecialEffect,
16 PictureAlignment,
17 PictureSizeMode,
18 MousePointer,
19 Size, Position,
20};
21use crate::common::{GUID, VarFlags, VarType};
22
23pub mod parser;
24pub mod stream;
25pub mod designex;
26
27bitflags!{
28 /// A bit field that specifies Boolean properties of a form.
29 pub struct FormFlags: u32 {
30 /// Specifies whether the form is enabled.
31 const ENABLED = 0x00000004;
32 /// Specifies whether Design Extender properties are persisted with this form.
33 const DESINKPERSISTED = 0x00004000;
34 /// Specifies whether the Class Table of a form is not persisted. A value of zero specifies that the Class Table is persisted if it is not empty.
35 const DONTSAVECLASSTABLE = 0x00008000;
36 }
37}
38
39#[repr(u8)]
40#[derive(Debug, FromPrimitive, ToPrimitive)]
41pub enum BorderStyle {
42 /// The control has no visible border line.
43 None = 0x00,
44 /// The control has a single-line border.
45 Single = 0x01,
46}
47
48/// Specifies the behavior of the TAB key in the last control of a form
49#[repr(u8)]
50#[derive(Debug, FromPrimitive, ToPrimitive)]
51pub enum Cycle {
52 /// The focus is next set to the first control on the next form, returning to the first control of this form only after all controls on all other forms have been reached.
53 AllForms = 0x00,
54 /// The focus is next set to the first control on this form, ignoring other forms.
55 CurrentForm = 0x02,
56}
57
58bitflags! {
59 /// A bit field that specifies the location of the scroll bars of a form.
60 pub struct FormScrollBarFlags: u8 {
61 /// Specifies whether the horizontal scroll bar is displayed.
62 const HORIZONTAL = 0x01;
63 /// Specifies whether the vertical scroll bar is displayed.
64 const VERTICAL = 0x02;
65 /// Specifies whether to display the horizontal scroll bar at all times, even when all controls are visible without scrolling.
66 const KEEP_HORIZONTAL = 0x04;
67 /// Specifies whether to display the vertical scroll bar at all times, even when all controls are visible without scrolling.
68 const KEEP_VERTICAL = 0x08;
69 /// Specifies whether to display the vertical scroll bar on the left side of the form.
70 const KEEP_LEFT = 0x10;
71 /// The default value
72 const DEFAULT = Self::KEEP_HORIZONTAL.bits | Self::KEEP_VERTICAL.bits;
73 }
74}
75
76#[derive(Debug)]
77pub enum Site {
78 Ole(OleSiteConcrete),
79}
80
81#[derive(Debug)]
82pub struct FormControl {
83 /// default: 0x8000000F = COLOR_BTNFACE from the system palette.
84 pub back_color: OleColor,
85 /// default: 0x00000004 = FORM_FLAG_ENABLED
86 pub boolean_properties: FormFlags,
87 /// default: 0x80000012 = COLOR_BTNTEXT from the system palette.
88 pub border_color: OleColor,
89 /// default: 0x00 = None
90 pub border_style: BorderStyle,
91 /// default: ""
92 pub caption: String,
93 /// default: AllForms
94 pub cycle: Cycle,
95 /// default: (4000, 3000)
96 pub displayed_size: Size,
97 /// REQUIRED
98 pub draw_buffer: u32,
99 /// default: no font
100 pub font: GuidAndFont,
101 /// default: 0x80000012 = COLOR_BTNTEXT from the system palette
102 pub fore_color: OleColor,
103 /// An unsigned integer that specifies the number of control groups on a form. default: 0
104 pub group_count: u32,
105 /// An fmSize that specifies the full scrollable size, in HIMETRIC units, of a form, including all controls. A value of zero in either width or height specifies that the scrollable size is equivalent to the value of the corresponding portion of DisplayedSize.
106 ///
107 /// default: (4000, 3000)
108 pub logical_size: Size,
109 /// A GuidAndPicture that specifies a custom icon to display as the mouse pointer for the control, which is used when the value of the MousePointer property is set to 99, fmMousePointerCustom.
110 ///
111 /// The file format default is no custom icon.
112 pub mouse_icon: GuidAndPicture,
113 /// An unsigned integer that specifies the type of icon displayed as the mouse pointer for the control. SHOULD be a value from the fmMousePointer enumeration.<8>
114 ///
115 /// The file format default is 0x00, fmMousePointerDefault.
116 pub mouse_pointer: MousePointer,
117 /// An unsigned integer that specifies the largest ID that has been used by an embedded control on a form. The value of this property can be used by the client application to determine the next valid ID for a new control.
118 ///
119 /// The file format default is 0x00000000.
120 pub next_available_id: u32,
121 /// A GuidAndPicture that specifies the picture to display on a control.
122 ///
123 /// The file format default is no picture.
124 pub picture: GuidAndPicture,
125
126 /// An fmPictureAlignment that specifies the alignment of the picture in the Form or Image.
127 ///
128 /// The file format default is 0x02, fmPictureAlignmentCenter.
129 pub picture_alignment: PictureAlignment,
130 /// An fmPictureSizeMode that specifies how to display the picture.
131 ///
132 /// The file format default is 0x00, fmPictureSizeModeClip.
133 pub picture_size_mode: PictureSizeMode,
134 /// A Boolean value that specifies whether the picture is tiled across the background.
135 ///
136 /// The file format default is FALSE.
137 pub picture_tiling: bool,
138 /// A FormScrollBarFlags that specifies whether a form has vertical or horizontal scroll bars and when to display them.
139 ///
140 /// The file format default is 0x0000000C, fScrollBarsKeepHorizontal and fScrollBarsKeepVertical.
141 pub scroll_bars: FormScrollBarFlags,
142 /// An fmPosition that specifies, in HIMETRIC units, the coordinates of the first point in the LogicalSize of the form that is visible.
143 ///
144 /// The file format default is a position of (0, 0), which specifies that the form has not been scrolled.
145 pub scroll_position: Position,
146 /// An unsigned integer that specifies the number of times the dynamic type information of a form has changed. The value of this property can be used to determine whether a form being loaded still matches the dynamic type information against which it was compiled.
147 ///
148 /// The file format default is 0x00000000.
149 pub shape_cookie: u32,
150 /// An fmSpecialEffect that specifies the visual appearance of the control.
151 ///
152 /// The file format default is 0x00, fmSpecialEffectFlat
153 pub special_effect: SpecialEffect,
154 /// A signed integer that specifies the magnification of embedded controls, in percentage points of the size of the parent control. MUST be greater than or equal to 10 (10 percent of actual size) and less than or equal to 400 (four times or 400 percent of actual size).
155 ///
156 /// The file format default is 100, or actual size.
157 pub zoom: u32,
158 /// All contained sites
159 pub sites: Vec<Site>,
160
161 /// All contained site classes
162 pub site_classes: Vec<ClassTable>,
163}
164
165bitflags! {
166 /// A bit field that specifies Boolean properties of a SiteClassInfo.
167 pub struct ClsTableFlags: u16 {
168 /// Specifies whether the typeKind member of the TYPEATTR that describes this type
169 /// information, as specified in [MS-OAUT] section 2.2.44, is set to TKIND_ALIAS, as
170 /// specified in [MS-OAUT] section 2.2.17.
171 const EXCLUSIVE_VALUE = 0x0001;
172 /// Specifies whether this type information implements a dual interface.
173 const DUAL_INTERFACE = 0x0002;
174 /// Specifies whether this type information supports aggregation. A value of 1 specifies
175 /// that the control does not support aggregation.
176 const NO_AGGREGATION = 0x0004;
177 }
178}
179
180/// Specifies the structure, as persisted to a stream, of the type information of an embedded ActiveX control.
181#[derive(Debug)]
182pub struct ClassTable {
183 /// A CLSTABLE_FLAGS that specifies Boolean properties of the type information.
184 ///
185 /// The file format default is 0x0000.
186 pub class_table_flags: ClsTableFlags,
187 /// A VARFLAGS, as specified in [MS-OAUT] section 2.2.18, that specifies Boolean properties of
188 /// the type information.
189 ///
190 /// The file format default is 0x0000.
191 pub var_flags: VarFlags,
192 /// An unsigned integer that specifies the number of methods on the default dual interface of
193 /// the type information.
194 ///
195 /// The file format default is 0x00000000.
196 pub count_of_methods: u32,
197 /// An unsigned integer that specifies the IDispatch identifier (DispID) of the default
198 /// bindable property, as specified in [MS-OAUT] section 2.2.49.5.2, in this type information.
199 /// The value of this field is the memid field of the VARDESC of the function, as specified in
200 /// [MS-OAUT] section 2.2.43. The VARDESC.wVarFlags field MUST be set to 0x00000014, or
201 /// FUNCFLAG_FBINDABLE and FUNCFLAG_FDISPLAYBIND, as specified in [MS-OAUT] section 2.2.11.
202 pub dispid_bind: u32,
203 /// An unsigned integer that specifies the index of the "get" function of the default bindable
204 /// property, as specified in [MS-OAUT] section 2.2.49.5.2, into the dynamic virtual table of a
205 /// type information that implements a dual interface. The value of this field is the oVft
206 /// field of the FUNCDESC that specifies the function, as specified in [MS-OAUT] section 2.2.42.
207 /// The memid field of this FUNCDESC MUST NOT be set to DISPID_VALUE, as specified in [MS-OAUT]
208 /// section 2.2.32.1. The invkind field of this FUNCDESC MUST be set to INVOKE_PROPERTYGET, as
209 /// specified in [MS-OAUT] section 2.2.14.
210 ///
211 /// The file format default is 0x0000.
212 pub get_bind_index: u16,
213 /// An unsigned integer that specifies the index of the "put" function of the default bindable
214 /// property, as specified in [MS-OAUT] section 2.2.49.5.2, into the dynamic virtual table of a
215 /// type information that implements a dual interface. The value of this field is the oVft
216 /// field of the FUNCDESC that specifies the function, as specified in [MS-OAUT] section 2.2.42.
217 /// The memid field of this FUNCDESC MUST NOT be set to DISPID_VALUE, as specified in [MS-OAUT]
218 /// section 2.2.32.1. The invkind field of this FUNCDESC MUST be set to INVOKE_PROPERTYPUT, as
219 /// specified in [MS-OAUT] section 2.2.14.
220 ///
221 /// The file format default is 0x0000.
222 pub put_bind_index: u16,
223 /// A variant type that specifies the type of the default bindable property, as specified in
224 /// [MS-OAUT] section 2.2.49.5.2. The value of this field is the vt field of the TYPEDESC, as
225 /// specified in [MS-OAUT] section 2.2.37, of the FUNCDESC.elemdescFunc, as specified in
226 /// [MS-OAUT] section 2.2.42, of the function referenced by GetBindIndex or PutBindIndex in
227 /// this ClassInfoDataBlock.
228 ///
229 /// The file format default is 0x0000, VT_EMPTY.
230 pub bind_type: VarType,
231 /// An unsigned integer that specifies the index of the function that retrieves the value of
232 /// the control into the dynamic virtual table of the class. The value of this field is the
233 /// oVft field of the FUNCDESC that specifies the function, as specified in [MS-OAUT] section
234 /// 2.2.42. The memid of the FUNCDESC MUST be set to DISPID_VALUE, as specified in [MS-OAUT]
235 /// section 2.2.32.1. The invkind field of the FUNCDESC MUST be set to INVOKE_PROPERTYGET, as
236 /// specified in [MS-OAUT] section 2.2.14.
237 ///
238 /// The file format default is 0x0000.
239 pub get_value_index: u16,
240 /// An unsigned integer that specifies the index of the function that sets the value of the
241 /// control into the dynamic virtual table of the class. The value of this field is the oVft
242 /// field of the FUNCDESC that specifies the function, as specified in [MS-OAUT] section
243 /// 2.2.42. The memid of the FUNCDESC MUST be set to DISPID_VALUE, as specified in [MS-OAUT]
244 /// section 2.2.32.1. The invkind field of the FUNCDESC MUST be set to INVOKE_PROPERTYPUT, as
245 /// specified in [MS-OAUT] section 2.2.14.
246 ///
247 /// The file format default is 0x0000.
248 pub put_value_index: u16,
249 /// A variant type that specifies the type of the value that is returned in response to
250 /// DISPID_VALUE. The value of this field is the vt field of the TYPEDESC, as specified in
251 /// [MS-OAUT] section 2.2.37, of the FUNCDESC.elemdescFunc, as specified in [MS-OAUT] section
252 /// 2.2.42, of the function referenced by GetValueIndex or PutValueIndex in this
253 /// ClassInfoDataBlock.
254 ///
255 /// The file format default is 0x0000, VT_EMPTY.
256 pub value_type: VarType,
257 /// An unsigned integer that specifies the DispID of a property that supports a method for
258 /// fetching rows sequentially, getting the data from those rows, and managing rows. The
259 /// value of this field is the memid field of the FUNCDESC that specifies the property "set"
260 /// method, as specified in [MS-OAUT] section 2.2.42, or of the VARDESC that specifies the
261 /// property, as specified in [MS-OAUT] section 2.2.43. The value of memid can be determined by
262 /// the algorithm specified in section 2.6.1.1.
263 ///
264 /// The file format default is 0xFFFFFFFF, DISPID_UNKNOWN.
265 pub dispid_rowset: u32,
266 /// An unsigned integer that specifies the index of the "set" function into the dynamic virtual
267 /// table of the class, for a property that supports a method for fetching rows sequentially,
268 /// getting the data from those rows, and managing rows. The value of this field is the oVft
269 /// field of the FUNCDESC that specifies the property "set" method, as specified in [MS-OAUT]
270 /// section 2.2.42. The value of oVft can be determined by the algorithm specified in section
271 /// 2.6.1.2.
272 ///
273 /// The file format default is 0x0000.
274 pub set_rowset: u16,
275 /// A GUID, as specified in [MS-DTYP], that specifies the CLSID of a control.
276 ///
277 /// The file format default is {00000000-0000-0000-0000-000000000000}.
278 pub cls_id: GUID,
279 /// A GUID, as specified in [MS-DTYP], that specifies the source interface, as specified in
280 /// [MS-OAUT] section 2.2.49.8, in this type information.
281 ///
282 /// The file format default is {00020400-0000-0000-C000-000000000046}.
283 pub disp_event: GUID,
284 /// A GUID, as specified in [MS-DTYP], that specifies the default interface, as specified in
285 /// [MS-OAUT] section 2.2.49.8, in this type information.
286 ///
287 /// The file format default is {00020400-0000-0000-C000-000000000046}.
288 pub default_proc: GUID,
289}