Exemplo n.º 1
0
/** Frees resources prior to destruction.

Documents must be saved before the application process is deleted, otherwise 
data may be lost.

In debug mode, the destructor raises an APPARC 6 panic if documents still 
exist, and an APPARC 5 panic if applications still exist. */
EXPORT_C CApaProcess::~CApaProcess()
// If this is called without calling ResetL() or CApaDocument::SaveL() first, data may be lost
//
	{
	if (iMainDoc)
		{
		DestroyDocument(iMainDoc);
		iMainDoc = NULL;
		}

	if (iDocList)
		{
		__ASSERT_DEBUG(iDocList->Count()==0,Panic(EPanicDocListNotEmpty));
		for (TInt i=iDocList->Count()-1 ; i>=0 ; i--)
			delete (*iDocList)[i]; // delete stray doc's in release mode, just to be tidy
		}

	if (iAppList)
		{
		for (TInt i = iAppList->Count()-1 ; i >= 0 ; i--)
			(*iAppList)[i]->Close();
		}

	delete iAppList;
	delete iDocList;
	delete iMainDocFileName;
	delete iAsyncAppRemover;
	delete iMonitor;
	}
Exemplo n.º 2
0
void CHTMLSection::LoadFromResource( UINT uID )
{
	CResourceLoader rsrc( m_hDefaultInstance );

	VERIFY( rsrc.Load( uID, RT_RCDATA ) );
	
	CHTMLDocument *pDoc = NULL;

#ifdef _UNICODE
	LPTSTR pszHTML = reinterpret_cast<LPTSTR>( malloc( rsrc.GetSize() * sizeof( TCHAR ) + 1 ) );
	{
		MultiByteToWideChar(CP_ACP, 0, (LPCSTR)rsrc.GetData(), rsrc.GetSize(), pszHTML, rsrc.GetSize() * sizeof( TCHAR ) );
		CHTMLParse html( pszHTML, rsrc.GetSize(), m_hDefaultInstance, NULL, m_pDefaults );
#else	//	_UNICODE
		CHTMLParse html( (LPCTSTR)rsrc.GetData(), rsrc.GetSize(), m_hDefaultInstance, NULL, m_pDefaults );
#endif	//	_UNICODE
		pDoc = html.Parse();

#ifdef _UNICODE
		free( pszHTML );
	}
#endif	//	_UNICODE

	if( pDoc )
	{
		DestroyDocument();
		m_pDocument = pDoc;
	}
}
Exemplo n.º 3
0
CHTMLSection::~CHTMLSection()
{
	DestroyDocument();
	InterlockedDecrement( &g_lHTMLSectionCount );
	if( g_lHTMLSectionCount == 0 )
	{
		GS::CDrawContext::ClearAllObjects();
	}
}
Exemplo n.º 4
0
void CHTMLSection::SetHTML( LPCTSTR pcszHTMLText, UINT uLength, LPCTSTR pcszPathToFile )
{
	m_strHTML.Set( pcszHTMLText, uLength );

	CHTMLParse html( pcszHTMLText, uLength, m_hDefaultInstance, pcszPathToFile, m_pDefaults );
	CHTMLDocument *pDoc = html.Parse();

	if( pDoc )
	{
#ifdef _DEBUG
//	pDoc->Dump();
#endif
		DestroyDocument();
		m_pDocument = pDoc;
	}

	OnLoadedDocument();
}
Exemplo n.º 5
0
bool CHTMLSection::SetHTML( HINSTANCE hInst, LPCTSTR pcszName )
{
	CResourceLoader rsrc( hInst );

	if( rsrc.Load( pcszName, RT_RCDATA ) || rsrc.Load( pcszName, RT_HTML ) )
	{
		CHTMLDocument *pDoc = NULL;

#ifdef _UNICODE
		LPTSTR pszHTML = reinterpret_cast<LPTSTR>( malloc( rsrc.GetSize() * sizeof( TCHAR ) + 1 ) );
		{
			MultiByteToWideChar(CP_ACP, 0, (LPCSTR)rsrc.GetData(), rsrc.GetSize(), pszHTML, rsrc.GetSize() * sizeof( TCHAR ) );
			CHTMLParse html( pszHTML, rsrc.GetSize(), hInst, NULL, m_pDefaults );
			m_strHTML.Set( pszHTML, rsrc.GetSize() );
#else	//	_UNICODE
			CHTMLParse html( (LPCTSTR)rsrc.GetData(), rsrc.GetSize(), hInst, NULL, m_pDefaults );
			m_strHTML.Set( (LPCTSTR)rsrc.GetData(), rsrc.GetSize() );
#endif	//	_UNICODE
			pDoc = html.Parse();

#ifdef _UNICODE
			free( pszHTML );
		}
#endif	//	_UNICODE

		if( pDoc )
		{
			DestroyDocument();
			m_pDocument = pDoc;

			OnLoadedDocument();

			return true;
		}
	}
	return false;
}
Exemplo n.º 6
0
int 
OpenDocument(
    WORD    mode,
    WORD    type,
    int     doc,
    LPSTR   FileName,
    int     dupView,
    int     Preference,
    BOOL    bUserActivated
    )

