home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / df3os2.zip / FOCUS.CPP < prev    next >
C/C++ Source or Header  |  1993-09-15  |  2KB  |  107 lines

  1. // ------------- focus.cpp
  2.  
  3. #include "dflatpp.h"
  4.  
  5. void DFWindow::CaptureFocus()
  6. {
  7.     if (this != desktop.FocusCapture())    {
  8.         prevcapture = desktop.FocusCapture();
  9.         prevfocus = desktop.InFocus();
  10.         desktop.SetFocusCapture(this);
  11.         if (this != desktop.InFocus())
  12.             SetFocus();
  13.     }
  14. }
  15.  
  16. void DFWindow::ReleaseFocus()
  17. {
  18.     if (this == desktop.FocusCapture())    {
  19.         desktop.SetFocusCapture(prevcapture);
  20.         prevcapture = 0;
  21.         if (prevfocus != 0)
  22.             prevfocus->SetFocus();
  23.         prevfocus = 0;
  24.     }
  25. }
  26.  
  27. Bool DFWindow::SetFocus()
  28. {
  29.     if (this != desktop.InFocus())    {
  30.         // --- notify parent that child is taking the focus
  31.         if (Parent() != 0)
  32.             Parent()->EnterFocus(this);
  33.         if (desktop.InFocus() != 0)
  34.             desktop.InFocus()->ResetFocus();
  35.         desktop.SetFocus(this);
  36.         if (Parent() == 0 || Parent()->windowtype != DialogWindow)    {
  37.             Dequeue();        // move the window to the
  38.             Enqueue();        // top of the focus queue
  39.         }
  40.         Show();
  41.     }
  42.     return True;
  43. }
  44.  
  45. void DFWindow::ResetFocus()
  46. {
  47.     desktop.SetFocus(0);
  48.     Border();
  49.     if (Parent() != 0)
  50.         // --- notify parent that child lost the focus
  51.         Parent()->LeaveFocus(this);
  52. }
  53.  
  54. // --- set the focus to the next eligible sibling window
  55. void DFWindow::NextSiblingFocus()
  56. {
  57.     DFWindow *Wnd = desktop.InFocus();
  58.     while (Wnd != 0)    {
  59.         if (Wnd->Next() == 0)    {
  60.             if (Wnd->Parent() != 0)
  61.                 Wnd = Wnd->Parent()->First();
  62.         }
  63.         else
  64.             Wnd = Wnd->Next();
  65.         if (Wnd == desktop.InFocus())
  66.             break;
  67.         if (Wnd != 0)
  68.             if (Wnd->SetFocus())
  69.                 break;
  70.     }
  71. }
  72.  
  73. // --- set the focus to the next previous eligible sibling window
  74. void DFWindow::PrevSiblingFocus()
  75. {
  76.     DFWindow *Wnd = desktop.InFocus();
  77.     while (Wnd != 0)    {
  78.         if (Wnd->Prev() == 0)    {
  79.             if (Wnd->Parent() != 0)
  80.                 Wnd = Wnd->Parent()->Last();
  81.         }
  82.         else
  83.             Wnd = Wnd->Prev();
  84.         if (Wnd == desktop.InFocus())
  85.             break;
  86.         if (Wnd != 0)
  87.             if (Wnd->SetFocus())
  88.                 break;
  89.     }
  90. }
  91.  
  92. // --------- add the window to the linked list
  93. void DFWindow::Enqueue()
  94. {
  95.     family.Append(this);
  96. }
  97.  
  98. // --------- remove the window from the linked list
  99. void DFWindow::Dequeue()
  100. {
  101.     family.Remove(this);
  102. }
  103.  
  104.  
  105.  
  106.  
  107.