wxMSW update for CW, wxMac updated
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4803 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
739
include/wx/geometry.h
Normal file
739
include/wx/geometry.h
Normal file
@@ -0,0 +1,739 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: geometry.h
|
||||
// Purpose: Common Geometry Classes
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 08/05/99
|
||||
// RCS-ID:
|
||||
// Copyright: (c)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_GEOMETRY__
|
||||
#define _WX_GEOMETRY__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "geometry.h"
|
||||
#endif
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
|
||||
#elif defined( __WXMAC__ )
|
||||
#include "Math64.h"
|
||||
#define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
|
||||
#else
|
||||
#define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
|
||||
#endif
|
||||
|
||||
class wxDataInputStream ;
|
||||
class wxDataOutputStream ;
|
||||
|
||||
// clipping from Cohen-Sutherland
|
||||
|
||||
enum wxOutCode
|
||||
{
|
||||
wxInside = 0x00 ,
|
||||
wxOutLeft = 0x01 ,
|
||||
wxOutRight = 0x02 ,
|
||||
wxOutTop = 0x08 ,
|
||||
wxOutBottom = 0x04
|
||||
} ;
|
||||
|
||||
// wxPoint2Ds represent a point or a vector in a 2d coordinate system
|
||||
|
||||
class WXDLLEXPORT wxPoint2DDouble
|
||||
{
|
||||
public :
|
||||
wxPoint2DDouble();
|
||||
wxPoint2DDouble( wxDouble x , wxDouble y ) ;
|
||||
wxPoint2DDouble( const wxPoint2DDouble &pt ) ;
|
||||
|
||||
// two different conversions to integers, floor and rounding
|
||||
void GetFloor( wxInt32 *x , wxInt32 *y ) ;
|
||||
void GetRounded( wxInt32 *x , wxInt32 *y ) ;
|
||||
|
||||
wxDouble GetVectorLength() ;
|
||||
wxDouble GetVectorAngle() ;
|
||||
void SetVectorLength( wxDouble length ) ;
|
||||
void SetVectorAngle( wxDouble degrees ) ;
|
||||
void SetPolarCoordinates( wxDouble angle , wxDouble length ) ;
|
||||
// set the vector length to 1.0, preserving the angle
|
||||
void Normalize() ;
|
||||
|
||||
wxDouble GetDistance( const wxPoint2DDouble &pt ) ;
|
||||
wxDouble GetDistanceSquare( const wxPoint2DDouble &pt ) ;
|
||||
wxDouble GetDotProduct( const wxPoint2DDouble &vec ) ;
|
||||
wxDouble GetCrossProduct( const wxPoint2DDouble &vec ) ;
|
||||
|
||||
// the reflection of this point
|
||||
wxPoint2DDouble operator-() ;
|
||||
|
||||
wxPoint2DDouble& operator=(const wxPoint2DDouble& pt) ;
|
||||
wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt) ;
|
||||
wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt) ;
|
||||
wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt) ;
|
||||
wxPoint2DDouble& operator*=(wxDouble n) ;
|
||||
wxPoint2DDouble& operator*=(wxInt32 n) ;
|
||||
wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt) ;
|
||||
wxPoint2DDouble& operator/=(wxDouble n) ;
|
||||
wxPoint2DDouble& operator/=(wxInt32 n) ;
|
||||
|
||||
bool operator==(const wxPoint2DDouble& pt) const ;
|
||||
bool operator!=(const wxPoint2DDouble& pt) const ;
|
||||
|
||||
wxDouble m_x ;
|
||||
wxDouble m_y ;
|
||||
} ;
|
||||
|
||||
wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
|
||||
wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
|
||||
wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
|
||||
wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt) ;
|
||||
wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt) ;
|
||||
wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n) ;
|
||||
wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n) ;
|
||||
wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
|
||||
wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n) ;
|
||||
wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n) ;
|
||||
|
||||
inline wxPoint2DDouble::wxPoint2DDouble()
|
||||
{
|
||||
m_x = 0.0 ;
|
||||
m_y = 0.0 ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y )
|
||||
{
|
||||
m_x = x ;
|
||||
m_y = y ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt )
|
||||
{
|
||||
m_x = pt.m_x ;
|
||||
m_y = pt.m_y ;
|
||||
}
|
||||
|
||||
inline void wxPoint2DDouble::GetFloor( wxInt32 *x , wxInt32 *y )
|
||||
{
|
||||
*x = (wxInt32) floor( m_x ) ;
|
||||
*y = (wxInt32) floor( m_y ) ;
|
||||
}
|
||||
|
||||
inline void wxPoint2DDouble::GetRounded( wxInt32 *x , wxInt32 *y )
|
||||
{
|
||||
*x = (wxInt32) floor( m_x + 0.5 ) ;
|
||||
*y = (wxInt32) floor( m_y + 0.5) ;
|
||||
}
|
||||
|
||||
inline wxDouble wxPoint2DDouble::GetVectorLength() ;
|
||||
inline void wxPoint2DDouble::SetVectorLength( wxDouble length ) ;
|
||||
inline wxDouble wxPoint2DDouble::GetVectorAngle() ;
|
||||
inline void wxPoint2DDouble::SetVectorAngle( wxDouble degrees ) ;
|
||||
inline void wxPoint2DDouble::SetPolarCoordinates( wxDouble angle , wxDouble length ) ;
|
||||
inline void wxPoint2DDouble::Normalize() ;
|
||||
|
||||
inline wxDouble wxPoint2DDouble::GetDistance( const wxPoint2DDouble &pt )
|
||||
{
|
||||
return sqrt( GetDistanceSquare( pt ) );
|
||||
}
|
||||
|
||||
inline wxDouble wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble &pt )
|
||||
{
|
||||
return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ;
|
||||
}
|
||||
|
||||
inline wxDouble wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble &vec )
|
||||
{
|
||||
return ( m_x * vec.m_x + m_y * vec.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxDouble wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble &vec )
|
||||
{
|
||||
return ( m_x * vec.m_y - vec.m_x * m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble wxPoint2DDouble::operator-()
|
||||
{
|
||||
return wxPoint2DDouble( -m_x, -m_y);
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble& wxPoint2DDouble::operator=(const wxPoint2DDouble& pt)
|
||||
{
|
||||
m_x = pt.m_x ;
|
||||
m_y = pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt)
|
||||
{
|
||||
m_x = m_x + pt.m_x ;
|
||||
m_y = m_y + pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble& wxPoint2DDouble::operator-=(const wxPoint2DDouble& pt)
|
||||
{
|
||||
m_x = m_x - pt.m_x ;
|
||||
m_y = m_y - pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble& wxPoint2DDouble::operator*=(const wxPoint2DDouble& pt)
|
||||
{
|
||||
m_x = m_x + pt.m_x ;
|
||||
m_y = m_y + pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt)
|
||||
{
|
||||
m_x = m_x - pt.m_x ;
|
||||
m_y = m_y - pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const
|
||||
{
|
||||
return m_x == pt.m_x && m_y == pt.m_y;
|
||||
}
|
||||
|
||||
inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const
|
||||
{
|
||||
return m_x != pt.m_x || m_y != pt.m_y;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
|
||||
{
|
||||
return wxPoint2DDouble( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
|
||||
{
|
||||
return wxPoint2DDouble( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ;
|
||||
}
|
||||
|
||||
|
||||
inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
|
||||
{
|
||||
return wxPoint2DDouble( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt)
|
||||
{
|
||||
return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt)
|
||||
{
|
||||
return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n)
|
||||
{
|
||||
return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n)
|
||||
{
|
||||
return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
|
||||
{
|
||||
return wxPoint2DDouble( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n)
|
||||
{
|
||||
return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n)
|
||||
{
|
||||
return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ;
|
||||
}
|
||||
|
||||
// wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the
|
||||
// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
|
||||
// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
|
||||
|
||||
class WXDLLEXPORT wxRect2DDouble
|
||||
{
|
||||
public:
|
||||
wxRect2DDouble() { m_x = m_y = m_width = m_height = 0 ; }
|
||||
wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h) { m_x = x ; m_y = y ; m_width = w ; m_height = h ; }
|
||||
wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
|
||||
wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
|
||||
wxRect2DDouble(const wxRect2DDouble& rect);
|
||||
|
||||
// single attribute accessors
|
||||
|
||||
inline wxPoint2DDouble GetPosition() { return wxPoint2DDouble(m_x, m_y); }
|
||||
inline wxSize GetSize() { return wxSize(m_width, m_height); }
|
||||
|
||||
// for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
|
||||
// position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
|
||||
|
||||
inline wxDouble GetLeft() const { return m_x; }
|
||||
inline void SetLeft( wxDouble n ) { m_width += m_x - n ; m_x = n ; }
|
||||
inline void MoveLeftTo( wxDouble n ) { m_x = n ; }
|
||||
inline wxDouble GetTop() const { return m_y; }
|
||||
inline void SetTop( wxDouble n ) { m_height += m_y - n ; m_y = n ; }
|
||||
inline void MoveTopTo( wxDouble n ) { m_y = n ; }
|
||||
inline wxDouble GetBottom() const { return m_y + m_height; }
|
||||
inline void SetBottom( wxDouble n ) { m_height += n - (m_y+m_height) ;}
|
||||
inline void MoveBottomTo( wxDouble n ) { m_y = n - m_height ; }
|
||||
inline wxDouble GetRight() const { return m_x + m_width; }
|
||||
inline void SetRight( wxDouble n ) { m_width += n - (m_x+m_width) ; }
|
||||
inline void MoveRightTo( wxDouble n ) { m_x = n - m_width ; }
|
||||
|
||||
inline wxPoint2DDouble GetLeftTop() const { return wxPoint2DDouble( m_x , m_y ) ; }
|
||||
inline void SetLeftTop( const wxPoint2DDouble &pt ) { m_width += m_x - pt.m_x ; m_height += m_y - pt.m_y ; m_x = pt.m_x ; m_y = pt.m_y ; }
|
||||
inline void MoveLeftTopTo( const wxPoint2DDouble &pt ) { m_x = pt.m_x ; m_y = pt.m_y ; }
|
||||
inline wxPoint2DDouble GetLeftBottom() const { return wxPoint2DDouble( m_x , m_y + m_height ) ; }
|
||||
inline void SetLeftBottom( const wxPoint2DDouble &pt ) { m_width += m_x - pt.m_x ; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x ; }
|
||||
inline void MoveLeftBottomTo( const wxPoint2DDouble &pt ) { m_x = pt.m_x ; m_y = pt.m_y - m_height; }
|
||||
inline wxPoint2DDouble GetRightTop() const { return wxPoint2DDouble( m_x+m_width , m_y ) ; }
|
||||
inline void SetRightTop( const wxPoint2DDouble &pt ) { m_width += pt.m_x - ( m_x + m_width ) ; m_height += m_y - pt.m_y ; m_y = pt.m_y ; }
|
||||
inline void MoveRightTopTo( const wxPoint2DDouble &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y ; }
|
||||
inline wxPoint2DDouble GetRightBottom() const { return wxPoint2DDouble( m_x+m_width , m_y + m_height ) ; }
|
||||
inline void SetRightBottom( const wxPoint2DDouble &pt ) { m_width += pt.m_x - ( m_x + m_width ) ; m_height += pt.m_y - (m_y+m_height) ;}
|
||||
inline void MoveRightBottomTo( const wxPoint2DDouble &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y - m_height; }
|
||||
inline wxPoint2DDouble GetCentre() const { return wxPoint2DDouble( m_x+m_width/2 , m_y+m_height/2 ) ; }
|
||||
inline void SetCentre( const wxPoint2DDouble &pt ) { MoveCentreTo( pt ) ; } // since this is impossible without moving...
|
||||
inline void MoveCentreTo( const wxPoint2DDouble &pt ) { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2) ; }
|
||||
inline wxOutCode GetOutcode( const wxPoint2DDouble &pt ) const
|
||||
{ return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
|
||||
( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) +
|
||||
( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
|
||||
( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )) ; }
|
||||
inline bool Contains( const wxPoint2DDouble &pt ) const
|
||||
{ return GetOutcode( pt ) == wxInside ; }
|
||||
inline bool Contains( const wxRect2DDouble &rect ) const
|
||||
{ return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
|
||||
( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ) ; }
|
||||
inline bool IsEmpty() const
|
||||
{ return ( m_width <= 0 || m_height <= 0 ) ; }
|
||||
inline bool HaveEqualSize( const wxRect2DDouble &rect ) const
|
||||
{ return ( rect.m_width == m_width && rect.m_height == m_height ) ; }
|
||||
|
||||
inline void Inset( wxDouble x , wxDouble y ) { m_x += x ; m_y += y ; m_width -= 2 * x ; m_height -= 2 * y ; }
|
||||
inline void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom )
|
||||
{ m_x += left ; m_y += top ; m_width -= left + right ; m_height -= top + bottom ;}
|
||||
inline void Offset( const wxPoint2DDouble &pt ) { m_x += pt.m_x ; m_y += pt.m_y ; }
|
||||
void ConstrainTo( const wxRect2DDouble &rect ) ;
|
||||
inline wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ) { return wxPoint2DDouble( m_x + m_width * widthfactor , m_y + m_height * heightfactor ) ; }
|
||||
|
||||
static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ) ;
|
||||
inline void Intersect( const wxRect2DDouble &otherRect ) { Intersect( *this , otherRect , this ) ; }
|
||||
inline wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const { wxRect2DDouble result ; Intersect( *this , otherRect , &result) ; return result ; }
|
||||
bool Intersects( const wxRect2DDouble &rect ) const ;
|
||||
|
||||
static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ) ;
|
||||
void Union( const wxRect2DDouble &otherRect ) { Union( *this , otherRect , this ) ; }
|
||||
void Union( const wxPoint2DDouble &pt ) ;
|
||||
inline wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const { wxRect2DDouble result ; Union( *this , otherRect , &result) ; return result ; }
|
||||
|
||||
inline void Scale( wxDouble f ) { m_x *= f ; m_y *= f ; m_width *= f ; m_height *= f ;}
|
||||
inline void Scale( wxInt32 num , wxInt32 denum )
|
||||
{ m_x *= ((wxDouble)num)/((wxDouble)denum) ; m_y *= ((wxDouble)num)/((wxDouble)denum) ;
|
||||
m_width *= ((wxDouble)num)/((wxDouble)denum) ; m_height *= ((wxDouble)num)/((wxDouble)denum) ;}
|
||||
|
||||
wxRect2DDouble& operator = (const wxRect2DDouble& rect);
|
||||
bool operator == (const wxRect2DDouble& rect);
|
||||
bool operator != (const wxRect2DDouble& rect);
|
||||
|
||||
wxDouble m_x ;
|
||||
wxDouble m_y ;
|
||||
wxDouble m_width;
|
||||
wxDouble m_height;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxPoint2DInt
|
||||
{
|
||||
public :
|
||||
wxPoint2DInt();
|
||||
wxPoint2DInt( wxInt32 x , wxInt32 y ) ;
|
||||
wxPoint2DInt( const wxPoint2DInt &pt ) ;
|
||||
wxPoint2DInt( const wxPoint &pt ) ;
|
||||
|
||||
// two different conversions to integers, floor and rounding
|
||||
void GetFloor( wxInt32 *x , wxInt32 *y ) ;
|
||||
void GetRounded( wxInt32 *x , wxInt32 *y ) ;
|
||||
|
||||
wxDouble GetVectorLength() ;
|
||||
wxDouble GetVectorAngle() ;
|
||||
void SetVectorLength( wxDouble length ) ;
|
||||
void SetVectorAngle( wxDouble degrees ) ;
|
||||
void SetPolarCoordinates( wxInt32 angle , wxInt32 length ) ;
|
||||
// set the vector length to 1.0, preserving the angle
|
||||
void Normalize() ;
|
||||
|
||||
wxDouble GetDistance( const wxPoint2DInt &pt ) const ;
|
||||
wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const;
|
||||
wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const;
|
||||
wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const;
|
||||
|
||||
// the reflection of this point
|
||||
wxPoint2DInt operator-() ;
|
||||
|
||||
wxPoint2DInt& operator=(const wxPoint2DInt& pt) ;
|
||||
wxPoint2DInt& operator+=(const wxPoint2DInt& pt) ;
|
||||
wxPoint2DInt& operator-=(const wxPoint2DInt& pt) ;
|
||||
wxPoint2DInt& operator*=(const wxPoint2DInt& pt) ;
|
||||
wxPoint2DInt& operator*=(wxDouble n) ;
|
||||
wxPoint2DInt& operator*=(wxInt32 n) ;
|
||||
wxPoint2DInt& operator/=(const wxPoint2DInt& pt) ;
|
||||
wxPoint2DInt& operator/=(wxDouble n) ;
|
||||
wxPoint2DInt& operator/=(wxInt32 n) ;
|
||||
operator wxPoint() const ;
|
||||
bool operator==(const wxPoint2DInt& pt) const ;
|
||||
bool operator!=(const wxPoint2DInt& pt) const ;
|
||||
|
||||
void WriteTo( wxDataOutputStream &stream ) const ;
|
||||
void ReadFrom( wxDataInputStream &stream ) ;
|
||||
|
||||
wxInt32 m_x ;
|
||||
wxInt32 m_y ;
|
||||
} ;
|
||||
|
||||
wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
|
||||
wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
|
||||
wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
|
||||
wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt) ;
|
||||
wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt) ;
|
||||
wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n) ;
|
||||
wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n) ;
|
||||
wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
|
||||
wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n) ;
|
||||
wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n) ;
|
||||
|
||||
inline wxPoint2DInt::wxPoint2DInt()
|
||||
{
|
||||
m_x = 0.0 ;
|
||||
m_y = 0.0 ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
|
||||
{
|
||||
m_x = x ;
|
||||
m_y = y ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
|
||||
{
|
||||
m_x = pt.m_x ;
|
||||
m_y = pt.m_y ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt )
|
||||
{
|
||||
m_x = pt.x ;
|
||||
m_y = pt.y ;
|
||||
}
|
||||
|
||||
inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y )
|
||||
{
|
||||
*x = (wxInt32) floor( m_x ) ;
|
||||
*y = (wxInt32) floor( m_y ) ;
|
||||
}
|
||||
|
||||
inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y )
|
||||
{
|
||||
*x = (wxInt32) floor( m_x + 0.5 ) ;
|
||||
*y = (wxInt32) floor( m_y + 0.5) ;
|
||||
}
|
||||
|
||||
inline wxDouble wxPoint2DInt::GetVectorLength()
|
||||
{
|
||||
return sqrt( (m_x)*(m_x) + (m_y)*(m_y) ) ;
|
||||
}
|
||||
|
||||
inline void wxPoint2DInt::SetVectorLength( wxDouble length )
|
||||
{
|
||||
wxDouble before = GetVectorLength() ;
|
||||
m_x *= length / before ;
|
||||
m_y *= length / before ;
|
||||
}
|
||||
|
||||
inline void wxPoint2DInt::SetPolarCoordinates( wxInt32 angle , wxInt32 length ) ;
|
||||
inline void wxPoint2DInt::Normalize()
|
||||
{
|
||||
SetVectorLength( 1 ) ;
|
||||
}
|
||||
|
||||
inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const
|
||||
{
|
||||
return sqrt( GetDistanceSquare( pt ) );
|
||||
}
|
||||
|
||||
inline wxDouble wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt &pt ) const
|
||||
{
|
||||
return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ;
|
||||
}
|
||||
|
||||
inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const
|
||||
{
|
||||
return ( m_x * vec.m_x + m_y * vec.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const
|
||||
{
|
||||
return ( m_x * vec.m_y - vec.m_x * m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt::operator wxPoint() const
|
||||
{
|
||||
return wxPoint( m_x, m_y);
|
||||
}
|
||||
|
||||
inline wxPoint2DInt wxPoint2DInt::operator-()
|
||||
{
|
||||
return wxPoint2DInt( -m_x, -m_y);
|
||||
}
|
||||
|
||||
inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt)
|
||||
{
|
||||
m_x = pt.m_x ;
|
||||
m_y = pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt)
|
||||
{
|
||||
m_x = m_x + pt.m_x ;
|
||||
m_y = m_y + pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt)
|
||||
{
|
||||
m_x = m_x - pt.m_x ;
|
||||
m_y = m_y - pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
|
||||
{
|
||||
m_x = m_x + pt.m_x ;
|
||||
m_y = m_y + pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
|
||||
{
|
||||
m_x = m_x - pt.m_x ;
|
||||
m_y = m_y - pt.m_y;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const
|
||||
{
|
||||
return m_x == pt.m_x && m_y == pt.m_y;
|
||||
}
|
||||
|
||||
inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const
|
||||
{
|
||||
return m_x != pt.m_x || m_y != pt.m_y;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
|
||||
{
|
||||
return wxPoint2DInt( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
|
||||
{
|
||||
return wxPoint2DInt( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ;
|
||||
}
|
||||
|
||||
|
||||
inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
|
||||
{
|
||||
return wxPoint2DInt( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
|
||||
{
|
||||
return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
|
||||
{
|
||||
return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n)
|
||||
{
|
||||
return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n)
|
||||
{
|
||||
return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
|
||||
{
|
||||
return wxPoint2DInt( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n)
|
||||
{
|
||||
return wxPoint2DInt( pt.m_x / n , pt.m_y / n ) ;
|
||||
}
|
||||
|
||||
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n)
|
||||
{
|
||||
return wxPoint2DInt( pt.m_x / n , pt.m_y / n ) ;
|
||||
}
|
||||
|
||||
// wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the
|
||||
// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
|
||||
// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
|
||||
|
||||
class WXDLLEXPORT wxRect2DInt
|
||||
{
|
||||
public:
|
||||
wxRect2DInt() { m_x = m_y = m_width = m_height = 0 ; }
|
||||
wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h) { m_x = x ; m_y = y ; m_width = w ; m_height = h ; }
|
||||
wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight);
|
||||
wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size);
|
||||
wxRect2DInt(const wxRect2DInt& rect);
|
||||
|
||||
// single attribute accessors
|
||||
|
||||
inline wxPoint2DInt GetPosition() { return wxPoint2DInt(m_x, m_y); }
|
||||
inline wxSize GetSize() { return wxSize(m_width, m_height); }
|
||||
|
||||
// for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
|
||||
// position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
|
||||
|
||||
inline wxInt32 GetLeft() const { return m_x; }
|
||||
inline void SetLeft( wxInt32 n ) { m_width += m_x - n ; m_x = n ; }
|
||||
inline void MoveLeftTo( wxInt32 n ) { m_x = n ; }
|
||||
inline wxInt32 GetTop() const { return m_y; }
|
||||
inline void SetTop( wxInt32 n ) { m_height += m_y - n ; m_y = n ; }
|
||||
inline void MoveTopTo( wxInt32 n ) { m_y = n ; }
|
||||
inline wxInt32 GetBottom() const { return m_y + m_height; }
|
||||
inline void SetBottom( wxInt32 n ) { m_height += n - (m_y+m_height) ;}
|
||||
inline void MoveBottomTo( wxInt32 n ) { m_y = n - m_height ; }
|
||||
inline wxInt32 GetRight() const { return m_x + m_width; }
|
||||
inline void SetRight( wxInt32 n ) { m_width += n - (m_x+m_width) ; }
|
||||
inline void MoveRightTo( wxInt32 n ) { m_x = n - m_width ; }
|
||||
|
||||
inline wxPoint2DInt GetLeftTop() const { return wxPoint2DInt( m_x , m_y ) ; }
|
||||
inline void SetLeftTop( const wxPoint2DInt &pt ) { m_width += m_x - pt.m_x ; m_height += m_y - pt.m_y ; m_x = pt.m_x ; m_y = pt.m_y ; }
|
||||
inline void MoveLeftTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x ; m_y = pt.m_y ; }
|
||||
inline wxPoint2DInt GetLeftBottom() const { return wxPoint2DInt( m_x , m_y + m_height ) ; }
|
||||
inline void SetLeftBottom( const wxPoint2DInt &pt ) { m_width += m_x - pt.m_x ; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x ; }
|
||||
inline void MoveLeftBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x ; m_y = pt.m_y - m_height; }
|
||||
inline wxPoint2DInt GetRightTop() const { return wxPoint2DInt( m_x+m_width , m_y ) ; }
|
||||
inline void SetRightTop( const wxPoint2DInt &pt ) { m_width += pt.m_x - ( m_x + m_width ) ; m_height += m_y - pt.m_y ; m_y = pt.m_y ; }
|
||||
inline void MoveRightTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y ; }
|
||||
inline wxPoint2DInt GetRightBottom() const { return wxPoint2DInt( m_x+m_width , m_y + m_height ) ; }
|
||||
inline void SetRightBottom( const wxPoint2DInt &pt ) { m_width += pt.m_x - ( m_x + m_width ) ; m_height += pt.m_y - (m_y+m_height) ;}
|
||||
inline void MoveRightBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y - m_height; }
|
||||
inline wxPoint2DInt GetCentre() const { return wxPoint2DInt( m_x+m_width/2 , m_y+m_height/2 ) ; }
|
||||
inline void SetCentre( const wxPoint2DInt &pt ) { MoveCentreTo( pt ) ; } // since this is impossible without moving...
|
||||
inline void MoveCentreTo( const wxPoint2DInt &pt ) { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2) ; }
|
||||
inline wxOutCode GetOutcode( const wxPoint2DInt &pt ) const
|
||||
{ return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
|
||||
( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) +
|
||||
( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
|
||||
( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )) ; }
|
||||
inline bool Contains( const wxPoint2DInt &pt ) const
|
||||
{ return GetOutcode( pt ) == wxInside ; }
|
||||
inline bool Contains( const wxRect2DInt &rect ) const
|
||||
{ return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
|
||||
( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ) ; }
|
||||
inline bool IsEmpty() const
|
||||
{ return ( m_width <= 0 || m_height <= 0 ) ; }
|
||||
inline bool HaveEqualSize( const wxRect2DInt &rect ) const
|
||||
{ return ( rect.m_width == m_width && rect.m_height == m_height ) ; }
|
||||
|
||||
inline void Inset( wxInt32 x , wxInt32 y ) { m_x += x ; m_y += y ; m_width -= 2 * x ; m_height -= 2 * y ; }
|
||||
inline void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom )
|
||||
{ m_x += left ; m_y += top ; m_width -= left + right ; m_height -= top + bottom ;}
|
||||
inline void Offset( const wxPoint2DInt &pt ) { m_x += pt.m_x ; m_y += pt.m_y ; }
|
||||
void ConstrainTo( const wxRect2DInt &rect ) ;
|
||||
inline wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ) { return wxPoint2DInt( m_x + m_width * widthfactor , m_y + m_height * heightfactor ) ; }
|
||||
|
||||
static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ) ;
|
||||
inline void Intersect( const wxRect2DInt &otherRect ) { Intersect( *this , otherRect , this ) ; }
|
||||
inline wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const { wxRect2DInt result ; Intersect( *this , otherRect , &result) ; return result ; }
|
||||
bool Intersects( const wxRect2DInt &rect ) const ;
|
||||
|
||||
static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ) ;
|
||||
void Union( const wxRect2DInt &otherRect ) { Union( *this , otherRect , this ) ; }
|
||||
void Union( const wxPoint2DInt &pt ) ;
|
||||
inline wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const { wxRect2DInt result ; Union( *this , otherRect , &result) ; return result ; }
|
||||
|
||||
inline void Scale( wxInt32 f ) { m_x *= f ; m_y *= f ; m_width *= f ; m_height *= f ;}
|
||||
inline void Scale( wxInt32 num , wxInt32 denum )
|
||||
{ m_x *= ((wxInt32)num)/((wxInt32)denum) ; m_y *= ((wxInt32)num)/((wxInt32)denum) ;
|
||||
m_width *= ((wxInt32)num)/((wxInt32)denum) ; m_height *= ((wxInt32)num)/((wxInt32)denum) ;}
|
||||
|
||||
wxRect2DInt& operator = (const wxRect2DInt& rect);
|
||||
bool operator == (const wxRect2DInt& rect);
|
||||
bool operator != (const wxRect2DInt& rect);
|
||||
|
||||
void WriteTo( wxDataOutputStream &stream ) const ;
|
||||
void ReadFrom( wxDataInputStream &stream ) ;
|
||||
|
||||
wxInt32 m_x ;
|
||||
wxInt32 m_y ;
|
||||
wxInt32 m_width;
|
||||
wxInt32 m_height;
|
||||
};
|
||||
|
||||
inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r )
|
||||
{
|
||||
m_x = r.m_x ;
|
||||
m_y = r.m_y ;
|
||||
m_width = r.m_width ;
|
||||
m_height = r.m_height ;
|
||||
}
|
||||
|
||||
inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b)
|
||||
{
|
||||
m_x = wxMin( a.m_x , b.m_x ) ;
|
||||
m_y = wxMin( a.m_y , b.m_y ) ;
|
||||
m_width = abs( a.m_x - b.m_x ) ;
|
||||
m_height = abs( a.m_y - b.m_y ) ;
|
||||
}
|
||||
|
||||
class wxTransform2D
|
||||
{
|
||||
public :
|
||||
virtual void Transform( wxPoint2DInt* pt )const = 0 ;
|
||||
virtual void Transform( wxRect2DInt* r ) const ;
|
||||
virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const ;
|
||||
virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ;
|
||||
|
||||
virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
|
||||
virtual void InverseTransform( wxRect2DInt* r ) const ;
|
||||
virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
|
||||
virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
|
||||
} ;
|
||||
|
||||
inline void wxTransform2D::Transform( wxRect2DInt* r ) const
|
||||
{ wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; Transform( &a ) ; Transform( &b ) ; *r = wxRect2DInt( a , b ) ; }
|
||||
|
||||
inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const
|
||||
{ wxPoint2DInt res = pt ; Transform( &res ) ; return res ; }
|
||||
|
||||
inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const
|
||||
{ wxRect2DInt res = r ; Transform( &res ) ; return res ; }
|
||||
|
||||
inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const
|
||||
{ wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; InverseTransform( &a ) ; InverseTransform( &b ) ; *r = wxRect2DInt( a , b ) ; }
|
||||
|
||||
inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const
|
||||
{ wxPoint2DInt res = pt ; InverseTransform( &res ) ; return res ; }
|
||||
|
||||
inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const
|
||||
{ wxRect2DInt res = r ; InverseTransform( &res ) ; return res ; }
|
||||
|
||||
#endif
|
6
src/mac/apprsrc.h
Normal file
6
src/mac/apprsrc.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#define kMacSTRWrongMachine 1
|
||||
#define kMacSTRSmallSize 2
|
||||
#define kMacSTRNoMemory 3
|
||||
#define kMacSTROldSystem 4
|
||||
#define kMacSTRGenericAbout 5
|
||||
#define kMacSTRNoPre8Yet 6
|
6
src/mac/carbon/apprsrc.h
Normal file
6
src/mac/carbon/apprsrc.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#define kMacSTRWrongMachine 1
|
||||
#define kMacSTRSmallSize 2
|
||||
#define kMacSTRNoMemory 3
|
||||
#define kMacSTROldSystem 4
|
||||
#define kMacSTRGenericAbout 5
|
||||
#define kMacSTRNoPre8Yet 6
|
340
src/mac/carbon/dataobj.cpp
Normal file
340
src/mac/carbon/dataobj.cpp
Normal file
@@ -0,0 +1,340 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: os2/dataobj.cpp
|
||||
// Purpose: implementation of wx[I]DataObject class
|
||||
// Author: David Webster
|
||||
// Modified by:
|
||||
// Created: 10/21/99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1999 David Webster
|
||||
// Licence: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "dataobj.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#endif
|
||||
#include "wx/defs.h"
|
||||
|
||||
#include "wx/log.h"
|
||||
#include "wx/dataobj.h"
|
||||
#include "wx/mstream.h"
|
||||
#include "wx/image.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataFormat
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDataFormat::wxDataFormat()
|
||||
{
|
||||
m_vType = wxDF_INVALID;
|
||||
m_vFormat = 0;
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
wxDataFormatId vType
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetType(vType);
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
const wxChar* zId
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetId(zId);
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
const wxString& rId
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetId(rId);
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
NativeFormat vFormat
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetId(vFormat);
|
||||
}
|
||||
|
||||
void wxDataFormat::SetType(
|
||||
wxDataFormatId vType
|
||||
)
|
||||
{
|
||||
m_vType = vType;
|
||||
|
||||
if (m_vType == wxDF_TEXT)
|
||||
m_vFormat = 0;
|
||||
else
|
||||
if (m_vType == wxDF_BITMAP)
|
||||
m_vFormat = 0;
|
||||
else
|
||||
if (m_vType == wxDF_FILENAME)
|
||||
m_vFormat = 0;
|
||||
else
|
||||
{
|
||||
wxFAIL_MSG( wxT("invalid dataformat") );
|
||||
}
|
||||
}
|
||||
|
||||
wxDataFormatId wxDataFormat::GetType() const
|
||||
{
|
||||
return m_vType;
|
||||
}
|
||||
|
||||
wxString wxDataFormat::GetId() const
|
||||
{
|
||||
wxString sRet(""); // TODO: gdk_atom_name( m_format ) );
|
||||
return sRet;
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId(
|
||||
NativeFormat vFormat
|
||||
)
|
||||
{
|
||||
m_vFormat = vFormat;
|
||||
// TODO:
|
||||
/*
|
||||
if (m_format == g_textAtom)
|
||||
m_type = wxDF_TEXT;
|
||||
else
|
||||
if (m_format == g_pngAtom)
|
||||
m_type = wxDF_BITMAP;
|
||||
else
|
||||
if (m_format == g_fileAtom)
|
||||
m_type = wxDF_FILENAME;
|
||||
else
|
||||
m_type = wxDF_PRIVATE;
|
||||
*/
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId(
|
||||
const wxChar* zId
|
||||
)
|
||||
{
|
||||
wxString tmp(zId);
|
||||
|
||||
m_vType = wxDF_PRIVATE;
|
||||
m_vFormat = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
|
||||
}
|
||||
|
||||
void wxDataFormat::PrepareFormats()
|
||||
{
|
||||
// TODO:
|
||||
/*
|
||||
if (!g_textAtom)
|
||||
g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
||||
if (!g_pngAtom)
|
||||
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
|
||||
if (!g_fileAtom)
|
||||
g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
|
||||
*/
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// wxDataObject
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
wxDataObject::wxDataObject()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxDataObject::IsSupportedFormat(
|
||||
const wxDataFormat& rFormat
|
||||
, Direction vDir
|
||||
) const
|
||||
{
|
||||
size_t nFormatCount = GetFormatCount(vDir);
|
||||
|
||||
if (nFormatCount == 1)
|
||||
{
|
||||
return rFormat == GetPreferredFormat();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDataFormat* pFormats = new wxDataFormat[nFormatCount];
|
||||
GetAllFormats( pFormats
|
||||
,vDir
|
||||
);
|
||||
|
||||
size_t n;
|
||||
|
||||
for (n = 0; n < nFormatCount; n++)
|
||||
{
|
||||
if (pFormats[n] == rFormat)
|
||||
break;
|
||||
}
|
||||
|
||||
delete [] pFormats;
|
||||
|
||||
// found?
|
||||
return n < nFormatCount;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFileDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
{
|
||||
wxString sFilenames;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
{
|
||||
sFilenames += m_filenames[i];
|
||||
sFilenames += (wxChar)0;
|
||||
}
|
||||
|
||||
memcpy(pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
size_t wxFileDataObject::GetDataSize() const
|
||||
{
|
||||
size_t nRes = 0;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
{
|
||||
nRes += m_filenames[i].Len();
|
||||
nRes += 1;
|
||||
}
|
||||
|
||||
return nRes + 1;
|
||||
}
|
||||
|
||||
bool wxFileDataObject::SetData(
|
||||
size_t WXUNUSED(nSize)
|
||||
, const void* pBuf
|
||||
)
|
||||
{
|
||||
/* TODO */
|
||||
|
||||
wxString sFile( (const char *)pBuf); /* char, not wxChar */
|
||||
|
||||
AddFile(sFile);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxFileDataObject::AddFile(
|
||||
const wxString& rFilename
|
||||
)
|
||||
{
|
||||
m_filenames.Add(rFilename);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
: wxBitmapDataObjectBase(rBitmap)
|
||||
{
|
||||
Init();
|
||||
|
||||
DoConvertToPng();
|
||||
}
|
||||
|
||||
wxBitmapDataObject::~wxBitmapDataObject()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::SetBitmap(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
{
|
||||
ClearAll();
|
||||
wxBitmapDataObjectBase::SetBitmap(rBitmap);
|
||||
DoConvertToPng();
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
{
|
||||
if (!m_pngSize)
|
||||
{
|
||||
wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
|
||||
return FALSE;
|
||||
}
|
||||
memcpy(pBuf, m_pngData, m_pngSize);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::SetData(
|
||||
size_t nSize
|
||||
, const void* pBuf
|
||||
)
|
||||
{
|
||||
Clear();
|
||||
m_pngSize = nSize;
|
||||
m_pngData = malloc(m_pngSize);
|
||||
|
||||
memcpy(m_pngData, pBuf, m_pngSize);
|
||||
|
||||
wxMemoryInputStream vMstream((char*)m_pngData, m_pngSize);
|
||||
wxImage vImage;
|
||||
wxPNGHandler vHandler;
|
||||
|
||||
if (!vHandler.LoadFile(&vImage, vMstream))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_bitmap = vImage.ConvertToBitmap();
|
||||
return m_bitmap.Ok();
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::DoConvertToPng()
|
||||
{
|
||||
if (!m_bitmap.Ok())
|
||||
return;
|
||||
|
||||
wxImage vImage(m_bitmap);
|
||||
wxPNGHandler vHandler;
|
||||
wxCountingOutputStream vCount;
|
||||
|
||||
vHandler.SaveFile(&vImage, vCount);
|
||||
|
||||
m_pngSize = vCount.GetSize() + 100; // sometimes the size seems to vary ???
|
||||
m_pngData = malloc(m_pngSize);
|
||||
|
||||
wxMemoryOutputStream vMstream((char*) m_pngData, m_pngSize);
|
||||
|
||||
vHandler.SaveFile(&vImage, vMstream );
|
||||
}
|
||||
|
156
src/mac/carbon/dcprint.cpp
Normal file
156
src/mac/carbon/dcprint.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: dcprint.cpp
|
||||
// Purpose: wxPrinterDC class
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 01/02/97
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "dcprint.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/dcprint.h"
|
||||
#include "math.h"
|
||||
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_CLASS(wxPrinterDC, wxDC)
|
||||
#endif
|
||||
|
||||
GrafPtr macPrintFormerPort = NULL ;
|
||||
|
||||
wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
|
||||
{
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
m_printData = printdata ;
|
||||
m_printData.ConvertToNative() ;
|
||||
|
||||
::PrOpen() ;
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
PrClose() ;
|
||||
}
|
||||
|
||||
if ( ::PrValidate( m_printData.m_macPrintInfo ) )
|
||||
{
|
||||
// the driver has changed in the mean time, should we pop up a page setup dialog ?
|
||||
}
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
PrClose() ;
|
||||
}
|
||||
::GetPort( &macPrintFormerPort ) ;
|
||||
m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
|
||||
// sets current port
|
||||
m_macPort = (GrafPtr ) m_macPrintPort ;
|
||||
m_ok = TRUE ;
|
||||
m_minY = m_minX = 0 ;
|
||||
m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ;
|
||||
m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ;
|
||||
}
|
||||
|
||||
wxPrinterDC::~wxPrinterDC(void)
|
||||
{
|
||||
if ( m_ok )
|
||||
{
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
::PrCloseDoc( m_macPrintPort ) ;
|
||||
err = PrError() ;
|
||||
|
||||
if ( !err )
|
||||
{
|
||||
if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
|
||||
{
|
||||
TPrStatus status ;
|
||||
::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
PrClose() ;
|
||||
}
|
||||
::PrClose() ;
|
||||
::SetPort( macPrintFormerPort ) ;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
|
||||
{
|
||||
return m_ok ;
|
||||
}
|
||||
|
||||
void wxPrinterDC::EndDoc(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxPrinterDC::StartPage(void)
|
||||
{
|
||||
if ( !m_ok )
|
||||
return ;
|
||||
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
PrOpenPage( m_macPrintPort , NULL ) ;
|
||||
SetOrigin( - (**m_printData.m_macPrintInfo).rPaper.left , - (**m_printData.m_macPrintInfo).rPaper.top ) ;
|
||||
Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
|
||||
::ClipRect( &clip ) ;
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
::PrClosePage( m_macPrintPort) ;
|
||||
::PrCloseDoc( m_macPrintPort ) ;
|
||||
::PrClose() ;
|
||||
::SetPort( macPrintFormerPort ) ;
|
||||
m_ok = FALSE ;
|
||||
}
|
||||
}
|
||||
|
||||
void wxPrinterDC::EndPage(void)
|
||||
{
|
||||
if ( !m_ok )
|
||||
return ;
|
||||
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
PrClosePage( (TPrPort*) m_macPort ) ;
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
::PrCloseDoc( m_macPrintPort ) ;
|
||||
::PrClose() ;
|
||||
::SetPort( macPrintFormerPort ) ;
|
||||
m_ok = FALSE ;
|
||||
}
|
||||
}
|
159
src/mac/carbon/fontutil.cpp
Normal file
159
src/mac/carbon/fontutil.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: msw/fontutil.cpp
|
||||
// Purpose: font-related helper functions for wxMSW
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 05.11.99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "fontutil.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/fontutil.h"
|
||||
#include "wx/fontmap.h"
|
||||
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNativeEncodingInfo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// convert to/from the string representation: format is
|
||||
// facename[;charset]
|
||||
|
||||
bool wxNativeEncodingInfo::FromString(const wxString& s)
|
||||
{
|
||||
wxStringTokenizer tokenizer(s, _T(";"));
|
||||
|
||||
facename = tokenizer.GetNextToken();
|
||||
if ( !facename )
|
||||
return FALSE;
|
||||
|
||||
wxString tmp = tokenizer.GetNextToken();
|
||||
if ( !tmp )
|
||||
{
|
||||
// default charset (don't use DEFAULT_CHARSET though because of subtle
|
||||
// Windows 9x/NT differences in handling it)
|
||||
charset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( wxSscanf(tmp, _T("%u"), &charset) != 1 )
|
||||
{
|
||||
// should be a number!
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxString wxNativeEncodingInfo::ToString() const
|
||||
{
|
||||
wxString s(facename);
|
||||
if ( charset != 0 )
|
||||
{
|
||||
s << _T(';') << charset;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxGetNativeFontEncoding(wxFontEncoding encoding,
|
||||
wxNativeEncodingInfo *info)
|
||||
{
|
||||
wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
|
||||
|
||||
if ( encoding == wxFONTENCODING_DEFAULT )
|
||||
{
|
||||
encoding = wxFont::GetDefaultEncoding();
|
||||
}
|
||||
|
||||
switch ( encoding )
|
||||
{
|
||||
// although this function is supposed to return an exact match, do do
|
||||
// some mappings here for the most common case of "standard" encoding
|
||||
case wxFONTENCODING_SYSTEM:
|
||||
case wxFONTENCODING_ISO8859_1:
|
||||
case wxFONTENCODING_ISO8859_15:
|
||||
case wxFONTENCODING_CP1252:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1250:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1251:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1253:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1254:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1255:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1256:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1257:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP437:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
// no way to translate this encoding into a Windows charset
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
865
src/mac/carbon/pnghand.cpp
Normal file
865
src/mac/carbon/pnghand.cpp
Normal file
@@ -0,0 +1,865 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: pnghand.cpp
|
||||
// Purpose: Implements a PNG reader class + handler
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "pngread.h"
|
||||
#pragma implementation "pnghand.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if wxUSE_IOSTREAMH
|
||||
# include <fstream.h>
|
||||
#else
|
||||
# include <fstream>
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <wx/palette.h>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/mac/pnghand.h>
|
||||
#include <wx/mac/pngread.h>
|
||||
|
||||
extern "C" {
|
||||
#include "png.h"
|
||||
}
|
||||
|
||||
extern "C" void png_read_init PNGARG((png_structp png_ptr));
|
||||
extern "C" void png_write_init PNGARG((png_structp png_ptr));
|
||||
|
||||
extern CTabHandle wxMacCreateColorTable( int numColors ) ;
|
||||
extern void wxMacDestroyColorTable( CTabHandle colors ) ;
|
||||
extern void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
|
||||
extern GWorldPtr wxMacCreateGWorld( int height , int width , int depth ) ;
|
||||
extern void wxMacDestroyGWorld( GWorldPtr gw ) ;
|
||||
|
||||
void
|
||||
ima_png_error(png_struct *png_ptr, char *message)
|
||||
{
|
||||
wxMessageBox(message, "PNG error");
|
||||
longjmp(png_ptr->jmpbuf, 1);
|
||||
}
|
||||
|
||||
|
||||
// static wxGifReaderIter* iter;
|
||||
wxPalette *wxCopyPalette(const wxPalette *cmap);
|
||||
|
||||
wxPNGReader::wxPNGReader(void)
|
||||
{
|
||||
filetype = 0;
|
||||
RawImage = NULL; // Image data
|
||||
|
||||
Width = 0; Height = 0; // Dimensions
|
||||
Depth = 0; // (bits x pixel)
|
||||
ColorType = 0; // Bit 1 = Palette used
|
||||
// Bit 2 = Color used
|
||||
// Bit 3 = Alpha used
|
||||
|
||||
EfeWidth = 0; // Efective Width
|
||||
|
||||
lpbi = NULL;
|
||||
bgindex = -1;
|
||||
Palette = 0;
|
||||
imageOK = FALSE;
|
||||
}
|
||||
|
||||
wxPNGReader::wxPNGReader ( char* ImageFileName )
|
||||
{
|
||||
imageOK = FALSE;
|
||||
filetype = 0;
|
||||
RawImage = NULL; // Image data
|
||||
|
||||
Width = 0; Height = 0; // Dimensions
|
||||
Depth = 0; // (bits x pixel)
|
||||
ColorType = 0; // Bit 1 = Palette used
|
||||
// Bit 2 = Color used
|
||||
// Bit 3 = Alpha used
|
||||
|
||||
EfeWidth = 0; // Efective Width
|
||||
|
||||
lpbi = NULL;
|
||||
bgindex = -1;
|
||||
Palette = 0;
|
||||
|
||||
imageOK = ReadFile (ImageFileName);
|
||||
}
|
||||
|
||||
void
|
||||
wxPNGReader::Create(int width, int height, int depth, int colortype)
|
||||
{
|
||||
Width = width; Height = height; Depth = depth;
|
||||
ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0);
|
||||
|
||||
if (lpbi)
|
||||
{
|
||||
wxMacDestroyGWorld( lpbi ) ;
|
||||
// delete Palette;
|
||||
}
|
||||
RawImage = 0;
|
||||
Palette = 0;
|
||||
if (lpbi = wxMacCreateGWorld( Width , Height , Depth) )
|
||||
{
|
||||
EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4;
|
||||
int bitwidth = width ;
|
||||
if ( EfeWidth > bitwidth )
|
||||
bitwidth = EfeWidth ;
|
||||
|
||||
RawImage = (byte*) new char[ ( bitwidth * Height * ((Depth+7)>>3) ) ];
|
||||
imageOK = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
wxPNGReader::~wxPNGReader ( )
|
||||
{
|
||||
delete[] RawImage ;
|
||||
if (lpbi) {
|
||||
wxMacDestroyGWorld( lpbi ) ;
|
||||
}
|
||||
delete Palette;
|
||||
}
|
||||
|
||||
|
||||
int wxPNGReader::GetIndex(int x, int y)
|
||||
{
|
||||
if (!Inside(x, y) || (Depth>8)) return -1;
|
||||
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
int index = (int)(*ImagePointer);
|
||||
return index;
|
||||
}
|
||||
|
||||
bool wxPNGReader::GetRGB(int x, int y, byte* r, byte* g, byte* b)
|
||||
{
|
||||
if (!Inside(x, y)) return FALSE;
|
||||
|
||||
if (Palette) {
|
||||
return Palette->GetRGB(GetIndex(x, y), r, g, b);
|
||||
/* PALETTEENTRY entry;
|
||||
::GetPaletteEntries((HPALETTE) Palette->GetHPALETTE(), GetIndex(x, y), 1, &entry);
|
||||
*r = entry.peRed;
|
||||
*g = entry.peGreen;
|
||||
*b = entry.peBlue; */
|
||||
} else {
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
*b = ImagePointer[0];
|
||||
*g = ImagePointer[1];
|
||||
*r = ImagePointer[2];
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
bool wxPNGReader::SetIndex(int x, int y, int index)
|
||||
{
|
||||
if (!Inside(x, y) || (Depth>8)) return FALSE;
|
||||
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
*ImagePointer = index;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b)
|
||||
{
|
||||
if (!Inside(x, y)) return FALSE;
|
||||
|
||||
if (ColorType & COLORTYPE_PALETTE)
|
||||
{
|
||||
if (!Palette) return FALSE;
|
||||
SetIndex(x, y, Palette->GetPixel(r, g, b));
|
||||
|
||||
} else {
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
ImagePointer[0] = b;
|
||||
ImagePointer[1] = g;
|
||||
ImagePointer[2] = r;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxPNGReader::SetPalette(wxPalette* colourmap)
|
||||
{
|
||||
if (!colourmap)
|
||||
return FALSE;
|
||||
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
|
||||
Palette = colourmap;
|
||||
return true ;
|
||||
// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
|
||||
}
|
||||
|
||||
bool
|
||||
wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b)
|
||||
{
|
||||
Palette = new wxPalette();
|
||||
if (!Palette)
|
||||
return FALSE;
|
||||
|
||||
if (!g) g = r;
|
||||
if (!b) b = g;
|
||||
Palette->Create(n, r, g, b);
|
||||
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
|
||||
return true ;
|
||||
// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
|
||||
}
|
||||
|
||||
bool
|
||||
wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct)
|
||||
{
|
||||
Palette = new wxPalette();
|
||||
if (!Palette)
|
||||
return FALSE;
|
||||
|
||||
byte r[256], g[256], b[256];
|
||||
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
r[i] = rgb_struct[i].red;
|
||||
g[i] = rgb_struct[i].green;
|
||||
b[i] = rgb_struct[i].blue;
|
||||
}
|
||||
// Added by JACS copying from Andrew Davison's additions
|
||||
// to GIF-reading code
|
||||
// Make transparency colour black...
|
||||
if (bgindex != -1)
|
||||
r[bgindex] = g[bgindex] = b[bgindex] = 0;
|
||||
|
||||
Palette->Create(n, r, g, b);
|
||||
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
|
||||
return true ;
|
||||
// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
|
||||
}
|
||||
|
||||
void wxPNGReader::NullData()
|
||||
{
|
||||
lpbi = NULL;
|
||||
Palette = NULL;
|
||||
}
|
||||
|
||||
wxBitmap* wxPNGReader::GetBitmap(void)
|
||||
{
|
||||
wxBitmap *bitmap = new wxBitmap;
|
||||
if ( InstantiateBitmap(bitmap) )
|
||||
return bitmap;
|
||||
else
|
||||
{
|
||||
delete bitmap;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap)
|
||||
{
|
||||
if ( lpbi )
|
||||
{
|
||||
bitmap->SetHBITMAP((WXHBITMAP) lpbi);
|
||||
bitmap->SetWidth(GetWidth());
|
||||
bitmap->SetHeight(GetHeight());
|
||||
bitmap->SetDepth(GetDepth());
|
||||
if ( GetDepth() > 1 && Palette )
|
||||
bitmap->SetPalette(*Palette);
|
||||
bitmap->SetOk(TRUE);
|
||||
|
||||
|
||||
// Make a mask if appropriate
|
||||
/*
|
||||
if ( bgindex > -1 )
|
||||
{
|
||||
wxMask *mask = CreateMask();
|
||||
bitmap->SetMask(mask);
|
||||
}
|
||||
*/
|
||||
lpbi = NULL ; // bitmap has taken over ownership
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
/*
|
||||
HDC dc = ::CreateCompatibleDC(NULL);
|
||||
|
||||
if (dc)
|
||||
{
|
||||
// tmpBitmap is a dummy, to satisfy ::CreateCompatibleDC (it
|
||||
// is a memory dc that must have a bitmap selected into it)
|
||||
HDC dc2 = GetDC(NULL);
|
||||
HBITMAP tmpBitmap = ::CreateCompatibleBitmap(dc2, GetWidth(), GetHeight());
|
||||
ReleaseDC(NULL, dc2);
|
||||
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, tmpBitmap);
|
||||
|
||||
if ( Palette )
|
||||
{
|
||||
HPALETTE oldPal = ::SelectPalette(dc, (HPALETTE) Palette->GetHPALETTE(), FALSE);
|
||||
::RealizePalette(dc);
|
||||
}
|
||||
|
||||
HBITMAP hBitmap = ::CreateDIBitmap(dc, lpbi,
|
||||
CBM_INIT, RawImage, (LPBITMAPINFO) lpbi, DIB_PAL_COLORS);
|
||||
|
||||
::SelectPalette(dc, NULL, TRUE);
|
||||
::SelectObject(dc, oldBitmap);
|
||||
::DeleteObject(tmpBitmap);
|
||||
::DeleteDC(dc);
|
||||
|
||||
if ( hBitmap )
|
||||
{
|
||||
bitmap->SetHBITMAP((WXHBITMAP) hBitmap);
|
||||
bitmap->SetWidth(GetWidth());
|
||||
bitmap->SetHeight(GetHeight());
|
||||
bitmap->SetDepth(GetDepth());
|
||||
if ( GetDepth() > 1 && Palette )
|
||||
bitmap->SetPalette(*Palette);
|
||||
bitmap->SetOk(TRUE);
|
||||
|
||||
|
||||
// Make a mask if appropriate
|
||||
if ( bgindex > -1 )
|
||||
{
|
||||
wxMask *mask = CreateMask();
|
||||
bitmap->SetMask(mask);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
*/
|
||||
return false ;
|
||||
}
|
||||
|
||||
wxPalette *wxCopyPalette(const wxPalette *cmap)
|
||||
{
|
||||
wxPalette *newCmap = new wxPalette( *cmap ) ;
|
||||
return newCmap;
|
||||
}
|
||||
|
||||
wxMask *wxPNGReader::CreateMask(void)
|
||||
{
|
||||
/*
|
||||
HBITMAP hBitmap = ::CreateBitmap(GetWidth(), GetHeight(), 1, 1, NULL);
|
||||
|
||||
HDC dc = ::CreateCompatibleDC(NULL);
|
||||
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, hBitmap);
|
||||
|
||||
int bgIndex = GetBGIndex();
|
||||
|
||||
int x,y;
|
||||
|
||||
for (x=0; x<GetWidth(); x++)
|
||||
{
|
||||
for (y=0; y<GetHeight(); y++)
|
||||
{
|
||||
int index = GetIndex(x, y);
|
||||
if ( index == bgIndex )
|
||||
::SetPixel(dc, x, GetHeight() - y - 1, RGB(0, 0, 0));
|
||||
else
|
||||
::SetPixel(dc, x, GetHeight() - y - 1, RGB(255, 255, 255));
|
||||
|
||||
}
|
||||
}
|
||||
::SelectObject(dc, oldBitmap);
|
||||
wxMask *mask = new wxMask;
|
||||
mask->SetMaskBitmap((WXHBITMAP) hBitmap);
|
||||
return mask;
|
||||
*/
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
bool wxPNGReader::ReadFile(char * ImageFileName)
|
||||
{
|
||||
int number_passes;
|
||||
|
||||
if (ImageFileName)
|
||||
strcpy(filename, ImageFileName);
|
||||
|
||||
FILE *fp;
|
||||
png_struct *png_ptr;
|
||||
png_info *info_ptr;
|
||||
wxPNGReaderIter iter(this);
|
||||
|
||||
/* open the file */
|
||||
fp = fopen(wxUnix2MacFilename( ImageFileName ), "rb");
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
|
||||
/* allocate the necessary structures */
|
||||
png_ptr = new (png_struct);
|
||||
if (!png_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
info_ptr = new (png_info);
|
||||
if (!info_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
return FALSE;
|
||||
}
|
||||
/* set error handling */
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* If we get here, we had a problem reading the file */
|
||||
return FALSE;
|
||||
}
|
||||
//png_set_error(ima_png_error, NULL);
|
||||
|
||||
/* initialize the structures, info first for error handling */
|
||||
png_info_init(info_ptr);
|
||||
png_read_init(png_ptr);
|
||||
|
||||
/* set up the input control */
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
/* read the file information */
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
/* allocate the memory to hold the image using the fields
|
||||
of png_info. */
|
||||
png_color_16 my_background={ 0, 31, 127, 255, 0 };
|
||||
|
||||
if (info_ptr->valid & PNG_INFO_bKGD)
|
||||
{
|
||||
png_set_background(png_ptr, &(info_ptr->background),
|
||||
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||
if ( info_ptr->num_palette > 0 )
|
||||
bgindex = info_ptr->background.index;
|
||||
}
|
||||
else {
|
||||
png_set_background(png_ptr, &my_background,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
||||
|
||||
// Added by JACS: guesswork!
|
||||
if ( info_ptr->num_trans != 0 )
|
||||
bgindex = info_ptr->num_trans - 1 ;
|
||||
}
|
||||
|
||||
/* tell libpng to strip 16 bit depth files down to 8 bits */
|
||||
if (info_ptr->bit_depth == 16)
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
int pixel_depth=(info_ptr->pixel_depth<24) ? info_ptr->pixel_depth: 24;
|
||||
Create(info_ptr->width, info_ptr->height, pixel_depth,
|
||||
info_ptr->color_type);
|
||||
|
||||
if (info_ptr->num_palette>0)
|
||||
{
|
||||
SetPalette((int)info_ptr->num_palette, (rgb_color_struct*)info_ptr->palette);
|
||||
}
|
||||
|
||||
int row_stride = info_ptr->width * ((pixel_depth+7)>>3);
|
||||
// printf("P = %d D = %d RS= %d ", info_ptr->num_palette, info_ptr->pixel_depth,row_stride);
|
||||
// printf("CT = %d TRS = %d BD= %d ", info_ptr->color_type, info_ptr->valid & PNG_INFO_tRNS,info_ptr->bit_depth);
|
||||
|
||||
byte *row_pointers = new byte[row_stride];
|
||||
|
||||
/* turn on interlace handling */
|
||||
if (info_ptr->interlace_type)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
else
|
||||
number_passes = 1;
|
||||
// printf("NP = %d ", number_passes);
|
||||
|
||||
for (int pass=0; pass< number_passes; pass++)
|
||||
{
|
||||
iter.upset();
|
||||
int y=0;
|
||||
CGrafPtr origPort ;
|
||||
GDHandle origDevice ;
|
||||
|
||||
GetGWorld( &origPort , &origDevice ) ;
|
||||
// ignore shapedc
|
||||
SetGWorld( lpbi , NULL ) ;
|
||||
do
|
||||
{
|
||||
// (unsigned char *)iter.GetRow();
|
||||
if (info_ptr->interlace_type)
|
||||
{
|
||||
if (pass>0)
|
||||
iter.GetRow(row_pointers, row_stride);
|
||||
png_read_row(png_ptr, row_pointers, NULL);
|
||||
}
|
||||
else
|
||||
png_read_row(png_ptr, row_pointers, NULL);
|
||||
|
||||
if ( info_ptr->palette )
|
||||
{
|
||||
if ( pixel_depth == 8 )
|
||||
{
|
||||
png_color_struct* color ;
|
||||
RGBColor col ;
|
||||
unsigned char* p = &row_pointers[0] ;
|
||||
MoveTo( 0 , y ) ;
|
||||
unsigned char lastcol = *p ;
|
||||
color = &info_ptr->palette[lastcol] ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
RGBForeColor( &col ) ;
|
||||
for ( int i = 0 ; i < info_ptr->width ; ++i , ++p)
|
||||
{
|
||||
if ( *p != lastcol )
|
||||
{
|
||||
LineTo( i , y ) ;
|
||||
lastcol = *p ;
|
||||
color = &info_ptr->palette[lastcol] ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
RGBForeColor( &col ) ;
|
||||
}
|
||||
}
|
||||
LineTo( info_ptr->width - 1 , y ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0 ; i < info_ptr->width ; ++i )
|
||||
{
|
||||
png_color_struct* color ;
|
||||
RGBColor col ;
|
||||
|
||||
int byte = ( i * pixel_depth ) / 8 ;
|
||||
int offset = ( 8 - pixel_depth ) - ( i * pixel_depth ) % 8 ;
|
||||
|
||||
int index = ( row_pointers[byte] >> offset ) & ( 0xFF >> ( 8 - pixel_depth ) );
|
||||
color = &info_ptr->palette[index] ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
SetCPixel( i, y, &col);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0 ; i < info_ptr->width ; ++i )
|
||||
{
|
||||
png_color_struct* color ;
|
||||
RGBColor col ;
|
||||
color =(png_color_struct*) (&row_pointers[i*3]) ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
SetCPixel( i, y, &col);
|
||||
}
|
||||
}
|
||||
if (number_passes)
|
||||
iter.SetRow(row_pointers, row_stride);
|
||||
y++;
|
||||
}
|
||||
while(iter.PrevRow());
|
||||
SetGWorld( origPort , origDevice ) ;
|
||||
|
||||
// printf("Y=%d ",y);
|
||||
}
|
||||
delete[] row_pointers;
|
||||
|
||||
/* read the rest of the file, getting any additional chunks
|
||||
in info_ptr */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the read, and free any memory allocated */
|
||||
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
|
||||
|
||||
/* free the structures */
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* close the file */
|
||||
fclose(fp);
|
||||
|
||||
/* that's it */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* write a png file */
|
||||
|
||||
bool wxPNGReader::SaveFile(char * ImageFileName)
|
||||
{
|
||||
if (ImageFileName)
|
||||
strcpy(filename, ImageFileName);
|
||||
|
||||
wxPNGReaderIter iter(this);
|
||||
FILE *fp;
|
||||
png_struct *png_ptr;
|
||||
png_info *info_ptr;
|
||||
|
||||
/* open the file */
|
||||
fp = fopen(filename, "wb");
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
|
||||
/* allocate the necessary structures */
|
||||
png_ptr = new (png_struct);
|
||||
if (!png_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
info_ptr = new (png_info);
|
||||
if (!info_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set error handling */
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
png_write_destroy(png_ptr);
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* If we get here, we had a problem reading the file */
|
||||
return FALSE;
|
||||
}
|
||||
//png_set_error(ima_png_error, NULL);
|
||||
|
||||
// printf("writig pg %s ", filename);
|
||||
/* initialize the structures */
|
||||
png_info_init(info_ptr);
|
||||
png_write_init(png_ptr);
|
||||
|
||||
int row_stride = GetWidth() * ((GetDepth()+7)>>3);
|
||||
/* set up the output control */
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
/* set the file information here */
|
||||
info_ptr->width = GetWidth();
|
||||
info_ptr->height = GetHeight();
|
||||
info_ptr->pixel_depth = GetDepth();
|
||||
info_ptr->channels = (GetDepth()>8) ? 3: 1;
|
||||
info_ptr->bit_depth = GetDepth()/info_ptr->channels;
|
||||
info_ptr->color_type = GetColorType();
|
||||
info_ptr->compression_type = info_ptr->filter_type = info_ptr->interlace_type=0;
|
||||
info_ptr->valid = 0;
|
||||
info_ptr->rowbytes = row_stride;
|
||||
|
||||
|
||||
// printf("P = %d D = %d RS= %d GD= %d CH= %d ", info_ptr->pixel_depth, info_ptr->bit_depth, row_stride, GetDepth(), info_ptr->channels);
|
||||
/* set the palette if there is one */
|
||||
if ((GetColorType() & COLORTYPE_PALETTE) && GetPalette())
|
||||
{
|
||||
// printf("writing paleta[%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
|
||||
info_ptr->valid |= PNG_INFO_PLTE;
|
||||
info_ptr->palette = new png_color[256];
|
||||
info_ptr->num_palette = 256;
|
||||
for (int i=0; i<256; i++)
|
||||
GetPalette()->GetRGB(i, &info_ptr->palette[i].red, &info_ptr->palette[i].green, &info_ptr->palette[i].blue);
|
||||
}
|
||||
// printf("Paleta [%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
|
||||
|
||||
|
||||
/* optional significant bit chunk */
|
||||
// info_ptr->valid |= PNG_INFO_sBIT;
|
||||
// info_ptr->sig_bit = true_bit_depth;
|
||||
|
||||
/* optional gamma chunk */
|
||||
// info_ptr->valid |= PNG_INFO_gAMA;
|
||||
// info_ptr->gamma = gamma;
|
||||
|
||||
/* other optional chunks */
|
||||
|
||||
/* write the file information */
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
/* set up the transformations you want. Note that these are
|
||||
all optional. Only call them if you want them */
|
||||
|
||||
/* shift the pixels up to a legal bit depth and fill in
|
||||
as appropriate to correctly scale the image */
|
||||
// png_set_shift(png_ptr, &(info_ptr->sig_bit));
|
||||
|
||||
/* pack pixels into bytes */
|
||||
// png_set_packing(png_ptr);
|
||||
|
||||
/* flip bgr pixels to rgb */
|
||||
// png_set_bgr(png_ptr);
|
||||
|
||||
/* swap bytes of 16 bit files to most significant bit first */
|
||||
// png_set_swap(png_ptr);
|
||||
|
||||
/* get rid of filler bytes, pack rgb into 3 bytes */
|
||||
// png_set_rgbx(png_ptr);
|
||||
|
||||
/* If you are only writing one row at a time, this works */
|
||||
|
||||
byte *row_pointers = new byte[row_stride];
|
||||
iter.upset();
|
||||
do {
|
||||
// (unsigned char *)iter.GetRow();
|
||||
iter.GetRow(row_pointers, row_stride);
|
||||
png_write_row(png_ptr, row_pointers);
|
||||
} while(iter.PrevRow());
|
||||
|
||||
delete[] row_pointers;
|
||||
|
||||
/* write the rest of the file */
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
png_write_destroy(png_ptr);
|
||||
|
||||
/* if you malloced the palette, free it here */
|
||||
if (info_ptr->palette)
|
||||
delete[] (info_ptr->palette);
|
||||
|
||||
/* free the structures */
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* close the file */
|
||||
fclose(fp);
|
||||
|
||||
/* that's it */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int Power(int x, int y)
|
||||
{
|
||||
int z = 1;
|
||||
int i;
|
||||
for ( i = 0; i < y; i++)
|
||||
{
|
||||
z *= x;
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F' };
|
||||
|
||||
static void DecToHex(int dec, char *buf)
|
||||
{
|
||||
int firstDigit = (int)(dec/16.0);
|
||||
int secondDigit = (int)(dec - (firstDigit*16.0));
|
||||
buf[0] = hexArray[firstDigit];
|
||||
buf[1] = hexArray[secondDigit];
|
||||
buf[2] = 0;
|
||||
}
|
||||
|
||||
|
||||
bool wxPNGReader::SaveXPM(char *filename, char *name)
|
||||
{
|
||||
char nameStr[256];
|
||||
if ( name )
|
||||
strcpy(nameStr, name);
|
||||
else
|
||||
{
|
||||
strcpy(nameStr, filename);
|
||||
wxStripExtension(nameStr);
|
||||
}
|
||||
|
||||
if ( GetDepth() > 4 )
|
||||
{
|
||||
// Only a depth of 4 and below allowed
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( !GetPalette() )
|
||||
return FALSE;
|
||||
|
||||
ofstream str(filename);
|
||||
if ( str.bad() )
|
||||
return FALSE;
|
||||
|
||||
int noColours = Power(2, GetDepth());
|
||||
|
||||
// Output header
|
||||
str << "/* XPM */\n";
|
||||
str << "static char * " << nameStr << "_xpm[] = {\n";
|
||||
str << "\"" << GetWidth() << " " << GetHeight() << " " << noColours << " 1\",\n";
|
||||
|
||||
// Output colourmap
|
||||
int base = 97 ; // start from 'a'
|
||||
|
||||
unsigned char red, green, blue;
|
||||
char hexBuf[4];
|
||||
int i;
|
||||
for ( i = 0; i < noColours; i ++)
|
||||
{
|
||||
str << "\"" << (char)(base + i) << " c #";
|
||||
GetPalette()->GetRGB(i, &red, &green, &blue);
|
||||
DecToHex(red, hexBuf);
|
||||
str << hexBuf;
|
||||
DecToHex(green, hexBuf);
|
||||
str << hexBuf;
|
||||
DecToHex(blue, hexBuf);
|
||||
str << hexBuf;
|
||||
str << "\",\n";
|
||||
}
|
||||
|
||||
// Output the data
|
||||
int x, y;
|
||||
for ( y = 0; y < GetHeight(); y++)
|
||||
{
|
||||
str << "\"";
|
||||
for ( x = 0; x < GetWidth(); x++)
|
||||
{
|
||||
int index = GetIndex(x, y);
|
||||
str << (char)(base + index) ;
|
||||
}
|
||||
str << "\",\n";
|
||||
}
|
||||
|
||||
str << "};\n";
|
||||
str.flush();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPNGFileHandler, wxBitmapHandler)
|
||||
|
||||
bool wxPNGFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
|
||||
int desiredWidth, int desiredHeight)
|
||||
{
|
||||
wxPNGReader reader;
|
||||
if (reader.ReadFile((char*) (const char*) name))
|
||||
{
|
||||
return reader.InstantiateBitmap(bitmap);
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxPNGFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *pal)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
329
src/mac/carbon/printmac.cpp
Normal file
329
src/mac/carbon/printmac.cpp
Normal file
@@ -0,0 +1,329 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: printwin.cpp
|
||||
// Purpose: wxMacPrinter framework
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "printwin.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/utils.h"
|
||||
#include "wx/dc.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/msgdlg.h"
|
||||
#endif
|
||||
|
||||
#include "wx/mac/printmac.h"
|
||||
#include "wx/dcprint.h"
|
||||
#include "wx/printdlg.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
|
||||
IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Printer
|
||||
*/
|
||||
|
||||
wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
|
||||
wxPrinterBase(data)
|
||||
{
|
||||
}
|
||||
|
||||
wxMacPrinter::~wxMacPrinter(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
|
||||
{
|
||||
sm_abortIt = FALSE;
|
||||
sm_abortWindow = NULL;
|
||||
|
||||
if (!printout)
|
||||
return FALSE;
|
||||
|
||||
printout->SetIsPreview(FALSE);
|
||||
printout->OnPreparePrinting();
|
||||
|
||||
// Get some parameters from the printout, if defined
|
||||
int fromPage, toPage;
|
||||
int minPage, maxPage;
|
||||
printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
|
||||
|
||||
if (maxPage == 0)
|
||||
return FALSE;
|
||||
|
||||
m_printDialogData.SetMinPage(minPage);
|
||||
m_printDialogData.SetMaxPage(maxPage);
|
||||
if (fromPage != 0)
|
||||
m_printDialogData.SetFromPage(fromPage);
|
||||
if (toPage != 0)
|
||||
m_printDialogData.SetToPage(toPage);
|
||||
|
||||
if (minPage != 0)
|
||||
{
|
||||
m_printDialogData.EnablePageNumbers(TRUE);
|
||||
if (m_printDialogData.GetFromPage() < m_printDialogData.GetMinPage())
|
||||
m_printDialogData.SetFromPage(m_printDialogData.GetMinPage());
|
||||
else if (m_printDialogData.GetFromPage() > m_printDialogData.GetMaxPage())
|
||||
m_printDialogData.SetFromPage(m_printDialogData.GetMaxPage());
|
||||
if (m_printDialogData.GetToPage() > m_printDialogData.GetMaxPage())
|
||||
m_printDialogData.SetToPage(m_printDialogData.GetMaxPage());
|
||||
else if (m_printDialogData.GetToPage() < m_printDialogData.GetMinPage())
|
||||
m_printDialogData.SetToPage(m_printDialogData.GetMinPage());
|
||||
}
|
||||
else
|
||||
m_printDialogData.EnablePageNumbers(FALSE);
|
||||
|
||||
// Create a suitable device context
|
||||
// Create a suitable device context
|
||||
wxDC *dc = NULL;
|
||||
if (prompt)
|
||||
{
|
||||
PrOpen() ;
|
||||
m_printDialogData.ConvertToNative() ; // make sure we have a valid handle
|
||||
if ( m_printDialogData.m_macPrintInfo )
|
||||
{
|
||||
// todo incorporate the changes from a global page setup
|
||||
if ( ::PrStlDialog( m_printDialogData.m_macPrintInfo ) ) // we should have the page setup dialog
|
||||
{
|
||||
PrClose() ;
|
||||
wxPrintDialog dialog(parent, & m_printDialogData);
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
dc = dialog.GetPrintDC();
|
||||
m_printDialogData = dialog.GetPrintData();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrClose() ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
|
||||
}
|
||||
|
||||
|
||||
// May have pressed cancel.
|
||||
if (!dc || !dc->Ok())
|
||||
{
|
||||
if (dc) delete dc;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// on the mac we have always pixels as addressing mode with 72 dpi
|
||||
|
||||
printout->SetPPIScreen(72, 72);
|
||||
printout->SetPPIPrinter(72, 72);
|
||||
|
||||
// Set printout parameters
|
||||
printout->SetDC(dc);
|
||||
|
||||
int w, h;
|
||||
long ww, hh;
|
||||
dc->GetSize(&w, &h);
|
||||
printout->SetPageSizePixels((int)w, (int)h);
|
||||
dc->GetSizeMM(&ww, &hh);
|
||||
printout->SetPageSizeMM((int)ww, (int)hh);
|
||||
|
||||
// Create an abort window
|
||||
wxBeginBusyCursor();
|
||||
|
||||
/*
|
||||
wxWindow *win = CreateAbortWindow(parent, printout);
|
||||
wxYield();
|
||||
|
||||
if (!win)
|
||||
{
|
||||
wxEndBusyCursor();
|
||||
wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent);
|
||||
delete dc;
|
||||
}
|
||||
sm_abortWindow = win;
|
||||
sm_abortWindow->Show(TRUE);
|
||||
wxYield();
|
||||
*/
|
||||
|
||||
printout->OnBeginPrinting();
|
||||
|
||||
bool keepGoing = TRUE;
|
||||
|
||||
int copyCount;
|
||||
for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
|
||||
{
|
||||
if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
|
||||
{
|
||||
wxEndBusyCursor();
|
||||
wxMessageBox("Could not start printing.", "Print Error", wxOK, parent);
|
||||
break;
|
||||
}
|
||||
if (sm_abortIt)
|
||||
break;
|
||||
|
||||
int pn;
|
||||
for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
|
||||
pn++)
|
||||
{
|
||||
if (sm_abortIt)
|
||||
{
|
||||
keepGoing = FALSE;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
dc->StartPage();
|
||||
keepGoing = printout->OnPrintPage(pn);
|
||||
dc->EndPage();
|
||||
}
|
||||
}
|
||||
printout->OnEndDocument();
|
||||
}
|
||||
|
||||
printout->OnEndPrinting();
|
||||
|
||||
if (sm_abortWindow)
|
||||
{
|
||||
sm_abortWindow->Show(FALSE);
|
||||
delete sm_abortWindow;
|
||||
sm_abortWindow = NULL;
|
||||
}
|
||||
|
||||
wxEndBusyCursor();
|
||||
|
||||
delete dc;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
|
||||
{
|
||||
wxDC* dc = (wxDC*) NULL;
|
||||
|
||||
wxPrintDialog dialog(parent, & m_printDialogData);
|
||||
int ret = dialog.ShowModal();
|
||||
|
||||
if (ret == wxID_OK)
|
||||
{
|
||||
dc = dialog.GetPrintDC();
|
||||
m_printDialogData = dialog.GetPrintDialogData();
|
||||
}
|
||||
|
||||
return dc;
|
||||
}
|
||||
|
||||
bool wxMacPrinter::Setup(wxWindow *parent)
|
||||
{
|
||||
wxPrintDialog dialog(parent, & m_printDialogData);
|
||||
dialog.GetPrintDialogData().SetSetupDialog(TRUE);
|
||||
|
||||
int ret = dialog.ShowModal();
|
||||
|
||||
if (ret == wxID_OK)
|
||||
{
|
||||
m_printDialogData = dialog.GetPrintDialogData();
|
||||
}
|
||||
|
||||
return (ret == wxID_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print preview
|
||||
*/
|
||||
|
||||
wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
|
||||
wxPrintout *printoutForPrinting,
|
||||
wxPrintDialogData *data)
|
||||
: wxPrintPreviewBase(printout, printoutForPrinting, data)
|
||||
{
|
||||
DetermineScaling();
|
||||
}
|
||||
|
||||
wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
|
||||
wxPrintPreviewBase(printout, printoutForPrinting, data)
|
||||
{
|
||||
DetermineScaling();
|
||||
}
|
||||
|
||||
wxMacPrintPreview::~wxMacPrintPreview(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxMacPrintPreview::Print(bool interactive)
|
||||
{
|
||||
if (!m_printPrintout)
|
||||
return FALSE;
|
||||
wxMacPrinter printer(&m_printDialogData);
|
||||
return printer.Print(m_previewFrame, m_printPrintout, interactive);
|
||||
}
|
||||
|
||||
void wxMacPrintPreview::DetermineScaling(void)
|
||||
{
|
||||
/*
|
||||
HDC dc = ::GetDC(NULL);
|
||||
int screenWidth = ::GetDeviceCaps(dc, HORZSIZE);
|
||||
// int screenHeight = ::GetDeviceCaps(dc, VERTSIZE);
|
||||
int screenXRes = ::GetDeviceCaps(dc, HORZRES);
|
||||
// int screenYRes = ::GetDeviceCaps(dc, VERTRES);
|
||||
int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX);
|
||||
int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY);
|
||||
m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
|
||||
|
||||
::ReleaseDC(NULL, dc);
|
||||
|
||||
// Get a device context for the currently selected printer
|
||||
wxPrinterDC printerDC("", "", "", FALSE, m_printDialogData.GetOrientation());
|
||||
|
||||
int printerWidth = 150;
|
||||
int printerHeight = 250;
|
||||
int printerXRes = 1500;
|
||||
int printerYRes = 2500;
|
||||
|
||||
if (printerDC.GetHDC())
|
||||
{
|
||||
printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE);
|
||||
printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE);
|
||||
printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES);
|
||||
printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES);
|
||||
|
||||
int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX);
|
||||
int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY);
|
||||
|
||||
m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
|
||||
m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight);
|
||||
|
||||
if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0)
|
||||
m_isOk = FALSE;
|
||||
}
|
||||
else
|
||||
m_isOk = FALSE;
|
||||
|
||||
m_pageWidth = printerXRes;
|
||||
m_pageHeight = printerYRes;
|
||||
|
||||
// At 100%, the page should look about page-size on the screen.
|
||||
m_previewScale = (float)((float)screenWidth/(float)printerWidth);
|
||||
m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerYRes);
|
||||
*/
|
||||
}
|
61
src/mac/carbon/statline.cpp
Normal file
61
src/mac/carbon/statline.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: generic/statline.cpp
|
||||
// Purpose: a generic wxStaticLine class
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 28.06.99
|
||||
// Version: $Id$
|
||||
// Copyright: (c) 1998 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "statline.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/statline.h"
|
||||
#include "wx/statbox.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxStaticLine, wxControl)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStaticLine
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxStaticLine::Create( wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint &pos,
|
||||
const wxSize &size,
|
||||
long style,
|
||||
const wxString &name)
|
||||
{
|
||||
if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
|
||||
return FALSE;
|
||||
|
||||
// ok, this is ugly but it's better than nothing: use a thin static box to
|
||||
// emulate static line
|
||||
|
||||
wxSize sizeReal = AdjustSize(size);
|
||||
|
||||
// m_statbox = new wxStaticBox(parent, id, wxT(""), pos, sizeReal, style, name);
|
||||
|
||||
return TRUE;
|
||||
}
|
858
src/mac/carbon/uma.cpp
Normal file
858
src/mac/carbon/uma.cpp
Normal file
@@ -0,0 +1,858 @@
|
||||
#include <wx/mac/uma.h>
|
||||
#include <wx/mac/aga.h>
|
||||
|
||||
// init
|
||||
|
||||
static bool sUMAHasAppearance = false ;
|
||||
static long sUMAAppearanceVersion = 0 ;
|
||||
extern int gAGABackgroundColor ;
|
||||
bool UMAHasAppearance() { return sUMAHasAppearance ; }
|
||||
long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
|
||||
|
||||
static bool sUMAHasWindowManager = false ;
|
||||
static long sUMAWindowManagerAttr = 0 ;
|
||||
|
||||
bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
|
||||
long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
|
||||
|
||||
void UMAInitToolbox( UInt16 inMoreMastersCalls )
|
||||
{
|
||||
#if !TARGET_CARBON
|
||||
::MaxApplZone();
|
||||
for (long i = 1; i <= inMoreMastersCalls; i++)
|
||||
::MoreMasters();
|
||||
|
||||
::InitGraf(&qd.thePort);
|
||||
::InitFonts();
|
||||
::InitWindows();
|
||||
::InitMenus();
|
||||
::TEInit();
|
||||
::InitDialogs(0L);
|
||||
::FlushEvents(everyEvent, 0);
|
||||
::InitCursor();
|
||||
long total,contig;
|
||||
PurgeSpace(&total, &contig);
|
||||
#else
|
||||
InitMenus() ;
|
||||
#endif
|
||||
|
||||
#if UMA_USE_APPEARANCE
|
||||
long theAppearance ;
|
||||
if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
|
||||
{
|
||||
sUMAHasAppearance = true ;
|
||||
RegisterAppearanceClient();
|
||||
if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
|
||||
{
|
||||
sUMAAppearanceVersion = theAppearance ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sUMAAppearanceVersion = 0x0100 ;
|
||||
}
|
||||
}
|
||||
#endif // UMA_USE_APPEARANCE
|
||||
#if UMA_USE_8_6
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr )
|
||||
{
|
||||
sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ;
|
||||
}
|
||||
#endif // UMA_USE_WINDOWMGR
|
||||
#endif
|
||||
}
|
||||
|
||||
// process manager
|
||||
long UMAGetProcessMode()
|
||||
{
|
||||
OSErr err ;
|
||||
ProcessInfoRec processinfo;
|
||||
ProcessSerialNumber procno ;
|
||||
|
||||
procno.highLongOfPSN = NULL ;
|
||||
procno.lowLongOfPSN = kCurrentProcess ;
|
||||
processinfo.processInfoLength = sizeof(ProcessInfoRec);
|
||||
processinfo.processName = NULL;
|
||||
processinfo.processAppSpec = NULL;
|
||||
|
||||
err = ::GetProcessInformation( &procno , &processinfo ) ;
|
||||
wxASSERT( err == noErr ) ;
|
||||
return processinfo.processMode ;
|
||||
}
|
||||
|
||||
bool UMAGetProcessModeDoesActivateOnFGSwitch()
|
||||
{
|
||||
return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
|
||||
}
|
||||
|
||||
// menu manager
|
||||
|
||||
void UMASetMenuTitle( MenuRef menu , ConstStr255Param title )
|
||||
{
|
||||
#if !TARGET_CARBON
|
||||
long size = GetHandleSize( (Handle) menu ) ;
|
||||
const long headersize = 14 ;
|
||||
int oldlen = (**menu).menuData[0] + 1;
|
||||
int newlen = title[0] + 1 ;
|
||||
|
||||
if ( oldlen < newlen )
|
||||
{
|
||||
// enlarge before adjusting
|
||||
SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
|
||||
}
|
||||
|
||||
if ( oldlen != newlen )
|
||||
memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
|
||||
|
||||
memcpy( (char*) (**menu).menuData , title , newlen ) ;
|
||||
if ( oldlen > newlen )
|
||||
{
|
||||
// shrink after
|
||||
SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
|
||||
}
|
||||
#else
|
||||
SetMenuTitle( menu , title ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
UInt32 UMAMenuEvent( EventRecord *inEvent )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return MenuEvent( inEvent ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( inEvent->what == keyDown && inEvent->modifiers & cmdKey)
|
||||
{
|
||||
return MenuKey( inEvent->message & charCodeMask ) ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
|
||||
{
|
||||
#if UMA_USE_8_6
|
||||
EnableMenuItem( inMenu , inItem ) ;
|
||||
#else
|
||||
EnableItem( inMenu , inItem ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
|
||||
{
|
||||
#if UMA_USE_8_6
|
||||
DisableMenuItem( inMenu , inItem ) ;
|
||||
#else
|
||||
DisableItem( inMenu , inItem ) ;
|
||||
#endif
|
||||
}
|
||||
// quickdraw
|
||||
|
||||
#if !TARGET_CARBON
|
||||
|
||||
pascal QDGlobalsPtr GetQDGlobalsPtr (void)
|
||||
{
|
||||
return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void UMAShowWatchCursor()
|
||||
{
|
||||
OSErr err = noErr;
|
||||
|
||||
CursHandle watchFob = GetCursor (watchCursor);
|
||||
|
||||
if (!watchFob)
|
||||
err = nilHandleErr;
|
||||
else
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
Cursor preservedArrow;
|
||||
GetQDGlobalsArrow (&preservedArrow);
|
||||
SetQDGlobalsArrow (*watchFob);
|
||||
InitCursor ( );
|
||||
SetQDGlobalsArrow (&preservedArrow);
|
||||
#else
|
||||
SetCursor (*watchFob);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void UMAShowArrowCursor()
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
Cursor arrow;
|
||||
SetCursor (GetQDGlobalsArrow (&arrow));
|
||||
#else
|
||||
SetCursor (&(qd.arrow));
|
||||
#endif
|
||||
}
|
||||
|
||||
// window manager
|
||||
|
||||
GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
|
||||
{
|
||||
wxASSERT( inWindowRef != NULL ) ;
|
||||
#if TARGET_CARBON
|
||||
return GetWindowPort( inWindowRef ) ;
|
||||
#else
|
||||
return (GrafPtr) inWindowRef ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMADisposeWindow( WindowRef inWindowRef )
|
||||
{
|
||||
wxASSERT( inWindowRef != NULL ) ;
|
||||
DisposeWindow( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMASetWTitleC( WindowRef inWindowRef , const char *title )
|
||||
{
|
||||
Str255 ptitle ;
|
||||
strncpy( (char*)ptitle , title , 96 ) ;
|
||||
ptitle[96] = 0 ;
|
||||
c2pstr( (char*)ptitle ) ;
|
||||
SetWTitle( inWindowRef , ptitle ) ;
|
||||
}
|
||||
void UMAGetWTitleC( WindowRef inWindowRef , char *title )
|
||||
{
|
||||
GetWTitle( inWindowRef , (unsigned char*)title ) ;
|
||||
p2cstr( (unsigned char*)title ) ;
|
||||
}
|
||||
|
||||
void UMAShowWindow( WindowRef inWindowRef )
|
||||
{
|
||||
ShowWindow( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMAHideWindow( WindowRef inWindowRef )
|
||||
{
|
||||
HideWindow( inWindowRef) ;
|
||||
}
|
||||
|
||||
void UMASelectWindow( WindowRef inWindowRef )
|
||||
{
|
||||
SelectWindow( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMABringToFront( WindowRef inWindowRef )
|
||||
{
|
||||
BringToFront( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMASendBehind( WindowRef inWindowRef , WindowRef behindWindow )
|
||||
{
|
||||
SendBehind( inWindowRef , behindWindow ) ;
|
||||
}
|
||||
|
||||
void UMACloseWindow(WindowRef inWindowRef)
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
#else
|
||||
CloseWindow( inWindowRef ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
// appearance additions
|
||||
|
||||
void UMAActivateControl( ControlHandle inControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::ActivateControl( inControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAActivateControl( inControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMADrawControl( ControlHandle inControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::DrawControlInCurrentPort( inControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGADrawControl( inControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMAMoveControl( ControlHandle inControl , short x , short y )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::MoveControl( inControl , x , y ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAMoveControl( inControl , x ,y ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMASizeControl( ControlHandle inControl , short x , short y )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::SizeControl( inControl , x , y ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGASizeControl( inControl , x ,y ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMADeactivateControl( ControlHandle inControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::DeactivateControl( inControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGADeactivateControl( inControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMASetThemeWindowBackground (WindowRef inWindow,
|
||||
ThemeBrush inBrush,
|
||||
Boolean inUpdate){
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ControlHandle UMANewControl(WindowPtr owningWindow,
|
||||
const Rect * boundsRect,
|
||||
ConstStr255Param controlTitle,
|
||||
Boolean initiallyVisible,
|
||||
SInt16 initialValue,
|
||||
SInt16 minimumValue,
|
||||
SInt16 maximumValue,
|
||||
SInt16 procID,
|
||||
SInt32 controlReference)
|
||||
{
|
||||
ControlHandle theControl = NULL ;
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
theControl = NewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
|
||||
initialValue , minimumValue , maximumValue , procID , controlReference ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
theControl = AGANewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
|
||||
initialValue , minimumValue , maximumValue , procID , controlReference ) ;
|
||||
}
|
||||
return theControl ;
|
||||
}
|
||||
|
||||
void UMADisposeControl (ControlHandle theControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::DisposeControl( theControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::DisposeControl( theControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMAHiliteControl (ControlHandle theControl,
|
||||
ControlPartCode hiliteState)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::HiliteControl( theControl , hiliteState ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::HiliteControl( theControl , hiliteState ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMAShowControl (ControlHandle theControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::ShowControl( theControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::ShowControl( theControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMAHideControl (ControlHandle theControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::HideControl( theControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::HideControl( theControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMASetControlVisibility (ControlHandle inControl,
|
||||
Boolean inIsVisible,
|
||||
Boolean inDoDraw)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool UMAIsControlActive (ControlHandle inControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return IsControlActive( inControl ) ;
|
||||
}
|
||||
else
|
||||
return (**inControl).contrlHilite == 0 ;
|
||||
}
|
||||
|
||||
|
||||
bool UMAIsControlVisible (ControlHandle inControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return IsControlVisible( inControl ) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
OSErr UMAGetBestControlRect (ControlHandle inControl,
|
||||
Rect * outRect,
|
||||
SInt16 * outBaseLineOffset)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return GetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OSErr UMASetControlFontStyle (ControlHandle inControl,
|
||||
const ControlFontStyleRec * inStyle)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return ::SetControlFontStyle( inControl , inStyle ) ;
|
||||
}
|
||||
else
|
||||
return AGASetControlFontStyle( inControl , inStyle ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// control hierarchy
|
||||
|
||||
OSErr UMACreateRootControl (WindowPtr inWindow,
|
||||
ControlHandle * outControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return CreateRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
else
|
||||
return AGACreateRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OSErr UMAEmbedControl (ControlHandle inControl,
|
||||
ControlHandle inContainer)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return EmbedControl( inControl , inContainer ) ;
|
||||
}
|
||||
else
|
||||
return AGAEmbedControl( inControl , inContainer ) ; ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// keyboard focus
|
||||
OSErr UMASetKeyboardFocus (WindowPtr inWindow,
|
||||
ControlHandle inControl,
|
||||
ControlFocusPart inPart)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return SetKeyboardFocus( inWindow , inControl , inPart ) ;
|
||||
}
|
||||
else
|
||||
return AGASetKeyboardFocus( inWindow , inControl , inPart ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// events
|
||||
|
||||
ControlPartCode UMAHandleControlClick (ControlHandle inControl,
|
||||
Point inWhere,
|
||||
SInt16 inModifiers,
|
||||
ControlActionUPP inAction)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return HandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAHandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SInt16 UMAHandleControlKey (ControlHandle inControl,
|
||||
SInt16 inKeyCode,
|
||||
SInt16 inCharCode,
|
||||
SInt16 inModifiers)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return HandleControlKey( inControl , inKeyCode , inCharCode , inModifiers ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAHandleControlKey(inControl , inKeyCode , inCharCode , inModifiers ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UMAIdleControls (WindowPtr inWindow)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
IdleControls( inWindow ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAIdleControls( inWindow ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
UpdateControls( inWindow , inRgn ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAUpdateControls( inWindow , inRgn ) ;
|
||||
}
|
||||
}
|
||||
|
||||
OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return GetRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// handling control data
|
||||
|
||||
OSErr UMASetControlData (ControlHandle inControl,
|
||||
ControlPartCode inPart,
|
||||
ResType inTagName,
|
||||
Size inSize,
|
||||
Ptr inData)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return SetControlData( inControl , inPart , inTagName , inSize , inData ) ;
|
||||
}
|
||||
else
|
||||
return AGASetControlData( inControl , inPart , inTagName , inSize , inData ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OSErr UMAGetControlData (ControlHandle inControl,
|
||||
ControlPartCode inPart,
|
||||
ResType inTagName,
|
||||
Size inBufferSize,
|
||||
Ptr outBuffer,
|
||||
Size * outActualSize)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return ::GetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
OSErr UMAGetControlDataSize (ControlHandle inControl,
|
||||
ControlPartCode inPart,
|
||||
ResType inTagName,
|
||||
Size * outMaxSize)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return GetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// system 8.0 changes
|
||||
|
||||
short UMAFindWindow( Point inPoint , WindowRef *outWindow )
|
||||
{
|
||||
// todo add the additional area codes
|
||||
return FindWindow( inPoint , outWindow ) ;
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowFeatures( WindowRef inWindowRef , UInt32 *outFeatures )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
return GetWindowFeatures( inWindowRef , outFeatures ) ;
|
||||
#else
|
||||
return 0 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowRegion( WindowRef inWindowRef , WindowRegionCode inRegionCode , RgnHandle ioWinRgn )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
return GetWindowRegion( inWindowRef , inRegionCode , ioWinRgn ) ;
|
||||
#else
|
||||
return 0 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMADrawGrowIcon( WindowRef inWindowRef )
|
||||
{
|
||||
DrawGrowIcon( inWindowRef ) ;
|
||||
}
|
||||
|
||||
OSStatus UMACollapseWindow( WindowRef inWindowRef , Boolean inCollapseIt )
|
||||
{
|
||||
return CollapseWindow( inWindowRef , inCollapseIt ) ;
|
||||
}
|
||||
|
||||
OSStatus UMACollapseAllWindows( Boolean inCollapseEm )
|
||||
{
|
||||
return CollapseAllWindows( inCollapseEm ) ;
|
||||
}
|
||||
|
||||
Boolean UMAIsWindowCollapsed( WindowRef inWindowRef )
|
||||
{
|
||||
return IsWindowCollapsed( inWindowRef ) ;
|
||||
}
|
||||
|
||||
Boolean UMAIsWindowCollapsable( WindowRef inWindowRef )
|
||||
{
|
||||
return IsWindowCollapsable( inWindowRef ) ;
|
||||
}
|
||||
|
||||
// system 8.5 changes<MacWindows.h>
|
||||
OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attributes , const Rect *bounds, WindowRef *outWindow )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return CreateNewWindow( windowClass , attributes, bounds, outWindow ) ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
short procID ;
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
switch( windowClass )
|
||||
{
|
||||
case kMovableModalWindowClass :
|
||||
procID = kWindowMovableModalDialogProc;
|
||||
break ;
|
||||
case kDocumentWindowClass :
|
||||
procID = kWindowFullZoomGrowDocumentProc;
|
||||
break ;
|
||||
default :
|
||||
procID = kWindowMovableModalDialogProc;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( windowClass )
|
||||
{
|
||||
case kMovableModalWindowClass :
|
||||
procID = movableDBoxProc;
|
||||
// procID += kMovableModalDialogVariantCode;
|
||||
break ;
|
||||
case kDocumentWindowClass :
|
||||
procID = zoomDocProc;
|
||||
break ;
|
||||
default :
|
||||
procID = documentProc;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
*outWindow = NewCWindow(nil, bounds, "\p", false, procID, (WindowRef) -1 /*behind*/,
|
||||
attributes & kWindowCloseBoxAttribute , (long)NULL);
|
||||
return noErr ;
|
||||
}
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowClass( WindowRef inWindowRef , WindowClass *outWindowClass )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return GetWindowClass( inWindowRef , outWindowClass ) ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return kDocumentWindowClass ;
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowAttributes( WindowRef inWindowRef , WindowAttributes *outAttributes )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return GetWindowAttributes( inWindowRef , outAttributes ) ;
|
||||
}
|
||||
#endif
|
||||
return kWindowNoAttributes ;
|
||||
}
|
||||
|
||||
void UMAShowFloatingWindows()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
ShowFloatingWindows() ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMAHideFloatingWindows()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
HideFloatingWindows() ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Boolean UMAAreFloatingWindowsVisible()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return AreFloatingWindowsVisible() ;
|
||||
}
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
WindowRef UMAFrontNonFloatingWindow()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return FrontNonFloatingWindow() ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return FrontWindow() ;
|
||||
}
|
||||
}
|
||||
|
||||
WindowRef UMAFrontWindow()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return FrontWindow() ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return FrontWindow() ;
|
||||
}
|
||||
}
|
||||
|
||||
WindowRef UMAGetActiveNonFloatingWindow()
|
||||
{
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
bool UMAIsWindowFloating( WindowRef inWindow )
|
||||
{
|
||||
WindowClass cl ;
|
||||
|
||||
UMAGetWindowClass( inWindow , &cl ) ;
|
||||
return cl == kFloatingWindowClass ;
|
||||
}
|
||||
|
||||
bool UMAIsWindowModal( WindowRef inWindow )
|
||||
{
|
||||
WindowClass cl ;
|
||||
|
||||
UMAGetWindowClass( inWindow , &cl ) ;
|
||||
return cl < kFloatingWindowClass ;
|
||||
}
|
||||
|
||||
// others
|
||||
|
||||
void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
|
||||
{
|
||||
if ( inWindowRef )
|
||||
{
|
||||
// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
|
||||
// if ( inActivate != isHightlited )
|
||||
HiliteWindow( inWindowRef , inActivate ) ;
|
||||
}
|
||||
}
|
||||
|
340
src/mac/dataobj.cpp
Normal file
340
src/mac/dataobj.cpp
Normal file
@@ -0,0 +1,340 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: os2/dataobj.cpp
|
||||
// Purpose: implementation of wx[I]DataObject class
|
||||
// Author: David Webster
|
||||
// Modified by:
|
||||
// Created: 10/21/99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1999 David Webster
|
||||
// Licence: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "dataobj.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#endif
|
||||
#include "wx/defs.h"
|
||||
|
||||
#include "wx/log.h"
|
||||
#include "wx/dataobj.h"
|
||||
#include "wx/mstream.h"
|
||||
#include "wx/image.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataFormat
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDataFormat::wxDataFormat()
|
||||
{
|
||||
m_vType = wxDF_INVALID;
|
||||
m_vFormat = 0;
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
wxDataFormatId vType
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetType(vType);
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
const wxChar* zId
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetId(zId);
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
const wxString& rId
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetId(rId);
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat(
|
||||
NativeFormat vFormat
|
||||
)
|
||||
{
|
||||
PrepareFormats();
|
||||
SetId(vFormat);
|
||||
}
|
||||
|
||||
void wxDataFormat::SetType(
|
||||
wxDataFormatId vType
|
||||
)
|
||||
{
|
||||
m_vType = vType;
|
||||
|
||||
if (m_vType == wxDF_TEXT)
|
||||
m_vFormat = 0;
|
||||
else
|
||||
if (m_vType == wxDF_BITMAP)
|
||||
m_vFormat = 0;
|
||||
else
|
||||
if (m_vType == wxDF_FILENAME)
|
||||
m_vFormat = 0;
|
||||
else
|
||||
{
|
||||
wxFAIL_MSG( wxT("invalid dataformat") );
|
||||
}
|
||||
}
|
||||
|
||||
wxDataFormatId wxDataFormat::GetType() const
|
||||
{
|
||||
return m_vType;
|
||||
}
|
||||
|
||||
wxString wxDataFormat::GetId() const
|
||||
{
|
||||
wxString sRet(""); // TODO: gdk_atom_name( m_format ) );
|
||||
return sRet;
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId(
|
||||
NativeFormat vFormat
|
||||
)
|
||||
{
|
||||
m_vFormat = vFormat;
|
||||
// TODO:
|
||||
/*
|
||||
if (m_format == g_textAtom)
|
||||
m_type = wxDF_TEXT;
|
||||
else
|
||||
if (m_format == g_pngAtom)
|
||||
m_type = wxDF_BITMAP;
|
||||
else
|
||||
if (m_format == g_fileAtom)
|
||||
m_type = wxDF_FILENAME;
|
||||
else
|
||||
m_type = wxDF_PRIVATE;
|
||||
*/
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId(
|
||||
const wxChar* zId
|
||||
)
|
||||
{
|
||||
wxString tmp(zId);
|
||||
|
||||
m_vType = wxDF_PRIVATE;
|
||||
m_vFormat = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
|
||||
}
|
||||
|
||||
void wxDataFormat::PrepareFormats()
|
||||
{
|
||||
// TODO:
|
||||
/*
|
||||
if (!g_textAtom)
|
||||
g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
||||
if (!g_pngAtom)
|
||||
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
|
||||
if (!g_fileAtom)
|
||||
g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
|
||||
*/
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// wxDataObject
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
wxDataObject::wxDataObject()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxDataObject::IsSupportedFormat(
|
||||
const wxDataFormat& rFormat
|
||||
, Direction vDir
|
||||
) const
|
||||
{
|
||||
size_t nFormatCount = GetFormatCount(vDir);
|
||||
|
||||
if (nFormatCount == 1)
|
||||
{
|
||||
return rFormat == GetPreferredFormat();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDataFormat* pFormats = new wxDataFormat[nFormatCount];
|
||||
GetAllFormats( pFormats
|
||||
,vDir
|
||||
);
|
||||
|
||||
size_t n;
|
||||
|
||||
for (n = 0; n < nFormatCount; n++)
|
||||
{
|
||||
if (pFormats[n] == rFormat)
|
||||
break;
|
||||
}
|
||||
|
||||
delete [] pFormats;
|
||||
|
||||
// found?
|
||||
return n < nFormatCount;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFileDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
{
|
||||
wxString sFilenames;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
{
|
||||
sFilenames += m_filenames[i];
|
||||
sFilenames += (wxChar)0;
|
||||
}
|
||||
|
||||
memcpy(pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
size_t wxFileDataObject::GetDataSize() const
|
||||
{
|
||||
size_t nRes = 0;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
{
|
||||
nRes += m_filenames[i].Len();
|
||||
nRes += 1;
|
||||
}
|
||||
|
||||
return nRes + 1;
|
||||
}
|
||||
|
||||
bool wxFileDataObject::SetData(
|
||||
size_t WXUNUSED(nSize)
|
||||
, const void* pBuf
|
||||
)
|
||||
{
|
||||
/* TODO */
|
||||
|
||||
wxString sFile( (const char *)pBuf); /* char, not wxChar */
|
||||
|
||||
AddFile(sFile);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxFileDataObject::AddFile(
|
||||
const wxString& rFilename
|
||||
)
|
||||
{
|
||||
m_filenames.Add(rFilename);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
: wxBitmapDataObjectBase(rBitmap)
|
||||
{
|
||||
Init();
|
||||
|
||||
DoConvertToPng();
|
||||
}
|
||||
|
||||
wxBitmapDataObject::~wxBitmapDataObject()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::SetBitmap(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
{
|
||||
ClearAll();
|
||||
wxBitmapDataObjectBase::SetBitmap(rBitmap);
|
||||
DoConvertToPng();
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
{
|
||||
if (!m_pngSize)
|
||||
{
|
||||
wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
|
||||
return FALSE;
|
||||
}
|
||||
memcpy(pBuf, m_pngData, m_pngSize);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::SetData(
|
||||
size_t nSize
|
||||
, const void* pBuf
|
||||
)
|
||||
{
|
||||
Clear();
|
||||
m_pngSize = nSize;
|
||||
m_pngData = malloc(m_pngSize);
|
||||
|
||||
memcpy(m_pngData, pBuf, m_pngSize);
|
||||
|
||||
wxMemoryInputStream vMstream((char*)m_pngData, m_pngSize);
|
||||
wxImage vImage;
|
||||
wxPNGHandler vHandler;
|
||||
|
||||
if (!vHandler.LoadFile(&vImage, vMstream))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_bitmap = vImage.ConvertToBitmap();
|
||||
return m_bitmap.Ok();
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::DoConvertToPng()
|
||||
{
|
||||
if (!m_bitmap.Ok())
|
||||
return;
|
||||
|
||||
wxImage vImage(m_bitmap);
|
||||
wxPNGHandler vHandler;
|
||||
wxCountingOutputStream vCount;
|
||||
|
||||
vHandler.SaveFile(&vImage, vCount);
|
||||
|
||||
m_pngSize = vCount.GetSize() + 100; // sometimes the size seems to vary ???
|
||||
m_pngData = malloc(m_pngSize);
|
||||
|
||||
wxMemoryOutputStream vMstream((char*) m_pngData, m_pngSize);
|
||||
|
||||
vHandler.SaveFile(&vImage, vMstream );
|
||||
}
|
||||
|
156
src/mac/dcprint.cpp
Normal file
156
src/mac/dcprint.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: dcprint.cpp
|
||||
// Purpose: wxPrinterDC class
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 01/02/97
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "dcprint.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/dcprint.h"
|
||||
#include "math.h"
|
||||
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_CLASS(wxPrinterDC, wxDC)
|
||||
#endif
|
||||
|
||||
GrafPtr macPrintFormerPort = NULL ;
|
||||
|
||||
wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
|
||||
{
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
m_printData = printdata ;
|
||||
m_printData.ConvertToNative() ;
|
||||
|
||||
::PrOpen() ;
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
PrClose() ;
|
||||
}
|
||||
|
||||
if ( ::PrValidate( m_printData.m_macPrintInfo ) )
|
||||
{
|
||||
// the driver has changed in the mean time, should we pop up a page setup dialog ?
|
||||
}
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
PrClose() ;
|
||||
}
|
||||
::GetPort( &macPrintFormerPort ) ;
|
||||
m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
|
||||
// sets current port
|
||||
m_macPort = (GrafPtr ) m_macPrintPort ;
|
||||
m_ok = TRUE ;
|
||||
m_minY = m_minX = 0 ;
|
||||
m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ;
|
||||
m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ;
|
||||
}
|
||||
|
||||
wxPrinterDC::~wxPrinterDC(void)
|
||||
{
|
||||
if ( m_ok )
|
||||
{
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
::PrCloseDoc( m_macPrintPort ) ;
|
||||
err = PrError() ;
|
||||
|
||||
if ( !err )
|
||||
{
|
||||
if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
|
||||
{
|
||||
TPrStatus status ;
|
||||
::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
PrClose() ;
|
||||
}
|
||||
::PrClose() ;
|
||||
::SetPort( macPrintFormerPort ) ;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
|
||||
{
|
||||
return m_ok ;
|
||||
}
|
||||
|
||||
void wxPrinterDC::EndDoc(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxPrinterDC::StartPage(void)
|
||||
{
|
||||
if ( !m_ok )
|
||||
return ;
|
||||
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
PrOpenPage( m_macPrintPort , NULL ) ;
|
||||
SetOrigin( - (**m_printData.m_macPrintInfo).rPaper.left , - (**m_printData.m_macPrintInfo).rPaper.top ) ;
|
||||
Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
|
||||
::ClipRect( &clip ) ;
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
::PrClosePage( m_macPrintPort) ;
|
||||
::PrCloseDoc( m_macPrintPort ) ;
|
||||
::PrClose() ;
|
||||
::SetPort( macPrintFormerPort ) ;
|
||||
m_ok = FALSE ;
|
||||
}
|
||||
}
|
||||
|
||||
void wxPrinterDC::EndPage(void)
|
||||
{
|
||||
if ( !m_ok )
|
||||
return ;
|
||||
|
||||
OSErr err ;
|
||||
wxString message ;
|
||||
|
||||
PrClosePage( (TPrPort*) m_macPort ) ;
|
||||
err = PrError() ;
|
||||
if ( err )
|
||||
{
|
||||
message.Printf( "Print Error %d", err ) ;
|
||||
wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
|
||||
::PrCloseDoc( m_macPrintPort ) ;
|
||||
::PrClose() ;
|
||||
::SetPort( macPrintFormerPort ) ;
|
||||
m_ok = FALSE ;
|
||||
}
|
||||
}
|
159
src/mac/fontutil.cpp
Normal file
159
src/mac/fontutil.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: msw/fontutil.cpp
|
||||
// Purpose: font-related helper functions for wxMSW
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 05.11.99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "fontutil.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/fontutil.h"
|
||||
#include "wx/fontmap.h"
|
||||
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNativeEncodingInfo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// convert to/from the string representation: format is
|
||||
// facename[;charset]
|
||||
|
||||
bool wxNativeEncodingInfo::FromString(const wxString& s)
|
||||
{
|
||||
wxStringTokenizer tokenizer(s, _T(";"));
|
||||
|
||||
facename = tokenizer.GetNextToken();
|
||||
if ( !facename )
|
||||
return FALSE;
|
||||
|
||||
wxString tmp = tokenizer.GetNextToken();
|
||||
if ( !tmp )
|
||||
{
|
||||
// default charset (don't use DEFAULT_CHARSET though because of subtle
|
||||
// Windows 9x/NT differences in handling it)
|
||||
charset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( wxSscanf(tmp, _T("%u"), &charset) != 1 )
|
||||
{
|
||||
// should be a number!
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxString wxNativeEncodingInfo::ToString() const
|
||||
{
|
||||
wxString s(facename);
|
||||
if ( charset != 0 )
|
||||
{
|
||||
s << _T(';') << charset;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxGetNativeFontEncoding(wxFontEncoding encoding,
|
||||
wxNativeEncodingInfo *info)
|
||||
{
|
||||
wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
|
||||
|
||||
if ( encoding == wxFONTENCODING_DEFAULT )
|
||||
{
|
||||
encoding = wxFont::GetDefaultEncoding();
|
||||
}
|
||||
|
||||
switch ( encoding )
|
||||
{
|
||||
// although this function is supposed to return an exact match, do do
|
||||
// some mappings here for the most common case of "standard" encoding
|
||||
case wxFONTENCODING_SYSTEM:
|
||||
case wxFONTENCODING_ISO8859_1:
|
||||
case wxFONTENCODING_ISO8859_15:
|
||||
case wxFONTENCODING_CP1252:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1250:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1251:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1253:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1254:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1255:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1256:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP1257:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
case wxFONTENCODING_CP437:
|
||||
info->charset = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
// no way to translate this encoding into a Windows charset
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
865
src/mac/pnghand.cpp
Normal file
865
src/mac/pnghand.cpp
Normal file
@@ -0,0 +1,865 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: pnghand.cpp
|
||||
// Purpose: Implements a PNG reader class + handler
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "pngread.h"
|
||||
#pragma implementation "pnghand.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if wxUSE_IOSTREAMH
|
||||
# include <fstream.h>
|
||||
#else
|
||||
# include <fstream>
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <wx/palette.h>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/mac/pnghand.h>
|
||||
#include <wx/mac/pngread.h>
|
||||
|
||||
extern "C" {
|
||||
#include "png.h"
|
||||
}
|
||||
|
||||
extern "C" void png_read_init PNGARG((png_structp png_ptr));
|
||||
extern "C" void png_write_init PNGARG((png_structp png_ptr));
|
||||
|
||||
extern CTabHandle wxMacCreateColorTable( int numColors ) ;
|
||||
extern void wxMacDestroyColorTable( CTabHandle colors ) ;
|
||||
extern void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
|
||||
extern GWorldPtr wxMacCreateGWorld( int height , int width , int depth ) ;
|
||||
extern void wxMacDestroyGWorld( GWorldPtr gw ) ;
|
||||
|
||||
void
|
||||
ima_png_error(png_struct *png_ptr, char *message)
|
||||
{
|
||||
wxMessageBox(message, "PNG error");
|
||||
longjmp(png_ptr->jmpbuf, 1);
|
||||
}
|
||||
|
||||
|
||||
// static wxGifReaderIter* iter;
|
||||
wxPalette *wxCopyPalette(const wxPalette *cmap);
|
||||
|
||||
wxPNGReader::wxPNGReader(void)
|
||||
{
|
||||
filetype = 0;
|
||||
RawImage = NULL; // Image data
|
||||
|
||||
Width = 0; Height = 0; // Dimensions
|
||||
Depth = 0; // (bits x pixel)
|
||||
ColorType = 0; // Bit 1 = Palette used
|
||||
// Bit 2 = Color used
|
||||
// Bit 3 = Alpha used
|
||||
|
||||
EfeWidth = 0; // Efective Width
|
||||
|
||||
lpbi = NULL;
|
||||
bgindex = -1;
|
||||
Palette = 0;
|
||||
imageOK = FALSE;
|
||||
}
|
||||
|
||||
wxPNGReader::wxPNGReader ( char* ImageFileName )
|
||||
{
|
||||
imageOK = FALSE;
|
||||
filetype = 0;
|
||||
RawImage = NULL; // Image data
|
||||
|
||||
Width = 0; Height = 0; // Dimensions
|
||||
Depth = 0; // (bits x pixel)
|
||||
ColorType = 0; // Bit 1 = Palette used
|
||||
// Bit 2 = Color used
|
||||
// Bit 3 = Alpha used
|
||||
|
||||
EfeWidth = 0; // Efective Width
|
||||
|
||||
lpbi = NULL;
|
||||
bgindex = -1;
|
||||
Palette = 0;
|
||||
|
||||
imageOK = ReadFile (ImageFileName);
|
||||
}
|
||||
|
||||
void
|
||||
wxPNGReader::Create(int width, int height, int depth, int colortype)
|
||||
{
|
||||
Width = width; Height = height; Depth = depth;
|
||||
ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0);
|
||||
|
||||
if (lpbi)
|
||||
{
|
||||
wxMacDestroyGWorld( lpbi ) ;
|
||||
// delete Palette;
|
||||
}
|
||||
RawImage = 0;
|
||||
Palette = 0;
|
||||
if (lpbi = wxMacCreateGWorld( Width , Height , Depth) )
|
||||
{
|
||||
EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4;
|
||||
int bitwidth = width ;
|
||||
if ( EfeWidth > bitwidth )
|
||||
bitwidth = EfeWidth ;
|
||||
|
||||
RawImage = (byte*) new char[ ( bitwidth * Height * ((Depth+7)>>3) ) ];
|
||||
imageOK = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
wxPNGReader::~wxPNGReader ( )
|
||||
{
|
||||
delete[] RawImage ;
|
||||
if (lpbi) {
|
||||
wxMacDestroyGWorld( lpbi ) ;
|
||||
}
|
||||
delete Palette;
|
||||
}
|
||||
|
||||
|
||||
int wxPNGReader::GetIndex(int x, int y)
|
||||
{
|
||||
if (!Inside(x, y) || (Depth>8)) return -1;
|
||||
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
int index = (int)(*ImagePointer);
|
||||
return index;
|
||||
}
|
||||
|
||||
bool wxPNGReader::GetRGB(int x, int y, byte* r, byte* g, byte* b)
|
||||
{
|
||||
if (!Inside(x, y)) return FALSE;
|
||||
|
||||
if (Palette) {
|
||||
return Palette->GetRGB(GetIndex(x, y), r, g, b);
|
||||
/* PALETTEENTRY entry;
|
||||
::GetPaletteEntries((HPALETTE) Palette->GetHPALETTE(), GetIndex(x, y), 1, &entry);
|
||||
*r = entry.peRed;
|
||||
*g = entry.peGreen;
|
||||
*b = entry.peBlue; */
|
||||
} else {
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
*b = ImagePointer[0];
|
||||
*g = ImagePointer[1];
|
||||
*r = ImagePointer[2];
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
bool wxPNGReader::SetIndex(int x, int y, int index)
|
||||
{
|
||||
if (!Inside(x, y) || (Depth>8)) return FALSE;
|
||||
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
*ImagePointer = index;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b)
|
||||
{
|
||||
if (!Inside(x, y)) return FALSE;
|
||||
|
||||
if (ColorType & COLORTYPE_PALETTE)
|
||||
{
|
||||
if (!Palette) return FALSE;
|
||||
SetIndex(x, y, Palette->GetPixel(r, g, b));
|
||||
|
||||
} else {
|
||||
ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
|
||||
ImagePointer[0] = b;
|
||||
ImagePointer[1] = g;
|
||||
ImagePointer[2] = r;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxPNGReader::SetPalette(wxPalette* colourmap)
|
||||
{
|
||||
if (!colourmap)
|
||||
return FALSE;
|
||||
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
|
||||
Palette = colourmap;
|
||||
return true ;
|
||||
// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
|
||||
}
|
||||
|
||||
bool
|
||||
wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b)
|
||||
{
|
||||
Palette = new wxPalette();
|
||||
if (!Palette)
|
||||
return FALSE;
|
||||
|
||||
if (!g) g = r;
|
||||
if (!b) b = g;
|
||||
Palette->Create(n, r, g, b);
|
||||
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
|
||||
return true ;
|
||||
// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
|
||||
}
|
||||
|
||||
bool
|
||||
wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct)
|
||||
{
|
||||
Palette = new wxPalette();
|
||||
if (!Palette)
|
||||
return FALSE;
|
||||
|
||||
byte r[256], g[256], b[256];
|
||||
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
r[i] = rgb_struct[i].red;
|
||||
g[i] = rgb_struct[i].green;
|
||||
b[i] = rgb_struct[i].blue;
|
||||
}
|
||||
// Added by JACS copying from Andrew Davison's additions
|
||||
// to GIF-reading code
|
||||
// Make transparency colour black...
|
||||
if (bgindex != -1)
|
||||
r[bgindex] = g[bgindex] = b[bgindex] = 0;
|
||||
|
||||
Palette->Create(n, r, g, b);
|
||||
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
|
||||
return true ;
|
||||
// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
|
||||
}
|
||||
|
||||
void wxPNGReader::NullData()
|
||||
{
|
||||
lpbi = NULL;
|
||||
Palette = NULL;
|
||||
}
|
||||
|
||||
wxBitmap* wxPNGReader::GetBitmap(void)
|
||||
{
|
||||
wxBitmap *bitmap = new wxBitmap;
|
||||
if ( InstantiateBitmap(bitmap) )
|
||||
return bitmap;
|
||||
else
|
||||
{
|
||||
delete bitmap;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap)
|
||||
{
|
||||
if ( lpbi )
|
||||
{
|
||||
bitmap->SetHBITMAP((WXHBITMAP) lpbi);
|
||||
bitmap->SetWidth(GetWidth());
|
||||
bitmap->SetHeight(GetHeight());
|
||||
bitmap->SetDepth(GetDepth());
|
||||
if ( GetDepth() > 1 && Palette )
|
||||
bitmap->SetPalette(*Palette);
|
||||
bitmap->SetOk(TRUE);
|
||||
|
||||
|
||||
// Make a mask if appropriate
|
||||
/*
|
||||
if ( bgindex > -1 )
|
||||
{
|
||||
wxMask *mask = CreateMask();
|
||||
bitmap->SetMask(mask);
|
||||
}
|
||||
*/
|
||||
lpbi = NULL ; // bitmap has taken over ownership
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
/*
|
||||
HDC dc = ::CreateCompatibleDC(NULL);
|
||||
|
||||
if (dc)
|
||||
{
|
||||
// tmpBitmap is a dummy, to satisfy ::CreateCompatibleDC (it
|
||||
// is a memory dc that must have a bitmap selected into it)
|
||||
HDC dc2 = GetDC(NULL);
|
||||
HBITMAP tmpBitmap = ::CreateCompatibleBitmap(dc2, GetWidth(), GetHeight());
|
||||
ReleaseDC(NULL, dc2);
|
||||
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, tmpBitmap);
|
||||
|
||||
if ( Palette )
|
||||
{
|
||||
HPALETTE oldPal = ::SelectPalette(dc, (HPALETTE) Palette->GetHPALETTE(), FALSE);
|
||||
::RealizePalette(dc);
|
||||
}
|
||||
|
||||
HBITMAP hBitmap = ::CreateDIBitmap(dc, lpbi,
|
||||
CBM_INIT, RawImage, (LPBITMAPINFO) lpbi, DIB_PAL_COLORS);
|
||||
|
||||
::SelectPalette(dc, NULL, TRUE);
|
||||
::SelectObject(dc, oldBitmap);
|
||||
::DeleteObject(tmpBitmap);
|
||||
::DeleteDC(dc);
|
||||
|
||||
if ( hBitmap )
|
||||
{
|
||||
bitmap->SetHBITMAP((WXHBITMAP) hBitmap);
|
||||
bitmap->SetWidth(GetWidth());
|
||||
bitmap->SetHeight(GetHeight());
|
||||
bitmap->SetDepth(GetDepth());
|
||||
if ( GetDepth() > 1 && Palette )
|
||||
bitmap->SetPalette(*Palette);
|
||||
bitmap->SetOk(TRUE);
|
||||
|
||||
|
||||
// Make a mask if appropriate
|
||||
if ( bgindex > -1 )
|
||||
{
|
||||
wxMask *mask = CreateMask();
|
||||
bitmap->SetMask(mask);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
*/
|
||||
return false ;
|
||||
}
|
||||
|
||||
wxPalette *wxCopyPalette(const wxPalette *cmap)
|
||||
{
|
||||
wxPalette *newCmap = new wxPalette( *cmap ) ;
|
||||
return newCmap;
|
||||
}
|
||||
|
||||
wxMask *wxPNGReader::CreateMask(void)
|
||||
{
|
||||
/*
|
||||
HBITMAP hBitmap = ::CreateBitmap(GetWidth(), GetHeight(), 1, 1, NULL);
|
||||
|
||||
HDC dc = ::CreateCompatibleDC(NULL);
|
||||
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, hBitmap);
|
||||
|
||||
int bgIndex = GetBGIndex();
|
||||
|
||||
int x,y;
|
||||
|
||||
for (x=0; x<GetWidth(); x++)
|
||||
{
|
||||
for (y=0; y<GetHeight(); y++)
|
||||
{
|
||||
int index = GetIndex(x, y);
|
||||
if ( index == bgIndex )
|
||||
::SetPixel(dc, x, GetHeight() - y - 1, RGB(0, 0, 0));
|
||||
else
|
||||
::SetPixel(dc, x, GetHeight() - y - 1, RGB(255, 255, 255));
|
||||
|
||||
}
|
||||
}
|
||||
::SelectObject(dc, oldBitmap);
|
||||
wxMask *mask = new wxMask;
|
||||
mask->SetMaskBitmap((WXHBITMAP) hBitmap);
|
||||
return mask;
|
||||
*/
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
bool wxPNGReader::ReadFile(char * ImageFileName)
|
||||
{
|
||||
int number_passes;
|
||||
|
||||
if (ImageFileName)
|
||||
strcpy(filename, ImageFileName);
|
||||
|
||||
FILE *fp;
|
||||
png_struct *png_ptr;
|
||||
png_info *info_ptr;
|
||||
wxPNGReaderIter iter(this);
|
||||
|
||||
/* open the file */
|
||||
fp = fopen(wxUnix2MacFilename( ImageFileName ), "rb");
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
|
||||
/* allocate the necessary structures */
|
||||
png_ptr = new (png_struct);
|
||||
if (!png_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
info_ptr = new (png_info);
|
||||
if (!info_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
return FALSE;
|
||||
}
|
||||
/* set error handling */
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* If we get here, we had a problem reading the file */
|
||||
return FALSE;
|
||||
}
|
||||
//png_set_error(ima_png_error, NULL);
|
||||
|
||||
/* initialize the structures, info first for error handling */
|
||||
png_info_init(info_ptr);
|
||||
png_read_init(png_ptr);
|
||||
|
||||
/* set up the input control */
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
/* read the file information */
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
/* allocate the memory to hold the image using the fields
|
||||
of png_info. */
|
||||
png_color_16 my_background={ 0, 31, 127, 255, 0 };
|
||||
|
||||
if (info_ptr->valid & PNG_INFO_bKGD)
|
||||
{
|
||||
png_set_background(png_ptr, &(info_ptr->background),
|
||||
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||
if ( info_ptr->num_palette > 0 )
|
||||
bgindex = info_ptr->background.index;
|
||||
}
|
||||
else {
|
||||
png_set_background(png_ptr, &my_background,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
||||
|
||||
// Added by JACS: guesswork!
|
||||
if ( info_ptr->num_trans != 0 )
|
||||
bgindex = info_ptr->num_trans - 1 ;
|
||||
}
|
||||
|
||||
/* tell libpng to strip 16 bit depth files down to 8 bits */
|
||||
if (info_ptr->bit_depth == 16)
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
int pixel_depth=(info_ptr->pixel_depth<24) ? info_ptr->pixel_depth: 24;
|
||||
Create(info_ptr->width, info_ptr->height, pixel_depth,
|
||||
info_ptr->color_type);
|
||||
|
||||
if (info_ptr->num_palette>0)
|
||||
{
|
||||
SetPalette((int)info_ptr->num_palette, (rgb_color_struct*)info_ptr->palette);
|
||||
}
|
||||
|
||||
int row_stride = info_ptr->width * ((pixel_depth+7)>>3);
|
||||
// printf("P = %d D = %d RS= %d ", info_ptr->num_palette, info_ptr->pixel_depth,row_stride);
|
||||
// printf("CT = %d TRS = %d BD= %d ", info_ptr->color_type, info_ptr->valid & PNG_INFO_tRNS,info_ptr->bit_depth);
|
||||
|
||||
byte *row_pointers = new byte[row_stride];
|
||||
|
||||
/* turn on interlace handling */
|
||||
if (info_ptr->interlace_type)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
else
|
||||
number_passes = 1;
|
||||
// printf("NP = %d ", number_passes);
|
||||
|
||||
for (int pass=0; pass< number_passes; pass++)
|
||||
{
|
||||
iter.upset();
|
||||
int y=0;
|
||||
CGrafPtr origPort ;
|
||||
GDHandle origDevice ;
|
||||
|
||||
GetGWorld( &origPort , &origDevice ) ;
|
||||
// ignore shapedc
|
||||
SetGWorld( lpbi , NULL ) ;
|
||||
do
|
||||
{
|
||||
// (unsigned char *)iter.GetRow();
|
||||
if (info_ptr->interlace_type)
|
||||
{
|
||||
if (pass>0)
|
||||
iter.GetRow(row_pointers, row_stride);
|
||||
png_read_row(png_ptr, row_pointers, NULL);
|
||||
}
|
||||
else
|
||||
png_read_row(png_ptr, row_pointers, NULL);
|
||||
|
||||
if ( info_ptr->palette )
|
||||
{
|
||||
if ( pixel_depth == 8 )
|
||||
{
|
||||
png_color_struct* color ;
|
||||
RGBColor col ;
|
||||
unsigned char* p = &row_pointers[0] ;
|
||||
MoveTo( 0 , y ) ;
|
||||
unsigned char lastcol = *p ;
|
||||
color = &info_ptr->palette[lastcol] ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
RGBForeColor( &col ) ;
|
||||
for ( int i = 0 ; i < info_ptr->width ; ++i , ++p)
|
||||
{
|
||||
if ( *p != lastcol )
|
||||
{
|
||||
LineTo( i , y ) ;
|
||||
lastcol = *p ;
|
||||
color = &info_ptr->palette[lastcol] ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
RGBForeColor( &col ) ;
|
||||
}
|
||||
}
|
||||
LineTo( info_ptr->width - 1 , y ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0 ; i < info_ptr->width ; ++i )
|
||||
{
|
||||
png_color_struct* color ;
|
||||
RGBColor col ;
|
||||
|
||||
int byte = ( i * pixel_depth ) / 8 ;
|
||||
int offset = ( 8 - pixel_depth ) - ( i * pixel_depth ) % 8 ;
|
||||
|
||||
int index = ( row_pointers[byte] >> offset ) & ( 0xFF >> ( 8 - pixel_depth ) );
|
||||
color = &info_ptr->palette[index] ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
SetCPixel( i, y, &col);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0 ; i < info_ptr->width ; ++i )
|
||||
{
|
||||
png_color_struct* color ;
|
||||
RGBColor col ;
|
||||
color =(png_color_struct*) (&row_pointers[i*3]) ;
|
||||
col.red = (color->red << 8) | color->red ;
|
||||
col.green = (color->green << 8) | color->green ;
|
||||
col.blue = (color->blue << 8) | color->blue ;
|
||||
SetCPixel( i, y, &col);
|
||||
}
|
||||
}
|
||||
if (number_passes)
|
||||
iter.SetRow(row_pointers, row_stride);
|
||||
y++;
|
||||
}
|
||||
while(iter.PrevRow());
|
||||
SetGWorld( origPort , origDevice ) ;
|
||||
|
||||
// printf("Y=%d ",y);
|
||||
}
|
||||
delete[] row_pointers;
|
||||
|
||||
/* read the rest of the file, getting any additional chunks
|
||||
in info_ptr */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the read, and free any memory allocated */
|
||||
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
|
||||
|
||||
/* free the structures */
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* close the file */
|
||||
fclose(fp);
|
||||
|
||||
/* that's it */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* write a png file */
|
||||
|
||||
bool wxPNGReader::SaveFile(char * ImageFileName)
|
||||
{
|
||||
if (ImageFileName)
|
||||
strcpy(filename, ImageFileName);
|
||||
|
||||
wxPNGReaderIter iter(this);
|
||||
FILE *fp;
|
||||
png_struct *png_ptr;
|
||||
png_info *info_ptr;
|
||||
|
||||
/* open the file */
|
||||
fp = fopen(filename, "wb");
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
|
||||
/* allocate the necessary structures */
|
||||
png_ptr = new (png_struct);
|
||||
if (!png_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
info_ptr = new (png_info);
|
||||
if (!info_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set error handling */
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
png_write_destroy(png_ptr);
|
||||
fclose(fp);
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* If we get here, we had a problem reading the file */
|
||||
return FALSE;
|
||||
}
|
||||
//png_set_error(ima_png_error, NULL);
|
||||
|
||||
// printf("writig pg %s ", filename);
|
||||
/* initialize the structures */
|
||||
png_info_init(info_ptr);
|
||||
png_write_init(png_ptr);
|
||||
|
||||
int row_stride = GetWidth() * ((GetDepth()+7)>>3);
|
||||
/* set up the output control */
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
/* set the file information here */
|
||||
info_ptr->width = GetWidth();
|
||||
info_ptr->height = GetHeight();
|
||||
info_ptr->pixel_depth = GetDepth();
|
||||
info_ptr->channels = (GetDepth()>8) ? 3: 1;
|
||||
info_ptr->bit_depth = GetDepth()/info_ptr->channels;
|
||||
info_ptr->color_type = GetColorType();
|
||||
info_ptr->compression_type = info_ptr->filter_type = info_ptr->interlace_type=0;
|
||||
info_ptr->valid = 0;
|
||||
info_ptr->rowbytes = row_stride;
|
||||
|
||||
|
||||
// printf("P = %d D = %d RS= %d GD= %d CH= %d ", info_ptr->pixel_depth, info_ptr->bit_depth, row_stride, GetDepth(), info_ptr->channels);
|
||||
/* set the palette if there is one */
|
||||
if ((GetColorType() & COLORTYPE_PALETTE) && GetPalette())
|
||||
{
|
||||
// printf("writing paleta[%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
|
||||
info_ptr->valid |= PNG_INFO_PLTE;
|
||||
info_ptr->palette = new png_color[256];
|
||||
info_ptr->num_palette = 256;
|
||||
for (int i=0; i<256; i++)
|
||||
GetPalette()->GetRGB(i, &info_ptr->palette[i].red, &info_ptr->palette[i].green, &info_ptr->palette[i].blue);
|
||||
}
|
||||
// printf("Paleta [%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
|
||||
|
||||
|
||||
/* optional significant bit chunk */
|
||||
// info_ptr->valid |= PNG_INFO_sBIT;
|
||||
// info_ptr->sig_bit = true_bit_depth;
|
||||
|
||||
/* optional gamma chunk */
|
||||
// info_ptr->valid |= PNG_INFO_gAMA;
|
||||
// info_ptr->gamma = gamma;
|
||||
|
||||
/* other optional chunks */
|
||||
|
||||
/* write the file information */
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
/* set up the transformations you want. Note that these are
|
||||
all optional. Only call them if you want them */
|
||||
|
||||
/* shift the pixels up to a legal bit depth and fill in
|
||||
as appropriate to correctly scale the image */
|
||||
// png_set_shift(png_ptr, &(info_ptr->sig_bit));
|
||||
|
||||
/* pack pixels into bytes */
|
||||
// png_set_packing(png_ptr);
|
||||
|
||||
/* flip bgr pixels to rgb */
|
||||
// png_set_bgr(png_ptr);
|
||||
|
||||
/* swap bytes of 16 bit files to most significant bit first */
|
||||
// png_set_swap(png_ptr);
|
||||
|
||||
/* get rid of filler bytes, pack rgb into 3 bytes */
|
||||
// png_set_rgbx(png_ptr);
|
||||
|
||||
/* If you are only writing one row at a time, this works */
|
||||
|
||||
byte *row_pointers = new byte[row_stride];
|
||||
iter.upset();
|
||||
do {
|
||||
// (unsigned char *)iter.GetRow();
|
||||
iter.GetRow(row_pointers, row_stride);
|
||||
png_write_row(png_ptr, row_pointers);
|
||||
} while(iter.PrevRow());
|
||||
|
||||
delete[] row_pointers;
|
||||
|
||||
/* write the rest of the file */
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
png_write_destroy(png_ptr);
|
||||
|
||||
/* if you malloced the palette, free it here */
|
||||
if (info_ptr->palette)
|
||||
delete[] (info_ptr->palette);
|
||||
|
||||
/* free the structures */
|
||||
delete(png_ptr);
|
||||
delete(info_ptr);
|
||||
|
||||
/* close the file */
|
||||
fclose(fp);
|
||||
|
||||
/* that's it */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int Power(int x, int y)
|
||||
{
|
||||
int z = 1;
|
||||
int i;
|
||||
for ( i = 0; i < y; i++)
|
||||
{
|
||||
z *= x;
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F' };
|
||||
|
||||
static void DecToHex(int dec, char *buf)
|
||||
{
|
||||
int firstDigit = (int)(dec/16.0);
|
||||
int secondDigit = (int)(dec - (firstDigit*16.0));
|
||||
buf[0] = hexArray[firstDigit];
|
||||
buf[1] = hexArray[secondDigit];
|
||||
buf[2] = 0;
|
||||
}
|
||||
|
||||
|
||||
bool wxPNGReader::SaveXPM(char *filename, char *name)
|
||||
{
|
||||
char nameStr[256];
|
||||
if ( name )
|
||||
strcpy(nameStr, name);
|
||||
else
|
||||
{
|
||||
strcpy(nameStr, filename);
|
||||
wxStripExtension(nameStr);
|
||||
}
|
||||
|
||||
if ( GetDepth() > 4 )
|
||||
{
|
||||
// Only a depth of 4 and below allowed
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( !GetPalette() )
|
||||
return FALSE;
|
||||
|
||||
ofstream str(filename);
|
||||
if ( str.bad() )
|
||||
return FALSE;
|
||||
|
||||
int noColours = Power(2, GetDepth());
|
||||
|
||||
// Output header
|
||||
str << "/* XPM */\n";
|
||||
str << "static char * " << nameStr << "_xpm[] = {\n";
|
||||
str << "\"" << GetWidth() << " " << GetHeight() << " " << noColours << " 1\",\n";
|
||||
|
||||
// Output colourmap
|
||||
int base = 97 ; // start from 'a'
|
||||
|
||||
unsigned char red, green, blue;
|
||||
char hexBuf[4];
|
||||
int i;
|
||||
for ( i = 0; i < noColours; i ++)
|
||||
{
|
||||
str << "\"" << (char)(base + i) << " c #";
|
||||
GetPalette()->GetRGB(i, &red, &green, &blue);
|
||||
DecToHex(red, hexBuf);
|
||||
str << hexBuf;
|
||||
DecToHex(green, hexBuf);
|
||||
str << hexBuf;
|
||||
DecToHex(blue, hexBuf);
|
||||
str << hexBuf;
|
||||
str << "\",\n";
|
||||
}
|
||||
|
||||
// Output the data
|
||||
int x, y;
|
||||
for ( y = 0; y < GetHeight(); y++)
|
||||
{
|
||||
str << "\"";
|
||||
for ( x = 0; x < GetWidth(); x++)
|
||||
{
|
||||
int index = GetIndex(x, y);
|
||||
str << (char)(base + index) ;
|
||||
}
|
||||
str << "\",\n";
|
||||
}
|
||||
|
||||
str << "};\n";
|
||||
str.flush();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPNGFileHandler, wxBitmapHandler)
|
||||
|
||||
bool wxPNGFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
|
||||
int desiredWidth, int desiredHeight)
|
||||
{
|
||||
wxPNGReader reader;
|
||||
if (reader.ReadFile((char*) (const char*) name))
|
||||
{
|
||||
return reader.InstantiateBitmap(bitmap);
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxPNGFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *pal)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
329
src/mac/printmac.cpp
Normal file
329
src/mac/printmac.cpp
Normal file
@@ -0,0 +1,329 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: printwin.cpp
|
||||
// Purpose: wxMacPrinter framework
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "printwin.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/utils.h"
|
||||
#include "wx/dc.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/msgdlg.h"
|
||||
#endif
|
||||
|
||||
#include "wx/mac/printmac.h"
|
||||
#include "wx/dcprint.h"
|
||||
#include "wx/printdlg.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
|
||||
IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Printer
|
||||
*/
|
||||
|
||||
wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
|
||||
wxPrinterBase(data)
|
||||
{
|
||||
}
|
||||
|
||||
wxMacPrinter::~wxMacPrinter(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
|
||||
{
|
||||
sm_abortIt = FALSE;
|
||||
sm_abortWindow = NULL;
|
||||
|
||||
if (!printout)
|
||||
return FALSE;
|
||||
|
||||
printout->SetIsPreview(FALSE);
|
||||
printout->OnPreparePrinting();
|
||||
|
||||
// Get some parameters from the printout, if defined
|
||||
int fromPage, toPage;
|
||||
int minPage, maxPage;
|
||||
printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
|
||||
|
||||
if (maxPage == 0)
|
||||
return FALSE;
|
||||
|
||||
m_printDialogData.SetMinPage(minPage);
|
||||
m_printDialogData.SetMaxPage(maxPage);
|
||||
if (fromPage != 0)
|
||||
m_printDialogData.SetFromPage(fromPage);
|
||||
if (toPage != 0)
|
||||
m_printDialogData.SetToPage(toPage);
|
||||
|
||||
if (minPage != 0)
|
||||
{
|
||||
m_printDialogData.EnablePageNumbers(TRUE);
|
||||
if (m_printDialogData.GetFromPage() < m_printDialogData.GetMinPage())
|
||||
m_printDialogData.SetFromPage(m_printDialogData.GetMinPage());
|
||||
else if (m_printDialogData.GetFromPage() > m_printDialogData.GetMaxPage())
|
||||
m_printDialogData.SetFromPage(m_printDialogData.GetMaxPage());
|
||||
if (m_printDialogData.GetToPage() > m_printDialogData.GetMaxPage())
|
||||
m_printDialogData.SetToPage(m_printDialogData.GetMaxPage());
|
||||
else if (m_printDialogData.GetToPage() < m_printDialogData.GetMinPage())
|
||||
m_printDialogData.SetToPage(m_printDialogData.GetMinPage());
|
||||
}
|
||||
else
|
||||
m_printDialogData.EnablePageNumbers(FALSE);
|
||||
|
||||
// Create a suitable device context
|
||||
// Create a suitable device context
|
||||
wxDC *dc = NULL;
|
||||
if (prompt)
|
||||
{
|
||||
PrOpen() ;
|
||||
m_printDialogData.ConvertToNative() ; // make sure we have a valid handle
|
||||
if ( m_printDialogData.m_macPrintInfo )
|
||||
{
|
||||
// todo incorporate the changes from a global page setup
|
||||
if ( ::PrStlDialog( m_printDialogData.m_macPrintInfo ) ) // we should have the page setup dialog
|
||||
{
|
||||
PrClose() ;
|
||||
wxPrintDialog dialog(parent, & m_printDialogData);
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
dc = dialog.GetPrintDC();
|
||||
m_printDialogData = dialog.GetPrintData();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrClose() ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
|
||||
}
|
||||
|
||||
|
||||
// May have pressed cancel.
|
||||
if (!dc || !dc->Ok())
|
||||
{
|
||||
if (dc) delete dc;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// on the mac we have always pixels as addressing mode with 72 dpi
|
||||
|
||||
printout->SetPPIScreen(72, 72);
|
||||
printout->SetPPIPrinter(72, 72);
|
||||
|
||||
// Set printout parameters
|
||||
printout->SetDC(dc);
|
||||
|
||||
int w, h;
|
||||
long ww, hh;
|
||||
dc->GetSize(&w, &h);
|
||||
printout->SetPageSizePixels((int)w, (int)h);
|
||||
dc->GetSizeMM(&ww, &hh);
|
||||
printout->SetPageSizeMM((int)ww, (int)hh);
|
||||
|
||||
// Create an abort window
|
||||
wxBeginBusyCursor();
|
||||
|
||||
/*
|
||||
wxWindow *win = CreateAbortWindow(parent, printout);
|
||||
wxYield();
|
||||
|
||||
if (!win)
|
||||
{
|
||||
wxEndBusyCursor();
|
||||
wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent);
|
||||
delete dc;
|
||||
}
|
||||
sm_abortWindow = win;
|
||||
sm_abortWindow->Show(TRUE);
|
||||
wxYield();
|
||||
*/
|
||||
|
||||
printout->OnBeginPrinting();
|
||||
|
||||
bool keepGoing = TRUE;
|
||||
|
||||
int copyCount;
|
||||
for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
|
||||
{
|
||||
if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
|
||||
{
|
||||
wxEndBusyCursor();
|
||||
wxMessageBox("Could not start printing.", "Print Error", wxOK, parent);
|
||||
break;
|
||||
}
|
||||
if (sm_abortIt)
|
||||
break;
|
||||
|
||||
int pn;
|
||||
for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
|
||||
pn++)
|
||||
{
|
||||
if (sm_abortIt)
|
||||
{
|
||||
keepGoing = FALSE;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
dc->StartPage();
|
||||
keepGoing = printout->OnPrintPage(pn);
|
||||
dc->EndPage();
|
||||
}
|
||||
}
|
||||
printout->OnEndDocument();
|
||||
}
|
||||
|
||||
printout->OnEndPrinting();
|
||||
|
||||
if (sm_abortWindow)
|
||||
{
|
||||
sm_abortWindow->Show(FALSE);
|
||||
delete sm_abortWindow;
|
||||
sm_abortWindow = NULL;
|
||||
}
|
||||
|
||||
wxEndBusyCursor();
|
||||
|
||||
delete dc;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
|
||||
{
|
||||
wxDC* dc = (wxDC*) NULL;
|
||||
|
||||
wxPrintDialog dialog(parent, & m_printDialogData);
|
||||
int ret = dialog.ShowModal();
|
||||
|
||||
if (ret == wxID_OK)
|
||||
{
|
||||
dc = dialog.GetPrintDC();
|
||||
m_printDialogData = dialog.GetPrintDialogData();
|
||||
}
|
||||
|
||||
return dc;
|
||||
}
|
||||
|
||||
bool wxMacPrinter::Setup(wxWindow *parent)
|
||||
{
|
||||
wxPrintDialog dialog(parent, & m_printDialogData);
|
||||
dialog.GetPrintDialogData().SetSetupDialog(TRUE);
|
||||
|
||||
int ret = dialog.ShowModal();
|
||||
|
||||
if (ret == wxID_OK)
|
||||
{
|
||||
m_printDialogData = dialog.GetPrintDialogData();
|
||||
}
|
||||
|
||||
return (ret == wxID_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print preview
|
||||
*/
|
||||
|
||||
wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
|
||||
wxPrintout *printoutForPrinting,
|
||||
wxPrintDialogData *data)
|
||||
: wxPrintPreviewBase(printout, printoutForPrinting, data)
|
||||
{
|
||||
DetermineScaling();
|
||||
}
|
||||
|
||||
wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
|
||||
wxPrintPreviewBase(printout, printoutForPrinting, data)
|
||||
{
|
||||
DetermineScaling();
|
||||
}
|
||||
|
||||
wxMacPrintPreview::~wxMacPrintPreview(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxMacPrintPreview::Print(bool interactive)
|
||||
{
|
||||
if (!m_printPrintout)
|
||||
return FALSE;
|
||||
wxMacPrinter printer(&m_printDialogData);
|
||||
return printer.Print(m_previewFrame, m_printPrintout, interactive);
|
||||
}
|
||||
|
||||
void wxMacPrintPreview::DetermineScaling(void)
|
||||
{
|
||||
/*
|
||||
HDC dc = ::GetDC(NULL);
|
||||
int screenWidth = ::GetDeviceCaps(dc, HORZSIZE);
|
||||
// int screenHeight = ::GetDeviceCaps(dc, VERTSIZE);
|
||||
int screenXRes = ::GetDeviceCaps(dc, HORZRES);
|
||||
// int screenYRes = ::GetDeviceCaps(dc, VERTRES);
|
||||
int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX);
|
||||
int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY);
|
||||
m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
|
||||
|
||||
::ReleaseDC(NULL, dc);
|
||||
|
||||
// Get a device context for the currently selected printer
|
||||
wxPrinterDC printerDC("", "", "", FALSE, m_printDialogData.GetOrientation());
|
||||
|
||||
int printerWidth = 150;
|
||||
int printerHeight = 250;
|
||||
int printerXRes = 1500;
|
||||
int printerYRes = 2500;
|
||||
|
||||
if (printerDC.GetHDC())
|
||||
{
|
||||
printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE);
|
||||
printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE);
|
||||
printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES);
|
||||
printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES);
|
||||
|
||||
int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX);
|
||||
int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY);
|
||||
|
||||
m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
|
||||
m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight);
|
||||
|
||||
if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0)
|
||||
m_isOk = FALSE;
|
||||
}
|
||||
else
|
||||
m_isOk = FALSE;
|
||||
|
||||
m_pageWidth = printerXRes;
|
||||
m_pageHeight = printerYRes;
|
||||
|
||||
// At 100%, the page should look about page-size on the screen.
|
||||
m_previewScale = (float)((float)screenWidth/(float)printerWidth);
|
||||
m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerYRes);
|
||||
*/
|
||||
}
|
61
src/mac/statline.cpp
Normal file
61
src/mac/statline.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: generic/statline.cpp
|
||||
// Purpose: a generic wxStaticLine class
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 28.06.99
|
||||
// Version: $Id$
|
||||
// Copyright: (c) 1998 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "statline.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/statline.h"
|
||||
#include "wx/statbox.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxStaticLine, wxControl)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStaticLine
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxStaticLine::Create( wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint &pos,
|
||||
const wxSize &size,
|
||||
long style,
|
||||
const wxString &name)
|
||||
{
|
||||
if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
|
||||
return FALSE;
|
||||
|
||||
// ok, this is ugly but it's better than nothing: use a thin static box to
|
||||
// emulate static line
|
||||
|
||||
wxSize sizeReal = AdjustSize(size);
|
||||
|
||||
// m_statbox = new wxStaticBox(parent, id, wxT(""), pos, sizeReal, style, name);
|
||||
|
||||
return TRUE;
|
||||
}
|
858
src/mac/uma.cpp
Normal file
858
src/mac/uma.cpp
Normal file
@@ -0,0 +1,858 @@
|
||||
#include <wx/mac/uma.h>
|
||||
#include <wx/mac/aga.h>
|
||||
|
||||
// init
|
||||
|
||||
static bool sUMAHasAppearance = false ;
|
||||
static long sUMAAppearanceVersion = 0 ;
|
||||
extern int gAGABackgroundColor ;
|
||||
bool UMAHasAppearance() { return sUMAHasAppearance ; }
|
||||
long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
|
||||
|
||||
static bool sUMAHasWindowManager = false ;
|
||||
static long sUMAWindowManagerAttr = 0 ;
|
||||
|
||||
bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
|
||||
long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
|
||||
|
||||
void UMAInitToolbox( UInt16 inMoreMastersCalls )
|
||||
{
|
||||
#if !TARGET_CARBON
|
||||
::MaxApplZone();
|
||||
for (long i = 1; i <= inMoreMastersCalls; i++)
|
||||
::MoreMasters();
|
||||
|
||||
::InitGraf(&qd.thePort);
|
||||
::InitFonts();
|
||||
::InitWindows();
|
||||
::InitMenus();
|
||||
::TEInit();
|
||||
::InitDialogs(0L);
|
||||
::FlushEvents(everyEvent, 0);
|
||||
::InitCursor();
|
||||
long total,contig;
|
||||
PurgeSpace(&total, &contig);
|
||||
#else
|
||||
InitMenus() ;
|
||||
#endif
|
||||
|
||||
#if UMA_USE_APPEARANCE
|
||||
long theAppearance ;
|
||||
if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
|
||||
{
|
||||
sUMAHasAppearance = true ;
|
||||
RegisterAppearanceClient();
|
||||
if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
|
||||
{
|
||||
sUMAAppearanceVersion = theAppearance ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sUMAAppearanceVersion = 0x0100 ;
|
||||
}
|
||||
}
|
||||
#endif // UMA_USE_APPEARANCE
|
||||
#if UMA_USE_8_6
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr )
|
||||
{
|
||||
sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ;
|
||||
}
|
||||
#endif // UMA_USE_WINDOWMGR
|
||||
#endif
|
||||
}
|
||||
|
||||
// process manager
|
||||
long UMAGetProcessMode()
|
||||
{
|
||||
OSErr err ;
|
||||
ProcessInfoRec processinfo;
|
||||
ProcessSerialNumber procno ;
|
||||
|
||||
procno.highLongOfPSN = NULL ;
|
||||
procno.lowLongOfPSN = kCurrentProcess ;
|
||||
processinfo.processInfoLength = sizeof(ProcessInfoRec);
|
||||
processinfo.processName = NULL;
|
||||
processinfo.processAppSpec = NULL;
|
||||
|
||||
err = ::GetProcessInformation( &procno , &processinfo ) ;
|
||||
wxASSERT( err == noErr ) ;
|
||||
return processinfo.processMode ;
|
||||
}
|
||||
|
||||
bool UMAGetProcessModeDoesActivateOnFGSwitch()
|
||||
{
|
||||
return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
|
||||
}
|
||||
|
||||
// menu manager
|
||||
|
||||
void UMASetMenuTitle( MenuRef menu , ConstStr255Param title )
|
||||
{
|
||||
#if !TARGET_CARBON
|
||||
long size = GetHandleSize( (Handle) menu ) ;
|
||||
const long headersize = 14 ;
|
||||
int oldlen = (**menu).menuData[0] + 1;
|
||||
int newlen = title[0] + 1 ;
|
||||
|
||||
if ( oldlen < newlen )
|
||||
{
|
||||
// enlarge before adjusting
|
||||
SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
|
||||
}
|
||||
|
||||
if ( oldlen != newlen )
|
||||
memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
|
||||
|
||||
memcpy( (char*) (**menu).menuData , title , newlen ) ;
|
||||
if ( oldlen > newlen )
|
||||
{
|
||||
// shrink after
|
||||
SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
|
||||
}
|
||||
#else
|
||||
SetMenuTitle( menu , title ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
UInt32 UMAMenuEvent( EventRecord *inEvent )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return MenuEvent( inEvent ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( inEvent->what == keyDown && inEvent->modifiers & cmdKey)
|
||||
{
|
||||
return MenuKey( inEvent->message & charCodeMask ) ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
|
||||
{
|
||||
#if UMA_USE_8_6
|
||||
EnableMenuItem( inMenu , inItem ) ;
|
||||
#else
|
||||
EnableItem( inMenu , inItem ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
|
||||
{
|
||||
#if UMA_USE_8_6
|
||||
DisableMenuItem( inMenu , inItem ) ;
|
||||
#else
|
||||
DisableItem( inMenu , inItem ) ;
|
||||
#endif
|
||||
}
|
||||
// quickdraw
|
||||
|
||||
#if !TARGET_CARBON
|
||||
|
||||
pascal QDGlobalsPtr GetQDGlobalsPtr (void)
|
||||
{
|
||||
return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void UMAShowWatchCursor()
|
||||
{
|
||||
OSErr err = noErr;
|
||||
|
||||
CursHandle watchFob = GetCursor (watchCursor);
|
||||
|
||||
if (!watchFob)
|
||||
err = nilHandleErr;
|
||||
else
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
Cursor preservedArrow;
|
||||
GetQDGlobalsArrow (&preservedArrow);
|
||||
SetQDGlobalsArrow (*watchFob);
|
||||
InitCursor ( );
|
||||
SetQDGlobalsArrow (&preservedArrow);
|
||||
#else
|
||||
SetCursor (*watchFob);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void UMAShowArrowCursor()
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
Cursor arrow;
|
||||
SetCursor (GetQDGlobalsArrow (&arrow));
|
||||
#else
|
||||
SetCursor (&(qd.arrow));
|
||||
#endif
|
||||
}
|
||||
|
||||
// window manager
|
||||
|
||||
GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
|
||||
{
|
||||
wxASSERT( inWindowRef != NULL ) ;
|
||||
#if TARGET_CARBON
|
||||
return GetWindowPort( inWindowRef ) ;
|
||||
#else
|
||||
return (GrafPtr) inWindowRef ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMADisposeWindow( WindowRef inWindowRef )
|
||||
{
|
||||
wxASSERT( inWindowRef != NULL ) ;
|
||||
DisposeWindow( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMASetWTitleC( WindowRef inWindowRef , const char *title )
|
||||
{
|
||||
Str255 ptitle ;
|
||||
strncpy( (char*)ptitle , title , 96 ) ;
|
||||
ptitle[96] = 0 ;
|
||||
c2pstr( (char*)ptitle ) ;
|
||||
SetWTitle( inWindowRef , ptitle ) ;
|
||||
}
|
||||
void UMAGetWTitleC( WindowRef inWindowRef , char *title )
|
||||
{
|
||||
GetWTitle( inWindowRef , (unsigned char*)title ) ;
|
||||
p2cstr( (unsigned char*)title ) ;
|
||||
}
|
||||
|
||||
void UMAShowWindow( WindowRef inWindowRef )
|
||||
{
|
||||
ShowWindow( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMAHideWindow( WindowRef inWindowRef )
|
||||
{
|
||||
HideWindow( inWindowRef) ;
|
||||
}
|
||||
|
||||
void UMASelectWindow( WindowRef inWindowRef )
|
||||
{
|
||||
SelectWindow( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMABringToFront( WindowRef inWindowRef )
|
||||
{
|
||||
BringToFront( inWindowRef ) ;
|
||||
}
|
||||
|
||||
void UMASendBehind( WindowRef inWindowRef , WindowRef behindWindow )
|
||||
{
|
||||
SendBehind( inWindowRef , behindWindow ) ;
|
||||
}
|
||||
|
||||
void UMACloseWindow(WindowRef inWindowRef)
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
#else
|
||||
CloseWindow( inWindowRef ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
// appearance additions
|
||||
|
||||
void UMAActivateControl( ControlHandle inControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::ActivateControl( inControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAActivateControl( inControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMADrawControl( ControlHandle inControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::DrawControlInCurrentPort( inControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGADrawControl( inControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMAMoveControl( ControlHandle inControl , short x , short y )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::MoveControl( inControl , x , y ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAMoveControl( inControl , x ,y ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMASizeControl( ControlHandle inControl , short x , short y )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::SizeControl( inControl , x , y ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGASizeControl( inControl , x ,y ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMADeactivateControl( ControlHandle inControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::DeactivateControl( inControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGADeactivateControl( inControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMASetThemeWindowBackground (WindowRef inWindow,
|
||||
ThemeBrush inBrush,
|
||||
Boolean inUpdate){
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ControlHandle UMANewControl(WindowPtr owningWindow,
|
||||
const Rect * boundsRect,
|
||||
ConstStr255Param controlTitle,
|
||||
Boolean initiallyVisible,
|
||||
SInt16 initialValue,
|
||||
SInt16 minimumValue,
|
||||
SInt16 maximumValue,
|
||||
SInt16 procID,
|
||||
SInt32 controlReference)
|
||||
{
|
||||
ControlHandle theControl = NULL ;
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
theControl = NewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
|
||||
initialValue , minimumValue , maximumValue , procID , controlReference ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
theControl = AGANewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
|
||||
initialValue , minimumValue , maximumValue , procID , controlReference ) ;
|
||||
}
|
||||
return theControl ;
|
||||
}
|
||||
|
||||
void UMADisposeControl (ControlHandle theControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::DisposeControl( theControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::DisposeControl( theControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMAHiliteControl (ControlHandle theControl,
|
||||
ControlPartCode hiliteState)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::HiliteControl( theControl , hiliteState ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::HiliteControl( theControl , hiliteState ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMAShowControl (ControlHandle theControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::ShowControl( theControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::ShowControl( theControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMAHideControl (ControlHandle theControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::HideControl( theControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
::HideControl( theControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UMASetControlVisibility (ControlHandle inControl,
|
||||
Boolean inIsVisible,
|
||||
Boolean inDoDraw)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool UMAIsControlActive (ControlHandle inControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return IsControlActive( inControl ) ;
|
||||
}
|
||||
else
|
||||
return (**inControl).contrlHilite == 0 ;
|
||||
}
|
||||
|
||||
|
||||
bool UMAIsControlVisible (ControlHandle inControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return IsControlVisible( inControl ) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
OSErr UMAGetBestControlRect (ControlHandle inControl,
|
||||
Rect * outRect,
|
||||
SInt16 * outBaseLineOffset)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return GetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OSErr UMASetControlFontStyle (ControlHandle inControl,
|
||||
const ControlFontStyleRec * inStyle)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return ::SetControlFontStyle( inControl , inStyle ) ;
|
||||
}
|
||||
else
|
||||
return AGASetControlFontStyle( inControl , inStyle ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// control hierarchy
|
||||
|
||||
OSErr UMACreateRootControl (WindowPtr inWindow,
|
||||
ControlHandle * outControl)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return CreateRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
else
|
||||
return AGACreateRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OSErr UMAEmbedControl (ControlHandle inControl,
|
||||
ControlHandle inContainer)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return EmbedControl( inControl , inContainer ) ;
|
||||
}
|
||||
else
|
||||
return AGAEmbedControl( inControl , inContainer ) ; ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// keyboard focus
|
||||
OSErr UMASetKeyboardFocus (WindowPtr inWindow,
|
||||
ControlHandle inControl,
|
||||
ControlFocusPart inPart)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return SetKeyboardFocus( inWindow , inControl , inPart ) ;
|
||||
}
|
||||
else
|
||||
return AGASetKeyboardFocus( inWindow , inControl , inPart ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// events
|
||||
|
||||
ControlPartCode UMAHandleControlClick (ControlHandle inControl,
|
||||
Point inWhere,
|
||||
SInt16 inModifiers,
|
||||
ControlActionUPP inAction)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return HandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAHandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SInt16 UMAHandleControlKey (ControlHandle inControl,
|
||||
SInt16 inKeyCode,
|
||||
SInt16 inCharCode,
|
||||
SInt16 inModifiers)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return HandleControlKey( inControl , inKeyCode , inCharCode , inModifiers ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAHandleControlKey(inControl , inKeyCode , inCharCode , inModifiers ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UMAIdleControls (WindowPtr inWindow)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
IdleControls( inWindow ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAIdleControls( inWindow ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
UpdateControls( inWindow , inRgn ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAUpdateControls( inWindow , inRgn ) ;
|
||||
}
|
||||
}
|
||||
|
||||
OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl )
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return GetRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetRootControl( inWindow , outControl ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// handling control data
|
||||
|
||||
OSErr UMASetControlData (ControlHandle inControl,
|
||||
ControlPartCode inPart,
|
||||
ResType inTagName,
|
||||
Size inSize,
|
||||
Ptr inData)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return SetControlData( inControl , inPart , inTagName , inSize , inData ) ;
|
||||
}
|
||||
else
|
||||
return AGASetControlData( inControl , inPart , inTagName , inSize , inData ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OSErr UMAGetControlData (ControlHandle inControl,
|
||||
ControlPartCode inPart,
|
||||
ResType inTagName,
|
||||
Size inBufferSize,
|
||||
Ptr outBuffer,
|
||||
Size * outActualSize)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return ::GetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
OSErr UMAGetControlDataSize (ControlHandle inControl,
|
||||
ControlPartCode inPart,
|
||||
ResType inTagName,
|
||||
Size * outMaxSize)
|
||||
{
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
return GetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AGAGetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// system 8.0 changes
|
||||
|
||||
short UMAFindWindow( Point inPoint , WindowRef *outWindow )
|
||||
{
|
||||
// todo add the additional area codes
|
||||
return FindWindow( inPoint , outWindow ) ;
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowFeatures( WindowRef inWindowRef , UInt32 *outFeatures )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
return GetWindowFeatures( inWindowRef , outFeatures ) ;
|
||||
#else
|
||||
return 0 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowRegion( WindowRef inWindowRef , WindowRegionCode inRegionCode , RgnHandle ioWinRgn )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
return GetWindowRegion( inWindowRef , inRegionCode , ioWinRgn ) ;
|
||||
#else
|
||||
return 0 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMADrawGrowIcon( WindowRef inWindowRef )
|
||||
{
|
||||
DrawGrowIcon( inWindowRef ) ;
|
||||
}
|
||||
|
||||
OSStatus UMACollapseWindow( WindowRef inWindowRef , Boolean inCollapseIt )
|
||||
{
|
||||
return CollapseWindow( inWindowRef , inCollapseIt ) ;
|
||||
}
|
||||
|
||||
OSStatus UMACollapseAllWindows( Boolean inCollapseEm )
|
||||
{
|
||||
return CollapseAllWindows( inCollapseEm ) ;
|
||||
}
|
||||
|
||||
Boolean UMAIsWindowCollapsed( WindowRef inWindowRef )
|
||||
{
|
||||
return IsWindowCollapsed( inWindowRef ) ;
|
||||
}
|
||||
|
||||
Boolean UMAIsWindowCollapsable( WindowRef inWindowRef )
|
||||
{
|
||||
return IsWindowCollapsable( inWindowRef ) ;
|
||||
}
|
||||
|
||||
// system 8.5 changes<MacWindows.h>
|
||||
OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attributes , const Rect *bounds, WindowRef *outWindow )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return CreateNewWindow( windowClass , attributes, bounds, outWindow ) ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
short procID ;
|
||||
if ( UMAHasAppearance() )
|
||||
{
|
||||
switch( windowClass )
|
||||
{
|
||||
case kMovableModalWindowClass :
|
||||
procID = kWindowMovableModalDialogProc;
|
||||
break ;
|
||||
case kDocumentWindowClass :
|
||||
procID = kWindowFullZoomGrowDocumentProc;
|
||||
break ;
|
||||
default :
|
||||
procID = kWindowMovableModalDialogProc;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( windowClass )
|
||||
{
|
||||
case kMovableModalWindowClass :
|
||||
procID = movableDBoxProc;
|
||||
// procID += kMovableModalDialogVariantCode;
|
||||
break ;
|
||||
case kDocumentWindowClass :
|
||||
procID = zoomDocProc;
|
||||
break ;
|
||||
default :
|
||||
procID = documentProc;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
*outWindow = NewCWindow(nil, bounds, "\p", false, procID, (WindowRef) -1 /*behind*/,
|
||||
attributes & kWindowCloseBoxAttribute , (long)NULL);
|
||||
return noErr ;
|
||||
}
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowClass( WindowRef inWindowRef , WindowClass *outWindowClass )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return GetWindowClass( inWindowRef , outWindowClass ) ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return kDocumentWindowClass ;
|
||||
}
|
||||
|
||||
OSStatus UMAGetWindowAttributes( WindowRef inWindowRef , WindowAttributes *outAttributes )
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return GetWindowAttributes( inWindowRef , outAttributes ) ;
|
||||
}
|
||||
#endif
|
||||
return kWindowNoAttributes ;
|
||||
}
|
||||
|
||||
void UMAShowFloatingWindows()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
ShowFloatingWindows() ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void UMAHideFloatingWindows()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
HideFloatingWindows() ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Boolean UMAAreFloatingWindowsVisible()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return AreFloatingWindowsVisible() ;
|
||||
}
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
WindowRef UMAFrontNonFloatingWindow()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return FrontNonFloatingWindow() ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return FrontWindow() ;
|
||||
}
|
||||
}
|
||||
|
||||
WindowRef UMAFrontWindow()
|
||||
{
|
||||
#if UMA_USE_WINDOWMGR
|
||||
if ( UMAHasWindowManager() )
|
||||
{
|
||||
return FrontWindow() ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return FrontWindow() ;
|
||||
}
|
||||
}
|
||||
|
||||
WindowRef UMAGetActiveNonFloatingWindow()
|
||||
{
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
bool UMAIsWindowFloating( WindowRef inWindow )
|
||||
{
|
||||
WindowClass cl ;
|
||||
|
||||
UMAGetWindowClass( inWindow , &cl ) ;
|
||||
return cl == kFloatingWindowClass ;
|
||||
}
|
||||
|
||||
bool UMAIsWindowModal( WindowRef inWindow )
|
||||
{
|
||||
WindowClass cl ;
|
||||
|
||||
UMAGetWindowClass( inWindow , &cl ) ;
|
||||
return cl < kFloatingWindowClass ;
|
||||
}
|
||||
|
||||
// others
|
||||
|
||||
void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
|
||||
{
|
||||
if ( inWindowRef )
|
||||
{
|
||||
// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
|
||||
// if ( inActivate != isHightlited )
|
||||
HiliteWindow( inWindowRef , inActivate ) ;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user