App inst fixed on invalid image file; App zinstall for ZDE works - we've got GUI...
[ZeXOS.git] / apps / zde / dialog.c
blob50f693e3d44a0ced5bfd6496cc66871d07b1f817
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 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 <fcntl.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <pthread.h>
25 #include <libx/base.h>
26 #include <libx/object.h>
27 #include <libx/image.h>
28 #include <libx/cursor.h>
29 #include <libx/text.h>
31 #include "kbd.h"
32 #include "appcl.h"
33 #include "dialog.h"
34 #include "cursor.h"
35 #include "window.h"
36 #include "appsrv.h"
37 #include "handler.h"
39 zde_dobj_t zde_dobj_list;
41 extern zde_cursor_t *zde_cursor;
42 extern unsigned short *bitmap_button;
43 static char mouse_trigger;
45 zde_dobj_t *create_dialog_object (int type, void *arg, unsigned x, unsigned y, zde_win_t *window)
47 if (!window)
48 return 0;
50 if (!arg)
51 return 0;
53 zde_dobj_t *dobj = (zde_dobj_t *) malloc (sizeof (zde_dobj_t));
55 if (!dobj)
56 return 0;
58 dobj->x = x;
59 dobj->y = y;
61 switch (type) {
62 case ZDE_DOBJ_TYPE_TEXT:
63 dobj->arg = malloc (sizeof (zde_dobj_text_t));
65 if (!dobj->arg)
66 return 0;
68 memcpy (dobj->arg, arg, sizeof (zde_dobj_text_t));
69 break;
70 case ZDE_DOBJ_TYPE_APPCL:
71 dobj->arg = malloc (sizeof (zde_dobj_appcl_t));
73 if (!dobj->arg)
74 return 0;
76 memcpy (dobj->arg, arg, sizeof (zde_dobj_appcl_t));
77 break;
80 dobj->object = (void *) window;
81 dobj->type = type;
83 /* add into list */
84 dobj->next = &zde_dobj_list;
85 dobj->prev = zde_dobj_list.prev;
86 dobj->prev->next = dobj;
87 dobj->next->prev = dobj;
89 return dobj;
92 unsigned destroy_dialog_object (zde_win_t *window)
94 unsigned i;
96 while (1) {
97 i = 0;
99 zde_dobj_t *dobj;
100 for (dobj = zde_dobj_list.next; dobj != &zde_dobj_list; dobj = dobj->next) {
101 if (dobj->object == (void *) window) {
102 dobj->next->prev = dobj->prev;
103 dobj->prev->next = dobj->next;
105 /* send exit state to client's app */
106 if (dobj->type == ZDE_DOBJ_TYPE_APPCL)
107 appsrv_exit (dobj->arg);
109 free (dobj);
111 i = 1;
112 break;
116 if (!i)
117 break;
120 return 1;
123 static void draw_bitmap (unsigned short x, unsigned short y)
125 unsigned i = 0;
126 unsigned j = 0;
127 unsigned k = 0;
128 unsigned pix = 0;
130 for (i = 0; i < 32*32; i ++) {
131 if (k >= 32) {
132 j ++;
133 k = 0;
136 pix = (1024-i)+34;
138 if (pix > 2100)
139 continue;
141 if (bitmap_folder[pix] != (unsigned short) 0)
142 if (k <= 32 && j <= 32)
143 xpixel ((unsigned) x+k, (unsigned) y+j, (unsigned) bitmap_folder[pix]);
145 k ++;
149 int draw_dialog_object (zde_win_t *window)
151 unsigned x, y;
153 zde_dobj_t *dobj;
154 for (dobj = zde_dobj_list.next; dobj != &zde_dobj_list; dobj = dobj->next) {
155 if (dobj->object != (void *) window)
156 continue;
158 /* update dobj position */
159 x = window->x + dobj->x + 4;
160 y = window->y + dobj->y + 25;
162 /* we click on left button */
163 /*if (zde_cursor->state == XCURSOR_STATE_LBUTTON)
164 if (!(zde_cursor->flags & CURSOR_FLAG_MOVE)) {
165 if (zde_cursor->x >= dobj->x && zde_cursor->x <= dobj->x+32)
166 if (zde_cursor->y >= dobj->y && zde_cursor->y <= dobj->y+32) {
167 //zde_cursor->state = 0;
169 //pthread_t thread;
171 //pthread_create (&thread, NULL, dobj->entry, dobj->arg);
175 zde_dobj_text_t *dobj_text;
176 zde_dobj_appcl_t *dobj_appcl;
177 unsigned i;
178 unsigned j = 0;
179 unsigned k = 0;
181 switch (dobj->type) {
182 case ZDE_DOBJ_TYPE_TEXT:
183 dobj_text = (zde_dobj_text_t *) dobj->arg;
185 if (!dobj_text)
186 break;
188 for (i = 0; i < dobj_text->len; i ++) {
189 if (dobj_text->data[i] == '\n') {
190 j += 6;
191 k = 0;
192 continue;
193 } else
194 if (dobj_text->data[i] == '\t') {
195 k += 4*5;
196 continue;
199 if (!dobj_text->sizex && window->sizex < k+15) {
200 j += 6;
201 k = 0;
202 continue;
205 if (!dobj_text->sizey && j < window->sizey-21)
206 xtext_putch (x+k, y+j, 0, dobj_text->data[i]);
208 k += 6;
211 break;
212 case ZDE_DOBJ_TYPE_APPCL:
213 dobj_appcl = (zde_dobj_appcl_t *) dobj->arg;
215 if (!dobj_appcl)
216 break;
218 /* setup windows properties*/
219 dobj_appcl->x = window->x;
220 dobj_appcl->y = window->y;
221 dobj_appcl->sizex = window->sizex;
222 dobj_appcl->sizey = window->sizey;
223 dobj_appcl->mousex = (short) (zde_cursor->x - window->x);
224 dobj_appcl->mousey = (short) (zde_cursor->y - window->y);
226 if (isactive_window () == window) {
227 if (!mouse_trigger) {
228 if (zde_cursor->state == XCURSOR_STATE_LBUTTON) {
229 dobj_appcl->state |= APPCL_STATE_LBUTTON;
230 mouse_trigger = 1;
234 if (!dobj_appcl->kbd)
235 dobj_appcl->kbd = kbd_getkey ();
238 if (zde_cursor->state != XCURSOR_STATE_LBUTTON) {
239 mouse_trigger = 0;
240 dobj_appcl->state &= ~APPCL_STATE_LBUTTON;
243 /* redraw client's window */
244 appsrv_redraw (dobj_appcl);
246 if (dobj_appcl->state & APPCL_STATE_RESIZE) {
247 dobj_appcl->state &= ~APPCL_STATE_RESIZE;
249 window->x = dobj_appcl->x;
250 window->y = dobj_appcl->y;
251 window->sizex = dobj_appcl->sizex;
252 window->sizey = dobj_appcl->sizey;
255 break;
257 /*if (dobj->bitmap)
258 draw_bitmap (dobj->x, dobj->y);
259 else
260 xrectfill (dobj->x, dobj->y, dobj->x+32, dobj->y+32, ~0);
262 if (dobj->name)
263 xtext_puts (dobj->x-7, dobj->y+35, 0, dobj->name);*/
266 return 0;
269 int init_dialog ()
271 zde_dobj_list.next = &zde_dobj_list;
272 zde_dobj_list.prev = &zde_dobj_list;
274 mouse_trigger = 0;
276 return 0;