| 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
|
|---|
| 51 | * @param rwndlist Place to store pointer to new window list
|
|---|
| 52 | * @return @c EOK on success or an error code
|
|---|
| 53 | */
|
|---|
| 54 | errno_t wndlist_create(ui_resource_t *res, ui_fixed_t *fixed,
|
|---|
| 55 | wndlist_t **rwndlist)
|
|---|
| 56 | {
|
|---|
| 57 | wndlist_t *wndlist = NULL;
|
|---|
| 58 | errno_t rc;
|
|---|
| 59 |
|
|---|
| 60 | wndlist = calloc(1, sizeof(wndlist_t));
|
|---|
| 61 | if (wndlist == NULL) {
|
|---|
| 62 | rc = ENOMEM;
|
|---|
| 63 | goto error;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | wndlist->res = res;
|
|---|
| 67 | wndlist->fixed = fixed;
|
|---|
| 68 | list_initialize(&wndlist->entries);
|
|---|
| 69 | *rwndlist = wndlist;
|
|---|
| 70 | return EOK;
|
|---|
| 71 | error:
|
|---|
| 72 | return rc;
|
|---|
| 73 |
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /** Destroy task bar window list. */
|
|---|
| 77 | void wndlist_destroy(wndlist_t *wndlist)
|
|---|
| 78 | {
|
|---|
| 79 | free(wndlist);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /** Append new entry to window list.
|
|---|
| 83 | *
|
|---|
| 84 | * @param wndlist Window list
|
|---|
| 85 | * @param caption Entry caption
|
|---|
| 86 | * @return @c EOK on success or an error code
|
|---|
| 87 | */
|
|---|
| 88 | errno_t wndlist_append(wndlist_t *wndlist, const char *caption)
|
|---|
| 89 | {
|
|---|
| 90 | wndlist_entry_t *entry = NULL;
|
|---|
| 91 | gfx_rect_t rect;
|
|---|
| 92 | errno_t rc;
|
|---|
| 93 |
|
|---|
| 94 | entry = calloc(1, sizeof(wndlist_entry_t));
|
|---|
| 95 | if (entry == NULL) {
|
|---|
| 96 | rc = ENOMEM;
|
|---|
| 97 | goto error;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | rc = ui_pbutton_create(wndlist->res, caption, &entry->button);
|
|---|
| 101 | if (rc != EOK)
|
|---|
| 102 | goto error;
|
|---|
| 103 |
|
|---|
| 104 | if (ui_resource_is_textmode(wndlist->res)) {
|
|---|
| 105 | rect.p0.x = 9;
|
|---|
| 106 | rect.p0.y = 0;
|
|---|
| 107 | rect.p1.x = 25;
|
|---|
| 108 | rect.p1.y = 1;
|
|---|
| 109 | } else {
|
|---|
| 110 | rect.p0.x = 90;
|
|---|
| 111 | rect.p0.y = 3;
|
|---|
| 112 | rect.p1.x = 230;
|
|---|
| 113 | rect.p1.y = 29;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | ui_pbutton_set_rect(entry->button, &rect);
|
|---|
| 117 |
|
|---|
| 118 | rc = ui_fixed_add(wndlist->fixed, ui_pbutton_ctl(entry->button));
|
|---|
| 119 | if (rc != EOK)
|
|---|
| 120 | goto error;
|
|---|
| 121 |
|
|---|
| 122 | entry->wndlist = wndlist;
|
|---|
| 123 | list_append(&entry->lentries, &wndlist->entries);
|
|---|
| 124 |
|
|---|
| 125 | return EOK;
|
|---|
| 126 | error:
|
|---|
| 127 | if (entry != NULL && entry->button != NULL)
|
|---|
| 128 | ui_pbutton_destroy(entry->button);
|
|---|
| 129 | if (entry != NULL)
|
|---|
| 130 | free(entry);
|
|---|
| 131 | return rc;
|
|---|
| 132 |
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /** @}
|
|---|
| 136 | */
|
|---|