1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** GUIX Component */
16 /** */
17 /** Scrollbar Management (Scrollbar) */
18 /** */
19 /**************************************************************************/
20
21 #define GX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "gx_api.h"
27 #include "gx_widget.h"
28 #include "gx_button.h"
29 #include "gx_utility.h"
30 #include "gx_scrollbar.h"
31 #include "gx_system.h"
32 #include "gx_window.h"
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _gx_vertical_scrollbar_create PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* Kenneth Maxwell, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This service creates a vertical scrollbar. */
48 /* */
49 /* INPUT */
50 /* */
51 /* scrollbar Scrollbar control block */
52 /* name Name of scrollbar */
53 /* parent Pointer to parent widget */
54 /* appearance Appearance of vertical */
55 /* scrollbar widget */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* status Completion status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _gx_utility_rectangle_define Define a rectangle */
64 /* _gx_system_scroll_appearance_get Retrieve scroll bar settings */
65 /* _gx_button_create Create a button */
66 /* _gx_widget_status_add Set status bit */
67 /* _gx_widget_status_remove Remove status bit */
68 /* [gx_window_scroll_info_get] Retrieve widget scroll info */
69 /* _gx_scroll_thumb_create Create scroll thumb image */
70 /* _gx_pixelmap_transparent_detect Detect whether or not a */
71 /* pixelmap contains */
72 /* transparency information */
73 /* _gx_widget_link Link a widget to its parent */
74 /* _gx_widget_child_clipping_update Update child clipping info */
75 /* */
76 /* CALLED BY */
77 /* */
78 /* Application Code */
79 /* */
80 /* RELEASE HISTORY */
81 /* */
82 /* DATE NAME DESCRIPTION */
83 /* */
84 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
85 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
86 /* resulting in version 6.1 */
87 /* */
88 /**************************************************************************/
_gx_vertical_scrollbar_create(GX_SCROLLBAR * scrollbar,GX_CONST GX_CHAR * name,GX_WINDOW * parent,GX_SCROLLBAR_APPEARANCE * appearance,ULONG style)89 UINT _gx_vertical_scrollbar_create(GX_SCROLLBAR *scrollbar, GX_CONST GX_CHAR *name,
90 GX_WINDOW *parent, GX_SCROLLBAR_APPEARANCE *appearance, ULONG style)
91 {
92
93 GX_RECTANGLE size;
94 USHORT id;
95
96 _gx_utility_rectangle_define(&size, 0, 0, 0, 0);
97 id = GX_ID_VERTICAL_SCROLL;
98
99 if (appearance)
100 {
101 scrollbar -> gx_scrollbar_appearance = *appearance;
102 }
103 else
104 {
105 _gx_system_scroll_appearance_get(GX_SCROLLBAR_VERTICAL, &scrollbar -> gx_scrollbar_appearance);
106 }
107
108 /* make sure style is set correctly */
109 style &= (ULONG)(~GX_SCROLLBAR_HORIZONTAL);
110 style |= GX_SCROLLBAR_VERTICAL;
111
112 /* Call the base widget create function. */
113 _gx_widget_create((GX_WIDGET *)scrollbar, name, GX_NULL, style, id, &size);
114
115 scrollbar -> gx_widget_type = GX_TYPE_VERTICAL_SCROLL;
116 scrollbar -> gx_widget_normal_fill_color = GX_COLOR_ID_SCROLL_FILL;
117 scrollbar -> gx_widget_selected_fill_color = GX_COLOR_ID_SCROLL_FILL;
118
119 if (style & GX_SCROLLBAR_END_BUTTONS)
120 {
121 /* create the up/left button */
122 _gx_button_create(&scrollbar -> gx_scrollbar_upleft, NULL, (GX_WIDGET *)scrollbar,
123 GX_STYLE_ENABLED | GX_STYLE_BORDER_RAISED, GX_ID_SCROLL_UP_LEFT, &size);
124 _gx_widget_fill_color_set((GX_WIDGET *)&scrollbar -> gx_scrollbar_upleft,
125 scrollbar -> gx_scrollbar_appearance.gx_scroll_button_color,
126 scrollbar -> gx_scrollbar_appearance.gx_scroll_button_color,
127 scrollbar -> gx_scrollbar_appearance.gx_scroll_button_color);
128 scrollbar -> gx_scrollbar_upleft.gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS;
129
130 /* create the down/right button */
131 _gx_button_create(&scrollbar -> gx_scrollbar_downright, NULL, (GX_WIDGET *)scrollbar,
132 GX_STYLE_ENABLED | GX_STYLE_BORDER_RAISED, GX_ID_SCROLL_DOWN_RIGHT, &size);
133 _gx_widget_fill_color_set((GX_WIDGET *)&scrollbar -> gx_scrollbar_downright,
134 scrollbar -> gx_scrollbar_appearance.gx_scroll_button_color,
135 scrollbar -> gx_scrollbar_appearance.gx_scroll_button_color,
136 scrollbar -> gx_scrollbar_appearance.gx_scroll_button_color);
137 scrollbar -> gx_scrollbar_downright.gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS;
138 }
139
140 /* scroll-bars have non-client area status and do not accept focus */
141 scrollbar -> gx_widget_status |= GX_STATUS_NONCLIENT;
142 scrollbar -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS;
143
144 /* create the thumb button */
145 _gx_scroll_thumb_create(&scrollbar -> gx_scrollbar_thumb, scrollbar,
146 (ULONG)((scrollbar -> gx_scrollbar_appearance.gx_scroll_thumb_border_style) | GX_SCROLLBAR_VERTICAL) | GX_STYLE_ENABLED);
147
148 /* initialize the drawing function */
149 scrollbar -> gx_widget_draw_function = (VOID (*)(GX_WIDGET *))_gx_scrollbar_draw;
150
151 /* initialize the event handler function */
152 scrollbar -> gx_widget_event_process_function = (UINT (*)(GX_WIDGET *, GX_EVENT *))_gx_scrollbar_event_process;
153
154 /* Determine if a parent widget was provided. */
155 if (parent)
156 {
157 _gx_widget_link((GX_WIDGET *)parent, (GX_WIDGET *)scrollbar);
158
159 if (parent -> gx_widget_status & GX_STATUS_VISIBLE)
160 {
161 _gx_widget_child_clipping_update((GX_WIDGET *)parent);
162 }
163 }
164
165 return(GX_SUCCESS);
166 }
167
168