home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / pm2csci / german / window.cx_ / WINDOW.CXX
Encoding:
C/C++ Source or Header  |  1994-01-18  |  7.8 KB  |  308 lines

  1. /*******************************************************************
  2. *  WINDOW.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #define TEXTY       15
  9. #define WINDOWX    200
  10. #define WINDOWY    150
  11.  
  12. // --- class MyApp -------------------------------------------------
  13.  
  14. class MyApp : public Application
  15. {
  16. public:
  17.     virtual void Main( int, char*[] );
  18. };
  19.  
  20. // --- class WindowWithParent --------------------------------------
  21.  
  22. class WindowWithParent : public WorkWindow
  23. {
  24. public:
  25.                  WindowWithParent( Window* );
  26.  
  27.     virtual void Resize();
  28.     virtual void Paint( const Rectangle& );
  29.     virtual void Move();
  30. };
  31.  
  32. // --- class WindowWithoutParent -----------------------------------
  33.  
  34. class WindowWithoutParent : public WorkWindow
  35. {
  36. public:
  37.                  WindowWithoutParent();
  38.  
  39.     virtual void Resize();
  40.     virtual void Paint( const Rectangle& );
  41.     virtual void Move();
  42. };
  43.  
  44. // --- class ChildWindow -------------------------------------------
  45.  
  46. class ChildWindow : public Window
  47. {
  48. public:
  49.                  ChildWindow( Window* );
  50.  
  51.     virtual void Resize();
  52.     virtual void Paint( const Rectangle& );
  53.     virtual void Move();
  54. };
  55.  
  56. // --- class MyWindow ----------------------------------------------
  57.  
  58. class MyWindow : public WorkWindow
  59. {
  60. protected:
  61.     WindowWithParent    aWindowWithParent;
  62.     WindowWithoutParent aWindowWithoutParent;
  63.     ChildWindow         aChildWindow;
  64.  
  65. public:
  66.                         MyWindow();
  67.  
  68.     virtual void        Resize();
  69.     virtual void        Move();
  70. };
  71.  
  72. // --- WindowWithParent::WindowWithParent --------------------------
  73.  
  74. WindowWithParent::WindowWithParent( Window* pParent ) :
  75.                       WorkWindow( pParent, WB_STDWORK )
  76. {
  77.     Font aFont;
  78.     aFont.ChangePitch( PITCH_FIXED );
  79.     ChangeFont( aFont );
  80. }
  81.  
  82. // --- WindowWithParent::Resize() ----------------------------------
  83.  
  84. void WindowWithParent::Resize()
  85. {
  86.     Invalidate();
  87. }
  88.  
  89. // --- WindowWithParent::Move() ------------------------------------
  90.  
  91. void WindowWithParent::Move()
  92. {
  93.     Invalidate();
  94. }
  95.  
  96. // --- WindowWithParent::Paint() -----------------------------------
  97.  
  98. void WindowWithParent::Paint( const Rectangle& )
  99. {
  100.     Point   aPosition( GetPosPixel() );
  101.     Point   aScreenPosition( OutputToScreenPixel( Point( 0, 0 ) ) );
  102.     Size    aSize( GetSizePixel() );
  103.     Size    aOutputSize( GetOutputSizePixel() );
  104.     String  aOutStr;
  105.  
  106.     aOutStr  = "Pos:      ";
  107.     aOutStr += aPosition.X();
  108.     aOutStr += " , ";
  109.     aOutStr += aPosition.Y();
  110.     DrawText( Point( 0, 0 ), aOutStr );
  111.  
  112.     aOutStr  = "Scr-Pos:  ";
  113.     aOutStr += aScreenPosition.X();
  114.     aOutStr += " , ";
  115.     aOutStr += aScreenPosition.Y();
  116.     DrawText( Point( 0, TEXTY ), aOutStr );
  117.  
  118.     aOutStr  = "Size:     ";
  119.     aOutStr += aSize.Width();
  120.     aOutStr += " : ";
  121.     aOutStr += aSize.Height();
  122.     DrawText( Point( 0, 2*TEXTY ), aOutStr );
  123.  
  124.     aOutStr  = "Out-Size: ";
  125.     aOutStr += aOutputSize.Width();
  126.     aOutStr += " : ";
  127.     aOutStr += aOutputSize.Height();
  128.     DrawText( Point( 0, 3*TEXTY ), aOutStr );
  129. }
  130.  
  131. // --- WindowWithoutParent::WindowWithoutParent --------------------
  132.  
  133. WindowWithoutParent::WindowWithoutParent() :
  134.                          WorkWindow( NULL, WB_STDWORK )
  135. {
  136.     Font aFont;
  137.     aFont.ChangePitch( PITCH_FIXED );
  138.     ChangeFont( aFont );
  139. }
  140.  
  141. // --- WindowWithoutParent::Resize() -------------------------------
  142.  
  143. void WindowWithoutParent::Resize()
  144. {
  145.     Invalidate();
  146. }
  147.  
  148. // --- WindowWithoutParent::Move() ---------------------------------
  149.  
  150. void WindowWithoutParent::Move()
  151. {
  152.     Invalidate();
  153. }
  154.  
  155. // --- WindowWithoutParent::Paint() --------------------------------
  156.  
  157. void WindowWithoutParent::Paint( const Rectangle& )
  158. {
  159.     Point   aPosition( GetPosPixel() );
  160.     Point   aScreenPosition( OutputToScreenPixel( Point( 0, 0 ) ) );
  161.     Size    aSize( GetSizePixel() );
  162.     Size    aOutputSize( GetOutputSizePixel() );
  163.     String  aOutStr;
  164.  
  165.     aOutStr  = "Pos:      ";
  166.     aOutStr += aPosition.X();
  167.     aOutStr += " , ";
  168.     aOutStr += aPosition.Y();
  169.     DrawText( Point( 0, 0 ), aOutStr );
  170.  
  171.     aOutStr  = "Scr-Pos:  ";
  172.     aOutStr += aScreenPosition.X();
  173.     aOutStr += " , ";
  174.     aOutStr += aScreenPosition.Y();
  175.     DrawText( Point( 0, TEXTY ), aOutStr );
  176.  
  177.     aOutStr  = "Size:     ";
  178.     aOutStr += aSize.Width();
  179.     aOutStr += " : ";
  180.     aOutStr += aSize.Height();
  181.     DrawText( Point( 0, 2*TEXTY ), aOutStr );
  182.  
  183.     aOutStr  = "Out-Size: ";
  184.     aOutStr += aOutputSize.Width();
  185.     aOutStr += " : ";
  186.     aOutStr += aOutputSize.Height();
  187.     DrawText( Point( 0, 3*TEXTY ), aOutStr );
  188. }
  189.  
  190. // --- ChildWindow::ChildWindow ------------------------------------
  191.  
  192. ChildWindow::ChildWindow( Window* pParent ) :
  193.                  Window( pParent, WB_BORDER )
  194. {
  195.     Font aFont;
  196.     aFont.ChangePitch( PITCH_FIXED );
  197.     ChangeFont( aFont );
  198. }
  199.  
  200. // --- ChildWindow::Resize() ---------------------------------------
  201.  
  202. void ChildWindow::Resize()
  203. {
  204.     Invalidate();
  205. }
  206.  
  207. // --- ChildWindow::Move() -----------------------------------------
  208.  
  209. void ChildWindow::Move()
  210. {
  211.     Invalidate();
  212. }
  213.  
  214. // --- ChildWindow::Paint() ----------------------------------------
  215.  
  216. void ChildWindow::Paint( const Rectangle& )
  217. {
  218.     Point   aPosition( GetPosPixel() );
  219.     Point   aScreenPosition( OutputToScreenPixel( Point( 0, 0 ) ) );
  220.     Size    aSize( GetSizePixel() );
  221.     Size    aOutputSize( GetOutputSizePixel() );
  222.     String  aOutStr;
  223.  
  224.     aOutStr  = "Pos:      ";
  225.     aOutStr += aPosition.X();
  226.     aOutStr += " , ";
  227.     aOutStr += aPosition.Y();
  228.     DrawText( Point( 0, 0 ), aOutStr );
  229.  
  230.     aOutStr  = "Scr-Pos:  ";
  231.     aOutStr += aScreenPosition.X();
  232.     aOutStr += " , ";
  233.     aOutStr += aScreenPosition.Y();
  234.     DrawText( Point( 0, TEXTY ), aOutStr );
  235.  
  236.     aOutStr  = "Size:     ";
  237.     aOutStr += aSize.Width();
  238.     aOutStr += " : ";
  239.     aOutStr += aSize.Height();
  240.     DrawText( Point( 0, 2*TEXTY ), aOutStr );
  241.  
  242.     aOutStr  = "Out-Size: ";
  243.     aOutStr += aOutputSize.Width();
  244.     aOutStr += " : ";
  245.     aOutStr += aOutputSize.Height();
  246.     DrawText( Point( 0, 3*TEXTY ), aOutStr );
  247. }
  248.  
  249. // --- MyWindow::MyWindow ------------------------------------------
  250.  
  251. MyWindow::MyWindow() :
  252.               WorkWindow( NULL, WB_APP | WB_STDWORK ),
  253.               aWindowWithParent( this ),
  254.               aWindowWithoutParent(),
  255.               aChildWindow( this )
  256. {
  257.     aChildWindow.ChangeSizePixel( Size( WINDOWX,WINDOWY ) );
  258.     aChildWindow.ChangePosPixel( Point( 160,210 ) );
  259.     aChildWindow.Show();
  260.  
  261.     aWindowWithParent.ChangeSizePixel( Size( WINDOWX,WINDOWY ) );
  262.     aWindowWithParent.ChangePosPixel( Point( 305,30 ) );
  263.     aWindowWithParent.SetText( "With Parent" );
  264.     aWindowWithParent.Show();
  265.  
  266.     aWindowWithoutParent.ChangeSizePixel( Size( WINDOWX,WINDOWY ) );
  267.     aWindowWithoutParent.ChangePosPixel( Point( 25,30 ) );
  268.     aWindowWithoutParent.SetText( "Without Parent" );
  269.     aWindowWithoutParent.Show();
  270.  
  271.     ChangeSizePixel( Size( 540, 400 ) );
  272.     ChangePosPixel( Point( 0, 0 ) );
  273.     SetText( "Application Window" );
  274.     Show();
  275.  
  276.     aWindowWithoutParent.ToTop();
  277. }
  278.  
  279. // --- MyWindow::Move() --------------------------------------------
  280.  
  281. void MyWindow::Move()
  282. {
  283.     aChildWindow.Invalidate();
  284.     aWindowWithParent.Invalidate();
  285.     aWindowWithoutParent.Invalidate();
  286. }
  287.  
  288. // --- MyWindow::Resize() ------------------------------------------
  289.  
  290. void MyWindow::Resize()
  291. {
  292.     aChildWindow.Invalidate();
  293.     aWindowWithParent.Invalidate();
  294.     aWindowWithoutParent.Invalidate();
  295. }
  296.  
  297. // --- MyApp::Main() -----------------------------------------------
  298.  
  299. void MyApp::Main( int, char*[] )
  300. {
  301.     MyWindow aWindow;
  302.     Execute();
  303. }
  304.  
  305. // --- aMyApp ------------------------------------------------------
  306.  
  307. MyApp aMyApp;
  308.