/* Name: cc_main.c Author: Michal Sudolsky Date: 24.08.2005 18:34 */ // modified by Juraj Kolesar #include "cc.h" Cc_Win *_cc_hlwin=NULL, *_cc_hlendwin=NULL, *_cc_focuswin=NULL, *_cc_capturewin=NULL, *_cc_hlmenu=NULL, *_cc_hldowntext=NULL, _cc_mainwin; bool (*_cc_acelproc)()=NULL; void (*_cc_resizescreen)()=NULL; Cc_Timer *_cc_hltimer=NULL; bool _cc_hasmodal=false; bool _cc_apprun=true; bool _cc_hlvisible=false; GList *_cc_dialoglist=NULL; char *_cc_clipboard=NULL; Cc_Win *_cc_clipboardmenu=NULL; GSList *_cc_topwinlist=NULL; long _cc_oldattr; CMAP *_cc_cmap=NULL; long _cc_fobvx=DEF_FOB_VX,_cc_fobvy=DEF_FOB_VY; char *_cc_bitmap[BITMAPY]={ // nejake to logo do pozadia "...............................................................................", ".........................................oo.oo.................................", "..........................................oo...................................", ".....ooooooooooo...oooo.....oooo.......oooooooo................................", ".....ooooooooooo....oo.......oo......oo.......oo...............................", ".........ooo........oo.......oo.....oo........o.o..............................", ".........ooo........oo.......oo....oo..........................................", ".........ooo........oo.......oo....oo..........................................", ".........ooo........oo.......oo....oo..........................................", ".........ooo........oo.......oo....oo..........................................", ".........ooo........oooo...oooo.....oo........o.o..............................", ".........ooo.........ooooooooo.......oo......ooo...............................", "........ooooo..........ooooo...........ooooooo.................................", "...............................................................................", "...............................................................................", "......................oooo......oooo...oooo.........oooo.........oooo...ooo....", ".......................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........ooo..........", ".......................oo....oo..oo.....oo.......oooo..oooo.......oo.oo........", ".......................oo.....oo.oo.....oo......oo........oo......oo...oo......", ".......................oo.......ooo.....oo.....oo..........oo.....oo....oo.....", "......................oooo......oooo...oooo..oooo..........oooo..oooo...ooo....", "...............................................................................", }; void _cc_fobsetnameedit(Cc_Win *win) { TUFOB *tufob=(TUFOB*)win->user; long i,len=strlen(tufob->filename); char *name=tufob->filename+len-1; for(i=len-1;(i>0)&&(*name!='/');i--)name--; if(*name=='/')name++; cc_set_text(tufob->nameedit,name); } static int __cc_fobfileselector(const struct dirent *entry) { return 1; } static int __cc_fobfilecmp(const void *f1,const void *f2) { return 1; } void _cc_fobsetfilelist(Cc_Win *win,char *mask) { TUFOB *tufob=(TUFOB*)win->user; char *dir=cc_get_text(tufob->diskcombo); GList *flist=NULL,*gl; LIST *list=&tufob->filelist->extra->list; struct dirent **namelist; chdir(dir); if(scandir(dir,&namelist,__cc_fobfileselector,__cc_fobfilecmp)!=-1) { flist=g_list_prepend(flist,"file.ext"); gl=list->lines; while(gl!=NULL) { free(gl->data); gl=g_list_next(gl); } if(list->lines!=NULL)g_list_free(list->lines); cc_set_list(tufob->filelist,flist); } } void _cc_fobsetdiskcombo(Cc_Win *win) { TUFOB *tufob=(TUFOB*)win->user; long i,len=strlen(tufob->filename); char *name=tufob->filename+len-1; for(i=len-1;(i>0)&&(*name!='/');i--)name--; if(*name=='/') { char text[i+2]; text[i+1]='\0'; while(i>=0){text[i]=tufob->filename[i];i--;} cc_set_text(tufob->diskcombo,text); } } void _cc_fobdiskbuttonproc(Cc_Win *win) { TUFOB *tufob=(TUFOB*)win->parent->user; cc_set_focus(tufob->diskcombo); } void _cc_fobnamebuttonproc(Cc_Win *win) { TUFOB *tufob=(TUFOB*)win->parent->user; cc_set_focus(tufob->nameedit); } void _cc_fobmaskbuttonproc(Cc_Win *win) { TUFOB *tufob=(TUFOB*)win->parent->user; cc_set_focus(tufob->maskcombo); } void _cc_fobopenbuttonproc(Cc_Win *win) { TUFOB *tufob=(TUFOB*)win->parent->user; if(tufob->action!=NULL)tufob->action(win->parent,tufob->filename); _cc_fobcloseproc(win->parent); } void _cc_fobcancelbuttonproc(Cc_Win *win) { _cc_fobcloseproc(win->parent); } void _cc_fobsizeokproc(Cc_Win *win,long *x,long *y,long *vx,long *vy) { if(*vxuser; _cc_fobvx=sender->vx; _cc_fobvy=sender->vy; GList *disklines=tufob->diskcombo->extra->combo.list->extra->list.lines, *masklines=tufob->maskcombo->extra->combo.list->extra->list.lines; if(disklines!=NULL)g_list_free(disklines); if(masklines!=NULL) { GList *ls=masklines; while(ls!=NULL) { free(ls->data); ls=g_list_next(ls); } g_list_free(masklines); } if(tufob->mmlines!=NULL) { GList *ls=tufob->mmlines; while(ls!=NULL) { free(ls->data); ls=g_list_next(ls); } g_list_free(tufob->mmlines); } free(tufob); cc_delete_win(sender); } void _cc_fobdiskcombochangeproc(Cc_Win *win) { } void _cc_fobfilelistdblclkproc(Cc_Win *win) { } bool _cc_fobfilelistacelproc(Cc_Win *win,long x,long y,unsigned short key) { return cc_send_message(win,x,y,key); } void _cc_cbcombochangeproc(Cc_Win *win) { long color=win->extra->combo.activeline; TUCB *tucb=(TUCB*)(win->parent->user); Cc_Win *p1=tucb->p1,*p2=tucb->p2; cc_move_win(p1,(color%4)*2+5,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE); cc_move_win(p2,CC_NOCHANGE,(color/4)+3,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE); } bool _cc_cbpaintacelproc(Cc_Win *win,long x,long y,unsigned short key) { if(key==CC_MOUSE_L_DOWN) { long color=(long)win->user; TUCB *tucb=(TUCB*)(win->parent->user); Cc_Win *combo=tucb->combo,*p1=tucb->p1,*p2=tucb->p2; cc_set_pos(combo,color); cc_move_win(p1,(color%4)*2+5,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE, CC_NOCHANGE); cc_move_win(p2,CC_NOCHANGE,(color/4)+3,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE); } return cc_send_message(win,x,y,key); } bool _cc_cbdialogacelproc(Cc_Win *win,long x,long y,unsigned short key) { if(key==CC_KEY_ESC) { free(win->user); cc_delete_win(win); return true; } return cc_send_message(win,x,y,key); } void _cc_cbcloseproc(Cc_Win *sender) { free(sender->user); cc_delete_win(sender); } void _cc_cbpushproc(Cc_Win *sender) { if((bool)sender->user) { TUCB *tucb=(TUCB*)sender->parent->user; if(tucb->action!=NULL) tucb->action(sender->parent,tucb->combo->extra->combo.activeline); } free(sender->parent->user); cc_delete_win(sender->parent); } bool _cc_mbdialogacelproc(Cc_Win *win,long x,long y,unsigned short key) { if(key==CC_KEY_ESC) { TUMB *tumb=(TUMB*)win->user; if(tumb->action!=NULL)tumb->action(win,CC_MB_CANCEL); free(tumb->st); free(tumb); cc_delete_win(win); return true; } return cc_send_message(win,x,y,key); } void _cc_mbcloseproc(Cc_Win *sender) { TUMB *tumb=(TUMB*)sender->user; if(tumb->action!=NULL)tumb->action(sender,CC_MB_CANCEL); free(tumb->st); free(tumb); cc_delete_win(sender); } void _cc_mbpushproc(Cc_Win *sender) { TUMB *tumb=(TUMB*)sender->parent->user; if(tumb->action!=NULL)tumb->action(sender->parent,(long)sender->user); free(tumb->st); free(tumb); cc_delete_win(sender->parent); } bool _cc_claeditacel(Cc_Win *sender,long x,long y,unsigned short key) { if((key&CC_MASK_KEY)==CC_KEY_TAB)return false; bool ret=cc_send_message(sender,x,y,key); if(key==CC_MOUSE_L_DOWN)cc_set_focus(sender->parent); return ret; } void _cc_scrollincombochangeproc(Cc_Win *sender) { _cc_redrawclientwin(sender->parent); } long _cc_fadecolor(long chr) { char cb,cf; short pair; cb=CC_C_BLACK; cf=CC_C_WHITE; pair=cb&0x7; pair<<=3; pair+=cf; if(pair==7)pair=0;else if(pair==0)pair=7; init_pair(pair,cf,cb); return chr&~A_BOLD&~A_REVERSE&~A_COLOR|COLOR_PAIR(pair); } void _cc_setuplistparams(Cc_Win *win) { LIST *list=&win->extra->list; if(list->lines==NULL) { list->numlines=0; list->maxitemlen=0; free(list->lencells); list->lencells=NULL; list->activeitem=NULL; return; } GList *lines; long poz; list->numlines=g_list_length(list->lines); if((list->activeline>=0)&&(list->activelinenumlines)) list->activeitem=g_list_nth(list->lines,list->activeline); list->oldscrollpos=list->vscroll->extra->scroll.pos; list->scrollupitem=g_list_nth(list->lines,list->oldscrollpos); if(list->combotyp!=CC_LI_TABLE) { list->maxitemlen=0; lines=list->lines; while(lines!=NULL) { if(lines->data==NULL)continue; poz=strlen(lines->data); if(poz>list->maxitemlen)list->maxitemlen=poz; lines=g_list_next(lines); } } else { long i; if(list->lencells!=NULL)g_slist_free(list->lencells); for(i=0;ilines->data);i++) list->lencells=g_slist_append(list->lencells,NULL); lines=list->lines; GSList *sc,*sl; sc=list->lencells; while(sc!=NULL) { sc->data=(void*)0; sc=g_slist_next(sc); } while(lines!=NULL) { sl=(GSList*)lines->data; sc=list->lencells; while((sl!=NULL)&&(sc!=NULL)) { i=strlen(sl->data); if(i>(long)sc->data)sc->data=(void*)i; sc=g_slist_next(sc); sl=g_slist_next(sl); } lines=g_list_next(lines); } sc=list->lencells; list->maxitemlen=-1; while(sc!=NULL) { list->maxitemlen+=(long)sc->data+1; sc=g_slist_next(sc); i++; } if(list->maxitemlen<0)list->maxitemlen=0; } } char *_cc_getcolorname(long color) { switch(color) { case CC_C_BLACK:return "black";break; case CC_C_RED:return "red";break; case CC_C_GREEN:return "green";break; case CC_C_YELLOW:return "yellow";break; case CC_C_BLUE:return "blue";break; case CC_C_MAGENTA:return "magenta";break; case CC_C_CYAN:return "cyan";break; case CC_C_WHITE:return "light gray";break; case CC_C_LBLACK:return "dark gray";break; case CC_C_LRED:return "light red";break; case CC_C_LGREEN:return "light green";break; case CC_C_LYELLOW:return "light yellow";break; case CC_C_LBLUE:return "light blue";break; case CC_C_LMAGENTA:return "light magenta";break; case CC_C_LCYAN:return "light cyan";break; case CC_C_LWHITE:return "white";break; default:return NULL; } } long _cc_strlenmenu(char *text) { if(strcmp(text,"-")==0)return 0; long i,l=0,len=strlen(text); bool ch=true; for(i=0;ichild,win))return true; p=p->next; } return false; } bool _cc_winexist(Cc_Win *win) { if(win==NULL)return true; else return _cc_searchwinexist(_cc_hlwin,win); } void _cc_setparent(Cc_Win *win,Cc_Win *parent) { Cc_Win *p; if(win->parent==NULL) { if(_cc_hlwin==win) { _cc_hlwin=win->next; if(_cc_hlendwin==win)_cc_hlendwin=NULL; } else if(_cc_hlwin!=NULL) { p=_cc_hlwin; while(p->next!=win){p=p->next;if(p==NULL)return;} p->next=win->next; if(win==_cc_hlendwin)_cc_hlendwin=p; } } else { if(win->parent->lastfocus==win)win->parent->lastfocus=NULL; if(win->parent->child==win) { win->parent->child=win->next; if(win->parent->childend==win)win->parent->childend=NULL; } else if(win->parent->child!=NULL) { p=win->parent->child; while(p->next!=win){p=p->next;if(p==NULL)return;} p->next=win->next; if(win==win->parent->childend)win->parent->childend=p; } } win->parent=parent; win->next=NULL; if(_cc_hlwin==NULL) { _cc_hlwin=win; _cc_hlendwin=win; } else { if(parent==NULL) { _cc_hlendwin->next=win; _cc_hlendwin=win; } else { if(parent->child==NULL) { parent->child=win; parent->childend=win; } else { parent->childend->next=win; parent->childend=win; } } } } char *_cc_getshortcuttext(unsigned short shortcut) { static char s[MAXLEN_SHORTCUT_STRING]; char *c; unsigned short mod=shortcut&CC_MASK_MOD,key=shortcut&CC_MASK_KEY; s[0]='\0'; if(key>=CC_OFFSET_CHAR) { if((mod&CC_MOD_CTRL)==CC_MOD_CTRL)sprintf(s,"%s%s",s,"CTRL+"); if((mod&CC_MOD_ALT)==CC_MOD_ALT)sprintf(s,"%s%s",s,"ALT+"); if((mod&CC_MOD_SHIFT)==CC_MOD_SHIFT)sprintf(s,"%s%s",s,"SHIFT+"); if(keylines; long actline; for(actline=menu->activeline;(actline>0)&&(lines!=NULL);actline--) { lines=g_list_next(lines); } if(actline==0)return ((Cc_Menu_I*)lines->data)->id;else return -1; } bool _cc_isactive(Cc_Win *win) { if(!_cc_isvisible(win))return false; if(win==NULL)return !_cc_hasmodal; if(win->extra->type==TP_FADE)return false; Cc_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==CC_TP_DIALOG)&&p->extra->dialog.modal))&& p->parent->hasmodal)return false; p=p->parent; } if((!((p->extra->type==CC_TP_DIALOG)&&p->extra->dialog.modal))&&_cc_hasmodal) return false; return true; } bool _cc_dosearchfocused(Cc_Win *win) { while(win!=NULL) { if(win==_cc_focuswin)return true; if(_cc_dosearchfocused(win->child))return true; win=win->next; if((win!=NULL)&&(win->extra->type==CC_TP_DIALOG))break; } return false; } bool _cc_isfocused(Cc_Win *win) { if(win==_cc_focuswin)return true; return _cc_dosearchfocused(win->child); } bool _cc_isvisible(Cc_Win *win) { if(!_cc_hlvisible)return false; Cc_Win *prev; if(win==NULL)return true; if(!win->active)return false; prev=win; win=win->parent; while(win!=NULL) { if(((win->extra->type==CC_TP_DIALOG)&& (win->extra->dialog.state==CC_SV_MINIMIZED)&& (((prev->y!=0)||(prev->vy!=1))&&(prev->extra->type!=TP_FADE)))|| (!win->active))return false; prev=win; win=win->parent; } return true; } bool _cc_isdlgactive(Cc_Win *win) { if(win==NULL)return false; Cc_Win *p=_cc_focuswin; while(p!=NULL) { if(p==win)return true; p=p->parent; } return false; } void _cc_dobringonewintotop(Cc_Win *win) { Cc_Win *p; if(win->parent!=NULL) { if(win!=win->parent->childend) { if(win!=win->parent->child) { for(p=win->parent->child;p->next!=NULL;p=p->next)if(p->next==win)break; p->next=win->next; } else { win->parent->child=win->next; } win->next=NULL; win->parent->childend->next=win; win->parent->childend=win; } } else { if(win!=_cc_hlendwin) { if(win!=_cc_hlwin) { for(p=_cc_hlwin;p->next!=NULL;p=p->next)if(p->next==win)break; p->next=win->next; } else { _cc_hlwin=win->next; } win->next=NULL; _cc_hlendwin->next=win; _cc_hlendwin=win; } } } void _cc_dobringwintotop(Cc_Win *win) { if(win==NULL)return; if((win->extra->type==CC_TP_DIALOG)||(win->extra->type==CC_TP_MENU)) _cc_dobringonewintotop(win); _cc_dobringwintotop(win->parent); } void _cc_bringwintotop(Cc_Win *win) { _cc_dobringwintotop(win); _cc_redraw(); } Cc_Win *_cc_findchild(Cc_Win *win) { Cc_Win *p; if((win!=NULL)&&(win->lastfocus!=NULL))return win->lastfocus; if(win!=NULL)p=win->child; else p=_cc_hlwin; for(;p!=NULL;p=p->next) { if(((p->extra->type==CC_TP_EDIT)||((p->extra->type==CC_TP_BUTTON)&& (p->extra->button.hasfocus))||(p->extra->type==CC_TP_COMBO)|| (p->extra->type==CC_TP_LIST))&&_cc_isactive(p))return p; if((p->extra->type==CC_TP_DIALOG)&&(_cc_isactive(p)||p->hasmodal)) return _cc_findchild(p); } return win; } Cc_Win *_cc_findchildnom(Cc_Win *win) { Cc_Win *p; if((win!=NULL)&&(win->lastfocus!=NULL)&& (win->lastfocus->extra->type!=CC_TP_DIALOG))return win->lastfocus; if(win!=NULL)p=win->child; else p=_cc_hlwin; for(;p!=NULL;p=p->next) { if(((p->extra->type==CC_TP_EDIT)||((p->extra->type==CC_TP_BUTTON)&& (p->extra->button.hasfocus))||(p->extra->type==CC_TP_COMBO)|| (p->extra->type==CC_TP_LIST))&&_cc_isactive(p))return p; if((p->extra->type==CC_TP_DIALOG)&&(_cc_isactive(p)||p->hasmodal)) return _cc_findchildnom(p); } return win; } void _cc_combodblclkproc(Cc_Win *sender) { if(sender->extra->type==CC_TP_LIST) if(sender->parent!=NULL) if(sender->parent->extra->type==CC_TP_COMBO) { COMBO *combo=&sender->parent->extra->combo; long i=sender->extra->list.activeline; _cc_setcomboactiveitem(combo,combo->activeline,i); combo->activeline=i; combo->scroll=0; if(combo->change!=NULL)combo->change(sender->parent); _cc_redrawclientwin(sender->parent); } } void _cc_buttontimer(Cc_Timer *sender) { _cc_redrawclientwin(sender->win); cc_del_timer(sender); } void _cc_bclosepush(Cc_Win *sender) { DIALOG *dialog=&sender->parent->extra->dialog; if(dialog->close!=NULL)dialog->close(sender->parent); } void _cc_bmaximizepush(Cc_Win *sender) { if(sender->parent->extra->dialog.state==CC_SV_MAXIMIZED) cc_move_win(sender->parent,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE, CC_SV_NORMAL); else cc_move_win(sender->parent,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE, CC_SV_MAXIMIZED); } void _cc_bminimizepush(Cc_Win *sender) { if(sender->parent->extra->dialog.state==CC_SV_MINIMIZED) cc_move_win(sender->parent,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE, CC_SV_NORMAL); else cc_move_win(sender->parent,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE,CC_NOCHANGE, CC_SV_MINIMIZED); } void _cc_dodeletewin(Cc_Win *win) { Cc_Win *p,*pnext; if(win==NULL)return; if(win->parent==NULL) { if(_cc_hlwin==win) { _cc_hlwin=win->next; if(_cc_hlendwin==win)_cc_hlendwin=NULL; } else if(_cc_hlwin!=NULL) { p=_cc_hlwin; while(p->next!=win){p=p->next;if(p==NULL)return;} p->next=win->next; if(win==_cc_hlendwin)_cc_hlendwin=p; } } else { if(win->parent->lastfocus==win)win->parent->lastfocus=NULL; if(win->parent->child==win) { win->parent->child=win->next; if(win->parent->childend==win)win->parent->childend=NULL; } else if(win->parent->child!=NULL) { p=win->parent->child; while(p->next!=win){p=p->next;if(p==NULL)return;} p->next=win->next; if(win==win->parent->childend)win->parent->childend=p; } } p=win->child; while(p!=NULL) { pnext=p->next; _cc_dodeletewin(p); p=pnext; } if(win->extra->type==CC_TP_EDIT)free(win->extra->edit.text); if(_cc_focuswin==win)_cc_focuswin=NULL; if(_cc_capturewin==win)_cc_capturewin=NULL; _cc_usekeys=true; cc_del_timer_for_win(win); while(g_list_find(_cc_dialoglist,win)!=NULL) _cc_dialoglist=g_list_remove(_cc_dialoglist,win); if(win->extra->type==CC_TP_MENU) { Cc_Win *parent=win->parent; if(parent!=NULL) { if(parent->extra->type==CC_TP_DIALOG) { DIALOG *dialog=&parent->extra->dialog; if(dialog->menu==win)dialog->menu=NULL; } else if(parent->extra->type==CC_TP_MENU) { MENU *menu=&parent->extra->menu; GList *lines=menu->lines; while(lines!=NULL) { if(((Cc_Menu_I*)lines->data)->submenu==win) ((Cc_Menu_I*)lines->data)->submenu=NULL; lines=g_list_next(lines); } } } if(_cc_hlmenu==win)_cc_hlmenu=NULL; MENU *menu=&win->extra->menu; GList *lines=menu->lines; while(lines!=NULL) { free(lines->data); lines=g_list_next(lines); } if(menu->lines!=NULL)g_list_free(menu->lines); } else if(win->extra->type==CC_TP_TEXT) { if(_cc_hldowntext==win)_cc_hldowntext=NULL; } if(win==_cc_lastfocused)_cc_lastfocused=NULL; free(win->extra); free(win->windata); free(win); } Cc_Win *_cc_findnextwin(Cc_Win *win) { if(win==NULL)return NULL; Cc_Win *p=win->next; while(true) { if(p==NULL)p=(win->parent==NULL)?_cc_hlwin:win->parent->child; if(((p==win)||( ((p->extra->type==CC_TP_EDIT)||((p->extra->type==CC_TP_BUTTON)&& (p->extra->button.hasfocus))||(p->extra->type==CC_TP_COMBO)|| (p->extra->type==CC_TP_LIST))))&&_cc_isactive(p))return p; p=p->next; } } Cc_Win *_cc_findprevwin(Cc_Win *win) { if(win==NULL)return NULL; Cc_Win *val=win,*prev=win; while(1) { val=_cc_findnextwin(val); if(val!=NULL){if(val==win)return prev;}else return NULL; prev=val; } } Cc_Win *_cc_cyclenextwin(Cc_Win *win) { if(win==NULL)return NULL; Cc_Win *parent=win->parent; win=win->next; if(win==NULL) { if(parent!=NULL)win=parent->child; else win=_cc_hlwin; } return win; } Cc_Win *_cc_searchnextdialog(Cc_Win *win) { Cc_Win *start=win; if(win==NULL)return NULL; do { Cc_Win *n=_cc_searchnextdialog(win->child); if(n!=NULL)return n; if((win->extra->type==CC_TP_DIALOG)&&_cc_isactive(win))return win; win=_cc_cyclenextwin(win); } while(win!=start); return NULL; } Cc_Win *_cc_findnextdialog(Cc_Win *win) { Cc_Win *p=_cc_searchnextdialog((win!=NULL)?_cc_cyclenextwin(win):_cc_hlwin); if((win!=NULL)&&(p!=win)) { _cc_dialoglist=g_list_prepend(_cc_dialoglist,win); if(g_list_length(_cc_dialoglist)>MAX_PREVIOUS_DIALOGS) { GList *l=g_list_last(_cc_dialoglist); _cc_dialoglist=g_list_remove_link(_cc_dialoglist,l); g_list_free(l); } } return p; } Cc_Win *_cc_findprevdialog(Cc_Win *win) { Cc_Win *p; if(_cc_dialoglist==NULL)return win; p=_cc_dialoglist->data; _cc_dialoglist=g_list_remove(_cc_dialoglist,p); return (p!=NULL)?p:win; } bool _cc_runacel(Cc_Win *win,long x,long y,unsigned short key) { Cc_Win *p=win,*parent; if(p==NULL)p=_cc_hlmenu; while(p!=NULL) { if(p->extra->type==CC_TP_DIALOG) { parent=p->extra->dialog.menu; } else if((p->extra->type==CC_TP_MENU)&&!p->extra->menu.vert) { parent=p->parent; if(parent!=NULL)parent=p->parent; if(parent==NULL)parent=(Cc_Win*)-1; } else parent=p->parent; if(p->acel!=NULL){if(p->acel(p,x,y,key))return true;} else if(cc_send_message(p,x,y,key))return true; p=parent; if(!_cc_winexist(p))break; if(p==NULL)p=_cc_hlmenu; else if(p==(Cc_Win*)-1)break; } if(_cc_acelproc!=NULL){if(_cc_acelproc(NULL,x,y,key))return true;} else if(cc_send_message(NULL,x,y,key))return true; return false; } Cc_Win *_cc_findwin(long x,long y) { if((x<0)||(y<0)||(x>=_cc_screenx)||(y>=_cc_screeny))return NULL; return _cc_cmap[x+y*_cc_screenx].win; } Cc_Win *_cc_findwinonlypaint(long x,long y) { if((x<0)||(y<0)||(x>=_cc_screenx)||(y>=_cc_screeny))return NULL; return _cc_cmap[x+y*_cc_screenx].paint; } void _cc_dosetredrawed(Cc_Win *win,bool redrawed) { if(_cc_hlmenu!=NULL) { if(_cc_hlmenu->parent!=NULL)_cc_setparent(_cc_hlmenu,NULL); _cc_hlmenu->x=0; _cc_hlmenu->y=0; _cc_hlmenu->vx=_cc_screenx; _cc_hlmenu->vy=1; } if(_cc_hldowntext!=NULL) { if(_cc_hldowntext->parent!=NULL)_cc_setparent(_cc_hldowntext,NULL); _cc_hldowntext->style|=CC_ST_TOP_WIN; _cc_hldowntext->x=0; _cc_hldowntext->y=_cc_screeny-1; _cc_hldowntext->vx=_cc_screenx; _cc_hldowntext->vy=1; } for(;win!=NULL;win=win->next) { _cc_checkwin(win); win->redrawed=redrawed; _cc_dosetredrawed(win->child,redrawed); } } int _cc_doredraw(Cc_Win *win,char drawmode) { for(;win!=NULL;win=win->next) { if(drawmode==DM_BOTTOM) { if(!(win->style&CC_ST_TOP_WIN)) { if(_cc_drawwin(win,true)==ERR)return ERR; win->redrawed=true; _cc_checkbars(win,true); if(_cc_doredraw(win->child,DM_BOTTOM)==ERR)return ERR; } else { _cc_topwinlist=g_slist_append(_cc_topwinlist,win); if(_cc_doredraw(win->child,DM_MARK_TOP)==ERR)return ERR; } } else if(drawmode==DM_MARK_TOP) { if(win->style&CC_ST_TOP_WIN) _cc_topwinlist=g_slist_append(_cc_topwinlist,win); if(_cc_doredraw(win->child,DM_MARK_TOP)==ERR)return ERR; } else if(drawmode==DM_TOP_BOTTOM) { if(!(win->style&CC_ST_TOP_WIN)) { if(_cc_drawwin(win,true)==ERR)return ERR; win->redrawed=true; _cc_checkbars(win,true); } if(_cc_doredraw(win->child,DM_TOP_BOTTOM)==ERR)return ERR; } } return OK; } void _cc_doneredraw() { long x,y; if((_cc_focuswin!=NULL)&&(_cc_focuswin->extra->type==CC_TP_EDIT)&& (_cc_focuswin->extra->edit.maskpos==-1)) { EDIT *edit=&_cc_focuswin->extra->edit; x=0;y=0; cc_client_to_screen(_cc_focuswin,&x,&y); x+=edit->curpos-edit->scroll; if(((x>=0)&&(y>=0)&&(x<_cc_screenx)&&(y<_cc_screeny))&& (_cc_isvisible(_cc_focuswin))&&(_cc_findwin(x,y)==_cc_focuswin)) { move(y,x); curs_set(1); } else { curs_set(0); move(0,0); } } else { curs_set(0); move(0,0); } if(_cc_mouseactive==MOUSE_GPM)_cc_redrawmouse=0; } void _cc_redrawclientwin(Cc_Win *win) { if(!_cc_winexist(win))return; if(win==NULL)return; if((win->style&CC_ST_AUTOXSIZE)||(win->style&CC_ST_AUTOYSIZE)) { _cc_redraw(); return; } if(!_cc_isvisible(win))return; _cc_drawwin(win,false); long x=0,y=0,j,i,z; attr_t *data=win->windata; CMAP *map=_cc_cmap; cc_client_to_screen(win,&x,&y); wredrawln(stdscr,y,win->vy); for(j=y;jvy;j++) { map=_cc_cmap+j*_cc_screenx+x; for(i=x;ivx;i++) { if(map->win==win) { z=*data; if(map->fade)z=_cc_fadecolor(z); mvaddch(j,i,z); } map++; data++; } } refresh(); _cc_doneredraw(); } int _cc_redraw() { Cc_Win *win; long x,y,px,py,a1,a2; short c1,c2; GSList *sl; curs_set(0); move(0,0); if(_cc_hlvisible) { c1=CC_C_BLUE;c1<<=3;c1+=CC_C_WHITE; init_pair(c1,CC_C_WHITE,CC_C_BLUE); c2=!_cc_uglycharset?CC_C_BLUE:CC_C_WHITE;c2<<=3;c2+=CC_C_WHITE; init_pair(c2,CC_C_WHITE,!_cc_uglycharset?CC_C_BLUE:CC_C_WHITE); a1=(!_cc_uglycharset?A_ALTCHARSET:0)+COLOR_PAIR(c1)+_cc_mapsymbol[CHESS]; a2=A_BOLD+(!_cc_uglycharset?A_ALTCHARSET:0)+COLOR_PAIR(c2)+ _cc_mapsymbol[CHESS]; px=(_cc_screenx-BITMAPX)/2; py=(_cc_screeny-BITMAPY)/2; _cc_fillback(&_cc_mainwin,a1); for(y=py;ydata; if(_cc_drawwin(win,true)==ERR)return ERR; win->redrawed=true; _cc_checkbars(win,true); if(_cc_doredraw(win->child,DM_TOP_BOTTOM)==ERR)return ERR; sl=g_slist_next(sl); } if(_cc_topwinlist!=NULL) { g_slist_free(_cc_topwinlist); _cc_topwinlist=NULL; } } else { c1=CC_C_BLACK;c1<<=3;c1+=CC_C_WHITE; init_pair(c1,CC_C_WHITE,CC_C_BLACK); a1=COLOR_PAIR(c1)+' '; _cc_fillback(&_cc_mainwin,a1); } _cc_mrefresh(&_cc_mainwin); refresh(); _cc_doneredraw(); return OK; } void _cc_checkwin(Cc_Win *win) { if(win==NULL)return; long x,y,wx,wy,px,py; bool result; cc_get_client_size(win->parent,&px,&py,&wx,&wy); switch(win->style&CC_ST_AL_FIXED) { case CC_ST_AL_LEFT:win->x=px;break; case CC_ST_AL_CENTER: win->x=(win->style&CC_ST_AR_FIXED)!=CC_ST_AR_CENTER?(wx+px)/2: (wx+px-win->vx)/2; break; case CC_ST_AL_FIXED:win->x=win->flx;break; } switch(win->style&CC_ST_AR_FIXED) { case CC_ST_AR_RIGHT: if(win->style&CC_ST_AL_FIXED)win->vx=wx+px-win->x; else win->x=wx+px-win->vx; break; case CC_ST_AR_CENTER: if(win->style&CC_ST_AL_FIXED) { if((win->style&CC_ST_AL_FIXED)!=CC_ST_AL_CENTER) win->vx=(wx+px)/2-win->x; } else win->x=(wx+px)/2-win->vx; break; case CC_ST_AR_FIXED: if(win->style&CC_ST_AL_FIXED)win->vx=wx+px-win->frx-win->x; else win->x=wx+px-win->frx-win->vx; break; } switch(win->style&CC_ST_AU_FIXED) { case CC_ST_AU_UP:win->y=py;break; case CC_ST_AU_CENTER: win->y=(win->style&CC_ST_AD_FIXED)!=CC_ST_AD_CENTER?(wy+py)/2: (wy+py-win->vy)/2; break; case CC_ST_AU_FIXED:win->y=win->fly;break; } switch(win->style&CC_ST_AD_FIXED) { case CC_ST_AD_DOWN: if(win->style&CC_ST_AU_FIXED)win->vy=wy+py-win->y; else win->y=wy+py-win->vy; break; case CC_ST_AD_CENTER: if(win->style&CC_ST_AU_FIXED) { if((win->style&CC_ST_AU_FIXED)!=CC_ST_AU_CENTER) win->vy=(wy+py)/2-win->y; } else win->y=(wy+py)/2-win->vy; break; case CC_ST_AD_FIXED: if(win->style&CC_ST_AU_FIXED)win->vy=wy+py-win->fry-win->y; else win->y=wy+py-win->fry-win->vy; break; } if(win->style&CC_ST_A_TEMP) win->style&=~(CC_ST_AL_FIXED|CC_ST_AU_FIXED|CC_ST_AR_FIXED|CC_ST_AD_FIXED| CC_ST_A_TEMP); x=win->x; y=win->y; cc_client_to_screen(win->parent,&x,&y); if(win->extra->type==CC_TP_DIALOG) { if(win->vx<10)win->vx=10; if(x>_cc_screenx-1)x=_cc_screenx-1; if(y>_cc_screeny-1-(_cc_hldowntext!=NULL?1:0)) y=_cc_screeny-1-(_cc_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==CC_TP_LIST)&& (win->extra->list.combotyp==CC_LI_COMBO)) { if((win->parent!=NULL)&&(win->parent->extra->type==CC_TP_COMBO)) { px=0;py=0;cc_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>_cc_screeny)y=py-win->vy; } if(x+win->vx>_cc_screenx)x=_cc_screenx-win->vx; if(x<0)x=0; if(x+win->vx>_cc_screenx)win->vx=_cc_screenx-x; if(y+win->vy>_cc_screeny)y=_cc_screeny-win->vy; if(y<0)y=0; if(y+win->vy>_cc_screeny)win->vy=_cc_screeny-y; } else if((win->extra->type==CC_TP_MENU)&&(win->extra->menu.vert)) { if(x+win->vx>_cc_screenx)x=_cc_screenx-win->vx; if(x<0)x=0; if(y+win->vy>_cc_screeny)y=_cc_screeny-win->vy; if(y<0)y=0; } else if((win->extra->type==CC_TP_TEXT)|| (win->extra->type==CC_TP_EDIT)|| (win->extra->type==CC_TP_COMBO)|| ((win->extra->type==CC_TP_SCROLL)&&(!win->extra->scroll.vert))|| ((win->extra->type==CC_TP_STATUS)&&(!win->extra->status.vert))|| ((win->extra->type==CC_TP_MENU)&&(!win->extra->menu.vert))) { if(win->vy>1)win->vy=1; } else if(((win->extra->type==CC_TP_SCROLL)&&(win->extra->scroll.vert))|| ((win->extra->type==CC_TP_STATUS)&&(win->extra->status.vert))) { if(win->vx>1)win->vx=1; } if(win->extra->type==CC_TP_TEXT) { if(win->extra->text.text!=NULL) if((win->style&CC_ST_AUTOXSIZE)==CC_ST_AUTOXSIZE) win->vx=strlen(win->extra->text.text); } else if(win->extra->type==CC_TP_BUTTON) { if(win->extra->button.text!=NULL) if((win->style&CC_ST_AUTOXSIZE)==CC_ST_AUTOXSIZE) win->vx=_cc_strlenmenu(win->extra->button.text)+4; } else if(win->extra->type==CC_TP_COMBO) { long maxlen,numlines; COMBO *combo=&win->extra->combo; LIST *list=&combo->list->extra->list; numlines=list->numlines; maxlen=list->maxitemlen; if((win->style&CC_ST_AUTOXSIZE)==CC_ST_AUTOXSIZE)win->vx=maxlen+1; } else if(win->extra->type==CC_TP_LIST) { LIST *list=&win->extra->list; GList *lines=list->lines; if((win->style&CC_ST_AUTOXSIZE)==CC_ST_AUTOXSIZE)win->vx=list->maxitemlen+2; if((win->style&CC_ST_AUTOYSIZE)==CC_ST_AUTOYSIZE)win->vy=list->numlines+2; } cc_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; cc_client_to_screen(win,&wx,&wy); x=wx; y=wy; if((x>=_cc_screenx)||(y>=_cc_screeny))return; wx=_cc_screenx-wx; wy=_cc_screeny-wy; if(wx<0)wx=0; if(wy<0)wy=0; if(win->vxvx; if(win->vyvy; 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 CC_TP_COMBO:_cc_checkwincombo(win);break; case CC_TP_LIST:_cc_checkwinlist(win);break; case CC_TP_MENU:_cc_checkwinmenu(win);break; case CC_TP_DIALOG:_cc_checkwindialog(win); } } int _cc_drawwin(Cc_Win *win,bool dorefresh) { if(win==NULL)return; if(!_cc_isvisible(win))return; long x,y,wx; x=0; y=0; cc_client_to_screen(win,&x,&y); if((x>=_cc_screenx)||(y>=_cc_screeny))return; if((x+win->vx<=0)||(y+win->vy<=0))return; wx=win->vx; switch(win->extra->type) { case CC_TP_TEXT:_cc_drawwintext(win);break; case CC_TP_EDIT:_cc_drawwinedit(win);break; case CC_TP_BUTTON:_cc_drawwinbutton(win,wx);break; case CC_TP_SCROLL:_cc_drawwinscroll(win);break; case CC_TP_LIST:_cc_drawwinlist(win,wx);break; case CC_TP_COMBO:_cc_drawwincombo(win);break; case CC_TP_STATUS:_cc_drawwinstatus(win);break; case CC_TP_PAINT:_cc_drawwinpaint(win);break; case CC_TP_MENU:_cc_drawwinmenu(win,wx);break; case CC_TP_DIALOG:_cc_drawwindialog(win,wx);break; case TP_FADE:_cc_drawwinfade(win,x,y);break; } if(dorefresh)_cc_mrefresh(win); } void _cc_clipboardmenuproc(Cc_Win *win,long id) { switch(id) { case 0:cc_edit_cut(win->parent);break; case 1:cc_edit_copy(win->parent);break; case 2:cc_edit_paste(win->parent);break; case 3:cc_edit_delete(win->parent);break; case 4:cc_edit_select(win->parent,0,CC_MAXLONG);break; } }