Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for tucniak/cuchar/cc_main.c between version 1.1 and 1.2

version 1.1, 2005/11/25 22:41:24 version 1.2, 2005/11/27 20:14:50
Line 1 
Line 1 
 // Copyright (c) 2005 Michal Sudolsky  /*
 // modified by Juraj Kolesár <koli@koli.sk>    Name: lc_main.c
 #include "cuchar.h"    Author: Michal Sudolsky
     Date: 24.08.2005 18:34
   */
   // modified by Juraj Kolesar <koli@koli.sk>
   
   #include "cc.h"
   
 WIN *hlwin=NULL,  WIN *hlwin=NULL,
     *hlendwin=NULL,      *hlendwin=NULL,
Line 16  bool hasmodal=false;
Line 21  bool hasmodal=false;
 bool apprun=true;  bool apprun=true;
 bool hlvisible=false;  bool hlvisible=false;
 GList *dialoglist=NULL;  GList *dialoglist=NULL;
   char *clipboard=NULL;
   WIN *clipboardmenu=NULL;
 char *bitmap[BITMAPY]={ // nejake to logo do pozadia  char *bitmap[BITMAPY]={ // nejake to logo do pozadia
 ".......................................",  "oo...........................................................................oo",
 ".......................................",  "o.............................................................................o",
 "..........................o..o.........",  "..........................o..o.................................................",
 "...........................oo..........",  "...........................oo..................................................",
 "..oooooooooo..oo....oo....oooo.........",  "..oooooooooo..oo....oo....oooo.................................................",
 "......oo......oo....oo...oo..oo........",  "......oo......oo....oo...oo..oo................................................",
 "......oo......oo....oo..oo.............",  "......oo......oo....oo..oo.....................................................",
 "......oo......oo....oo..oo.............",  "......oo......oo....oo..oo.....................................................",
 "......oo.......oo..oo....oo..oo........",  "......oo.......oo..oo....oo..oo................................................",
 "......oo........oooo......oooo.........",  "......oo........oooo......oooo.................................................",
 ".......................................",  "...............................................................................",
 "...oooo.....oo..oo.....ooo.....oo...oo.",  "...oooo.....oo..oo.....ooo.....oo...oo.........................................",
 "...oo.oo....oo..oo....oo.oo....oo..oo..",  "...oo.oo....oo..oo....oo.oo....oo..oo..........................................",
 "...oo..oo...oo..oo...oo...oo...oo.oo...",  "...oo..oo...oo..oo...oo...oo...oo.oo...........................................",
 "...oo...oo..oo..oo..ooooooooo..oooo....",  "...oo...oo..oo..oo..ooooooooo..oooo............................................",
 "...oo....oo.oo..oo..oo.....oo..oo.oo...",  "...oo....oo.oo..oo..oo.....oo..oo.oo...........................................",
 "...oo.....oooo..oo..oo.....oo..oo..oo..",  "...oo.....oooo..oo..oo.....oo..oo..oo..........................................",
 "...oo......ooo..oo..oo.....oo..oo...oo.",  "...oo......ooo..oo..oo.....oo..oo...oo.........................................",
 ".......................................",  "...............................................................................",
 "......................................."  "...............................................................................",
   "...............................................................................",
   "...............................................................................",
   "...............................................................................",
   "o.............................................................................o",
   "oo...........................................................................oo",
                       };                        };
   
   void fobdiskbuttonproc(WIN *win)
   {
   
   
   }
   
   void fobnamebuttonproc(WIN *win)
   {
   
   
   }
   
   void fobmaskbuttonproc(WIN *win)
   {
   
   
   }
   
   void fobopenbuttonproc(WIN *win)
   {
   
   
   }
   
   void fobcancelbuttonproc(WIN *win)
   {
   
   
   }
   
   void fobsizeokproc(WIN *win,long *x,long *y,long *vx,long *vy)
   {
     if(*vx<MIN_FOB_VX)*vx=MIN_FOB_VX;
     if(*vy<MIN_FOB_VY)*vy=MIN_FOB_VY;
   }
   
   bool fobdialogacelproc(WIN *win,long x,long y,unsigned short key)
   {
     if(key==KK_ESC)((TUFOB*)(win->user))->i=0;
     return send_message(win,x,y,key);
   }
   
   void fobcloseproc(WIN *sender)
   {
     ((TUFOB*)(sender->user))->i=0;
   }
   
   void fobdiskcombochangeproc(WIN *win)
   {
   
   
   
   }
   
   void fobfilelistdblclkproc(WIN *win)
   {
   
   
   
   }
   
   bool fobfilelistacelproc(WIN *win,long x,long y,unsigned short key)
   {
   
     return send_message(win,x,y,key);
   }
   
   void cbcombochangeproc(WIN *win)
   {
     long color=win->extra->combo.activeline;
     TUCB *tucb=(TUCB*)(win->parent->user);
     WIN *p1=tucb->p1,*p2=tucb->p2;
     move_win(p1,(color%4)*2+5,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE);
     move_win(p2,NOCHANGE,(color/4)+3,NOCHANGE,NOCHANGE,NOCHANGE);
   }
   
   bool cbpaintacelproc(WIN *win,long x,long y,unsigned short key)
   {
     if(key==MM_LBUTTONDOWN)
     {
       long color=(long)win->user;
       TUCB *tucb=(TUCB*)(win->parent->user);
       WIN *combo=tucb->combo,*p1=tucb->p1,*p2=tucb->p2;
       set_pos(combo,color);
       move_win(p1,(color%4)*2+5,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE);
       move_win(p2,NOCHANGE,(color/4)+3,NOCHANGE,NOCHANGE,NOCHANGE);
     }
     return send_message(win,x,y,key);
   }
   
   bool cbdialogacelproc(WIN *win,long x,long y,unsigned short key)
   {
     if(key==KK_ESC)((TUCB*)(win->user))->i=-1;
     return send_message(win,x,y,key);
   }
   
   void cbcloseproc(WIN *sender)
   {
     ((TUCB*)(sender->user))->i=-1;
   }
   
   void cbpushproc(WIN *sender)
   {
     ((TUCB*)(sender->parent->user))->i=(long)sender->user;
   }
   
   bool mbdialogacelproc(WIN *win,long x,long y,unsigned short key)
   {
     if(key==KK_ESC)win->user=(void*)MB_CANCEL;
     return send_message(win,x,y,key);
   }
   
   void mbcloseproc(WIN *sender)
   {
     sender->user=(void*)MB_CANCEL;
   }
   
   void mbpushproc(WIN *sender)
   {
     sender->parent->user=sender->user;
   }
   
   bool claeditacel(WIN *sender,long x,long y,unsigned short key)
   {
     if((key&KKMASK)==KK_TAB)return false;
     bool ret=send_message(sender,x,y,key);
     if(key==MM_LBUTTONDOWN)set_focus(sender->parent);
     return ret;
   }
   
   char *getcolorname(long color)
   {
     switch(color)
     {
       case C_BLACK:return "black";break;
       case C_RED:return "red";break;
       case C_GREEN:return "green";break;
       case C_YELLOW:return "yellow";break;
       case C_BLUE:return "blue";break;
       case C_MAGENTA:return "magenta";break;
       case C_CYAN:return "cyan";break;
       case C_WHITE:return "light gray";break;
       case C_LBLACK:return "dark gray";break;
       case C_LRED:return "light red";break;
       case C_LGREEN:return "light green";break;
       case C_LYELLOW:return "light yellow";break;
       case C_LBLUE:return "light blue";break;
       case C_LMAGENTA:return "light magenta";break;
       case C_LCYAN:return "light cyan";break;
       case C_LWHITE:return "white";break;
       default:return NULL;
     }
   }
   
 long strlenmenu(char *text)  long strlenmenu(char *text)
 {  {
   if(strcmp(text,"-")==0)return 0;    if(strcmp(text,"-")==0)return 0;
Line 55  long strlenmenu(char *text)
Line 222  long strlenmenu(char *text)
   
 bool searchwinexist(WIN *p,WIN *win)  bool searchwinexist(WIN *p,WIN *win)
 {  {
   while(p!=NULL)    while(p!=NULL)
   {    {
     if(p==win)return true;      if(p==win)return true;
     if(searchwinexist(p->child,win))return true;      if(searchwinexist(p->child,win))return true;
     p=p->next;      p=p->next;
   }    }
   return false;    return false;
 }  }
   
 bool winexist(WIN *win)  bool winexist(WIN *win)
Line 79  void setparent(WIN *win,WIN *parent)
Line 246  void setparent(WIN *win,WIN *parent)
     {      {
       hlwin=win->next;        hlwin=win->next;
       if(hlendwin==win)hlendwin=NULL;        if(hlendwin==win)hlendwin=NULL;
     }      }
     else if(hlwin!=NULL)      else if(hlwin!=NULL)
     {      {
       p=hlwin;        p=hlwin;
       while(p->next!=win){p=p->next;if(p==NULL)return;}        while(p->next!=win){p=p->next;if(p==NULL)return;}
       p->next=win->next;        p->next=win->next;
       if(win==hlendwin)hlendwin=p;        if(win==hlendwin)hlendwin=p;
     }      }
   }    }
   else    else
