App inst fixed on invalid image file; App zinstall for ZDE works - we've got GUI...
[ZeXOS.git] / apps / wm / window.c
blobaafef32e85ddb90e1e935923457bb27ec26f2e5f
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <libx/base.h>
25 #include <libx/object.h>
26 #include <libx/image.h>
27 #include <libx/cursor.h>
28 #include <libx/text.h>
29 #include "window.h"
30 #include "cursor.h"
32 wmwindow wmwindow_list;
34 xbitmap *window_img;
36 unsigned window_last_x;
37 unsigned window_last_y;
39 extern wmcursor *cursor;
41 wmwindow *window_create (const char *caption)
43 wmwindow *window = (wmwindow *) malloc (sizeof (wmwindow));
45 if (!window)
46 return 0;
48 window_last_x += 10;
49 window_last_y += 10;
51 window->x = window_last_x;
52 window->y = window_last_y;
53 window->size_x = 200;
54 window->size_y = 150;
55 window->active = 1;
57 unsigned l = strlen (caption);
58 if (l) {
59 window->caption = (char *) malloc (sizeof (char) * l + 1);
60 memcpy (window->caption, caption, l);
61 window->caption[l] = '\0';
62 } else
63 window->caption = 0;
65 //window->hnd_exit = 0;
67 /* add into list */
68 window->next = &wmwindow_list;
69 window->prev = wmwindow_list.prev;
70 window->prev->next = window;
71 window->next->prev = window;
73 return window;
76 unsigned window_sendquit (wmwindow *window)
78 if (!window)
79 return 0;
81 window->active = 0;
84 //typedef void (*void_fn_void_t)(void);
85 unsigned window_delete (wmwindow *window)
87 if (!window)
88 return 0;
90 //if (window->hnd_exit)
91 // ((void_fn_void_t) window->hnd_exit) ();
93 if (window->active)
94 return 0;
96 if (window->caption)
97 free (window->caption);
99 /* delete from list */
100 window->next->prev = window->prev;
101 window->prev->next = window->next;
103 free (window);
105 return 1;
108 unsigned window_draw (wmwindow *window)
110 if (!window)
111 return 0;
113 /* 50 - zluta
114 60 - cervena
115 70 - cerna
116 30 - vybledle zluta
117 35 - seda
118 40 - ruzova
119 45 - fialova
120 55 - jasne zluta
121 15 - jasne modra
122 18 - jasne razici zelena
123 1 - modra
124 3 - trochu tmavsi seda
125 4 - tmavsi cervena
126 5 - fialova
127 6 - zluto-hneda
128 7 - jasne seda
129 8 - tmave modra
130 9 - pekna modra
131 27 - biele-modra
135 xrect (window->x, window->y, window->x+window->size_x, window->y+window->size_y, 0xd3d3d3);
137 if (window->active) {
138 xline (window->x+1, window->y+1, window->x+window->size_x-1, window->y+1, 60*256);
139 xline (window->x+1, window->y+2, window->x+window->size_x-1, window->y+2, 70*256);
140 xline (window->x+1, window->y+3, window->x+window->size_x-1, window->y+3, 80*256);
141 xline (window->x+1, window->y+4, window->x+window->size_x-1, window->y+4, 100*256);
142 xline (window->x+1, window->y+5, window->x+window->size_x-1, window->y+5, 125*256);
143 xline (window->x+1, window->y+6, window->x+window->size_x-1, window->y+6, 150*256);
144 xline (window->x+1, window->y+7, window->x+window->size_x-1, window->y+7, 175*256);
145 xline (window->x+1, window->y+8, window->x+window->size_x-1, window->y+8, 180*256);
146 xline (window->x+1, window->y+9, window->x+window->size_x-1, window->y+9, 190*256);
147 xline (window->x+1, window->y+10, window->x+window->size_x-1, window->y+10, 200*256);
148 } else
149 xrectfill (window->x+1, window->y+1, window->x+window->size_x-1, window->y+10, 1*256);
151 xrectfill (window->x+1, window->y+11, window->x+window->size_x-1, window->y+window->size_y-1, 0xffffff);
153 if (window->caption)
154 xtext_puts (window->x+5, window->y+2, 0, window->caption);
156 return 1;
159 unsigned window_draw_all ()
161 wmwindow *window;
162 for (window = wmwindow_list.next; window != &wmwindow_list; window = window->next) {
163 if (!window)
164 continue;
166 if (cursor->action)
167 if (cursor->state != XCURSOR_STATE_LBUTTON) {
168 if (window->flags & WINDOW_FLAG_DRAG) {
169 window->flags &= ~WINDOW_FLAG_DRAG;
170 cursor->action = 0;
174 /* mame mys na zahlavi okna ? */
175 if (cursor->x > (signed) window->x && cursor->x < (signed) window->x+(signed) window->size_x &&
176 cursor->y > (signed) window->y && cursor->y <= (signed) window->y+11) {
178 if (!cursor->action) {
179 if (cursor->state == XCURSOR_STATE_LBUTTON) {
180 if (!(window->flags & WINDOW_FLAG_DRAG)) {
181 window->flags |= WINDOW_FLAG_DRAG;
182 cursor->action = 1;
187 if (cursor->state == XCURSOR_STATE_RBUTTON) {
188 if (window_delete (window))
189 return 1;
193 if (window->flags & WINDOW_FLAG_DRAG) {
194 window->x = cursor->x;
195 window->y = cursor->y;
198 window_draw (window);
201 return 1;
204 unsigned init_window ()
206 window_last_x = 0;
207 window_last_y = 0;
209 wmwindow_list.next = &wmwindow_list;
210 wmwindow_list.prev = &wmwindow_list;
212 return 1;