home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 11.4 KB | 403 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWUtil.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWGDEV_H
- #include "FWGDev.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWGRGLOB_H
- #include "FWGrGlob.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWFXMATH_H
- #include "FWFxMath.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
- #include <Drag.h>
- #endif
-
- // ----- Windows Includes -----
-
- #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
- #include <windows.h>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment framework
- #endif
-
- //========================================================================================
- // Globales Methods
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // ::XorShape
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR ODShape* XorShape(Environment* ev, ODShape* a, ODShape* b)
- {
- ODShape* result = a->Copy(ev);
- result->Union(ev, b);
-
- FW_CAcquiredODShape aqIntersect(a->Copy(ev));
- aqIntersect->Intersect(ev, b);
-
- result->Subtract(ev, aqIntersect);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // ::FW_Beep
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR void FW_Beep()
- {
- #ifdef FW_BUILD_MAC
- ::SysBeep(10);
- #endif
- #ifdef FW_BUILD_WIN
- ::MessageBeep(-1);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // ::CenterRectOnScreen
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR void CenterRectOnScreen(FW_SPlatformRect& aRect, FW_Boolean horizontally, FW_Boolean vertically, FW_Boolean forDialog)
- {
- #ifdef FW_BUILD_MAC
- short newSize = 0;
- FW_SPlatformPoint rectSize, screenSize;
-
- ::SetPt(&rectSize, aRect.right - aRect.left, aRect.bottom - aRect.top);
- ::SetPt(&screenSize, FW_QDGlobals.screenBits.bounds.right - FW_QDGlobals.screenBits.bounds.left,
- FW_QDGlobals.screenBits.bounds.bottom - FW_QDGlobals.screenBits.bounds.top);
- screenSize.v -= GetMBarHeight();
-
- // Calculate screen size minus menu bar
- if (horizontally)
- aRect.left = (screenSize.h - rectSize.h) / 2;
- if (vertically)
- if (forDialog)
- {
- newSize = (screenSize.v - rectSize.v) / 5;
- aRect.top = (short)(FW_Maximum(newSize, 10) + GetMBarHeight());
- }
- else
- aRect.top = (screenSize.v - rectSize.v) / 2;
-
- aRect.bottom = aRect.top + rectSize.v;
- aRect.right = aRect.left + rectSize.h;
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_UNUSED(aRect);
- FW_UNUSED(horizontally);
- FW_UNUSED(vertically);
- FW_UNUSED(forDialog);
- FW_DEBUG_MESSAGE("Not Yet Implemented");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_GetMainScreenBounds
- //----------------------------------------------------------------------------------------
-
- void FW_GetMainScreenBounds(FW_CRect& bounds)
- {
- #ifdef FW_BUILD_MAC
- FW_CFixed menuBarHeight = FW_IntToFixed(LMGetMBarHeight());
- bounds.Set(FW_kFixed0,
- menuBarHeight,
- FW_IntToFixed(FW_QDGlobals.screenBits.bounds.right),
- menuBarHeight + FW_IntToFixed(FW_QDGlobals.screenBits.bounds.bottom));
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_SPlatformRect scr;
- ::GetWindowRect(::GetDesktopWindow(), &scr);
- bounds = scr;
- #endif
- }
-
- //========================================================================================
- // class FW_CFacetContext
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetContext::FW_CFacetContext
- //----------------------------------------------------------------------------------------
-
- FW_CFacetContext::FW_CFacetContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
- FW_CGraphicContext(ev),
- fFacet(facet)
- {
- FW_ASSERT(facet != NULL);
-
- FW_CAcquiredODTransform aqContentTransform = facet->AcquireContentTransform(ev, NULL);
-
- // InitGraphicContext expect clip shape in content coordinates
- FW_CAcquiredODTransform aqInternalTransform = fFacet->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
- FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL)));
- aqClipShape->InverseTransform(ev, aqInternalTransform);
-
- if (invalidShape != NULL)
- aqClipShape->Intersect(ev, invalidShape);
-
- InitGraphicContext(FW_CFacetPartInfo::GetFacetGraphicDevice(ev, fFacet),
- aqContentTransform,
- aqClipShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetContext::~FW_CFacetContext
- //----------------------------------------------------------------------------------------
-
- FW_CFacetContext::~FW_CFacetContext()
- {
- }
-
- //========================================================================================
- // class FW_CWindowContext
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::FW_CWindowContext
- //----------------------------------------------------------------------------------------
-
- FW_CWindowContext::FW_CWindowContext(Environment* ev, ODFacet* odFacet) :
- FW_CGraphicContext(ev),
- fTempDevice(NULL),
- fODWindow(NULL)
- {
- InitWindowContext(ev, odFacet->GetWindow(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::FW_CWindowContext
- //----------------------------------------------------------------------------------------
-
- FW_CWindowContext::FW_CWindowContext(Environment* ev, ODWindow *odWindow) :
- FW_CGraphicContext(ev),
- fTempDevice(NULL),
- fODWindow(NULL)
- {
- InitWindowContext(ev, odWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::InitWindowContext
- //----------------------------------------------------------------------------------------
-
- void FW_CWindowContext::InitWindowContext(Environment* ev, ODWindow *odWindow)
- {
- FW_ASSERT(odWindow != NULL);
- fODWindow = odWindow;
- fODWindow->Acquire(ev);
-
- ODFacet *facet = odWindow->GetRootFacet(ev);
-
- #ifdef FW_BUILD_MAC
- FW_CRect rect(odWindow->GetPlatformWindow(ev)->portRect);
- #endif
- #ifdef FW_BUILD_WIN
- FW_SPlatformRect clientRect;
- ::GetClientRect(odWindow->GetPlatformWindow(ev), &clientRect);
- FW_CRect rect(clientRect);
- #endif
-
- FW_CAcquiredODShape aqClipShape = ::FW_NewODShape(ev, rect);
-
- /*
- [HLX] there is a problem trying to reuse the graphic device of the root frame.
- First of all if the graphic device has a fContext, it should be suspended. Also
- now that we are running static part I don't know what the effect is. We need to
- look at that. Might be able to put it back when we move the graphic to a SOM DLL.
-
- FW_CGraphicDevice* device = FW_CFacetPartInfo::GetFacetGraphicDevice(ev, facet);
- if (device == NULL)
- {
- fTempDevice = new FW_CGraphicDevice(ev, facet->GetCanvas(ev));
- device = fTempDevice;
- }
-
- InitGraphicContext(device,
- NULL,
- aqClipShape);
- */
-
- fTempDevice = new FW_CGraphicDevice(ev, facet->GetCanvas(ev));
-
- InitGraphicContext(fTempDevice,
- NULL,
- aqClipShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::~FW_CWindowContext
- //----------------------------------------------------------------------------------------
-
- FW_CWindowContext::~FW_CWindowContext()
- {
- if (fODWindow)
- fODWindow->Release(somGetGlobalEnvironment());
-
- if (fTempDevice)
- fTempDevice->Release();
- }
-
- //========================================================================================
- // class FW_CPlatformGraphicContext
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformGraphicContext::FW_CPlatformGraphicContext
- //----------------------------------------------------------------------------------------
-
- FW_CPlatformGraphicContext::FW_CPlatformGraphicContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
- FW_CGraphicContext(ev),
- fFacet(facet)
- #ifdef FW_BUILD_MAC
- ,fMacPort(NULL)
- #endif
- {
- FW_ASSERT(facet != NULL);
-
- // InitGraphicContext expect clip shape in content coordinates
- FW_CAcquiredODTransform aqInternalTransform = fFacet->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
- FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL)));
- aqClipShape->InverseTransform(ev, aqInternalTransform);
-
- if (invalidShape != NULL)
- aqClipShape->Intersect(ev, invalidShape);
-
- InitGraphicContext(FW_CFacetPartInfo::GetFacetGraphicDevice(ev, fFacet),
- NULL,
- aqClipShape);
-
- #ifdef FW_BUILD_MAC
- FW_CAcquiredODTransform aqContentTransform = facet->AcquireContentTransform(ev, NULL);
- FW_CPoint origin(FW_kZeroPoint);
- origin.Transform(ev, aqContentTransform);
-
- ::GetPort(&fMacPort);
- fMacOrigin.h = fMacPort->portRect.left;
- fMacOrigin.v = fMacPort->portRect.top;
-
- ::SetOrigin(- origin.x.AsInt(), - origin.y.AsInt());
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext
- //----------------------------------------------------------------------------------------
-
- FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext()
- {
- #ifdef FW_BUILD_MAC
- if (fMacPort != NULL)
- {
- GrafPtr port;
- ::GetPort(&port);
- ::SetPort(fMacPort);
- ::SetOrigin(-fMacOrigin.h, -fMacOrigin.v);
- ::SetPort(port);
- }
- #endif
- }
-
- //========================================================================================
- // Storage Unit Utilities
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_SUAddPropValue
- //----------------------------------------------------------------------------------------
-
- void FW_FUNC_ATTR FW_SUAddPropValue(Environment* ev, ODStorageUnit* su, ODPropertyName prop, ODValueType val)
- {
- if (!su->Exists(ev, prop, NULL, 0))
- {
- su->AddProperty(ev, prop)->AddValue(ev, val);
- }
- else
- {
- su->Focus(ev, prop, kODPosUndefined, NULL, 0, kODPosUndefined);
- if (!su->Exists(ev, prop, val, 0))
- su->AddValue(ev, val);
- }
- }
-
-