Line 98  void setparent(WIN *win,WIN *parent)
Line 265  void setparent(WIN *win,WIN *parent)
     }      }
     else if(win->parent->child!=NULL)      else if(win->parent->child!=NULL)
     {      {
       p=win->parent->child;        p=win->parent->child;
       while(p->next!=win){p=p->next;if(p==NULL)return;}        while(p->next!=win){p=p->next;if(p==NULL)return;}
       p->next=win->next;        p->next=win->next;
       if(win==win->parent->childend)win->parent->childend=p;        if(win==win->parent->childend)win->parent->childend=p;
     }      }
   }    }
   win->parent=parent;    win->parent=parent;
   win->next=NULL;    win->next=NULL;
   if(hlwin==NULL)    if(hlwin==NULL)
   {    {
     hlwin=win;      hlwin=win;
     hlendwin=win;      hlendwin=win;
   }    }
   else    else
   {    {
     if(parent==NULL)      if(parent==NULL)
     {      {
       hlendwin->next=win;        hlendwin->next=win;
       hlendwin=win;        hlendwin=win;
     }      }
     else      else
     {      {
       if(parent->child==NULL)        if(parent->child==NULL)
       {        {
         parent->child=win;          parent->child=win;
         parent->childend=win;          parent->childend=win;
       }        }
       else        else
       {        {
         parent->childend->next=win;          parent->childend->next=win;
         parent->childend=win;          parent->childend=win;
       }        }
     }      }
   }    }
 }  }
   
