home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * PAINT.CXX
- * (c) 1992-1994 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- #include "paintwin.hxx"
- #include "paint.hxx"
- #include "paint.hrc"
-
- // --- aPaintApp ---------------------------------------------------
-
- PaintApp aPaintApp;
-
- // --- PaintApp::Main() --------------------------------------------
-
- void PaintApp::Main( int, char*[] )
- {
- EnableSVLook();
-
- #if defined( WIN ) || defined( WNT ) || defined( OS2 )
- #ifdef OS2
- Font aFont( "Helv", Size( 0, 12 ) );
- #else
- Font aFont( "MS Sans Serif", Size( 0, 12 ) );
- #endif
- aFont.ChangeFamily( FAMILY_SWISS );
- aFont.ChangeWeight( WEIGHT_BOLD );
- ChangeAppFont( aFont );
- #endif
-
- Help aHelp;
- ChangeHelp( &aHelp );
- EnableHelp( HELPMODE_ALL );
-
- MenuBar aInitMenu( ResId( MENU_INIT ) );
- MenuBar aAppMenu( ResId( MENU_MENUBAR ) );
- pInitMenu = &aInitMenu;
- pAppMenu = &aAppMenu;
- PaintAppWin aWin;
-
- SetInitMenu();
-
- aWin.Show();
-
- Execute();
- }
-
- // --- PaintApp::SetInitMenu() -------------------------------------
-
- void PaintApp::SetInitMenu()
- {
- ChangeAppMenu( pInitMenu );
- ChangeMDIMenu( NULL );
-
- ToolBox* pBox = ((PaintAppWin*)GetAppWindow())->GetToolBox();
- pBox->EnableItem( MI_FILESAVE, FALSE );
- pBox->EnableItem( MI_FILEPRINT, FALSE );
- pBox->EnableItem( MI_DRAWPOINT, FALSE );
- pBox->EnableItem( MI_DRAWLINE, FALSE );
- pBox->EnableItem( MI_DRAWRECT, FALSE );
- pBox->EnableItem( MI_DRAWELLIPSE, FALSE );
- pBox->EnableItem( MI_DRAWARC, FALSE );
- pBox->EnableItem( MI_DRAWPIE, FALSE );
- pBox->EnableItem( MI_DRAWPOLYGON, FALSE );
- pBox->EnableItem( MI_DRAWTEXT, FALSE );
- pBox->EnableItem( MI_DRAWINVERTRECT, FALSE );
- }
-
- // --- PaintApp::SetAppMenu() --------------------------------------
-
- void PaintApp::SetAppMenu()
- {
- ChangeAppMenu( pAppMenu );
- ChangeMDIMenu( pAppMenu->GetPopupMenu( MENU_WINDOW ) );
-
- ToolBox* pBox = ((PaintAppWin*)GetAppWindow())->GetToolBox();
- pBox->EnableItem( MI_FILESAVE, TRUE );
- pBox->EnableItem( MI_FILEPRINT, TRUE );
- pBox->EnableItem( MI_DRAWPOINT, TRUE );
- pBox->EnableItem( MI_DRAWLINE, TRUE );
- pBox->EnableItem( MI_DRAWRECT, TRUE );
- pBox->EnableItem( MI_DRAWELLIPSE, TRUE );
- pBox->EnableItem( MI_DRAWARC, TRUE );
- pBox->EnableItem( MI_DRAWPIE, TRUE );
- pBox->EnableItem( MI_DRAWPOLYGON, TRUE );
- pBox->EnableItem( MI_DRAWTEXT, TRUE );
- pBox->EnableItem( MI_DRAWINVERTRECT, TRUE );
- }
-
- // --- PaintAppWin::PaintAppWin() ----------------------------------
-
- PaintAppWin::PaintAppWin() :
- WorkWindow( NULL, WB_APP | WB_STDWORK ),
- aBox( this, ResId( TOOLBOX_APP ) ),
- aStatus( this )
- {
- ChangeIcon( Icon( ResId( ICON_APP ) ) );
- SetText( "StarView Paint" );
-
- MenuBar* pMenu = ((PaintApp*)pApp)->GetInitMenu();
- pMenu->PushActivateHdl(
- LINK( this, PaintAppWin, ActivateHdl ) );
- pMenu->PushHighlightHdl(
- LINK( this, PaintAppWin, HighlightHdl ) );
- pMenu->PushSelectHdl(
- LINK( this, PaintAppWin, SelectHdl ) );
- pMenu->PushDeactivateHdl(
- LINK( this, PaintAppWin, DeactivateHdl ) );
-
- pMenu = ((PaintApp*)pApp)->GetAppMenu();
- pMenu->PushActivateHdl(
- LINK( this, PaintAppWin, ActivateHdl ) );
- pMenu->PushDeactivateHdl(
- LINK( this, PaintAppWin, DeactivateHdl ) );
- pMenu->PushHighlightHdl(
- LINK( this, PaintAppWin, HighlightHdl ) );
- pMenu->PushSelectHdl(
- LINK( this, PaintAppWin, SelectHdl ) );
-
- aBox.ChangeActivateHdl( LINK( this, PaintAppWin, ActivateBoxHdl ) );
- aBox.ChangeDeactivateHdl( LINK( this, PaintAppWin, DeactivateBoxHdl ) );
- aBox.ChangeHighlightHdl( LINK( this, PaintAppWin, HighlightBoxHdl ) );
- aBox.ChangeSelectHdl( LINK( this, PaintAppWin, SelectBoxHdl ) );
-
- nBoxHeight = aBox.CalcWindowSizePixel().Height();
- nBarHeight = aStatus.GetSizePixel().Height();
- }
-
- // --- PaintAppWin::~PaintAppWin() ---------------------------------
-
- PaintAppWin::~PaintAppWin()
- {
- Hide();
- }
-
- // --- PaintAppWin::Resize() ---------------------------------------
-
- void PaintAppWin::Resize()
- {
- aBox.SetPosSizePixel( Point( 0, 0 ),
- Size( GetOutputSizePixel().Width(), nBoxHeight ) );
- aStatus.SetPosSizePixel( Point( 0, GetOutputSizePixel().Height()-nBarHeight ),
- Size( GetOutputSizePixel().Width(), nBarHeight ) );
- }
-
- // --- PaintAppWin::Close() ----------------------------------------
-
- BOOL PaintAppWin::Close()
- {
- if ( ((PaintApp*)pApp)->CloseAll() )
- return WorkWindow::Close();
- else
- return FALSE;
- }
-
- // --- PaintAppWin::ActivateHdl() ----------------------------------
-
- long PaintAppWin::ActivateHdl( Menu* pMenu )
- {
- if ( pMenu == pApp->GetAppMenu() )
- aStatus.HideItems();
- else if ( pMenu == pApp->GetAppMenu()->GetPopupMenu( MENU_EDIT ) )
- {
- if ( !Clipboard::HasFormat( FORMAT_GDIMETAFILE ) )
- pMenu->EnableItem( MI_EDITPASTE, FALSE );
- }
-
- return TRUE;
- }
-
- // --- PaintAppWin::DeactivateHdl() --------------------------------
-
- long PaintAppWin::DeactivateHdl( Menu* pMenu )
- {
- if ( pMenu == pApp->GetAppMenu() )
- {
- aStatus.SetText( String( ResId( STRING_READY ) ) );
- aStatus.ShowItems();
- }
- else if ( pMenu == pApp->GetAppMenu()->GetPopupMenu( MENU_EDIT ) )
- pMenu->EnableItem( MI_EDITPASTE, TRUE );
-
- return TRUE;
- }
-
- // --- PaintAppWin::HighlightHdl() ---------------------------------
-
- long PaintAppWin::HighlightHdl( Menu* pMenu )
- {
- aStatus.SetText( pMenu->GetHelpText( pMenu->GetCurItemId() ) );
- return TRUE;
- }
-
- // --- PaintAppWin::SelectHdl() ------------------------------------
-
- long PaintAppWin::SelectHdl( Menu* pMenu )
- {
- Command( pMenu->GetCurItemId() );
- return TRUE;
- }
-
- // --- PaintAppWin::ActivateBoxHdl() -------------------------------
-
- void PaintAppWin::ActivateBoxHdl( ToolBox* )
- {
- aStatus.HideItems();
- }
-
- // --- PaintAppWin::DeactivateBoxHdl() -----------------------------
-
- void PaintAppWin::DeactivateBoxHdl( ToolBox* )
- {
- aStatus.SetText( String( ResId( STRING_READY ) ) );
- aStatus.ShowItems();
- }
-
- // --- PaintAppWin::HighlightBoxHdl() ------------------------------
-
- void PaintAppWin::HighlightBoxHdl( ToolBox* pBox )
- {
- aStatus.SetText( pBox->GetHelpText( pBox->GetCurItemId() ) );
- }
-
- // --- PaintAppWin::SelectBoxHdl() ---------------------------------
-
- void PaintAppWin::SelectBoxHdl( ToolBox* pBox )
- {
- Command( pBox->GetCurItemId() );
- }
-
- // --- PaintAppWin::Open() -----------------------------------------
-
- void PaintAppWin::Open()
- {
- FileDialog aDlg( this, WB_OPEN | WB_SVLOOK | WB_STDMODAL );
-
- if ( aDlg.Execute() )
- new PaintDocWin( aDlg.GetPath() );
- }
-
- // --- PaintAppWin::Commad() ---------------------------------------
-
- BOOL PaintAppWin::Command( USHORT nItemId )
- {
- switch ( nItemId )
- {
- case MI_FILENEW:
- new PaintDocWin;
- break;
- case MI_FILEOPEN:
- Open();
- break;
- case MI_FILEQUIT:
- Close();
- break;
-
- case MI_VIEWSTATUS:
- {
- PopupMenu* pMenu = pApp->GetAppMenu()->GetPopupMenu( MENU_VIEW );
- if ( aStatus.IsVisible() )
- {
- aStatus.Hide();
- pMenu->CheckItem( MI_VIEWSTATUS, FALSE );
- }
- else
- {
- aStatus.Show();
- pMenu->CheckItem( MI_VIEWSTATUS, TRUE );
- }
- }
- break;
-
- case MI_WINDOWCASCADE:
- ((MDIApplication*)pApp)->Cascade();
- break;
- case MI_WINDOWTILE:
- ((MDIApplication*)pApp)->Tile();
- break;
- case MI_WINDOWHORZ:
- ((MDIApplication*)pApp)->Horizontal();
- break;
- case MI_WINDOWVERT:
- ((MDIApplication*)pApp)->Vertical();
- break;
- case MI_WINDOWARRANGE:
- ((MDIApplication*)pApp)->Arrange();
- break;
- case MI_WINDOWCLOSEALL:
- ((MDIApplication*)pApp)->CloseAll();
- break;
-
- case MI_HELPINDEX:
- {
- Help().Start( HELP_INDEX );
- }
- break;
- case MI_HELPONHELP:
- {
- Help().Start( HELP_HELPONHELP );
- }
- break;
- case MI_HELPABOUT:
- {
- String aStr( "StarView Paint\n"
- "(c) 1992-1994 STAR DIVISION" );
- InfoBox( NULL, aStr ).Execute();
- }
- break;
-
- default:
- ((PaintDocWin*)((MDIApplication*)pApp)->
- GetActiveWindow())->Command( nItemId );
- }
-
- return TRUE;
- }
-
- // --- StatusLine::StatusLine() ------------------------------------
-
- StatusLine::StatusLine( Window* pParent ) :
- StatusBar( pParent, WB_BORDER | WB_SVLOOK ),
- aIntn( pApp->GetAppInternational() )
- {
- pApp->InsertIdleHdl( LINK( this, StatusLine, IdleHdl ), 1 );
-
- InsertItem( 1, GetTextSize(
- aIntn.GetDate( Date( 11,11,1111 ) ) ).Width()+2 );
- InsertItem( 2, GetTextSize(
- aIntn.GetTime( Time( 11,11,11 ) ) ).Width()+2 );
-
- IdleHdl( NULL );
-
- Show();
- }
-
- // --- StatusLine::IdleHdl() ---------------------------------------
-
- void StatusLine::IdleHdl( void* )
- {
- SetItemText( 1, aIntn.GetDate( Date() ) );
- SetItemText( 2, aIntn.GetTime( Time() ) );
- }
-