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 /**   System Management (System)                                          */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_system.h"
28 #include "gx_utility.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gx_system_view_split                               PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This splits a rectangle into over and under views                   */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    over                                  Pointer to window on top      */
48 /*    root                                  Pointer to root window        */
49 /*    original                              Rectangle to split into       */
50 /*                                            smaller chunks              */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    gx_system_root_view_add               Add viewport to root window   */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    _gx_system_root_view_add              Add view to a root window     */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
73 
_gx_system_view_split(GX_WINDOW * over,GX_WINDOW_ROOT * root,GX_RECTANGLE * original)74 VOID _gx_system_view_split(GX_WINDOW *over, GX_WINDOW_ROOT *root, GX_RECTANGLE *original)
75 {
76 GX_RECTANGLE split;
77 GX_RECTANGLE oversize = over -> gx_widget_size;
78 
79     /* check to see if any area on top is exposed */
80     if (oversize.gx_rectangle_top > original -> gx_rectangle_top)
81     {
82         split.gx_rectangle_left = original -> gx_rectangle_left;
83         split.gx_rectangle_right = original -> gx_rectangle_right;
84         split.gx_rectangle_top = original -> gx_rectangle_top;
85         split.gx_rectangle_bottom = (GX_VALUE)(oversize.gx_rectangle_top - 1);
86 
87         /* try to add this piece to the 'under' window's viewports */
88         _gx_system_root_view_add(root, &split);
89     }
90 
91     /* check to see if any area on bottom is exposed */
92     if (oversize.gx_rectangle_bottom < original -> gx_rectangle_bottom)
93     {
94         split.gx_rectangle_left = original -> gx_rectangle_left;
95         split.gx_rectangle_right = original -> gx_rectangle_right;
96         split.gx_rectangle_top = (GX_VALUE)(oversize.gx_rectangle_bottom + 1);
97         split.gx_rectangle_bottom = original -> gx_rectangle_bottom;
98 
99         /* try to add this piece to the 'under' window's viewports */
100         _gx_system_root_view_add(root, &split);
101     }
102 
103     /* check to see if any area on left is exposed */
104     if (oversize.gx_rectangle_left > original -> gx_rectangle_left)
105     {
106         split.gx_rectangle_left = original -> gx_rectangle_left;
107         split.gx_rectangle_right = (GX_VALUE)(oversize.gx_rectangle_left - 1);
108 
109         if (original -> gx_rectangle_top > oversize.gx_rectangle_top)
110         {
111             split.gx_rectangle_top = original -> gx_rectangle_top;
112         }
113         else
114         {
115             split.gx_rectangle_top = oversize.gx_rectangle_top;
116         }
117 
118         if (original -> gx_rectangle_bottom < oversize.gx_rectangle_bottom)
119         {
120             split.gx_rectangle_bottom = original -> gx_rectangle_bottom;
121         }
122         else
123         {
124             split.gx_rectangle_bottom = oversize.gx_rectangle_bottom;
125         }
126 
127         /* try to add this piece to the 'under' window's viewports */
128         _gx_system_root_view_add(root, &split);
129     }
130 
131     /* check to see if any area on right is exposed */
132     if (oversize.gx_rectangle_right < original -> gx_rectangle_right)
133     {
134         split.gx_rectangle_left = (GX_VALUE)(oversize.gx_rectangle_right + 1);
135         split.gx_rectangle_right = original -> gx_rectangle_right;
136 
137         if (original -> gx_rectangle_top > oversize.gx_rectangle_top)
138         {
139             split.gx_rectangle_top = original -> gx_rectangle_top;
140         }
141         else
142         {
143             split.gx_rectangle_top = oversize.gx_rectangle_top;
144         }
145 
146         if (original -> gx_rectangle_bottom < oversize.gx_rectangle_bottom)
147         {
148             split.gx_rectangle_bottom = original -> gx_rectangle_bottom;
149         }
150         else
151         {
152             split.gx_rectangle_bottom = oversize.gx_rectangle_bottom;
153         }
154         /* try to add this piece to the 'under' window's viewports */
155         _gx_system_root_view_add(root, &split);
156     }
157 }
158 
159