Line 197  long getmenucellid(MENU *menu)
Line 364  long getmenucellid(MENU *menu)
   }    }
   if(actline==0)return ((CMENU*)lines->data)->id;else return -1;    if(actline==0)return ((CMENU*)lines->data)->id;else return -1;
 }  }
   
 bool isactive(WIN *win)  bool isactive(WIN *win)
   {
     if(!isvisible(win))return false;
     if(win==NULL)return !hasmodal;
     if(win->extra->type==TP_FADE)return false;
     WIN *p=win;
     while(p!=NULL)
     {
       if(!p->active)return false;
       p=p->parent;
     }
     p=win;
     if(p->hasmodal)return false;
     while(p->parent!=NULL)
     {
       if((!((p->extra->type==TP_DIALOG)&&p->extra->dialog.modal))&&p->parent->hasmodal)return false;
       p=p->parent;
     }
     if((!((p->extra->type==TP_DIALOG)&&p->extra->dialog.modal))&&hasmodal)return false;
     return true;
   }
   
   bool dosearchfocused(WIN *win)
 {  {
   if(!isvisible(win))return false;    while(win!=NULL)
   if(win==NULL)return !hasmodal;    {
   if(win->extra->type==TP_FADE)return false;      if(win==focuswin)return true;
   WIN *p=win;      if(dosearchfocused(win->child))return true;
   while(p!=NULL)  
   {  
     if(!p->active)return false;  
     p=p->parent;  
   }  
   p=win;  
   if(p->hasmodal)return false;  
   while(p->parent!=NULL)  
   {  
     if((!((p->extra->type==TP_DIALOG)&&p->extra->dialog.modal))&&p->parent->hasmodal)return false;  
     p=p->parent;  
   }  
   if((!((p->extra->type==TP_DIALOG)&&p->extra->dialog.modal))&&hasmodal)return false;  
   return true;  
 }  
   
 bool dosearchfocused(WIN *win)  
 {  
   while(win!=NULL)  
   {  
     if(win==focuswin)return true;  
     if(dosearchfocused(win->child))return true;  
     win=win->next;      win=win->next;
     if((win!=NULL)&&(win->extra->type==TP_DIALOG))break;      if((win!=NULL)&&(win->extra->type==TP_DIALOG))break;
   }    }
   return false;    return false;
 }  }
   
 bool isfocused(WIN *win)  bool isfocused(WIN *win)
 {  {
   if(win==focuswin)return true;    if(win==focuswin)return true;
   return dosearchfocused(win->child);    return dosearchfocused(win->child);
 }  }
   
 bool isvisible(WIN *win)  bool isvisible(WIN *win)
 {  {
   if(!hlvisible)return false;    if(!hlvisible)return false;
   WIN *prev;    WIN *prev;
   if(win==NULL)return true;    if(win==NULL)return true;
   if(!win->active)return false;    if(!win->active)return false;
   prev=win;    prev=win;
   win=win->parent;    win=win->parent;
   while(win!=NULL)    while(win!=NULL)
   {    {
     if(((win->extra->type==TP_DIALOG)&&      if(((win->extra->type==TP_DIALOG)&&
        (win->extra->dialog.state==SV_MINIMIZED)&&         (win->extra->dialog.state==SV_MINIMIZED)&&
        (((prev->y!=0)||(prev->vy!=1))&&(prev->extra->type!=TP_FADE)))||         (((prev->y!=0)||(prev->vy!=1))&&(prev->extra->type!=TP_FADE)))||
        (!win->active))return false;         (!win->active))return false;
     prev=win;      prev=win;
     win=win->parent;      win=win->parent;
   }    }
   return true;    return true;
 }  }
   
 bool isdlgactive(WIN *win)  bool isdlgactive(WIN *win)
 {  {
   if(win==NULL)return false;    if(win==NULL)return false;
   WIN *p=focuswin;    WIN *p=focuswin;
   while(p!=NULL)    while(p!=NULL)
   {    {
     if(p==win)return true;      if(p==win)return true;
     p=p->parent;      p=p->parent;
   }    }
   return false;    return false;
 }  }
   
 void dobringonewintotop(WIN *win)  void dobringonewintotop(WIN *win)
 {  {
   WIN *p;    WIN *p;
   if(win->parent!=NULL)    if(win->parent!=NULL)
   {    {
     if(win!=win->parent->childend)      if(win!=win->parent->childend)
     {      {
       if(win!=win->parent->child)        if(win!=win->parent->child)
       {        {
         for(p=win->parent->child;p->next!=NULL;p=p->next)if(p->next==win)break;          for(p=win->parent->child;p->next!=NULL;p=p->next)if(p->next==win)break;
         p->next=win->next;          p->next=win->next;
       }        }
       else        else
       {        {
         win->parent->child=win->next;          win->parent->child=win->next;
       }        }
       win->next=NULL;        win->next=NULL;
       win->parent->childend->next=win;        win->parent->childend->next=win;
       win->parent->childend=win;        win->parent->childend=win;
     }      }
   }    }
   else    else
   {    {
     if(win!=hlendwin)      if(win!=hlendwin)
     {      {
       if(win!=hlwin)        if(win!=hlwin)
       {        {
         for(p=hlwin;p->next!=NULL;p=p->next)if(p->next==win)break;          for(p=hlwin;p->next!=NULL;p=p->next)if(p->next==win)break;
         p->next=win->next;          p->next=win->next;
       }        }
       else        else
       {        {
         hlwin=win->next;          hlwin=win->next;
       }        }
       win->next=NULL;        win->next=NULL;
       hlendwin->next=win;        hlendwin->next=win;
       hlendwin=win;        hlendwin=win;
     }      }
   }    }
 }  }
   
 void dobringwintotop(WIN *win)  void dobringwintotop(WIN *win)
 {  {
   if(win==NULL)return;    if(win==NULL)return;
   if((win->extra->type==TP_DIALOG)||(win->extra->type==TP_MENU))dobringonewintotop(win);    if((win->extra->type==TP_DIALOG)||(win->extra->type==TP_MENU))dobringonewintotop(win);
   dobringwintotop(win->parent);    dobringwintotop(win->parent);
 }  }
   
 void bringwintotop(WIN *win)  void bringwintotop(WIN *win)
 {  {
   dobringwintotop(win);    dobringwintotop(win);
   redraw();    redraw();
 }  }
   
 WIN *findchild(WIN *win)  WIN *findchild(WIN *win)
 {  {
   WIN *p;    WIN *p;
   if((win!=NULL)&&(win->lastfocus!=NULL))return win->lastfocus;    if((win!=NULL)&&(win->lastfocus!=NULL))return win->lastfocus;
   if(win!=NULL)p=win->child;    if(win!=NULL)p=win->child;
   else p=hlwin;    else p=hlwin;
   for(;p!=NULL;p=p->next)    for(;p!=NULL;p=p->next)
   {    {
     if(((p->extra->type==TP_EDIT)||((p->extra->type==TP_BUTTON)&&(p->extra->button.hasfocus))      if(((p->extra->type==TP_EDIT)||((p->extra->type==TP_BUTTON)&&(p->extra->button.hasfocus))
        ||(p->extra->type==TP_COMBO)||(p->extra->type==TP_LIST))&&isactive(p))return p;         ||(p->extra->type==TP_COMBO)||(p->extra->type==TP_LIST))&&isactive(p))return p;
     if((p->extra->type==TP_DIALOG)&&(isactive(p)||p->hasmodal))return findchild(p);      if((p->extra->type==TP_DIALOG)&&(isactive(p)||p->hasmodal))return findchild(p);
   }    }
   return win;    return win;
 }  }
   
 WIN *findchildnom(WIN *win)  WIN *findchildnom(WIN *win)
 {  {
   WIN *p;    WIN *p;
   if((win!=NULL)&&(win->lastfocus!=NULL)&&(win->lastfocus->extra->type!=TP_DIALOG))return win->lastfocus;    if((win!=NULL)&&(win->lastfocus!=NULL)&&(win->lastfocus->extra->type!=TP_DIALOG))return win->lastfocus;
   if(win!=NULL)p=win->child;    if(win!=NULL)p=win->child;
   else p=hlwin;    else p=hlwin;
   for(;p!=NULL;p=p->next)    for(;p!=NULL;p=p->next)
   {    {
     if(((p->extra->type==TP_EDIT)||((p->extra->type==TP_BUTTON)&&(p->extra->button.hasfocus))      if(((p->extra->type==TP_EDIT)||((p->extra->type==TP_BUTTON)&&(p->extra->button.hasfocus))
        ||(p->extra->type==TP_COMBO)||(p->extra->type==TP_LIST))&&isactive(p))return p;         ||(p->extra->type==TP_COMBO)||(p->extra->type==TP_LIST))&&isactive(p))return p;
     if((p->extra->type==TP_DIALOG)&&(isactive(p)||p->hasmodal))return findchildnom(p);      if((p->extra->type==TP_DIALOG)&&(isactive(p)||p->hasmodal))return findchildnom(p);
   }    }
   return win;    return win;
 }  }
   
 void combodblclkproc(WIN *Sender)  void combodblclkproc(WIN *Sender)
 {  {
   if(Sender->extra->type==TP_LIST)    if(Sender->extra->type==TP_LIST)
   if(Sender->parent!=NULL)    if(Sender->parent!=NULL)
   if(Sender->parent->extra->type==TP_COMBO)    if(Sender->parent->extra->type==TP_COMBO)
   {    {
     COMBO *combo=&Sender->parent->extra->combo;      COMBO *combo=&Sender->parent->extra->combo;
     combo->activeline=Sender->extra->list.activeline;      combo->activeline=Sender->extra->list.activeline;
     combo->scroll=0;      combo->scroll=0;
     if(combo->change!=NULL)combo->change(Sender->parent);      if(combo->change!=NULL)combo->change(Sender->parent);
   }    }
 }  }
   
 void buttontimer(TIMER *sender)  void buttontimer(TIMER *sender)
 {  {
   redraw();    redraw();
   del_timer(sender);    del_timer(sender);
 }  }
   
 void bclosepush(WIN *sender)  void bclosepush(WIN *sender)
 {  {
   DIALOG *dialog=&sender->parent->extra->dialog;    DIALOG *dialog=&sender->parent->extra->dialog;
   if(dialog->close!=NULL)dialog->close(sender->parent);    if(dialog->close!=NULL)dialog->close(sender->parent);
 }  }
   
 void bmaximizepush(WIN *sender)  void bmaximizepush(WIN *sender)
 {  {
   if(sender->parent->extra->dialog.state==SV_MAXIMIZED)    if(sender->parent->extra->dialog.state==SV_MAXIMIZED)
     move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_NORMAL);        move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_NORMAL);
   else    else
     move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_MAXIMIZED);      move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_MAXIMIZED);
 }  }
   
 void bminimizepush(WIN *sender)  void bminimizepush(WIN *sender)
 {  {
   if(sender->parent->extra->dialog.state==SV_MINIMIZED)    if(sender->parent->extra->dialog.state==SV_MINIMIZED)
     move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_NORMAL);        move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_NORMAL);
   else    else
     move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_MINIMIZED);      move_win(sender->parent,NOCHANGE,NOCHANGE,NOCHANGE,NOCHANGE,SV_MINIMIZED);
 }  }
   
 void dodeletewin(WIN *win)  void dodeletewin(WIN *win)
 {  {
   WIN *p,*pnext;    WIN *p,*pnext;
   if(win==NULL)return;    if(win==NULL)return;
   if(win->parent==NULL)    if(win->parent==NULL)
   {    {
Line 405  void dodeletewin(WIN *win)
Line 572  void dodeletewin(WIN *win)
     {      {
       hlwin=win->next;        hlwin=win->next;
       if(hlendwin==win)hlendwin=NULL;        if(hlendwin==win)hlendwin=NULL;
     }      }
     else if(hlwin!=NULL)      else if(hlwin!=NULL)
     {      {
       p=hlwin;        p=hlwin;
       while(p->next!=win){p=p->next;if(p==NULL)return;}        while(p->next!=win){p=p->next;if(p==NULL)return;}
       p->next=win->next;        p->next=win->next;
       if(win==hlendwin)hlendwin=p;        if(win==hlendwin)hlendwin=p;
     }      }
   }    }
   else    else
Line 424  void dodeletewin(WIN *win)
Line 591  void dodeletewin(WIN *win)
     }      }
     else if(win->parent->child!=NULL)      else if(win->parent->child!=NULL)
     {      {
       p=win->parent->child;        p=win->parent->child;
       while(p->next!=win){p=p->next;if(p==NULL)return;}        while(p->next!=win){p=p->next;if(p==NULL)return;}
       p->next=win->next;        p->next=win->next;
       if(win==win->parent->childend)win->parent->childend=p;        if(win==win->parent->childend)win->parent->childend=p;
     }      }
   }    }
   p=win->child;    p=win->child;
   while(p!=NULL)    while(p!=NULL)
   {    {
Line 437  void dodeletewin(WIN *win)
Line 604  void dodeletewin(WIN *win)
     dodeletewin(p);      dodeletewin(p);
     p=pnext;      p=pnext;
   }    }
   if(win->extra->type==TP_EDIT)free(win->extra->edit.text);    if(win->extra->type==TP_EDIT)free(win->extra->edit.text);
   if(focuswin==win)focuswin=NULL;    if(focuswin==win)focuswin=NULL;
   if(capturewin==win)capturewin=NULL;    if(capturewin==win)capturewin=NULL;
   usekeys=true;    usekeys=true;
   del_timer_for_win(win);    del_timer_for_win(win);
