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.UI < prev    next >
Text File  |  2002-09-24  |  16KB  |  473 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //----------------------------------------------------------------------------//
  3. //-----project DESINGER, copyright 2002 Libor Bareτ-------------------------//
  4. //----------------------------------------------------------------------------//
  5. ////////////////////////////////////////////////////////////////////////////////
  6.  
  7.  
  8.  
  9.  
  10. // DEBUG!
  11. // hlavni promene pro funkci celeho systemu oken :
  12. int m_modalshow=0;
  13. unsigned m_ObjectWithFocus=0 /* DESKTOP */;
  14. DIAGRAMCELL m_MEMORY_CELL;
  15.  
  16.  
  17. unsigned m_pWndLastOver=-1;
  18. unsigned m_hWndCapturedObject = -1;
  19. char m_PopUpMenuFilter = 0;
  20. char m_bMouseMenuFirstTime = 0;
  21. char m_POPUPMENU_TOMENU = 0;
  22. char m_POPUPMENU_FROMMENU = 0;
  23. char m_DIAGRAM_DOCKING_DEPENDENT = 0;
  24. RECT m_LAST_POINTS;
  25. int m_ProtectedTimer[1/*IDTSIZE_TIMER*/];
  26. long m_ProtectedTimerTime[1/*IDTSIZE_TIMER*/];
  27. long m_ProtectedTimerCount[1/*IDTSIZE_TIMER*/];
  28.  
  29. char m_DIAGRAM_ADDINGDEPENDENT;
  30. POINT m_DIAGRAM_DEPENDENT_FROM;
  31. char m_DIAGRAM_ADDINGDEPENDENT_USEMOVING=0;
  32.  
  33. void CopyRect(RECT* lprcDst,/* const */ RECT* lprcSrc){
  34.    memcpy(lprcDst,lprcSrc,sizeof(RECT));
  35. }
  36. void LoadFont(string File,void& pArray){
  37.    long src=SouborOtev²i(File,0x01|0x200/*SouborP²ístupBinární*/);
  38.    Soubor¼tiBlok(src,&pArray,sizeof(char)*255);SouborZav²i(src);if(DOSChyba())m_LastedMessage=1;
  39. }
  40. //# define ShowMouse() ShowMouse()
  41. //# define HideMouse() HideMouse()
  42.  
  43. void HideMouse(){
  44. AnimP²edm╪tSchovej(MouseObject);
  45. }
  46.  
  47. //void ShowCursor(char bShow){
  48. //    if(bShow == 0)
  49. //      AnimP²edm╪tSchovej(MouseObject);
  50. //    else
  51. //         AnimP²edm╪tAnimuj(MouseObject,MouseEvent.X-10/*-MOUSEOFFSET.left*/,MouseEvent.Y/*-MOUSEOFFSET.top*/-10,-1);
  52. //
  53. //}
  54.  
  55. void SetZOrderControl(int nID){
  56.   // move array ...
  57.   if(m_ZOrderControlSize != 0 && m_ControlzOrderArray[0] == nID )return; // this control is jet topmost !
  58.   if(m_ZOrderControlSize != 0 ){
  59.      // is nID control in array ?
  60.      int i;
  61.      int movefrom = -1;
  62.      for(i=0;i<m_ZOrderControlSize;i++){
  63.          if(m_ControlzOrderArray[i] == nID){ // yes, it is
  64.            movefrom =i;break;
  65.         }
  66.  
  67.      }
  68.      if(movefrom == -1)movefrom = m_ZOrderControlSize;
  69.      memcpy(&m_ControlzOrderArray[1],&m_ControlzOrderArray[0],sizeof(char)*movefrom);
  70.  
  71.   }
  72.  
  73.   m_ControlzOrderArray[0]=nID;
  74.  
  75.  
  76.  
  77.  
  78. }
  79. void MyWndProc(unsigned hWnd,unsigned nMessage, long lParam, long wParam);
  80. void Diagram__WndProc( unsigned nMessage, long lParam, long wParam );
  81.  
  82.  
  83.  
  84. void SendMessage(unsigned dest, unsigned nMessage,long lParam, long wParam){
  85. // UPOZORNENI : Tato fuknce ma cetnost volani cca 1000x / 10 s !!!
  86.    if(dest == 2 /* IDC_DIAGRAM */){Diagram__WndProc(nMessage,lParam,wParam);return;}
  87.    MyWndProc(dest,nMessage,lParam,wParam);
  88.  
  89.  
  90.  
  91. }
  92. void STYLEMINUS(long &nStyle,long style){
  93.    if(nStyle & style)
  94.        nStyle^=style;
  95. }
  96.  
  97. void Invalidate(unsigned nID){
  98.         WND* pWnd  = GetWindow(nID);
  99. if(pWnd->dwStyle & 0x00020000L/*WS_VISIBLE*/){ // send 8/*WM_PAINT*/  only if control is visible in else case will be BUG !
  100.         SendMessage(nID,8/*WM_PAINT*/ ,-1,-1);
  101.         if(pWnd->nChildSize > 0){
  102.              int i=0;
  103.              for(;i < pWnd->nChildSize; i++)
  104.                   Invalidate(pWnd->pChild[i]->hWnd);
  105.         }
  106.     }
  107. }
  108.  
  109. unsigned SetFocus(unsigned hWndToSetFocus){
  110.    if(hWndToSetFocus==m_ObjectWithFocus)return m_ObjectWithFocus;
  111.    if(hWndToSetFocus == 3/*IDC_POPUPMENU*/)return 3/*IDC_POPUPMENU*/;
  112.    int tmp=m_ObjectWithFocus;
  113.    if(m_ObjectWithFocus != -1 && m_ObjectWithFocus != hWndToSetFocus){
  114.        STYLEMINUS(GetWindow(m_ObjectWithFocus)->dwStyle,0x00400000L);
  115.            if(GetWindow(tmp)->nType == 4/*DFC_BUTTON*/){
  116.                    Invalidate(tmp);
  117.            }
  118.        SendMessage(m_ObjectWithFocus,12/*WM_KILLFOCUS*/,hWndToSetFocus,-1);
  119.  
  120.    }
  121.    if(m_ObjectWithFocus != hWndToSetFocus){
  122.            GetWindow(hWndToSetFocus)->dwStyle|= 0x00400000L;
  123.            SendMessage(hWndToSetFocus,11/*WM_SETFOCUS*/,tmp,-1);
  124.    }
  125.    m_ObjectWithFocus = hWndToSetFocus;
  126.    return tmp;
  127. }
  128. RECT* GetWindowRect(unsigned nID){
  129.      return &m_ControlArray[nID].Rect;
  130. }
  131. int GetWindowWidth(unsigned hWnd){
  132.         return (GetWindowRect(hWnd)->right - GetWindowRect(hWnd)->left);
  133. }
  134. int GetWindowHeight(unsigned hWnd){
  135.         return (GetWindowRect(hWnd)->bottom - GetWindowRect(hWnd)->top);
  136. }
  137.  
  138. void MoveRect(RECT* rect,int x,int y, int x2, int y2){
  139.    // InflateRect(rect,-x,-y,x2,y2);
  140.     rect->left+=x;
  141.     rect->top+=y;
  142.     rect->right+=x2;
  143.     rect->bottom+=y2;
  144.  
  145. }
  146.  
  147. void SetParent(unsigned nParent, unsigned nControl){
  148.   WND * pWnd=GetWindow(nParent),*pControl=GetWindow(nControl);
  149.   pWnd->pChild = AddChildWindow(pWnd->pChild,pWnd->nChildSize,pWnd->nChildSize+1);
  150.   pWnd->pChild[pWnd->nChildSize-1] = pControl;
  151.   pControl->pParent = pWnd;
  152.   MoveRect(&pControl->Rect,4,23,4,23);
  153.  
  154. }
  155.  
  156.  
  157.  
  158. char PtInRect(int x, int y, RECT* rect){
  159.       if(rect->left <= x && rect->top <= y && rect->right >= x && rect->bottom >= y){
  160.         return 1;
  161.  
  162.       }
  163.        return 0;
  164.  
  165. }
  166.  
  167. void ShowMouse(){
  168.   AnimP²edm╪tAnimuj(MouseObject,MouseEvent.X-10/*-MOUSEOFFSET.left*/,MouseEvent.Y-10/*-MOUSEOFFSET.top*/,-1);
  169. }
  170. void AnimMouse(){
  171.  Myτ¼tiUdálost(MouseEvent);
  172.  if(UnderXP && NoXP){ // mouse error cathing ....
  173.   MouseEvent.X=(GrMaxX()/639.)*MouseEvent.X;
  174.   MouseEvent.Y=(GrMaxY()/199.)*MouseEvent.Y;
  175.  }
  176.  ShowMouse();
  177.  
  178. }
  179.  
  180. WND* GetWindow(unsigned nID){
  181.      return &m_ControlArray[nID];
  182. }
  183. void _CheckNewOverControl(){
  184.      if(m_pWndLastOver != -1){
  185.          STYLEMINUS(GetWindow(m_pWndLastOver)->dwStyle,0x00100000L/*WS_MOUSEOVER*/);
  186.          SendMessage(m_pWndLastOver,4/*WM_MOUSELEAVE*/,MouseEvent.X,MouseEvent.Y);
  187.          m_pWndLastOver = -1;
  188.      }
  189. }
  190. // KERNEL !!!!!!!!!!!!!
  191. // vnitrni API programu pro poslani zpravy programu ...
  192. void _SendMouseEventFor(unsigned i){
  193.    int MSG=0;
  194.    if(MouseEvent.Typ == 4/*MyτUdálostLevéTlNahoru*/){
  195.           MSG=7;
  196.    }
  197.    else if(MouseEvent.Typ == 2/*MyτUdálostLevéTlDolà*/){
  198.           MSG=1;
  199.    }
  200.    else if(MouseEvent.Typ == 8/*MyτUdálostPravéTlDolà*/){
  201.           MSG=2;
  202.    }
  203.    else if(MouseEvent.Typ == 16/*MyτUdálostPravéTlNahoru*/){
  204.           MSG=6;
  205.    }
  206.    else if (MouseEvent.Typ ==1/*MyτUdálostPohyb*/){
  207.           MSG=3;
  208.    }
  209.    if(MSG != 0 && MSG != 3)
  210.            SetFocus(i);
  211.    if(MSG !=0)   
  212.            SendMessage(i,MSG,MouseEvent.X,MouseEvent.Y);
  213.    return;
  214.  
  215. }
  216. void StopTrackingPopUpMenu();
  217. void KERNEL(){
  218.         m_keyIDKey = ¼tiKlávesuZFronty();
  219.                 if(m_keyIDKey & 0x3b00){SendMessage(0 /* DESKTOP */,9/* WM_COMMAND*/,205/*IDC_HELP_CONTENT*/,-1);}
  220.  
  221.        // timers ...
  222.        int tim;
  223.        for(tim = 0; tim < 1/*IDTSIZE_TIMER*/; tim++){
  224.           if(m_ProtectedTimer[tim] > 0){
  225.               if(m_ProtectedTimerTime[tim] < Systémov∞Tikot() ){
  226.                   m_ProtectedTimerTime[tim] = Systémov∞Tikot()+m_ProtectedTimer[tim];
  227.                    m_ProtectedTimerCount[tim]++;
  228.  
  229.                   SendMessage(0 /* DESKTOP */,13/* WM_TIMER */,tim,m_ProtectedTimerCount[tim]);
  230.  
  231.               }
  232.           }
  233.        }
  234.  #ifdef _DEBUG
  235.     #ifdef _MEMORY_PREVIEW
  236.        GrNastavPozici(0,GrMaxY()-10);
  237.        GrNastavBarvuPozadí(5);
  238.        GrNastavBarvuPop²edí(6);
  239.        GrPiτⁿet╪zec("MEMORY_FREE="+StrD¼íslo(HromadaVolnáPam╪£(),-1,0));
  240.     #endif
  241.     #ifdef _MOUSE_DEBUG
  242.        GrNastavPozici(GrMaxX()-200,GrMaxY()-10);
  243.        GrNastavBarvuPozadí(5);
  244.        GrNastavBarvuPop²edí(6);
  245.        GrPiτⁿet╪zec("MousePosition("+StrD¼íslo(MouseEvent.X,-1,0)+","+StrD¼íslo(MouseEvent.Y,-1,0)+");");
  246.     #endif
  247.  #endif
  248.        AnimMouse();
  249.        if(MouseEvent.X == 0 && MouseEvent.Y == 0 && MouseEvent.Tlaƒítka == 1){
  250.           HideMouse();
  251.           GrUloºBMP(0,0,-1,-1,"*\\designer.dir\\common\\prev.bmp");
  252.           ShowMouse();
  253.  
  254.        }
  255.  
  256.  
  257.      if(m_hWndCapturedObject == -1){
  258.              // pomoci [void] SetCapture se muze upravit smycka posilani zprav tak,
  259.              // ze veskere zpravy poputuji oknu, ktery tuto udalost nastavil.
  260.              STARTPROCES :
  261.              int i,OA;
  262.              for(i=0;i<m_nm_ControlArraySize;i++){
  263.                                   OA = m_ControlzOrderArray[i];
  264.                   if(!(GetWindow(OA)->dwStyle & 0x00080000L/* WS_DISABLE*/) && GetWindow(OA)->dwStyle & 0x00020000L/* WS_VISIBLE */ && PtInRect(MouseEvent.X,MouseEvent.Y,GetWindowRect(OA))){
  265.                     if(m_modalshow  != 0 && GetWindow(OA)->pParent->hWnd == m_modalshow || m_modalshow  == 0){
  266.  
  267.  
  268.                       if(m_pWndLastOver != OA){
  269.                          _CheckNewOverControl();
  270.                          m_pWndLastOver = OA;
  271.                          GetWindow(OA)->dwStyle |= 0x00100000L/*WS_MOUSEOVER*/;
  272.                          SendMessage(OA,5/* WM_MOUSEENTER*/,MouseEvent.X,MouseEvent.Y);
  273.                       }
  274.                       _SendMouseEventFor(OA);
  275.                       goto keyboards;
  276.                     }
  277.                   }
  278.              }
  279.              if(MouseEvent.Tlaƒítka == 1 || MouseEvent.Tlaƒítka == 2){
  280.                  SetFocus(0);
  281.  
  282.              }
  283.              _CheckNewOverControl();
  284.  
  285.           }
  286.           else {
  287.  
  288.               if(m_pWndLastOver != m_hWndCapturedObject){
  289.  
  290.                    _CheckNewOverControl();
  291.                    m_pWndLastOver = m_hWndCapturedObject;
  292.               }
  293.               if(PtInRect(MouseEvent.X,MouseEvent.Y,GetWindowRect(m_hWndCapturedObject))){
  294.  
  295.                                  if(!(GetWindow(m_hWndCapturedObject)->dwStyle & 0x00100000L/*WS_MOUSEOVER*/)){
  296.                                  GetWindow(m_pWndLastOver)->dwStyle |= 0x00100000L/*WS_MOUSEOVER*/;
  297.                                          SendMessage(m_hWndCapturedObject,5/* WM_MOUSEENTER*/,MouseEvent.X,MouseEvent.Y);
  298.                                  }
  299.  
  300.  
  301.               }
  302.               else {
  303.  
  304.  
  305.                                  if(GetWindow(m_hWndCapturedObject)->dwStyle & 0x00100000L/*WS_MOUSEOVER*/){
  306.                                          STYLEMINUS(GetWindow(m_pWndLastOver)->dwStyle,0x00100000L/*WS_MOUSEOVER*/);
  307.                                          SendMessage(m_hWndCapturedObject,4/*WM_MOUSELEAVE*/,MouseEvent.X,MouseEvent.Y);
  308.                                  }
  309.                  if(m_hWndCapturedObject == 1 /* IDC_MENU */ || m_hWndCapturedObject == 3/*IDC_POPUPMENU*/){
  310.                       int gg = 0;
  311.                       if(m_PopUpMenuFilter == 1){
  312.                          if(m_POPUPMENU_TOMENU==1 ){ gg=PtInRect(MouseEvent.X,MouseEvent.Y,GetWindowRect(1 /* IDC_MENU */));if(gg){
  313.  
  314.                               SendMessage(1 /* IDC_MENU */,3/* WM_MOUSEMOVE*/,MouseEvent.X,MouseEvent.Y);
  315.                             }
  316.                             }
  317.                       }
  318.                       if((m_bMouseMenuFirstTime == 0 && (MouseEvent.Tlaƒítka & 1 || MouseEvent.Tlaƒítka & 2) && !gg)){
  319.                              StopTrackingPopUpMenu();
  320.                              m_pWndLastOver = -1;
  321.                              goto STARTPROCES;
  322.                       }
  323.                  }
  324.               }
  325.  
  326.               _SendMouseEventFor(m_hWndCapturedObject);
  327.  
  328.  
  329.           }
  330.  
  331.      keyboards:
  332.         if(m_keyIDKey != 0){
  333.  
  334.  
  335.              // note : KlUp and so on is contained in 0x??00 !!
  336.              if((char)m_keyIDKey != 0){  // only for some keys
  337.                          char id = m_keyIDKey;
  338.                          SgpAsciiToWinChar(id); // decode charset to oficial WindowsCharset
  339.                          m_keyIDKey = id;
  340.              }
  341.              SendMessage(m_ObjectWithFocus,14 /* WM_CHAR*/,m_keyIDKey,-1);
  342.  
  343.         }
  344.  
  345. }
  346. void ShowWindow(unsigned hWnd,int nCmdShow){
  347.         if(nCmdShow ){ GetWindow(hWnd)->dwStyle |= 0x00020000L/* WS_VISIBLE */;
  348.             SendMessage(hWnd,16 /* WM_SHOWWINDOW */,1,-1);
  349.          }
  350.     else {
  351.                   STYLEMINUS(GetWindow(hWnd)->dwStyle,0x00020000L/* WS_VISIBLE */);
  352.                   SendMessage(hWnd,16 /* WM_SHOWWINDOW */,0,-1);
  353.  
  354.                   
  355.          }
  356. }
  357. #define GetWindowText(x) m_ControlArray[x].szText
  358. //string GetWindowText(unsigned nID){
  359. //     return m_ControlArray[nID].szText;
  360. //
  361. //}
  362. // nastavuje ctverec pro okno
  363. void SetRect(RECT* dest,int x, int y, int x2, int y2){
  364.    dest->left = x;
  365.    dest->top=y;
  366.    dest->right=x2;
  367.    dest->bottom=y2;
  368.  
  369. }
  370. // nastavuje ctverec pro okno
  371. void SetWindowRect2(unsigned nID,int x, int y, int x2, int y2){
  372.    SetRect(&m_ControlArray[nID].Rect,x,y,x2,y2);
  373.  
  374.  
  375. }
  376. void MoveWindow(unsigned hWnd, int x, int y){
  377.         WND* pWnd = GetWindow(hWnd);
  378.         WND* pChild;
  379.         RECT Rect;CopyRect(&Rect,&pWnd->Rect);
  380.         if(pWnd->nChildSize > 0){
  381.              int i=0;
  382.              for(;i < pWnd->nChildSize; i++){pChild=GetWindow(hWnd)->pChild[i];
  383.                                                                   MoveWindow(pChild->hWnd,pChild->Rect.left+(x-Rect.left),
  384.                                   pChild->Rect.top+(y-Rect.top)
  385.                                   );
  386.                          }
  387.         }
  388.     SetWindowRect2(hWnd,x,y,x+Rect.right - Rect.left ,Rect.bottom-Rect.top+y);
  389.  
  390. }
  391. void InflateRect(RECT* dest, int x,int y, int x2, int y2){
  392.    dest->left-=x;
  393.    dest->top-=y;
  394.    dest->right+=x2;
  395.    dest->bottom+=y2;
  396.  
  397. }
  398.  
  399. // nastavuje text okna
  400. void SetWindowText(unsigned nID,string szText){
  401.    m_ControlArray[nID].szText = szText;
  402.    SendMessage(nID,17 /* WM_SETTEXT */,-1,-1);
  403. }
  404. void ResetControl(unsigned hParent){
  405.         int i=0;
  406.                 WND* pChild;
  407.         for(;i < GetWindow(hParent)->nChildSize; i++){
  408.                 pChild = GetWindow(hParent)->pChild[i];
  409.                 if(pChild->nType != 13)STYLEMINUS(pChild->dwStyle,0x00080000L/*DFCS_PUSHED*/);
  410.                 STYLEMINUS(pChild->dwStyle,0x0000200L/*DFCS_PUSHED*/);
  411.                 if(pChild->nType == 7 /*EDIT*/)SetWindowText(pChild->hWnd,"");
  412.     }
  413.  
  414. }
  415. void DestroyDialog(){
  416.     if(m_modalshow ==0 )return;
  417.     ShowWindow(m_modalshow,0);
  418.     m_modalshow =0;
  419.     
  420. }
  421. void ShowDialog(unsigned hWnd){
  422.    if(m_modalshow > 0)DestroyDialog();
  423.    int x =(GrMaxX()-GetWindowWidth(hWnd))/2;
  424.    int y = (GrMaxY()-GetWindowHeight(hWnd))/2;
  425.    MoveWindow(hWnd,x,y);
  426.    m_modalshow = hWnd;
  427.    ShowWindow(hWnd,1);
  428.  
  429. }
  430.  
  431. // pripoji mysi udalosti k oknu
  432. #define SetCapture(x) m_hWndCapturedObject = x;
  433.  
  434. // uvolnit mys
  435. #define ReleaseCapture() m_hWndCapturedObject = -1
  436.  
  437. int MenuHitTest(unsigned nID){
  438.        switch(nID){
  439.           case 1 /* IDC_MENU */:
  440.              RECT rect,*rc=GetWindowRect(nID);
  441.              CopyRect(&rect,rc);
  442.              rect.right = rect.left;
  443.              int i;
  444.              for(i = 0; i < 5;i++){
  445.                  rect.right=rc->left+IDC_MENU_RECT[i];
  446.                  if(PtInRect(MouseEvent.X,MouseEvent.Y,&rect))
  447.                      return i;
  448.                  rect.left=rc->left+IDC_MENU_RECT[i];
  449.              }
  450.              return -1;
  451.  
  452.        }
  453.  
  454.   return -1;
  455. }
  456. void EnableWindow(unsigned hWnd, char bEnable){
  457.    WND* pWnd =  GetWindow(hWnd);
  458.    long s = (pWnd->dwStyle & 0x00080000L/* WS_DISABLE*/);
  459.    if((!s && bEnable)||(s && !bEnable))return;
  460.    if(bEnable==1){
  461.        STYLEMINUS(pWnd->dwStyle,0x00080000L);
  462.    }
  463.    else{
  464.        pWnd->dwStyle|= 0x00080000L;
  465.    }
  466.  
  467.    Invalidate(hWnd);
  468. }
  469. // KONEC SOUB
  470. ///////////////////////////////////////////////////////////////////////////
  471. ///////////////////////////////////////////////////////////////////////////
  472. ///////////////////////////////////////////////////////////////////////////
  473.