home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
odtlktv4.zip
/
ODTLKT
/
TOOLKIT
/
SAMPLES
/
OPENDOC
/
PARTS
/
PUSHBTN
/
PUSHBTN.CPP
< prev
next >
Wrap
Text File
|
1995-12-15
|
56KB
|
1,271 lines
/***************************************************************************
*
* File Name : PUSHBTN.CPP
*
* Description : Contains the implementation of the OpenDoc class
* PushButtonPart
*
* Notes : N/A
*
* Entry Points: PushButtonCommonInitPart
* PushButtonDisplayMsgBox
* PushButtonsomInit
* PushButtonsomUninit
* PushButtonInitPart
* PushButtonInitPartFromStorage
* PushButtonExternalize
* PushButtonCloneInto
* PushButtonCheckAndAddProperties
* PushButtonExternalizeContent
* PushButtonHandleEvent
* PushButtonFacetAdded
* PushButtonFacetRemoved
* PushButtonGeometryChanged
* PushButtonDraw
* PushButtonViewTypeChanged
* PushButtonDrawIconView
* PushButtonDrawThumbnailView
* M_PushButtonPartclsGetODPartHandlerName
* M_PushButtonPartclsGetODPartHandlerDisplayName
* M_PushButtonPartclsGetODPartKinds
* M_PushButtonPartclsGetOLE2ClassId
* M_PushButtonPartclsGetWindowsIconFileName
*
* (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_pushbtn_Source
#define SOM_Module_pushbtn_Source
#endif
#define PushButtonPart_Class_Source
#ifndef SOM_PushButtonPart_xih
#include "pushbtn.xih"
#endif
#ifndef _PUSHBTN_HPP_
#include "pushbtn.hpp"
#endif
/****************************************************************************
*
* Method(s) : PushButtonCommonInitPart()
*
* Description : This method contains the initialization code that is
* common to both situations, whether the part is newly
* created or is to be read in from persistent storage.
*
* Parameters : PushButtonPart *somSelf - References the object
* Environment *ev - References SOM environment
* information
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonCommonInitPart(PushButtonPart *somSelf,
Environment *ev)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonCommonInitPart");
// Allocate memory for Push Button text.
_fBuffer = new CHAR[TEXTBUFFERSIZE];
// In order to load the resources (strings, icon or bitmap), the module
// handle for the part DLL and the anchor block must be obtained.
DosQueryModuleHandle(MODULENAME, &_ModuleHandle);
_habDeskTop = WinQueryAnchorBlock( HWND_DESKTOP );
// Get tokens representing the frame, large icon, small icon and
// thumbnail views, respectively, so a new unique token is generated
// if the type has not yet been tokenized.
_Session = somSelf->GetStorageUnit(ev)->GetSession(ev);
_FrameView = _Session->Tokenize(ev, kODViewAsFrame);
_LargeIconView = _Session->Tokenize(ev, kODViewAsLargeIcon);
_SmallIconView = _Session->Tokenize(ev, kODViewAsSmallIcon);
_ThumbnailView = _Session->Tokenize(ev, kODViewAsThumbnail);
}
/****************************************************************************
*
* Method(s) : PushButtonDisplayMsgBox()
*
* Description : This method displays a message window when Push Button
* is depressed.
*
* Parameters : PushButtonPart *somSelf - References the object
* Environment *ev - References SOM environment
* information
* ODFacet* facet - References the facet for this object
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonDisplayMsgBox(PushButtonPart *somSelf,
Environment *ev,
ODFacet* facet)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonDisplayMsgBox");
CHAR szMsg[MSGBUFFERSIZE]; // buffer for message test
// Load the message text from the resource (DLL file in this case).
WinLoadString( _habDeskTop, _ModuleHandle, IDS_PUSHBUTTONMSG, sizeof(szMsg),
(PSZ)szMsg );
// Create and display the message window.
WinMessageBox( HWND_DESKTOP, _hwndPushButton,
szMsg, kTitleBarText,
0, MB_OK | MB_INFORMATION | MB_MOVEABLE );
}
/****************************************************************************
*
* Method(s) : PushButtonsomInit()
*
* Description : This method initializes instance variables or attributes
* in a newly created object. It is similar to constructor
* method in C++.
*
* Parameters : PushButtonPart *somSelf - References the object to be
* initialized
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonsomInit(PushButtonPart *somSelf)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonsomInit");
// Call the superclass (parent) somInit method.
PushButtonPart_parent_ContainerPart_somInit(somSelf);
// Set initial values for the instance variables
_fIsInitFromStorage = kODFalse;
_fShowDefaultFrameSize = kODTrue;
}
/****************************************************************************
*
* Method(s) : PushButtonsomUninit()
*
* Description : This method is the SOM equivalent of a C++ destructor
* in that it is called by the run-time system when its
* object (PushButtonPart in this case) is deleted.
*
* Parameters : PushButtonPart *somSelf - References the object to be
* uninitialized
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonsomUninit(PushButtonPart *somSelf)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonsomUninit");
// Deallocate the memory which used by the instance variable in run-time
delete[] _fBuffer;
// Call the superclass (parent) somUninit method.
PushButtonPart_parent_ContainerPart_somUninit(somSelf);
}
/****************************************************************************
*
* Method(s) : PushButtonInitPart()
*
* Description : OpenDoc calls the InitPart method of the part object,
* if the part is newly created from stationery. This method
* prepares the part properties and values that will allow
* the part editor to run.
*
* Parameters : PushButtonPart *somSelf - References the object
* (part) to be initialized
* Environment *ev - References SOM environment
* information
* ODStorageUnit* storageUnit - References the storage unit
* for the part
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonInitPart(PushButtonPart *somSelf,
Environment *ev,
ODStorageUnit* storageUnit,
ODPart* partWrapper)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonInitPart");
// Call the superclass (parent) InitPart method.
PushButtonPart_parent_ContainerPart_InitPart(somSelf, ev,
storageUnit, partWrapper);
// Call the common initialization code in the PushButtonPart object.
somSelf->CommonInitPart(ev);
// Initialize instance variable by loading the message text from
// the resource (DLL file in this case).
WinLoadString( _habDeskTop, _ModuleHandle, PB_INITTEXT, TEXTBUFFERSIZE,
_fBuffer );
}
/****************************************************************************
*
* Method(s) : PushButtonInitPartFromStorage()
*
* Description : OpenDoc calls the part's InitPartFromStorage method of
* the part object, if the part was previously created,
* either as the root part or embedded in a document.
*
* This method should do many of the same things as InitPart,
* but which must also handle reading content information
* from the storage unit into memory.
*
* Parameters : PushButtonPart *somSelf - References the object
* (part) to be initialized
* Environment *ev - References SOM environment
* information
* ODStorageUnit* storageUnit - References the storage unit
* for the part
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonInitPartFromStorage(PushButtonPart *somSelf,
Environment *ev,
ODStorageUnit* storageUnit,
ODPart* partWrapper)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonInitPartFromStorage");
// Call the superclass (parent) InitPartFromStorage method.
PushButtonPart_parent_ContainerPart_InitPartFromStorage(somSelf,
ev,
storageUnit,
partWrapper);
// Set the flag to true
_fIsInitFromStorage = kODTrue;
// Call the common initialization code in the PushButtonPart object.
somSelf->CommonInitPart(ev);
// Focus and read in the part's content value from the storage unit.
ODStorageUnit* su = somSelf->GetStorageUnit(ev);
su->Focus(ev, kODPropContents, kODPosUndefined,
kPushButtonTextType, 0, kODPosUndefined);
StorageUnitGetValue(su, ev, TEXTBUFFERSIZE, _fBuffer);
// Focus the part's storage unit on the kODPropPushButtonAttr
// Property and the kPushButtonAttrType value type.
su->Focus(ev, kODPropPushButtonAttr, kODPosUndefined,
kPushButtonAttrType, 0, kODPosUndefined);
StorageUnitGetValue(su, ev, sizeof(_fShowDefaultFrameSize),
(ODValue)&_fShowDefaultFrameSize);
}
/****************************************************************************
*
* Method(s) : PushButtonExternalize()
*
* Description : OpenDoc calls the Externalize method of your part editor
* object whenever it is necessary to write the part to
* persistent storage. The most common circumstance is
* when the user saves the document.
*
* Parameters : PushButtonPart *somSelf - References the object which should
* externalize its data
* Environment *ev - References SOM environment
* information
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonExternalize(PushButtonPart *somSelf,
Environment *ev)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonExternalize");
// Call the superclass (parent) Externalize method.
PushButtonPart_parent_ContainerPart_Externalize(somSelf,
ev);
// Retrieve a pointer to the part's storage unit.
ODStorageUnit* su = somSelf->GetStorageUnit(ev);
// Verify that the storage unit has the appropriate properties
// and values to allow us to run. If not, add them.
somSelf->CheckAndAddProperties(ev, su);
// Write out the part's content.
somSelf->ExternalizeContent(ev, su);
}
/****************************************************************************
*
* Method(s) : PushButtonCloneInto()
*
* Description : Deep-copy all properties and values of this storage
* unit to the specified toSU.
*
* Parameters : PushButtonPart *somSelf - References the object which should
* externalize its data
* Environment *ev - References SOM environment
* information
* ODDraftKey key - Identifying the clone transaction.
* ODStorageUnit* toSU - All storage units cloned from
* this point on should be within
* the scope of this ODFrame.
* ODFrame* scope - All storage units cloned from
* this point on should be within
* the scope of this ODFrame.
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonCloneInto(PushButtonPart *somSelf,
Environment *ev,
ODDraftKey key, ODStorageUnit* toSU,
ODFrame* scope)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonCloneInto");
// Call the superclass (parent) CloneInto method.
PushButtonPart_parent_ContainerPart_CloneInto(somSelf, ev, key,
toSU, scope);
// We must first verify that we've never written to this storage unit.
// If we have, we should do nothing, otherwise we need to write out
// the current state of the part content.
if ( !toSU->Exists(ev, kODPropContents, kPushButtonTextType, 0) ) {
// Add the properties we need to successfully externalize
// ourselves into the destination storage unit.
somSelf->CheckAndAddProperties(ev, toSU);
// Write out the part's content.
somSelf->ExternalizeContent(ev, toSU);
}
}
/****************************************************************************
*
* Method(s) : PushButtonCheckAndAddProperties()
*
* Description : This method is called during externalization of the part to
* verify all the properties needed to persistently represent
* the current running state of the part.
*
* Parameters : PushButtonPart *somSelf - References the object which should
* externalize its data
* Environment *ev - References SOM environment
* information
* ODStorageUnit* storageUnit - Reference the storage unit to
* save the data
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonCheckAndAddProperties(PushButtonPart *somSelf,
Environment *ev,
ODStorageUnit* storageUnit)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonCheckAndAddProperties");
// Add the Contents Property (kODPropContents) to the storage unit.
// The Push Button part's contents is the text which is displayed
// on the Push Button.
if ( !storageUnit->Exists(ev, kODPropContents, kODNULL, 0) )
storageUnit->AddProperty(ev, kODPropContents);
if ( !storageUnit->Exists(ev, kODPropContents, kPushButtonTextType, 0) )
storageUnit->AddValue(ev, kPushButtonTextType);
// The Push Button part's attribute data includes:
// 1. the frame negotiation flag - whether an initial frame size has
// been negotiated with its containing part.
if ( !storageUnit->Exists(ev, kODPropPushButtonAttr, kODNULL, 0) )
storageUnit->AddProperty(ev, kODPropPushButtonAttr);
if ( !storageUnit->Exists(ev, kODPropPushButtonAttr, kPushButtonAttrType, 0) )
storageUnit->AddValue(ev, kPushButtonAttrType);
}
/****************************************************************************
*
* Method(s) : PushButtonExternalizeContent()
*
* Description : This method is called during externalization of the part. The
* content of the part should be written out.
*
* Parameters : PushButtonPart *somSelf - References the object which should
* externalize its data
* Environment *ev - References SOM environment
* information
* ODStorageUnit* storageUnit - Reference the storage unit to
* save the data
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonExternalizeContent(PushButtonPart *somSelf,
Environment *ev,
ODStorageUnit* storageUnit)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonExternalizeContent");
// Focus the storage unit to the value of preferred representation
// of its contents property and write out the value.
// Focus the storage unit on the kODPropContents contents
// property and the kPushButtonTextType property value.
storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
kPushButtonTextType, 0, kODPosUndefined);
// Write the Push Button text to its location in the part's storage unit.
StorageUnitSetValue(storageUnit, ev, TEXTBUFFERSIZE, (ODValue) _fBuffer);
// Focus the storage unit on the kODPropPushButtonAttr attributes
// property and the kPushButtonAttrType property value.
storageUnit->Focus(ev, kODPropPushButtonAttr, kODPosUndefined,
kPushButtonAttrType, 0, kODPosUndefined);
// Write the contents of the fShowDefaultFrameSize flag (true or false,
// true will show the default frame size).
StorageUnitSetValue(storageUnit, ev, sizeof(_fShowDefaultFrameSize),
(ODValue) &_fShowDefaultFrameSize);
}
/****************************************************************************
*
* Method(s) : PushButtonHandleEvent()
*
* Description : The implementation of a part editor's HandleEvent method
* works in much the same way as event-handling code in a
* standard PM application. This method is overridden
* in order to recognize the event of button ID when user
* clicks mouse button 1 in the content area of the part.
*
* Parameters : PushButtonPart *somSelf - Pointer to the object which
* should handle the event
* Environment *ev - References SOM environment
* information
* ODEventData* event - References event data that indicates
* what type of event has occurred
* ODFrame* frame - References the display frame for
* the part
* ODFacet* facet - References the facet for this object
*
* Returns : ODBoolean value describing if the event was processed or
* not
* kODFalse = event was not processed by this method
* kODTrue = event was processed by this method
*
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope ODBoolean SOMLINK PushButtonHandleEvent(PushButtonPart *somSelf,
Environment *ev,
ODEventData* event,
ODFrame* frame,
ODFacet* facet,
ODEventInfo* eventInfo)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonHandleEvent");
ODBoolean fHandled = kODFalse; // Initialize the result flag to indicate
// that no event was processed by this
// method
// Make sure we have a facet and the facet's window handle is same as
// the event's window handle.
if (facet && event->hwnd == facet->GetFacetHWND(ev)) {
// A switch statement is used to determine if the event passed to the
// method can be handled by the method. Note that a switch statement
// is used, rather than an if statement, to allow for expansion. This
// style also mimics that of a PM window procedure.
switch (event->msg) {
case WM_COMMAND:
// Verify the value of mp1 and handle the event if it matches
// the button ID.
switch (SHORT1FROMMP(event->mp1)) {
case PB_ID:
// Just beep and display a message box
DosBeep(2000,100);
DosBeep(1500,50);
somSelf->DisplayMsgBox(ev, facet);
break;
default:
break;
}
fHandled = kODTrue;
break;
default:
break;
}
}
// Call and return the superclass (parent) HandleEvent method.
// (if the event was not handled by this push button part).
if (fHandled == kODFalse) {
return (PushButtonPart_parent_ContainerPart_HandleEvent(somSelf,
ev,
event,
frame,
facet,
eventInfo));
}
else {
return fHandled;
}
}
/****************************************************************************
*
* Method(s) : PushButtonFacetAdded()
*
* Description : This method notifies this frame that a facet has been
* added to it.
*
* The facet being added calls this method on its frame.
* The frame in turn calls the parent's FacetAdded method
* to notify its part that a facet has been added to one
* of its frames.
*
* Parameters : PushButtonPart *somSelf - References the object
* Environment *ev - References SOM environment
* information
* ODFacet* facet - A reference to the facet to be added
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonFacetAdded(PushButtonPart *somSelf,
Environment *ev,
ODFacet* facet)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonFacetAdded");
// Call the superclass (parent) FacetAdded method.
// If you don't call the parent method then your embedded part(s) will
// not show up when you drag and drop the push button to a container part
PushButtonPart_parent_ContainerPart_FacetAdded(somSelf, ev,
facet);
HWND hwndFacet = facet->GetFacetHWND(ev); // Window handle of facet.
// If find facet's window handle
if ( hwndFacet ) {
// Use PM control to create this push button
// We will give the position and size information of the window
// in GeometryChanged method
_hwndPushButton = WinCreateWindow(hwndFacet, WC_BUTTON, _fBuffer,
BS_PUSHBUTTON | BS_DEFAULT | BS_TEXT,
0, 0, 0, 0,
hwndFacet, HWND_TOP, PB_ID, 0, 0);
ULONG ulStyle = WinQueryWindowULong(_hwndPushButton, QWL_STYLE);
WinSetWindowULong(_hwndPushButton,
QWL_STYLE,
ulStyle & ~WS_PARENTCLIP);
ODFrame* frame = facet->GetFrame(ev);
if ( _fShowDefaultFrameSize == kODFalse ) {
// No frame negotiation. The part is initialized from the
// storage unit.
ODTypeToken view = frame->GetViewType(ev);
// Make sure we display our part in correct view type.
// Force to setup a correct used shape for different view types and
// only frame view and thumbnail view need to call GeometryChanged
// method to display the Button.
if ( view == _FrameView ) {
// Size and repaint the window.
somSelf->GeometryChanged(ev, facet, kODFalse, kODFalse);
}
else {
somSelf->ViewTypeChanged(ev, frame);
if ( view == _ThumbnailView )
// Size and repaint the window.
somSelf->GeometryChanged(ev, facet, kODFalse, kODFalse);
}
}
else {
// Do the frame negotiation
// Setup Push Button size in OpenDoc coordinate
// The MAKEFIXED macro creates a fixed value from an
// integer and a faction.
ODRect newRect = { 0, MAKEFIXED(PB_HEIGHT,0),
MAKEFIXED(PB_WIDTH,0), 0 };
ODShape* newShape = frame->CreateShape(ev);
newShape->SetRectangle(ev, &newRect);
// Negotiate the display frame size with its containing part.
// There is no need to argue with containing part, so just accept
// the shape.
frame->RequestFrameShape(ev, newShape, kODNULL);
ODReleaseObject(ev, newShape);
_fShowDefaultFrameSize = kODFalse;
// Size and repaint the window.
somSelf->GeometryChanged(ev, facet, kODFalse, kODFalse);
}
// Make sure we act on the drag and drop event.
facet->SetHandleMouseEvents(ev, kODPartHandlesDragDropEvents);
}
}
/****************************************************************************
*
* Method(s) : PushButtonFacetRemoved()
*
* Description : This method notifies this frame that a facet has been
* removed from it.
*
* The facet being removed calls this method on its frame.
* The frame in turn calls the ODPart::FacetRemoved method
* to notify its part that a facet has been removed from one
* of its frames.
*
* Parameters : PushButtonPart *somSelf - References the object
* Environment *ev - References SOM environment
* information
* ODFacet* facet - A reference to the facet to be
* removed
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonFacetRemoved(PushButtonPart *somSelf,
Environment *ev,
ODFacet* facet)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonFacetRemoved");
// Destroy the push button window handle if find any
if ( _hwndPushButton != kODNULL )
WinDestroyWindow(_hwndPushButton);
// Call the superclass (parent) FacetRemoved method.
PushButtonPart_parent_ContainerPart_FacetRemoved(somSelf, ev,
facet);
}
/****************************************************************************
*
* Method(s) : PushButtonGeometryChanged()
*
* Description : This method is called to inform your part that the clipping
* shape and/or external transform of one of its facets has
* changed.
*
* Parameters : PushButtonPart *somSelf - References the object
* Environment *ev - References SOM environment
* information
* ODFacet* facet - A refernece to the facet where
* the clip shape has changed
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonGeometryChanged(PushButtonPart *somSelf,
Environment *ev,
ODFacet* facet,
ODBoolean clipShapeChanged,
ODBoolean externalTransformChanged)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonGeometryChanged");
// Push Button has been created
if (_hwndPushButton) {
MATRIXLF mtx; // Transformation matrix-elements structure.
ODRect rect; // Rectangle whose sides are aligned with the axes
// of the OpenDoc coordinate system.
ODTransform* transform = facet->AcquireFrameTransform(ev, kODNULL);
// We want to display the PushButton if our frame transform specifies
// only translation and scale (no reflection, rotation or shear).
transform->GetMATRIXLF(ev, &mtx);
if (mtx.fxM12 == 0 && mtx.fxM21 == 0 && mtx.fxM11 > 0 && mtx.fxM22 > 0 ) {
// Hide the push button window first before we do any updates
WinShowWindow(_hwndPushButton, FALSE);
ODTypeToken view = facet->GetFrame(ev)->GetViewType(ev);
// Get the smallest retangle that contains this shape and use it
// to set the position and size of push button window.
// Use used shape when in thumbnail view and use frame shape when
// in other types of view.
if ( view == _ThumbnailView ) {
ODShape* usedShape = facet->GetFrame(ev)->AcquireUsedShape(ev, kODNULL);
usedShape->GetBoundingBox(ev, &rect);
ODReleaseObject(ev, usedShape);
}
else {
ODShape* frameShape= facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
frameShape->GetBoundingBox(ev, &rect);
ODReleaseObject(ev, frameShape);
}
ODPoint botLeft = {rect.left, rect.bottom};
ODPoint topRight = {rect.right, rect.top};
transform->TransformPoint(ev, &botLeft);
transform->TransformPoint(ev, &topRight);
WinSetWindowPos(_hwndPushButton, 0,
FIXED2LONG(botLeft.x),
FIXED2LONG(botLeft.y),
FIXED2LONG(topRight.x - botLeft.x),
FIXED2LONG(topRight.y - botLeft.y),
SWP_MOVE | SWP_SIZE);
// Make a local copy of the aggregate clip shape and use it
// to get the transform object that represents the window
// frame transform associated with this facet.
ODShape* tempShape = facet->AcquireAggregateClipShape(ev, kODNULL);
ODShape* clipShape = tempShape->Copy(ev);
ODReleaseObject(ev, tempShape);
ODTransform* windowFrameTransform = facet->AcquireWindowFrameTransform(ev, kODNULL);
clipShape->Transform(ev, windowFrameTransform);
ODReleaseObject(ev, windowFrameTransform);
// Clip shape is in window coords of my facet window.
// Move to window coords of the PushButton window.
ODTransform* offset = new ODTransform;
botLeft.x = -botLeft.x;
botLeft.y = -botLeft.y;
offset->SetOffset(ev, &botLeft);
clipShape->Transform(ev, offset);
// Set window clipping
// This API will support of proper clipping of non-OpenDoc aware
// windows (PM controls) within OpenDoc. Since OpenDoc parts
// may have arbitrary (non-rectangular) clip shapes, any PM control
// windows within an OpenDoc part may need to be clipped to a
// shape which is determined by the clip shape of it's
// containing part and/or the clip shapes of overlapping parts.
WinSetClipRegion(_hwndPushButton, clipShape->GetRegion(ev));
delete clipShape;
// Set the window to visible state when in frame and thumbnail view.
if ( view == _FrameView || view == _ThumbnailView )
WinShowWindow(_hwndPushButton, TRUE);
else
WinShowWindow(_hwndPushButton, FALSE);
}
else {
// We can't properly display the PushButton in this frame with
// the given transform. Hide the window and we'll draw the text
// into the frame in our Draw method.
WinShowWindow(_hwndPushButton, FALSE);
}
ODReleaseObject(ev, transform);
}
// Call the superclass (parent) GeometryChanged method.
// If you don't call the parent method then your embedded part(s) will
// not move together with push button part.
PushButtonPart_parent_ContainerPart_GeometryChanged(somSelf,
ev, facet,
clipShapeChanged,
externalTransformChanged);
}
/****************************************************************************
*
* Method(s) : PushButtonDraw()
*
* Description : This method tells the part associated with this facet to
* draw itself within the portion of the PushButton part
* that needs updating in this facet.
*
* Parameters : PushButtonPart *somSelf - A pointer to the object to be drawn
* Environment *ev - References the SOM environment
* information
* ODFacet* facet - References the facet for this object
* ODShape* invalidShape - References the update shape,
* expressed in the coordinate
* system of the facet's frame
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonDraw(PushButtonPart *somSelf,
Environment *ev, ODFacet* facet,
ODShape* invalidShape)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonDraw");
// Get the current view type - how the part is currently display.
ODTypeToken view = facet->GetFrame(ev)->GetViewType(ev);
if ( view == _FrameView ) {
// Don't need to do anything here since we ask PM to draw this
// push button.
}
else if ( view == _LargeIconView ) {
// Set Push Button window to invisible state and invoke
// DrawIconView with size (length of one side) set to LARGEICONSIZE.
WinShowWindow(_hwndPushButton, FALSE);
somSelf->DrawIconView(ev, facet, LARGEICONSIZE);
}
else if ( view == _SmallIconView ) {
// Set Push Button window to invisible state and invoke
// DrawIconView with size (length of one side) set to SMALLICONSIZE.
WinShowWindow(_hwndPushButton, FALSE);
somSelf->DrawIconView(ev, facet, SMALLICONSIZE);
}
else if ( view == _ThumbnailView )
// Invoke DrawThumbnailView.
somSelf->DrawThumbnailView(ev, facet);
}
/****************************************************************************
*
* Standard View Types
*
****************************************************************************/
/****************************************************************************
*
* Method(s) : PushButtonViewTypeChanged()
*
* Description : This method is called to notify Push Button part that the
* view type of one of its embedded frames has been changed.
*
* Parameters : PushButtonPart *somSelf - A pointer to the object to be drawn
* Environment *ev - References the SOM environment
* information
* ODFrame frame - A reference to a display frame of
* push button part
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonViewTypeChanged(PushButtonPart *somSelf,
Environment *ev,
ODFrame* frame)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonViewTypeChanged");
// Call the superclass (parent) ViewTypeChanged method.
PushButtonPart_parent_ContainerPart_ViewTypeChanged(somSelf,
ev, frame);
// Obtain the current view type
ODTypeToken view = frame->GetViewType(ev);
// The view field may be null, if so, we prefer to be displayed
// in a frame view.
if ( view == kODNullTypeToken )
frame->SetViewType(ev, _FrameView);
ODRect usedShapeRect; // Used shape rectangle.
ODShape* newUsedShape = new ODShape();
// Obtain a copy of used shape from frame shape.
ODShape* frameShape = frame->AcquireFrameShape(ev, kODNULL);
newUsedShape->CopyFrom(ev, frameShape);
ODReleaseObject(ev, frameShape);
// Obtain the used shape's bounding box
newUsedShape->GetBoundingBox(ev, &usedShapeRect);
CHAR szFontNameSize[TEXTBUFFERSIZE]; // Buffer to store font name and size.
if ( view == _FrameView ) {
// Reset used shape to frame shape
frame->ChangeUsedShape(ev, kODNULL, kODNULL);
// Set the text on button to default font and size
strcpy( szFontNameSize, "10.System Proportional Non-ISO" );
WinSetPresParam( _hwndPushButton,
PP_FONTNAMESIZE,
strlen( szFontNameSize ) + 1,
(PVOID)szFontNameSize );
}
else if ( view == _LargeIconView ) {
// Change the new used shape rectangle dimensions to the LARGEICONSIZE.
ODRect Rect = { 0, MAKEFIXED(LARGEICONSIZE,0), MAKEFIXED(LARGEICONSIZE,0), 0};
newUsedShape->SetRectangle(ev, &Rect);
frame->ChangeUsedShape(ev, newUsedShape, kODNULL);
}
else if ( view == _SmallIconView ) {
// Change the new used shape rectangle dimensions to the SMALLICONSIZE.
ODRect Rect = { 0, MAKEFIXED(SMALLICONSIZE,0), MAKEFIXED(SMALLICONSIZE,0), 0};
newUsedShape->SetRectangle(ev, &Rect);
frame->ChangeUsedShape(ev, newUsedShape, kODNULL);
}
else if ( view == _ThumbnailView ) {
// Change the new used shape rectangle dimensions to the THUMBNAILSIZE.
ODRect Rect = { 0, MAKEFIXED(THUMBNAILSIZE,0), MAKEFIXED(THUMBNAILSIZE,0), 0};
newUsedShape->SetRectangle(ev, &Rect);
frame->ChangeUsedShape(ev, newUsedShape, kODNULL);
// Set the text on button to a different font and smaller size than
// frame view.
strcpy( szFontNameSize, "4.System VIO" );
WinSetPresParam( _hwndPushButton,
PP_FONTNAMESIZE,
strlen( szFontNameSize ) + 1,
(PVOID)szFontNameSize );
}
// If Push Button part is the root part then force a redraw of the
// Push Button part else force a redraw of the containing part.
ODFrame* parentFrame = frame->AcquireContainingFrame(ev);
if ( parentFrame != kODNULL )
parentFrame->Invalidate(ev, kODNULL, kODNULL);
ODReleaseObject(ev, parentFrame);
}
/****************************************************************************
*
* Method(s) : PushButtonDrawIconView()
*
* Description : Draw Push Button part as a large or small icon.
*
* Parameters : PushButtonPart *somSelf - A pointer to the object to be drawn
* Environment *ev - References the SOM environment
* information
* ODFacet* facet - References the facet for this object
* 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 PushButtonDrawIconView(PushButtonPart *somSelf,
Environment *ev,
ODFacet* facet,
ODULong size)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonDrawIconView");
BITMAPINFOHEADER2 bmp; // Bitmap information header structure.
ODFrame* displayFrame = facet->GetFrame(ev);
// Get the icon's dimensions in terms of OpenDoc's coordinate system.
ODRect rect;
ODShape* usedShape = displayFrame->AcquireUsedShape(ev, kODNULL);
usedShape->GetBoundingBox(ev, &rect);
ODReleaseObject(ev, usedShape);
ODRECTL frameRect(rect);
HBITMAP hbm, // Bitmap handle associated with load from resource.
hbmNew, // New bitmap handle associated with bitmap created in memory.
hbmOld; // Old bitmap handle associated with selected bitmap.
POINTL aptl[4]; // Target/source coordinate pair array.
// Get PM Presentation Space from the facet.
HPS hps = facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODGPI)->GetPS(ev, facet);
// Set the transformation matrix from content transform.
MATRIXLF mtx;
ODTransform* contentTransform = facet->AcquireContentTransform(ev, kODNULL);
contentTransform->GetMATRIXLF(ev, &mtx);
ODReleaseObject(ev, contentTransform);
GpiSetModelTransformMatrix(hps, 9, &mtx, TRANSFORM_REPLACE);
// Load the bitmap as resource identified by IDB_BMP.
hbm = GpiLoadBitmap(hps, _ModuleHandle,
IDB_BMP,
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 in worrld coordinate
aptl[0].y = frameRect.yBottom; // target rectangle bottom in worrld coordinate
aptl[1].x = frameRect.xRight; // target rectangle right in worrld coordinate
aptl[1].y = frameRect.yTop; // target rectangle top in worrld coordinate
aptl[2].x = aptl[2].y = 0; // source rectangle left and bottom
aptl[3].x = bmp.cx; // source rectangle right in worrld coordinate
aptl[3].y = bmp.cy; // source rectangle top in worrld coordinate
// 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 Space).
facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODGPI)->ReleasePS(ev, facet);
}
/****************************************************************************
*
* Method(s) : PushButtonDrawThumbnailView()
*
* Description : Draw the Push Button part as a thumbnail.
*
* Parameters : PushButtonPart *somSelf - A pointer to the object to be drawn
* Environment *ev - References the SOM environment
* information
* ODFacet* facet - References the facet for this object
*
* Returns : void
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope void SOMLINK PushButtonDrawThumbnailView(PushButtonPart *somSelf,
Environment *ev,
ODFacet* facet)
{
PushButtonPartData *somThis = PushButtonPartGetData(somSelf);
PushButtonPartMethodDebug("PushButtonPart","PushButtonDrawThumbnailView");
// Size and repaint the window.
somSelf->GeometryChanged(ev, facet, kODFalse, kODFalse);
}
/****************************************************************************
*
* Part Registration
*
****************************************************************************/
/****************************************************************************
*
* Method(s) : M_PushButtonPartclsGetODPartHandlerName()
*
* Description : Return the SOM class name (PushButtonPart) to the
* registration process.
*
* Parameters : M_PushButtonPart *somSelf - References the SOM object
* Environment *ev - References the SOM environment
* information
*
* Returns : ISOString - SOM class name of Push Button part
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope ISOString SOMLINK M_PushButtonPartclsGetODPartHandlerName(M_PushButtonPart *somSelf,
Environment *ev)
{
/* M_PushButtonPartData *somThis = M_PushButtonPartGetData(somSelf); */
M_PushButtonPartMethodDebug("M_PushButtonPart","M_PushButtonPartclsGetODPartHandlerName");
// Set string to the Part Handler, or SOM class ("PushButtonPart")
ISOString partHandlerName = kPartHandlerName;
return partHandlerName;
}
/****************************************************************************
*
* Method(s) : M_PushButtonPartclsGetODPartHandlerDisplayName()
*
* Description : Return the part handler name OpenDoc will associate with
* its template to the registration.
*
* Parameters : M_PushButtonPart *somSelf - References the SOM object
* Environment *ev - References the SOM environment
* information
*
* Returns : string - Part handler display name
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope string SOMLINK M_PushButtonPartclsGetODPartHandlerDisplayName(M_PushButtonPart *somSelf,
Environment *ev)
{
/* M_PushButtonPartData *somThis = M_PushButtonPartGetData(somSelf); */
M_PushButtonPartMethodDebug("M_PushButtonPart","M_PushButtonPartclsGetODPartHandlerDisplayName");
// Set string to the Part Handler Display name ("Push Button Part")
string partHandlerDisplayName = kPartHandlerDisplayName;
return partHandlerDisplayName;
}
/****************************************************************************
*
* Method(s) : M_PushButtonPartclsGetODPartKinds()
*
* Description : Return the Push Button part handler's Part Kind data to
* the registration process. Place the data in a record
* structure and return it.
*
* Parameters : M_PushButtonPart *somSelf - References the SOM object
* Environment *ev - References the SOM environment
* information
*
* Returns : _IDL_SEQUENCE_PartKindInfo - Part Kind record structure
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope _IDL_SEQUENCE_PartKindInfo SOMLINK M_PushButtonPartclsGetODPartKinds(M_PushButtonPart *somSelf,
Environment *ev)
{
/* M_PushButtonPartData *somThis = M_PushButtonPartGetData(somSelf); */
M_PushButtonPartMethodDebug("M_PushButtonPart","M_PushButtonPartclsGetODPartKinds");
// Structure which contains tha part's part kind information. This is
// information about the data types the part supports.
_IDL_SEQUENCE_PartKindInfo PushButtonPartInfo;
// Create structure PartKindInfo and allocate memory for variable
PartKindInfo * info = (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));
info->partKindName = (ISOString) SOMMalloc(strlen(kKindPushButtonPart) + 1);
info->partKindDisplayName = (string)SOMMalloc(strlen(kKindDisplayName)+1);
info->filenameFilters = (string)SOMMalloc(strlen("")+1);
info->filenameTypes = (string)SOMMalloc(strlen("")+1);
info->categories = (string)SOMMalloc(strlen(kODCategoryControl)+1);
info->categoryDisplayName = (string)SOMMalloc(strlen(kCategory)+1);
info->objectID = (string)SOMMalloc(strlen("")+1);
// Copy the information into the structure
strcpy(info->partKindName , kKindPushButtonPart);
strcpy(info->partKindDisplayName, kKindDisplayName);
strcpy(info->filenameFilters, "");
strcpy(info->filenameTypes, "");
strcpy(info->categories, kODCategoryControl);
strcpy(info->categoryDisplayName, kCategory);
strcpy(info->objectID, "");
PushButtonPartInfo._maximum = 1;
PushButtonPartInfo._length = 1;
PushButtonPartInfo._buffer = info;
return PushButtonPartInfo;
}
/****************************************************************************
*
* Method(s) : M_PushButtonPartclsGetOLE2ClassId()
*
* Description : Return the OLE 2 identifier to the registration process.
*
* Parameters : M_PushButtonPart *somSelf - References the SOM object
* Environment *ev - References the SOM environment
* information
*
* Returns : string - OLE2 class id
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope string SOMLINK M_PushButtonPartclsGetOLE2ClassId(M_PushButtonPart *somSelf,
Environment *ev)
{
/* M_PushButtonPartData *somThis = M_PushButtonPartGetData(somSelf); */
M_PushButtonPartMethodDebug("M_PushButtonPart","M_PushButtonPartclsGetOLE2ClassId");
// The OLE2 class identifier is current empty.
string classID = "";
return classID; // Return the empty string.
}
/****************************************************************************
*
* Method(s) : M_PushButtonPartclsGetWindowsIconFileName()
*
* Description : Return the file name of the icon to be associated with
* the Push Button part handler's template to the
* registration process.
*
* Parameters : M_PushButtonPart *somSelf - References the SOM object
* Environment *ev - References the SOM environment
* information
*
* Returns : string - Icon file name
*
* Notes : N/A
*
****************************************************************************/
SOM_Scope string SOMLINK M_PushButtonPartclsGetWindowsIconFileName(M_PushButtonPart *somSelf,
Environment *ev)
{
/* M_PushButtonPartData *somThis = M_PushButtonPartGetData(somSelf); */
M_PushButtonPartMethodDebug("M_PushButtonPart","M_PushButtonPartclsGetWindowsIconFileName");
// There is no icon associated with the Push Button part handler.
string iconFileName = "";
return iconFileName; // Return the empty string.
}
/****************************************************************************
* End of File
****************************************************************************/