Line 480  void dodeletewin(WIN *win)
Line 647  void dodeletewin(WIN *win)
     if(hldowntext==win)hldowntext=NULL;      if(hldowntext==win)hldowntext=NULL;
   }    }
   if(win==lastfocused)lastfocused=NULL;    if(win==lastfocused)lastfocused=NULL;
   free(win->extra);    free(win->extra);
   free(win->windata);    free(win->windata);
   free(win);    free(win);
 }  }
   
 WIN *findnextwin(WIN *win)  WIN *findnextwin(WIN *win)
 {  {
   if(win==NULL)return NULL;    if(win==NULL)return NULL;
   WIN *p=win->next;    WIN *p=win->next;
   while(true)    while(true)
   {    {
     if(p==NULL)p=(win->parent==NULL)?hlwin:win->parent->child;      if(p==NULL)p=(win->parent==NULL)?hlwin:win->parent->child;
     if(((p==win)||(      if(((p==win)||(
        ((p->extra->type==TP_EDIT)||((p->extra->type==TP_BUTTON)&&(p->extra->button.hasfocus))||         ((p->extra->type==TP_EDIT)||((p->extra->type==TP_BUTTON)&&(p->extra->button.hasfocus))||
        (p->extra->type==TP_COMBO)||(p->extra->type==TP_LIST))         (p->extra->type==TP_COMBO)||(p->extra->type==TP_LIST))
        ))&&isactive(p))return p;         ))&&isactive(p))return p;
     p=p->next;      p=p->next;
   }    }
 }  }
   
 WIN *findprevwin(WIN *win)  WIN *findprevwin(WIN *win)
 {  {
   if(win==NULL)return NULL;    if(win==NULL)return NULL;
   WIN *val=win,*prev=win;    WIN *val=win,*prev=win;
   while(1)    while(1)
Line 510  WIN *findprevwin(WIN *win)
Line 677  WIN *findprevwin(WIN *win)
     if(val!=NULL){if(val==win)return prev;}else return NULL;      if(val!=NULL){if(val==win)return prev;}else return NULL;
     prev=val;      prev=val;
   }    }
 }  }
   
 WIN *cyclenextwin(WIN *win)  WIN *cyclenextwin(WIN *win)
 {  {
Line 523  WIN *cyclenextwin(WIN *win)
Line 690  WIN *cyclenextwin(WIN *win)
     else win=hlwin;      else win=hlwin;
   }    }
   return win;    return win;
 }  }
   
 WIN *searchnextdialog(WIN *win)  WIN *searchnextdialog(WIN *win)
 {  {
Line 533  WIN *searchnextdialog(WIN *win)
Line 700  WIN *searchnextdialog(WIN *win)
   {    {
     WIN *n=searchnextdialog(win->child);      WIN *n=searchnextdialog(win->child);
     if(n!=NULL)return n;      if(n!=NULL)return n;
     if((win->extra->type==TP_DIALOG)&&isactive(win))return win;      if((win->extra->type==TP_DIALOG)&&isactive(win))return win;
     win=cyclenextwin(win);      win=cyclenextwin(win);
   }    }
   while(win!=start);    while(win!=start);
   return NULL;    return NULL;
 }  }
   
 WIN *findnextdialog(WIN *win)  WIN *findnextdialog(WIN *win)
 {  {
   if(win!=NULL)    WIN *p=searchnextdialog((win!=NULL)?cyclenextwin(win):hlwin);
     if((win!=NULL)&&(p!=win))
   {    {
     dialoglist=g_list_prepend(dialoglist,win);      dialoglist=g_list_prepend(dialoglist,win);
     if(g_list_length(dialoglist)>MAX_PREVIOUS_DIALOGS)      if(g_list_length(dialoglist)>MAX_PREVIOUS_DIALOGS)
Line 552  WIN *findnextdialog(WIN *win)
Line 720  WIN *findnextdialog(WIN *win)
       g_list_free(l);        g_list_free(l);
     }      }
   }    }
   return searchnextdialog((win!=NULL)?cyclenextwin(win):hlwin);    return p;
 }  }
   
 WIN *findprevdialog(WIN *win)  WIN *findprevdialog(WIN *win)
 {  {
   WIN *p;    WIN *p;
   if(dialoglist==NULL)return win;    if(dialoglist==NULL)return win;
   p=dialoglist->data;    p=dialoglist->data;
   dialoglist=g_list_remove(dialoglist,p);    dialoglist=g_list_remove(dialoglist,p);
   return (p!=NULL)?p:win;    return (p!=NULL)?p:win;
 }  }
   
 bool runacel(WIN *win,long x,long y,unsigned short key)  bool runacel(WIN *win,long x,long y,unsigned short key)
 {  {
   WIN *p=win,*parent;    WIN *p=win,*parent;
   if(p==NULL)p=hlmenu;    if(p==NULL)p=hlmenu;
   while(p!=NULL)    while(p!=NULL)
   {    {
     if(p->extra->type==TP_DIALOG)      if(p->extra->type==TP_DIALOG)
     {      {
       parent=p->extra->dialog.menu;        parent=p->extra->dialog.menu;
Line 581  bool runacel(WIN *win,long x,long y,unsi
Line 749  bool runacel(WIN *win,long x,long y,unsi
       if(parent==NULL)parent=(WIN*)-1;        if(parent==NULL)parent=(WIN*)-1;
     }      }
     else parent=p->parent;      else parent=p->parent;
     if(p->acel!=NULL){if(p->acel(p,x,y,key))return true;}      if(p->acel!=NULL){if(p->acel(p,x,y,key))return true;}
     else if(send_message(p,x,y,key))return true;      else if(send_message(p,x,y,key))return true;
     p=parent;      p=parent;
     if(!winexist(p))break;      if(!winexist(p))break;
     if(p==NULL)p=hlmenu;      if(p==NULL)p=hlmenu;
     else if(p==(WIN*)-1)break;      else if(p==(WIN*)-1)break;
   }    }
   if(acelproc!=NULL){if(acelproc(NULL,x,y,key))return true;}    if(acelproc!=NULL){if(acelproc(NULL,x,y,key))return true;}
   else if(send_message(NULL,x,y,key))return true;    else if(send_message(NULL,x,y,key))return true;
   return false;    return false;
 }  }
   
 WIN *searchwin(WIN *win,long x,long y)  WIN *searchwin(WIN *win,long x,long y)
 {  {
   long px,py;    long px,py;
   WIN *p=NULL,*n;    WIN *p=NULL,*n;
   while(win!=NULL)    while(win!=NULL)
   {    {
     px=0;      px=0;
     py=0;      py=0;
     client_to_screen(win,&px,&py);      client_to_screen(win,&px,&py);
     if((px<=x)&&(py<=y)&&(px+win->vx>x)&&(py+win->vy>y)&&(isactive(win)||win->hasmodal))p=win;      if((px<=x)&&(py<=y)&&(px+win->vx>x)&&(py+win->vy>y)&&(isactive(win)||win->hasmodal))p=win;
     n=searchwin(win->child,x,y);      n=searchwin(win->child,x,y);
     if(n!=NULL)p=n;      if(n!=NULL)p=n;
     win=win->next;      win=win->next;
   }    }
   return p;    return p;
 }  }
   
 WIN *findwin(long x,long y)  WIN *findwin(long x,long y)
 {  {
   return searchwin(hlwin,x,y);    return searchwin(hlwin,x,y);
 }  }
   
 WIN *searchwintostop(WIN *stop,WIN *win,long x,long y)  WIN *searchwintostop(WIN *stop,WIN *win,long x,long y)
 {  {
   long px,py;    long px,py;
   WIN *p=NULL,*n;    WIN *p=NULL,*n;
   while(win!=NULL)    while(win!=NULL)
   {    {
     if((win==stop)&&(stop!=NULL))return p;      if((win==stop)&&(stop!=NULL))return p;
     px=0;      px=0;
     py=0;      py=0;
     client_to_screen(win,&px,&py);      client_to_screen(win,&px,&py);
     if((px<=x)&&(py<=y)&&(px+win->vx>x)&&(py+win->vy>y)&&isvisible(win))p=win;      if((px<=x)&&(py<=y)&&(px+win->vx>x)&&(py+win->vy>y)&&isvisible(win))p=win;
     n=searchwintostop(stop,win->child,x,y);      n=searchwintostop(stop,win->child,x,y);
     if(n!=NULL)p=n;      if(n!=NULL)p=n;
     win=win->next;      win=win->next;
   }    }
   return p;    return p;
 }  }
   
 WIN *findwintostop(WIN *stop,long x,long y)  WIN *findwintostop(WIN *stop,long x,long y)
 {  {
   return searchwintostop(stop,hlwin,x,y);    return searchwintostop(stop,hlwin,x,y);
 }  }
   
 WIN *searchwinonlypaint(WIN *win,long x,long y)  WIN *searchwinonlypaint(WIN *win,long x,long y)
 {  {
   long px,py;    long px,py;
   WIN *p=NULL,*n;    WIN *p=NULL,*n;
   while(win!=NULL)    while(win!=NULL)
   {    {
     px=0;      px=0;
     py=0;      py=0;
     client_to_screen(win,&px,&py);      client_to_screen(win,&px,&py);
     if((px<=x)&&(py<=y)&&(px+win->vx>x)&&(py+win->vy>y)&&      if((px<=x)&&(py<=y)&&(px+win->vx>x)&&(py+win->vy>y)&&
        (win->extra->type==TP_PAINT)&&(win->extra->paint.style==PA_BORDER)&&         (win->extra->type==TP_PAINT)&&(win->extra->paint.style==PA_BORDER)&&
        (win->redrawed)&&isvisible(win))p=win;         (win->redrawed)&&isvisible(win))p=win;
     n=searchwinonlypaint(win->child,x,y);      n=searchwinonlypaint(win->child,x,y);
     if(n!=NULL)p=n;      if(n!=NULL)p=n;
     win=win->next;      win=win->next;
   }    }
   return p;    return p;
 }  }
   
 WIN *findwinonlypaint(long x,long y)  WIN *findwinonlypaint(long x,long y)
 {  {
   return searchwinonlypaint(hlwin,x,y);    return searchwinonlypaint(hlwin,x,y);
 }  }
   
 void dosetredrawed(WIN *win,bool redrawed)  void dosetredrawed(WIN *win,bool redrawed)
 {  {
   if(hldowntext!=NULL)    if(hldowntext!=NULL)
   {    {
     if(hldowntext!=hlendwin)      if(hldowntext!=hlendwin)
Line 699  void dosetredrawed(WIN *win,bool redrawe
Line 867  void dosetredrawed(WIN *win,bool redrawe
     hldowntext->vx=screenx;      hldowntext->vx=screenx;
     hldowntext->vy=1;      hldowntext->vy=1;
   }    }
   for(;win!=NULL;win=win->next)    for(;win!=NULL;win=win->next)
   {    {
     checkwin(win);      checkwin(win);
     win->redrawed=redrawed;      win->redrawed=redrawed;
     dosetredrawed(win->child,redrawed);      dosetredrawed(win->child,redrawed);
   }    }
 }  }
   
 int doredraw(WIN *win)  int doredraw(WIN *win)
 {  {
   for(;win!=NULL;win=win->next)    for(;win!=NULL;win=win->next)
   {    {
     if(drawwin(win,true)==ERR)return ERR;      if(drawwin(win,true)==ERR)return ERR;
     win->redrawed=true;      win->redrawed=true;
     checkbars(win,true);      checkbars(win,true);
     if(doredraw(win->child)==ERR)return ERR;      if(doredraw(win->child)==ERR)return ERR;
   }    }
   return OK;    return OK;
 }  }
   
 void doneredraw()  void doneredraw()
 {  {
   long x,y;    long x,y;
   if((focuswin!=NULL)&&(focuswin->extra->type==TP_EDIT))    if((focuswin!=NULL)&&(focuswin->extra->type==TP_EDIT)&&
   {       (focuswin->extra->edit.maskpos==-1))
     x=0;y=0;    {
     client_to_screen(focuswin,&x,&y);      EDIT *edit=&focuswin->extra->edit;
     x+=focuswin->extra->edit.curpos-focuswin->extra->edit.scroll;      x=0;y=0;
     if(((x>=0)&&(y>=0)&&(x<screenx)&&(y<screeny))&&(isvisible(focuswin))&&(findwin(x,y)==focuswin))      client_to_screen(focuswin,&x,&y);
     {      x+=edit->curpos-edit->scroll;
       move(y,x);      if(((x>=0)&&(y>=0)&&(x<screenx)&&(y<screeny))&&(isvisible(focuswin))&&(findwin(x,y)==focuswin))
       curs_set(1);      {
     }        move(y,x);
     else        curs_set(1);
     {      }
       curs_set(0);      else
       move(0,0);      {
     }          curs_set(0);
   }        move(0,0);
   else      }
   {    }
     curs_set(0);    else
     move(0,0);    {
   }        curs_set(0);
   if(mouseactive==MOUSE_GPM)redrawmouse=0;      move(0,0);
 }    }
     if(mouseactive==MOUSE_GPM)redrawmouse=0;
 int redraw()  }
 {  
   WIN *win;  int redraw()
   long x,y,px,py,a1,a2;  {
   short c1,c2;    WIN *win;
     long x,y,px,py,a1,a2;
     short c1,c2;
   if(hlvisible)    if(hlvisible)
   {    {
     c1=C_BLUE;c1<<=3;c1+=C_WHITE;      c1=C_BLUE;c1<<=3;c1+=C_WHITE;
     init_pair(c1,C_WHITE,C_BLUE);      init_pair(c1,C_WHITE,C_BLUE);
     c2=!uglycharset?C_BLUE:C_WHITE;c2<<=3;c2+=C_WHITE;      c2=!uglycharset?C_BLUE:C_WHITE;c2<<=3;c2+=C_WHITE;
     init_pair(c2,C_WHITE,!uglycharset?C_BLUE:C_WHITE);      init_pair(c2,C_WHITE,!uglycharset?C_BLUE:C_WHITE);
     a1=(!uglycharset?A_ALTCHARSET:0)+COLOR_PAIR(c1)+mapsymbol[CHESS];      a1=(!uglycharset?A_ALTCHARSET:0)+COLOR_PAIR(c1)+mapsymbol[CHESS];
     a2=A_BOLD+(!uglycharset?A_ALTCHARSET:0)+COLOR_PAIR(c2)+mapsymbol[CHESS];      a2=A_BOLD+(!uglycharset?A_ALTCHARSET:0)+COLOR_PAIR(c2)+mapsymbol[CHESS];
     px=(screenx-BITMAPX)/2;      px=(screenx-BITMAPX)/2;
     py=(screeny-BITMAPY)/2;      py=(screeny-BITMAPY)/2;
     fillback(&mainwin,a1);      fillback(&mainwin,a1);
     for(y=py;y<py+BITMAPY;y++)      for(y=py;y<py+BITMAPY;y++)
       for(x=px;x<px+BITMAPX;x++)        for(x=px;x<px+BITMAPX;x++)
         if(bitmap[y-py][x-px]=='o')          if(bitmap[y-py][x-px]=='o')
           maddch(&mainwin,y,x,a2);            maddch(&mainwin,y,x,a2);
     dosetredrawed(hlwin,false);      dosetredrawed(hlwin,false);
     if(doredraw(hlwin)==ERR)return ERR;      if(doredraw(hlwin)==ERR)return ERR;
   }    }
   else    else
   {    {
     c1=C_BLACK;c1<<=3;c1+=C_WHITE;      c1=C_BLACK;c1<<=3;c1+=C_WHITE;
     init_pair(c1,C_WHITE,C_BLACK);      init_pair(c1,C_WHITE,C_BLACK);
     a1=COLOR_PAIR(c1)+' ';      a1=COLOR_PAIR(c1)+' ';
     fillback(&mainwin,a1);      fillback(&mainwin,a1);
     }
     mrefresh(&mainwin);
     doneredraw();
     refresh();
     return OK;
   }
   
   void checkwin(WIN *win)
   {
     if(win==NULL)return;
     long x,y,wx,wy,px,py;
     bool result;
     get_client_size(win->parent,&px,&py,&wx,&wy);
     switch(win->style&ST_AL_FIXED)
     {
       case ST_AL_LEFT:win->x=px;break;
       case ST_AL_CENTER:
         win->x=(win->style&ST_AR_FIXED)!=ST_AR_CENTER?(wx+px)/2:(wx+px-win->vx)/2;
       break;
       case ST_AL_FIXED:win->x=win->flx;break;
     }
     switch(win->style&ST_AR_FIXED)
     {
       case ST_AR_RIGHT:
         if(win->style&ST_AL_FIXED)win->vx=wx+px-win->x;
         else win->x=wx+px-win->vx;
       break;
       case ST_AR_CENTER:
         if(win->style&ST_AL_FIXED)
         {
           if((win->style&ST_AL_FIXED)!=ST_AL_CENTER)win->vx=(wx+px)/2-win->x;
         }
         else win->x=(wx+px)/2-win->vx;
       break;
       case ST_AR_FIXED:
         if(win->style&ST_AL_FIXED)win->vx=wx+px-win->frx-win->x;
         else win->x=wx+px-win->frx-win->vx;
       break;
     }
     switch(win->style&ST_AU_FIXED)
     {
       case ST_AU_UP:win->y=py;break;
       case ST_AU_CENTER:
         win->y=(win->style&ST_AD_FIXED)!=ST_AD_CENTER?(wy+py)/2:(wy+py-win->vy)/2;
       break;
       case ST_AU_FIXED:win->y=win->fly;break;
     }
     switch(win->style&ST_AD_FIXED)
     {
       case ST_AD_DOWN:
         if(win->style&ST_AU_FIXED)win->vy=wy+py-win->y;
         else win->y=wy+py-win->vy;
       break;
       case ST_AD_CENTER:
         if(win->style&ST_AU_FIXED)
         {
           if((win->style&ST_AU_FIXED)!=ST_AU_CENTER)win->vy=(wy+py)/2-win->y;
         }
         else win->y=(wy+py)/2-win->vy;
       break;
       case ST_AD_FIXED:
         if(win->style&ST_AU_FIXED)win->vy=wy+py-win->fry-win->y;
         else win->y=wy+py-win->fry-win->vy;
       break;
     }
     if(win->style&ST_A_TEMP)
       win->style&=~(ST_AL_FIXED|ST_AU_FIXED|ST_AR_FIXED|ST_AD_FIXED|ST_A_TEMP);
     x=win->x;
     y=win->y;
     client_to_screen(win->parent,&x,&y);
     if(win->extra->type==TP_DIALOG)
     {
       if(win->vx<10)win->vx=10;
       if(x>screenx-1)x=screenx-1;
       if(y>screeny-1-(hldowntext!=NULL?1:0))y=screeny-1-(hldowntext!=NULL?1:0);
       if(x+win->vx<=0)x=1-win->vx;
       if(y+win->vy<=0)y=1-win->vy;
   }    }
   mrefresh(&mainwin);    else if((win->extra->type==TP_LIST)&&(win->extra->list.combotyp==CT_COMBO))
   doneredraw();    {
   refresh();      if((win->parent!=NULL)&&(win->parent->extra->type==TP_COMBO))
   return OK;      {
 }        px=0;py=0;client_to_screen(win->parent,&px,&py);
         x=px-1;
 void checkwin(WIN *win)        win->vx=win->parent->vx+2;
 {        win->vy=win->parent->extra->combo.lstvy;
   if(win==NULL)return;        y=py+win->parent->vy;
   long x,y,wx,wy,px,py;        if(y+win->vy>screeny)y=py-win->vy;
   bool result;      }
   x=win->x;      if(x+win->vx>screenx)x=screenx-win->vx;
   y=win->y;      if(x<0)x=0;
   client_to_screen(win->parent,&x,&y);      if(x+win->vx>screenx)win->vx=screenx-x;
   if(win->extra->type==TP_DIALOG)      if(y+win->vy>screeny)y=screeny-win->vy;
   {      if(y<0)y=0;
     if(win->vx<10)win->vx=10;      if(y+win->vy>screeny)win->vy=screeny-y;
     if(x>screenx-1)x=screenx-1;  
     if(y>screeny-1-(hldowntext!=NULL?1:0))y=screeny-1-(hldowntext!=NULL?1:0);  
     if(x+win->vx<=0)x=1-win->vx;  
     if(y+win->vy<=0)y=1-win->vy;  
   }  
   else if((win->extra->type==TP_LIST)&&(win->extra->list.combotyp))  
   {  
     if((win->parent!=NULL)&&(win->parent->extra->type==TP_COMBO))  
     {  
       px=0;py=0;client_to_screen(win->parent,&px,&py);  
       x=px-1;  
       win->vx=win->parent->vx+2;  
       win->vy=win->parent->extra->combo.lstvy;  
       y=py+win->parent->vy;  
       if(y+win->vy>screeny)y=py-win->vy;  
     }  
     if(x+win->vx>screenx)x=screenx-win->vx;  
     if(x<0)x=0;  
     if(x+win->vx>screenx)win->vx=screenx-x;  
     if(y+win->vy>screeny)y=screeny-win->vy;  
     if(y<0)y=0;  
     if(y+win->vy>screeny)win->vy=screeny-y;  
   }    }
   else if((win->extra->type==TP_MENU)&&(win->extra->menu.vert))    else if((win->extra->type==TP_MENU)&&(win->extra->menu.vert))
   {    {
     if(x+win->vx>screenx)x=screenx-win->vx;      if(x+win->vx>screenx)x=screenx-win->vx;
     if(x<0)x=0;      if(x<0)x=0;
     if(y+win->vy>screeny)y=screeny-win->vy;      if(y+win->vy>screeny)y=screeny-win->vy;
     if(y<0)y=0;      if(y<0)y=0;
   }    }
   else if((win->extra->type==TP_TEXT)||    else if((win->extra->type==TP_TEXT)||
           (win->extra->type==TP_EDIT)||            (win->extra->type==TP_EDIT)||
Line 829  void checkwin(WIN *win)
Line 1054  void checkwin(WIN *win)
           ((win->extra->type==TP_SCROLL)&&(!win->extra->scroll.vert))||            ((win->extra->type==TP_SCROLL)&&(!win->extra->scroll.vert))||
           ((win->extra->type==TP_STATUS)&&(!win->extra->status.vert))||            ((win->extra->type==TP_STATUS)&&(!win->extra->status.vert))||
           ((win->extra->type==TP_MENU)&&(!win->extra->menu.vert)))            ((win->extra->type==TP_MENU)&&(!win->extra->menu.vert)))
   {    {
     if(win->vy>1)win->vy=1;      if(win->vy>1)win->vy=1;
   }    }
   else if(((win->extra->type==TP_SCROLL)&&(win->extra->scroll.vert))||    else if(((win->extra->type==TP_SCROLL)&&(win->extra->scroll.vert))||
Line 837  void checkwin(WIN *win)
Line 1062  void checkwin(WIN *win)
   {    {
     if(win->vx>1)win->vx=1;      if(win->vx>1)win->vx=1;
   }    }
   screen_to_client(win->parent,&x,&y);    if(win->extra->type==TP_TEXT)
   win->x=x;    {
   win->y=y;      if(win->extra->text.text!=NULL)
   if(win->vx<1)win->vx=1;        if((win->style&ST_AUTOXSIZE)==ST_AUTOXSIZE)
   if(win->vy<1)win->vy=1;          win->vx=strlen(win->extra->text.text);
   wx=0;    }
   wy=0;    else if(win->extra->type==TP_BUTTON)
   client_to_screen(win,&wx,&wy);    {
   x=wx;      if(win->extra->button.text!=NULL)
   y=wy;        if((win->style&ST_AUTOXSIZE)==ST_AUTOXSIZE)
   if((x>=screenx)||(y>=screeny))return;          win->vx=strlenmenu(win->extra->button.text)+4;
   wx=screenx-wx;    }
   wy=screeny-wy;    else if(win->extra->type==TP_COMBO)
   if(wx<0)wx=0;    {
   if(wy<0)wy=0;      long poz,maxlen=0,numlines=0;
   if(win->vx<wx)wx=win->vx;      COMBO *combo=&win->extra->combo;
   if(win->vy<wy)wy=win->vy;      GList *lines=combo->list->extra->list.lines;
   if((x+wx<=0)||(y+wy<=0))return;      if(lines!=NULL)numlines=g_list_length(lines);
   if((win->vx!=win->svx)||(win->vy!=win->svy))      while(lines!=NULL)
   {      {
     win->windata=realloc(win->windata,win->vx*win->vy*sizeof(attr_t));        if(lines->data==NULL)continue;
     win->svx=win->vx;        poz=strlen(lines->data);
     win->svy=win->vy;        if(poz>maxlen)maxlen=poz;
   }        lines=g_list_next(lines);
   switch(win->extra->type)      }
   {      if((win->style&ST_AUTOXSIZE)==ST_AUTOXSIZE)win->vx=maxlen+1;
     case TP_LIST:checkwinlist(win);break;    }
     case TP_MENU:checkwinmenu(win);break;    else if(win->extra->type==TP_LIST)
     case TP_DIALOG:checkwindialog(win);    {
   }      long poz,maxlen=0,numlines=0;
 }      LIST *list=&win->extra->list;
       GList *lines=list->lines;
 int drawwin(WIN *win,bool dorefresh)      if(lines!=NULL)numlines=g_list_length(lines);
 {  
   if(win==NULL)return;  
   if(!isvisible(win))return;      // this may be in list setup function
   long x,y,wx;      if(list->combotyp!=CT_TABLE)
   x=0;      {
   y=0;        while(lines!=NULL)
   client_to_screen(win,&x,&y);        {
   if((x>=screenx)||(y>=screeny))return;          if(lines->data==NULL)continue;
   if((x+win->vx<=0)||(y+win->vy<=0))return;          poz=strlen(lines->data);
   wx=win->vx;          if(poz>maxlen)maxlen=poz;
   switch(win->extra->type)          lines=g_list_next(lines);
   {        }
     case TP_TEXT:drawwintext(win);break;      }
     case TP_EDIT:drawwinedit(win);break;      else
     case TP_BUTTON:drawwinbutton(win,wx);break;      {
     case TP_SCROLL:drawwinscroll(win);break;        GSList *sc;
     case TP_LIST:drawwinlist(win,wx);break;        long i;
     case TP_COMBO:drawwincombo(win);break;        sc=list->lencells;
     case TP_STATUS:drawwinstatus(win);break;        maxlen=-1;
     case TP_TABLE:drawwintable(win);break;        while(sc!=NULL)
     case TP_PAINT:drawwinpaint(win);break;        {
     case TP_MENU:drawwinmenu(win,wx);break;          maxlen+=(long)sc->data+1;
     case TP_DIALOG:drawwindialog(win,wx);break;          sc=g_slist_next(sc);
     case TP_FADE:drawwinfade(win,x,y);dorefresh=false;          i++;
   }          }
   if(dorefresh)mrefresh(win);        if(maxlen<0)maxlen=0;
 }      }
       // -----------------------------------
 #include <term.h>  
 #undef buttons  
       if((win->style&ST_AUTOXSIZE)==ST_AUTOXSIZE)win->vx=maxlen+2;
 int main(int argc,char *argv[])      if((win->style&ST_AUTOYSIZE)==ST_AUTOYSIZE)win->vy=numlines+2;
 {    }
     screen_to_client(win->parent,&x,&y);
     win->x=x;
     win->y=y;
     if(win->vx<1)win->vx=1;
     if(win->vy<1)win->vy=1;
     wx=0;
     wy=0;
     client_to_screen(win,&wx,&wy);
     x=wx;
     y=wy;
     if((x>=screenx)||(y>=screeny))return;
     wx=screenx-wx;
     wy=screeny-wy;
     if(wx<0)wx=0;
     if(wy<0)wy=0;
     if(win->vx<wx)wx=win->vx;
     if(win->vy<wy)wy=win->vy;
     if((x+wx<=0)||(y+wy<=0))return;
     if((win->vx!=win->svx)||(win->vy!=win->svy))
     {
       win->windata=realloc(win->windata,win->vx*win->vy*sizeof(attr_t));
       win->svx=win->vx;
       win->svy=win->vy;
     }
     switch(win->extra->type)
     {
       case TP_COMBO:checkwincombo(win);break;
       case TP_LIST:checkwinlist(win);break;
       case TP_MENU:checkwinmenu(win);break;
       case TP_DIALOG:checkwindialog(win);
     }
   }
   
   int drawwin(WIN *win,bool dorefresh)
   {
     if(win==NULL)return;
     if(!isvisible(win))return;
     long x,y,wx;
     x=0;
     y=0;
     client_to_screen(win,&x,&y);
     if((x>=screenx)||(y>=screeny))return;
     if((x+win->vx<=0)||(y+win->vy<=0))return;
     wx=win->vx;
     switch(win->extra->type)
     {
       case TP_TEXT:drawwintext(win);break;
       case TP_EDIT:drawwinedit(win);break;
       case TP_BUTTON:drawwinbutton(win,wx);break;
       case TP_SCROLL:drawwinscroll(win);break;
       case TP_LIST:drawwinlist(win,wx);break;
       case TP_COMBO:drawwincombo(win);break;
       case TP_STATUS:drawwinstatus(win);break;
       case TP_PAINT:drawwinpaint(win);break;
       case TP_MENU:drawwinmenu(win,wx);break;
       case TP_DIALOG:drawwindialog(win,wx);break;
       case TP_FADE:drawwinfade(win,x,y);dorefresh=false;
     }
     if(dorefresh)mrefresh(win);
   }
   
   void clipboardmenuproc(WIN *win,long id)
   {
     switch(id)
     {
       case 0:edit_cut(win->parent);break;
       case 1:edit_copy(win->parent);break;
       case 2:edit_paste(win->parent);break;
       case 3:edit_delete(win->parent);break;
       case 4:edit_select(win->parent,0,MAXLONG);break;
     }
   }
   
   #include <term.h>
   #undef buttons
   
   int main(int argc,char *argv[])
   {
   long i;    long i;
   if((i=main_api(argc,argv))!=0)return i;    if((i=main_api(argc,argv))!=0)return i;
   long key,oldattr,temp;    long oldattr;
   unsigned char res;    Gpm_Event ev;
   unsigned short mod;    initscr();
   TIMER *p,*pnext;    start_color();
   long time;    oldattr=attrset(0);
   MEVENT event;    ESCDELAY=0;
   Gpm_Event ev;  
   initscr();  
   start_color();  
   oldattr=attrset(0);  
   ESCDELAY=0;  
   uglycharset=false;    uglycharset=false;
   for(i=1;i<argc;i++)if(strcmp(argv[i],"-a")==0){uglycharset=true;break;}    for(i=1;i<argc;i++)if(strcmp(argv[i],"-a")==0){uglycharset=true;break;}
   if(uglycharset)mapsymbol=ugmsymbol;      if(uglycharset)mapsymbol=ugmsymbol;
   hascolors=has_colors();    hascolors=has_colors();
   keypad(stdscr,true);    keypad(stdscr,true);
   cbreak();    cbreak();
   noecho();    noecho();
   nodelay(stdscr,true);    nodelay(stdscr,true);
   curs_set(0);    curs_set(0);
   mousex=-1;    mousex=-1;
   mousey=-1;    mousey=-1;
   Gpm_Connect conn;    Gpm_Connect conn;
   conn.eventMask=GPM_MOVE|GPM_DRAG|GPM_DOWN|GPM_UP;    conn.eventMask=GPM_MOVE|GPM_DRAG|GPM_DOWN|GPM_UP;
   conn.defaultMask=0;    conn.defaultMask=0;
   conn.minMod=0;    conn.minMod=0;
   conn.maxMod=-1;    conn.maxMod=-1;
   gpm_zerobased=true;    gpm_zerobased=true;
   if((Gpm_Open(&conn,0)!=-1)&&(Gpm_GetEvent(&ev)!=-1))    if((Gpm_Open(&conn,0)!=-1)&&(Gpm_GetEvent(&ev)!=-1))
   {      {
     gpmev.x=mousex=ev.x;      gpmev.x=mousex=ev.x;
     gpmev.y=mousey=ev.y;      gpmev.y=mousey=ev.y;
     mouseactive=MOUSE_GPM;      mouseactive=MOUSE_GPM;
     Gpm_Repeat(0);      Gpm_Repeat(0);
     GPM_XTERM_ON;      GPM_XTERM_ON;
     pthread_create(&gpmthreadp,NULL,gpmthread,NULL);      pthread_create(&gpmthreadp,NULL,gpmthread,NULL);
   }    }
   else    else
   {    {
     mouseactive=MOUSE_XTERM;      mouseactive=MOUSE_XTERM;
     mousemask(ALL_MOUSE_EVENTS|REPORT_MOUSE_POSITION,NULL);      mousemask(ALL_MOUSE_EVENTS|REPORT_MOUSE_POSITION,NULL);
     mouseinterval(0);      mouseinterval(0);
   }    }
   screenx=columns;    screenx=columns;
   screeny=lines;    screeny=lines;
   mainwin.x=0;    mainwin.x=0;
   mainwin.y=0;    mainwin.y=0;
   mainwin.vx=screenx;    mainwin.vx=screenx;
   mainwin.vy=screeny;    mainwin.vy=screeny;
   mainwin.parent=NULL;    mainwin.parent=NULL;
   mainwin.windata=malloc(screenx*screeny*sizeof(attr_t));    mainwin.windata=malloc(screenx*screeny*sizeof(attr_t));
   redraw();    {
       PMENU menu;
       menu.type=TP_MENU;
       menu.cback=C_DEFAULT;
       menu.cborder=C_DEFAULT;
       menu.ctext=C_DEFAULT;
       menu.cutext=C_DEFAULT;
       menu.cactive=C_DEFAULT;
       menu.cactivetext=C_DEFAULT;
       menu.cactiveutext=C_DEFAULT;
       menu.change=NULL;
       menu.select=clipboardmenuproc;
       menu.vert=true;
       clipboardmenu=create_menu(NULL,&menu,NULL);
       add_menu_item(clipboardmenu,&(CMENU){0,false,"Cu&t",MD_CTRL|'X',NULL});
       add_menu_item(clipboardmenu,&(CMENU){1,false,"&Copy",MD_CTRL|'C',NULL});
       add_menu_item(clipboardmenu,&(CMENU){2,false,"&Paste",MD_CTRL|'V',NULL});
       add_menu_item(clipboardmenu,&(CMENU){3,false,"&Delete",0,NULL});
       add_menu_item(clipboardmenu,&(CMENU){4,false,"Select &All",0,NULL});
     }
     redraw();
   init_api();    init_api();
   do    do message_pump();while(apprun);
   {    done_api();
     mousex=NOCHANGE;    bkgd(oldattr);
     mousey=NOCHANGE;    clear();
     res=6;    refresh();
     mod=0;    if(mouseactive==MOUSE_GPM)
     key=getch();    {
     if(ioctl(0,TIOCLINUX,&res)>=0)      GPM_XTERM_OFF;
     {      Gpm_Close();
       if((res&SHIFT_PRESSED)==SHIFT_PRESSED)mod|=MD_SHIFT;    }
       if((res&CTRL_PRESSED)==CTRL_PRESSED)mod|=MD_CTRL;    noecho();
       if(((res&ALTL_PRESSED)==ALTL_PRESSED)||((res&ALTR_PRESSED)==ALTR_PRESSED))    cbreak();
       {    free(mainwin.windata);
         mod|=MD_ALT;    endwin();
         if(key==27)key=getch();    mousemask(0,NULL);
       }  
     }  
     if(key==27)  
     {  
       if((temp=getch())!=27)  
         ungetch(temp);  
       else  
       {  
         key=temp;  
         mod|=MD_ALT;  
       }  
     }  
     if((mouseactive==MOUSE_GPM)&&(gpmgetevent(&ev)))  
     {  
       event.x=ev.x;  
       event.y=ev.y;  
       event.bstate=0;  
       if((ev.buttons&GPM_B_LEFT)==GPM_B_LEFT)  
       {  
         if((ev.type&GPM_DOWN)==GPM_DOWN)event.bstate|=BUTTON1_PRESSED;  
         else if((ev.type&GPM_UP)==GPM_UP)event.bstate|=BUTTON1_RELEASED;  
       }  
       if((ev.buttons&GPM_B_RIGHT)==GPM_B_RIGHT)  
       {  
         if((ev.type&GPM_DOWN)==GPM_DOWN)event.bstate|=BUTTON3_PRESSED;  
         else if((ev.type&GPM_UP)==GPM_UP)event.bstate|=BUTTON3_RELEASED;  
       }  
       if((ev.modifiers&SHIFT_PRESSED)==SHIFT_PRESSED)event.bstate|=BUTTON_SHIFT;  
       if((ev.modifiers&CTRL_PRESSED)==CTRL_PRESSED)event.bstate|=BUTTON_CTRL;  
       if(((ev.modifiers&ALTL_PRESSED)==ALTL_PRESSED)||((ev.modifiers&ALTR_PRESSED)==ALTR_PRESSED))  
         event.bstate|=BUTTON_ALT;  
       domouseevent(&event);  
     }      
     dokey(key,mod);  
     if((screenx!=columns)||(screeny!=lines))  
     {  
       screenx=columns;  
       screeny=lines;  
       mainwin.vx=screenx;  
       mainwin.vy=screeny;  
       mainwin.windata=realloc(mainwin.windata,screenx*screeny*sizeof(attr_t));  
       if(resizescreen!=NULL)resizescreen(NULL);  
       redraw();  
     }  
     if(key!=-1)redrawmouse=0;  
     if(redrawmouse<2)  
     {  
       Gpm_DrawPointer(gpmev.x,gpmev.y,gpm_consolefd);  
       redrawmouse++;  
     }  
     refresh();  
     for(p=hltimer;p!=NULL;p=pnext)  
     {  
       time=get_tick();  
       pnext=p->next;  
       if(time-p->tminus>=p->period)  
       {  
         p->tminus=time;  
         p->timer(p);  
       }  
     }  
   }  
   while(apprun);  
   done_api();  
   bkgd(oldattr);  
   clear();  
   refresh();  
   if(mouseactive==MOUSE_GPM)  
   {  
     GPM_XTERM_OFF;  
     Gpm_Close();  
   }  
   noecho();  
   cbreak();  
   free(mainwin.windata);  
   endwin();  
   mousemask(0,NULL);  
   curs_set(1);    curs_set(1);
   return end_api();    return end_api();
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top