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/>.
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>
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
)
53 zde_dobj_t
*dobj
= (zde_dobj_t
*) malloc (sizeof (zde_dobj_t
));
62 case ZDE_DOBJ_TYPE_TEXT
:
63 dobj
->arg
= malloc (sizeof (zde_dobj_text_t
));
68 memcpy (dobj
->arg
, arg
, sizeof (zde_dobj_text_t
));
70 case ZDE_DOBJ_TYPE_APPCL
:
71 dobj
->arg
= malloc (sizeof (zde_dobj_appcl_t
));
76 memcpy (dobj
->arg
, arg
, sizeof (zde_dobj_appcl_t
));
80 dobj
->object
= (void *) window
;
84 dobj
->next
= &zde_dobj_list
;
85 dobj
->prev
= zde_dobj_list
.prev
;
86 dobj
->prev
->next
= dobj
;
87 dobj
->next
->prev
= dobj
;
92 unsigned destroy_dialog_object (zde_win_t
*window
)
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
);
123 static void draw_bitmap (unsigned short x, unsigned short y)
130 for (i = 0; i < 32*32; i ++) {
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]);
149 int draw_dialog_object (zde_win_t
*window
)
154 for (dobj
= zde_dobj_list
.next
; dobj
!= &zde_dobj_list
; dobj
= dobj
->next
) {
155 if (dobj
->object
!= (void *) window
)
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;
171 //pthread_create (&thread, NULL, dobj->entry, dobj->arg);
175 zde_dobj_text_t
*dobj_text
;
176 zde_dobj_appcl_t
*dobj_appcl
;
181 switch (dobj
->type
) {
182 case ZDE_DOBJ_TYPE_TEXT
:
183 dobj_text
= (zde_dobj_text_t
*) dobj
->arg
;
188 for (i
= 0; i
< dobj_text
->len
; i
++) {
189 if (dobj_text
->data
[i
] == '\n') {
194 if (dobj_text
->data
[i
] == '\t') {
199 if (!dobj_text
->sizex
&& window
->sizex
< k
+15) {
205 if (!dobj_text
->sizey
&& j
< window
->sizey
-21)
206 xtext_putch (x
+k
, y
+j
, 0, dobj_text
->data
[i
]);
212 case ZDE_DOBJ_TYPE_APPCL
:
213 dobj_appcl
= (zde_dobj_appcl_t
*) dobj
->arg
;
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
;
234 if (!dobj_appcl
->kbd
)
235 dobj_appcl
->kbd
= kbd_getkey ();
238 if (zde_cursor
->state
!= XCURSOR_STATE_LBUTTON
) {
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
;
258 draw_bitmap (dobj->x, dobj->y);
260 xrectfill (dobj->x, dobj->y, dobj->x+32, dobj->y+32, ~0);
263 xtext_puts (dobj->x-7, dobj->y+35, 0, dobj->name);*/
271 zde_dobj_list
.next
= &zde_dobj_list
;
272 zde_dobj_list
.prev
= &zde_dobj_list
;