home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 December / PCWorld_2002-12_cd.bin / Software / Komercni / Baltik / katB.exe / katB / DESIGN / DESIGN_C.DIA < prev    next >
Text File  |  2002-09-22  |  33KB  |  764 lines

  1.  
  2. ////////////////////////////////////////////////////////////////////////////////
  3. //----------------------------------------------------------------------------//
  4. //-----project DESINGER, copyright 2002 Libor Bareτ-------------------------//
  5. //----------------------------------------------------------------------------//
  6. ////////////////////////////////////////////////////////////////////////////////
  7.  
  8.  
  9.  
  10. #define Diagram__ScreenToClient(x) x-=32
  11. #define Diagram__ClientToScreen(x) x+=32
  12. //#define Diagram__ScreenToClient2(x) (x).top-=32;(x).bottom-=32
  13. //#define Diagram__ClientToScreen2(x) (x).top+=32;(x).bottom+=32
  14.  
  15.  
  16. int Diagram__MakeCellWidth(int nID){
  17.         return (m_DiagramCells[nID].Rect.right-m_DiagramCells[nID].Rect.left);
  18. }
  19. int Diagram__MakeCellHeight(int nID){
  20.         return (m_DiagramCells[nID].Rect.bottom-m_DiagramCells[nID].Rect.top);
  21. }
  22. //void Diagram__ScreenToClient(int &y ){
  23. //   y +=-32;
  24. //}
  25. void Diagram__ScreenToClient2( RECT &rc){
  26.         Diagram__ScreenToClient(rc.top);
  27.         Diagram__ScreenToClient(rc.bottom);
  28. }
  29. //void Diagram__ClientToScreen(int &y ){
  30. //   y +=32;
  31. //}
  32. void Diagram__ClientToScreen2(RECT & rc ){
  33.    Diagram__ClientToScreen(rc.top);
  34.    Diagram__ClientToScreen(rc.bottom);
  35. }
  36.  
  37. void Diagram__GetCenterCell(int nID, int & x, int &y){
  38.         RECT* r=&Diagram__GetCell(nID)->Rect;
  39.     x=r->left+Diagram__MakeCellWidth(nID)/2;
  40.     y=r->top+Diagram__MakeCellHeight(nID)/2;
  41. }
  42. void Diagram__SetInterZOrder(unsigned nID){
  43.   // move array ...
  44.   int a;
  45.   if(m_nm_DiagramCellsSize != 0 && nID == m_DiagramZOrder[0]){
  46.       return;
  47.   }
  48.  
  49.   if(m_nm_DiagramCellsSize != 0 ){
  50.      // is nID control in array ?
  51.      int i;
  52.      int movefrom = -1;
  53.      for(i=0;i<m_nm_DiagramCellsSize;i++){
  54.          if(m_DiagramZOrder[i] == nID){ // yes, it is
  55.            movefrom =i;break;
  56.         
  57.         }
  58.  
  59.      }
  60.      if(movefrom == -1)movefrom = m_nm_DiagramCellsSize-1;
  61.      memcpy(&m_DiagramZOrder[1],&m_DiagramZOrder[0],sizeof(int)*movefrom);
  62.   }
  63.   m_DiagramZOrder[0]=nID;
  64.  
  65.  
  66. }
  67. void  Diagram__DrawOA(string strText,unsigned nType,int left,top, char draw,int &nPlusX){
  68.    // parser text and draw it ...
  69.    nPlusX=3;int nFont=FONT_TAHOMA_8;
  70.  
  71.    if(nType & 0x00000100L/*TYPE_OA_ABSTRACT*/ )nFont=FONT_TAHOMA_ITALIC_8;
  72.    if(nType & 0x00000010L/*TYPE_OA_DELIVER*/){if(draw)TextOut(left+nPlusX,top,"/",4,5,FONT_TAHOMA_8);nPlusX+=6;}
  73.    if(nType & 0x00000001L/*TYPE_OA_PROTECTED*/){if(draw)TextOut(left+nPlusX,top,"#",4,5,FONT_TAHOMA_8);nPlusX+=10;}
  74.    else if(nType & 0x00000002L/*TYPE_OA_PRIVATE*/){if(draw)TextOut(left+nPlusX,top,"-",4,5,FONT_TAHOMA_8);nPlusX+=10;}
  75.    // parsering
  76.    int nLen = StrVelikost(strText);
  77.    unsigned nPos = StrPozicePod²et╪zce(strText,0,"(");
  78.    SIZE sz;
  79.    string sdef;
  80.    if(nPos != 0xffff){
  81.        sdef = StrKopie(strText,0,nPos+1);
  82.  
  83.    }
  84.    else {
  85.        sdef = strText;
  86.    }
  87.    GetTextExtent(sdef,sz,nFont);
  88.    if(draw)TextOut(left+nPlusX,top,sdef,4,5,nFont);
  89.    nPlusX+=sz.x;
  90.    if(nPos != 0xffff){
  91.      nPos++;
  92.      while(nPos < nLen){
  93.        if((strText[nPos-1] == " " || strText[nPos-1] == "(" || strText[nPos-1] == ",") && StrKopie(strText,nPos,4) == "out " || StrKopie(strText,nPos,3) == "in " || StrKopie(strText,nPos,6) == "inout "){
  94.           int nstart = nPos;
  95.           while(strText[nPos] != ' ' && nPos < nLen ){
  96.               nPos++;
  97.           }
  98.           GetTextExtent(StrKopie(strText,nstart,nPos-nstart),sz,FONT_TAHOMA_BOLD_8);
  99.           if(draw)TextOut(left+nPlusX,top,StrKopie(strText,nstart,nPos-nstart),4,5,FONT_TAHOMA_BOLD_8);
  100.           nPlusX+=sz.x;
  101.        }
  102.        GetTextExtent(strText[nPos],sz,nFont);
  103.        if(draw)TextOut(left+nPlusX,top,strText[nPos],4,5,nFont);
  104.        nPlusX+=sz.x;
  105.        nPos++;
  106.  
  107.  
  108.      }
  109.    }
  110.  
  111.    nPlusX+=3;
  112.    if(nType & 0x00000008L/*TYPE_OA_CONSTANT*/){
  113.        if(draw)TextOut(left+nPlusX,top,"{constant}",4,5,nFont);
  114.        GetTextExtent("{constant}",sz,nFont);nPlusX+=sz.x;
  115.    }
  116.    if(nType & 0x00000100L/*TYPE_OA_ABSTRACT*/ ){
  117.        if(draw)TextOut(left+nPlusX,top,"{abstract}",4,5,nFont);
  118.        GetTextExtent("{abstract}",sz,nFont);nPlusX+=sz.x;
  119.  
  120.    }
  121.    nPlusX+=8;
  122. }
  123. char Diagram__DrawDepControl(int nType,int&x , int&y, int x2, int y2,double& ratex, double& ratey,nSize, char bDraw){
  124.     float onex = (x-x2);
  125.     float oney = (y-y2);
  126.     int size = sqrt((double)((onex*onex)+(oney*oney)));
  127.     if(size <= 0)return 1;//error
  128.     double rate;
  129.     rate=(((double)size)/(double)nSize);
  130.     ratex=onex/rate;  // vector.size = nSize ...
  131.     ratey=oney/rate;
  132.     int x3= x - ratex;
  133.     int y3= y - ratey;
  134.     ratey/=2;
  135.     ratex/=2;
  136.     if(bDraw == 2)return 0;
  137.         if(nType == 2 || nType == 1){int retx=x3*2-x,rety=y3*2-y;
  138.  
  139.            if(nType == 2) GrNastavBarvuPozadí(2);
  140.            else GrNastavBarvuPozadí(5);
  141.            GrKresliVypln╪n∞Mnohoúhelník(5,x,y,x3+(int)ratey,y3-(int)ratex,retx,rety,x3-(int)ratey,y3+(int)ratex,x,y);
  142.     //       else GrKresliMnohoúhelník(5,x,y,x3+(int)ratey,y3-(int)ratex,retx,rety,x3-(int)ratey,y3+(int)ratex,x,y);
  143.            x=retx;y=rety;
  144.  
  145.         }
  146.         else if(nType == 3){
  147.                 GrKresliMnohoúhelník(4,x,y,x3+(int)ratey,y3-(int)ratex,x3-(int)ratey,y3+(int)ratex,x,y);
  148.                                 x=x3;y=y3;
  149.  
  150.                 }
  151.    return 0;
  152. }
  153. void Diagram__DrawLabel(unsigned nType /*LABEL TYPE*/,string strText,int x,y,x2,y2,char bDraw,RECT* lprcDst){
  154.         if(strText=="")return;
  155.    // label types :
  156.    // first bit is set to '0' if is label below line else about line
  157.    // second bit is set to '0' if is label on leftside of line (usually on side whitch is dependented)
  158.    // supported value : 
  159.         //     vl=1,0x01      vl=17,0x11
  160.         //   ----------------------
  161.         //     vl=0,0x00      vl=16,0x10
  162.         //
  163.     double ratex,ratey,x3,y3;
  164.     if(Diagram__DrawDepControl(0,x,y,x2,y2,ratex,ratey,20,2))return; // only for recalculate rect and if is too small cell-rect return
  165.         x3=ratex,y3=ratey;
  166.         if(x <= x2){x3 =-x3;y3 =-y3;}
  167.         SIZE szText;
  168.         GetTextExtent(strText,szText,FONT_TAHOMA_8);szText.x+=2;szText.y+=2;
  169.         POINT ptFrom;
  170.                 if(nType%2 == 0){
  171.                   y3=-y3;
  172.                   x3=-x3;
  173.         }
  174.         if(nType > 1 )SetPoint(&ptFrom,x-ratex*1.5+y3,y-ratey*1.5-x3);
  175.         else SetPoint(&ptFrom,x2+ratex*1.5+y3,y2+ratey*1.5-x3);
  176.         SetRect(lprcDst,ptFrom.left,ptFrom.top,ptFrom.left+((y3 < 0)?-szText.x:szText.x),ptFrom.top-((x3 < 0)?-szText.y:szText.y));
  177.                 NormalizeRect(lprcDst); // normalize coordinations of rectangle
  178.                 if(lprcDst->top <=32){lprcDst->top=32;return;}
  179.         if(bDraw){
  180.                 FillSolidRect(lprcDst,1);
  181.                 TextOut(lprcDst->left+1,lprcDst->top+1,strText,4,1,FONT_TAHOMA_8);
  182.                                 InflateRect(lprcDst,1,1,1,1);
  183.                 
  184.         }
  185. }
  186. void Diagram__DrawDependent(int x, int y, int x2, int y2, char bDesigning, long nType,int nIDCell){
  187.         if(bDesigning==1){GrNastavBarvuPop²edí(1);GrNastavLinku(36/*1|0x20|4*/);}
  188.     CLASSITEM* pData;
  189.         DIAGRAMCELL *pCell;
  190.         long dwFlags=0;
  191.     char sError = ((40 > abs(x2-x) && 40 > abs(y2-y)));
  192.         if(nIDCell >= 0){
  193.                 
  194.                 pData = ((CLASSITEM*)((Diagram__GetCell(nIDCell))->pVariable));
  195.                 pCell = Diagram__GetCell(nIDCell);
  196.                 dwFlags = pCell->dwFlags;
  197.                 }
  198.     
  199.         double ratex,ratey,oneratex,oneratey;
  200.            int x3,y3;
  201.            if( nType & 2 /*TYPE_DEPENDENT_AGREGACE*/ || nType & 8/*TYPE_DEPENDENT_KOMPOZICE*/ || nType & 4){
  202.                    //ratey-=oneratey;ratex-=oneratex;
  203.                    GrNastavBarvuPozadí(2);
  204.                    if(bDesigning!=2){
  205.                                         if(!(nType & 4))if(Diagram__DrawDepControl(1+((nType & 8)?1:0),x,y,x2,y2,ratex,ratey,10,bDesigning)){GrKresliLinku(x,y,x2,y2);return;}
  206.                                                                                 GrKresliLinku(x,y,x2,y2);
  207.                                                                                 }
  208.                                                                                  string str;
  209.                                                                                  if(dwFlags & 0x00000100L)str+="ordered, ";
  210.                                                                                  if(dwFlags & 0x00000400L)str+="tree, ";
  211.                                                                                  if(dwFlags & 0x00000200L) str+="list, ";
  212.                                                                                  if(dwFlags & 0x00001000L)str+="bag, ";
  213.                                                                                  if(dwFlags & 0x00000800L) str+="set, ";
  214.                                                                                  if(StrDélka(str) > 2){
  215.                                                                                         StrNastavVelikost(str,StrDélka(str)-2);
  216.                                                                 str=" {"+str+"}";
  217.                                                                                  }
  218.                                                                                 str = pCell->ClassName+str;
  219.  
  220.                                         CenterText(x+(x2-x)/2,y+(y2-y)/2-7,str,4,1,FONT_TAHOMA_8,(bDesigning!=2),&pData[0].nRectType);
  221.                                         int i;
  222.                                         for(i=1;i < 5;i++)
  223.                                            Diagram__DrawLabel(pData[i].nType,pData[i].strText,x,y,x2,y2,(bDesigning!=2),&pData[i].nRectType);
  224.  
  225.  
  226.             }
  227.             else if(( nType & 16/*TYPE_DEPENDENT_MESSAGE*/)){
  228.  
  229.                
  230.                 POINT ptCenter;POINT pt2;
  231.                 if(!sError){
  232.                       if(dwFlags & 0x00001000L){
  233.                         Diagram__DrawDepControl(1,x2,y2,x,y,ratex,ratey,10,bDesigning);
  234.                         if(Diagram__DrawDepControl(3,x,y,x2,y2,ratex,ratey,16,bDesigning))return;
  235.  
  236.                      }else { if(Diagram__DrawDepControl(0,x2,y2,x,y,ratex,ratey,16,bDesigning))return;ratex*=-1;ratey*=-1;}
  237.  
  238.                 }else {bDesigning=3;}
  239.                                 if(bDesigning!=2)GrKresliLinku(x,y,x2,y2);
  240.                 if((80 > abs(x2-x) && 80 > abs(y2-y))||bDesigning==3)return;
  241.                 SetPoint(&ptCenter,(x2+(x-x2)/2-((x  > x2 )?-ratey:ratey)*1.5),(y2 +( y-y2 )/2+((x > x2 )?-ratex:ratex)*1.5));
  242.                 x3 = ratex*6;y3 = ratey*6;
  243.                                 SetPoint(&pt2,ptCenter.left+x3,ptCenter.top+y3);
  244.                 if(bDesigning!=2)GrKresliLinku(ptCenter.left-x3,ptCenter.top-y3,pt2.left,pt2.top);
  245.                 x3  = ratex;y3 = ratey;
  246.                 if(x < x2){
  247.                     x3 =-ratex;
  248.                     y3 =-ratey;
  249.                 }
  250.  
  251.                 if(bDesigning!=2){
  252.                    if((nType & 0x00000400L)){
  253.                       GrKresliLinku(pt2.left,pt2.top,pt2.left-ratex-y3,pt2.top-ratey+x3);
  254.                    }
  255.                    GrKresliLinku(pt2.left,pt2.top,pt2.left-ratex+y3,pt2.top-ratey-x3);
  256.                 }
  257.  
  258.                 SIZE s;
  259.  
  260.                 int plusy=-18;
  261.                 string str;
  262.                 if(pCell->strExStereotypes != ""){str="{priority = "+pCell->strExStereotypes+"} ";}
  263.                 if(nType & 0x00000800L ){str+=" ½broadcast╗";}
  264.                                 else if(nType & 0x00001000L && pCell->strExProperties != ""){
  265.                                     Diagram__DrawLabel(17,pCell->strExProperties,x,y,x2,y2,(bDesigning!=2),&pData[2].nRectType);
  266.                                 }
  267.                 if(str != ""){
  268.                       CenterText(ptCenter.left,ptCenter.top+plusy,str,4,5,FONT_TAHOMA_8,(bDesigning!=2),&pData[1].nRectType);
  269.                       plusy+=-13;
  270.  
  271.                 }
  272.                 CenterText(ptCenter.left,ptCenter.top+plusy,pCell->ClassName,4,5,FONT_TAHOMA_8,(bDesigning!=2),&pData[0].nRectType);
  273.                 
  274.             }
  275.             else {
  276.                   if(!sError)if(Diagram__DrawDepControl(3,x,y,x2,y2,ratex,ratey,16,bDesigning))return;
  277.  
  278.                   GrKresliLinku(x,y,x2,y2);
  279.                   string str;
  280.                     if(dwFlags & 0x00000400L)str+="disjoint, ";
  281.                     else if(dwFlags & 0x00000800L)str+="overlapping, ";
  282.                     if(dwFlags & 0x00000100L)str+="compete, ";
  283.                     else if(dwFlags & 0x00000200L)str+="incompete, ";
  284.                     if(dwFlags & 0x00001000L)str+="dynamic, ";
  285.                     else if(dwFlags & 0x00002000L)str+="static, ";
  286.                                         if(StrDélka(str) > 2){
  287.                          StrNastavVelikost(str,StrDélka(str)-2);
  288.                          str="{"+str+"}";
  289.                          CenterText(x+(x2-x)/2,y+(y2-y)/2-7,str,4,1,FONT_TAHOMA_8,(bDesigning!=2),&pData[0].nRectType);
  290.                          }
  291.  
  292.  
  293.  }
  294.    GrNastavLinku(21);/*1|0x10|4*/
  295.  
  296.  
  297. }
  298.  
  299.  
  300. void Diagram__DrawCell(unsigned nIDCell,char bDraw,int & nPlusX,int & nPlusY){
  301.     if(bDraw)HideMouse();
  302.     DIAGRAMCELL * cell = Diagram__GetCell(nIDCell);
  303.         int nType = cell->nType;
  304.         long dwFlags = cell->dwFlags;
  305.     RECT rect;
  306.     if(nType != 4/*TYPE_CLASS_DEPENDENT*/)CopyRect(&rect,&cell->Rect);
  307.     else CopyRect(&rect,&cell->PT);
  308.     int nPos=0;int nState=0;char bFocus =(m_nInterCellFocus == nIDCell)?1:0;
  309.     Diagram__ClientToScreen2(rect);
  310.     DIAGRAMCELL* pC;
  311.     for(nPos = 0; nPos < cell->nSizeDependents; nPos++){
  312.       pC = Diagram__GetCell(cell->pDependents[nPos]);   
  313.       if(pC->dwFlags & 0x00000010L && pC->nBreakA == nIDCell && (pC->dwFlags & 0x00001000L || pC->dwFlags & 0x00000800L)){
  314.           if(bDraw){FillSolidRect2(rect.left+4,rect.top+4,rect.right-2,rect.bottom-2,5);
  315.                                         Draw3dRect2(rect.left+4,rect.top+4,rect.right-2,rect.bottom-2,4,4);
  316.                     }
  317.                   InflateRect(&rect,0,0,-6,-6);
  318.           nState=1; // draw as
  319.                   
  320.           break;
  321.                         
  322.           }
  323.     }
  324.  
  325.     nPlusY = 0;
  326.     string ToRender;
  327.     char FontType=0;
  328.     if(nType < 4){ // 2/*TYPE_CLASS_FULL*/ ||  TYPE_CLASS_ONLY || 3/*TYPE_CLASS_OBJECT*/
  329.                 
  330.                 if(bDraw){FillSolidRect2(rect.left+1,rect.top+1,rect.right-2,rect.bottom-2,5);
  331.                     Draw3dRect2(rect.left,rect.top,rect.right-2,rect.bottom-2,4,4);
  332.                 }
  333.                    
  334.                 
  335.                 SIZE extent;
  336.                                 long bAbstract = dwFlags & 0x00000100L/*TYPE_OA_ABSTRACT*/;
  337.                 GetTextExtent(cell->ClassName,extent,FONT_ARIAL_BOLD_10);
  338.                                 nPlusX=0;
  339.                 if(extent.x > Diagram__MakeCellWidth(nIDCell)) nPlusX= 20+extent.x;
  340.                 else if(extent.x < Diagram__MakeCellWidth(nIDCell)){
  341.                          nPlusX =  20+(extent.x < 100 ? 100: extent.x);
  342.  
  343.                 if(dwFlags & 0x00000040L/*TYPE_OA_UTILITY*/)ToRender+="½utility╗ ";
  344.                 if(dwFlags & 0x00000080L/*TYPE_OA_IMPLEMENT*/)ToRender+="½implement╗ ";
  345.                 if(dwFlags & 0x00000020L/*TYPE_OA_INTERFACE*/)ToRender+="½interface╗ ";
  346.                 if(dwFlags & 0x00000200L/*TYPE_OA_BIND*/)ToRender+="½bind╗ ";
  347.                 ToRender+=cell->strExStereotypes;
  348.                 if(ToRender != ""){ToRender=trim(ToRender);
  349.                     if(bDraw)DrawText(ToRender,&rect,4,5,0x00000001/*DT_CENTER*/,FONT_TAHOMA_BOLD_8);
  350.                     GetTextExtent(ToRender,extent,FONT_TAHOMA_BOLD_8);
  351.                     if(extent.x+15 > nPlusX)nPlusX=extent.x+15;
  352.                     nPlusY += 10;
  353.                 }
  354.  
  355.                 }
  356.                 RECT ClassText;
  357.                 SetRect(&ClassText,rect.left-2,rect.top+nPlusY+6,rect.right-2,rect.bottom);
  358.                 ToRender = "";
  359.                                 if(bAbstract)FontType = 1; // italic
  360.                                                                 if(bDraw)DrawText(cell->ClassName,&ClassText,4,5,0x00000001/*DT_CENTER*/|((nType == 3/*TYPE_CLASS_OBJECT*/)?0x00000020/*DT_UNDERLINE*/:0),((FontType == 1)?FONT_ARIAL_BOLD_ITALIC_10:FONT_ARIAL_BOLD_10));
  361.  
  362.                                 cell->nBreakA = ClassText.top;
  363.                 nPlusY+=18;
  364.  
  365.                                 if(bAbstract || cell->strExProperties != ""){
  366.                                         if(bAbstract){
  367.                                            ToRender = "{abstract}";
  368.                                         }
  369.                                     ToRender+=cell->strExProperties;
  370.                                         InflateRect(&ClassText,0,-17,0,+17);
  371.                                         if(bDraw)DrawText(trim(ToRender),&ClassText,4,5,0x00000001/*DT_CENTER*/,FONT_TAHOMA_BOLD_8);
  372.                                         GetTextExtent(ToRender,extent,FONT_TAHOMA_BOLD_8);
  373.                                         if(extent.x+15 > nPlusX) nPlusX=extent.x+15;
  374.  
  375.                     nPlusY += 23;
  376.  
  377.                 }
  378.  
  379. //                      if(dwFlags & TYPE_OA_ABSTRACT){
  380. //                   if(bDraw)TextOut(rect.left+((rect.right-rect.left)-extent.x)/2,rect.top+nPlusY,cell->ClassName,4,5,FONT_ARIAL_BOLD_10);
  381. //                }
  382.                 if(nPlusY < 34)nPlusY=34;
  383.                 int nNoUse = 0;
  384.                 if(nType == 2/*TYPE_CLASS_FULL*/){
  385.                            int fgo;
  386.                            if(bDraw)LineFromTo2(rect.left,rect.top+nPlusY,rect.right-1,rect.top+nPlusY,4); // first divider
  387.                                                    cell->nBreakB =rect.top+nPlusY;
  388.                                                    if(cell->nSizeVariable == 0)nPlusY+=20;
  389.                            else {
  390.                                   nPlusY+=4;
  391.  
  392.                                   for(fgo=0;fgo < cell->nSizeVariable;fgo++){
  393.                                           Diagram__DrawOA(((CLASSITEM*)(cell->pVariable))[fgo].strText,((CLASSITEM*)(cell->pVariable))[fgo].nType,rect.left+5,rect.top+nPlusY,bDraw,nNoUse);
  394.                                           if(!bDraw && nPlusX < nNoUse)nPlusX = nNoUse;
  395.                                           nPlusY+= 13;
  396.  
  397.                                   }
  398.                                   nPlusY+=4;
  399.                            }
  400.                            if(bDraw)LineFromTo2(rect.left,rect.top+nPlusY,rect.right-1,rect.top+nPlusY,4); // second divider
  401.                                                    cell->nBreakC =rect.top+nPlusY;
  402.                            if(cell->nSizeOperation == 0)nPlusY+=20;
  403.                            else {
  404.                                   nPlusY+=4;
  405.                                   for(fgo=0;fgo < cell->nSizeOperation;fgo++){
  406.                                           Diagram__DrawOA(((CLASSITEM*)(cell->pOperation))[fgo].strText,((CLASSITEM*)(cell->pOperation))[fgo].nType,rect.left+5,rect.top+nPlusY,bDraw,nNoUse );
  407.                                           if(!bDraw && nPlusX < nNoUse)nPlusX = nNoUse;
  408.                                           nPlusY+= 13;
  409.  
  410.                                   }
  411.                                   nPlusY+=4;
  412.                            }
  413.  
  414.  
  415.  
  416.                 }
  417.         }
  418.         else {
  419.                 if(nType == 5/*TYPE_CLASS_IMG*/){
  420.                    if(bDraw){
  421.                    GrNaƒtiBMP(rect.left,rect.top,cell->ClassName,0,0,-1,-1,0);
  422.                    Draw3dRect2(rect.left,rect.top,rect.right-2,rect.bottom-2,0,3);
  423.                    }
  424.                 }
  425.                 else if(nType  == 4/*TYPE_CLASS_DEPENDENT*/){
  426.                                GrNastavBarvuPop²edí((bFocus)?6:4);
  427.                                Diagram__DrawDependent(rect.left,rect.top,rect.right,rect.bottom,0,dwFlags,nIDCell);
  428.  
  429.                 }
  430.  
  431.  
  432.  
  433.         }
  434.          if(nType  != 4/*TYPE_CLASS_DEPENDENT*/){
  435.     
  436.                  if(nState == 1){
  437.                     InflateRect(&rect,-4,-4,6,6);
  438.                         nPlusY+=6;nPlusX+=6;
  439.                         
  440.                  }
  441.      if(bDraw){
  442.                 char color = (bFocus)?6:7 /* BLUE*/;
  443.             LineFromTo2(rect.left+3,rect.bottom-1,rect.right,rect.bottom-1,color);
  444.         LineFromTo2(rect.left+3,rect.bottom,rect.right,rect.bottom,color);
  445.         LineFromTo2(rect.right,rect.top+3,rect.right,rect.bottom,color);
  446.         LineFromTo2(rect.right-1,rect.top+3,rect.right-1,rect.bottom,color);
  447.         }
  448.                 nPlusX+=2;
  449.                 nPlusY+=4;
  450.        
  451.         }
  452.  
  453.     if(bDraw)ShowMouse();
  454.  
  455. }
  456. void Diagram__DrawCellEx(int nID){
  457.   int x,y;
  458.   Diagram__DrawCell(nID,1,x,y);
  459. }
  460.  
  461. //DIAGRAMCELL* Diagram__GetCell(unsigned nId){
  462. //  return &m_DiagramCells[nId];
  463. //} /
  464.  
  465. void Diagram__SetInterFocus( int nID ){
  466.     int id = m_nInterCellFocus;
  467.     if(id == nID)return;
  468.     m_nInterCellFocus = nID;
  469.     if(id != -1)SendMessage(2 /* IDC_DIAGRAM */,101/*DIA_KILLFOCUS*/,id,-1);
  470.     if(nID != -1)SendMessage(2 /* IDC_DIAGRAM */,102/*DIA_SETFOCUS*/,nID,-1);
  471.  
  472. }
  473.  
  474. void Diagram__WCCopy(){
  475.    int i = m_nInterCellFocus;
  476.    if( i == -1)return; // nothing to move to ex. memory
  477.    // this command I cannot use because I copy only memory space of m_DiagramCells[?],
  478.    // but some datas is store outside this structure. I have to copy some variable to
  479.    // m_MEMORY_CELL and create new space for operations and variables
  480.    // memcpy(&m_MEMORY_CELL,&m_DiagramCells[i],sizeof(DIAGRAMCELL));
  481.    //
  482.    DIAGRAMCELL* pCell = &m_DiagramCells[i];
  483.    m_MEMORY_CELL.ClassName = pCell->ClassName;
  484.    m_MEMORY_CELL.dwFlags = pCell->dwFlags;
  485.    m_MEMORY_CELL.nType = pCell->nType;
  486.    CopyRect(&m_MEMORY_CELL.Rect,&pCell->Rect);
  487.    int d;
  488.    //GrNastavPozici(0,0);GrPiτⁿet╪zec("XXX");Wait();
  489.    CLASSITEM * pO,*pM;
  490.    if(pCell->nSizeOperation!=0){
  491.         m_MEMORY_CELL.pOperation=ClassItemInit(m_MEMORY_CELL.pOperation,m_MEMORY_CELL.nSizeOperation, pCell->nSizeOperation);
  492.                         for(d=0; d < pCell->nSizeOperation; d++){
  493.                                          pO = &((CLASSITEM*)pCell->pOperation)[d];
  494.                                          pM = &((CLASSITEM*)m_MEMORY_CELL.pOperation)[d];
  495.                      pM->strText = pO->strText;
  496.                      pM->nType  = pO->nType ;
  497. //                     GrPiτD¼íslo(d,-1,2);GrPiτⁿet╪zec((((CLASSITEM*)m_MEMORY_CELL.pOperation)[d]).strText );
  498.                 }
  499.  
  500.    }
  501.    else if(m_MEMORY_CELL.nSizeOperation != 0)
  502.             m_MEMORY_CELL.pOperation=ClassItemInit(m_MEMORY_CELL.pOperation,m_MEMORY_CELL.nSizeOperation,0);
  503.  
  504.    if(pCell->nSizeVariable!=0){
  505.         m_MEMORY_CELL.pVariable=ClassItemInit(m_MEMORY_CELL.pVariable,m_MEMORY_CELL.nSizeVariable, pCell->nSizeVariable);
  506.                 for(d=0; d < pCell->nSizeVariable; d++){
  507.                                          pO = &((CLASSITEM*)pCell->pVariable)[d];
  508.                                          pM = &((CLASSITEM*)m_MEMORY_CELL.pVariable)[d];
  509.                      pM->strText = pO->strText;
  510.                      pM->nType  = pO->nType ;
  511.                 }
  512.  
  513.    }
  514.    else if(m_MEMORY_CELL.nSizeVariable  != 0)
  515.                 m_MEMORY_CELL.pVariable=ClassItemInit(m_MEMORY_CELL.pVariable,m_MEMORY_CELL.nSizeVariable, 0);
  516.  
  517.  
  518. }
  519. unsigned Diagram__CreateCell(int x, int y, unsigned nType );
  520.  
  521. void Diagram__WCPaste(){
  522.     int id = Diagram__CreateCell(0,0,0);
  523.     //memcpy(&m_DiagramCells[id],&m_MEMORY_CELL,sizeof(DIAGRAMCELL));
  524.     DIAGRAMCELL * pCell = &m_DiagramCells[id];
  525.         SetRect(&pCell->Rect,0,0,(m_MEMORY_CELL.Rect.right - m_MEMORY_CELL.Rect.left),(m_MEMORY_CELL.Rect.bottom - m_MEMORY_CELL.Rect.top));
  526.     pCell->nType = m_MEMORY_CELL.nType;
  527.     pCell->ClassName = m_MEMORY_CELL.ClassName;
  528.     pCell->dwFlags = m_MEMORY_CELL.dwFlags;
  529.     int i;
  530.  
  531.         for(i=0;i < m_MEMORY_CELL.nSizeOperation; i++) {
  532.  
  533.                 if(m_MEMORY_CELL.nType < 3 ){
  534.                         Diagram__AddOperation(id,((CLASSITEM*)m_MEMORY_CELL.pOperation)[i].strText,((CLASSITEM*)m_MEMORY_CELL.pOperation)[i].nType);
  535.                 }
  536.         }
  537.         for(i=0;i < m_MEMORY_CELL.nSizeVariable; i++) {
  538.                 if(m_MEMORY_CELL.nType < 3){
  539.                         Diagram__AddVariable(id,((CLASSITEM*)m_MEMORY_CELL.pVariable)[i].strText,((CLASSITEM*)m_MEMORY_CELL.pVariable)[i].nType);
  540.                 }
  541.         }
  542.         Diagram__SetInterFocus(id);
  543. }
  544. void Diagram__OnDrawClipRect( int x,int y, int x2, int y2 );
  545.  
  546. void Diagram__WCDelete(){
  547.     int i = m_nInterCellFocus;
  548.     if( i == -1)return; // nothing to move to ex. memory
  549.         RECT rc;
  550.                 int xi =i;
  551.         CopyRect(&rc,&m_DiagramCells[i].Rect);
  552.         Diagram__DestroyCell(i);
  553.         // delete cell from
  554.          // a) m_DiagramCells
  555.              int nDep;
  556.              if(i < m_nm_DiagramCellsSize-1) {// cell cannot be last !
  557.                                 for(; xi < m_nm_DiagramCellsSize-1;xi++){
  558.                                       memmove(&m_DiagramCells[xi],&m_DiagramCells[xi+1],sizeof(DIAGRAMCELL));
  559.                                 }
  560.              }
  561.                          int a;
  562.  
  563.             for(a = 0; a < m_nm_DiagramCellsSize; a++){
  564.                 DIAGRAMCELL * pCell = &m_DiagramCells[a];
  565.                 if(pCell->nType == 4/*TYPE_CLASS_DEPENDENT*/){
  566.                      if(pCell->nBreakA == i)pCell->nBreakA=-1;
  567.                      if(pCell->nBreakB == i)pCell->nBreakB=-1;
  568.                      if(pCell->nBreakA > i)pCell->nBreakA--;
  569.                      if(pCell->nBreakB > i)pCell->nBreakB--;
  570.  
  571.                 }
  572.                 else {
  573.                      int an=0;
  574.                      for(;an < pCell->nSizeDependents;an++){
  575.                          if(pCell->pDependents[an] > i){
  576.                              pCell->pDependents[an] -=1;
  577.  
  578.                                                  }
  579.                                          }
  580.                                 }
  581.  
  582.            }
  583.  
  584.  
  585.      // b) ZOrder indexer
  586.                // where is i control in array ?
  587.                     int ix;
  588.                     int movefrom = -1;
  589.                     for(ix=0;ix<m_nm_DiagramCellsSize;ix++){
  590.                                 if(m_DiagramZOrder[ix] == xi){ // yes, it is
  591.                                         movefrom =ix;break;
  592.                                 }
  593.  
  594.                         }
  595.                         if(movefrom != -1){  // yes, i is in array.
  596.                             // Note : Another case wont be, but this is better/nice :-)
  597.                                                         for(movefrom; movefrom < m_nm_DiagramCellsSize-1;movefrom++){
  598.                                                       memcpy(&m_DiagramZOrder[movefrom],&m_DiagramZOrder[movefrom+1],sizeof(int));
  599.                                                         }
  600.  
  601.                         }
  602.  
  603.  
  604.      // c) realloc memory space :
  605.                   m_nm_DiagramCellsSize--;
  606.                   m_DiagramCells = (DIAGRAMCELL*)realloc(m_DiagramCells,sizeof(DIAGRAMCELL)*(m_nm_DiagramCellsSize));
  607.                   m_DiagramZOrder = (int*)realloc(m_DiagramZOrder,sizeof(int)*(m_nm_DiagramCellsSize));
  608.                   m_nInterCellFocus = -1;
  609.                                   Diagram__OnDrawClipRect(rc.left,rc.top,rc.right,rc.bottom);
  610. }
  611. void Diagram__HideDragingRect(){
  612.         int x,y;
  613.         x=m_LastEvent.x-m_DiaIncrease.left;y=m_LastEvent.y-m_DiaIncrease.top;
  614.         HideMouse();
  615.         GrNastavBarvuPop²edí(1);
  616.         GrNastavLinku(42/*8|2|0x20*/,0xAAAA);
  617.         GrKresliObdélník(x+1,y+1,
  618.             x-1+Diagram__MakeCellWidth(m_nInterCellFocus),
  619.             y -1+Diagram__MakeCellHeight(m_nInterCellFocus));
  620.         GrNastavLinku(21/*4|1|0x10*/,0xFFFF);
  621.         ShowMouse();
  622. }
  623. void SetCursor(int nID){
  624.         AnimP²edm╪tZruτ(MouseObject);
  625.         MouseObject=AnimP²edm╪tVytvo²(nID,1,0,1);
  626.         //      SetPoint(&MOUSEOFFSET,10,10);
  627.                 ShowMouse();
  628. }
  629. void Diagram__HideAddingDependent(){
  630.         HideMouse();
  631.                 
  632.     if(m_LAST_POINTS.left >= 0)
  633.          Diagram__DrawDependent(m_LAST_POINTS.left,m_LAST_POINTS.top,m_LAST_POINTS.right,m_LAST_POINTS.bottom,1,1/*TYPE_DEPENDENT_INHERITANCE*/,-1);
  634.     m_DIAGRAM_ADDINGDEPENDENT =0;
  635.         SetCursor(85);
  636.         
  637.   
  638.  
  639.     
  640. }
  641. void Button__SetCheck(unsigned hWnd, long bCheck );
  642. void AddDialog__GetName(string strText,int &nPos){
  643.     SetWindowText(26/*IDC_ADD_NAME*/,trim(StrKopie(strText,0,nPos)));
  644. }
  645. void AddDialog__AddParaByString(string str){
  646.   int x,i = StrPozicePod²et╪zce(str,0,":"),g;
  647.   if(StrKopie(str,0,5)=="inout"){Button__SetCheck(24/*IDC_PARA_INOUT*/,1);x=6;g=24;}
  648.   else if ((StrKopie(str,0,3)=="out")){Button__SetCheck(25/*IDC_PARA_OUT*/,1);x=4;g=25;}
  649.   else if ((StrKopie(str,0,2)=="in")){Button__SetCheck(27/*IDC_PARA_IN*/,1);x=3;g=27;}
  650.   else {Button__SetCheck(27/*IDC_PARA_IN*/,1);x=0;g=27;}
  651.   Invalidate(g);
  652.   SetWindowText(20/*IDC_PARA_NAME*/,trim(StrKopie(str,x,i-x)));
  653.   Invalidate(20/*IDC_PARA_NAME*/);
  654.   SetWindowText(19/*IDC_PARA_TYPE*/,trim(StrKopie(str,i+1,-1)));
  655.   Invalidate(19/*IDC_PARA_TYPE*/);
  656.  
  657. }
  658. void AddDialog__ParserString( string strText ){
  659.    int nPos;
  660.    int nLen = StrDélka(strText);
  661.    char nName = 0;
  662.    ListBox__DeleteAll(21/*IDC_PARA_LIST*/);
  663.    for(nPos=0;nPos < nLen;nPos++){
  664.        if(strText[nPos]=='('){
  665.                   AddDialog__GetName(strText,nPos);
  666.           nName =1;
  667.  
  668.           unsigned end = StrPozicePod²et╪zce(strText,0,")");
  669.           if(end != 0xffff){
  670.               int nX,id=0;
  671.               string strx;
  672.               for(nPos++;nPos < end && strText[nPos] != ')';nPos++){
  673.                   int nX=nPos;
  674.                   for(;nPos < nLen && strText[nPos] != ')' && strText[nPos] != ',';nPos++){}
  675.                   strx = trim(StrKopie(strText,nX,nPos-nX));
  676.                   if(strx != ""){
  677.                      ListBox__AddItem(21/*IDC_PARA_LIST*/,id,strx);id++;
  678.                   }
  679.               }
  680.           }
  681.        }
  682.        if(strText[nPos]==':'){  // read type
  683.            if(nName==0)AddDialog__GetName(strText,nPos);
  684.            SetWindowText(12/*IDC_ADD_TYPENAME*/,trim(StrKopie(strText,nPos+1,-1)));
  685.        }
  686.    }
  687.  
  688.  
  689. }
  690.  
  691. char Diagram__HitTestCell(int nID, int& yDest){
  692.         if(nID < 0)return 0;
  693.         DIAGRAMCELL* pCell = Diagram__GetCell(nID);
  694.         int nBreakC=pCell->nBreakC+4;
  695.         int nBreakB=pCell->nBreakB+4;
  696.         if(nBreakB > yDest )
  697.            return 0;
  698.         if(nBreakB < yDest && nBreakC-8 > yDest){
  699.             if(pCell->nSizeVariable == 0)
  700.                    return 0;
  701.             else {
  702.                    yDest = -((yDest-nBreakB)/13+1);
  703.                    return 1;
  704.             }
  705.         }
  706.         if(nBreakC < yDest && (nBreakC+pCell->nSizeOperation*13) > yDest){
  707.             if(pCell->nSizeOperation == 0)
  708.                    return 0;
  709.             else {
  710.                    yDest = (yDest-nBreakC)/13+1;
  711.                    return 1;
  712.            }
  713.         }
  714.         return 0;
  715. }
  716. void Button__GetCheckRange(int nPosStart,int nPosEnd,long& dwFlags);
  717. void Diagram__OnInsert(){
  718.        DestroyDialog();
  719.        string declare;
  720.        int nFocus = m_nInterCellFocus;
  721.        long nNewState=0;
  722.        DIAGRAMCELL* pCell = Diagram__GetFocusCell();
  723.        long lparam= GetWindow(10 /*IDC_ADDINGDIALOG*/)->lParam;
  724.        declare = AddDialog__CreateString();
  725.        Button__GetCheckRange(13,18,nNewState);
  726.        if(lparam > 0){
  727.           if(lparam == 1){
  728.              Diagram__AddOperation(nFocus,declare,nNewState);
  729.           }
  730.           else {
  731.               Diagram__AddVariable(nFocus,declare,nNewState);
  732.           }
  733.        }
  734.        else {
  735.           CLASSITEM* pData=0;
  736.           if(lparam == -1){
  737.               pData =&((CLASSITEM*)(pCell->pOperation))[m_MOUSEOVER_PTY-1];
  738.           }
  739.           else {
  740.               pData =&((CLASSITEM*)(pCell->pVariable))[-m_MOUSEOVER_PTY-1];
  741.           }
  742.           pData->strText = declare;
  743.           pData->nType =nNewState;
  744.       }
  745.       if(pCell->nType = 1/*TYPE_CLASS_ONLY*/)pCell->nType = 2/*TYPE_CLASS_FULL*/;
  746.       Diagram__RecalculateCellRect(nFocus,2);
  747.  
  748.  
  749. }
  750. // END OF FILE ...
  751. //
  752. //
  753. //
  754. //
  755. //
  756. //
  757. //
  758. //
  759. //
  760. //
  761. //
  762. ///////////////////////////////////////////////////////////////////////////
  763. ///////////////////////////////////////////////////////////////////////////
  764. ///////////////////////////////////////////////////////////////////////////