home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
odtlktv4.zip
/
ODTLKT
/
TOOLKIT
/
SAMPLES
/
OPENDOC
/
PARTS
/
TTAPE1
/
TTAPE1.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-15
|
90KB
|
2,483 lines
/*
* This file was generated by the SOM Compiler and Emitter Framework.
* Generated using:
* SOM Emitter emitxtm: 2.41
*/
/***********************************************************************
*
* File Name : TTAPE1.CPP
*
* Description : This module contains the implementation of the Ticker-
* Tape1 SOM class. TickerTape1 is an example of an
* OpenDoc part handler.
*
* The part is a Ticker Tape, which is a rectangular
* window containing text which scrolls from right to
* left.
*
* The Ticker Tape has the following features:
*
* 1. The text adjusts when the size of the rectangle is
* adjusted, so that the height of the text always
* fills the height of the rectangle.
* 2. The background color can be selected by selecting
* "Background" from the Pop-up menu, which appears
* when the mouse is clicked over the part with mouse
* button 2.
* 3. A text file can be selected to replace the displayed
* Ticker Tape text. The text file is selected by
* selecting "Open Text File" from the Pop-up menu.
* 4. Because the TickerTape1's parent class is a container
* part handler, the TickerTape1 part handler allows the
* embedding of OpenDoc parts within the Ticker Tape
* text window.
*
* Notes : N/A
*
* Utility routine entry points:
* MessageBox
* FrameWndProc
* MenuColorFromRGBColor
*
* TickerTape1Part class entry points:
* TickerTape1CommonInitPart
* TickerTape1SetOrigin
* TickerTape1FileOpenDialog
* TickerTape1DrawFrameOrThumbnailView
* TickerTape1DrawIconView
* TickerTape1SetFrameSize
* TickerTape1GetTextData
* TickerTape1IsNewText
* TickerTape1LoadPopupMenu
* TickerTape1CheckAndAddProperties
* TickerTape1ExternalizeContent
* TickerTape1somInit
* TickerTape1somUninit
* TickerTape1Draw
* TickerTape1Externalize
* TickerTape1FrameShapeChanged
* TickerTape1HandleEvent
* TickerTape1FacetAdded
* TickerTape1FacetRemoved
* TickerTape1FocusAcquired
* TickerTape1FocusLost
* TickerTape1InitPart
* TickerTape1InitPartFromStorage
* TickerTape1ViewTypeChanged
*
* M_TickerTape1 metaclass entry points:
* M_TickerTape1clsGetODPartHandlerName
* M_TickerTape1clsGetODPartHandlerDisplayName
* M_TickerTape1clsGetODPartKinds
* M_TickerTape1clsGetOLE2ClassId
* M_TickerTape1clsGetWindowsIconFileName
*
* (C) COPYRIGHT International Business Machines Corp. 1995
* All Rights Reserved
* Licensed Materials - Property of IBM
*
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*
* DISCLAIMER OF WARRANTIES. The following [enclosed] code is
* sample code created by IBM Corporation. This sample code is not
* part of any standard or IBM product and is provided to you solely
* for the purpose of assisting you in the development of your
* applications. The code is provided "AS IS", without
* warranty of any kind. IBM shall not be liable for any damages
* arising out of your use of the sample code, even if they have
* been advised of the possibility of such damages.
*
***********************************************************************/
#ifndef SOM_Module_ttape1_Source
#define SOM_Module_ttape1_Source
#endif
#define TickerTape1_Class_Source
#define M_TickerTape1_Class_Source
/*
* Allow use of underscore prefix to the TickerTape1's instance
* variables. The underscore prefix replaces the use of "somThis->".
*/
#define VARIABLE_MACROS
#define INCL_WIN
#define INCL_WINSYS
#define INCL_WINERRORS
#define INCL_GPI
#define INCL_GPIERRORS
#define INCL_DOS
#define INCL_DOSMODULEMGR
#define INCL_DOSRESOURCES
#define INCL_ODAPI
#define INCL_ODCANVAS
#define INCL_ODALTPOINT
#define INCL_ODFACET
#define INCL_ODDRAFT
#define INCL_ODFOCUSSET
#define INCL_ODFRAME
#define INCL_ODSHAPE
#define INCL_ODTRANSFORM
#define INCL_ODSESSION
#define INCL_ODSTORAGEUNIT
#define INCL_ODWINDOW
#define INCL_ODWINDOWSTATE
#include <stdio.h>
#include <string.h>
#include <fstream.h>
#include <os2.h>
#ifndef SOM_ODPopup_xh /* Definition for ODPopup */
#include <popup.xh>
#endif
#include "ttape1.xih"
#include "textdata.hpp"
#include "ttape1.hpp"
/*
* Prototypes for the utility routines.
*/
void MessageBox(HMODULE, HWND, ULONG, PSZ);
MRESULT EXPENTRY FrameWndProc(HWND, ULONG, MPARAM, MPARAM);
USHORT MenuColorFromRGBColor(RGBColor bgColor);
/*
*
* Method(s) : MessageBox
*
* Description : A utility routine which displays a message box. The
* message is obtained from the MessageTable resource
* when provided the message ID.
*
* Parameters : HMODULE hmod - Handle to TickerTape1 module.
* HWND hwndClient - Client window handle.
* ULONG ulID - ID which identifies the message.
* PSZ pszTitle - Message box title string.
*
* Returns : VOID
*
* Notes : N/A
*/
void MessageBox(HMODULE hmMod, HWND hwndClient, ULONG ulID, PSZ pszTitle)
{
CHAR msg[MESSAGESIZE];
/*
* Load the message from the module's message table resource.
*/
WinLoadMessage(WinQueryAnchorBlock(HWND_DESKTOP),
hmMod,
ulID,
MESSAGESIZE,
msg);
/*
* Display the message in a PM message box.
*/
WinMessageBox(HWND_DESKTOP,
hwndClient,
msg,
pszTitle,
0,
MB_CANCEL|MB_MOVEABLE|MB_ICONEXCLAMATION);
}
/*
*
* Method(s) : FrameWndProc
*
* Description : A utility routine which handles messages sent to the
* TickerTape1 facet's PM timer window.
*
* Parameters : HWND hWnd - Handle to the PM timer window.
* ULONG message - The message identity.
* MPARAM mp1 - The message parameter 1.
* MPARAM mp2 - The message parameter 2.
*
* Returns : MRESULT - Message-return data.
*
* Notes : N/A
*/
MRESULT EXPENTRY FrameWndProc(HWND hWnd,
ULONG message,
MPARAM mp1,
MPARAM mp2)
{
MRESULT mresult;
TickerTape1Part *somSelf; /* Reference to the TickerTape1 SOM object. */
/*
* Get the SOM environment information variable.
*/
Environment *ev = somGetGlobalEnvironment();
ODFacet *facet; /* The TickerTape1 part's facet. */
/*
* Get the reference to the TickerTape1 SOM object.
*/
somSelf = (TickerTape1Part *)WinQueryWindowULong(hWnd, 0);
/*
* Get the reference to the Ticker Tape 1 part's current facet.
*/
facet = (ODFacet *)WinQueryWindowULong(hWnd, sizeof(ULONG));
/*
* Handle the event based on the message sent to the timer window.
*/
switch (message)
{
case WM_DESTROY: /* About to close the PM timer window. */
WinStopTimer(WinQueryAnchorBlock(hWnd), hWnd, 0);
mresult = (MRESULT)0;
break;
case WM_TIMER: /* Message from Timer. Draw the part. */
somSelf->DrawFrameOrThumbnailView(ev, facet);
mresult = (MRESULT)1;
break;
default:
/*
* Invoke the default routine for handling messages.
*/
mresult = frameProc(hWnd, message, mp1, mp2);
}
return mresult;
}
/*
*
* Method(s) : MenuColorFromRGBColor
*
* Description : A utility routine which converts the given RGBColor value
* to its corresponding value as a MENUITEM resource.
*
* Parameters : RGBColor - The color as an RGB value.
*
* Returns : USHORT - the MENUITEM resource value.
*
* Notes : N/A
*/
USHORT MenuColorFromRGBColor(RGBColor bgColor)
{
USHORT usColorItem; /* The identifier for the menu item. */
switch (bgColor)
{
case CLR_DARKGRAY: /* Set the identifier to dark gray. */
usColorItem = IDMA_COLOR_GRAY;
break;
case CLR_RED: /* Set the identifier to red. */
usColorItem = IDMA_COLOR_RED;
break;
case CLR_GREEN: /* Set the identifier to green. */
usColorItem = IDMA_COLOR_GREEN;
break;
case CLR_YELLOW: /* Set the identifier to yellow. */
usColorItem = IDMA_COLOR_YELLOW;
break;
case CLR_BLUE: /* Set the identifier to blue. */
usColorItem = IDMA_COLOR_BLUE;
break;
case CLR_DARKPINK: /* Set the identifier to magenta. */
usColorItem = IDMA_COLOR_MAGENTA;
break;
case CLR_CYAN: /* Set the identifier to cyan. */
usColorItem = IDMA_COLOR_CYAN;
break;
default: /* Set the identifier to white. */
usColorItem = IDMA_COLOR_WHITE;
}
return usColorItem;
}
/*
*
* Method(s) : TickerTape1CommonInitPart
*
* Description : Ticker Tape 1 Part initialization common to both the
* InitPart and InitPartFromStorage methods.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* CHAR *text - The initial Ticker Tape text.
* CHAR *filename - The initial text starting pos.
* TEXTATTRIBUTES textAttr - Text attributes:
* - position of first character
* of text in the window.
* - index position of first
* character to display.
* - Text background color.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1CommonInitPart(TickerTape1Part *somSelf,
Environment *ev,
char* text,
char* fileName,
TEXTATTRIBUTES textAttr)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1CommonInitPart");
/*
* Get session in which the TickerTape1's storage unit is running.
*/
_fSession = somSelf->GetStorageUnit(ev)->GetSession(ev);
/*
* Get the selection focus token from the TickerTape1's session.
*/
_fSelectionFocus = _fSession->Tokenize(ev, kODSelectionFocus);
/*
* Obtain tokens representing the frame, large icon, small icon,
* and thumbnail views, respectively, of the Ticker Tape 1 part.
*/
_FrameView = _fSession->Tokenize(ev, kODViewAsFrame);
_LargeIconView = _fSession->Tokenize(ev, kODViewAsLargeIcon);
_SmallIconView = _fSession->Tokenize(ev, kODViewAsSmallIcon);
_ThumbnailView = _fSession->Tokenize(ev, kODViewAsThumbnail);
/*
* Create and initialize the _textArea class, which maintains
* the Ticker Tape text and text attributes.
*/
_textArea = new TextData();
_textArea->SetTextBuffer(text, textAttr.sGap, textAttr.sScrollPos);
_textArea->SetBackText(textAttr.lBackText); /* background color. */
/*
* Create and initialize a new File Dialog record. Initialize with
* the filename obtained from InitPart (empty) or InitPartFromStorage.
*/
memset(&_fild, 0, sizeof(FILEDLG));
strcpy (_fild.szFullFile, fileName); /* The text file name. */
_fild.cbSize = sizeof(FILEDLG);
_fild.fl = FDS_CENTER | FDS_OPEN_DIALOG;
/*
* Load the Popup menu - displayed when user mouse-clicks with MB2.
*/
somSelf->LoadPopupMenu(ev);
}
/*
*
* Method(s) : SetOrigin
*
* Description : This method sets the origin coordinates of the facet
* in preparation of drawing the Ticker Tape 1 part.
*
* Parameters : TickerTape1Part *somSelf - References the object.
* Environment *ev - References SOM environment
* information.
* ODFacet *facet - References the facet for this object.
* HPS hpsDraw - Presentation screen handle.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1SetOrigin(TickerTape1Part *somSelf,
Environment *ev,
ODFacet* facet,
HPS hpsDraw)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1SetOrigin");
/*
* Obtain the content transform associated with the part's facet.
*/
ODCanvas* canvas = facet->GetCanvas(ev); /* The facet's bias canvas. */
ODTransform* localToGlobal = facet->AcquireContentTransform(ev, canvas);
/*
* Get the transformation matrix from the transform.
*/
MATRIXLF mtx;
localToGlobal->GetMATRIXLF(ev, &mtx);
ODReleaseObject(ev, localToGlobal);
/*
* Replace the current model transform in the Presentation Manager with
* the one obtained from the transform above. The transform acts on each
* point (x,y).
*/
GpiSetModelTransformMatrix(hpsDraw, 9, &mtx, TRANSFORM_REPLACE);
}
/*
*
* Method(s) : TickerTape1FileOpenDialog
*
* Description : This method sets up a Font Dialog Box, which is opened
* for the user to select a new text font and scroll rate.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1FileOpenDialog(TickerTape1Part *somSelf,
Environment *ev,
HWND hwndClient)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1FileOpenDialog");
HFILE hfFileHandle; /* Handle address of the text file. */
ULONG ulAction, /* Receives action taken by DosOpen. */
cbRead; /* New logical size of the file. */
APIRET rc; /* Return code from the file routine. */
FILESTATUS FileInfo; /* File Information record. */
CHAR cTitle[MESSAGESIZE]; /* Title of PM dialog & message box. */
CHAR *pszBuf; /* Temporary buffer for text file. */
/*
* Get the Title string for the "Open Text file" dialog box.
*/
WinLoadMessage(WinQueryAnchorBlock(HWND_DESKTOP),
_hmMod,
IDM_OPENTEXTFILE,
MESSAGESIZE,
cTitle);
/*
* Initialize the File Dialog record.
*/
_fild.pszTitle = cTitle;
/*
* Display the File Open Dialog box and get the selected file.
*/
HWND hwndDlg = WinFileDlg(HWND_DESKTOP, hwndClient, &_fild);
if ((hwndDlg != NULL) && (_fild.lReturn == DID_OK))
{
/*
* Open the file selected via the File Open Dialog box.
* The path name returned is in _fild.szFullFile.
*/
rc = DosOpen(_fild.szFullFile, /* File name */
&hfFileHandle, /* Returned to us */
&ulAction, /* Action taken */
0, /* File Size (N/A) */
FILE_NORMAL, /* File attributes */
FILE_OPEN,
OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
NULL); /* EA buffer (N/A) */
if (rc != 0) /* If DosOpen failed, display error message. */
{
MessageBox(_hmMod, hwndClient, IDM_ERROROPENING, cTitle);
return;
}
/*
* Get the file information, specifically the file size.
*/
DosQueryFileInfo(hfFileHandle,
FIL_STANDARD, /* File Information level */
&FileInfo,
sizeof(FileInfo));
/*
* If the file size is greater than 32,000 bytes, display
* the error message in message box.
*/
if (FileInfo.cbFile > MAXSIZETEXTFILE)
{
MessageBox(_hmMod, hwndClient, IDM_ERRORSIZEFILE, cTitle);
}
else
{
/*
* Allocate a temporary buffer for the text file.
* Read the entire text file into this buffer.
*/
pszBuf = new CHAR[FileInfo.cbFile+1];
if (pszBuf != NULL)
{
rc = DosRead(hfFileHandle,
(PVOID)pszBuf,
FileInfo.cbFile,
&cbRead);
pszBuf[FileInfo.cbFile] = 0;
}
/*
* If read failed then display Read failed message.
*/
if ((rc != 0) || (pszBuf == NULL))
{
MessageBox(_hmMod, hwndClient, IDM_ERRORREADING, cTitle);
}
else
{
/*
* Success. Set the _textArea's text buffer to
* the contents of the temporary buffer. Set
* "New Ticker Tape Text" to true.
*/
if (_textArea->SetTextBuffer(pszBuf,0,MAXSIZETEXTFILE+1) == 1)
_fNewTickerTapeText = kODTrue;
else
MessageBox(_hmMod, hwndClient, IDM_ERRORREADING, cTitle);
}
delete [] pszBuf; /* Delete the temporary buffer. */
}
DosClose(hfFileHandle); /* Close the text file. */
}
}
/*
*
* Method(s) : TickerTape1DrawFrameOrThumbnailView
*
* Description : Draw the Ticker Tape 1 part either within its frame or as
* a thumbnail (ie, a thumbnail-size frame). Draw the Ticker
* Tape content in the provided facet. Only the visible
* portion of the part needs to be drawn, based on the
* obtained aggregate clip shape.
*
* This method is invoked whenever the Ticker Tape timer
* window handler receives a TIMER message.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODFacet *facet - References the part's facet.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1DrawFrameOrThumbnailView(
TickerTape1Part *somSelf,
Environment *ev,
ODFacet* facet)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1DrawFrameView");
/*
* Get PM Presentation Space from the facet.
*/
ODCanvas * canvas = facet->GetCanvas(ev);
HPS hpsDraw = canvas->GetPlatformCanvas(ev, kODGPI)->GetPS(ev, facet);
/*
* Set the origin for the part's content for PM drawing.
*/
somSelf->SetOrigin(ev, facet, hpsDraw);
/*
* Set up clipping due to overlapping OpenDoc parts. The clip
* shape is initialized by copying the aggregate clip shape
* associated with this part's facet.
*/
ODRgnHandle saveClip;
ODShape *clipShape = facet->GetFrame(ev)->CreateShape(ev);
ODShape *tempShape = facet->AcquireAggregateClipShape(ev, canvas);
clipShape->CopyFrom(ev, tempShape);
ODReleaseObject(ev, tempShape);
/*
* The clip shape is transformed by the Frame transform object
* to the frame coordinate space of the facet.
*/
ODTransform* transform = facet->AcquireFrameTransform(ev, canvas);
clipShape->Transform(ev, transform);
/*
* Put the clipping in PM terms. Set the PM Clip Region.
* Save the old PM region handle so the drawing environment can
* be restored after the part is drawn.
*/
ODRgnHandle clip = clipShape->GetRegion(ev);
/*
* Free the OpenDoc Shape object created above.
*/
GpiSetClipRegion(hpsDraw, clip, &saveClip);
/*
* Draw the text on PM presentation screen at origin of facet.
*/
_textArea->DrawTape(hpsDraw);
/*
* Reset the Presentation Manager-specific clip region.
*/
GpiSetClipRegion(hpsDraw, 0, &saveClip);
/*
* Release access to the platform-specific drawing structure
* (i.e., the Presentation Manager Presentation screen).
*/
ODReleaseObject(ev, transform);
ODReleaseObject(ev, clipShape);
canvas->GetPlatformCanvas(ev, kODGPI)->ReleasePS(ev, facet);
}
/*
*
* Method(s) : TickerTape1DrawIconView
*
* Description : Draw the Ticker Tape 1 part as a large or small icon.
*
* Parameters : TickerTape1Part *somSelf - Reference the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODFacet *facet - References the part's facet.
* ODULong size - The icon size in pixels. Size is
* actually the length of one side,
* either 32 (large), or 16 (small).
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1DrawIconView(TickerTape1Part *somSelf,
Environment *ev,
ODFacet* facet,
ODULong size)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1DrawIconView");
BITMAPINFOHEADER2 bmp; /* Bitmap information header structure. */
HBITMAP hbm; /* bitmap handle associated with load from resource. */
POINTL aptl[4]; /* target/source coordinate pair array. */
/*
* Get the facet's frame and bias canvas.
*/
ODFrame* displayFrame = facet->GetFrame(ev);
ODCanvas* canvas = facet->GetCanvas(ev);
/*
* Get the icon's dimensions in terms of OpenDoc's coordinate system.
*/
ODRect rect;
ODShape *usedShape = displayFrame->AcquireUsedShape(ev, canvas);
usedShape->GetBoundingBox(ev, &rect);
ODRECTL frameRect(rect);
ODReleaseObject(ev, usedShape);
/*
* Get PM Presentation Space from the facet.
*/
HPS hps = canvas->GetPlatformCanvas(ev, kODGPI)->GetPS(ev, facet);
/*
* Set the origin for rendering the icon within the facet.
*/
somSelf->SetOrigin(ev, facet, hps);
/*
* Load the bitmap as a resource identified by IDB_BMP1.
*/
hbm = GpiLoadBitmap(hps, _hmMod, IDB_BMP1, size, size);
/*
* Query the contents of the bitmap information header and,
* if successful, perform a BitBlt to the target PS.
*/
bmp.cbFix = sizeof(bmp);
if (GpiQueryBitmapInfoHeader(hbm, &bmp) == GPI_OK)
{
aptl[0].x = frameRect.xLeft; /* target rectangle left. */
aptl[0].y = frameRect.yBottom; /* target rectangle bottom. */
aptl[1].x = frameRect.xRight; /* target rectangle right. */
aptl[1].y = frameRect.yTop; /* target rectangle top. */
aptl[2].x = aptl[2].y = 0; /* source rectangle left and bottom. */
aptl[3].x = bmp.cx; /* source rectangle left. */
aptl[3].y = bmp.cy; /* source rectangle right. */
/*
* Perform a BitBlt of the bitmap to the target PS.
*/
if (GpiWCBitBlt(hps, hbm, 4, aptl, ROP_SRCCOPY, BBO_IGNORE)==GPI_ERROR)
{
DosBeep(700UL, 500UL);
}
}
/*
* Release access to the platform-specific drawing structure
* (i.e., the Presentation Manager Presentation screen).
*/
canvas->GetPlatformCanvas(ev, kODGPI)->ReleasePS(ev, facet);
}
/*
*
* Method(s) : TickerTape1SetFrameSize
*
* Description : Set the size of the rectangle the Ticker Tape text is
* drawn in. The text height is set to the rectangle height.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODRect *Rect - the frame size in terms of an
* OpenDoc rectangle.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1SetFrameSize(TickerTape1Part *somSelf,
Environment *ev,
ODRect* Rect)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1SetFrameSize");
/*
* Convert the frame's bounding box coordinates to PM coordinates.
*/
RECTL rclFrame;
rclFrame.xLeft = FIXED2LONG(Rect->left);
rclFrame.xRight = FIXED2LONG(Rect->right);
rclFrame.yTop = FIXED2LONG(Rect->top);
rclFrame.yBottom = FIXED2LONG(Rect->bottom);
/*
* Set the size of the Ticker Tape text box stored in _textArea.
*/
_textArea->SetSize(&rclFrame);
}
/*
*
* Method(s) : TickerTape1GetTextData
*
* Description : Get the TextData text-maintenance object owned by Ticker
* Tape 1. This is an accessor method provided for classes
* subclassing from the TickerTape1 class.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : TextData* - the TextData class object.
*
* Notes : N/A
*/
SOM_Scope TextData* SOMLINK TickerTape1GetTextData(TickerTape1Part *somSelf,
Environment *ev)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1GetTextData");
/* Return statement to be customized: */
return _textArea;
}
/*
*
* Method(s) : TickerTape1IsNewText
*
* Description : Returns the value of the fNewTickerTape text variable.
* Allows a subclass to determine if the Ticker Tape text
* has been replaced by text from a file. This is an
* accessor method provided for classes subclassing from
* the TickerTape1 class.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : ODBoolean - the value of fNewTickerTapeText.
*
* Notes : N/A
*/
SOM_Scope ODBoolean SOMLINK TickerTape1IsNewText(TickerTape1Part *somSelf,
Environment *ev)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1IsNewText");
/* Return statement to be customized: */
return _fNewTickerTapeText;
}
/*
*
* Method(s) : TickerTape1LoadPopupMenu
*
* Description : Loads the Popup menu which will be displayed when the
* user mouse-clicks with mouse button 2 over the part.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1LoadPopupMenu(TickerTape1Part *somSelf,
Environment *ev)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1Part","TickerTape1LoadPopupMenu");
/*
* Copy the default popup menu from the session's window state.
*/
_fPopup = _fSession->GetWindowState(ev)->CopyBasePopup(ev);
/*
* If the base popup menu is not NULL customize the Popup menu.
*/
if (_fPopup != kODNULL)
{
HWND hwndMenu = NULLHANDLE; /* The handle to the menu resource. */
ODPlatformMenuItem mi; /* The menu item structure. */
/*
* Remove the "Open As" and "Properties" menu items.
*/
_fPopup->RemoveMenuItem(ev, kODNULL, VIEW_OPENAS);
_fPopup->RemoveMenuItem(ev, kODNULL, VIEW_PROPERTIES);
/*
* Add the "Open Text File..." menu item before the "Show As" item.
*/
memset((PCH)&mi, 0, sizeof(MENUITEM));
mi.id = IDMP_FILE_OPEN;
mi.afStyle = MIS_TEXT;
_fPopup->AddMenuItemBefore(ev, kODNULL, kODNULL, &mi, VIEW_SHOWAS);
_fPopup->SetMenuItemText(ev, kODNULL, IDMP_FILE_OPEN,
"~Open Text File...");
/*
* Load up our background color menu from our resource module.
*/
hwndMenu = WinLoadMenu(HWND_OBJECT, _hmMod, ID_POPUPMENU);
/*
* Add the "Background" menu item for selecting background color.
*/
mi.id = ID_POPUPMENU;
mi.hwndSubMenu = hwndMenu;
_fPopup->AddMenuItemBefore(ev, kODNULL, kODNULL, &mi, VIEW_SHOWAS);
_fPopup->SetMenuItemText(ev, kODNULL, ID_POPUPMENU, "~Background");
/*
* Put a check in front of the current view (eg, frame, because the
* Popup menu is not accessible when the view type is not frame).
*/
_fPopup->CheckMenuItem(ev, VIEW_SHOWAS, VIEW_SAFRAME, kODTrue);
/*
* Get the current background color.
*/
RGBColor bgColor = (RGBColor)_textArea->GetBackText();
/*
* Get the menu item value corresponding to the color.
*/
USHORT usColorItem = MenuColorFromRGBColor(bgColor);
/*
* Put a check in front of the current background color.
*/
_fPopup->CheckMenuItem(ev, ID_POPUPMENU, usColorItem, kODTrue);
} /* endif */
}
/*
*
* Method(s) : TickerTape1CheckAndAddProperties
*
* Description : If the Ticker Tape 1 Part storage unit properties are not
* already there, the properties and their corresponding
* values are added.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODStorageUnit *storageUnit - A storage unit belonging
* either to the part or to a
* drag and drop operation.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1CheckAndAddProperties(
TickerTape1Part *somSelf,
Environment *ev,
ODStorageUnit* storageUnit)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1Part","TickerTape1CheckAndAddProperties");
/*
* Add the Contents Property (kODPropContents) to the storage unit.
* The Ticker Tape 1 part's contents is the Ticker Tape text which
* is displayed within the Ticker Tape window.
*/
if (!storageUnit->Exists(ev, kODPropContents, kODNULL, 0))
storageUnit->AddProperty(ev, kODPropContents);
if (!storageUnit->Exists(ev, kODPropContents, kTickerTape1TextType, 0))
storageUnit->AddValue(ev, kTickerTape1TextType);
/*
* Add a Ticker Tape Attributes property (kODPropTickerTapeAttr).
* The Ticker Tape 1 part's attribute data includes:
* 1. the frame negotiation flag - whether an initial frame size has
* been negotiated with its containing part.
* 2. Ticker Tape text attributes, which include:
* - the "Gap", or starting position of text within the Ticker
* Tape window.
* - the "Scroll Position", or position of the starting character
* of text to display within the Ticker Tape window.
* - the text background color.
* 3. the file name of the file which contained the Ticker Tape text.
*/
if (!storageUnit->Exists(ev, kODPropTickerTapeAttr, kODNULL, 0))
storageUnit->AddProperty(ev, kODPropTickerTapeAttr);
if (!storageUnit->Exists(ev, kODPropTickerTapeAttr,
kTickerTape1AttrType, 0))
storageUnit->AddValue(ev, kTickerTape1AttrType);
}
/*
*
* Method(s) : TickerTape1ExternalizeContent
*
* Description : Put the Ticker Tape 1 part's intrinsic data into the
* specified storage unit.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODStorageUnit *storageUnit - A storage unit belonging either
* to the part or to a drag and
* drop operation.
* ODBoolean isPartStorage - Flag to determine if the
* storage unit belongs to the
* part of to a drag and drop
* operation.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1ExternalizeContent(TickerTape1Part *somSelf,
Environment *ev,
ODStorageUnit* storageUnit,
ODBoolean isPartStorage)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1Part",
"TickerTape1ExternalizeContent");
/*
* Focus the storage unit on the kODPropTickerTapeAttr contents
* property and the kTickerTape1AttrType property value.
*/
storageUnit->Focus(ev, kODPropTickerTapeAttr, kODPosUndefined,
kTickerTape1AttrType, 0, kODPosUndefined);
/*
* Write the contents of the fFrameNegotiated flag (true or false,
* true if an initial frame size has been negotiated).
*/
StorageUnitSetValue(storageUnit,
ev, sizeof(ODBoolean), &_fFrameNegotiated);
TEXTATTRIBUTES textAttr;
textAttr.sGap = _textArea->GetGap();
textAttr.sScrollPos = _textArea->GetScrollPos();
textAttr.lBackText = _textArea->GetBackText();
/*
* Write the position of the text in the window, index position of
* the first character displayed in the window, and the background
* text color to document storage.
*/
StorageUnitSetValue(storageUnit, ev, sizeof(textAttr), &textAttr);
/*
* If the Ticker Tape text has been modified, externalize it.
*/
if (_fNewTickerTapeText == kODTrue || isPartStorage == kODFalse)
{
/*
* Strip the drive and directory path from the text file name.
*/
char *ptr = strrchr(_fild.szFullFile, '\\');
if (ptr != NULL)
++ptr;
else
ptr = _fild.szFullFile;
/*
* Write the Ticker Tape text filename to its location in the
* part's storage unit.
*/
StorageUnitSetValue(storageUnit, ev, CCHMAXPATH, ptr);
/*
* Focus the storage unit on the kODPropContents contents
* property and the kTickerTape1TextType property value.
*/
storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
kTickerTape1TextType, 0, kODPosUndefined);
/*
* Delete the text currently stored in the storage unit.
*/
storageUnit->DeleteValue(ev, storageUnit->GetSize(ev));
/*
* Get the Ticker Tape Text length and write the Ticker Tape text.
*/
SHORT sTextSize = _textArea->GetTextFileSize() + 1;
StorageUnitSetValue(storageUnit,
ev, sTextSize, _textArea->GetTextBuffer(0));
/*
* Because the text has been written to document storage, the
* new ticker tape text flag is now false.
*/
if (isPartStorage == kODTrue)
_fNewTickerTapeText = kODFalse;
}
}
/*
*
* Method(s) : TickerTape1somInit
*
* Description : TickerTape1somInit initializes the newly created
* Ticker Tape Base object's instance variables.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1somInit(TickerTape1Part *somSelf)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1somInit");
/*
* Call the parent (Container Part) somInit method.
*/
TickerTape1Part_parent_ContainerPart_somInit(somSelf);
_textArea = 0; /* Ticker Tape text data class. */
_fNewTickerTapeText = kODFalse; /* Need to externalize our text? */
_fFrameNegotiated = kODFalse; /* Was a frame size negotiated? */
_fIsActivated = kODFalse; /* Has the part been activated? */
_msgWnd = 0; /* Handle to PM timer window. */
_fSession = kODNULL; /* Our storage unit's session. */
/*
* Get handle to the TickerTape1 class module ("TTAPE1.DLL").
*/
DosQueryModuleHandle(MODULENAME, &_hmMod);
}
/*
*
* Method(s) : TickerTape1somUninit
*
* Description : This method uninitializes the TickerTape1 SOM object.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1somUninit(TickerTape1Part *somSelf)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1somUninit");
/*
* Delete the Ticker Tape text-maintenance object.
*/
delete _textArea;
/*
* Call the parent (Container Part) somUninit method.
*/
TickerTape1Part_parent_ContainerPart_somUninit(somSelf);
}
/*
*
* Method(s) : TickerTape1Draw
*
* Description : This method draws the Ticker Tape 1 part when invoked
* by OpenDoc. Draw is invoked whenever the part's
* contents need to be rendered onto a canvas. The
* contents must be rendered whenever it is moved,
* resized, or loses its focus.
*
* For simplicity, this method does not differentiate
* between the displaying of the part's content based on
* whether the canvas is static or dynamic, or onscreen
* or offscreen.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODFacet* facet - References the part's facet
* ODShape* invalidShape - References the update shape,
* or the shape to be rendered,
* expressed in the facet's
* frame coordinate system.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1Draw(TickerTape1Part *somSelf,
Environment *ev, ODFacet* facet,
ODShape* invalidShape)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1Draw");
/*
* Get the current view type - how the part is currently displayed.
*/
ODTypeToken view = facet->GetFrame(ev)->GetViewType(ev);
/*
* If the view is large icon invoke DrawIconView with size (length
* of one side) set to LARGEICONSIZE (32 pixels).
*/
if (view == _LargeIconView)
{
somSelf->DrawIconView(ev, facet, LARGEICONSIZE);
}
/*
* If the view is small icon invoke DrawIconView with size (length
* of one side) set to SMALLICONSIZE (16 pixels).
*/
else if (view == _SmallIconView)
{
somSelf->DrawIconView(ev, facet, SMALLICONSIZE);
}
/*
* If the view is either frame or thumbnail (thumbnail-size frame),
* invoke DrawFrameOrThumbnail view after drawing the parent part.
*/
else
{
/*
* Draw the container part and its embedded parts.
*/
TickerTape1Part_parent_ContainerPart_Draw(somSelf, ev, facet,
invalidShape);
somSelf->DrawFrameOrThumbnailView(ev, facet);
}
}
/*
*
* Method(s) : TickerTape1Externalize
*
* Description : This method writes the Ticker Tape 1 part's persistent
* information to its OpenDoc storage unit. The data
* written to its storage unit includes:
*
* - The Ticker Tape Text.
* - The text's starting position within the window.
* - The position of the first character to display
* within the window.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1Externalize(TickerTape1Part *somSelf,
Environment *ev)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1Externalize");
/*
* Externalize the Container Part's persistent data.
*/
TickerTape1Part_parent_ContainerPart_Externalize(somSelf, ev);
/*
* Obtain a reference to the TickerTape1 part's storage unit.
*/
ODStorageUnit* su = somSelf->GetStorageUnit(ev);
/*
* If not already there, add the Ticker Tape 1 part's properties to
* its storage unit.
*/
somSelf->CheckAndAddProperties(ev, su);
/*
* Externalize the Ticker Tape 1 part's intrinsic data to its
* storage unit.
*/
somSelf->ExternalizeContent(ev, su, kODTrue);
}
/*
*
* Method(s) : TickerTape1FrameShapeChanged
*
* Description : This method is invoked by OpenDoc when the shape of
* the Ticker Tape 1 part's frame has changed. The dimensions
* of the rectangle the Ticker Tape text is drawn in is
* updated, if the current view of the part is frame view.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODFrame *frame - References the part's display frame.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1FrameShapeChanged(TickerTape1Part *somSelf,
Environment *ev,
ODFrame* frame)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1FrameShapeChanged");
/*
* Call the parent (Container Part) FrameShapeChanged method.
*/
TickerTape1Part_parent_ContainerPart_FrameShapeChanged(somSelf,
ev,
frame);
/*
* Get the current view type - how the part is currently displayed.
*/
ODTypeToken view = frame->GetViewType(ev);
/*
* If the view is Frame view, update the dimensions of the rectangle
* the Ticker Tape text is drawn in.
*/
if (view == _FrameView)
{
ODRect Rect; /* The frame's new rectangle coordinates. */
ODCanvas* canvas = kODNULL; /* The frame's drawing space. */
/*
* Get the frame's bounding box coordinates.
*/
ODShape *frameShape = frame->AcquireFrameShape(ev, canvas);
frameShape->GetBoundingBox(ev, &Rect);
ODReleaseObject(ev, frameShape);
/*
* Set the dimensions of the Ticker Tape text's rectangle to
* the dimensions stored in Rect.
*/
somSelf->SetFrameSize(ev, &Rect);
}
}
/*
*
* Method(s) : TickerTape1HandleEvent
*
* Description : This method handles significant events sent from the
* OpenDoc Dispatcher to the Ticker Tape par handler.
* Handled events include the creation of a Pop-up menu
* (after the user clicks over the part with mouse
* button 2) and the selection of the Open Text File
* dialog box. All other events are handled by the
* parent (Container) part handler.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODEventData *event - References event data which
* indicates the type of event.
* ODFrame *frame - References the part's display
* frame.
* ODFacet *facet - References the part's facet.
*
* Returns : ODBoolean - kODTrue if the event was handled by this
* method. kODFalse if the event was not
* handled by this method.
*
* Notes : N/A
*/
SOM_Scope ODBoolean SOMLINK TickerTape1HandleEvent(TickerTape1Part *somSelf,
Environment *ev,
ODEventData* event,
ODFrame* frame,
ODFacet* facet,
ODEventInfo* eventInfo)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1HandleEvent");
/*
* Initialize the result flag to indicate that initially no
* event has been handled.
*/
ODBoolean handled = kODFalse;
ODCanvas* canvas = kODNULL;
/*
* Handle the event based on the identity of the message provided
* with the event information. Only certain messages are important
* to this method.
*/
switch (event->msg)
{
case WM_CONTEXTMENU:
{
/*
* If the part is not already activated, activate it.
*/
if (_fIsActivated == kODFalse)
somSelf->ActivateFrame(ev, frame);
/*
* Display the Popup menu.
*/
_fPopup->Display(ev);
handled = kODTrue;
event->result = (MRESULT)1; // handled
}
break;
/*
* Command message. The user has selected from Pop-up menu.
*/
case WM_COMMAND:
{
/*
* Determine whether the Ticker Tape 1 part is the root part.
*/
ODBoolean isRoot = frame->IsRoot(ev);
/*
* Initialize bgColor to black. If it stays black, then the
* user did not select a new background color.
*/
RGBColor bgColor = CLR_BLACK;
LONG lItem = LONGFROMMP(event->mp1);
switch (lItem)
{
/*
* 'Open Text File' was selected from the Pop-up Menu.
* Display the Open Text File dialog box and get the text
* file the user selects.
*/
case IDMP_FILE_OPEN:
{
/*
* The provided facet is NULL (why?). Get the facet
* by iterating thru the frame's facets.
*/
ODFrameFacetIterator* facets =
frame->CreateFacetIterator(ev);
/*
* Get the facet's window handle - use as client window.
*/
HWND hwndFacet = facets->First(ev)->GetFacetHWND(ev);
/*
* Open dialog to allow user to select a text file.
*/
somSelf->FileOpenDialog(ev, hwndFacet);
/*
* If a new text file has been selected, prepare
* for redraw of text by invalidating the facet.
*/
if (_fNewTickerTapeText == kODTrue)
{
canvas = facets->First(ev)->GetCanvas(ev);
/*
* Force redraw by invalidating the facet.
*/
facets->First(ev)->Invalidate(ev, kODNULL, canvas);
}
/*
* Set handled flag to indicate event was handled.
*/
handled = kODTrue;
delete facets;
}
break;
/*
* 'Show as Large Icon' was selected from either the
* Popup menu or menu bar. Change view type to Large Icon.
*/
case VIEW_SALARGEICON:
if ((_CurrentView != _LargeIconView) &&
(isRoot == kODFalse))
frame->ChangeViewType(ev, _LargeIconView);
/*
* Set handled flag to indicate event was handled.
*/
handled = kODTrue;
break;
/*
* 'Show as Small Icon' was selected from either the
* Popup menu or menu bar. Change view type to Small Icon.
*/
case VIEW_SASMALLICON:
if ((_CurrentView != _SmallIconView) &&
(isRoot == kODFalse))
frame->ChangeViewType(ev, _SmallIconView);
/*
* Set handled flag to indicate event was handled.
*/
handled = kODTrue;
break;
/*
* 'Show as Thumbnail' was selected from either the
* Popup menu or menu bar. Change view type to Thumbnail.
*/
case VIEW_SATHUMBNAIL:
if ((_CurrentView != _ThumbnailView) &&
(isRoot == kODFalse))
frame->ChangeViewType(ev, _ThumbnailView);
/*
* Set handled flag to indicate event was handled.
*/
handled = kODTrue;
break;
/*
* 'Show as Frame' was selected from either the
* Popup menu or menu bar. Change view type to Frame.
*/
case VIEW_SAFRAME:
if (_CurrentView != _FrameView)
frame->ChangeViewType(ev, _FrameView);
/*
* Set handled flag to indicate event was handled.
*/
handled = kODTrue;
break;
default: ; /* Do nothing. */
}
}
break;
default: ; /* Do nothing. */
}
/*
* If the event wasn't handled here, pass the event to the parent.
*/
if (handled == kODFalse)
handled = TickerTape1Part_parent_ContainerPart_HandleEvent(somSelf,
ev,
event,
frame,
facet,
eventInfo);
RGBColor bgColor = somSelf->GetBGColor(ev);
RGBColor currentColor = (RGBColor)_textArea->GetBackText();
/*
* If a color was selected then change the background color. The
* color is changed by calling the parent's set background color
* method. This is necessary because the parent doesn't provide a
* a background color accessor method.
*/
if (bgColor != currentColor)
{
/*
* Get the menu item value corresponding to the color.
*/
USHORT usColorItem = MenuColorFromRGBColor(currentColor);
/*
* Remove the check in front of the current background color.
*/
_fPopup->CheckMenuItem(ev, ID_POPUPMENU, usColorItem, kODFalse);
usColorItem = MenuColorFromRGBColor(bgColor);
/*
* Add a check in front of the new background color.
*/
_fPopup->CheckMenuItem(ev, ID_POPUPMENU, usColorItem, kODTrue);
/*
* Set the background color for both the ticker tape text and
* he parent container part.
*/
_textArea->SetBackText(bgColor);
}
return handled; /* return whether event was handled. */
}
/*
*
* Method(s) : TickerTape1FacetAdded
*
* Description : This method handles the addition of a facet to the
* Ticker Tape Base part's frame.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object
* Environment *ev - References the SOM environment
* ODFacet *facet - References the added facet.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1FacetAdded(TickerTape1Part *somSelf,
Environment *ev,
ODFacet* facet)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1FacetAdded");
/*
* Notify the parent (Container) part handler that a facet has
* been added to one of its frames.
*/
TickerTape1Part_parent_ContainerPart_FacetAdded(somSelf, ev, facet);
/*
* Get the facet's frame and bias canvas.
*/
ODFrame* frame = facet->GetFrame(ev);
ODCanvas* canvas = facet->GetCanvas(ev);
/*
* If the frame is the root frame, activate the frame to prevent OpenDoc
* from getting into an ambiguous state.
*/
if (frame->IsRoot(ev) == kODTrue) /* Is this frame the root frame? */
{
somSelf->ActivateFrame(ev, frame);
/*
* If frame is the root frame, remove the "Show As" submenu.
* The frame view is the only possible view for the root frame.
*/
_fPopup->RemoveMenuItem(ev, kODNULL, VIEW_SHOWAS);
}
else
{
/*
* Negotiate an initial frame size - for a "ticker tape" shape.
*/
if (_fFrameNegotiated == kODFalse)
{
/*
* Set up initial Ticker Tape size using PM coordinates
* and place in a new OpenDoc shape object.
*/
ODRect newRect = {0, MAKEFIXED(TTAPE1_HEIGHT,0),
MAKEFIXED(TTAPE1_WIDTH,0), 0};
ODShape* newShape = frame->CreateShape(ev);
newShape->SetRectangle(ev, &newRect);
/*
* Negotiate the display frame size with its containing part.
*/
frame->RequestFrameShape(ev, newShape, canvas);
ODReleaseObject(ev, newShape);
/*
* Set frame negotiated to True. If the part was instantiated
* either from its template or as a root part this flag was false.
*/
_fFrameNegotiated = kODTrue;
}
}
/*
* Get the text background color, and invoke the parent's set background
* color method. This is necessary because the parent doesn't provide
* a background color accessor method.
*/
RGBColor bgColor = (RGBColor)_textArea->GetBackText();
somSelf->SetBGColor2(ev, frame, bgColor);
/*
* Create and initialize the PM timer window.
*/
if ((_msgWnd = WinCreateWindow(HWND_OBJECT,
WC_FRAME,
(PSZ)0,
0L,
0,0,0,0,
HWND_OBJECT,
HWND_TOP,
67L,
(PVOID)0,
(PVOID)0)) != NULL)
{
/*
* Install the FrameWndProc routine to handle the messages
* sent to the PM timer window.
*/
frameProc = WinSubclassWindow(_msgWnd, (PFNWP)FrameWndProc);
/*
* Store both a reference to the Ticker Tape SOM object and a
* reference to its facet in the PM timer window.
*/
WinSetWindowULong(_msgWnd, 0, (ULONG)somSelf);
WinSetWindowULong(_msgWnd, sizeof(ULONG), (ULONG)facet);
}
/*
* The view type? Don't know what it is so handle it..
*/
somSelf->ViewTypeChanged(ev, frame);
}
/*
*
* Method(s) : TickerTape1FacetRemoved
*
* Description : This method handles the removal of a facet from the
* Ticker Tape Base part's frame.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODFacet *facet - References the removed facet.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1FacetRemoved(TickerTape1Part *somSelf,
Environment *ev,
ODFacet* facet)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1FacetRemoved");
/*
* Close the PM timer window. Text scrolling is active only while
* the facet is alive.
*/
if (_msgWnd != NULL)
WinDestroyWindow(_msgWnd);
/*
* Notify the parent (Container) part handler that a facet has
* been removed from one of its frames.
*/
TickerTape1Part_parent_ContainerPart_FacetRemoved(somSelf, ev, facet);
}
/*
*
* Method(s) : TickerTape1FocusAcquired
*
* Description : This method handles the acquiring of the focus by the
* Ticker Tape Base part's frame.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODTypeToken focus - Tokenized representation of the
* type of focus acquired.
* ODFrame *ownerFrame - Reference to the frame owning
* the focus.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1FocusAcquired(TickerTape1Part *somSelf,
Environment *ev,
ODTypeToken focus,
ODFrame* ownerFrame)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1FocusAcquired");
/*
* Notify the parent (Container) part handler that one of its
* embedded frames has acquired the focus.
*/
TickerTape1Part_parent_ContainerPart_FocusAcquired(somSelf,
ev, focus,
ownerFrame);
/*
* The focus was acquired when the user selected the part.
*/
if (focus == _fSelectionFocus)
{
_fIsActivated = kODTrue; /* The part has been activated. */
/*
* Stop the text scrolling by stopping the timer.
*/
WinStopTimer(WinQueryAnchorBlock(_msgWnd), _msgWnd, 0);
/*
* Tell the _textArea's draw method not to draw the Ticker
* Tape text at a new scroll position.
*/
_textArea->SetNeedToScroll(kODFalse);
/*
* Set up redraw of Ticker Tape, which will show any
* embedded parts within the Ticker Tape window.
*/
ODFrameFacetIterator* facets = ownerFrame->CreateFacetIterator(ev);
/*
* Force redraw the Ticker Tape by invalidating the facet.
*/
ODCanvas* canvas = facets->First(ev)->GetCanvas(ev);
facets->First(ev)->Invalidate(ev, kODNULL, canvas);
delete facets;
}
}
/*
*
* Method(s) : TickerTape1FocusLost
*
* Description : This method handles the losing the focus by the
* Ticker Tape Base part's frame.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODTypeToken focus - Tokenized representation of the
* type of focus acquired.
* ODFrame *ownerFrame - Reference to the frame owning
* the focus.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1FocusLost(TickerTape1Part *somSelf,
Environment *ev,
ODTypeToken focus,
ODFrame* ownerFrame)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1", "TickerTape1FocusLost");
/*
* Notify the parent (Container) part handler that one of its
* embedded frames has lost the focus.
*/
TickerTape1Part_parent_ContainerPart_FocusLost(somSelf,
ev, focus, ownerFrame);
/*
* The focus was lost when the user activated another part.
*/
if (focus == _fSelectionFocus)
{
_fIsActivated = kODFalse; /* The part is no longer activated. */
/*
* Scrolling should be started only if the current view is either
* frame or thumbnail (ie, a thumbnail-size frame).
*/
if ((_CurrentView == _FrameView) || (_CurrentView == _ThumbnailView))
{
/*
* Get the text scroll rate from the text maintenance object.
*/
LONG lScrollRate = _textArea->GetScrollRate();
/*
* Start the text scrolling by starting the timer.
*/
WinStartTimer(WinQueryAnchorBlock(_msgWnd),_msgWnd,0,lScrollRate);
/*
* Tell the _textArea's draw method to draw the Ticker Tape
* text at a new scroll position.
*/
_textArea->SetNeedToScroll(kODTrue);
}
}
}
/*
*
* Method(s) : TickerTape1InitPart
*
* Description : This method handles the initialization of the SOM
* object as a newly-instantiated OpenDoc part.
*
* This method is only called once in the lifetime of
* the part, when the part is first created for an
* OpenDoc document and has no persistent data from
* a previously externalized OpenDoc document.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object
* Environment *ev - References the SOM environment
* ODStorageUnit *storageUnit - References the part's
* document storage unit.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1InitPart(TickerTape1Part *somSelf,
Environment *ev,
ODStorageUnit* storageUnit,
ODPart* partWrapper)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1InitPart");
/*
* The parent's (Container) part handler InitPart method must be
* called to initialize the parent.
*/
TickerTape1Part_parent_ContainerPart_InitPart(somSelf, ev, storageUnit,
partWrapper);
CHAR msg[MESSAGESIZE]; /* Buffer for initial Ticker Tape text. */
/*
** Load the welcome message from the message table resource.
*/
WinLoadMessage(WinQueryAnchorBlock(HWND_DESKTOP),
_hmMod, IDM_WELCOME, MESSAGESIZE, msg);
/*
* Set the text attributes to the defaults. The initial gap and
* scroll position values indicate that they must be calculated
* when it comes time to draw the part.
*/
TEXTATTRIBUTES textAttr;
textAttr.sGap = 0;
textAttr.sScrollPos = MAXSIZETEXTFILE+1;
textAttr.lBackText = CLR_RED; /* The background color is RED. */
/*
* CommonInitPart performs the part initialization which is
* common to both InitPart and InitPartFromStorage.
*/
somSelf->CommonInitPart(ev, msg, "", textAttr);
/*
* The new text is the welcome message loaded from the resource file.
*/
_fNewTickerTapeText = kODTrue;
}
/*
*
* Method(s) : TickerTape1InitPartFromStorage
*
* Description : This method handles messages the initialization of the
* SOM object as an OpenDoc part from OpenDoc storage.
*
* This method retrieve's the part's persistent storage
* data from OpenDoc storage.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODStorageUnit *storageUnit - References the part's
* document storage unit.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1InitPartFromStorage(
TickerTape1Part *somSelf,
Environment *ev,
ODStorageUnit* storageUnit,
ODPart* partWrapper)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1",
"TickerTape1InitPartFromStorage");
/*
* The parent's (Container) part handler InitPartFromStorage
* method must be called initialize the parent from storage.
*/
TickerTape1Part_parent_ContainerPart_InitPartFromStorage(somSelf,
ev, storageUnit,
partWrapper);
CHAR* text; /* Temporary buffer for the retrieved text. */
CHAR filename[CCHMAXPATH]; /* file name which contained the text. */
/*
* Focus the part's storage unit on the kODPropTickerTapeAttr
* Property and the kTickerTape1AttrType value type.
*/
storageUnit->Focus(ev, kODPropTickerTapeAttr, kODPosUndefined,
kTickerTape1AttrType, 0, kODPosUndefined);
/*
* Read the starting position of the text within the Ticker Tape
* window from the part's storage unit.
*/
StorageUnitGetValue(storageUnit,ev,sizeof(ODBoolean), &_fFrameNegotiated);
/*
* Read the starting position of the text within the Ticker Tape
* window from the part's storage unit.
*/
TEXTATTRIBUTES textAttr;
StorageUnitGetValue(storageUnit, ev, sizeof(textAttr), &textAttr);
/*
* Read the text information, which will be displayed in the
* Ticker Tape window, from the part's storage unit.
*/
StorageUnitGetValue(storageUnit, ev, CCHMAXPATH, filename);
/*
* Focus the part's storage unit on the kODPropContents Property
* and the kTickerTape1TextType value type.
*/
storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
kTickerTape1TextType, 0, kODPosUndefined);
/*
* Get the size of the text stored in the part's storage unit.
*/
ULONG ulTextSize = storageUnit->GetSize(ev);
/*
* Create a temporary buffer for storing the Ticker Tape text.
*/
text = new CHAR [ulTextSize];
/*
* Read the text information, which will be displayed in the
* Ticker Tape window, from the part's storage unit.
*/
StorageUnitGetValue(storageUnit, ev, ulTextSize, text);
/*
* Mark this draft of the storage unit dirty. This ensures that
* the draft will be externalized when the document is closed.
*/
storageUnit->GetDraft(ev)->SetChangedFromPrev(ev);
/*
* CommonInitPart performs the part initialization which is
* common to both InitPart and InitPartFromStorage.
*/
somSelf->CommonInitPart(ev, text, filename, textAttr);
delete [] text; /* Delete the temporary Ticker Tape text buffer. */
}
/*
*
* Method(s) : TickerTape1CloneInto
*
* Description : This method handles the deep copy of the Ticker Tape
* 1 Part's intrinsic data to a storage unit. This occurs
* when the Ticker Tape 1 part is being registered as well
* when it is participating in a drag and drop operation.
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODDraftKey key - The key for clone operation.
* ODStorageUnit *toSu - The storage unit to which the
* cloned data will go.
* ODFrame *scope - The scope of the clone.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1CloneInto(TickerTape1Part *somSelf,
Environment *ev,
ODDraftKey key,
ODStorageUnit* toSU,
ODFrame* scope)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1CloneInto");
TickerTape1Part_parent_ContainerPart_CloneInto(somSelf, ev, key, toSU,
scope);
/*
* If not already there, add the Ticker Tape 1 part's properties to
* the storage unit.
*/
somSelf->CheckAndAddProperties(ev, toSU);
/*
* Externalize the Ticker Tape 1 part's intrinsic data to the
* storage unit.
*/
somSelf->ExternalizeContent(ev, toSU, kODFalse);
}
/*
*
* Method(s) : TickerTape1ViewTypeChanged
*
* Description : Handle change in view type (eg, from frame to icon, or
* icon to thumbnail);
*
* Parameters : TickerTape1Part *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
* ODFrame *frame - References the part's persistent
* layout information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope void SOMLINK TickerTape1ViewTypeChanged(TickerTape1Part *somSelf,
Environment *ev,
ODFrame* frame)
{
TickerTape1PartData *somThis = TickerTape1PartGetData(somSelf);
TickerTape1PartMethodDebug("TickerTape1","TickerTape1ViewTypeChanged");
/*
* Get the new view type - how the part is to be displayed.
*/
ODTypeToken view = frame->GetViewType(ev);
/*
* If the view is null have the part displayed in its frame view.
*/
if (view == kODNullTypeToken)
{
frame->SetViewType(ev, _FrameView);
view = _FrameView;
}
/*
* If the new view type is either Frame or Thumbnail, and the current
* view is a large or small icon, then start the text scrolling.
*/
if ((view == _FrameView) || (view == _ThumbnailView))
{
if ((_fIsActivated == kODFalse) || (view == _ThumbnailView))
{
/*
* Get the text scroll rate from the text maintenance object.
*/
LONG lScrollRate = _textArea->GetScrollRate();
/*
* Start the text scrolling by starting the timer.
*/
WinStartTimer(WinQueryAnchorBlock(_msgWnd),_msgWnd,0, lScrollRate);
/*
* Set need to scroll to true to invalidate the background.
*/
_textArea->SetNeedToScroll(kODTrue);
}
else
{
_textArea->SetNeedToScroll(kODFalse);
}
}
/*
* If the new view type is either a small or large icon, and the current
* view is a frame or thumbnail, then stop the text scrolling.
*/
else if ((view == _LargeIconView) || (view == _SmallIconView))
{
/*
* Stop the text scrolling by stopping the timer.
*/
WinStopTimer(WinQueryAnchorBlock(_msgWnd), _msgWnd, 0);
}
/*
* Get the facet from the frame's facet iterator.
* Get the facet's bias canvas.
*/
ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
ODFacet* facet = facets->First(ev);
ODCanvas* canvas = kODNULL;
ODRect Rect = {0, 0, 0, 0}; /* Rectangle containing the used shape size. */
/*
* If the new view is Frame View then set the used shape back to the
* frame shape. Get the frame's bounding box and set the Ticker Tape
* text's rectangle to the bounding box dimensions.
*/
if (view == _FrameView)
{
// Reset used shape to frame shape
frame->ChangeUsedShape(ev, kODNULL, canvas);
/*
* Get the frame's bounding box coordinates.
*/
ODShape *frameShape = frame->AcquireFrameShape(ev, canvas);
frameShape->GetBoundingBox(ev, &Rect);
somSelf->SetFrameSize(ev, &Rect);
ODReleaseObject(ev, frameShape);
/*
* The current view is now the large icon view.
*/
_CurrentView = _FrameView;
}
else
{
/*
* Create a new used shape. The new shape is initially a copy
* of the frame shape.
*/
ODShape* newUsedShape = frame->CreateShape(ev);
ODShape* tempShape = frame->AcquireFrameShape(ev, canvas);
newUsedShape->CopyFrom(ev, tempShape);
ODReleaseObject(ev, tempShape);
/*
* If the new view is the large icon view set the new used shape
* rectangle dimensions to the Large icon size dimensions.
*/
if (view == _LargeIconView)
{
Rect.right = MAKEFIXED(LARGEICONSIZE,0);
Rect.top = MAKEFIXED(LARGEICONSIZE,0);
/*
* The current view is now the large icon view.
*/
_CurrentView = _LargeIconView;
}
/*
* If the new view is the small icon view set the new used shape
* rectangle dimensions to the small icon size dimensions.
*/
else if (view == _SmallIconView)
{
Rect.right = MAKEFIXED(SMALLICONSIZE,0);
Rect.top = MAKEFIXED(SMALLICONSIZE,0);
/*
* The current view is now the small icon view.
*/
_CurrentView = _SmallIconView;
}
/*
* If the new view is the thumbnail view set the new used shape
* rectangle dimensions to the thumbnail size dimensions.
*/
else if (view == _ThumbnailView)
{
Rect.right = MAKEFIXED(THUMBNAILSIZE,0);
Rect.top = MAKEFIXED(THUMBNAILSIZE,0);
somSelf->SetFrameSize(ev, &Rect);
/*
* The current view is now the thumbnail view.
*/
_CurrentView = _ThumbnailView;
}
/*
* Set the rectangle dimensions of the new used shape.
*/
newUsedShape->SetRectangle(ev, &Rect);
/*
* Set the used shape to the new used shape created above.
*/
frame->ChangeUsedShape(ev, newUsedShape, canvas);
ODReleaseObject(ev, newUsedShape);
}
/*
* Force a redraw of the containing part.
*/
ODFrame *containingFrame = frame->AcquireContainingFrame(ev);
if (containingFrame != kODNULL)
{
containingFrame->Invalidate(ev, kODNULL, canvas);
ODReleaseObject(ev, containingFrame);
}
delete facets;
}
/*
*
* Method(s) : M_TickerTape1clsGetODPartHandlerName
*
* Description : Return the SOM class name (TickerTape1) to the registration
* process.
*
* Parameters : M_TickerTape1 *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope ISOString SOMLINK M_TickerTape1clsGetODPartHandlerName(
M_TickerTape1 *somSelf,
Environment *ev)
{
/* M_TickerTape1PartData *somThis = M_TickerTape1GetData(somSelf); */
M_TickerTape1MethodDebug("M_TickerTape1",
"M_TickerTape1clsGetODPartHandlerName");
/*
* Set string to the Part Handler, or SOM class, name ("TickerTape1").
*/
string handlerName = kPartHandlerName;
return (ISOString) handlerName; /* return the SOM class name. */
}
/*
*
* Method(s) : M_TickerTape1clsGetODPartHandlerDisplayName
*
* Description : Return the part handler name OpenDoc will associate with
* its template (Ticker Tape 1 Part) to the registration
* process.
*
* Parameters : M_TickerTape1 *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope string SOMLINK M_TickerTape1clsGetODPartHandlerDisplayName(
M_TickerTape1 *somSelf,
Environment *ev)
{
/* M_TickerTape1PartData *somThis = M_TickerTape1GetData(somSelf); */
M_TickerTape1MethodDebug("M_TickerTape1",
"M_TickerTape1clsGetODPartHandlerDisplayName");
/*
* Set string to the Part Handler Display name ("Ticker Tape 1 Part").
*/
string displayName = kPartHandlerDisplayName;
return displayName; /* Return the Part Handler Display name. */
}
/*
*
* Method(s) : M_TickerTape1clsGetODPartKinds
*
* Description : Return the Ticker Tape 1 part handler's Part Kind data to
* the registration process. Place the data in a record
* structure _IDL_SEQUENCE_PartKindInfo and return the record.
*
* Parameters : M_TickerTape1 *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope _IDL_SEQUENCE_PartKindInfo SOMLINK M_TickerTape1clsGetODPartKinds(
M_TickerTape1 *somSelf,
Environment *ev)
{
/* M_TickerTape1Data *somThis = M_TickerTape1GetData(somSelf); */
M_TickerTape1MethodDebug("M_TickerTape1","M_TickerTape1clsGetODPartKinds");
/*
* Structure which contains the part's part kind information. This is
* information about the data types the part supports.
*/
_IDL_SEQUENCE_PartKindInfo TickerTape1Info;
/*
* Create structure PartKindInfo and allocate memory for its data items.
*/
PartKindInfo * info = (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));
info->partKindName = (ISOString) SOMMalloc(strlen(kKindTickerTape1Part)+1);
info->partKindDisplayName =
(string)SOMMalloc(strlen(kTickerTape1KindDisplayName)+1);
info->filenameFilters = (string)SOMMalloc(strlen("")+1);
info->filenameTypes = (string)SOMMalloc(strlen("")+1);
info->categories = (string)SOMMalloc(strlen(kODCategoryPlainText)+1);
info->categoryDisplayName = (string)SOMMalloc(strlen("Text")+1);
info->objectID = (string)SOMMalloc(strlen("") + 1);
/*
* Copy the information into the structure.
*/
strcpy(info->partKindName , kKindTickerTape1Part);
strcpy(info->partKindDisplayName, kTickerTape1KindDisplayName);
strcpy(info->filenameFilters, "");
strcpy(info->filenameTypes, "");
strcpy(info->categories, kODCategoryPlainText);
strcpy(info->categoryDisplayName, "Text");
strcpy(info->objectID, "");
/*
* The number of items stored in the TickerTape1Info record is 1.
*/
TickerTape1Info._maximum = 1;
TickerTape1Info._length = 1;
TickerTape1Info._buffer = info;
return TickerTape1Info; /* Return the part kind data information. */
}
/*
*
* Method(s) : M_TickerTape1clsGetOLE2ClassId
*
* Description : Return the OLE 2 Identifier to the registration process.
*
* Parameters : M_TickerTape1 *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope string SOMLINK M_TickerTape1clsGetOLE2ClassId(
M_TickerTape1 *somSelf,
Environment *ev)
{
/* M_TickerTape1Data *somThis = M_TickerTape1GetData(somSelf); */
M_TickerTape1MethodDebug("M_TickerTape1","M_TickerTape1clsGetOLE2ClassId");
/*
* The OLE 2 class identifier is currently empty.
*/
string classID = "";
return classID; /* Return the empty string. */
}
/*
*
* Method(s) : M_TickerTape1clsGetWindowsIconFileName
*
* Description : Return the file name of the icon to be associated with
* the Ticker Tape 1 part handler's template to the
* registration process.
*
* Parameters : M_TickerTape1 *somSelf - References the SOM object.
* Environment *ev - References the SOM environment
* information.
*
* Returns : VOID
*
* Notes : N/A
*/
SOM_Scope string SOMLINK M_TickerTape1clsGetWindowsIconFileName(
M_TickerTape1 *somSelf,
Environment *ev)
{
/* M_TickerTape1Data *somThis = M_TickerTape1GetData(somSelf); */
M_TickerTape1MethodDebug("M_TickerTape1",
"M_TickerTape1clsGetWindowsIconFileName");
/*
* There is no icon associated with the Ticker Tape 1 part handler.
*/
string fileName = "";
return fileName; /* Return the empty string. */
}