/*++

Routine Description:

    This routine is used to create a new document or to duplicate
    the view of an existing document.

Arguments:

    mode        - Supplies MODE_DUPLICATE if the document is to be duplicated
                           MODE_RELOAD if the file is to be reloaded
                           MODE_CREATE if the document is to be created
    type        - Supplies the document type
    doc         - Supplies
    FileName    - Supplies a pointer to the name of the file for the document
    dupView     - Supplies the view to be duplicated (mode == MODE_DUPLICATE)
    Preference  - Supplies the view preference (-1 if none)
    bUserActivated - Indicates whether this action was initiated by the
                user or by windbg. The value is to determine the Z order of
                any windows that are opened.

Return Value:

    -1 on failure
    view number on success (>= 0)
    return-value - Description of conditions needed to return value. - or -

--*/

{
    LPLINEREC   pl;
    int         nView = 0;
    BOOL        create;
    int         n;
    int         language;
    LPDOCREC    d;
    LPVIEWREC   views;

    //
    //  In mode duplicate, we create a new nView being a copy of the previous
    //  nView of the same document
    //

    if (mode == MODE_DUPLICATE) {

        //
        // Search a free entry for the nView we will create
        //

        if ( (Preference != -1) && Views[ Preference ].Doc == -1 ) {
            nView = Preference;
        } else {
            for (nView = 0; (nView < MAX_VIEWS) && (Views[nView].Doc != -1); nView++);
        }

        if (nView == MAX_VIEWS) {
            ErrorBox(ERR_Too_Many_Opened_Views);
            return -1;
        }

        //
        // Copy parameters from previous nView
        //

        Assert( Docs[Views[dupView].Doc].FirstView >= 0);

        //
        //      Find the last nView for this document
        //

        n = dupView;
        while (Views[n].NextView != -1) {
            n = Views[n].NextView;
        }

        Assert(n < MAX_VIEWS);

        //
        //     Attach new nView to last one found
        //

        Views[nView] = Views[n];
        Views[n].NextView = nView;
        Views[nView].hwndClient = NULL;

        //
        //
        //

        Views[nView].iYTop = Views[dupView].iYTop;

        //
        //     Enlist nView in window menu
        //

        AddWindowMenuItem(Views[dupView].Doc, nView);

        return nView;

    } else if (mode == MODE_RELOAD) {
        nView = Docs[doc].FirstView;
    }

    //
    // First search a free entry for the document
    //

    if (mode != MODE_RELOAD) {
        for (doc = 0; (doc < MAX_DOCUMENTS) && (Docs[doc].FirstView != -1); doc++);
    }

    if (doc >= MAX_DOCUMENTS) {
        ErrorBox(ERR_Too_Many_Opened_Documents);
        return -1;
    }

    d = &Docs[doc];

    if (type == DOC_WIN) {

        //
        //      Check if file is not already loaded
        //

        if (mode == MODE_RELOAD) {
            DestroyDocument(doc);
            language = SetLanguage(doc);
        } else {
            if (FileName != NULL) {
                TCHAR szAbsolutePath[_MAX_PATH] = {0};

                Assert(sizeof(szAbsolutePath) == sizeof(d->szFileName));

                // We may have a relative path name to a file. Try to get the absolute path.
                if ( _fullpath(szAbsolutePath, FileName, sizeof(szAbsolutePath) ) ) {
                    // success
                    _tcscpy(d->szFileName, szAbsolutePath);
                } else {
                    // error. Use as is.
                    _tcscpy(d->szFileName, FileName);
                }

                for (n = 0; n < MAX_DOCUMENTS; n++) {
                    if (Docs[n].FirstView != -1
                        && _strcmpi(Docs[n].szFileName, d->szFileName) == 0) {

                        SetMessageText_StatusBar(ERR_File_Already_Loaded, STATUS_INFOTEXT, FileName);
                        MessageBeep(0);

                        //
                        //  Reactivate window
                        //

                        //SendMessage(g_hwndMDIClient, WM_MDIACTIVATE, (WPARAM) Views[Docs[n].FirstView].hwndFrame, 0L);
                        ActivateMDIChild(Views[Docs[n].FirstView].hwndFrame, bUserActivated);
                        return -1;
                    }
                }

                language = SetLanguage(doc);

            } else {
                // shouldn't happen anymore
                Assert(0);
// BUGBUG - dead code - kcarlos
#if 0
                //
                //  Initialize document record and first nView
                //

                register int i, j;

                for (i = 0; i < MAX_DOCUMENTS; i++) {
                    CreateUntitled(d->FileName, i + 1);
                    for (j = 0; j < MAX_DOCUMENTS; j++) {
                        if (j != doc &&
                            _strcmpi (d->szFileName, Docs[j].szFileName) == 0) {
                            break;
                        }
                    }
                    if (j >= MAX_DOCUMENTS) {
                        break;
                    }
                }

                language = C_LANGUAGE;
#endif
            }
        }
    } else {

        WORD winTitle;
        char rgch[MAX_MSG_TXT];

        language = NO_LANGUAGE;

        //
        //  Non Document type, Load window title from ressource
        //

        switch (type) {

        case DISASM_WIN:
            winTitle = SYS_DisasmWin_Title;
            break;       
        case COMMAND_WIN:
            winTitle = SYS_CmdWin_Title;
            break;
        case MEMORY_WIN:
            winTitle = SYS_MemoryWin_Title;
            break;
        default:
            Assert(FALSE);
            return -1;
            break;
        }
        Dbg(LoadString(g_hInst, winTitle, rgch, MAX_MSG_TXT));
        RemoveMnemonic(rgch, d->szFileName);

        if (type == MEMORY_WIN) {
            lstrcat (d->szFileName,"(");
            lstrcat (d->szFileName,TempMemWinDesc.szAddress);
            lstrcat (d->szFileName,")");
        }
    }

    //
    //  Then search a free entry for the first nView we will create
    //

    if (mode != MODE_RELOAD) {

        if ( (Preference != -1) && Views[ Preference ].Doc == -1 ) {
            nView = Preference;
        } else {
            for (nView = 0; nView < MAX_VIEWS && Views[nView].Doc != -1; nView++);
        }
        if (nView == MAX_VIEWS) {
            ErrorBox(ERR_Too_Many_Opened_Views);
            return -1;
        }
    }

    //
    // Check if file exist
    //

    if (mode == MODE_CREATE || type != DOC_WIN) {
        create = TRUE;
    } else {
        if (mode == MODE_OPEN || FileExist(FileName)) {
            create = FALSE;
        } else {
            if (mode == MODE_OPENCREATE) {
                // Tell the user that the file does not exist.

                // kcarlos
                // BUGBUG
                // Quick hack. To fix a bug, hopefully this all disappear soon.
                VarMsgBox(hwndFrame, SYS_Does_Not_Exist_Create, MB_OK, FileName);
                return -1;
            } else {
                create = FALSE;
            }
        }
    }

    d->readOnly = FALSE;
    d->docType = type;
    d->language = (WORD) language;
    d->untitled = (FileName == NULL);
    d->ismodified = FALSE;

    if (create) {

        LPBLOCKDEF pb;

        //
        //  Initialize the file with a null-string
        //


        d->LastBlock = d->FirstBlock = (LPBLOCKDEF)DocAlloc(sizeof(BLOCKDEF));
        GetSystemTimeAsFileTime(&d->time);

        if (d->FirstBlock == NULL) {
            ErrorBox(SYS_Allocate_Memory);
            return -1;
        }

        pb = d->FirstBlock;

        //
        //  Initialize first block
        //

        pb->PrevBlock = pb->NextBlock = NULL;
        pb->LastLineOffset = 0;

        //
        // Initialize first line
        //

        pl = (LPLINEREC)pb->Data;
        pl->PrevLength = 0;
        pl->Length = LHD;
        pl->Status = 0;

        d->NbLines = 1;         // We start with one null line

    } else {

        //
        // Load the file and check if it's a valid one
        //

        if (!LoadFile(doc)) {
            return -1;
        }
    }

    //
    // Initialize current pointers
    //

    d->CurrentBlock = d->FirstBlock;
    d->CurrentLine = 0;
    d->CurrentLineOffset = 0;
    pl = (LPLINEREC)(d->FirstBlock->Data);
    ExpandTabs(&pl);

    //
    // Undo/redo part
    //

    d->undo.h = 0;
    d->redo.h = 0;
    d->playCount = REC_CANNOTUNDO;
    if (g_contGlobalPreferences_WkSp.m_dwUndoResize == 0 || type != DOC_WIN) {
        d->recType = REC_STOPPED;
    } else {
        d->recType = REC_UNDO;
    }
    CreateRecBuf(doc, REC_UNDO, g_contGlobalPreferences_WkSp.m_dwUndoResize);

    if (mode == MODE_RELOAD) {
        RefreshWindowsTitle(doc);
    } else {

        //
        //  Initialize nView part
        //

        views = &Views[nView];
        views->NextView = -1;
        views->X = views->Y = 0;
        views->hwndClient = views->hwndFrame = NULL;
        views->hScrollBar = g_contGlobalPreferences_WkSp.m_bHorzScrollBars;
        views->vScrollBar = g_contGlobalPreferences_WkSp.m_bVertScrollBars;
        views->scrollFactor = 0;
        views->iYTop = -1;

        //
        //  Everything is OK, add title in window menu and return the nView
        //

        d->FirstView = nView;
        views->Doc = doc;
        AddWindowMenuItem(doc, nView);
    }

    //
    // Check syntax if C
    //

    if (d->language == C_LANGUAGE) {
        d->lineTop = 0;
        d->lineBottom = d->NbLines;
        CheckSyntax(doc);
    }

    return nView;
}                                       // OpenDocument()