📄 txtwindw.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: txtwindw.cpp,v 1.1.2.1 2004/07/09 01:50:20 hubbe Exp $ * * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** *////////////////////////////////////////////////////////////////////////////////// TXTWINDW.CPP//// TextWindow class implementation.//// A class TextWindow object holds the location, size, background color,// ...etc for the space on the screen where the text is to be rendered.//#include "hxtypes.h" /*Must be included before windows.h for VC6 compiler */#if defined(_WINDOWS)#include <windows.h>#else/* Need to include what's necessary for window resources: mac, ppc, unix. */#endif#include <stdlib.h>#include <string.h>#include "hxwintyp.h" //For struct HXxWindow#include "rt_types.h"#include "atocolor.h"#include "atotime.h"#include "rt_string.h"#include "parsing.h"#include "fontdefs.h" //for CHARSET defines.#include "hxslist.h" //for base class CHXSimpleList.#include "hxstack.h" //for class CHXStack#include "txtattrb.h" //for class TextAttributes#include "txtcntnr.h" //for class TextAttributes#include "textline.h" //for class TextLine & TextLineList#include "textprsr.h" /* for REAL_TEXT_TRANSPARENT_BGCOLOR_MAJOR_VERSION + ... */#include "txtwindw.h"#include "fontinfo.h" //for GetStringWidthInPixels() function.#include "dict.h" /* For Unix font dict */#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static char HX_THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// Method:// TextWindowBase constructor// Purpose:// Initializes all data members to default values.//TextWindowBase::TextWindowBase() : m_width(WINDOW_DIMENSION_UNSPECIFIED) , m_height(WINDOW_DIMENSION_UNSPECIFIED) , m_ulContentMajorVersion(0L) , m_ulContentMinorVersion(0L) , m_borderSize(DEFAULT_BORDERSIZE) , m_upperLeftX(DEFAULT_WINDOWUPPERLEFTX) , m_upperLeftY(DEFAULT_WINDOWUPPERLEFTY) , m_scrollRate(SCROLLRATE_UNSPECIFIED) , m_crawlRate(CRAWLRATE_UNSPECIFIED) , m_type(TYPE_UNSPECIFIED) , m_scrollType(SCROLLTYPE_UNSPECIFIED) , m_backgroundColor(BGCOLOR_RGB_UNSPECIFIED) , m_ulBackgroundOpacity(255) , m_ulMediaOpacity(255) , m_bIsChromaKeySet(FALSE) , m_ulChromaKey(0) , m_ulChromaKeyTolerance(0) , m_ulChromaKeyOpacity(0) , m_loop(DOLOOP_UNSPECIFIED) , m_numBreakTagsEncountered(0L) , m_currentTextLineStartY(0L) , m_currentTextLineEndY(0L) , m_currentTextLineStartX(0L) , m_currentTextLineEndX(0L) , m_xOfFakeNewLine(0L) , m_linkColor(DEFAULT_LINKCOLOR) , m_bUnderlineHyperlinks(DEFAULT_DO_UNDERLINE_HYPERLINKS) , m_bUseWordwrap(DEFAULT_USE_WORDWRAP) , m_bExpandTabs(DEFAULT_EXPAND_TABS) , m_kHorizAlign(kHAlignLeft) , m_kVertAlign(kVAlignTop) , m_bVertAlignWasExplicitlySet(FALSE) , m_bRightToLeft(FALSE) , m_ulDefaultPointSize(DEFAULT_FONT_PTSIZE) , m_defaultTextColor(DEFAULT_TEXT_COLOR) , m_defaultTextBgColor(BGCOLOR_RGB_UNSPECIFIED) , m_ulDefaultFontWeight(DEFAULT_FONT_WEIGHT) , m_bDefaultFontStyleIsItalic(FALSE) , m_pDefaultFontFaceString(NULL) , m_pDefaultCharsetString(NULL) , m_bIsCharsetTranslatedForOS(FALSE) , m_dAngleOfEscapement(0.0) , m_dAngleOfCharOrientation(0.0) , m_bAngleOfCharOrientationWasExplicitlySet(FALSE) , m_bUserTextSizingPrefIsSet(FALSE) , m_bUserPrefSizeIsRelative(TRUE) , m_ulUserPrefTextSizeOrScaleFactorPct(100) , m_bDontIgnoreExtraSpaces(DEFAULT_DONT_IGNORE_EXTRA_SPACES) , m_ulNumberOfFontColorPushesInsideLinkText(0L) , m_bIsLiveSource(DEFAULT_IS_LIVE_SOURCE) , m_ulTimeAtStartup(0L) , m_ulTimeOfLastClearTag(0L) , m_newPktStartXAtTimeZero(INVALID_LONG32) , m_newPktStartYAtTimeZero(INVALID_LONG32) , m_bClearWasJustSent(FALSE) , m_bUseXPOSVal(FALSE) , m_bUseYPOSVal(FALSE) , m_ulInsideCommentTagNestCount(0L) , m_ulNumNewlinesStatedInPacketHeader(0L) , m_ulDuration(0L){ m_pTLList = new TextLineList; m_pFontUndoTagList = new TextLineList;#if defined(_DEBUG) m_ulDebugFlags = 0L;#endif}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindowBase destructor// Purpose:// janitorial function.//TextWindowBase::~TextWindowBase(){ reset(); if(m_pTLList) { m_pTLList->flush(); delete m_pTLList; m_pTLList = NULL; } if(m_pFontUndoTagList) { m_pFontUndoTagList->flush(); delete m_pFontUndoTagList; m_pFontUndoTagList = NULL; } if (m_pDefaultFontFaceString) { delete [] m_pDefaultFontFaceString; m_pDefaultFontFaceString = NULL; } if (m_pDefaultCharsetString) { delete [] m_pDefaultCharsetString; m_pDefaultCharsetString = NULL; }}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindowBase::reset()//// Purpose:// Clears all text attribute stacks so that the next text that arrives will // get the default font size, color, bold, ...etc, until new attribute tags// are received.//void TextWindowBase::reset(){ TextAttributeStacks::flush(); TextContainerList::flush(); if(m_pTLList) { m_pTLList->flush(); } if(m_pFontUndoTagList) { m_pFontUndoTagList->flush(); } m_numBreakTagsEncountered = 0L; m_currentTextLineStartY = m_currentTextLineEndY = 0L; m_currentTextLineStartX = m_currentTextLineEndX = 0L;}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindowBase::getCommentTagNestCount()//// Purpose:// Tells whether we're currently parsing inside HTML-style comments, i.e.,// <!-- we're inside a comment --> :ULONG32 TextWindowBase::getCommentTagNestCount(){ return m_ulInsideCommentTagNestCount;}void TextWindowBase::setInsideCommentTagNestCount(ULONG32 ulCTNC){ m_ulInsideCommentTagNestCount = ulCTNC;}ULONG32 TextWindowBase::incrementCommentTagNestCount(){ return ++m_ulInsideCommentTagNestCount;}ULONG32 TextWindowBase::decrementCommentTagNestCount(){ if(m_ulInsideCommentTagNestCount) m_ulInsideCommentTagNestCount--; return m_ulInsideCommentTagNestCount;}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindow constructor// Purpose:// Initializes all data members to default values.//TextWindow::TextWindow() : m_pURL(NULL) , m_ulLenURLbuf(0L) , m_ulTargetOfURL(URL_TARGET_INVALID) , m_ulTimeOfLastTimeSync(0L) //In live on encoder side, this needs to // get reset to encoder start time which // may not be zero.#if defined(_WINDOWS) , m_pDeviceContextMemory(NULL)#if !defined(USE_DIB_SECTION) , m_pBmpCompat(NULL)#else //USE_DIB_SECTION: , m_hBitmap(NULL) , m_hOldBitmap(NULL) , m_LPBITMAPINFO(NULL) , m_pBits(NULL)#endif#elif defined(_MACINTOSH) || defined(_MAC_UNIX) , m_pOffScreenWorld(NULL)#endif , m_visibleWindowWidth(0L) , m_visibleWindowHeight(0L) , m_lCurrentXOffsetDueToLooping(0L) , m_lCurrentYOffsetDueToLooping(0L) , m_lCurrentYOffsetForTeleprompter(0L) , m_bPriorLineAlreadyCentered(FALSE) , m_bHandlingWindowResizing(FALSE){#if defined(_UNIX) && !defined(_MAC_UNIX) m_font_dict = new Dict;#endif#ifdef _WINDOWS#if !defined(USE_DIB_SECTION) m_hDIB = new CHXDIBits();#else //USE_DIB_SECTION: //nothing to do here.#endif m_pDeviceContextMemory = (void*)CreateCompatibleDC(NULL);#endif // _WINDOWS}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindow destructor// Purpose:// janitorial function.//TextWindow::~TextWindow(){ clear_all();#if defined(_WINDOWS)#if !defined(USE_DIB_SECTION) if(m_pBmpCompat) { DeleteObject((HBITMAP)m_pBmpCompat); } if (m_hDIB) { delete m_hDIB; m_hDIB = NULL; }#else //USE_DIB_SECTION: if(m_hBitmap) { DeleteObject(m_hBitmap); } if(m_hOldBitmap && m_pDeviceContextMemory) { SelectObject((HDC)m_pDeviceContextMemory, m_hOldBitmap); } m_hOldBitmap = NULL; if(m_LPBITMAPINFO) { delete m_LPBITMAPINFO; m_LPBITMAPINFO = NULL; } //XXXEH- clean up m_pBits here? Or, no need to clean it up...?;#endif if(m_pDeviceContextMemory) { DeleteDC((HDC)m_pDeviceContextMemory); }#elif defined(_MACINTOSH) || defined(_MAC_UNIX) if(m_pOffScreenWorld) { DisposeGWorld(m_pOffScreenWorld); m_pOffScreenWorld=NULL; }#else //platform-specific code needed here.#endif#if defined(_UNIX) && !defined(_MAC_UNIX) HX_DELETE(m_font_dict);#endif}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindow::clear_all()//// Purpose:// Erases all text that has already been received from the stream and clears// all text attribute stacks so that the next text that arrives will be // rendered with the default font size, color, bold, ...etc, until new// attribute tags are received.//void TextWindow::clear_all(){ reset(); //::TextWindowBase's function. clearURL(); m_ulTimeOfLastTimeSync=0L;}/////////////////////////////////////////////////////////////////////////////// Methods:// TextWindow::getURL()// TextWindow::hasValidURL()// TextWindow::setURL(_CHAR* pNewURL, ULONG32 newURLstrlen)// TextWindow::clearURL()//// Purpose:// These functions keep track of//// Returns:// returns TRUE upon success, FALSE if (sr < MIN_SCROLLRATE) or if// (sr > MAX_SCROLLRATE)://_CHAR* TextWindow::getURL(){ return m_pURL; //note: this may be NULL.}ULONG32 TextWindow::getLenURLbuf(){ return m_ulLenURLbuf;}BOOL TextWindow::hasValidURL(){ return (NULL!=m_pURL && 0<m_ulLenURLbuf);}//returns FALSE if pNewURL is empty or NULL:BOOL TextWindow::setURL(_CHAR* pNewURL, ULONG32 newURLstrlen){ if(!pNewURL || !newURLstrlen) { return FALSE; } if(m_pURL) { delete [] m_pURL; m_pURL = NULL; } m_ulLenURLbuf = 0L; m_pURL = new _CHAR[newURLstrlen+1]; HX_ASSERT(m_pURL); if(!m_pURL) { return FALSE; } m_pURL[newURLstrlen] = '\0'; //not needed, but do this anyway. m_ulLenURLbuf = newURLstrlen;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -