home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n08
/
sketchsc.exe
/
USER.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-01
|
6KB
|
216 lines
//-----------------------------------------------------------------------
// USER.CPP: Implemenation for the user_interface (view) class
//-----------------------------------------------------------------------
#include "stdafx.h"
#include "sketch.h"
#include "user.h"
#include "data.h"
#include "mywin.h"
#include <limits.h> // for INT_MIN and INT_MAX
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// user_interface
IMPLEMENT_DYNCREATE(user_interface, CScrollView)
BEGIN_MESSAGE_MAP(user_interface, CScrollView)
//{{AFX_MSG_MAP(user_interface)
ON_COMMAND(ID_DISPLAYASTEXT, OnDisplayastext)
ON_UPDATE_COMMAND_UI(ID_DISPLAYASTEXT, OnUpdateDisplayastext)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_SIZE()
ON_COMMAND(ID_TRACELINE, OnTraceline)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// user_interface construction/destruction
user_interface::user_interface() : dwg_object (0)
, display_as_text (0)
{
// Install random mapping mode and size. This is required by the
// framework. OnInitialUpdate (called after the document object
// exists) will set it for real.
SetScrollSizes( MM_TEXT, CSize(0, 0) );
}
/*virtual*/ user_interface::~user_interface()
{}
/////////////////////////////////////////////////////////////////////////////
// user_interface drawing
//-----------------------------------------------------------------------
void user_interface::OnDraw(CDC* pDC)
{
data_interface* pDoc = GetDocument();
ASSERT_VALID(pDoc);
device dc(pDC);
rect_clip clip_rect( dc );
if( !clip_rect.IsRectEmpty() )
{
if( display_as_text )
pDoc->print_all_objects_in_this_rect( &dc, CRect(0,0,INT_MAX,INT_MAX), 1 );
else
pDoc->print_all_objects_in_this_rect( &dc, clip_rect, 0 );
}
}
//-----------------------------------------------------------------------
/*afx_msg*/ void user_interface::OnSize(UINT nType, int cx, int cy)
{
GetDocument()->set_up_scrolling( this );
CScrollView::OnSize(nType, cx, cy);
}
//-----------------------------------------------------------------------
/*virtual*/ void user_interface::OnInitialUpdate( void )
{
GetDocument()->set_up_scrolling( this );
CScrollView::OnInitialUpdate();
}
//-----------------------------------------------------------------------
/*virtual*/ void user_interface::OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint )
{
// This function is called implicitly by OnInitialUpdate() as well
// as being called from UpdateAllViews. In the former case, all
// arguments are zero or NULL. It is also called explicitly
// to update an entire window when all objects in the document
// have been deleted.
Invalidate();
}
//-----------------------------------------------------------------------
void user_interface::new_drawing_element( drawing_element *element )
{
if( display_as_text ) // for text displays, just invalidate the whole window
Invalidate();
else // if image, invaliate only the rectangle for the new object.
{
device dc ( this );
rect_client client_rect ( dc );
if( element->is_in( client_rect ) )
element->invalidate(this);
}
}
/////////////////////////////////////////////////////////////////////////////
// user_interface printing
BOOL user_interface::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void user_interface::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void user_interface::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// user_interface diagnostics
#ifdef _DEBUG
void user_interface::AssertValid() const
{
CScrollView::AssertValid();
}
void user_interface::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
data_interface* user_interface::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(data_interface)));
return (data_interface*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// user_interface message handlers
void user_interface::OnLButtonDown( UINT flags, CPoint point )
{
// We don't want to accept any mouse input at all if displaying objects
// as text. By not calling SetCapture(), OnMouseMove() and OnLButtonUp()
// are both effectivly disabled.
if( !display_as_text )
{
device dc ( this );
dc.DPtoLP ( &point );
SetCapture();
dwg_object = GetDocument()->give_me_an_empty_drawing_element();
dwg_object->start_load( point, &dc );
}
}
void user_interface::OnMouseMove( UINT flags, CPoint point )
{
if( ::GetCapture() == m_hWnd && dwg_object )
{
device dc( this );
dc.DPtoLP( &point );
dwg_object->mouse_has_moved( point, &dc );
}
}
void user_interface::OnLButtonUp( UINT flags, CPoint point )
{
if( ::GetCapture() == m_hWnd && dwg_object )
{
device dc( this );
dc.DPtoLP( &point ); // convert point to document coordinates
ReleaseCapture();
int redraw =
dwg_object ->end_load (point, &dc );
GetDocument()->am_done_loading(this, dwg_object );
if( redraw ) // Update all of current view to clean up after
Invalidate(); // creating a line. (Document doesn't update current view.)
dwg_object = NULL;
}
}
void user_interface::OnDisplayastext()
{
display_as_text = !display_as_text ;
Invalidate();
}
void user_interface::OnUpdateDisplayastext(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck( display_as_text );
}
void user_interface::OnTraceline()
{
TRACE("================================================\n");
}