00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gui/components/window.h"
00020 #include "gui/components/frame.h"
00021 #include "gui/components/component.h"
00022 #include "gui/utility.h"
00023 #include "gui/components/cursor.h"
00024
00025
00026 void window::win_init(DW _id, DW _parent_id, DW _x, DW _y, DW _width, DW _height, DD _style, DW _is_diag,char* _title)
00027 {
00028 this->cntr_init(_id,_parent_id,_x,_y,_width,_height);
00029 this->style = _style;
00030
00031 this->hasMenu = false;
00032
00033 memcpy(this->title,_title,strlen(_title));
00034 diag = (window *)NULL;
00035 is_diag = _is_diag;
00036
00037
00038
00039
00040
00041 buf = (COLOR *)kmalloc(width * height * sizeof(COLOR));
00044
00045
00046
00047 }
00048
00049 void window::paint_win()
00050 {
00051 DW i;
00052 DW _x, _y, _width, _height;
00053 DW x1,x2,y1,y2;
00054
00055 if(style & HIDDEN || style & W_MINIMIZE)
00056 return;
00057 else if(style & W_MAXIMIZE)
00058 {
00059 _x = 0;
00060 _y = 0;
00061 _width = SCREEN_WIDTH;
00062 _height = SCREEN_HEIGHT;
00063 }
00064 else
00065 {
00066 _x = x;
00067 _y = y;
00068 _width = width;
00069 _height = height;
00070
00071 }
00072
00073
00074
00075 fillrect(_x,_y,_width,_height,FILL_COLOR);
00076
00077
00078
00079
00080
00081
00082
00083
00084 fillrect(_x+BORDER_WIDTH,_y+BORDER_HEIGHT,_width-2*BORDER_WIDTH,TITLE_HEIGHT,TITLE_COLOR);
00085 drawstring(_x+BORDER_WIDTH+SUMMA_WIDTH,_y+BORDER_HEIGHT+(TITLE_HEIGHT-7)/2,title);
00086
00087
00088
00089 if(is_diag == 0)
00090 {
00091 charrect(_x+_width-3*14 - BORDER_WIDTH,_y+BORDER_HEIGHT+3,12,12,'-');
00092 emboss3D(_x+_width-3*14 - BORDER_WIDTH,_y+BORDER_HEIGHT+3,12,12,0,_false,2);
00093 charrect(_x+_width-2*14 - BORDER_WIDTH,_y+BORDER_HEIGHT+3,12,12,127);
00094 emboss3D(_x+_width-2*14 - BORDER_WIDTH,_y+BORDER_HEIGHT+3,12,12,0,_false,2);
00095 }
00096
00097 charrect(_x+_width-1*14 - BORDER_WIDTH,_y+BORDER_HEIGHT+3,12,12,'X');
00098 emboss3D(_x+_width-1*14 - BORDER_WIDTH,_y+BORDER_HEIGHT+3,12,12,0,_false,2);
00099
00100 emboss3D(_x,_y,_width,_height,0,_false,2);
00101
00102 for(i = 0;i<num_comps;)
00103 {
00104 if(comp[i] != NULL)
00105 {
00106 paint_component(comp[i]);
00107 i++;
00108 }
00109 }
00110
00111 for(i = 0;i<num_conts;)
00112 {
00113 if(cont[i] != NULL)
00114 {
00115 ((frame *)cont[i])->paint();
00116 i++;
00117 }
00118 }
00119
00120 if(hasMenu)
00121 {
00122
00123 MenuBar->paint();
00124 }
00125
00126 if(diag != NULL)
00127 diag->paint_win();
00128 }
00129
00130 void window::freeAll()
00131 {
00132 DW i;
00133
00134 for(i = 0;i<num_comps;)
00135 {
00136 if(comp[i] != NULL)
00137 {
00138 free((void*)comp[i]);
00139 i++;
00140 }
00141 }
00142 for(i = 0;i<num_conts;)
00143 {
00144 if(cont[i] != NULL)
00145 {
00146 ((frame *)cont[i])->freeAll();
00147 free((void *)cont[i]);
00148 i++;
00149 }
00150 }
00151
00152 if(MenuBar != NULL)
00153 {
00154 MenuBar->freeAll();
00155 free(MenuBar);
00156 }
00157
00158 if(buf != NULL)
00159 free(buf);
00160 }
00161
00162 ENTITY window::findEntity(DW cx,DW cy)
00163 {
00164 DW _x, _y, _width, _height;
00165 DW i;
00166 ENTITY en;
00167 en.type = NO_TYPE;
00168
00169 if(style & W_MAXIMIZE)
00170 {
00171 _x = BORDER_WIDTH;
00172 _y = TITLE_HEIGHT + BORDER_HEIGHT + ((hasMenu) ? MENUBAR_HEIGHT : 0);
00173 _width = SCREEN_WIDTH;
00174 _height = SCREEN_HEIGHT;
00175 }
00176 else
00177 {
00178 _x = x + BORDER_WIDTH;
00179 _y = y + TITLE_HEIGHT + BORDER_HEIGHT + ((hasMenu) ? MENUBAR_HEIGHT : 0);
00180 _width = width;
00181 _height = height;
00182 }
00183
00184 for(i = 0; i < num_comps;)
00185 {
00186 if(comp[i] != NULL)
00187 {
00188 if(!(comp[i]->style & DISABLED))
00189 {
00190 if(iswithin(cx,cy,_x + comp[i]->x, _y + comp[i]->y,comp[i]->width,comp[i]->height))
00191 {
00192 comp_focus = comp[i];
00193
00194 switch(comp[i]->type)
00195 {
00196 case BUT_TYPE:
00197 en.alias_id = comp[i]->alias_id;
00198 en.id = comp[i]->id;
00199 en.type = BUTTON;
00200
00201 ((button*)comp[i])->react();
00202 return en;
00203 break;
00204
00205 case TEXT_TYPE:
00206 ((text*)comp[i])->react(cx,cy);
00207 break;
00208
00209 case TEXTAREA_TYPE:
00210 ((textarea*)comp[i])->react(cx,cy);
00211 break;
00212 }
00213
00214 break;
00215 }
00216 }
00217 i++;
00218 }
00219 }
00220 }
00221
00222 SDB window::processMenu(DW x,DW y)
00223 {
00224
00225 if(hasMenu)
00226 {
00227 return MenuBar->process(x,y);
00228 }
00229 else
00230 return -1;
00231 }
00232
00233 void window::deactivate()
00234 {
00235 style |= W_DISABLED;
00236 }
00237
00238 void window::activate()
00239 {
00240 style &= ~W_DISABLED;
00241 }
00242
00243 void window::keyPress(DW state, DW ch)
00244 {
00245 if(diag != NULL)
00246 {
00247 diag->keyPress(state,ch);
00248 return;
00249 }
00250 if(comp_focus != NULL)
00251 {
00252
00253 if((comp_focus->style & DISABLED))
00254 return;
00255
00256 switch(comp_focus->type)
00257 {
00258 case TEXT_TYPE:
00259 ((text *)comp_focus)->keyPress(state,ch);
00260 break;
00261 case TEXTAREA_TYPE:
00262 ((textarea *)comp_focus)->keyPress(state,ch);
00263 break;
00264 }
00265 }
00266 }
00267
00268
00269 void window::move(SDW del_x, SDW del_y)
00270 {
00271 DW tmpX, tmpY;
00272
00273 if(style & W_MAXIMIZE)
00274 return;
00275
00276 tmpX = x + del_x;
00277 tmpY = y + del_y;
00278
00279 if(tmpX > 0 && (tmpX + width) < SCREEN_WIDTH && tmpY > 0 && (tmpY + height) < SCREEN_HEIGHT)
00280 {
00281 x += del_x;
00282 y += del_y;
00283 paint_win();
00284 mvBuf2Svga();
00285 }
00286 }
00287
00288 void window::menuInit(DD _user_menu_addr, DW _pid)
00289 {
00290 hasMenu = true;
00291 MenuBar = (menubar *)kmalloc(sizeof(menubar));
00292 MenuBar->menubar_init(this,0,0,width-2*BORDER_WIDTH,MENUBAR_HEIGHT,_user_menu_addr,_pid);
00293 }
00294
00295 void window::attachDialog(window* diag_ptr)
00296 {
00297 diag = diag_ptr;
00298 }
00299
00300 void window::detachDialog()
00301 {
00302 diag = (window *)NULL;
00303 }