home *** CD-ROM | disk | FTP | other *** search
- // OCRView.cpp : implementation of the COCRDEMOView class
- //
-
- #include "stdafx.h"
- #include "OCRDEMO.h"
-
- #include "OCRDoc.h"
- #include "CntrItem.h"
- #include "OCRView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- extern COCRApp theApp;
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMOView
-
- IMPLEMENT_DYNCREATE(COCRDEMOView, CFormView)
-
- BEGIN_MESSAGE_MAP(COCRDEMOView, CFormView)
- //{{AFX_MSG_MAP(COCRDEMOView)
- ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
- ON_WM_SETFOCUS()
- ON_WM_SIZE()
- ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
- ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
- ON_COMMAND(ID_VIEW_FITIMAGETOWINDOW, OnViewFitimagetowindow)
- ON_UPDATE_COMMAND_UI(ID_VIEW_FITIMAGETOWINDOW, OnUpdateViewFitimagetowindow)
- ON_COMMAND(ID_VIEW_NORMAL, OnViewNormal)
- ON_UPDATE_COMMAND_UI(ID_VIEW_NORMAL, OnUpdateViewNormal)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMOView construction/destruction
-
- COCRDEMOView::COCRDEMOView()
- : CFormView(COCRDEMOView::IDD)
- {
- //{{AFX_DATA_INIT(COCRDEMOView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pSelection = NULL;
- // TODO: add construction code here
- }
-
- COCRDEMOView::~COCRDEMOView()
- {
- }
-
- void COCRDEMOView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(COCRDEMOView)
- DDX_Control(pDX, IDC_LEADCTRL1, m_Lead1);
- //}}AFX_DATA_MAP
- }
-
- BOOL COCRDEMOView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- void COCRDEMOView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- // Disable the scroll bars in the parent window
- SetScrollSizes(MM_TEXT,CSize(1,1));
-
- // Fit the LEAD control to the client area and enable autoscrolling.
- CRect rcClient;
- GetClientRect(rcClient);
- m_Lead1.MoveWindow(0, 0, rcClient.right, rcClient.bottom, FALSE);
- m_Lead1.SetAutoScroll(TRUE);
- m_Lead1.SetPaintSizeMode(theApp.m_nPaintSize);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // OLE Client support and commands
-
- BOOL COCRDEMOView::IsSelected(const CObject* pDocItem) const
- {
- // The implementation below is adequate if your selection consists of
- // only COCRDEMOCntrItem objects. To handle different selection
- // mechanisms, the implementation here should be replaced.
-
- // TODO: implement this function that tests for a selected OLE client item
-
- return pDocItem == m_pSelection;
- }
-
- void COCRDEMOView::OnInsertObject()
- {
- // Invoke the standard Insert Object dialog box to obtain information
- // for new COCRDEMOCntrItem object.
- COleInsertDialog dlg;
- if (dlg.DoModal() != IDOK)
- return;
-
- BeginWaitCursor();
-
- COCRDEMOCntrItem* pItem = NULL;
- TRY
- {
- // Create new item connected to this document.
- COCRDEMODoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pItem = new COCRDEMOCntrItem(pDoc);
- ASSERT_VALID(pItem);
-
- // Initialize the item from the dialog data.
- if (!dlg.CreateItem(pItem))
- AfxThrowMemoryException(); // any exception will do
- ASSERT_VALID(pItem);
-
- // If item created from class list (not from file) then launch
- // the server to edit the item.
- if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
- pItem->DoVerb(OLEIVERB_SHOW, this);
-
- ASSERT_VALID(pItem);
-
- // As an arbitrary user interface design, this sets the selection
- // to the last item inserted.
-
- // TODO: reimplement selection as appropriate for your application
-
- m_pSelection = pItem; // set selection to last inserted item
- pDoc->UpdateAllViews(NULL);
- }
- CATCH(CException, e)
- {
- if (pItem != NULL)
- {
- ASSERT_VALID(pItem);
- pItem->Delete();
- }
- AfxMessageBox(IDP_FAILED_TO_CREATE);
- }
- END_CATCH
-
- EndWaitCursor();
- }
-
- // The following command handler provides the standard keyboard
- // user interface to cancel an in-place editing session. Here,
- // the container (not the server) causes the deactivation.
- void COCRDEMOView::OnCancelEditCntr()
- {
- // Close any in-place active item on this view.
- COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
- if (pActiveItem != NULL)
- {
- pActiveItem->Close();
- }
- ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
- }
-
- // Special handling of OnSetFocus and OnSize are required for a container
- // when an object is being edited in-place.
- void COCRDEMOView::OnSetFocus(CWnd* pOldWnd)
- {
- COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
- if (pActiveItem != NULL &&
- pActiveItem->GetItemState() == COleClientItem::activeUIState)
- {
- // need to set focus to this item if it is in the same view
- CWnd* pWnd = pActiveItem->GetInPlaceWindow();
- if (pWnd != NULL)
- {
- pWnd->SetFocus(); // don't call the base class
- return;
- }
- }
-
- CFormView::OnSetFocus(pOldWnd);
- }
-
- void COCRDEMOView::OnSize(UINT nType, int cx, int cy)
- {
- // CFormView::OnSize(nType, cx, cy);
- // COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
- // if (pActiveItem != NULL)
- // pActiveItem->SetItemRects();
- CFormView::OnSize(nType, cx, cy);
-
- if( IsWindow(m_Lead1.m_hWnd) )
- m_Lead1.MoveWindow(CRect( 0, 0, cx, cy));
- }
-
- CLead* COCRDEMOView::GetDocLead()
- {
- COCRDEMODoc* pDoc = GetDocument();
- return(&pDoc->m_Lead1);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMOView diagnostics
-
- #ifdef _DEBUG
- void COCRDEMOView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void COCRDEMOView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- COCRDEMODoc* COCRDEMOView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COCRDEMODoc)));
- return (COCRDEMODoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMOView message handlers
-
- void COCRDEMOView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
- {
- CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
- if (bActivate)
- {
- ASSERT(pActivateView == this);
- OnDoRealize((WPARAM)theApp.m_pMainWnd->m_hWnd, (LPARAM) FALSE); // same as SendMessage(WM_DOREALIZE);
- }
- }
-
- LRESULT COCRDEMOView::OnDoRealize(WPARAM wParam, LPARAM lParam)
- {
- if( !IsWindow(m_Lead1.m_hWnd) || !m_Lead1.GetBitmap() )
- return FALSE;
- if(lParam)
- {
- return m_Lead1.SendMessage(WM_PALETTECHANGED, wParam);
- }
- else
- {
- UINT nColorsChanged = 0;
- CDC* pdc;
-
- pdc = theApp.m_pMainWnd->GetDC();
- HPALETTE hpal = (HPALETTE)m_Lead1.GetPalette((OLE_HANDLE) pdc->m_hDC);
- if(hpal)
- {
- CPalette pal;
-
- pal.Attach(hpal);
- CPalette* oldPalette = pdc->SelectPalette(&pal, (BOOL) lParam);
- nColorsChanged = pdc->RealizePalette();
- if (nColorsChanged > 0)
- {
- m_Lead1.InvalidateRect(NULL, FALSE);
- }
- pdc->SelectPalette(oldPalette, TRUE);
- }
- theApp.m_pMainWnd->ReleaseDC(pdc);
- return ((LRESULT) (BOOL) (nColorsChanged > 0));
- }
- }
-
- void COCRDEMOView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // Note that this program has one instance of the Lead control for each
- // view, plus the one instance for the document, which is used as the master copy.
- // The UpdateAllViews function calls this function once for each view; and
- // this function uses the master copy to update each view.
-
- ASSERT(pSender != this);
- UNUSED(pSender); // unused in release builds
-
- COCRDEMODoc* pDoc = GetDocument();
-
- // Avoid repainting until we are ready.
- m_Lead1.SetAutoRepaint(FALSE);
-
- // Update this view's bitmap with the document bitmap.
- m_Lead1.SetBackErase(TRUE);
- if(IsWindow(pDoc->m_Lead1.m_hWnd))
- m_Lead1.SetBitmap(GetDocLead()->GetBitmap());
- m_Lead1.SetPaintPalette(PAINTPALETTE_AUTO);
- m_Lead1.SetPaintDither(PAINTDITHER_DIFFUSION);
- m_Lead1.SetBitonalScaling(BITONALSCALING_SCALETOGRAY);
-
- // Fit the LEAD control to the client area and enable autoscrolling.
- CRect rcClient;
- GetClientRect(rcClient);
- m_Lead1.MoveWindow(0, 0, rcClient.right, rcClient.bottom, FALSE);
- m_Lead1.SetAutoScroll(TRUE);
- m_Lead1.SetAutoRepaint(TRUE);
- }
-
-
- void COCRDEMOView::OnViewNormal()
- {
- m_Lead1.SetPaintSizeMode(PAINTSIZEMODE_NORMAL);
- theApp.m_nPaintSize = PAINTSIZEMODE_NORMAL;
- }
-
- void COCRDEMOView::OnUpdateViewNormal(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_Lead1.GetPaintSizeMode() == PAINTSIZEMODE_NORMAL);
- }
-
- void COCRDEMOView::OnViewFitimagetowindow()
- {
- m_Lead1.SetPaintSizeMode(PAINTSIZEMODE_FIT);
- theApp.m_nPaintSize = PAINTSIZEMODE_FIT;
- }
-
- void COCRDEMOView::OnUpdateViewFitimagetowindow(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_Lead1.GetPaintSizeMode() == PAINTSIZEMODE_FIT);
- }
-