home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / pm2blci / german / paint.cx_ / PAINT.CXX
Encoding:
C/C++ Source or Header  |  1994-01-18  |  9.9 KB  |  345 lines

  1. /*******************************************************************
  2. *  PAINT.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #include "paintwin.hxx"
  9. #include "paint.hxx"
  10. #include "paint.hrc"
  11.  
  12. // --- aPaintApp ---------------------------------------------------
  13.  
  14. PaintApp aPaintApp;
  15.  
  16. // --- PaintApp::Main() --------------------------------------------
  17.  
  18. void PaintApp::Main( int, char*[] )
  19. {
  20.     EnableSVLook();
  21.  
  22. #if defined( WIN ) || defined( WNT ) || defined( OS2 )
  23. #ifdef OS2
  24.     Font aFont( "Helv", Size( 0, 12 ) );
  25. #else
  26.     Font aFont( "MS Sans Serif", Size( 0, 12 ) );
  27. #endif
  28.     aFont.ChangeFamily( FAMILY_SWISS );
  29.     aFont.ChangeWeight( WEIGHT_BOLD );
  30.     ChangeAppFont( aFont );
  31. #endif
  32.  
  33.     Help aHelp;
  34.     ChangeHelp( &aHelp );
  35.     EnableHelp( HELPMODE_ALL );
  36.  
  37.     MenuBar     aInitMenu( ResId( MENU_INIT ) );
  38.     MenuBar     aAppMenu( ResId( MENU_MENUBAR ) );
  39.     pInitMenu = &aInitMenu;
  40.     pAppMenu  = &aAppMenu;
  41.     PaintAppWin aWin;
  42.  
  43.     SetInitMenu();
  44.  
  45.     aWin.Show();
  46.  
  47.     Execute();
  48. }
  49.  
  50. // --- PaintApp::SetInitMenu() -------------------------------------
  51.  
  52. void PaintApp::SetInitMenu()
  53. {
  54.     ChangeAppMenu( pInitMenu );
  55.     ChangeMDIMenu( NULL );
  56.  
  57.     ToolBox* pBox = ((PaintAppWin*)GetAppWindow())->GetToolBox();
  58.     pBox->EnableItem( MI_FILESAVE,       FALSE );
  59.     pBox->EnableItem( MI_FILEPRINT,      FALSE );
  60.     pBox->EnableItem( MI_DRAWPOINT,      FALSE );
  61.     pBox->EnableItem( MI_DRAWLINE,       FALSE );
  62.     pBox->EnableItem( MI_DRAWRECT,       FALSE );
  63.     pBox->EnableItem( MI_DRAWELLIPSE,    FALSE );
  64.     pBox->EnableItem( MI_DRAWARC,        FALSE );
  65.     pBox->EnableItem( MI_DRAWPIE,        FALSE );
  66.     pBox->EnableItem( MI_DRAWPOLYGON,    FALSE );
  67.     pBox->EnableItem( MI_DRAWTEXT,       FALSE );
  68.     pBox->EnableItem( MI_DRAWINVERTRECT, FALSE );
  69. }
  70.  
  71. // --- PaintApp::SetAppMenu() --------------------------------------
  72.  
  73. void PaintApp::SetAppMenu()
  74. {
  75.     ChangeAppMenu( pAppMenu );
  76.     ChangeMDIMenu( pAppMenu->GetPopupMenu( MENU_WINDOW ) );
  77.  
  78.     ToolBox* pBox = ((PaintAppWin*)GetAppWindow())->GetToolBox();
  79.     pBox->EnableItem( MI_FILESAVE,       TRUE );
  80.     pBox->EnableItem( MI_FILEPRINT,      TRUE );
  81.     pBox->EnableItem( MI_DRAWPOINT,      TRUE );
  82.     pBox->EnableItem( MI_DRAWLINE,       TRUE );
  83.     pBox->EnableItem( MI_DRAWRECT,       TRUE );
  84.     pBox->EnableItem( MI_DRAWELLIPSE,    TRUE );
  85.     pBox->EnableItem( MI_DRAWARC,        TRUE );
  86.     pBox->EnableItem( MI_DRAWPIE,        TRUE );
  87.     pBox->EnableItem( MI_DRAWPOLYGON,    TRUE );
  88.     pBox->EnableItem( MI_DRAWTEXT,       TRUE );
  89.     pBox->EnableItem( MI_DRAWINVERTRECT, TRUE );
  90. }
  91.  
  92. // --- PaintAppWin::PaintAppWin() ----------------------------------
  93.  
  94. PaintAppWin::PaintAppWin() :
  95.                  WorkWindow( NULL, WB_APP | WB_STDWORK ),
  96.                  aBox( this, ResId( TOOLBOX_APP ) ),
  97.                  aStatus( this )
  98. {
  99.     ChangeIcon( Icon( ResId( ICON_APP ) ) );
  100.     SetText( "StarView Paint" );
  101.  
  102.     MenuBar* pMenu = ((PaintApp*)pApp)->GetInitMenu();
  103.     pMenu->PushActivateHdl(
  104.                LINK( this, PaintAppWin, ActivateHdl ) );
  105.     pMenu->PushHighlightHdl(
  106.                LINK( this, PaintAppWin, HighlightHdl ) );
  107.     pMenu->PushSelectHdl(
  108.                 LINK( this, PaintAppWin, SelectHdl ) );
  109.     pMenu->PushDeactivateHdl(
  110.                LINK( this, PaintAppWin, DeactivateHdl ) );
  111.  
  112.     pMenu = ((PaintApp*)pApp)->GetAppMenu();
  113.     pMenu->PushActivateHdl(
  114.                LINK( this, PaintAppWin, ActivateHdl ) );
  115.     pMenu->PushDeactivateHdl(
  116.                LINK( this, PaintAppWin, DeactivateHdl ) );
  117.     pMenu->PushHighlightHdl(
  118.                LINK( this, PaintAppWin, HighlightHdl ) );
  119.     pMenu->PushSelectHdl(
  120.                 LINK( this, PaintAppWin, SelectHdl ) );
  121.  
  122.     aBox.ChangeActivateHdl(   LINK( this, PaintAppWin, ActivateBoxHdl   ) );
  123.     aBox.ChangeDeactivateHdl( LINK( this, PaintAppWin, DeactivateBoxHdl ) );
  124.     aBox.ChangeHighlightHdl(  LINK( this, PaintAppWin, HighlightBoxHdl  ) );
  125.     aBox.ChangeSelectHdl(     LINK( this, PaintAppWin, SelectBoxHdl     ) );
  126.  
  127.     nBoxHeight = aBox.CalcWindowSizePixel().Height();
  128.     nBarHeight = aStatus.GetSizePixel().Height();
  129. }
  130.  
  131. // --- PaintAppWin::~PaintAppWin() ---------------------------------
  132.  
  133. PaintAppWin::~PaintAppWin()
  134. {
  135.     Hide();
  136. }
  137.  
  138. // --- PaintAppWin::Resize() ---------------------------------------
  139.  
  140. void PaintAppWin::Resize()
  141. {
  142.     aBox.SetPosSizePixel( Point( 0, 0 ),
  143.                           Size( GetOutputSizePixel().Width(), nBoxHeight ) );
  144.     aStatus.SetPosSizePixel( Point( 0, GetOutputSizePixel().Height()-nBarHeight ),
  145.                              Size( GetOutputSizePixel().Width(), nBarHeight ) );
  146. }
  147.  
  148. // --- PaintAppWin::Close() ----------------------------------------
  149.  
  150. BOOL PaintAppWin::Close()
  151. {
  152.     if ( ((PaintApp*)pApp)->CloseAll() )
  153.         return WorkWindow::Close();
  154.     else
  155.         return FALSE;
  156. }
  157.  
  158. // --- PaintAppWin::ActivateHdl() ----------------------------------
  159.  
  160. long PaintAppWin::ActivateHdl( Menu* pMenu )
  161. {
  162.     if ( pMenu == pApp->GetAppMenu() )
  163.         aStatus.HideItems();
  164.     else if ( pMenu == pApp->GetAppMenu()->GetPopupMenu( MENU_EDIT ) )
  165.     {
  166.         if ( !Clipboard::HasFormat( FORMAT_GDIMETAFILE ) )
  167.             pMenu->EnableItem( MI_EDITPASTE, FALSE );
  168.     }
  169.  
  170.     return TRUE;
  171. }
  172.  
  173. // --- PaintAppWin::DeactivateHdl() --------------------------------
  174.  
  175. long PaintAppWin::DeactivateHdl( Menu* pMenu )
  176. {
  177.     if ( pMenu == pApp->GetAppMenu() )
  178.     {
  179.         aStatus.SetText( String( ResId( STRING_READY ) ) );
  180.         aStatus.ShowItems();
  181.     }
  182.     else if ( pMenu == pApp->GetAppMenu()->GetPopupMenu( MENU_EDIT ) )
  183.         pMenu->EnableItem( MI_EDITPASTE, TRUE );
  184.  
  185.     return TRUE;
  186. }
  187.  
  188. // --- PaintAppWin::HighlightHdl() ---------------------------------
  189.  
  190. long PaintAppWin::HighlightHdl( Menu* pMenu )
  191. {
  192.     aStatus.SetText( pMenu->GetHelpText( pMenu->GetCurItemId() ) );
  193.     return TRUE;
  194. }
  195.  
  196. // --- PaintAppWin::SelectHdl() ------------------------------------
  197.  
  198. long PaintAppWin::SelectHdl( Menu* pMenu )
  199. {
  200.     Command( pMenu->GetCurItemId() );
  201.     return TRUE;
  202. }
  203.  
  204. // --- PaintAppWin::ActivateBoxHdl() -------------------------------
  205.  
  206. void PaintAppWin::ActivateBoxHdl( ToolBox* )
  207. {
  208.     aStatus.HideItems();
  209. }
  210.  
  211. // --- PaintAppWin::DeactivateBoxHdl() -----------------------------
  212.  
  213. void PaintAppWin::DeactivateBoxHdl( ToolBox* )
  214. {
  215.     aStatus.SetText( String( ResId( STRING_READY ) ) );
  216.     aStatus.ShowItems();
  217. }
  218.  
  219. // --- PaintAppWin::HighlightBoxHdl() ------------------------------
  220.  
  221. void PaintAppWin::HighlightBoxHdl( ToolBox* pBox )
  222. {
  223.     aStatus.SetText( pBox->GetHelpText( pBox->GetCurItemId() ) );
  224. }
  225.  
  226. // --- PaintAppWin::SelectBoxHdl() ---------------------------------
  227.  
  228. void PaintAppWin::SelectBoxHdl( ToolBox* pBox )
  229. {
  230.     Command( pBox->GetCurItemId() );
  231. }
  232.  
  233. // --- PaintAppWin::Open() -----------------------------------------
  234.  
  235. void PaintAppWin::Open()
  236. {
  237.     FileDialog aDlg( this, WB_OPEN | WB_SVLOOK | WB_STDMODAL );
  238.  
  239.     if ( aDlg.Execute() )
  240.         new PaintDocWin( aDlg.GetPath() );
  241. }
  242.  
  243. // --- PaintAppWin::Commad() ---------------------------------------
  244.  
  245. BOOL PaintAppWin::Command( USHORT nItemId )
  246. {
  247.     switch ( nItemId )
  248.     {
  249.         case MI_FILENEW:
  250.             new PaintDocWin;
  251.             break;
  252.         case MI_FILEOPEN:
  253.             Open();
  254.             break;
  255.         case MI_FILEQUIT:
  256.             Close();
  257.             break;
  258.  
  259.         case MI_VIEWSTATUS:
  260.             {
  261.             PopupMenu* pMenu = pApp->GetAppMenu()->GetPopupMenu( MENU_VIEW );
  262.             if ( aStatus.IsVisible() )
  263.             {
  264.                 aStatus.Hide();
  265.                 pMenu->CheckItem( MI_VIEWSTATUS, FALSE );
  266.             }
  267.             else
  268.             {
  269.                 aStatus.Show();
  270.                 pMenu->CheckItem( MI_VIEWSTATUS, TRUE );
  271.             }
  272.             }
  273.             break;
  274.  
  275.         case MI_WINDOWCASCADE:
  276.             ((MDIApplication*)pApp)->Cascade();
  277.             break;
  278.         case MI_WINDOWTILE:
  279.             ((MDIApplication*)pApp)->Tile();
  280.             break;
  281.         case MI_WINDOWHORZ:
  282.             ((MDIApplication*)pApp)->Horizontal();
  283.             break;
  284.         case MI_WINDOWVERT:
  285.             ((MDIApplication*)pApp)->Vertical();
  286.             break;
  287.         case MI_WINDOWARRANGE:
  288.             ((MDIApplication*)pApp)->Arrange();
  289.             break;
  290.         case MI_WINDOWCLOSEALL:
  291.             ((MDIApplication*)pApp)->CloseAll();
  292.             break;
  293.  
  294.         case MI_HELPINDEX:
  295.             {
  296.             Help().Start( HELP_INDEX );
  297.             }
  298.             break;
  299.         case MI_HELPONHELP:
  300.             {
  301.             Help().Start( HELP_HELPONHELP );
  302.             }
  303.             break;
  304.         case MI_HELPABOUT:
  305.             {
  306.             String aStr( "StarView Paint\n"
  307.                          "(c) 1992-1994 STAR DIVISION" );
  308.             InfoBox( NULL, aStr ).Execute();
  309.             }
  310.             break;
  311.  
  312.         default:
  313.             ((PaintDocWin*)((MDIApplication*)pApp)->
  314.                 GetActiveWindow())->Command( nItemId );
  315.     }
  316.  
  317.     return TRUE;
  318. }
  319.  
  320. // --- StatusLine::StatusLine() ------------------------------------
  321.  
  322. StatusLine::StatusLine( Window* pParent ) :
  323.                  StatusBar( pParent, WB_BORDER | WB_SVLOOK ),
  324.                  aIntn( pApp->GetAppInternational() )
  325. {
  326.     pApp->InsertIdleHdl( LINK( this, StatusLine, IdleHdl ), 1 );
  327.  
  328.     InsertItem( 1, GetTextSize(
  329.                         aIntn.GetDate( Date( 11,11,1111 ) ) ).Width()+2 );
  330.     InsertItem( 2, GetTextSize(
  331.                         aIntn.GetTime( Time( 11,11,11 ) ) ).Width()+2 );
  332.  
  333.     IdleHdl( NULL );
  334.  
  335.     Show();
  336. }
  337.  
  338. // --- StatusLine::IdleHdl() ---------------------------------------
  339.  
  340. void StatusLine::IdleHdl( void* )
  341. {
  342.     SetItemText( 1, aIntn.GetDate( Date() ) );
  343.     SetItemText( 2, aIntn.GetTime( Time() ) );
  344. }
  345.