[e0e612b] | 1 | /*
|
---|
| 2 | * Copyright (c) 2022 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 | /** @addtogroup taskbar
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file Task bar window list
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <gfx/coord.h>
|
---|
| 36 | #include <stdio.h>
|
---|
| 37 | #include <stdlib.h>
|
---|
| 38 | #include <str.h>
|
---|
| 39 | #include <ui/fixed.h>
|
---|
| 40 | #include <ui/label.h>
|
---|
| 41 | #include <ui/resource.h>
|
---|
| 42 | #include <ui/ui.h>
|
---|
| 43 | #include <ui/window.h>
|
---|
| 44 | #include "clock.h"
|
---|
| 45 | #include "wndlist.h"
|
---|
| 46 |
|
---|
| 47 | /** Create task bar window list.
|
---|
| 48 | *
|
---|
| 49 | * @param res UI resource
|
---|
| 50 | * @param fixed Fixed layout to which buttons will be added
|
---|
[7a05d924] | 51 | * @param wndmgt Window management service
|
---|
[e0e612b] | 52 | * @param rwndlist Place to store pointer to new window list
|
---|
| 53 | * @return @c EOK on success or an error code
|
---|
| 54 | */
|
---|
| 55 | errno_t wndlist_create(ui_resource_t *res, ui_fixed_t *fixed,
|
---|
| 56 | wndlist_t **rwndlist)
|
---|
| 57 | {
|
---|
| 58 | wndlist_t *wndlist = NULL;
|
---|
| 59 | errno_t rc;
|
---|
| 60 |
|
---|
| 61 | wndlist = calloc(1, sizeof(wndlist_t));
|
---|
| 62 | if (wndlist == NULL) {
|
---|
| 63 | rc = ENOMEM;
|
---|
| 64 | goto error;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | wndlist->res = res;
|
---|
| 68 | wndlist->fixed = fixed;
|
---|
| 69 | list_initialize(&wndlist->entries);
|
---|
| 70 | *rwndlist = wndlist;
|
---|
| 71 | return EOK;
|
---|
| 72 | error:
|
---|
| 73 | return rc;
|
---|
[7a05d924] | 74 | }
|
---|
| 75 |
|
---|
| 76 | /** Attach window management service to window list.
|
---|
| 77 | *
|
---|
| 78 | * @param wndlist Window list
|
---|
| 79 | * @param rwndlist Place to store pointer to new window list
|
---|
| 80 | * @return @c EOK on success or an error code
|
---|
| 81 | */
|
---|
| 82 | errno_t wndlist_attach_wm(wndlist_t *wndlist, wndmgt_t *wndmgt)
|
---|
| 83 | {
|
---|
| 84 | errno_t rc;
|
---|
| 85 | wndmgt_window_list_t *wlist = NULL;
|
---|
| 86 | wndmgt_window_info_t *winfo = NULL;
|
---|
| 87 | sysarg_t i;
|
---|
| 88 |
|
---|
| 89 | rc = wndmgt_get_window_list(wndmgt, &wlist);
|
---|
| 90 | if (rc != EOK)
|
---|
| 91 | goto error;
|
---|
| 92 |
|
---|
| 93 | for (i = 0; i < wlist->nwindows; i++) {
|
---|
| 94 | rc = wndmgt_get_window_info(wndmgt, wlist->windows[i],
|
---|
| 95 | &winfo);
|
---|
| 96 | if (rc != EOK)
|
---|
| 97 | goto error;
|
---|
| 98 |
|
---|
| 99 | rc = wndlist_append(wndlist, winfo->caption);
|
---|
| 100 | if (rc != EOK) {
|
---|
| 101 | wndmgt_free_window_info(winfo);
|
---|
| 102 | goto error;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | wndmgt_free_window_info(winfo);
|
---|
| 106 | }
|
---|
[e0e612b] | 107 |
|
---|
[7a05d924] | 108 | wndlist->wndmgt = wndmgt;
|
---|
| 109 | return EOK;
|
---|
| 110 | error:
|
---|
| 111 | if (wlist != NULL)
|
---|
| 112 | wndmgt_free_window_list(wlist);
|
---|
| 113 | return rc;
|
---|
[e0e612b] | 114 | }
|
---|
| 115 |
|
---|
| 116 | /** Destroy task bar window list. */
|
---|
| 117 | void wndlist_destroy(wndlist_t *wndlist)
|
---|
| 118 | {
|
---|
| 119 | free(wndlist);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /** Append new entry to window list.
|
---|
| 123 | *
|
---|
| 124 | * @param wndlist Window list
|
---|
| 125 | * @param caption Entry caption
|
---|
| 126 | * @return @c EOK on success or an error code
|
---|
| 127 | */
|
---|
| 128 | errno_t wndlist_append(wndlist_t *wndlist, const char *caption)
|
---|
| 129 | {
|
---|
| 130 | wndlist_entry_t *entry = NULL;
|
---|
| 131 | gfx_rect_t rect;
|
---|
[7a05d924] | 132 | size_t nentries;
|
---|
[e0e612b] | 133 | errno_t rc;
|
---|
| 134 |
|
---|
[7a05d924] | 135 | /* Number of existing entries */
|
---|
| 136 | nentries = list_count(&wndlist->entries);
|
---|
| 137 |
|
---|
[e0e612b] | 138 | entry = calloc(1, sizeof(wndlist_entry_t));
|
---|
| 139 | if (entry == NULL) {
|
---|
| 140 | rc = ENOMEM;
|
---|
| 141 | goto error;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | rc = ui_pbutton_create(wndlist->res, caption, &entry->button);
|
---|
| 145 | if (rc != EOK)
|
---|
| 146 | goto error;
|
---|
| 147 |
|
---|
| 148 | if (ui_resource_is_textmode(wndlist->res)) {
|
---|
[7a05d924] | 149 | rect.p0.x = 17 * nentries + 9;
|
---|
[e0e612b] | 150 | rect.p0.y = 0;
|
---|
[7a05d924] | 151 | rect.p1.x = 17 * nentries + 25;
|
---|
[e0e612b] | 152 | rect.p1.y = 1;
|
---|
| 153 | } else {
|
---|
[7a05d924] | 154 | rect.p0.x = 145 * nentries + 90;
|
---|
[e0e612b] | 155 | rect.p0.y = 3;
|
---|
[7a05d924] | 156 | rect.p1.x = 145 * nentries + 230;
|
---|
[e0e612b] | 157 | rect.p1.y = 29;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | ui_pbutton_set_rect(entry->button, &rect);
|
---|
| 161 |
|
---|
| 162 | rc = ui_fixed_add(wndlist->fixed, ui_pbutton_ctl(entry->button));
|
---|
| 163 | if (rc != EOK)
|
---|
| 164 | goto error;
|
---|
| 165 |
|
---|
| 166 | entry->wndlist = wndlist;
|
---|
| 167 | list_append(&entry->lentries, &wndlist->entries);
|
---|
| 168 |
|
---|
| 169 | return EOK;
|
---|
| 170 | error:
|
---|
| 171 | if (entry != NULL && entry->button != NULL)
|
---|
| 172 | ui_pbutton_destroy(entry->button);
|
---|
| 173 | if (entry != NULL)
|
---|
| 174 | free(entry);
|
---|
| 175 | return rc;
|
---|
| 176 |
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /** @}
|
---|
| 180 | */
|
---|