home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / dlged002.zip / dlguser.cpp < prev    next >
C/C++ Source or Header  |  1995-11-24  |  5KB  |  217 lines

  1. /* 
  2.  
  3.  
  4.     dlguser.cpp (emx+gcc) 
  5.  
  6.     1995 Giovanni Iachello
  7.     This is freeware software. You can use or modify it as you wish,
  8.     provided that the part of code that I wrote remains freeware.
  9.     Freeware means that the source code must be available on request 
  10.     to anyone.
  11.     You must also include this notice in all files derived from this
  12.     file.
  13.  
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #define INCL_WIN
  21. #include "pmwin.h"
  22. #include "pmdlg.h"
  23. #include "pmgpi.h"
  24. #include "pmstdres.h"
  25. #include "dlgedit.h"
  26. #include "dlgdata.h"
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29.  
  30. ControlWin::ControlWin(PMWin* iowner, PCSZ pszClass, PCSZ pszName,
  31.     ULONG flStyle, LONG x, LONG y, LONG cx, LONG cy, 
  32.        HWND hwndInsertBehind, ULONG id, PVOID pCtlData, PVOID pPresParams) :
  33.  
  34.     PMSubclassWin(iowner->getHwnd(),pszClass,pszName,flStyle,x,y,cx,cy,
  35.         iowner->getHwnd(),hwndInsertBehind,id,pCtlData,pPresParams) 
  36. {
  37.     owner=iowner;
  38. }
  39.  
  40. BOOL ControlWin::destroyWin() 
  41. {
  42.     return WinDestroyWindow(hwnd);
  43. }
  44.  
  45. BOOL ControlWin::other(PMEvent &event)
  46. {
  47.     switch (event.msg) {
  48.         case WM_CONTEXTMENU:
  49.             owner->postMsg(WM_CTRLMENU,(MPARAM)this,event.mp1);
  50.             event.ret=(MRESULT)TRUE;
  51.             return TRUE;
  52.         default:
  53.             return FALSE;        
  54.     }
  55.     return FALSE;
  56. }
  57.  
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60.  
  61.  
  62. BOOL CtrlFlagsDialog::createWin()
  63. {
  64.     int i;
  65.     _style *p;
  66.     p=aWindowStyles; // ricava dalla struttura i flags
  67.     i=0;
  68.     while (p->label!=NULL) {
  69.         if (dc->flags&p->value) dlgflags.fl[i]=1; 
  70.         else dlgflags.fl[i]=0;
  71.         p++;
  72.         i++;
  73.     }
  74.     p=apsStyles[dc->classidx]; // ricava dalla struttura i flags
  75.     i=13;
  76.     while (p->label!=NULL) {
  77.         if (p->type) {
  78.             if ((dc->flags&p->bits)==p->value) dlgflags.fl[i]=1; 
  79.             else dlgflags.fl[i]=0;
  80.         } else {
  81.             if (dc->flags&p->value) dlgflags.fl[i]=1; 
  82.             else dlgflags.fl[i]=0;
  83.         }
  84.         p++;
  85.         i++;
  86.     }
  87.     int ret=PMModalDialog::createWin();
  88.     if (ret) {
  89.         dc->flags=0;
  90.         p=aWindowStyles; // ricava dalla struttura i flags
  91.         i=0;
  92.         while (p->label!=NULL) {
  93.             if (dlgflags.fl[i])
  94.                 dc->flags|=p->value;                
  95.             p++;
  96.             i++;
  97.         }
  98.         p=apsStyles[dc->classidx]; // ricava dalla struttura i flags
  99.         i=13;
  100.         while (p->label!=NULL) {
  101.             if (p->type) {
  102.                 if (dlgflags.fl[i]) 
  103.                     dc->flags=(dc->flags&(~p->bits))|p->value;
  104.             } else {
  105.                 if (dlgflags.fl[i])
  106.                     dc->flags|=p->value;
  107.             }
  108.             p++;
  109.             i++;
  110.         }
  111.     }                                
  112.     return ret;
  113. }
  114.  
  115. BOOL CtrlFlagsDialog::initdlg()
  116. {
  117.     _style *p=apsStyles[dc->classidx]; // scrivi nei checkbox i nomi dei flags
  118.     int cbid=DCF_1;
  119.     while (p->label!=NULL) {
  120.         PMControl *c=controlFromID(cbid);
  121.         assert(c);
  122.         c->setWindowText(p->label);
  123.         cbid++;
  124.         p++;
  125.     }
  126.     while (cbid<=DCF_F) {
  127.         controlFromID(cbid)->setPos(getHwnd(),0,0,0,0,SWP_HIDE );
  128.         cbid++;
  129.     }
  130.     return TRUE;
  131. }
  132.  
  133.  
  134. ////////////////////////////////////////////////////////////////////////////
  135.  
  136. CtrlListDialog::CtrlListDialog(HWND parent,HWND owner,WorkWindow *iww,PMWin* ieditor) :
  137.     PMModelessDialog(parent,owner,DLG_CTRLLIST,ctrlmap,&dlginfo) 
  138. {
  139.     ww=iww;
  140.     editor=ieditor;
  141. }
  142.  
  143.  
  144. BOOL CtrlListDialog::initdlg() 
  145. {
  146.     char buf[128];
  147.     PMListBox* lb=(PMListBox*)controlFromID(DCTRLLIST_LB_CTRLLIST);
  148.     if (ww) {
  149.         _dlgcontrol* p=ww->dlginfo->dlgctrl;
  150.     
  151.         while (p!=NULL) {
  152.             strcpy(buf,apchClassNames[p->classidx]);
  153.             strcat(buf," - ");
  154.             strcat(buf,p->idc);
  155.             lb->insertItem(LIT_END,buf);
  156.             p=p->next;
  157.         }
  158.     }
  159.     
  160.     return TRUE;
  161. }        
  162.  
  163. BOOL CtrlListDialog::command(USHORT id,USHORT cmddev) 
  164. {
  165.     // find pointer to control information structure
  166.     switch (id) {
  167.     case DCTRLLIST_PB_PROP:
  168.     case DCTRLLIST_PB_DELETE:
  169.     case DCTRLLIST_PB_FLAGS:
  170.         _dlgcontrol* p=ww->dlginfo->dlgctrl;
  171.         PMListBox* lb=(PMListBox*)controlFromID(DCTRLLIST_LB_CTRLLIST);
  172.         int ctrlnum=lb->querySelection();
  173.         if (ctrlnum<0) return PMModalDialog::command(id,cmddev); // non era selezionato nessun controllo
  174.         while (p!=NULL && ctrlnum>0) {
  175.             p=p->next;
  176.             ctrlnum--;
  177.         }                                  
  178.         ww->edctrl=p;
  179.     case DID_OK:
  180.         editor->postMsg(WM_CLOSECTRLLIST);
  181.     }
  182.     // le workwindow do the work!!
  183.     switch (id) {
  184.     case DCTRLLIST_PB_PROP:
  185.         ww->command(IDM_PU_PROP,cmddev);
  186.         break;
  187.     case DCTRLLIST_PB_DELETE:
  188.         ww->command(IDM_PU_DELETE,cmddev);
  189.         break;
  190.     case DCTRLLIST_PB_FLAGS:
  191.         ww->command(IDM_PU_FLAGS,cmddev);
  192.         break;
  193.     }
  194.     // refresh the control listbox
  195.     switch (id) {
  196.     case DCTRLLIST_PB_PROP:
  197.     case DCTRLLIST_PB_DELETE:
  198.         PMListBox* lb=(PMListBox*)controlFromID(DCTRLLIST_LB_CTRLLIST);
  199.         assert(lb);
  200.         lb->deleteAll(); // delete all items
  201.         initdlg();
  202.     }
  203.     return PMModalDialog::command(id,cmddev);
  204. }         
  205.  
  206. BOOL CtrlListDialog::other(PMEvent& evt) 
  207. {
  208.     if (evt.msg == WM_REFRESH) {
  209.         PMListBox* lb=(PMListBox*)controlFromID(DCTRLLIST_LB_CTRLLIST);
  210.         assert(lb);
  211.         lb->deleteAll(); // delete all items
  212.         initdlg();
  213.     }
  214.     return FALSE;
  215. }
  216.  
  217.