home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * EXAMPLE4.CXX
- * (c) 1992 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- #include "example4.hrc"
- #include "about4.hrc"
- #include "about4.hxx"
-
- // --- class MyApp -------------------------------------------------
-
- class MyApp : public Application
- {
- public:
- virtual void Main( int, char*[] );
- };
-
- // --- class MyWin -------------------------------------------------
-
- class MyWin : public WorkWindow
- {
- private:
- USHORT nColor;
- USHORT nWidth;
- Point aLastPoint;
-
- public:
- MyWin();
-
- virtual BOOL Close();
- virtual void MouseButtonDown( const MouseEvent& rMEvt );
- virtual void MouseButtonUp( const MouseEvent& rMEvt );
- virtual void MouseMove( const MouseEvent& rMEvt );
- long FileSelect( Menu* pMenu );
- long ColorSelect( Menu* pMenu );
- long WidthSelect( Menu* pMenu );
- };
-
- // --- MyWin::MyWin() ----------------------------------------------
-
- MyWin::MyWin() : WorkWindow( NULL, WB_STDWORK | WB_APP )
- {
- nColor = 0;
- nWidth = 0;
- }
-
- // --- MyWin::Close() ----------------------------------------------
-
- BOOL MyWin::Close()
- {
- QueryBox aBox( this, WB_OK_CANCEL | WB_DEF_OK, "Exit Paint" );
-
- if ( aBox.Execute() == RET_OK )
- return WorkWindow::Close();
- else
- return FALSE;
- }
-
- // --- MyWin::MouseButtonDown() ------------------------------------
-
- void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
- {
- CaptureMouse();
- aLastPoint = rMEvt.GetPosPixel();
- }
-
- // --- MyWin::MouseButtonUp() --------------------------------------
-
- void MyWin::MouseButtonUp( const MouseEvent& )
- {
- ReleaseMouse();
- }
-
- // --- MyWin::MouseMove() ------------------------------------------
-
- void MyWin::MouseMove( const MouseEvent& rMEvt )
- {
- if ( rMEvt.GetMode() == MOUSE_SIMPLEDRAG )
- {
- DrawLine( aLastPoint, rMEvt.GetPosPixel() );
- aLastPoint = rMEvt.GetPosPixel();
- }
- }
-
- // --- MyWin::FileSelect() -----------------------------------------
-
- long MyWin::FileSelect( Menu* pMenu )
- {
- switch ( pMenu->GetCurItemId() )
- {
- case MID_ABOUT:
- {
- AboutBox( this, ResId( RID_ABOUTBOX ) ).Execute();
- }
- break;
- case MID_QUIT:
- Close();
- break;
- }
-
- return TRUE;
- }
-
- // --- MyWin::ColorSelect() ----------------------------------------
-
- long MyWin::ColorSelect( Menu* pMenu )
- {
- if ( nColor )
- pMenu->CheckItem( nColor, FALSE );
- nColor = pMenu->GetCurItemId();
- pMenu->CheckItem( nColor );
-
- Pen aPen = GetPen();
- switch( nColor )
- {
- case MID_PENRED:
- aPen.ChangeColor( Color( COL_RED ) );
- break;
- case MID_PENBLUE:
- aPen.ChangeColor( Color( COL_BLUE ) );
- break;
- case MID_PENYELLOW:
- aPen.ChangeColor( Color( COL_YELLOW ) );
- break;
- }
- ChangePen( aPen );
-
- return TRUE;
- }
-
- // --- MyWin::WidthSelect() ----------------------------------------
-
- long MyWin::WidthSelect( Menu* pMenu )
- {
- if ( nWidth )
- pMenu->CheckItem( nWidth, FALSE );
- nWidth = pMenu->GetCurItemId();
- pMenu->CheckItem( nWidth );
-
- Pen aPen = GetPen();
- switch ( nWidth )
- {
- case MID_PENSMALL:
- aPen.ChangeWidth( 1 );
- break;
- case MID_PENMEDIUM:
- aPen.ChangeWidth( 4 );
- break;
- case MID_PENTHICK:
- aPen.ChangeWidth( 8 );
- break;
- }
- ChangePen( aPen );
-
- return TRUE;
- }
-
- // --- MyApp::Main() -----------------------------------------------
-
- void MyApp::Main( int, char*[] )
- {
- MyWin aMainWin;
- MenuBar aMenuBar( ResId( MID_MENUBAR ) );
-
- aMenuBar.GetPopupMenu( MID_FILE )->
- PushSelectHdl( LINK( &aMainWin, MyWin::FileSelect ) );
- aMenuBar.GetPopupMenu( MID_PENCOLOR )->
- PushSelectHdl( LINK( &aMainWin, MyWin::ColorSelect ) );
- aMenuBar.GetPopupMenu( MID_PENWIDTH )->
- PushSelectHdl( LINK( &aMainWin, MyWin::WidthSelect ) );
-
- ChangeAppMenu( &aMenuBar );
-
- aMainWin.SetText( "StarView Paint" );
- aMainWin.Show();
-
- Execute();
-
- PopupMenu* pDelMenu;
- pDelMenu = aMenuBar.ChangePopupMenu( MID_FILE, NULL );
- delete pDelMenu;
- pDelMenu = aMenuBar.ChangePopupMenu( MID_PENCOLOR, NULL );
- delete pDelMenu;
- pDelMenu = aMenuBar.ChangePopupMenu( MID_PENWIDTH, NULL );
- delete pDelMenu;
- }
-
- // --- aMyApp ------------------------------------------------------
-
- MyApp aMyApp;
-
- #ifdef MAC
- Application* pApp = &aMyApp;
- #endif
-