Skip to main content

vb6parse/language/controls/
picturebox.rs

1//! Properties for `PictureBox` controls.
2//!
3//! This is used as an enum variant of
4//! [`ControlKind::PictureBox`](crate::language::controls::ControlKind::PictureBox).
5//! tag, name, and index are not included in this struct, but instead are part
6//! of the parent [`Control`](crate::language::controls::Control) struct.
7//!
8
9use crate::{
10    files::common::Properties,
11    language::{
12        color::{Color, VB_BUTTON_FACE, VB_BUTTON_TEXT, VB_SCROLL_BARS},
13        controls::{
14            Activation, Align, Appearance, AutoRedraw, AutoSize, BorderStyle, CausesValidation,
15            ClipControls, DragMode, DrawMode, DrawStyle, FillStyle, Font, FontTransparency,
16            HasDeviceContext, LinkMode, MousePointer, OLEDragMode, OLEDropMode, ReferenceOrValue,
17            ScaleMode, TabStop, TextDirection, Visibility,
18        },
19    },
20};
21
22use image::DynamicImage;
23use serde::Serialize;
24
25/// Properties for a `PictureBox` control.
26///
27/// This is used as an enum variant of
28/// [`ControlKind::PictureBox`](crate::language::controls::ControlKind::PictureBox).
29/// tag, name, and index are not included in this struct, but instead are part
30/// of the parent [`Control`](crate::language::controls::Control) struct.
31#[derive(Debug, PartialEq, Clone)]
32pub struct PictureBoxProperties {
33    /// Alignment of the `PictureBox`.
34    pub align: Align,
35    /// Appearance of the `PictureBox`.
36    pub appearance: Appearance,
37    /// `AutoRedraw` setting of the `PictureBox`.
38    pub auto_redraw: AutoRedraw,
39    /// `AutoSize` setting of the `PictureBox`.
40    pub auto_size: AutoSize,
41    /// Background color of the `PictureBox`.
42    pub back_color: Color,
43    /// Border style of the `PictureBox`.
44    pub border_style: BorderStyle,
45    /// Indicates whether the `PictureBox` causes validation.
46    pub causes_validation: CausesValidation,
47    /// The `ClipControls` setting of the `PictureBox`.
48    pub clip_controls: ClipControls,
49    /// Data field associated with the `PictureBox`.
50    pub data_field: String,
51    /// Data format associated with the `PictureBox`.
52    pub data_format: String,
53    /// Data member associated with the `PictureBox`.
54    pub data_member: String,
55    /// Data source associated with the `PictureBox`.
56    pub data_source: String,
57    /// Drag icon for the `PictureBox`.
58    pub drag_icon: Option<ReferenceOrValue<DynamicImage>>,
59    /// Drag mode of the `PictureBox`.
60    pub drag_mode: DragMode,
61    /// Draw mode of the `PictureBox`.
62    pub draw_mode: DrawMode,
63    /// Draw style of the `PictureBox`.
64    pub draw_style: DrawStyle,
65    /// Width of the drawing pen.
66    pub draw_width: i32,
67    /// Indicates whether the `PictureBox` is enabled.
68    pub enabled: Activation,
69    /// The font style for the form.
70    pub font: Option<Font>,
71    /// Fill color of the `PictureBox`.
72    pub fill_color: Color,
73    /// Fill style of the `PictureBox`.
74    pub fill_style: FillStyle,
75    /// Font transparency setting of the `PictureBox`.
76    pub font_transparent: FontTransparency,
77    /// Foreground color of the `PictureBox`.
78    pub fore_color: Color,
79    /// Indicates whether the `PictureBox` has a device context.
80    pub has_dc: HasDeviceContext,
81    /// Height of the `PictureBox`.
82    pub height: i32,
83    /// Help context ID of the `PictureBox`.
84    pub help_context_id: i32,
85    /// Left position of the `PictureBox`.
86    pub left: i32,
87    /// Link item associated with the `PictureBox`.
88    pub link_item: String,
89    /// Link mode of the `PictureBox`.
90    pub link_mode: LinkMode,
91    /// Link timeout of the `PictureBox`.
92    pub link_timeout: i32,
93    /// Link topic associated with the `PictureBox`.
94    pub link_topic: String,
95    /// Mouse icon for the `PictureBox`.
96    pub mouse_icon: Option<ReferenceOrValue<DynamicImage>>,
97    /// Mouse pointer style of the `PictureBox`.
98    pub mouse_pointer: MousePointer,
99    /// Indicates whether the `PictureBox` negotiates OLE drag-and-drop operations.
100    pub negotiate: bool,
101    /// OLE drag mode of the `PictureBox`.
102    pub ole_drag_mode: OLEDragMode,
103    /// OLE drop mode of the `PictureBox`.
104    pub ole_drop_mode: OLEDropMode,
105    /// Picture displayed in the `PictureBox`.
106    pub picture: Option<ReferenceOrValue<DynamicImage>>,
107    /// Text direction of the `PictureBox`.
108    pub right_to_left: TextDirection,
109    /// Scale height of the `PictureBox`.
110    pub scale_height: i32,
111    /// Scale left position of the `PictureBox`.
112    pub scale_left: i32,
113    /// Scale mode of the `PictureBox`.
114    pub scale_mode: ScaleMode,
115    /// Scale top position of the `PictureBox`.
116    pub scale_top: i32,
117    /// Scale width of the `PictureBox`.
118    pub scale_width: i32,
119    /// Tab index of the `PictureBox`.
120    pub tab_index: i32,
121    /// Tab stop setting of the `PictureBox`.
122    pub tab_stop: TabStop,
123    /// Tool tip text of the `PictureBox`.
124    pub tool_tip_text: String,
125    /// Top position of the `PictureBox`.
126    pub top: i32,
127    /// Visibility of the `PictureBox`.
128    pub visible: Visibility,
129    /// "What's This?" help ID of the `PictureBox`.
130    pub whats_this_help_id: i32,
131    /// Width of the `PictureBox`.
132    pub width: i32,
133}
134
135impl Default for PictureBoxProperties {
136    fn default() -> Self {
137        PictureBoxProperties {
138            align: Align::None,
139            appearance: Appearance::ThreeD,
140            auto_redraw: AutoRedraw::Manual,
141            auto_size: AutoSize::Fixed,
142            back_color: VB_BUTTON_FACE,
143            border_style: BorderStyle::FixedSingle,
144            causes_validation: CausesValidation::Yes,
145            clip_controls: ClipControls::default(),
146            data_field: String::new(),
147            data_format: String::new(),
148            data_member: String::new(),
149            data_source: String::new(),
150            drag_icon: None,
151            drag_mode: DragMode::Manual,
152            draw_mode: DrawMode::CopyPen,
153            draw_style: DrawStyle::Solid,
154            draw_width: 1,
155            enabled: Activation::Enabled,
156            fill_color: VB_SCROLL_BARS,
157            fill_style: FillStyle::Transparent,
158            font: Some(Font::default()),
159            font_transparent: FontTransparency::Transparent,
160            fore_color: VB_BUTTON_TEXT,
161            has_dc: HasDeviceContext::HasContext,
162            height: 30,
163            help_context_id: 0,
164            left: 30,
165            link_item: String::new(),
166            link_mode: LinkMode::None,
167            link_timeout: 50,
168            link_topic: String::new(),
169            mouse_icon: None,
170            mouse_pointer: MousePointer::Default,
171            negotiate: false,
172            ole_drag_mode: OLEDragMode::Manual,
173            ole_drop_mode: OLEDropMode::default(),
174            picture: None,
175            right_to_left: TextDirection::LeftToRight,
176            scale_height: 100,
177            scale_left: 0,
178            scale_mode: ScaleMode::Twip,
179            scale_top: 0,
180            scale_width: 100,
181            tab_index: 0,
182            tab_stop: TabStop::Included,
183            tool_tip_text: String::new(),
184            top: 30,
185            visible: Visibility::Visible,
186            whats_this_help_id: 0,
187            width: 100,
188        }
189    }
190}
191
192impl Serialize for PictureBoxProperties {
193    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
194    where
195        S: serde::Serializer,
196    {
197        use serde::ser::SerializeStruct;
198
199        let mut s = serializer.serialize_struct("PictureBoxProperties", 39)?;
200        s.serialize_field("align", &self.align)?;
201        s.serialize_field("appearance", &self.appearance)?;
202        s.serialize_field("auto_redraw", &self.auto_redraw)?;
203        s.serialize_field("auto_size", &self.auto_size)?;
204        s.serialize_field("back_color", &self.back_color)?;
205        s.serialize_field("border_style", &self.border_style)?;
206        s.serialize_field("causes_validation", &self.causes_validation)?;
207        s.serialize_field("clip_controls", &self.clip_controls)?;
208        s.serialize_field("data_field", &self.data_field)?;
209        s.serialize_field("data_format", &self.data_format)?;
210        s.serialize_field("data_member", &self.data_member)?;
211        s.serialize_field("data_source", &self.data_source)?;
212
213        let option_text = self.drag_icon.as_ref().map(|_| "Some(DynamicImage)");
214
215        s.serialize_field("drag_icon", &option_text)?;
216        s.serialize_field("drag_mode", &self.drag_mode)?;
217        s.serialize_field("draw_mode", &self.draw_mode)?;
218        s.serialize_field("draw_style", &self.draw_style)?;
219        s.serialize_field("draw_width", &self.draw_width)?;
220        s.serialize_field("enabled", &self.enabled)?;
221        s.serialize_field("fill_color", &self.fill_color)?;
222        s.serialize_field("fill_style", &self.fill_style)?;
223        s.serialize_field("font_transparent", &self.font_transparent)?;
224        s.serialize_field("fore_color", &self.fore_color)?;
225        s.serialize_field("has_dc", &self.has_dc)?;
226        s.serialize_field("height", &self.height)?;
227        s.serialize_field("help_context_id", &self.help_context_id)?;
228        s.serialize_field("left", &self.left)?;
229        s.serialize_field("link_item", &self.link_item)?;
230        s.serialize_field("link_mode", &self.link_mode)?;
231        s.serialize_field("link_timeout", &self.link_timeout)?;
232        s.serialize_field("link_topic", &self.link_topic)?;
233
234        let option_text = self.mouse_icon.as_ref().map(|_| "Some(DynamicImage)");
235
236        s.serialize_field("mouse_icon", &option_text)?;
237        s.serialize_field("mouse_pointer", &self.mouse_pointer)?;
238        s.serialize_field("negotiate", &self.negotiate)?;
239        s.serialize_field("ole_drag_mode", &self.ole_drag_mode)?;
240        s.serialize_field("ole_drop_mode", &self.ole_drop_mode)?;
241
242        let option_text = self.picture.as_ref().map(|_| "Some(DynamicImage)");
243
244        s.serialize_field("picture", &option_text)?;
245        s.serialize_field("right_to_left", &self.right_to_left)?;
246        s.serialize_field("scale_height", &self.scale_height)?;
247        s.serialize_field("scale_left", &self.scale_left)?;
248        s.serialize_field("scale_mode", &self.scale_mode)?;
249        s.serialize_field("scale_top", &self.scale_top)?;
250        s.serialize_field("scale_width", &self.scale_width)?;
251        s.serialize_field("tab_index", &self.tab_index)?;
252        s.serialize_field("tab_stop", &self.tab_stop)?;
253        s.serialize_field("tool_tip_text", &self.tool_tip_text)?;
254        s.serialize_field("top", &self.top)?;
255        s.serialize_field("visible", &self.visible)?;
256        s.serialize_field("whats_this_help_id", &self.whats_this_help_id)?;
257        s.serialize_field("width", &self.width)?;
258
259        s.end()
260    }
261}
262
263impl From<Properties> for PictureBoxProperties {
264    fn from(prop: Properties) -> Self {
265        let mut picture_box_prop = PictureBoxProperties::default();
266
267        picture_box_prop.align = prop.get_property("Align", picture_box_prop.align);
268        picture_box_prop.appearance = prop.get_property("Appearance", picture_box_prop.appearance);
269        picture_box_prop.auto_redraw =
270            prop.get_property("AutoRedraw", picture_box_prop.auto_redraw);
271        picture_box_prop.auto_size = prop.get_property("AutoSize", picture_box_prop.auto_size);
272        picture_box_prop.back_color = prop.get_color("BackColor", picture_box_prop.back_color);
273        picture_box_prop.border_style =
274            prop.get_property("BorderStyle", picture_box_prop.border_style);
275        picture_box_prop.causes_validation =
276            prop.get_property("CausesValidation", picture_box_prop.causes_validation);
277        picture_box_prop.clip_controls =
278            prop.get_property("ClipControls", picture_box_prop.clip_controls);
279        picture_box_prop.data_field = match prop.get("DataField") {
280            Some(data_field) => data_field.into(),
281            None => picture_box_prop.data_field,
282        };
283        picture_box_prop.data_format = match prop.get("DataFormat") {
284            Some(data_format) => data_format.into(),
285            None => picture_box_prop.data_format,
286        };
287        picture_box_prop.data_member = match prop.get("DataMember") {
288            Some(data_member) => data_member.into(),
289            None => picture_box_prop.data_member,
290        };
291        picture_box_prop.data_source = match prop.get("DataSource") {
292            Some(data_source) => data_source.into(),
293            None => picture_box_prop.data_source,
294        };
295
296        // DragIcon
297
298        picture_box_prop.drag_mode = prop.get_property("DragMode", picture_box_prop.drag_mode);
299        picture_box_prop.draw_mode = prop.get_property("DrawMode", picture_box_prop.draw_mode);
300        picture_box_prop.draw_style = prop.get_property("DrawStyle", picture_box_prop.draw_style);
301        picture_box_prop.draw_width = prop.get_i32("DrawWidth", picture_box_prop.draw_width);
302        picture_box_prop.enabled = prop.get_property("Enabled", picture_box_prop.enabled);
303        picture_box_prop.fill_color = prop.get_color("FillColor", picture_box_prop.fill_color);
304        picture_box_prop.fill_style = prop.get_property("FillStyle", picture_box_prop.fill_style);
305        picture_box_prop.font_transparent =
306            prop.get_property("FontTransparent", picture_box_prop.font_transparent);
307        picture_box_prop.fore_color = prop.get_color("ForeColor", picture_box_prop.fore_color);
308        picture_box_prop.has_dc = prop.get_property("HasDC", picture_box_prop.has_dc);
309        picture_box_prop.height = prop.get_i32("Height", picture_box_prop.height);
310        picture_box_prop.help_context_id =
311            prop.get_i32("HelpContextID", picture_box_prop.help_context_id);
312        picture_box_prop.left = prop.get_i32("Left", picture_box_prop.left);
313        picture_box_prop.link_item = match prop.get("LinkItem") {
314            Some(link_item) => link_item.into(),
315            None => picture_box_prop.link_item,
316        };
317        picture_box_prop.link_mode = prop.get_property("LinkMode", picture_box_prop.link_mode);
318        picture_box_prop.link_timeout = prop.get_i32("LinkTimeout", picture_box_prop.link_timeout);
319        picture_box_prop.link_topic = match prop.get("LinkTopic") {
320            Some(link_topic) => link_topic.into(),
321            None => picture_box_prop.link_topic,
322        };
323
324        // TODO: process MouseIcon
325        // MouseIcon
326
327        picture_box_prop.mouse_pointer =
328            prop.get_property("MousePointer", picture_box_prop.mouse_pointer);
329        picture_box_prop.negotiate = prop.get_bool("Negotiate", picture_box_prop.negotiate);
330        picture_box_prop.ole_drag_mode =
331            prop.get_property("OLEDragMode", picture_box_prop.ole_drag_mode);
332        picture_box_prop.ole_drop_mode =
333            prop.get_property("OLEDropMode", picture_box_prop.ole_drop_mode);
334
335        // TODO: process Picture
336        // Picture
337
338        picture_box_prop.right_to_left =
339            prop.get_property("RightToLeft", picture_box_prop.right_to_left);
340        picture_box_prop.scale_height = prop.get_i32("ScaleHeight", picture_box_prop.scale_height);
341        picture_box_prop.scale_left = prop.get_i32("ScaleLeft", picture_box_prop.scale_left);
342        picture_box_prop.scale_mode = prop.get_property("ScaleMode", picture_box_prop.scale_mode);
343        picture_box_prop.scale_top = prop.get_i32("ScaleTop", picture_box_prop.scale_top);
344        picture_box_prop.scale_width = prop.get_i32("ScaleWidth", picture_box_prop.scale_width);
345        picture_box_prop.tab_index = prop.get_i32("TabIndex", picture_box_prop.tab_index);
346        picture_box_prop.tab_stop = prop.get_property("TabStop", picture_box_prop.tab_stop);
347        picture_box_prop.tool_tip_text = match prop.get("ToolTipText") {
348            Some(tool_tip_text) => tool_tip_text.into(),
349            None => String::new(),
350        };
351        picture_box_prop.top = prop.get_i32("Top", picture_box_prop.top);
352        picture_box_prop.visible = prop.get_property("Visible", picture_box_prop.visible);
353        picture_box_prop.whats_this_help_id =
354            prop.get_i32("WhatsThisHelpID", picture_box_prop.whats_this_help_id);
355        picture_box_prop.width = prop.get_i32("Width", picture_box_prop.width);
356
357        picture_box_prop
358    }
359}