// OContainerDoc.cpp : implementation of the COContainerDoc class
//

#include "stdafx.h"
#include "OContainer.h"

#include "OContainerDoc.h"
#include "CntrItem.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// COContainerDoc

IMPLEMENT_DYNCREATE(COContainerDoc, COleDocument)

BEGIN_MESSAGE_MAP(COContainerDoc, COleDocument)
	// Enable default OLE container implementation
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, &COleDocument::OnUpdatePasteMenu)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, &COleDocument::OnUpdatePasteLinkMenu)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, &COleDocument::OnUpdateObjectVerbMenu)
	ON_COMMAND(ID_OLE_EDIT_CONVERT, &COleDocument::OnEditConvert)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, &COleDocument::OnUpdateEditLinksMenu)
	ON_COMMAND(ID_OLE_EDIT_LINKS, &COleDocument::OnEditLinks)
	ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, &COleDocument::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()


// COContainerDoc construction/destruction

COContainerDoc::COContainerDoc()
{
	// Use OLE compound files
	EnableCompoundFile();

	// TODO: add one-time construction code here

}

COContainerDoc::~COContainerDoc()
{
}

BOOL COContainerDoc::OnNewDocument()
{
	if (!COleDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	return TRUE;
}


// COContainerDoc serialization

void COContainerDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}

	// Calling the base class COleDocument enables serialization
	//  of the container document's COleClientItem objects.
	COleDocument::Serialize(ar);
}

BOOL COContainerDoc::CanCloseFrame(CFrameWnd* pFrame)
{    
    COleClientItem* pActiveItem = GetInPlaceActiveItem(pFrame);
    if(pActiveItem != NULL)
    {
        int state = pActiveItem->GetItemState();        
        if(state == COleClientItem::activeUIState)
            switch(AfxMessageBox(L"Czy zakończyć edycję?", MB_YESNOCANCEL))
            {
                case IDYES: 
                    pActiveItem->Close();  
                    return 1;
                    break;
                case IDNO:
                    AfxMessageBox(L"Zmiany nie zostaną zachowane");
                    return 1;
                case IDCANCEL:
                    return 0;
                    break;
            }
        else
            return 1;
    }
    else
        return 1;
}

// COContainerDoc diagnostics

#ifdef _DEBUG
void COContainerDoc::AssertValid() const
{
	COleDocument::AssertValid();
}

void COContainerDoc::Dump(CDumpContext& dc) const
{
	COleDocument::Dump(dc);
}
#endif //_DEBUG


// COContainerDoc commands

