home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / dlged002.zip / dlgcomr.cpp next >
C/C++ Source or Header  |  1995-07-18  |  3KB  |  142 lines

  1. #include "dlgedit.h"
  2. #include "stdio.h"
  3. #include "string.h"
  4. #include "time.h"
  5.  
  6. char filebanner[]="DL Binary Dialog File version 0.0\x1a";
  7. char resbanner[]="/*\n * Resource file created by dlgedit version 0.0\n * Giovanni Iachello 1995\n * ";
  8.  
  9. /* */
  10.  
  11. void writecontrol(FILE* f,_dlgcontrol* ctrl);
  12.  
  13. BOOL compile(const char* file,_dlginfo* pdi)
  14. {
  15.     int i;
  16.     time_t compiletime;
  17.     char fn[300];
  18.     _dlginfo* p;
  19.  
  20.     time(&compiletime);
  21.  
  22.     strcpy(fn,file);
  23.     strcat(fn,"G");
  24.     if (pdi) p=pdi; else { p=new _dlginfo; loaddl(file,p); }
  25.  
  26.     FILE* f=fopen(fn,"wt");
  27.     fputs(resbanner,f);
  28.     fprintf(f,"%s compiled on %s */\n",fn,ctime(&compiletime));
  29.     fprintf(f,"DLGTEMPLATE %s \n{\n\tDIALOG \"%s\", %s , %d, %d, %d, %d,\n",
  30.         p->label,p->title,p->label,10,10,p->sx,p->sy);
  31.     fprintf(f,"\t\tWS_VISIBLE, ");
  32.     int notfirst=FALSE;
  33.     for (i=0; i<26; i++) {
  34.         if (p->fl[i]) {
  35.             if (notfirst) fputs("| ",f);
  36.             fprintf(f,"%s ",winflnames[i]);
  37.             notfirst=TRUE;
  38.         }
  39.     }        
  40.     fputs("\n\t{\n",f);
  41.     _dlgcontrol* ctrl=p->dlgctrl;
  42.     while ( ctrl != NULL ) {
  43.         writecontrol(f,ctrl);
  44.         ctrl=ctrl->next;
  45.     }
  46.  
  47.     fputs("\n\t}\n}\n",f);
  48.     fclose(f);
  49.     
  50.     if (p!=pdi) delete p;
  51.     return TRUE;
  52. }
  53.  
  54. void writecontrol(FILE* f,_dlgcontrol* ctrl)
  55. {
  56.     if (apchDialogControlRCNames[ctrl->classidx]) {
  57.         fprintf(f,"\t\t%s \"%s\", %s, %ld, %ld, %ld, %ld",
  58.             apchDialogControlRCNames[ctrl->classidx],
  59.             ctrl->text,
  60.             (ctrl->idc[0] ? ctrl->idc : "-1"),
  61.             ctrl->x,
  62.             ctrl->y,
  63.             ctrl->cx,
  64.             ctrl->cy);
  65.     } else {
  66.         fprintf(f,"\t\tCONTROL \"%s\", %s, %ld, %ld, %ld, %ld, %s",
  67.             ctrl->text,
  68.             (ctrl->idc[0] ? ctrl->idc : "-1"),
  69.             ctrl->x,
  70.             ctrl->y,
  71.             ctrl->cx,
  72.             ctrl->cy,
  73.             apchClassNames[ctrl->classidx]);
  74.     }
  75.     if (ctrl->flags) { // mettici i flags, prima quelli della finestra
  76.         int first=1;
  77.         fputs(", ",f);
  78.         _style *ws=aWindowStyles;
  79.         while (ws->label!=NULL) {
  80.             if (ws->value & ctrl->flags) {
  81.                 if (first) first=0; else fputs("| ",f);
  82.                 fprintf(f,"%s ",ws->label);
  83.             }
  84.             ws++;
  85.         }
  86.         ws=apsStyles[ctrl->classidx];
  87.         if (ws) {
  88.             while (ws->label!=NULL) { // poi quelli specifici
  89.                 if (ws->type==1) { // valore preciso 
  90.                     if ( ws->value == ( ctrl->flags & ws->bits ) ) {
  91.                         if (first) first=0; else fputs("| ",f);
  92.                         fprintf(f,"%s ",ws->label);
  93.                     }
  94.                 } else { // semplice bit
  95.                     if ( ws->value & ctrl->flags ) {
  96.                         if (first) first=0; else fputs("| ",f);
  97.                         fprintf(f,"%s ",ws->label);
  98.                     }
  99.                 }
  100.                 ws++;
  101.             }
  102.         }
  103.     }    
  104.     fputs("\n",f);
  105. }
  106.  
  107.  
  108. BOOL savedl(const char* file,_dlginfo* pdi)
  109. {
  110.     FILE* f=fopen(file,"wb");
  111.     fwrite(filebanner,strlen(filebanner)+1,1,f);
  112.     fwrite(pdi,sizeof(*pdi),1,f);
  113.     _dlgcontrol* pdc=pdi->dlgctrl;
  114.     while (pdc!=NULL) {
  115.         fwrite(pdc,sizeof(*pdc),1,f);
  116.         pdc=pdc->next;
  117.     }
  118.     fclose(f);
  119.     return TRUE;
  120. }
  121.  
  122. BOOL loaddl(const char* file,_dlginfo* pdi)
  123. {
  124.     FILE* f=fopen(file,"rb");
  125.     if (!f) return FALSE;
  126.     fseek(f,strlen(filebanner)+1,SEEK_CUR);
  127.  
  128.     fread(pdi,sizeof(*pdi),1,f);
  129.  
  130.     _dlgcontrol** pdc=&(pdi->dlgctrl);
  131.     while (!feof(f)) {
  132.         *pdc= new _dlgcontrol;
  133.         fread(*pdc,sizeof(**pdc),1,f);
  134.         if (feof(f)) { delete *pdc; break; }
  135.         pdc=&((*pdc)->next);
  136.     }
  137.     *pdc=NULL;
  138.     fclose(f);
  139.     return TRUE;
  140. }
  141.  
  142.