Skip to main content

vb6parse/language/controls/
dirlistbox.rs

1//! Properties for a `DirListBox` control.
2//!
3//! This is used as an enum variant of
4//! [`ControlKind::DirListBox`](crate::language::controls::ControlKind::DirListBox).
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//!
8use crate::files::common::Properties;
9use crate::language::controls::{
10    Activation, Appearance, CausesValidation, DragMode, Font, MousePointer, OLEDragMode,
11    OLEDropMode, ReferenceOrValue, TabStop, Visibility,
12};
13use crate::language::Color;
14
15use image::DynamicImage;
16use serde::Serialize;
17
18/// Properties for a `DirListBox` control.
19///
20/// This is used as an enum variant of
21/// [`ControlKind::DirListBox`](crate::language::controls::ControlKind::DirListBox).
22/// tag, name, and index are not included in this struct, but instead are part
23/// of the parent [`Control`](crate::language::controls::Control) struct.
24#[derive(Debug, PartialEq, Clone)]
25pub struct DirListBoxProperties {
26    /// The appearance of the `DirListBox`.
27    pub appearance: Appearance,
28    /// The background color of the `DirListBox`.
29    pub back_color: Color,
30    /// Whether the `DirListBox` causes validation.
31    pub causes_validation: CausesValidation,
32    /// The drag icon of the `DirListBox`.
33    pub drag_icon: Option<ReferenceOrValue<DynamicImage>>,
34    /// The drag mode of the `DirListBox`.
35    pub drag_mode: DragMode,
36    /// Whether the `DirListBox` is enabled.
37    pub enabled: Activation,
38    /// The font style for the form.
39    pub font: Option<Font>,
40    /// The foreground color of the `DirListBox`.
41    pub fore_color: Color,
42    /// The height of the `DirListBox`.
43    pub height: i32,
44    /// The help context ID of the `DirListBox`.
45    pub help_context_id: i32,
46    /// The left position of the `DirListBox`.
47    pub left: i32,
48    /// The mouse icon of the `DirListBox`.
49    pub mouse_icon: Option<ReferenceOrValue<DynamicImage>>,
50    /// The mouse pointer of the `DirListBox`.
51    pub mouse_pointer: MousePointer,
52    /// The OLE drag mode of the `DirListBox`.
53    pub ole_drag_mode: OLEDragMode,
54    /// The OLE drop mode of the `DirListBox`.
55    pub ole_drop_mode: OLEDropMode,
56    /// The tab index of the `DirListBox`.
57    pub tab_index: i32,
58    /// The tab stop of the `DirListBox`.
59    pub tab_stop: TabStop,
60    /// The tool tip text of the `DirListBox`.
61    pub tool_tip_text: String,
62    /// The top position of the `DirListBox`.
63    pub top: i32,
64    /// Whether the `DirListBox` is visible.
65    pub visible: Visibility,
66    /// The "What's This" help ID of the `DirListBox`.
67    pub whats_this_help_id: i32,
68    /// The width of the `DirListBox`.
69    pub width: i32,
70}
71
72impl Default for DirListBoxProperties {
73    fn default() -> Self {
74        DirListBoxProperties {
75            appearance: Appearance::ThreeD,
76            back_color: Color::System { index: 5 },
77            causes_validation: CausesValidation::Yes,
78            drag_icon: None,
79            drag_mode: DragMode::Manual,
80            enabled: Activation::Enabled,
81            font: Some(Font::default()),
82            fore_color: Color::System { index: 8 },
83            height: 3195,
84            help_context_id: 0,
85            left: 720,
86            mouse_icon: None,
87            mouse_pointer: MousePointer::Default,
88            ole_drag_mode: OLEDragMode::Manual,
89            ole_drop_mode: OLEDropMode::default(),
90            tab_index: 0,
91            tab_stop: TabStop::Included,
92            tool_tip_text: String::new(),
93            top: 720,
94            visible: Visibility::Visible,
95            whats_this_help_id: 0,
96            width: 975,
97        }
98    }
99}
100
101impl Serialize for DirListBoxProperties {
102    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
103    where
104        S: serde::Serializer,
105    {
106        use serde::ser::SerializeStruct;
107
108        let mut s = serializer.serialize_struct("DirListBoxProperties", 20)?;
109        s.serialize_field("appearance", &self.appearance)?;
110        s.serialize_field("back_color", &self.back_color)?;
111        s.serialize_field("causes_validation", &self.causes_validation)?;
112
113        let option_text = self.drag_icon.as_ref().map(|_| "Some(DynamicImage)");
114
115        s.serialize_field("drag_icon", &option_text)?;
116        s.serialize_field("drag_mode", &self.drag_mode)?;
117        s.serialize_field("enabled", &self.enabled)?;
118        s.serialize_field("fore_color", &self.fore_color)?;
119        s.serialize_field("height", &self.height)?;
120        s.serialize_field("help_context_id", &self.help_context_id)?;
121        s.serialize_field("left", &self.left)?;
122
123        let option_text = self.mouse_icon.as_ref().map(|_| "Some(DynamicImage)");
124
125        s.serialize_field("mouse_icon", &option_text)?;
126        s.serialize_field("mouse_pointer", &self.mouse_pointer)?;
127        s.serialize_field("ole_drag_mode", &self.ole_drag_mode)?;
128        s.serialize_field("ole_drop_mode", &self.ole_drop_mode)?;
129        s.serialize_field("tab_index", &self.tab_index)?;
130        s.serialize_field("tab_stop", &self.tab_stop)?;
131        s.serialize_field("tool_tip_text", &self.tool_tip_text)?;
132        s.serialize_field("top", &self.top)?;
133        s.serialize_field("visible", &self.visible)?;
134        s.serialize_field("whats_this_help_id", &self.whats_this_help_id)?;
135        s.serialize_field("width", &self.width)?;
136
137        s.end()
138    }
139}
140
141impl From<Properties> for DirListBoxProperties {
142    fn from(prop: Properties) -> Self {
143        let mut dir_list_box_prop = DirListBoxProperties::default();
144
145        dir_list_box_prop.appearance =
146            prop.get_property("Appearance", dir_list_box_prop.appearance);
147        dir_list_box_prop.back_color = prop.get_color("BackColor", dir_list_box_prop.back_color);
148        dir_list_box_prop.causes_validation =
149            prop.get_property("CausesValidation", dir_list_box_prop.causes_validation);
150
151        // TODO: Implement DragIcon parsing
152        // DragIcon
153
154        dir_list_box_prop.drag_mode = prop.get_property("DragMode", dir_list_box_prop.drag_mode);
155        dir_list_box_prop.enabled = prop.get_property("Enabled", dir_list_box_prop.enabled);
156        dir_list_box_prop.fore_color = prop.get_color("ForeColor", dir_list_box_prop.fore_color);
157        dir_list_box_prop.height = prop.get_i32("Height", dir_list_box_prop.height);
158        dir_list_box_prop.help_context_id =
159            prop.get_i32("HelpContextID", dir_list_box_prop.help_context_id);
160        dir_list_box_prop.left = prop.get_i32("Left", dir_list_box_prop.left);
161        dir_list_box_prop.mouse_pointer =
162            prop.get_property("MousePointer", dir_list_box_prop.mouse_pointer);
163        dir_list_box_prop.ole_drag_mode =
164            prop.get_property("OLEDragMode", dir_list_box_prop.ole_drag_mode);
165        dir_list_box_prop.ole_drop_mode =
166            prop.get_property("OLEDropMode", dir_list_box_prop.ole_drop_mode);
167        dir_list_box_prop.tab_index = prop.get_i32("TabIndex", dir_list_box_prop.tab_index);
168        dir_list_box_prop.tab_stop = prop.get_property("TabStop", dir_list_box_prop.tab_stop);
169        dir_list_box_prop.tool_tip_text = match prop.get("ToolTipText") {
170            Some(tool_tip_text) => tool_tip_text.into(),
171            None => String::new(),
172        };
173        dir_list_box_prop.top = prop.get_i32("Top", dir_list_box_prop.top);
174        dir_list_box_prop.visible = prop.get_property("Visible", dir_list_box_prop.visible);
175        dir_list_box_prop.whats_this_help_id =
176            prop.get_i32("WhatsThisHelpID", dir_list_box_prop.whats_this_help_id);
177        dir_list_box_prop.width = prop.get_i32("Width", dir_list_box_prop.width);
178
179        dir_list_box_prop
180    }
181}