home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / 3DTOSHI2.ZIP / mpgui / source / guiwin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  30.7 KB  |  1,150 lines

  1.  
  2. // guiwin.cpp
  3. //
  4. // Copyright (c) 1995 by Toshiaki Tsuji, all rights reserved.
  5.  
  6. #include "stdgfx.h"
  7. #include "guiwin.h"
  8.  
  9. BOOLEAN ExitApp = FALSE;
  10.  
  11. APIRESULT APIPROC GUIWinProc ( HWINDOW hWindow, MESSAGE iMessage,
  12.                                PARAM1 Param1, PARAM2 Param2 );
  13. APIRESULT APIPROC ClientProc ( HWINDOW hWindow, MESSAGE iMessage,
  14.                                PARAM1 Param1, PARAM2 Param2 );
  15. #if defined (__FORUNIX__)
  16.   #if defined (__FORMOTIF__)
  17.     VOID GUIWinXWinProc ( Widget W, XtPointer ClientData, 
  18.                           XEvent *EventPtr ); 
  19.   #endif
  20. #endif
  21.  
  22. struct WINDOWNODE
  23.   {
  24.     GUIWINDOW *WinPtr;
  25.     HWINDOW Handle;
  26.     WINDOWNODE *Next;
  27.  
  28.     WINDOWNODE () { WinPtr = NULL; Next = NULL; };
  29.     ~WINDOWNODE ()
  30.       {
  31.         if (WinPtr!=NULL)
  32.           delete WinPtr;
  33.         if (Next!=NULL)
  34.           delete Next;
  35.         WinPtr = NULL;
  36.         Next = NULL;
  37.       } // End of Destructor for WINDOWNODE
  38.   }; // End of WINDOWNODE
  39.  
  40. WINDOWNODE *WinHashTable[256];
  41. WINDOWNODE *RemovedList;
  42.  
  43. VOID AddWindow ( GUIWINDOW *NewWin, HWINDOW Handle )
  44.   {
  45.     LONG Index;
  46.     WINDOWNODE *NodePtr;
  47.     WINDOWNODE *NewNode;
  48.  
  49.     NewNode = new WINDOWNODE ();
  50.     NewNode->WinPtr = NewWin;
  51.     NewNode->Handle = Handle;
  52.  
  53.     Index = (LONG)Handle & 255;
  54.     NodePtr = WinHashTable[Index];
  55.     if (NodePtr==NULL)
  56.       WinHashTable[Index] = NewNode;
  57.     else
  58.       {
  59.         while (NodePtr->Next!=NULL)
  60.           NodePtr = NodePtr->Next;
  61.         NodePtr->Next = NewNode;
  62.       } // End else
  63.   } // End of AddWindow
  64.  
  65. VOID DiscardWindow ( HWINDOW hWindow )
  66.   {
  67.     LONG Index;
  68.     WINDOWNODE *NodePtr;
  69.     WINDOWNODE *PrevPtr;
  70.     WINDOWNODE *NextPtr;
  71.     WINDOWNODE *RemovePtr;
  72.     GUIWINDOW  *WinPtr;
  73.  
  74.     Index = (LONG)hWindow & 255;
  75.     NodePtr = WinHashTable[Index];
  76.     PrevPtr = NULL;
  77.     while (NodePtr!=NULL)
  78.       {
  79.         NextPtr = NodePtr->Next;
  80.         WinPtr = NodePtr->WinPtr;
  81.         if ((WinPtr!=NULL)&&(NodePtr->Handle==hWindow))
  82.           {
  83.             if (PrevPtr!=NULL)
  84.               {
  85.                 PrevPtr->Next = NextPtr;
  86.               } // End if
  87.             else
  88.               WinHashTable[Index] = NextPtr;
  89.  
  90.             NodePtr->Next = NULL;
  91.             RemovePtr = RemovedList;
  92.             if (RemovePtr==NULL)
  93.               RemovedList = NodePtr;
  94.             else
  95.               {
  96.                 while (RemovePtr->Next!=NULL)
  97.                   RemovePtr = RemovePtr->Next;
  98.                 RemovePtr->Next = NodePtr;
  99.               } // End else
  100.             return;
  101.           } // End if
  102.         PrevPtr = NodePtr;
  103.         NodePtr = NextPtr;
  104.       } // End while
  105.   } // End of DiscardWindow
  106.  
  107. VOID ClearRemovedList ()
  108.   {
  109.     WINDOWNODE *Ptr;
  110.  
  111.     Ptr = RemovedList;
  112.     if (Ptr!=NULL)
  113.       {
  114.         delete Ptr;
  115.       } // End while
  116.     RemovedList = NULL;
  117.   } // End of ClearRemovedList
  118.  
  119. GUIWINDOW *FindWindow ( HWINDOW hWindow )
  120.   {
  121.     LONG Index;
  122.     WINDOWNODE *NodePtr;
  123.     GUIWINDOW *WinPtr;
  124.  
  125.     Index = (LONG)hWindow & 255;
  126.     NodePtr = WinHashTable[Index];
  127.     while (NodePtr!=NULL)
  128.       {
  129.         WinPtr = NodePtr->WinPtr;
  130.         if ((WinPtr!=NULL)&&(NodePtr->Handle==hWindow))
  131.           return NodePtr->WinPtr;
  132.       } // End while
  133.     return NULL;
  134.   } // End of FindWindow
  135.  
  136. VOID InitWinHashTable ()
  137.   {
  138.     INT i;
  139.     for (i=0;i<256;i++)
  140.       {
  141.         WinHashTable[i] = NULL;
  142.       } // End for
  143.     RemovedList = NULL;
  144.   } // End of InitWinHashTable
  145.  
  146. VOID DeInitWinHashTable ()
  147.   {
  148.     INT i;
  149.     for (i=0;i<256;i++)
  150.       {
  151.         if (WinHashTable[i]!=NULL)
  152.         delete WinHashTable[i];
  153.         WinHashTable[i] = NULL;
  154.       } // End for
  155.     if (RemovedList!=NULL)
  156.       delete RemovedList;
  157.     RemovedList = NULL;
  158.   } // End of InitWinHashTable
  159.  
  160.  
  161. //****************************************************
  162. //
  163. // GUI Window Class
  164. //
  165. //****************************************************
  166.  
  167. GUIWINDOW *NewWindow=NULL;
  168.  
  169. GUIWINDOW::GUIWINDOW () : GUIOBJECT ()
  170.   {
  171.     ParentWindow = NULL;
  172.     ClientXPos = ClientYPos = 0;
  173.     hToolBar = NULL;
  174.     hWindow = hClient = NULL;
  175.     #if defined (__FORWINDOWS__)
  176.       WinBG = WHITE_BRUSH;
  177.       ClassStyle = GUI_CLASS_VREDRAW | GUI_CLASS_HREDRAW;
  178.       WinStyle = GUI_WIN_OVERLAPPEDWINDOW | GUI_WIN_CLIPSIBLINGS;
  179.       WinExStyle = 0;
  180.       WinBG = WHITE_BRUSH;
  181.       ClientFlag = GUI_WIN_CHILD | GUI_WIN_VISIBLE | GUI_WIN_CLIPSIBLINGS;
  182.       ClientClass = 0;
  183.       strcpy ( ClassName, "GUIWINDOW" );
  184.     #endif
  185.   } // End of Constructor for GUIWINDOW
  186.  
  187. GUIWINDOW::~GUIWINDOW ()
  188.   {
  189.   } // End of Destructor for GUIWINDOW
  190.  
  191. VOID GUIWINDOW::PreRegister ()
  192.   {
  193.     #if defined (__FORWINDOWS__)  
  194.       if (WinStyle&GUI_WIN_VSCROLL)
  195.         ClientFlag |= GUI_WIN_VSCROLL;  
  196.       if (WinStyle&GUI_WIN_HSCROLL)
  197.         ClientFlag |= GUI_WIN_HSCROLL;
  198.  
  199.       RemoveWinStyle ( GUI_WIN_VSCROLL );
  200.       RemoveWinStyle ( GUI_WIN_HSCROLL );
  201.       
  202.       if (ClassStyle|GUI_CLASS_OWNDISPLAY)
  203.         ClientClass |= GUI_CLASS_OWNDISPLAY;
  204.       
  205.       RemoveClassStyle ( GUI_CLASS_OWNDISPLAY );
  206.     #endif  
  207.   } // End of PreRegister for GUIWINDOW
  208.  
  209. VOID GUIWINDOW::RegisterWindow ()
  210.   {
  211.     #if defined (__FORWINDOWS__)
  212.       WNDCLASS WndClass;
  213.       WndClass.cbClsExtra = 0;
  214.       WndClass.cbWndExtra = 0;
  215.       #if defined (__FORWIN386__)
  216.         WndClass.hbrBackground = GetStockObject ( (short)WinBG );
  217.       #else
  218.         WndClass.hbrBackground = GetStockObject ( WinBG );
  219.       #endif
  220.       WndClass.hCursor = LoadCursor ( NULL, IDC_ARROW );
  221.       WndClass.hIcon = LoadIcon ( NULL, "END" );
  222.       WndClass.hInstance = (HINSTANCE)hInstance;
  223.       WndClass.lpfnWndProc = (WNDPROC)GUIWinProc;
  224.       WndClass.lpszClassName = ClassName;
  225.       WndClass.lpszMenuName = NULL;
  226.       WndClass.style = (UINT)ClassStyle;
  227.  
  228.       RegisterClass ( &WndClass );
  229.  
  230.     #elif defined (__FOROS2__)
  231.       WinRegisterClass ( hAB, ClassName, GUIWinProc, ClassStyle, 0 );
  232.     #endif
  233.   } // End of ResgisterWindow for GUIWINDOW
  234.  
  235. VOID GUIWINDOW::CreateClientWindow ()
  236.   {
  237.     #if defined (__FORGDK__)
  238.       hClient = hWindow;
  239.     #elif defined (__FORWINDOWS__)
  240.       WNDCLASS WndClass;
  241.       WndClass.cbClsExtra = 0;
  242.       WndClass.cbWndExtra = 4;
  243.       #if defined (__FORWIN386__)
  244.         WndClass.hbrBackground = GetStockObject ( (short)WinBG );
  245.       #else
  246.         WndClass.hbrBackground = GetStockObject ( WinBG );
  247.       #endif
  248.       WndClass.hCursor = LoadCursor ( NULL, IDC_ARROW );
  249.       WndClass.hIcon = LoadIcon ( NULL, "END" );
  250.       WndClass.hInstance = (HINSTANCE)hInstance;
  251.       WndClass.lpfnWndProc = (WNDPROC)ClientProc;
  252.       WndClass.lpszClassName = "GUICLIENT";
  253.       WndClass.lpszMenuName = NULL;      
  254.       WndClass.style = (UINT)ClientClass;
  255.  
  256.       RegisterClass ( &WndClass );
  257.  
  258.       RECT r;
  259.       GetClientRect ( hWindow, &r );
  260.  
  261.       #if defined (__FORWIN386__)
  262.         hClient = CreateWindow ( "GUICLIENT", "", ClientFlag,
  263.                                  (short)ClientXPos, (short)ClientYPos,
  264.                                  (short)(r.right-ClientXPos),
  265.                                  (short)(r.bottom-ClientYPos),
  266.                                  hWindow, NULL, hInstance, NULL );
  267.       #else
  268.         hClient = CreateWindow ( "GUICLIENT", "", ClientFlag,
  269.                                  ClientXPos, ClientYPos, r.right-ClientXPos,
  270.                                  r.bottom-ClientYPos,
  271.                                  hWindow, NULL, hInstance, NULL );
  272.       #endif  
  273.       SetWindowLong ( hClient, 0, (LONG)this );
  274.       ::ShowWindow ( hClient, SW_SHOW );
  275.     #else
  276.     #endif
  277.   } // End of CreateCleintWindow for GUIWINDOW
  278.  
  279. BOOLEAN GUIWINDOW::Create ( STRING Title, LONG x, LONG y, LONG Wd, LONG Ht,
  280.                             GUIWINDOW *Parent )
  281.   {
  282.     PreRegister (); 
  283.     RegisterWindow ();
  284.     NewWindow = this;
  285.  
  286.     ParentWindow = Parent;
  287.     HWINDOW hParent;
  288.     HWINDOW hNew;
  289.  
  290.     #if defined (__FORWINDOWS__)
  291.  
  292.       if (Parent==NULL)
  293.         hParent = HDESKTOP;
  294.       else
  295.         hParent = Parent->GetClient ();
  296.  
  297.       #if defined (__FORWIN386__)
  298.         if (WinExStyle==0)
  299.           hWindow = CreateWindow ( ClassName, Title, WinStyle, (short)x, (short)y,
  300.                                    (short)Wd, (short)Ht, hParent, NULL,
  301.                                    hInstance, NULL );
  302.         else
  303.           hWindow = CreateWindowEx ( WinExStyle, ClassName, Title, WinStyle, (short)x, (short)y,
  304.                                      (short)Wd, (short)Ht,
  305.                                      hParent, NULL, hInstance, NULL );
  306.       #else
  307.         if (WinExStyle==0)
  308.           hWindow = CreateWindow ( ClassName, Title, WinStyle, x, y, Wd, Ht, hParent, NULL,
  309.                                    hInstance, NULL );
  310.         else
  311.           hWindow = CreateWindowEx ( WinExStyle, ClassName, Title, WinStyle, x, y, Wd, Ht,
  312.                                      hParent, NULL, hInstance, NULL );
  313.       #endif
  314.       hNew = hWindow;
  315.       CreateClientWindow ();
  316.       
  317.     #elif defined (__FOROS2__)
  318.       if (Parent==NULL)
  319.         hParent = HDESKTOP;
  320.       else
  321.         hParent = Parent->GetClient ();
  322.         
  323.       ULONG CreateFlag = WinExStyle;
  324.       hWindow = WinCreateStdWindow ( hParent, WinStyle, &CreateFlag, ClassName,
  325.                                      Title, 0, 0, 0, &hClient );
  326.       hNew = hClient;
  327.       if (x&y&Wd&Ht)
  328.         {}
  329.                                            
  330.     #elif defined (__FORDOS__)
  331.       if (Title)
  332.         {}
  333.       if (x&y&Wd&Ht)
  334.         {}
  335.       if (Parent)
  336.         {}
  337.       if (hParent)
  338.         {}
  339.     #endif
  340.     AddWindow ( this, hNew );
  341.     NewWindow = NULL;
  342.     return SUCCESS;
  343.   } // End of Create for GUIWINDOW
  344.  
  345. VOID GUIWINDOW::InvalidateClient ()
  346.   {
  347.     #if defined (__FORWINDOWS__)
  348.       InvalidateRect ( hWindow, NULL, TRUE );  
  349.     #else
  350.     #endif  
  351.   } // End of InvalidateClient for GUIWINDOW
  352.  
  353. VOID GUIWINDOW::CloseWindow ()
  354.   {
  355.     #if defined (__FORWINDOWS__)
  356.       SendMessage ( hWindow, GUI_WM_CLOSE, 0, 0 );
  357.     #endif
  358.   } // End of CloseWindow for GUIWINDOW
  359.  
  360. HDISPLAY GUIWINDOW::GetDisplay ( HWINDOW hWnd )
  361.   {
  362.          if (hWnd)
  363.       {}
  364.          #if defined (__FORWINDOWS__)
  365.                 return GetDC ( hWnd );
  366.          #elif defined (__FOROS2__)
  367.                 return 0;
  368.          #elif defined (__FORUNIX__)
  369.                 return hWnd;
  370.          #elif defined (__FORDOS__)
  371.       return HVGA;
  372.     #endif
  373.   } // End of GetDisplay for GUIWINDOW
  374.  
  375. VOID GUIWINDOW::ReleaseDisplay ( HWINDOW hWnd, HDISPLAY hDisplay )
  376.   {
  377.     #if defined (__FORWINDOWS__)
  378.       ReleaseDC ( hWnd, hDisplay );
  379.     #elif defined (__FOROS2__)
  380.       if (hDisplay&hWnd)
  381.         {}
  382.     #elif defined (__FORDOS__)
  383.       if (hDisplay&hWnd)
  384.         {}
  385.     #endif
  386.   } // End of ReleaseDisplay for GUIWINDOW
  387.  
  388. VOID GUIWINDOW::ShowWindow ( LONG CmdShow )
  389.   {
  390.     if (CmdShow)
  391.       {}
  392.     #if defined (__FORWINDOWS__)
  393.       #if defined (__FORWIN386__)
  394.         ::ShowWindow ( hWindow, (short)CmdShow );
  395.       #else
  396.         ::ShowWindow ( hWindow, CmdShow );
  397.       #endif
  398.     #endif
  399.   } // End of ShowWindow for GUIWINDOW
  400.  
  401. VOID GUIWINDOW::UpdateWindow ()
  402.   {
  403.     #if defined (__FORWINDOWS__)
  404.       ::UpdateWindow ( hWindow );
  405.     #endif
  406.   } // nd of UpdateWindow for GUIWINDOW
  407.  
  408. LONG GUIWINDOW::ShowMessageBox ( STRING Title, STRING Message, LONG Flag )
  409.   {
  410.     #if defined (__FORWINDOWS__)
  411.       #if defined (__FORWIN386__)
  412.         return MessageBox ( hWindow, Message, Title, (short)Flag );
  413.       #else
  414.         return MessageBox ( hWindow, Message, Title, Flag );
  415.       #endif
  416.     #elif defined (__FOROS2__)
  417.       if (Title)
  418.         {}
  419.       if (Message)
  420.         {}
  421.       if (Flag)
  422.         {}
  423.       return SUCCESS;
  424.     #elif defined (__FORDOS__)
  425.       if (Title)
  426.         {}
  427.       if (Message)
  428.         {}
  429.       if (Flag)
  430.         {}
  431.       return SUCCESS;
  432.     #endif
  433.   } // End of ShowMessageBox for GUIWINDOW
  434.  
  435. VOID GUIWINDOW::SetClassStyle ( LONG Style )
  436.   {
  437.     ClassStyle = Style;
  438.   } // End of SetClassStyle for GUIWINDOW
  439.  
  440. VOID GUIWINDOW::AddClassStyle ( LONG Style )
  441.   {
  442.     ClassStyle |= Style;
  443.   } // End of SetClassStyle for GUIWINDOW
  444.  
  445. VOID GUIWINDOW::RemoveClassStyle ( LONG Style )
  446.   {
  447.     ClassStyle &= ~Style;
  448.   } // End of SetClassStyle for GUIWINDOW
  449.  
  450. VOID GUIWINDOW::SetWinStyle ( LONG Style )
  451.   {
  452.     WinStyle = Style;
  453.   } // End of SetClassStyle for GUIWINDOW
  454.  
  455. VOID GUIWINDOW::AddWinStyle ( LONG Style )
  456.   {
  457.     WinStyle |= Style;
  458.   } // End of SetClassStyle for GUIWINDOW
  459.  
  460. VOID GUIWINDOW::RemoveWinStyle ( LONG Style )
  461.   {
  462.     WinStyle &= ~Style;
  463.   } // End of SetClassStyle for GUIWINDOW
  464.  
  465. VOID GUIWINDOW::SetWinExStyle ( LONG Style )
  466.   {
  467.     WinExStyle = Style;
  468.   } // End of SetClassStyle for GUIWINDOW
  469.  
  470. VOID GUIWINDOW::AddWinExStyle ( LONG Style )
  471.   {
  472.     WinExStyle |= Style;
  473.   } // End of SetClassStyle for GUIWINDOW
  474.  
  475. VOID GUIWINDOW::RemoveExWinStyle ( LONG Style )
  476.   {
  477.     WinExStyle &= ~Style;
  478.   } // End of SetClassStyle for GUIWINDOW
  479.  
  480. VOID GUIWINDOW::SetBackGround ( LONG Background )
  481.   {
  482.     WinBG = Background;
  483.   } // End of SetBackground for GUIWINDOW
  484.  
  485. LONG GUIWINDOW::OnPaint ( HDISPLAY hDisplay )
  486.   {
  487.     if (hDisplay)
  488.       {}
  489.     return 0;
  490.   } // End of OnPaint for GUIWINDOW
  491.  
  492. LONG GUIWINDOW::OnCommand ( LONG Command )
  493.   {
  494.     if (Command)
  495.       {}
  496.     return 0;
  497.   } // End of OnCommand for GUIWINDOW
  498.  
  499. LONG GUIWINDOW::OnClose ()
  500.   {
  501.     return 0;
  502.   } // End of OnClose for GUIWINDOW
  503.  
  504. LONG GUIWINDOW::OnSize ( LONG Wd, LONG Ht )
  505.   {
  506.     if (Wd&Ht)
  507.       {}
  508.     return 0;
  509.   } // End of OnSize for GUIWINDOW
  510.  
  511. LONG GUIWINDOW::OnKeyDown ( LONG WhichKey )
  512.   {
  513.     if (WhichKey)
  514.       {}
  515.     return 0;
  516.   } // End of OnKeyDown for GUIWINDOW
  517.  
  518. LONG GUIWINDOW::OnKeyUp ( LONG WhichKey )
  519.   {
  520.     if (WhichKey)
  521.       {}
  522.     return 0;
  523.   } // End of OnKeyUp for GUIWINDOW
  524.  
  525. LONG GUIWINDOW::OnMouse ( LONG Event, LONG Flags, LONG Mx, LONG My )
  526.   {
  527.     if (Event)
  528.       {}
  529.     if (Mx&My)
  530.       {}
  531.     if (Flags)
  532.       {}
  533.     return 0;
  534.   } // End of OnMouse for GUIWINDOW
  535.  
  536. LONG GUIWINDOW::OnTimer ()
  537.   {
  538.     return 0;
  539.   } // End of OnTimer for GUIWINDOW
  540.  
  541. LONG GUIWINDOW::OnDestroy ()
  542.   {
  543.     return 0;
  544.   } // End of OnDestroy for GUIWINDOW
  545.  
  546. LONG GUIWINDOW::OnScroll ( LONG SBarID, LONG Code, LONG Pos )
  547.   {
  548.     if (SBarID)
  549.       {}
  550.     if (Code)
  551.       {}
  552.     if (Pos)
  553.       {}
  554.     return 0;
  555.   } // End of OnScroll for GUIWINDOW
  556.  
  557. LONG GUIWINDOW::OnPosChanging ( WINPOSCHANGE *WinPosChange )
  558.   {
  559.     if (WinPosChange)
  560.       {}
  561.     return 0;
  562.   } // End of OnPosChanging for GUIWINDOW
  563.  
  564. LONG GUIWINDOW::OnActivate ( LONG Flags, BOOLEAN IsMinimized )
  565.   {
  566.     if (Flags)
  567.       {}
  568.     if (IsMinimized)
  569.       {}
  570.     return 0;
  571.   } // End of OnActivate for GUIWINDOW
  572.  
  573. VOID GUIWINDOW::SetTimer ( LONG Timing )
  574.   {
  575.     #if defined (__FORWINDOWS__)
  576.       #if defined (__FORWIN386__)
  577.         ::SetTimer ( hWindow, NULL, (short)Timing, NULL );
  578.       #else
  579.         ::SetTimer ( hWindow, NULL, Timing, NULL );
  580.       #endif
  581.     #elif defined (__FOROS2__)
  582.       if (Timing)
  583.         {}
  584.     #elif defined (__FORDOS__)
  585.       if (Timing)
  586.         {}
  587.     #endif
  588.   } // End of SetTimer for GUIWINDOW
  589.  
  590. VOID GUIWINDOW::KillTimer ()
  591.   {
  592.     #if defined (__FORWINDOWS__)
  593.       ::KillTimer ( hWindow, 0 );
  594.     #elif defined (__FORDOS__)
  595.     #endif
  596.   } // End of KillTimer for GUIWINDOW
  597.  
  598. VOID GUIWINDOW::SetScrollRange ( LONG SBarID, LONG Min, LONG Max )
  599.   {
  600.     #if defined (__FORWINDOWS__)
  601.       #if defined (__FORWIN386__)
  602.         ::SetScrollRange ( hClient, (short)SBarID, (short)Min, (short)Max, TRUE );
  603.       #else
  604.         ::SetScrollRange ( hClient, SBarID, Min, Max, TRUE );
  605.       #endif
  606.     #else
  607.       if (SBarID)
  608.         {}
  609.       if (Min&Max)
  610.         {}
  611.     #endif
  612.   } // End of SetScrollRange for GUIWINDOW
  613.  
  614. VOID GUIWINDOW::GetScrollRange ( LONG SBarID, LONG *Min, LONG *Max )
  615.   {
  616.     #if defined (__FORWINDOWS__)
  617.       #if defined (__FORWIN386__)
  618.         SHORT iMin,iMax;
  619.         ::GetScrollRange ( hClient, (short)SBarID, &iMin, &iMax );
  620.       #else
  621.         INT iMin,iMax;
  622.         ::GetScrollRange ( hClient, SBarID, &iMin, &iMax );
  623.       #endif      
  624.       *Min = iMin;
  625.       *Max = iMax;
  626.     #else
  627.       if (SBarID)
  628.         {}
  629.       if (Min)
  630.         {}
  631.       if (Max)
  632.         {}
  633.     #endif
  634.   } // End of GetScrollRange for GUIWINDOW
  635.  
  636. VOID GUIWINDOW::SetScrollPos ( LONG SBarID, LONG Pos )
  637.   {
  638.     #if defined (__FORWINDOWS__)
  639.       #if defined (__FORWIN386__)
  640.         ::SetScrollPos ( hClient, (short)SBarID, (short)Pos, TRUE );
  641.       #else
  642.         ::SetScrollPos ( hClient, SBarID, Pos, TRUE );
  643.       #endif  
  644.     #else
  645.       if (SBarID)
  646.         {}
  647.       if (Pos)
  648.         {}
  649.     #endif
  650.   } // End of SetScrollPos for GUIWINDOW
  651.  
  652. VOID GUIWINDOW::GetScrollPos ( LONG SBarID, LONG *Pos )
  653.   {
  654.     #if defined (__FORWINDOWS__)
  655.       #if defined (__FORWIN386__)
  656.         *Pos = ::GetScrollPos ( hClient, (short)SBarID );
  657.       #else
  658.         *Pos = ::GetScrollPos ( hClient, SBarID );
  659.       #endif
  660.     #else
  661.       if (SBarID)
  662.         {}
  663.       if (Pos)
  664.         {}
  665.     #endif
  666.   } // End of SetScrollPos for GUIWINDOW
  667.  
  668. VOID GUIWINDOW::SetClientAreaPos ( LONG x, LONG y )
  669.   {
  670.     if (x&y)
  671.       {}
  672.     if (hWindow==hClient)
  673.       return;
  674.         
  675.     #if defined (__FORWINDOWS__)
  676.       ClientXPos = x;
  677.       ClientYPos = y;
  678.       #if defined (__FORWIN386__)
  679.         SetWindowPos ( hClient, NULL, (short)x, (short)y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE |
  680.                        SWP_NOZORDER );
  681.       #else
  682.         SetWindowPos ( hClient, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE |
  683.                        SWP_NOZORDER );
  684.       #endif
  685.     #else
  686.     #endif  
  687.   } // End of SetClientAreaPos for GUIWINDOW
  688.  
  689. BOOLEAN GUIWINDOW::AddChildWindow ( GUIWINDOW *ChildWindow, STRING Title, LONG x, LONG y,
  690.                                     LONG Wd, LONG Ht )
  691.   {
  692.     if (ChildWindow==NULL)
  693.       return FAILURE;
  694.     BOOLEAN Result;  
  695.     Result = ChildWindow->Create ( Title, x, y, Wd, Ht, this );
  696.     if (Result==FAILURE)
  697.       return FAILURE;
  698.     #if defined (__FORWINDOWS__)  
  699.       ChildWindow->ShowWindow ( SW_SHOW );
  700.     #endif  
  701.     return Result;  
  702.   } // End of AddChildWindow for GUIWINDOW
  703.                                     
  704. VOID GUIWINDOW::ExitApplication ( LONG ReturnValue )
  705.   {
  706.     if (ReturnValue)
  707.       {}
  708.     #if defined (__FORWINDOWS__)
  709.       #if defined (__FORWIN386__)
  710.         PostQuitMessage ( (short)ReturnValue );
  711.       #else
  712.         PostQuitMessage ( ReturnValue );
  713.       #endif
  714.     #elif defined (__FOROS2__)
  715.     #elif defined (__FORDOS__)
  716.     #elif defined (__FORUNIX__)
  717.       ExitApp = TRUE;
  718.     #endif
  719.   } // End of ExitApplication for GUIWINDOW
  720.  
  721. VOID GUIWINDOW::SetToolBar ( HWINDOW ToolBar, LONG Ht )
  722.   {
  723.     hToolBar = ToolBar;  
  724.     SetClientAreaPos ( 0, Ht );  
  725.   } // End of SetToolBar for GUIWINDOW
  726.  
  727. VOID GUIWINDOW::ResetClientArea ()
  728.   {
  729.     #if defined (__FORWINDOWS__)
  730.       RECT r;
  731.       GetClientRect ( hWindow, &r );
  732.       if (hClient!=hWindow)
  733.         {
  734.           #if defined (__FORWIN386__)
  735.             SetWindowPos ( hClient, NULL, (short)ClientXPos, (short)ClientYPos,
  736.                            (short)(r.right-ClientXPos),
  737.                            (short)(r.bottom-ClientYPos),
  738.                            SWP_NOZORDER | SWP_NOACTIVATE );
  739.           #else
  740.             SetWindowPos ( hClient, NULL, ClientXPos, ClientYPos, r.right-ClientXPos,
  741.                            r.bottom-ClientYPos,
  742.                            SWP_NOZORDER | SWP_NOACTIVATE );
  743.           #endif  
  744.         } // End if
  745.       if (hToolBar!=NULL)
  746.         {
  747.           #if defined (__FORWIN386__)
  748.             SetWindowPos ( hToolBar, NULL, 0, 0, r.right,
  749.                            (short)ClientYPos,
  750.                            SWP_NOZORDER | SWP_NOACTIVATE );
  751.           #else
  752.             SetWindowPos ( hToolBar, NULL, 0, 0, r.right,
  753.                            ClientYPos,
  754.                            SWP_NOZORDER | SWP_NOACTIVATE );
  755.           #endif  
  756.         } // End if                   
  757.     #else
  758.     #endif
  759.   } // End of ResetClientArea for GUIWINDOW
  760.  
  761. VOID GUIWINDOW::SetMenu ( GUIMENU *Menu )
  762.   {
  763.     #if defined (__FORWINDOWS__)
  764.       ::SetMenu ( hWindow, Menu->GetHandle() );
  765.       ::DrawMenuBar ( hWindow );
  766.     #elif defined (__FOROS2__)
  767.       if (Menu)
  768.         {}
  769.     #elif defined (__FORDOS__)
  770.       if (Menu)
  771.         {}      
  772.     #endif
  773.   } // End of SetMenu for GUIWINDOW
  774.  
  775. LONG GUIWINDOW::UserProc ( MESSAGE iMessage, PARAM1 Param1, PARAM2 Param2 )
  776.   {
  777.     if (iMessage)
  778.       {}
  779.     if (Param1)
  780.       {}
  781.     if (Param2)
  782.       {}
  783.     return 0;
  784.   } // End of UserProc for GUIWINDOW
  785.  
  786. LONG GUIWINDOW::WndProc ( HWINDOW hWnd, MESSAGE iMessage, PARAM1 Param1, PARAM2 Param2, BOOLEAN FromClient )
  787.   {
  788.     LONG Result;
  789.     hWindow = hWnd;
  790.     if (FromClient)
  791.       {}
  792.     if (Param1)
  793.       {}
  794.     if (Param2)
  795.       {}
  796.     Result = 0;
  797.     switch (iMessage)
  798.       {
  799.         case GUI_WM_CREATE :
  800.           Result = OnCreate ();
  801.           break;
  802.  
  803.         case GUI_WM_CLOSE :
  804.           Result = OnClose ();
  805.           break;
  806.           
  807.         case GUI_WM_DESTROY :
  808.           Result = OnDestroy ();
  809.           DiscardWindow ( hWindow );
  810.           break;
  811.  
  812.         case GUI_WM_PAINT :
  813.           #if defined (__FORWINDOWS__)
  814.             PAINTSTRUCT Ps,Ps1;
  815.             HDISPLAY hDisplay;
  816.  
  817.             if (hWindow!=hClient)
  818.               {
  819.                 BeginPaint ( hWindow, &Ps1 );
  820.                 hDisplay = BeginPaint ( hClient, &Ps );
  821.               } // End if
  822.             else
  823.               hDisplay = BeginPaint ( hWindow, &Ps1 );
  824.                   
  825.             Result = OnPaint ( hDisplay );
  826.  
  827.             if (hWindow!=hClient)
  828.               {
  829.                 EndPaint ( hClient, &Ps );
  830.                 EndPaint ( hWindow, &Ps1 );
  831.               } // End if
  832.             else
  833.               EndPaint ( hWindow, &Ps1 );
  834.  
  835.           #elif defined (__FOROS2__)
  836.             HDISPLAY hDisplay;
  837.             hDisplay = WinBeginPaint ( hWindow, NULLHANDLE, NULL );
  838.             Result = OnPaint ( hDisplay );
  839.             WinEndPaint ( hDisplay );
  840.  
  841.           #elif defined (__FORUNIX__)
  842.             Result = OnPaint ( hWindow );  
  843.  
  844.           #elif defined (__FORDOS__)
  845.             Result = OnPaint ( 0 );
  846.           #endif
  847.           break;
  848.  
  849.         case GUI_WM_COMMAND :
  850.           #if defined (__FORWINDOWS__)
  851.             Result = OnCommand ( Param1 );
  852.           #elif defined (__FOROS2__)
  853.             Result = OnCommand ( COMMANDMSG(&iMessage)->cmd );
  854.           #endif
  855.           break;
  856.  
  857.         case GUI_WM_ACTIVATE :
  858.           LONG ActiveFlags;
  859.           BOOLEAN Minimized;
  860.           ActiveFlags = LOWORD((LONG)Param1);
  861.           Minimized = HIWORD((LONG)Param1);
  862.           Result = OnActivate ( ActiveFlags, Minimized );
  863.           break;
  864.  
  865.         case GUI_WM_KEYDOWN :
  866.           Result = OnKeyDown ( (LONG)Param1 );
  867.           break;
  868.  
  869.         case GUI_WM_KEYUP :
  870.           Result = OnKeyUp ( (LONG)Param1 );
  871.           break;
  872.  
  873.         case GUI_WM_TIMER :
  874.           Result = OnTimer ();
  875.           break;
  876.  
  877.         case GUI_WM_MOUSEMOVE :
  878.         case GUI_WM_LBUTTONDOWN :
  879.         case GUI_WM_LBUTTONUP :
  880.         case GUI_WM_LBUTTONDBLCLK :
  881.         case GUI_WM_MBUTTONDOWN :
  882.         case GUI_WM_MBUTTONUP :
  883.         case GUI_WM_MBUTTONDBLCLK :
  884.         case GUI_WM_RBUTTONDOWN :
  885.         case GUI_WM_RBUTTONUP :
  886.         case GUI_WM_RBUTTONDBLCLK :
  887.           LONG Mx, My;
  888.           LONG Flags;
  889.  
  890.           #if defined (__FORWINDOWS__)
  891.             Flags = Param1;
  892.             Mx = LOWORD ( Param2 );
  893.             My = HIWORD ( Param2 );
  894.             if ((FromClient)&(hWindow!=hClient))
  895.               Result = OnMouse ( iMessage, Flags, Mx, My );
  896.             if ((FromClient==FALSE)&(hWindow==hClient))
  897.               Result = OnMouse ( iMessage, Flags, Mx, My );
  898.           #elif defined (__FOROS2__)
  899.             if (Mx&My&Flags)
  900.               {}
  901.           #elfi defined (__FORUNIX__)
  902.  
  903.           #elif defined (__FORDOS__)
  904.             if (Mx&My&Flags)
  905.               {}
  906.           #endif
  907.           break;
  908.  
  909.         case GUI_WM_SIZE :
  910.           ResetClientArea ();
  911.           Result = OnSize ( LOWORD (Param2), HIWORD (Param2) );
  912.           break;
  913.  
  914.         case GUI_WM_VSCROLL :
  915.           #if defined (__FORWINDOWS__)
  916.             Result = OnScroll ( SBAR_VERT, Param1, LOWORD(Param2));
  917.           #endif
  918.           break;
  919.         case GUI_WM_HSCROLL :
  920.           #if defined (__FORWINDOWS__)
  921.             Result = OnScroll ( SBAR_HORZ, Param1, LOWORD(Param2));
  922.           #endif
  923.           break;
  924.  
  925.         case GUI_WM_POSCHANGING :
  926.           #if defined (__FORWINDOWS__)
  927.             WINPOSCHANGE Wpc;
  928.             WINDOWPOS FAR *lpwp;
  929.             #if defined (__FORWIN386__)
  930.               lpwp = (WINDOWPOS FAR*)MK_FP(Param2>>16,Param2&0xFFFF);
  931.             #else
  932.               lpwp = (WINDOWPOS FAR*)Param2;
  933.             #endif
  934.             Wpc.xPos = lpwp->x;
  935.             Wpc.yPos = lpwp->y;
  936.             Wpc.Width = lpwp->cx;
  937.             Wpc.Height = lpwp->cy;
  938.             Wpc.Flags = lpwp->flags;
  939.  
  940.             Result = OnPosChanging ( &Wpc );
  941.  
  942.             #if defined (__FORWIN386__)
  943.               lpwp->x = (short)Wpc.xPos;
  944.               lpwp->y = (short)Wpc.yPos;
  945.               lpwp->cx = (short)Wpc.Width;
  946.               lpwp->cy = (short)Wpc.Height;
  947.             #else  
  948.               lpwp->x = Wpc.xPos;
  949.               lpwp->y = Wpc.yPos;
  950.               lpwp->cx = Wpc.Width;
  951.               lpwp->cy = Wpc.Height;
  952.             #endif
  953.             lpwp->flags = Wpc.Flags;
  954.           #endif
  955.           break;
  956.  
  957.         default :
  958.           Result = UserProc ( iMessage, Param1, Param2 );
  959.           break;
  960.       } // End switch
  961.     return Result;
  962.   } // End of WndProc for GUIWINDOW
  963.  
  964.  
  965. //****************************************************
  966. //
  967. // Window Procedure
  968. //
  969. //****************************************************
  970.  
  971. APIRESULT APIPROC GUIWinProc ( HWINDOW hWindow, MESSAGE iMessage,
  972.                                PARAM1 Param1, PARAM2 Param2 )
  973.   {
  974.     LONG Result;
  975.     GUIWINDOW *WinPtr;
  976.  
  977.     Result = 0;
  978.     WinPtr = FindWindow ( hWindow );
  979.     if (WinPtr==NULL)
  980.       {
  981.         if (NewWindow!=NULL)
  982.           Result = NewWindow->WndProc ( hWindow, iMessage, Param1, Param2, FALSE );
  983.       } // End if
  984.     else
  985.       {
  986.         Result = WinPtr->WndProc ( hWindow, iMessage, Param1, Param2, FALSE );
  987.       } // End else
  988.  
  989.     if (Result!=0)
  990.       return 0;
  991.  
  992.     #if defined (__FORWINDOWS__)
  993.       return DefWindowProc ( hWindow, iMessage, Param1, Param2 );
  994.  
  995.     #elif defined (__FOROS2__)
  996.       return WinDefWindowProc ( hWindow, iMessage, Param1, Param2 );
  997.  
  998.     #elif defined (__FORDOS__)
  999.       if (hWindow&iMessage&Param1&Param2)
  1000.         {}
  1001.       return 0;
  1002.     #endif
  1003.   } // End of GUIWinProc
  1004.  
  1005.  
  1006. //****************************************************
  1007. //
  1008. // Client Procedure
  1009. //
  1010. //****************************************************
  1011.  
  1012. BOOLEAN CallParent ( MESSAGE iMessage )
  1013.   {
  1014.     switch (iMessage)
  1015.       {
  1016.         case GUI_WM_MOUSEMOVE :
  1017.         case GUI_WM_LBUTTONDOWN :
  1018.         case GUI_WM_LBUTTONUP :
  1019.         case GUI_WM_LBUTTONDBLCLK :
  1020.         case GUI_WM_MBUTTONDOWN :
  1021.         case GUI_WM_MBUTTONUP :
  1022.         case GUI_WM_MBUTTONDBLCLK :
  1023.         case GUI_WM_RBUTTONDOWN :
  1024.         case GUI_WM_RBUTTONUP :
  1025.         case GUI_WM_RBUTTONDBLCLK :
  1026.         case GUI_WM_CHAR :
  1027.         case GUI_WM_PAINT :
  1028.         case GUI_WM_VSCROLL :
  1029.         case GUI_WM_HSCROLL :        
  1030.           return TRUE;
  1031.       } // end switch
  1032.     return FALSE;
  1033.   } // End of CallParent
  1034.  
  1035. APIRESULT APIPROC ClientProc ( HWINDOW hWindow, MESSAGE iMessage,
  1036.                                PARAM1 Param1, PARAM2 Param2 )
  1037.   {
  1038.     GUIWINDOW *Parent;
  1039.     LONG Result;
  1040.  
  1041.     #if defined (__FORWINDOWS__)
  1042.       Parent = (GUIWINDOW*)GetWindowLong( hWindow, 0 );
  1043.     #endif  
  1044.  
  1045.     Result = 0;
  1046.     if (Parent!=NULL)
  1047.       {
  1048.         if (CallParent(iMessage))
  1049.           Result = Parent->WndProc ( Parent->GetHandle(), iMessage,
  1050.                                      Param1, Param2, TRUE );
  1051.         else
  1052.           {
  1053.             if (iMessage==GUI_WM_PAINT)
  1054.               {
  1055.                 #if defined (__FORWINDOWS__)  
  1056.                   PAINTSTRUCT Ps;  
  1057.                   BeginPaint ( hWindow, &Ps );
  1058.                   EndPaint ( hWindow, &Ps );
  1059.                   Result = 1;
  1060.                 #endif  
  1061.               } // End if  
  1062.           } // End else                             
  1063.       } // End if
  1064.  
  1065.     if (Result!=0)
  1066.       {};
  1067.  
  1068.     #if defined (__FORWINDOWS__)
  1069.       return DefWindowProc ( hWindow, iMessage, Param1, Param2 );
  1070.  
  1071.     #elif defined (__FOROS2__)
  1072.       return WinDefWindowProc ( hWindow, iMessage, Param1, Param2 );
  1073.  
  1074.     #elif defined (__FORDOS__)
  1075.       if (hWindow&iMessage&Param1&Param2)
  1076.         {}
  1077.       return 0;
  1078.     #endif
  1079.   } // End of ClientProc
  1080.  
  1081. #if defined (__FORUNIX__)
  1082. VOID GUIWINDOW::MapXWinEvent ( MESSAGE *iMessage, XEvent *EventPtr )
  1083.   {
  1084.     switch (EventPtr->type)
  1085.       {
  1086.         case Expose :
  1087.           if (EventPtr->xexpose.count==0)
  1088.               *iMessage = GUI_WM_PAINT;
  1089.               break;
  1090.         case ButtonPress :
  1091.           switch (EventPtr->xbutton.button)
  1092.             {
  1093.               case Button1 :
  1094.                 *iMessage = GUI_WM_LBUTTONDOWN;
  1095.                 break;
  1096.               case Button2 :
  1097.                 *iMessage = GUI_WM_MBUTTONDOWN;
  1098.                 break;
  1099.               case Button3 :
  1100.                 *iMessage = GUI_WM_RBUTTONDOWN;
  1101.                 break;
  1102.             } // End switch
  1103.         case ButtonRelease :
  1104.           switch (EventPtr->xbutton.button)
  1105.             {
  1106.               case Button1 :
  1107.                 *iMessage = GUI_WM_LBUTTONUP;
  1108.                 break;
  1109.               case Button2 :
  1110.                 *iMessage = GUI_WM_MBUTTONUP;
  1111.                 break;
  1112.               case Button3 :
  1113.                 *iMessage = GUI_WM_RBUTTONUP;
  1114.                 break;
  1115.             } // End switch
  1116.           break;
  1117.         default :
  1118.           *iMessage = EventPtr->type;
  1119.           break;
  1120.       } // End switch
  1121.   } // End of MapXWinEvent for GUIWINDOW
  1122.  
  1123.   #if defined (__FORMOTIF__)
  1124. VOID GUIWinXWinProc ( Widget W, XtPointer ClientData, 
  1125.                       XEvent *EventPtr )
  1126.   {
  1127.     GUIWINDOW *WinPtr;
  1128.     HWINDOW hWindow;
  1129.     PARAM1 Param1;
  1130.     PARAM2 Param2;
  1131.     MESSAGE iMessage;
  1132.  
  1133.     hWindow = XtWindow ( W );
  1134.     WinPtr = FindWindow ( hWindow );
  1135.     if (WinPtr==NULL)
  1136.       {
  1137.       } // End if
  1138.     else
  1139.       {
  1140.         Param1 = EventPtr;
  1141.         Param2 = ClientData;
  1142.         WinPtr->MapXWinEvent ( &iMessage, EventPtr );
  1143.         WinPtr->WndProc ( hWindow, iMessage, Param1, 
  1144.                           Param2, FALSE );
  1145.        } // End else
  1146.     ClearRemovedList ();
  1147.   } // End of GUIWinXWinProc  
  1148.   #endif
  1149. #endif
  1150.