| 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 |  |  | /**************************************************************************/ | 
    
    | 89 |  | 1603 | 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 |  | 1603 |     _gx_utility_rectangle_define(&size, 0, 0, 0, 0); | 
    
    | 97 |  | 1603 |     id = GX_ID_VERTICAL_SCROLL; | 
    
    | 98 |  |  |  | 
    
    | 99 | ✓✓ | 1603 |     if (appearance) | 
    
    | 100 |  |  |     { | 
    
    | 101 |  | 1104 |         scrollbar -> gx_scrollbar_appearance = *appearance; | 
    
    | 102 |  |  |     } | 
    
    | 103 |  |  |     else | 
    
    | 104 |  |  |     { | 
    
    | 105 |  | 499 |         _gx_system_scroll_appearance_get(GX_SCROLLBAR_VERTICAL, &scrollbar -> gx_scrollbar_appearance); | 
    
    | 106 |  |  |     } | 
    
    | 107 |  |  |  | 
    
    | 108 |  |  |     /* make sure style is set correctly */ | 
    
    | 109 |  | 1603 |     style &= (ULONG)(~GX_SCROLLBAR_HORIZONTAL); | 
    
    | 110 |  | 1603 |     style |= GX_SCROLLBAR_VERTICAL; | 
    
    | 111 |  |  |  | 
    
    | 112 |  |  |     /* Call the base widget create function.  */ | 
    
    | 113 |  | 1603 |     _gx_widget_create((GX_WIDGET *)scrollbar, name, GX_NULL, style, id, &size); | 
    
    | 114 |  |  |  | 
    
    | 115 |  | 1603 |     scrollbar -> gx_widget_type = GX_TYPE_VERTICAL_SCROLL; | 
    
    | 116 |  | 1603 |     scrollbar -> gx_widget_normal_fill_color = GX_COLOR_ID_SCROLL_FILL; | 
    
    | 117 |  | 1603 |     scrollbar -> gx_widget_selected_fill_color = GX_COLOR_ID_SCROLL_FILL; | 
    
    | 118 |  |  |  | 
    
    | 119 | ✓✓ | 1603 |     if (style & GX_SCROLLBAR_END_BUTTONS) | 
    
    | 120 |  |  |     { | 
    
    | 121 |  |  |         /* create the up/left button */ | 
    
    | 122 |  | 1591 |         _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 |  | 1591 |         _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 |  | 1591 |         scrollbar -> gx_scrollbar_upleft.gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS; | 
    
    | 129 |  |  |  | 
    
    | 130 |  |  |         /* create the down/right button */ | 
    
    | 131 |  | 1591 |         _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 |  | 1591 |         _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 |  | 1591 |         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 |  | 1603 |     scrollbar -> gx_widget_status |= GX_STATUS_NONCLIENT; | 
    
    | 142 |  | 1603 |     scrollbar -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS; | 
    
    | 143 |  |  |  | 
    
    | 144 |  |  |     /* create the thumb button */ | 
    
    | 145 |  | 1603 |     _gx_scroll_thumb_create(&scrollbar -> gx_scrollbar_thumb, scrollbar, | 
    
    | 146 |  | 1603 |                             (ULONG)((scrollbar -> gx_scrollbar_appearance.gx_scroll_thumb_border_style) | GX_SCROLLBAR_VERTICAL) | GX_STYLE_ENABLED); | 
    
    | 147 |  |  |  | 
    
    | 148 |  |  |     /* initialize the drawing function */ | 
    
    | 149 |  | 1603 |     scrollbar -> gx_widget_draw_function = (VOID (*)(GX_WIDGET *))_gx_scrollbar_draw; | 
    
    | 150 |  |  |  | 
    
    | 151 |  |  |     /* initialize the event handler function */ | 
    
    | 152 |  | 1603 |     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 | ✓✓ | 1603 |     if (parent) | 
    
    | 156 |  |  |     { | 
    
    | 157 |  | 1602 |         _gx_widget_link((GX_WIDGET *)parent, (GX_WIDGET *)scrollbar); | 
    
    | 158 |  |  |  | 
    
    | 159 | ✓✓ | 1602 |         if (parent -> gx_widget_status & GX_STATUS_VISIBLE) | 
    
    | 160 |  |  |         { | 
    
    | 161 |  | 2 |             _gx_widget_child_clipping_update((GX_WIDGET *)parent); | 
    
    | 162 |  |  |         } | 
    
    | 163 |  |  |     } | 
    
    | 164 |  |  |  | 
    
    | 165 |  | 1603 |     return(GX_SUCCESS); | 
    
    | 166 |  |  | } | 
    
    | 167 |  |  |  |