home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / layout.pak / LAYOUT.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  3KB  |  119 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993 by Borland International
  3. //
  4. // Program Description:
  5. //  Interactive program to demonstrate TLayout window.  It creates
  6. //  a frame window, colored child windows and a client window.
  7. //
  8. //  The menu choice lets you bring up a dialog to let you set values for a
  9. //  TLayoutMetrics structure for the various child windows (the dialog is
  10. //  modeless, so you can layout several windows at the same time).
  11. //  A TLayoutMetrics (declared in layoutwi.h) has four TLayoutConstraints
  12. //  in it, X, Y, Width and Height.  When the dialog comes up, you choose
  13. //  which constraint you want to select, then set the various members of
  14. //  that constraint.
  15. //  There are some constraints that you don't do with layout windows.
  16. //  For example, if you constrain the lmWidth edges of a X constraint, it
  17. //  will cause a error.  (The lmWidth edge is best constrained through the
  18. //  Width constraint).
  19. //
  20. //  Functionality Demonstrated:
  21. //   OWL:  Low level use of TLayoutWindow and TLayoutMetrics
  22. //----------------------------------------------------------------------------
  23. #include <owl\owlpch.h>
  24. #include <owl\framewin.h>
  25. #include <owl\applicat.h>
  26. #include <owl\layoutwi.h>
  27. #include "layout.rh"
  28. #include "layout.h"
  29. #include "laydia.h"
  30.  
  31. TMyChildWindow::TMyChildWindow(TWindow* parent, int id, char far* title,
  32.                                TColor color)
  33.   : TWindow(parent, title)
  34. {
  35.   SetBkgndColor(color);
  36.   Attr.Style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS;
  37.   Attr.Id = id;
  38.   static int i = 0;
  39.   Attr.X = 10 + i++ * 100;
  40.   Attr.Y = 10;
  41.   Attr.W = 100;
  42.   Attr.H = 100;
  43. }
  44.  
  45. //----------------------------------------------------------------------------
  46.  
  47. DEFINE_RESPONSE_TABLE1(TMyLayout, TLayoutWindow)
  48.   EV_COMMAND(CM_LAYOUT, CmLayout),
  49.   EV_COMMAND(CM_RELAYOUT, CmReLayout),
  50. END_RESPONSE_TABLE;
  51.  
  52. TMyLayout::TMyLayout(TWindow* parent)
  53.   : TLayoutWindow(parent, 0)
  54. {
  55.   Attr.Style |= WS_BORDER;
  56.  
  57.   static TColor ChildColor[] = {
  58.     RGB(0xFF, 0x00, 0x00),
  59.     RGB(0x00, 0xFF, 0x00),
  60.     RGB(0x00, 0x00, 0xFF),
  61.     RGB(0xFF, 0xFF, 0x00),
  62.     RGB(0x00, 0xFF, 0xFF),
  63.     RGB(0xFF, 0x00, 0xFF),
  64.   };
  65.   static char* ChildName[] = {
  66.     "Red",
  67.     "Green",
  68.     "Blue",
  69.     "Yellow",
  70.     "Cyan",
  71.     "Magenta",
  72.   };
  73.  
  74.   for (int i = 0; i < MaxChildren; i++)
  75.     ChildInfo[i].Child = new TMyChildWindow(this, i+1, ChildName[i], ChildColor[i]);
  76.   ChildInfo[i].Child = 0;
  77.  
  78.   LayoutDialog = new TLayoutDialog(this, "IDD_LAYOUT", ChildInfo);
  79.  
  80. }
  81.  
  82. void TMyLayout::CmLayout()
  83. {
  84.   // Only one layout dialog at a time please
  85.   if (LayoutDialog->HWindow == 0){
  86.     LayoutDialog->Create();
  87.     }
  88. }
  89.  
  90. // Re-layout all of the children. Not really needed
  91. //
  92. void TMyLayout::CmReLayout()
  93. {
  94.   for (int i = 0; i < MaxChildren; i++)
  95.     SetChildLayoutMetrics(*ChildInfo[i].Child, ChildInfo[i].LayoutMetrics);
  96.   Layout();
  97. }
  98.  
  99. void TMyLayout::SetupWindow()
  100. {
  101.   TLayoutWindow::SetupWindow();
  102.   PostMessage(WM_COMMAND, CM_RELAYOUT);
  103. }
  104.  
  105. //----------------------------------------------------------------------------
  106.  
  107. class TLayoutApp : public TApplication {
  108.   public:
  109.     void InitMainWindow() {
  110.       MainWindow = new TFrameWindow(0, "Layout Window", new TMyLayout(0));
  111.       MainWindow->AssignMenu("IDM_LAYOUT");
  112.     }
  113. };
  114.  
  115. int OwlMain(int, char**)
  116. {
  117.   return TLayoutApp().Run();
  118. }
  119.