1 | /*
|
---|
2 | * Copyright (c) 2020 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <assert.h>
|
---|
30 | #include <display/wndresize.h>
|
---|
31 | #include <stdbool.h>
|
---|
32 |
|
---|
33 | /** Get stock cursor to use for the specified window resize type.
|
---|
34 | *
|
---|
35 | * The resize type must be valid, otherwise behavior is undefined.
|
---|
36 | * Resize type can be validated using @c display_wndrsz_valid().
|
---|
37 | *
|
---|
38 | * @param rsztype Resize type
|
---|
39 | * @return Cursor to use for this resize type
|
---|
40 | */
|
---|
41 | display_stock_cursor_t display_cursor_from_wrsz(display_wnd_rsztype_t rsztype)
|
---|
42 | {
|
---|
43 | switch (rsztype) {
|
---|
44 | case display_wr_top:
|
---|
45 | case display_wr_bottom:
|
---|
46 | return dcurs_size_ud;
|
---|
47 |
|
---|
48 | case display_wr_left:
|
---|
49 | case display_wr_right:
|
---|
50 | return dcurs_size_lr;
|
---|
51 |
|
---|
52 | case display_wr_top_left:
|
---|
53 | case display_wr_bottom_right:
|
---|
54 | return dcurs_size_uldr;
|
---|
55 |
|
---|
56 | case display_wr_top_right:
|
---|
57 | case display_wr_bottom_left:
|
---|
58 | return dcurs_size_urdl;
|
---|
59 |
|
---|
60 | default:
|
---|
61 | assert(false);
|
---|
62 | return dcurs_arrow;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | /** Determine if resize type is valid.
|
---|
67 | *
|
---|
68 | * Determine if the resize type has one of the valid values. This function
|
---|
69 | * should be used when the resize type comes from an untrusted source
|
---|
70 | * (such as from the client).
|
---|
71 | *
|
---|
72 | * @param rsztype Resize type
|
---|
73 | * @return @c true iff the resize type is valid
|
---|
74 | */
|
---|
75 | bool display_wndrsz_valid(display_wnd_rsztype_t rsztype)
|
---|
76 | {
|
---|
77 | bool valid;
|
---|
78 |
|
---|
79 | valid = false;
|
---|
80 |
|
---|
81 | switch (rsztype) {
|
---|
82 | case display_wr_top:
|
---|
83 | case display_wr_bottom:
|
---|
84 | case display_wr_left:
|
---|
85 | case display_wr_right:
|
---|
86 | case display_wr_top_left:
|
---|
87 | case display_wr_bottom_right:
|
---|
88 | case display_wr_top_right:
|
---|
89 | case display_wr_bottom_left:
|
---|
90 | valid = true;
|
---|
91 | break;
|
---|
92 | }
|
---|
93 |
|
---|
94 | return valid;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /** @}
|
---|
98 | */
|
---|