editor.c

00001 /***************************************************************************
00002                           editor.c  -  description
00003                           ------------------------
00004     begin                : 
00005     copyright            : (C) 2003 by Dynacube Team
00006     email                : mdshah82@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  #include "common/string.h"
00019  #include "gui/client/client_gui.h"
00020  #include "fs/client/client_fs.h"
00021 
00022  typedef struct
00023  {
00024   char lbl[MN_MAX_CHAR];
00025   DB cmdCode; //To be sent to the client
00026  } _MENUITEM;
00027 
00028   typedef struct
00029   {
00030    DB no_item;
00031    _MENUITEM mnuitem[MN_MAX_ITEM];
00032   } _MENU;
00033 
00034   typedef struct
00035   {
00036    DB no_menu;
00037 
00038    struct
00039    {
00040     char label[MB_MAX_CHAR];
00041     _MENU menu_ptr;
00042    }mnu[MB_MAX_MENU];
00043 
00044   } _MENUBAR;
00045 
00046  int main()
00047  {
00048   volatile MSG msg;
00049   volatile MSG msg1;
00050   CREATE_INFO cr;
00051   COMP_CREATE_INFO cmp;
00052   RESIZE_INFO rs;
00053   volatile SDD ret_val = -1;
00054   char filename[256];
00055   DB has_name=0,saved=0;
00056   DB i, j;
00057   SDW p,res;
00058   _MENUBAR mybar;
00059   _MENU mymenu[5];
00060 
00061   char *menubar[] = {"File","Edit"};
00062   char *menuitem[] = {"New","Open","Save","Save As","Close","Exit","Cut","Copy","Paste"};
00063 
00064   volatile char text[4096];
00065 
00066 
00067      msg.length = sizeof(cr);
00068      msg.type   = CREATE;
00069      msg.sub_type = WINDOW;
00070      cr.alias_id = 101;
00071      cr.cntr_id = 0;
00072      cr.height = 569;
00073      cr.width = 799;
00074      cr.style  = 0;
00075      cr.x = 0;
00076      cr.y = 0;
00077      strcpy(cr.title,"Editor");
00078 
00079      memcpy(msg.msg_buf,&cr,sizeof(cr));
00080 
00081      asm("pushl %0"::"r"(&msg));
00082      asm("pushl %0"::"r"(GUI_PID));
00083      asm("int $0x30"::"a"(3));
00084 
00085      msg.sub_type = TEXTAREA;
00086      cmp.alias_id = 201;
00087      cmp.cntr_id = 101;
00088      cmp.cnt_type = WIND_TYPE;
00089      cmp.height = 520;
00090      cmp.width = 790;
00091      cmp.x = 2;
00092      cmp.y = 2;
00093      cmp.style = 0;
00094      strcpy(cmp.label,"");
00095 
00096      memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00097 
00098      asm("pushl %0"::"r"(&msg));
00099      asm("pushl %0"::"r"(GUI_PID));
00100      asm("int $0x30"::"a"(3));
00101 
00102         //open dialog
00103 
00104      msg.type   = CREATE;
00105      msg.sub_type = DIALOG;
00106      msg.length = sizeof(cr);
00107      cr.alias_id = 102;
00108      cr.cntr_id = 101;
00109      cr.height = 90;
00110      cr.width = 150;
00111      cr.style  = 0;
00112      cr.x = 200;
00113      cr.y = 130;
00114      strcpy(cr.title,"Open File");
00115 
00116      memcpy(msg.msg_buf,&cr,sizeof(cr));
00117 
00118      asm("pushl %0"::"r"(&msg));
00119      asm("pushl %0"::"r"(GUI_PID));
00120      asm("int $0x30"::"a"(3));
00121 
00122      asm("pushl %eax");
00123      asm("popl %0":"=r"(ret_val));
00124 
00125      msg.type = CREATE;
00126      msg.sub_type = TEXT;
00127      cmp.alias_id = 301;
00128      cmp.cntr_id = 102;
00129      cmp.cnt_type = WIND_TYPE;
00130      cmp.height = 15;
00131      cmp.width = 130;
00132      cmp.x = 10;
00133      cmp.y = 10;
00134      strcpy(cmp.label,"");
00135 
00136      memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00137 
00138      __asm__ __volatile__("pushl %0"::"r"(&msg));
00139      __asm__ __volatile__("pushl %0"::"r"(GUI_PID));
00140      __asm__ __volatile__("int $0x30"::"a"(3));
00141 
00142 
00143      msg.sub_type = BUTTON;
00144      msg.length = sizeof(cmp);
00145      cmp.alias_id = 302;
00146      cmp.cntr_id = 102;
00147      cmp.cnt_type = WIND_TYPE;
00148      cmp.height = 20;
00149      cmp.width = 35;
00150      cmp.x = 30;
00151      cmp.y = 40;
00152      cmp.style = 0;
00153      strcpy(cmp.label,"Open");
00154 
00155      memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00156 
00157      asm("pushl %0"::"r"(&msg));
00158      asm("pushl %0"::"r"(GUI_PID));
00159      asm("int $0x30"::"a"(3));
00160 
00161      asm("pushl %eax");
00162      asm("popl %0":"=r"(ret_val));
00163 
00164      msg.sub_type = BUTTON;
00165      msg.length = sizeof(cmp);
00166      cmp.alias_id = 303;
00167      cmp.cntr_id = 102;
00168      cmp.cnt_type = WIND_TYPE;
00169      cmp.height = 20;
00170      cmp.width = 50;
00171      cmp.x = 70;
00172      cmp.y = 40;
00173      cmp.style = 0;
00174      strcpy(cmp.label,"Cancel");
00175 
00176      memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00177 
00178      asm("pushl %0"::"r"(&msg));
00179      asm("pushl %0"::"r"(GUI_PID));
00180      asm("int $0x30"::"a"(3));
00181 
00182      asm("pushl %eax");
00183      asm("popl %0":"=r"(ret_val));
00184 
00185         //save as dialog
00186 
00187      mybar.no_menu = 2;
00188      for(i = 0 ; i < mybar.no_menu ; i++)
00189      {
00190         strcpy(mybar.mnu[i].label, menubar[i]);
00191      }
00192 
00193      mybar.mnu[0].menu_ptr.no_item = 6;
00194      mybar.mnu[1].menu_ptr.no_item = 3;
00195 
00196      for(i = 0 ; i < mybar.no_menu ; i++)
00197      {
00198         for(j = 0 ; j < mybar.mnu[i].menu_ptr.no_item ; j++)
00199         {
00200          mybar.mnu[i].menu_ptr.mnuitem[j].cmdCode = i*10+j;
00201          strcpy(mybar.mnu[i].menu_ptr.mnuitem[j].lbl,menuitem[i*6+j]);//itoa(i*10+j,10));
00202         }
00203      }
00204 
00205      msg.type     = CREATE;
00206      msg.sub_type = MENU;
00207      msg.length   = 10;
00208      msg.msg_buf[0] = 101;
00209      *(DD*)(msg.msg_buf+2) = &mybar;
00210 
00211      asm("pushl %0"::"r"(&msg));
00212      asm("pushl %0"::"r"(GUI_PID));
00213      asm("int $0x30"::"a"(3));
00214 
00215      asm("pushl %eax");
00216      asm("popl %0"::"r"(ret_val));
00217 
00218      msg.type     = SHOW;
00219      msg.sub_type = WINDOW;
00220      msg.length   = sizeof(DW);
00221      msg.msg_buf[0] = 101;
00222 
00223      asm("pushl %0"::"r"(&msg));
00224      asm("pushl %0"::"r"(GUI_PID));
00225      asm("int $0x30"::"a"(3));
00226 
00227      asm("pushl %eax");
00228      asm("popl %0"::"r"(ret_val));
00229 
00230 
00231      while(1)
00232      {
00233       recv(&msg1);
00234 
00235        switch(msg1.type)
00236        {
00237          case WM_CLICKED:
00238 
00239                 switch(msg1.sub_type)
00240                 {
00241                  case BUT_TYPE:
00242                         switch(*(DW*)msg1.msg_buf)
00243                         {
00244                         case 302 :
00245                                 msg.type     = GET;
00246                                 msg.sub_type = TEXT;
00247                                 msg.length   = 10;//sizeof(DW) + sizeof(DD);
00248                                 *(DW*)msg.msg_buf = 301;
00249                                 *(DD*)(msg.msg_buf+2) = text;
00250 
00251                                 __asm__ __volatile__("pushl %0"::"r"(&msg));
00252                                 __asm__ __volatile__("pushl %0"::"r"(GUI_PID));
00253                                 __asm__ __volatile__("int $0x30"::"a"(3));
00254 
00255                                  p = open(text,O_RDONLY);
00256                                  if(p >= 0)
00257                                  {
00258                                   i = 0;
00259                                   while((res = read(p,text+i*512,512)) > 0)
00260                                   {
00261                                    i++;
00262                                   }
00263                                   close(p);
00264                                   msg.type     = FINISHED;
00265                                   msg.sub_type = BUT_TYPE;
00266                                   msg.length   = sizeof(DD);
00267                                   *(DW *)msg.msg_buf = 302;
00268 
00269 
00270                                   asm("pushl %0"::"r"(&msg));
00271                                   asm("pushl %0"::"r"(GUI_PID));
00272                                   asm("int $0x30"::"a"(3));
00273 
00274 
00275                                   msg.type     = HIDE;
00276                                   msg.sub_type = DIALOG;
00277                                   msg.length   = sizeof(DD);
00278                                   *(DW*)msg.msg_buf = 102;
00279 
00280                                   asm("pushl %0"::"r"(&msg));
00281                                   asm("pushl %0"::"r"(GUI_PID));
00282                                   asm("int $0x30"::"a"(3));
00283 
00284                                   msg.type     = SET;
00285                                   msg.sub_type = TEXTAREA;
00286                                   msg.length   = 10; //sizeof(DW) + sizeof(DD);
00287                                   msg.msg_buf[0] = 201;
00288                                  *(DD*)(msg.msg_buf+2) = text;
00289 
00290                                  __asm__ __volatile__("pushl %0"::"r"(&msg));
00291                                  __asm__ __volatile__("pushl %0"::"r"(GUI_PID));
00292                                  __asm__ __volatile__("int $0x30"::"a"(3));
00293 
00294                                 }
00295 
00296 
00297                                 if(p < 0)
00298                                  {
00299                                   msg.type     = FINISHED;
00300                                   msg.sub_type = BUT_TYPE;
00301                                   msg.length   = sizeof(DD);
00302                                   *(DW *)msg.msg_buf = 302;
00303 
00304 
00305                                   asm("pushl %0"::"r"(&msg));
00306                                   asm("pushl %0"::"r"(GUI_PID));
00307                                   asm("int $0x30"::"a"(3));
00308 
00309                                   msg.type     = HIDE;
00310                                   msg.sub_type = DIALOG;
00311                                   msg.length   = sizeof(DD);
00312                                   *(DW*)msg.msg_buf = 102;
00313 
00314                                   asm("pushl %0"::"r"(&msg));
00315                                   asm("pushl %0"::"r"(GUI_PID));
00316                                   asm("int $0x30"::"a"(3));
00317 
00318                                   if(p == E_FS_NEXISTS)
00319                                    {
00320                                    }
00321                                   else
00322                                    {
00323                                    }
00324                                  }
00325 
00326                                 break;
00327                         case 303 :
00328                                 msg.type     = FINISHED;
00329                                 msg.sub_type = BUT_TYPE;
00330                                 msg.length   = sizeof(DD);
00331                                 *(DW *)msg.msg_buf = 303;
00332 
00333 
00334                                 asm("pushl %0"::"r"(&msg));
00335                                 asm("pushl %0"::"r"(GUI_PID));
00336                                 asm("int $0x30"::"a"(3));
00337 
00338                                 msg.type     = HIDE;
00339                                 msg.sub_type = DIALOG;
00340                                 msg.length   = sizeof(DD);
00341                                 *(DW*)msg.msg_buf = 102;
00342 
00343                                 asm("pushl %0"::"r"(&msg));
00344                                 asm("pushl %0"::"r"(GUI_PID));
00345                                 asm("int $0x30"::"a"(3));
00346                         }
00347 
00348                       break;
00349 
00350               case MENU_TYPE:
00351 
00352                         switch(*(DW*)msg1.msg_buf)
00353                         {
00354                         case 1: //open
00355                         strcpy(text,"");
00356                         msg.type     = SET;
00357                         msg.sub_type = TEXT;
00358                         msg.length   = 10;//sizeof(DW) + sizeof(DD);
00359                         *(DW*)msg.msg_buf = 301;
00360                         *(DD*)(msg.msg_buf+2) = text;
00361 
00362                         __asm__ __volatile__("pushl %0"::"r"(&msg));
00363                         __asm__ __volatile__("pushl %0"::"r"(GUI_PID));
00364                         __asm__ __volatile__("int $0x30"::"a"(3));
00365 
00366                         msg.type     = SHOW;
00367                         msg.sub_type = DIALOG;
00368                         msg.length   = sizeof(DD);
00369                         *(DW*)msg.msg_buf = 102;
00370 
00371                         asm("pushl %0"::"r"(&msg));
00372                         asm("pushl %0"::"r"(GUI_PID));
00373                         asm("int $0x30"::"a"(3));
00374                         break;
00375                         }
00376                         break;
00377                 }
00378                 break;
00379 
00380          case WM_KEYPRESS:
00381                 break;
00382 
00383          case WM_DESTROY:
00384                 __asm__ __volatile__("int $0x30"::"a"(0));
00385                 break;
00386        }
00387 
00388      }
00389      while(1);
00390 }
00391 
00392  void recv(MSG *msg)
00393   {
00394    __asm__ __volatile__("pushl %0"::"r"(msg));
00395    __asm__ __volatile__("int $0x30"::"a"(4));
00396   }

Generated on Thu Jul 27 23:52:25 2006 for Dynacube by  doxygen 1.4.7