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 /** Horizontal List (List) */ 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_window.h" 29 #include "gx_system.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _gx_horizontal_list_children_position PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Kenneth Maxwell, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function positions the children for the horizontal list. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* horizontal_list Horizontal list widget */ 49 /* control block */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* status Completion status */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _gx_widget_width_get Retrieves the width of the */ 58 /* widget */ 59 /* _gx_widget_resize Resizes the widget */ 60 /* _gx_window_client_width_get Retrieves the width of the */ 61 /* client */ 62 /* */ 63 /* CALLED BY */ 64 /* */ 65 /* _gx_horizontal_list_event_process */ 66 /* */ 67 /* RELEASE HISTORY */ 68 /* */ 69 /* DATE NAME DESCRIPTION */ 70 /* */ 71 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ 72 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ 73 /* resulting in version 6.1 */ 74 /* */ 75 /**************************************************************************/ _gx_horizontal_list_children_position(GX_HORIZONTAL_LIST * horizontal_list)76UINT _gx_horizontal_list_children_position(GX_HORIZONTAL_LIST *horizontal_list) 77 { 78 GX_RECTANGLE childsize = horizontal_list -> gx_window_client; 79 GX_WIDGET *child = horizontal_list -> gx_widget_first_child; 80 INT index = horizontal_list -> gx_horizontal_list_top_index; 81 82 GX_VALUE width; 83 GX_VALUE client_width; 84 85 horizontal_list -> gx_horizontal_list_child_width = 0; 86 horizontal_list -> gx_horizontal_list_child_count = 0; 87 88 while (child) 89 { 90 if (!(child -> gx_widget_status & GX_STATUS_NONCLIENT)) 91 { 92 /* increment child count */ 93 horizontal_list -> gx_horizontal_list_child_count++; 94 95 /* assign this child's id */ 96 97 if (!(child -> gx_widget_id)) 98 { 99 child -> gx_widget_id = (USHORT)(LIST_CHILD_ID_START + horizontal_list -> gx_horizontal_list_child_count); 100 } 101 102 if (index == horizontal_list -> gx_horizontal_list_selected) 103 { 104 child -> gx_widget_style |= GX_STYLE_DRAW_SELECTED; 105 } 106 else 107 { 108 child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED; 109 } 110 index++; 111 112 child -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS; 113 114 /* pick up child item width, needed for scrolling */ 115 _gx_widget_width_get(child, &width); 116 if (width > horizontal_list -> gx_horizontal_list_child_width) 117 { 118 horizontal_list -> gx_horizontal_list_child_width = width; 119 } 120 121 /* move this child into position */ 122 childsize.gx_rectangle_right = (GX_VALUE)(childsize.gx_rectangle_left + width - 1); 123 _gx_widget_resize(child, &childsize); 124 childsize.gx_rectangle_left = (GX_VALUE)(childsize.gx_rectangle_right + 1); 125 } 126 child = child -> gx_widget_next; 127 } 128 129 /* calculate number of visible columns, needed for scrolling info */ 130 131 if (horizontal_list -> gx_horizontal_list_child_width > 0) 132 { 133 _gx_window_client_width_get((GX_WINDOW *)horizontal_list, &client_width); 134 horizontal_list -> gx_horizontal_list_visible_columns = (GX_VALUE)((client_width + horizontal_list -> gx_horizontal_list_child_width - 1) / 135 horizontal_list -> gx_horizontal_list_child_width); 136 } 137 else 138 { 139 horizontal_list -> gx_horizontal_list_visible_columns = 1; 140 } 141 return(GX_SUCCESS); 142 } 143 144