split classic and carbon

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26277 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2004-03-20 07:43:01 +00:00
parent f8991003ff
commit 2646f48516
95 changed files with 39232 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleIdentifier</key>
<string>org.wxwindows.IDENTIFIER</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>EXECUTABLE</string>
<key>CFBundleIconFile</key>
<string>wxmac.icns</string>
<key>CFBundleName</key>
<string>EXECUTABLE</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>VERSION</string>
<key>CFBundleShortVersionString</key>
<string>VERSION</string>
<key>CFBundleGetInfoString</key>
<string>EXECUTABLE version VERSION, (c) 2002 wxWindows</string>
<key>CFBundleLongVersionString</key>
<string>VERSION, (c) 2002 wxWindows</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2002 wxWindows</string>
<key>LSRequiresCarbon</key>
<true/>
<key>CSResourcesFileMapped</key>
<true/>
</dict>
</plist>

108
src/mac/classic/accel.cpp Normal file
View File

@@ -0,0 +1,108 @@
/////////////////////////////////////////////////////////////////////////////
// Name: accel.cpp
// Purpose: wxAcceleratorTable
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "accel.h"
#endif
#include "wx/setup.h"
#include "wx/accel.h"
#include "wx/string.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
#endif
// ----------------------------------------------------------------------------
// wxAccelList: a list of wxAcceleratorEntries
// ----------------------------------------------------------------------------
WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxAccelList);
// ----------------------------------------------------------------------------
// wxAccelRefData: the data used by wxAcceleratorTable
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
{
friend class WXDLLEXPORT wxAcceleratorTable;
public:
wxAcceleratorRefData();
~wxAcceleratorRefData();
wxAccelList m_accels;
};
#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
wxAcceleratorRefData::wxAcceleratorRefData()
: m_accels()
{
}
wxAcceleratorRefData::~wxAcceleratorRefData()
{
m_accels.DeleteContents( TRUE );
}
wxAcceleratorTable::wxAcceleratorTable()
{
m_refData = NULL;
}
wxAcceleratorTable::~wxAcceleratorTable()
{
}
// Create from an array
wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
{
m_refData = new wxAcceleratorRefData;
for (int i = 0; i < n; i++)
{
int flag = entries[i].GetFlags();
int keycode = entries[i].GetKeyCode();
int command = entries[i].GetCommand();
if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode );
M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
}
}
bool wxAcceleratorTable::Ok() const
{
return (m_refData != NULL);
}
int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
{
if (!Ok()) return -1;
wxAccelList::Node *node = M_ACCELDATA->m_accels.GetFirst();
while (node)
{
wxAcceleratorEntry *entry = (wxAcceleratorEntry*)node->GetData();
if ((event.m_keyCode == entry->GetKeyCode()) &&
(((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) &&
(((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) &&
(((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown()))
{
return entry->GetCommand();
}
node = node->GetNext();
}
return -1;
}

2
src/mac/classic/aga.cpp Normal file
View File

@@ -0,0 +1,2 @@
// NOT NEEDED ANYMORE

2439
src/mac/classic/app.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
#define kMacSTRWrongMachine 1
#define kMacSTRSmallSize 2
#define kMacSTRNoMemory 3
#define kMacSTROldSystem 4
#define kMacSTRGenericAbout 5
#define kMacSTRNoPre8Yet 6

32
src/mac/classic/apprsrc.r Normal file
View File

@@ -0,0 +1,32 @@
#ifdef __UNIX__
# include <Carbon.r>
#else
# include <Types.r>
#endif
#include "apprsrc.h"
resource 'STR#' ( 128 , "Simple Alert Messages" )
{
{
"This application needs at least a MacPlus" ,
"This application needs more memory" ,
"This application is out of memory" ,
"This application needs at least System 8.6" ,
"About this wxWindows Application" ,
"This application needs Appearance extension (built in with System 8) - this restriction will be relieved in the final release"
}
} ;
resource 'MENU' (1, preload)
{
1, textMenuProc, 0b11111111111111111111111111111110 , enabled, apple ,
{
"About<EFBFBD>" , noicon, nokey,nomark,plain ,
"-" , noicon, nokey,nomark,plain
}
} ;
resource 'MBAR' (1,preload)
{
{ 1 } ;
} ;

1436
src/mac/classic/bitmap.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,113 @@
/////////////////////////////////////////////////////////////////////////////
// Name: bmpbuttn.cpp
// Purpose: wxBitmapButton
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "bmpbuttn.h"
#endif
#include "wx/window.h"
#include "wx/bmpbuttn.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
#endif
#include "wx/mac/uma.h"
#include "wx/bitmap.h"
bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
// since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
// essentially creates an additional button
if ( !wxControl::Create(parent, id, pos, size,
style, validator, name) )
return false;
m_bmpNormal = bitmap;
if (style & wxBU_AUTODRAW)
{
m_marginX = wxDEFAULT_BUTTON_MARGIN;
m_marginY = wxDEFAULT_BUTTON_MARGIN;
}
else
{
m_marginX = 0;
m_marginY = 0;
}
int width = size.x;
int height = size.y;
if ( bitmap.Ok() )
{
wxSize newSize = DoGetBestSize();
if ( width == -1 )
width = newSize.x;
if ( height == -1 )
height = newSize.y;
}
Rect bounds ;
Str255 title ;
m_bmpNormal = bitmap;
wxBitmapRefData * bmap = NULL ;
if ( m_bmpNormal.Ok() )
bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
kControlBehaviorOffsetContents +
( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
kControlContentCIconHandle : kControlContentPictHandle ) , 0,
(( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
if ( info.contentType != kControlNoContent )
{
::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
}
MacPostControlCreate() ;
return TRUE;
}
void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
{
m_bmpNormal = bitmap;
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
if ( info.contentType != kControlNoContent )
{
::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
}
}
wxSize wxBitmapButton::DoGetBestSize() const
{
wxSize best;
if (m_bmpNormal.Ok())
{
best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
}
return best;
}

229
src/mac/classic/brush.cpp Normal file
View File

@@ -0,0 +1,229 @@
/////////////////////////////////////////////////////////////////////////////
// Name: brush.cpp
// Purpose: wxBrush
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "brush.h"
#endif
#include "wx/setup.h"
#include "wx/utils.h"
#include "wx/brush.h"
#include "wx/mac/private.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
#endif
class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
{
friend class WXDLLEXPORT wxBrush;
public:
wxBrushRefData();
wxBrushRefData(const wxBrushRefData& data);
~wxBrushRefData();
protected:
wxMacBrushKind m_macBrushKind ;
int m_style;
wxBitmap m_stipple ;
wxColour m_colour;
ThemeBrush m_macThemeBrush ;
ThemeBackgroundKind m_macThemeBackground ;
Rect m_macThemeBackgroundExtent ;
};
#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
wxBrushRefData::wxBrushRefData()
: m_style(wxSOLID)
{
m_macBrushKind = kwxMacBrushColour ;
}
wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
: wxGDIRefData()
, m_style(data.m_style)
{
m_stipple = data.m_stipple;
m_colour = data.m_colour;
m_macBrushKind = data.m_macBrushKind ;
m_macThemeBrush = data.m_macThemeBrush ;
m_macThemeBackground = data.m_macThemeBackground ;
m_macThemeBackgroundExtent = data.m_macThemeBackgroundExtent ;
}
wxBrushRefData::~wxBrushRefData()
{
}
// Brushes
wxBrush::wxBrush()
{
}
wxBrush::~wxBrush()
{
}
wxBrush::wxBrush(const wxColour& col, int Style)
{
m_refData = new wxBrushRefData;
M_BRUSHDATA->m_colour = col;
M_BRUSHDATA->m_style = Style;
RealizeResource();
}
wxBrush::wxBrush(const wxBitmap& stipple)
{
m_refData = new wxBrushRefData;
M_BRUSHDATA->m_colour = *wxBLACK;
M_BRUSHDATA->m_stipple = stipple;
if (M_BRUSHDATA->m_stipple.GetMask())
M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
else
M_BRUSHDATA->m_style = wxSTIPPLE;
RealizeResource();
}
wxBrush::wxBrush(ThemeBrush macThemeBrush )
{
m_refData = new wxBrushRefData;
M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
RealizeResource();
}
void wxBrush::Unshare()
{
// Don't change shared data
if (!m_refData)
{
m_refData = new wxBrushRefData();
}
else
{
wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
UnRef();
m_refData = ref;
}
}
void wxBrush::SetColour(const wxColour& col)
{
Unshare();
M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
M_BRUSHDATA->m_colour = col;
RealizeResource();
}
void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
{
Unshare();
M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
M_BRUSHDATA->m_colour.Set(r, g, b);
RealizeResource();
}
void wxBrush::SetStyle(int Style)
{
Unshare();
M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
M_BRUSHDATA->m_style = Style;
RealizeResource();
}
void wxBrush::SetStipple(const wxBitmap& Stipple)
{
Unshare();
M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
M_BRUSHDATA->m_stipple = Stipple;
RealizeResource();
}
void wxBrush::SetMacTheme(ThemeBrush macThemeBrush)
{
Unshare();
M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
RealizeResource();
}
void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
{
Unshare();
M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent ;
RealizeResource();
}
bool wxBrush::RealizeResource()
{
return TRUE;
}
unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent) const
{
if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
{
if ( extent )
*(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent ;
return M_BRUSHDATA->m_macThemeBackground ;
}
else
{
return 0 ;
}
}
short wxBrush::GetMacTheme() const
{
return (M_BRUSHDATA ? ( M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack);
}
wxColour& wxBrush::GetColour() const
{
return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour);
}
int wxBrush::GetStyle() const
{
return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0);
}
wxBitmap *wxBrush::GetStipple() const
{
return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0);
}
wxMacBrushKind wxBrush::MacGetBrushKind() const
{
return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour);
}

132
src/mac/classic/button.cpp Normal file
View File

@@ -0,0 +1,132 @@
/////////////////////////////////////////////////////////////////////////////
// Name: button.cpp
// Purpose: wxButton
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "button.h"
#endif
#include "wx/defs.h"
#include "wx/button.h"
#include "wx/panel.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
#endif
#include "wx/mac/uma.h"
// Button
static const int kMacOSXHorizontalBorder = 2 ;
static const int kMacOSXVerticalBorder = 4 ;
bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
return false;
Rect bounds ;
Str255 title ;
if ( UMAHasAquaLayout() )
{
m_macHorizontalBorder = kMacOSXHorizontalBorder;
m_macVerticalBorder = kMacOSXVerticalBorder;
}
MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
kControlPushButtonProc , (long) this ) ;
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
MacPostControlCreate() ;
return TRUE;
}
void wxButton::SetDefault()
{
wxWindow *parent = GetParent();
wxButton *btnOldDefault = NULL;
if ( parent )
{
btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
wxButton);
parent->SetDefaultItem(this);
}
Boolean inData;
if ( btnOldDefault && btnOldDefault->m_macControl )
{
inData = 0;
::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart ,
kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
}
if ( (ControlHandle) m_macControl )
{
inData = 1;
::SetControlData( (ControlHandle) m_macControl , kControlButtonPart ,
kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
}
}
wxSize wxButton::DoGetBestSize() const
{
wxSize sz = GetDefaultSize() ;
int wBtn = m_label.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ;
if (wBtn > sz.x) sz.x = wBtn;
return sz ;
}
wxSize wxButton::GetDefaultSize()
{
int wBtn = 70 ;
int hBtn = 20 ;
if ( UMAHasAquaLayout() )
{
wBtn += 2 * kMacOSXHorizontalBorder ;
hBtn += 2 * kMacOSXVerticalBorder ;
}
return wxSize(wBtn, hBtn);
}
void wxButton::Command (wxCommandEvent & event)
{
if ( (ControlHandle) m_macControl )
{
HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ;
unsigned long finalTicks ;
Delay( 8 , &finalTicks ) ;
HiliteControl( (ControlHandle) m_macControl , 0 ) ;
}
ProcessCommand (event);
}
void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
{
if ( controlpart != kControlNoPart )
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
event.SetEventObject(this);
ProcessCommand(event);
}
}

View File

@@ -0,0 +1,7 @@
// carbon for 9
data 'carb' (0) {
$"0000" /* .. */
};
// the plist resource should only be included in the application
// since it contains the bundle information and should not be duplicated

View File

@@ -0,0 +1,179 @@
/////////////////////////////////////////////////////////////////////////////
// Name: checkbox.cpp
// Purpose: wxCheckBox
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "checkbox.h"
#endif
#include "wx/defs.h"
#include "wx/checkbox.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
#endif
#include "wx/mac/uma.h"
// Single check box item
bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
return false;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
SInt16 maxValue = 1 /* kControlCheckboxCheckedValue */;
if (style & wxCHK_3STATE)
{
maxValue = 2 /* kControlCheckboxMixedValue */;
}
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , maxValue,
kControlCheckBoxProc , (long) this ) ;
MacPostControlCreate() ;
return TRUE;
}
void wxCheckBox::SetValue(bool val)
{
if (val)
{
Set3StateValue(wxCHK_CHECKED);
}
else
{
Set3StateValue(wxCHK_UNCHECKED);
}
}
bool wxCheckBox::GetValue() const
{
return (DoGet3StateValue() != 0);
}
void wxCheckBox::Command (wxCommandEvent & event)
{
int state = event.GetInt();
wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
|| (state == wxCHK_UNDETERMINED),
wxT("event.GetInt() returned an invalid checkbox state") );
Set3StateValue((wxCheckBoxState) state);
ProcessCommand(event);
}
wxCheckBoxState wxCheckBox::DoGet3StateValue() const
{
return (wxCheckBoxState) ::GetControl32BitValue( (ControlHandle) m_macControl );
}
void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
{
::SetControl32BitValue( (ControlHandle) m_macControl , (int) val) ;
MacRedrawControl() ;
}
void wxCheckBox::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown) )
{
wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
wxCheckBoxState state = Get3StateValue();
if (state == wxCHK_UNCHECKED)
{
state = wxCHK_CHECKED;
}
else if (state == wxCHK_CHECKED)
{
// If the style flag to allow the user setting the undetermined state
// is set, then set the state to undetermined. Otherwise set state to
// unchecked.
if ( Is3rdStateAllowedForUser() )
{
state = wxCHK_UNDETERMINED;
}
else
{
state = wxCHK_UNCHECKED;
}
}
else if (state == wxCHK_UNDETERMINED)
{
state = wxCHK_UNCHECKED;
}
Set3StateValue(state);
event.SetInt(state);
event.SetEventObject(this);
ProcessCommand(event);
}
// Bitmap checkbox
bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id,
const wxBitmap *label,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
SetName(name);
SetValidator(validator);
m_windowStyle = style;
if (parent) parent->AddChild(this);
if ( id == -1 )
m_windowId = NewControlId();
else
m_windowId = id;
// TODO: Create the bitmap checkbox
return FALSE;
}
void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
{
// TODO
wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
}
void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
{
wxControl::SetSize( x , y , width , height , sizeFlags ) ;
}
void wxBitmapCheckBox::SetValue(bool val)
{
// TODO
wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
}
bool wxBitmapCheckBox::GetValue() const
{
// TODO
wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
return FALSE;
}

View File

@@ -0,0 +1,453 @@
///////////////////////////////////////////////////////////////////////////////
// Name: checklst.cpp
// Purpose: implementation of wxCheckListBox class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// headers & declarations
// ============================================================================
#ifdef __GNUG__
#pragma implementation "checklst.h"
#endif
#include "wx/defs.h"
#if wxUSE_CHECKLISTBOX
#include "wx/checklst.h"
#include "wx/arrstr.h"
#include "wx/mac/uma.h"
#include <Appearance.h>
// ============================================================================
// implementation of wxCheckListBox
// ============================================================================
IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
const short kwxMacListWithVerticalScrollbar = 128 ;
const short kwxMacListItemHeight = 14 ;
const short kwxMacListCheckboxWidth = 14 ;
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
typedef struct {
unsigned short instruction;
void (*function)();
} ldefRec, *ldefPtr, **ldefHandle;
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
extern "C"
{
static pascal void wxMacCheckListDefinition( short message, Boolean isSelected, Rect *drawRect,
Cell cell, short dataOffset, short dataLength,
ListHandle listHandle ) ;
}
static pascal void wxMacCheckListDefinition( short message, Boolean isSelected, Rect *drawRect,
Cell cell, short dataOffset, short dataLength,
ListHandle listHandle )
{
wxCheckListBox* list;
list = (wxCheckListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) );
if ( list == NULL )
return ;
GrafPtr savePort;
GrafPtr grafPtr;
RgnHandle savedClipRegion;
SInt32 savedPenMode;
GetPort(&savePort);
SetPort((**listHandle).port);
grafPtr = (**listHandle).port ;
// typecast our refCon
// Calculate the cell rect.
switch( message ) {
case lInitMsg:
break;
case lCloseMsg:
break;
case lDrawMsg:
{
const wxString text = list->m_stringArray[cell.v] ;
int checked = list->m_checks[cell.v] ;
// Save the current clip region, and set the clip region to the area we are about
// to draw.
savedClipRegion = NewRgn();
GetClip( savedClipRegion );
ClipRect( drawRect );
EraseRect( drawRect );
const wxFont& font = list->GetFont();
if ( font.Ok() )
{
::TextFont( font.GetMacFontNum() ) ;
::TextSize( font.GetMacFontSize()) ;
::TextFace( font.GetMacFontStyle() ) ;
}
ThemeButtonDrawInfo info ;
info.state = kThemeStateActive ;
info.value = checked ? kThemeButtonOn : kThemeButtonOff ;
info.adornment = kThemeAdornmentNone ;
Rect checkRect = *drawRect ;
checkRect.left +=0 ;
checkRect.top +=0 ;
checkRect.right = checkRect.left + list->m_checkBoxWidth ;
checkRect.bottom = checkRect.top + list->m_checkBoxHeight ;
DrawThemeButton(&checkRect,kThemeCheckBox,
&info,NULL,NULL, NULL,0);
MoveTo(drawRect->left + 2 + list->m_checkBoxWidth+2, drawRect->top + list->m_TextBaseLineOffset );
DrawText(text, 0 , text.Length());
// If the cell is hilited, do the hilite now. Paint the cell contents with the
// appropriate QuickDraw transform mode.
if( isSelected ) {
savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
PaintRect( drawRect );
SetPortPenMode( (CGrafPtr) grafPtr, savedPenMode );
}
// Restore the saved clip region.
SetClip( savedClipRegion );
DisposeRgn( savedClipRegion );
}
break;
case lHiliteMsg:
// Hilite or unhilite the cell. Paint the cell contents with the
// appropriate QuickDraw transform mode.
GetPort( &grafPtr );
savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
PaintRect( drawRect );
SetPortPenMode( (CGrafPtr) grafPtr, savedPenMode );
break;
default :
break ;
}
SetPort(savePort);
}
extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ;
static ListDefUPP macCheckListDefUPP = NULL ;
// ----------------------------------------------------------------------------
// creation
// ----------------------------------------------------------------------------
void wxCheckListBox::Init()
{
}
bool wxCheckListBox::Create(wxWindow *parent,
wxWindowID id,
const wxPoint &pos,
const wxSize &size,
const wxArrayString& choices,
long style,
const wxValidator& validator,
const wxString &name)
{
wxCArrayString chs(choices);
return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(),
style, validator, name);
}
bool wxCheckListBox::Create(wxWindow *parent,
wxWindowID id,
const wxPoint &pos,
const wxSize &size,
int n,
const wxString choices[],
long style,
const wxValidator& validator,
const wxString &name)
{
if ( !wxCheckListBoxBase::Create(parent, id, pos, size,
n, choices, style, validator, name) )
return false;
m_noItems = 0 ; // this will be increased by our append command
m_selected = 0;
m_checkBoxWidth = 12;
m_checkBoxHeight= 10;
long h = m_checkBoxHeight ;
#if TARGET_CARBON
GetThemeMetric(kThemeMetricCheckBoxWidth,(long *)&m_checkBoxWidth);
GetThemeMetric(kThemeMetricCheckBoxHeight,&h);
#endif
const wxFont& font = GetFont();
FontInfo finfo;
FetchFontInfo(font.GetMacFontNum(),font.GetMacFontSize(),font.GetMacFontStyle(),&finfo);
m_TextBaseLineOffset= finfo.leading+finfo.ascent;
m_checkBoxHeight= finfo.leading+finfo.ascent+finfo.descent;
if (m_checkBoxHeight<h)
{
m_TextBaseLineOffset+= (h-m_checkBoxHeight)/2;
m_checkBoxHeight= h;
}
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
ListDefSpec listDef;
listDef.defType = kListDefUserProcType;
if ( macCheckListDefUPP == NULL )
{
macCheckListDefUPP = NewListDefUPP( wxMacCheckListDefinition );
}
listDef.u.userProc = macCheckListDefUPP ;
#if TARGET_CARBON
Size asize;
CreateListBoxControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, false, 0, 1, false, true,
m_checkBoxHeight+2, 14, false, &listDef, (ControlRef *)&m_macControl );
GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag,
sizeof(ListHandle), (Ptr) &m_macList, &asize);
SetControlReference( (ControlHandle) m_macControl, (long) this);
SetControlVisibility( (ControlHandle) m_macControl, false, false);
#else
long result ;
wxStAppResource resload ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
kwxMacListWithVerticalScrollbar , 0 , 0,
kControlListBoxProc , (long) this ) ;
::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
HLock( (Handle) m_macList ) ;
ldefHandle ldef ;
ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
if ( (**(ListHandle)m_macList).listDefProc != NULL )
{
(**ldef).instruction = 0x4EF9; /* JMP instruction */
(**ldef).function = (void(*)()) listDef.u.userProc;
(**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
}
Point pt = (**(ListHandle)m_macList).cellSize ;
pt.v = 14 ;
LCellSize( pt , (ListHandle)m_macList ) ;
LAddColumn( 1 , 0 , (ListHandle)m_macList ) ;
#endif
OptionBits options = 0;
if ( style & wxLB_MULTIPLE )
{
options += lNoExtend ;
}
else if ( style & wxLB_EXTENDED )
{
options += lExtendDrag ;
}
else
{
options = (OptionBits) lOnlyOne ;
}
SetListSelectionFlags((ListHandle)m_macList, options);
MacPostControlCreate() ;
for ( int i = 0 ; i < n ; i++ )
{
Append( choices[i] ) ;
}
LSetDrawingMode( true , (ListHandle) m_macList ) ;
return TRUE;
}
// ----------------------------------------------------------------------------
// wxCheckListBox functions
// ----------------------------------------------------------------------------
bool wxCheckListBox::IsChecked(size_t item) const
{
wxCHECK_MSG( item < m_checks.GetCount(), FALSE,
_T("invalid index in wxCheckListBox::IsChecked") );
return m_checks[item] != 0;
}
void wxCheckListBox::Check(size_t item, bool check)
{
wxCHECK_RET( item < m_checks.GetCount(),
_T("invalid index in wxCheckListBox::Check") );
// intermediate var is needed to avoid compiler warning with VC++
bool isChecked = m_checks[item] != 0;
if ( check != isChecked )
{
m_checks[item] = check;
MacRedrawControl() ;
}
}
// ----------------------------------------------------------------------------
// methods forwarded to wxListBox
// ----------------------------------------------------------------------------
void wxCheckListBox::Delete(int n)
{
wxCHECK_RET( n < GetCount(), _T("invalid index in wxListBox::Delete") );
wxListBox::Delete(n);
m_checks.RemoveAt(n);
}
int wxCheckListBox::DoAppend(const wxString& item)
{
LSetDrawingMode( false , (ListHandle) m_macList ) ;
int pos = wxListBox::DoAppend(item);
// the item is initially unchecked
m_checks.Insert(FALSE, pos);
LSetDrawingMode( true , (ListHandle) m_macList ) ;
return pos;
}
void wxCheckListBox::DoInsertItems(const wxArrayString& items, int pos)
{
wxListBox::DoInsertItems(items, pos);
size_t count = items.GetCount();
for ( size_t n = 0; n < count; n++ )
{
m_checks.Insert(FALSE, pos + n);
}
}
void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData)
{
// call it first as it does DoClear()
wxListBox::DoSetItems(items, clientData);
size_t count = items.GetCount();
for ( size_t n = 0; n < count; n++ )
{
m_checks.Add(FALSE);
}
}
void wxCheckListBox::DoClear()
{
m_checks.Empty();
}
BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
EVT_CHAR(wxCheckListBox::OnChar)
EVT_LEFT_DOWN(wxCheckListBox::OnLeftClick)
END_EVENT_TABLE()
// this will only work as soon as
void wxCheckListBox::OnChar(wxKeyEvent& event)
{
if ( event.GetKeyCode() == WXK_SPACE )
{
int index = GetSelection() ;
if ( index >= 0 )
{
Check(index, !IsChecked(index) ) ;
wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId());
event.SetInt(index);
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
}
else
event.Skip();
}
void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
{
// clicking on the item selects it, clicking on the checkmark toggles
if ( event.GetX() <= 20 /*check width*/ ) {
int lineheight ;
int topcell ;
#if TARGET_CARBON
Point pt ;
GetListCellSize( (ListHandle)m_macList , &pt ) ;
lineheight = pt.v ;
ListBounds visible ;
GetListVisibleCells( (ListHandle)m_macList , &visible ) ;
topcell = visible.top ;
#else
lineheight = (**(ListHandle)m_macList).cellSize.v ;
topcell = (**(ListHandle)m_macList).visible.top ;
#endif
size_t nItem = ((size_t)event.GetY()) / lineheight + topcell ;
if ( nItem < (size_t)m_noItems )
{
Check(nItem, !IsChecked(nItem) ) ;
wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId());
event.SetInt(nItem);
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
//else: it's not an error, just click outside of client zone
}
else {
// implement default behaviour: clicking on the item selects it
event.Skip();
}
}
#endif // wxUSE_CHECKLISTBOX

300
src/mac/classic/choice.cpp Normal file
View File

@@ -0,0 +1,300 @@
/////////////////////////////////////////////////////////////////////////////
// Name: choice.cpp
// Purpose: wxChoice
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "choice.h"
#endif
#include "wx/defs.h"
#include "wx/choice.h"
#include "wx/menu.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
#endif
extern MenuHandle NewUniqueMenu() ;
wxChoice::~wxChoice()
{
if ( HasClientObjectData() )
{
size_t i, max = GetCount();
for ( i = 0; i < max; ++i )
delete GetClientObject(i);
}
// DeleteMenu( m_macPopUpMenuId ) ;
// DisposeMenu( m_macPopUpMenuHandle ) ;
}
bool wxChoice::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos,
const wxSize& size,
const wxArrayString& choices,
long style,
const wxValidator& validator,
const wxString& name)
{
wxCArrayString chs(choices);
return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(),
style, validator, name);
}
bool wxChoice::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos,
const wxSize& size,
int n, const wxString choices[],
long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxChoiceBase::Create(parent, id, pos, size, style, validator, name) )
return false;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0 ,
kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
m_macPopUpMenuHandle = NewUniqueMenu() ;
SetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ;
SetControl32BitMaximum( (ControlHandle) m_macControl , 0) ;
if ( n > 0 )
SetControl32BitValue( (ControlHandle) m_macControl , 1 ) ;
MacPostControlCreate() ;
// TODO wxCB_SORT
for ( int i = 0; i < n; i++ )
{
Append(choices[i]);
}
return TRUE;
}
// ----------------------------------------------------------------------------
// adding/deleting items to/from the list
// ----------------------------------------------------------------------------
int wxChoice::DoAppend(const wxString& item)
{
UMAAppendMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item, m_font.GetEncoding() );
m_strings.Add( item ) ;
m_datas.Add( NULL ) ;
int index = m_strings.GetCount() - 1 ;
DoSetItemClientData( index , NULL ) ;
SetControl32BitMaximum( (ControlHandle) m_macControl , GetCount()) ;
return index ;
}
int wxChoice::DoInsert(const wxString& item, int pos)
{
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
if (pos == GetCount())
return DoAppend(item);
UMAAppendMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item, m_font.GetEncoding() );
m_strings.Insert( item, pos ) ;
m_datas.Insert( NULL, pos ) ;
DoSetItemClientData( pos , NULL ) ;
SetControl32BitMaximum( (ControlHandle) m_macControl , pos) ;
return pos ;
}
void wxChoice::Delete(int n)
{
wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
if ( HasClientObjectData() )
{
delete GetClientObject(n);
}
::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , n + 1) ;
m_strings.RemoveAt( n ) ;
m_datas.RemoveAt( n ) ;
SetControl32BitMaximum( (ControlHandle) m_macControl , GetCount()) ;
}
void wxChoice::Clear()
{
FreeData();
for ( int i = 0 ; i < GetCount() ; i++ )
{
::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , 1 ) ;
}
m_strings.Empty() ;
m_datas.Empty() ;
SetControl32BitMaximum( (ControlHandle) m_macControl , 0 ) ;
}
void wxChoice::FreeData()
{
if ( HasClientObjectData() )
{
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
delete GetClientObject(n);
}
}
}
// ----------------------------------------------------------------------------
// selection
// ----------------------------------------------------------------------------
int wxChoice::GetSelection() const
{
return GetControl32BitValue( (ControlHandle) m_macControl ) -1 ;
}
void wxChoice::SetSelection(int n)
{
SetControl32BitValue( (ControlHandle) m_macControl , n + 1 ) ;
}
// ----------------------------------------------------------------------------
// string list functions
// ----------------------------------------------------------------------------
int wxChoice::GetCount() const
{
return m_strings.GetCount() ;
}
int wxChoice::FindString(const wxString& s) const
{
for( int i = 0 ; i < GetCount() ; i++ )
{
if ( GetString( i ).IsSameAs(s, FALSE) )
return i ;
}
return wxNOT_FOUND ;
}
void wxChoice::SetString(int n, const wxString& s)
{
wxFAIL_MSG(wxT("wxChoice::SetString() not yet implemented"));
#if 0 // should do this, but no Insert() so far
Delete(n);
Insert(n + 1, s);
#endif
}
wxString wxChoice::GetString(int n) const
{
wxCHECK_MSG( n >= 0 && (size_t)n < m_strings.GetCount(), _T(""),
_T("wxChoice::GetString(): invalid index") );
return m_strings[n] ;
}
// ----------------------------------------------------------------------------
// client data
// ----------------------------------------------------------------------------
void wxChoice::DoSetItemClientData( int n, void* clientData )
{
wxCHECK_RET( n >= 0 && (size_t)n < m_datas.GetCount(),
wxT("invalid index in wxChoice::SetClientData") );
m_datas[n] = (char*) clientData ;
}
void *wxChoice::DoGetItemClientData(int n) const
{
wxCHECK_MSG( n >= 0 && (size_t)n < m_datas.GetCount(), NULL,
wxT("invalid index in wxChoice::GetClientData") );
return (void *)m_datas[n];
}
void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
{
DoSetItemClientData(n, clientData);
}
wxClientData* wxChoice::DoGetItemClientObject( int n ) const
{
return (wxClientData *)DoGetItemClientData(n);
}
void wxChoice::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
{
wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
int n = GetSelection();
// actually n should be made sure by the os to be a valid selection, but ...
if ( n > -1 )
{
event.SetInt( n );
event.SetString(GetStringSelection());
event.SetEventObject(this);
if ( HasClientObjectData() )
event.SetClientObject( GetClientObject(n) );
else if ( HasClientUntypedData() )
event.SetClientData( GetClientData(n) );
ProcessCommand(event);
}
}
wxSize wxChoice::DoGetBestSize() const
{
int lbWidth = GetCount() > 0 ? 20 : 100; // some defaults
int lbHeight = 20;
int wLine;
#if TARGET_CARBON
long metric ;
GetThemeMetric(kThemeMetricPopupButtonHeight , &metric );
lbHeight = metric ;
#endif
{
wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ;
if ( m_font.Ok() )
{
::TextFont( m_font.GetMacFontNum() ) ;
::TextSize( m_font.GetMacFontSize() ) ;
::TextFace( m_font.GetMacFontStyle() ) ;
}
else
{
::TextFont( kFontIDMonaco ) ;
::TextSize( 9 );
::TextFace( 0 ) ;
}
// Find the widest line
for(int i = 0; i < GetCount(); i++) {
wxString str(GetString(i));
#if wxUSE_UNICODE
Point bounds={0,0} ;
SInt16 baseline ;
::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) ,
kThemeCurrentPortFont,
kThemeStateActive,
false,
&bounds,
&baseline );
wLine = bounds.h ;
#else
wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
#endif
lbWidth = wxMax(lbWidth, wLine);
}
// Add room for the popup arrow
lbWidth += 2 * lbHeight ;
// And just a bit more
int cx = ::TextWidth( "X" , 0 , 1 ) ;
lbWidth += cx ;
}
return wxSize(lbWidth, lbHeight);
}

406
src/mac/classic/clipbrd.cpp Normal file
View File

@@ -0,0 +1,406 @@
/////////////////////////////////////////////////////////////////////////////
// Name: clipbrd.cpp
// Purpose: Clipboard functionality
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "clipbrd.h"
#endif
#include "wx/app.h"
#include "wx/frame.h"
#include "wx/bitmap.h"
#include "wx/utils.h"
#include "wx/metafile.h"
#include "wx/clipbrd.h"
#include "wx/intl.h"
#include "wx/log.h"
#ifndef __DARWIN__
#include <Scrap.h>
#endif
#include "wx/mac/uma.h"
#define wxUSE_DATAOBJ 1
#include <string.h>
// the trace mask we use with wxLogTrace() - call
// wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here
// (there will be a *lot* of them!)
static const wxChar *TRACE_CLIPBOARD = _T("clipboard");
void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
{
#if !TARGET_CARBON
OSErr err = noErr ;
#else
OSStatus err = noErr ;
#endif
void * data = NULL ;
Size byteCount;
switch (dataFormat.GetType())
{
case wxDF_OEMTEXT:
dataFormat = wxDF_TEXT;
// fall through
case wxDF_TEXT:
break;
case wxDF_UNICODETEXT:
break;
case wxDF_BITMAP :
case wxDF_METAFILE :
break ;
default:
{
wxLogError(_("Unsupported clipboard format."));
return NULL;
}
}
#if TARGET_CARBON
ScrapRef scrapRef;
err = GetCurrentScrap( &scrapRef );
if ( err != noTypeErr && err != memFullErr )
{
ScrapFlavorFlags flavorFlags;
if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr)
{
if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr)
{
Size allocSize = byteCount ;
if ( dataFormat.GetType() == wxDF_TEXT )
allocSize += 1 ;
else if ( dataFormat.GetType() == wxDF_UNICODETEXT )
allocSize += 2 ;
data = new char[ allocSize ] ;
if (( err = GetScrapFlavorData( scrapRef, dataFormat.GetFormatId(), &byteCount , data )) == noErr )
{
*len = allocSize ;
if ( dataFormat.GetType() == wxDF_TEXT )
((char*)data)[byteCount] = 0 ;
if ( dataFormat.GetType() == wxDF_UNICODETEXT )
((wxChar*)data)[byteCount/2] = 0 ;
}
else
{
delete[] ((char *)data) ;
data = NULL ;
}
}
}
}
#else
long offset ;
Handle datahandle = NewHandle(0) ;
HLock( datahandle ) ;
GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ;
HUnlock( datahandle ) ;
if ( GetHandleSize( datahandle ) > 0 )
{
byteCount = GetHandleSize( datahandle ) ;
Size allocSize = byteCount ;
if ( dataFormat.GetType() == wxDF_TEXT )
allocSize += 1 ;
else if ( dataFormat.GetType() == wxDF_UNICODETEXT )
allocSize += 2 ;
data = new char[ allocSize ] ;
memcpy( (char*) data , (char*) *datahandle , byteCount ) ;
if ( dataFormat.GetType() == wxDF_TEXT )
((char*)data)[byteCount] = 0 ;
if ( dataFormat.GetType() == wxDF_UNICODETEXT )
((wxChar*)data)[byteCount/2] = 0 ;
*len = byteCount ;
}
DisposeHandle( datahandle ) ;
#endif
if ( err )
{
wxLogSysError(_("Failed to get clipboard data."));
return NULL ;
}
if ( dataFormat.GetType() == wxDF_TEXT )
{
wxMacConvertNewlines10To13( (char*) data ) ;
}
return data;
}
/*
* Generalized clipboard implementation by Matthew Flatt
*/
IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
wxClipboard::wxClipboard()
{
m_open = false ;
m_data = NULL ;
}
wxClipboard::~wxClipboard()
{
if (m_data)
{
delete m_data;
m_data = (wxDataObject*) NULL;
}
}
void wxClipboard::Clear()
{
if (m_data)
{
delete m_data;
m_data = (wxDataObject*) NULL;
}
#if TARGET_CARBON
OSStatus err ;
err = ClearCurrentScrap( );
#else
OSErr err ;
err = ZeroScrap( );
#endif
if ( err )
{
wxLogSysError(_("Failed to empty the clipboard."));
}
}
bool wxClipboard::Flush()
{
return FALSE;
}
bool wxClipboard::Open()
{
wxCHECK_MSG( !m_open, FALSE, wxT("clipboard already open") );
m_open = true ;
return true ;
}
bool wxClipboard::IsOpened() const
{
return m_open;
}
bool wxClipboard::SetData( wxDataObject *data )
{
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
Clear();
// as we can only store one wxDataObject, this is the same in this
// implementation
return AddData( data );
}
bool wxClipboard::AddData( wxDataObject *data )
{
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
/* we can only store one wxDataObject */
Clear();
m_data = data;
/* get formats from wxDataObjects */
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
m_data->GetAllFormats( array );
for (size_t i = 0; i < m_data->GetFormatCount(); i++)
{
wxLogTrace( TRACE_CLIPBOARD,
wxT("wxClipboard now supports atom %s"),
array[i].GetId().c_str() );
#if !TARGET_CARBON
OSErr err = noErr ;
#else
OSStatus err = noErr ;
#endif
size_t sz = data->GetDataSize( array[i] ) ;
void* buf = malloc( sz + 1 ) ;
if ( buf )
{
data->GetDataHere( array[i] , buf ) ;
OSType mactype = 0 ;
switch ( array[i].GetType() )
{
case wxDF_TEXT:
case wxDF_OEMTEXT:
mactype = kScrapFlavorTypeText ;
break ;
#if wxUSE_UNICODE
case wxDF_UNICODETEXT :
mactype = kScrapFlavorTypeUnicode ;
break ;
#endif
#if wxUSE_DRAG_AND_DROP
case wxDF_METAFILE:
mactype = kScrapFlavorTypePicture ;
break ;
#endif
case wxDF_BITMAP:
case wxDF_DIB:
mactype = kScrapFlavorTypePicture ;
break ;
default:
break ;
}
UMAPutScrap( sz , mactype , buf ) ;
free( buf ) ;
}
}
delete[] array;
return true ;
}
void wxClipboard::Close()
{
wxCHECK_RET( m_open, wxT("clipboard not open") );
m_open = false ;
// Get rid of cached object. If this is not done copying from another application will
// only work once
if (m_data)
{
delete m_data;
m_data = (wxDataObject*) NULL;
}
}
bool wxClipboard::IsSupported( const wxDataFormat &dataFormat )
{
if ( m_data )
{
return m_data->IsSupported( dataFormat ) ;
}
#if TARGET_CARBON
OSStatus err = noErr;
ScrapRef scrapRef;
err = GetCurrentScrap( &scrapRef );
if ( err != noTypeErr && err != memFullErr )
{
ScrapFlavorFlags flavorFlags;
Size byteCount;
if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr)
{
if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr)
{
return TRUE ;
}
}
}
return FALSE;
#else
long offset ;
Handle datahandle = NewHandle(0) ;
HLock( datahandle ) ;
GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ;
HUnlock( datahandle ) ;
bool hasData = GetHandleSize( datahandle ) > 0 ;
DisposeHandle( datahandle ) ;
return hasData ;
#endif
}
bool wxClipboard::GetData( wxDataObject& data )
{
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
size_t formatcount = data.GetFormatCount() + 1 ;
wxDataFormat *array = new wxDataFormat[ formatcount ];
array[0] = data.GetPreferredFormat();
data.GetAllFormats( &array[1] );
bool transferred = false ;
if ( m_data )
{
for (size_t i = 0; !transferred && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
if ( m_data->IsSupported( format ) )
{
int size = m_data->GetDataSize( format );
transferred = true ;
if (size == 0)
{
data.SetData(format , 0 , 0 ) ;
}
else
{
char *d = new char[size];
m_data->GetDataHere( format , (void*) d );
data.SetData( format , size , d ) ;
delete[] d ;
}
}
}
}
/* get formats from wxDataObjects */
if ( !transferred )
{
for (size_t i = 0; !transferred && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
switch ( format.GetType() )
{
case wxDF_TEXT :
case wxDF_OEMTEXT :
case wxDF_BITMAP :
case wxDF_METAFILE :
{
long len ;
char* s = (char*)wxGetClipboardData(format, &len );
if ( s )
{
data.SetData( format , len , s ) ;
delete [] s;
transferred = true ;
}
}
break ;
default :
break ;
}
}
}
delete[] array ;
return transferred ;
}

View File

@@ -0,0 +1,70 @@
/////////////////////////////////////////////////////////////////////////////
// Name: colordlg.cpp
// Purpose: wxColourDialog class. NOTE: you can use the generic class
// if you wish, instead of implementing this.
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "colordlg.h"
#endif
#include "wx/mac/colordlg.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
#endif
#include "wx/mac/private.h"
#ifndef __DARWIN__
#include <ColorPicker.h>
#endif
/*
* wxColourDialog
*/
wxColourDialog::wxColourDialog()
{
m_dialogParent = NULL;
}
wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
{
Create(parent, data);
}
bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
{
m_dialogParent = parent;
if (data)
m_colourData = *data;
return TRUE;
}
int wxColourDialog::ShowModal()
{
Point where ;
RGBColor currentColor = *((RGBColor*)m_colourData.m_dataColour.GetPixel()) , newColor ;
where.h = where.v = -1;
if (GetColor( where, "\pSelect a new palette color.", &currentColor, &newColor ))
{
m_colourData.m_dataColour.Set( (WXCOLORREF*) &newColor ) ;
return wxID_OK;
}
else
{
return wxID_CANCEL;
}
return wxID_CANCEL;
}

116
src/mac/classic/colour.cpp Normal file
View File

@@ -0,0 +1,116 @@
/////////////////////////////////////////////////////////////////////////////
// Name: colour.cpp
// Purpose: wxColour class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "colour.h"
#endif
#include "wx/gdicmn.h"
#include "wx/colour.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
#endif
// Colour
#include "wx/mac/private.h"
static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green ) ;
static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green )
{
RGBColor* col = (RGBColor*) color ;
col->red = (red << 8) + red;
col->blue = (blue << 8) + blue;
col->green = (green << 8) + green;
}
void wxColour::Init()
{
m_isInit = false;
m_red =
m_blue =
m_green = 0;
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
}
wxColour::wxColour (const wxColour& col)
: wxObject()
{
m_red = col.m_red;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
memcpy( &m_pixel , &col.m_pixel , 6 ) ;
}
wxColour::wxColour (const wxColour* col)
{
m_red = col->m_red;
m_green = col->m_green;
m_blue = col->m_blue;
m_isInit = col->m_isInit;
memcpy( &m_pixel , &col->m_pixel , 6 ) ;
}
wxColour& wxColour::operator =(const wxColour& col)
{
m_red = col.m_red;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
memcpy( &m_pixel , &col.m_pixel , 6 ) ;
return *this;
}
void wxColour::InitFromName(const wxString& name)
{
if ( wxTheColourDatabase )
{
wxColour col = wxTheColourDatabase->Find(name);
if ( col.Ok() )
{
*this = col;
return;
}
}
// leave invalid
Init();
}
wxColour::~wxColour ()
{
}
void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = true;
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
}
void wxColour::Set( const WXCOLORREF* color )
{
RGBColor* col = (RGBColor*) color ;
memcpy( &m_pixel , color , 6 ) ;
m_red = col->red>>8 ;
m_blue = col->blue>>8 ;
m_green = col->green>>8 ;
}

View File

@@ -0,0 +1,540 @@
/////////////////////////////////////////////////////////////////////////////
// Name: combobox.cpp
// Purpose: wxComboBox class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "combobox.h"
#endif
#include "wx/combobox.h"
#include "wx/button.h"
#include "wx/menu.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
#endif
// composite combobox implementation by Dan "Bud" Keith bud@otsys.com
static int nextPopUpMenuId = 1000 ;
MenuHandle NewUniqueMenu()
{
MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
nextPopUpMenuId++ ;
return handle ;
}
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// the margin between the text control and the choice
static const wxCoord MARGIN = 2;
static const int POPUPWIDTH = 18;
static const int POPUPHEIGHT = 23;
// ----------------------------------------------------------------------------
// wxComboBoxText: text control forwards events to combobox
// ----------------------------------------------------------------------------
class wxComboBoxText : public wxTextCtrl
{
public:
wxComboBoxText( wxComboBox * cb )
: wxTextCtrl( cb , 1 )
{
m_cb = cb;
}
protected:
void OnChar( wxKeyEvent& event )
{
if ( event.GetKeyCode() == WXK_RETURN )
{
wxString value = GetValue();
if ( m_cb->GetCount() == 0 )
{
// make Enter generate "selected" event if there is only one item
// in the combobox - without it, it's impossible to select it at
// all!
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
event.SetInt( 0 );
event.SetString( value );
event.SetEventObject( m_cb );
m_cb->GetEventHandler()->ProcessEvent( event );
}
else
{
// add the item to the list if it's not there yet
if ( m_cb->FindString(value) == wxNOT_FOUND )
{
m_cb->Append(value);
m_cb->SetStringSelection(value);
// and generate the selected event for it
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
event.SetInt( m_cb->GetCount() - 1 );
event.SetString( value );
event.SetEventObject( m_cb );
m_cb->GetEventHandler()->ProcessEvent( event );
}
// This will invoke the dialog default action, such
// as the clicking the default button.
wxWindow *parent = GetParent();
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
parent = parent->GetParent() ;
}
if ( parent && parent->GetDefaultItem() )
{
wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
wxButton);
if ( def && def->IsEnabled() )
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
event.SetEventObject(def);
def->Command(event);
return ;
}
}
return;
}
}
event.Skip();
}
private:
wxComboBox *m_cb;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
EVT_CHAR( wxComboBoxText::OnChar)
END_EVENT_TABLE()
class wxComboBoxChoice : public wxChoice
{
public:
wxComboBoxChoice(wxComboBox *cb, int style)
: wxChoice( cb , 1 )
{
m_cb = cb;
}
protected:
void OnChoice( wxCommandEvent& e )
{
wxString s = e.GetString();
m_cb->DelegateChoice( s );
wxCommandEvent event2(wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
event2.SetInt(m_cb->GetSelection());
event2.SetEventObject(m_cb);
event2.SetString(m_cb->GetStringSelection());
m_cb->ProcessCommand(event2);
}
private:
wxComboBox *m_cb;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxComboBoxChoice, wxChoice)
EVT_CHOICE(-1, wxComboBoxChoice::OnChoice)
END_EVENT_TABLE()
wxComboBox::~wxComboBox()
{
// delete client objects
FreeData();
// delete the controls now, don't leave them alive even though they would
// still be eventually deleted by our parent - but it will be too late, the
// user code expects them to be gone now
if (m_text != NULL) {
delete m_text;
m_text = NULL;
}
if (m_choice != NULL) {
delete m_choice;
m_choice = NULL;
}
}
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
wxSize wxComboBox::DoGetBestSize() const
{
wxSize size = m_choice->GetBestSize();
if ( m_text != NULL )
{
wxSize sizeText = m_text->GetBestSize();
size.x = POPUPWIDTH + sizeText.x + MARGIN;
}
return size;
}
void wxComboBox::DoMoveWindow(int x, int y, int width, int height) {
height = POPUPHEIGHT;
wxControl::DoMoveWindow(x, y, width, height);
if ( m_text == NULL )
{
m_choice->SetSize(0, 0 , width, -1);
}
else
{
wxCoord wText = width - POPUPWIDTH - MARGIN;
m_text->SetSize(0, 0, wText, height);
m_choice->SetSize(0 + wText + MARGIN, 0, POPUPWIDTH, -1);
}
}
// ----------------------------------------------------------------------------
// operations forwarded to the subcontrols
// ----------------------------------------------------------------------------
bool wxComboBox::Enable(bool enable)
{
if ( !wxControl::Enable(enable) )
return FALSE;
return TRUE;
}
bool wxComboBox::Show(bool show)
{
if ( !wxControl::Show(show) )
return FALSE;
return TRUE;
}
void wxComboBox::SetFocus()
{
if ( m_text != NULL) {
m_text->SetFocus();
}
}
void wxComboBox::DelegateTextChanged( const wxString& value )
{
SetStringSelection( value );
}
void wxComboBox::DelegateChoice( const wxString& value )
{
SetStringSelection( value );
}
bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
const wxArrayString& choices,
long style,
const wxValidator& validator,
const wxString& name)
{
wxCArrayString chs( choices );
return Create( parent, id, value, pos, size, chs.GetCount(),
chs.GetStrings(), style, validator, name );
}
bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
int n, const wxString choices[],
long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
wxDefaultValidator, name) )
{
return FALSE;
}
m_choice = new wxComboBoxChoice(this, style );
wxSize csize = size;
if ( style & wxCB_READONLY )
{
m_text = NULL;
}
else
{
m_text = new wxComboBoxText(this);
if ( size.y == -1 ) {
csize.y = m_text->GetSize().y ;
}
}
DoSetSize(pos.x, pos.y, csize.x, csize.y);
for ( int i = 0 ; i < n ; i++ )
{
m_choice->DoAppend( choices[ i ] );
}
return TRUE;
}
wxString wxComboBox::GetValue() const
{
wxString result;
if ( m_text == NULL )
{
result = m_choice->GetString( m_choice->GetSelection() );
}
else
{
result = m_text->GetValue();
}
return result;
}
void wxComboBox::SetValue(const wxString& value)
{
int s = FindString (value);
if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) )
{
m_choice->Append(value) ;
}
SetStringSelection( value ) ;
}
// Clipboard operations
void wxComboBox::Copy()
{
if ( m_text != NULL )
{
m_text->Copy();
}
}
void wxComboBox::Cut()
{
if ( m_text != NULL )
{
m_text->Cut();
}
}
void wxComboBox::Paste()
{
if ( m_text != NULL )
{
m_text->Paste();
}
}
void wxComboBox::SetEditable(bool editable)
{
if ( ( m_text == NULL ) && editable )
{
m_text = new wxComboBoxText( this );
}
else if ( ( m_text != NULL ) && !editable )
{
delete m_text;
m_text = NULL;
}
int currentX, currentY;
GetPosition( &currentX, &currentY );
int currentW, currentH;
GetSize( &currentW, &currentH );
DoMoveWindow( currentX, currentY, currentW, currentH );
}
void wxComboBox::SetInsertionPoint(long pos)
{
// TODO
}
void wxComboBox::SetInsertionPointEnd()
{
// TODO
}
long wxComboBox::GetInsertionPoint() const
{
// TODO
return 0;
}
long wxComboBox::GetLastPosition() const
{
// TODO
return 0;
}
void wxComboBox::Replace(long from, long to, const wxString& value)
{
// TODO
}
void wxComboBox::Remove(long from, long to)
{
// TODO
}
void wxComboBox::SetSelection(long from, long to)
{
// TODO
}
int wxComboBox::DoAppend(const wxString& item)
{
return m_choice->DoAppend( item ) ;
}
int wxComboBox::DoInsert(const wxString& item, int pos)
{
return m_choice->DoInsert( item , pos ) ;
}
void wxComboBox::DoSetItemClientData(int n, void* clientData)
{
return m_choice->DoSetItemClientData( n , clientData ) ;
}
void* wxComboBox::DoGetItemClientData(int n) const
{
return m_choice->DoGetItemClientData( n ) ;
}
void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData)
{
return m_choice->DoSetItemClientObject( n , clientData ) ;
}
wxClientData* wxComboBox::DoGetItemClientObject(int n) const
{
return m_choice->DoGetItemClientObject( n ) ;
}
void wxComboBox::FreeData()
{
if ( HasClientObjectData() )
{
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
SetClientObject( n, NULL );
}
}
}
void wxComboBox::Delete(int n)
{
// force client object deletion
if( HasClientObjectData() )
SetClientObject( n, NULL );
m_choice->Delete( n );
}
void wxComboBox::Clear()
{
FreeData();
m_choice->Clear();
}
int wxComboBox::GetSelection() const
{
return m_choice->GetSelection();
}
void wxComboBox::SetSelection(int n)
{
m_choice->SetSelection( n );
if ( m_text != NULL )
{
m_text->SetValue( GetString( n ) );
}
}
int wxComboBox::FindString(const wxString& s) const
{
return m_choice->FindString( s );
}
wxString wxComboBox::GetString(int n) const
{
return m_choice->GetString( n );
}
wxString wxComboBox::GetStringSelection() const
{
int sel = GetSelection ();
if (sel > -1)
return wxString(this->GetString (sel));
else
return wxEmptyString;
}
bool wxComboBox::SetStringSelection(const wxString& sel)
{
int s = FindString (sel);
if (s > -1)
{
SetSelection (s);
return TRUE;
}
else
return FALSE;
}
void wxComboBox::SetString(int n, const wxString& s)
{
m_choice->SetString( n , s ) ;
}
void wxComboBox::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown))
{
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
event.SetInt(GetSelection());
event.SetEventObject(this);
event.SetString(GetStringSelection());
ProcessCommand(event);
}

814
src/mac/classic/control.cpp Normal file
View File

@@ -0,0 +1,814 @@
/////////////////////////////////////////////////////////////////////////////
// Name: control.cpp
// Purpose: wxControl class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "control.h"
#endif
#include "wx/defs.h"
#include "wx/control.h"
#include "wx/panel.h"
#include "wx/app.h"
#include "wx/dc.h"
#include "wx/dcclient.h"
#include "wx/notebook.h"
#include "wx/tabctrl.h"
#include "wx/radiobox.h"
#include "wx/spinbutt.h"
#include "wx/scrolbar.h"
#include "wx/button.h"
#include "wx/dialog.h"
#include "wx/statbox.h"
#include "wx/sizer.h"
#include "wx/stattext.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
BEGIN_EVENT_TABLE(wxControl, wxWindow)
EVT_MOUSE_EVENTS( wxControl::OnMouseEvent )
EVT_PAINT( wxControl::OnPaint )
END_EVENT_TABLE()
#endif
#include "wx/mac/uma.h"
#include "wx/mac/private.h"
// Item members
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
typedef struct {
unsigned short instruction;
void (*function)();
} cdefRec, *cdefPtr, **cdefHandle;
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ;
pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ;
pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
{
if ( partCode != 0)
{
wxControl* wx = (wxControl*) GetControlReference( control ) ;
if ( wx )
{
wx->MacHandleControlClick( control , partCode , true /* stillDown */ ) ;
}
}
}
ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ;
ControlDefUPP wxMacControlActionUPP = NULL ;
pascal SInt32 wxMacControlDefinition(SInt16 varCode, ControlRef theControl, ControlDefProcMessage message, SInt32 param)
{
wxControl* wx = (wxControl*) wxFindControlFromMacControl( theControl ) ;
if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) )
{
if( message == drawCntl )
{
wxMacWindowClipper clip( wx ) ;
return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ;
}
else
return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ;
}
return NULL ;
}
pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor )
{
OSStatus status = noErr ;
switch( iMessage )
{
case kControlMsgSetUpBackground :
{
wxControl* wx = (wxControl*) GetControlReference( iControl ) ;
if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) )
{
wxDC::MacSetupBackgroundForCurrentPort( wx->MacGetBackgroundBrush() ) ;
#if TARGET_CARBON
// under classic this would lead to partial redraws
RgnHandle clip = NewRgn() ;
int x = 0 , y = 0;
wx->MacWindowToRootWindow( &x,&y ) ;
CopyRgn( (RgnHandle) wx->MacGetVisibleRegion(false).GetWXHRGN() , clip ) ;
OffsetRgn( clip , x , y ) ;
SetClip( clip ) ;
DisposeRgn( clip ) ;
#endif
}
else
{
status = paramErr ;
}
}
break ;
default :
status = paramErr ;
break ;
}
return status ;
}
wxControl::wxControl()
{
m_macControl = NULL ;
m_macControlAction = NULL ;
m_macHorizontalBorder = 0 ; // additional pixels around the real control
m_macVerticalBorder = 0 ;
m_backgroundColour = *wxWHITE;
m_foregroundColour = *wxBLACK;
if ( wxMacLiveScrollbarActionUPP == NULL )
{
#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
#else
wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
#endif
}
}
bool wxControl::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
m_macControl = NULL ;
m_macHorizontalBorder = 0 ; // additional pixels around the real control
m_macVerticalBorder = 0 ;
bool rval = wxWindow::Create(parent, id, pos, size, style, name);
if ( parent )
{
m_backgroundColour = parent->GetBackgroundColour() ;
m_foregroundColour = parent->GetForegroundColour() ;
}
if (rval) {
#if wxUSE_VALIDATORS
SetValidator(validator);
#endif
}
return rval;
}
wxControl::~wxControl()
{
m_isBeingDeleted = TRUE;
wxRemoveMacControlAssociation( this ) ;
// If we delete an item, we should initialize the parent panel,
// because it could now be invalid.
wxWindow *parent = GetParent() ;
if ( parent )
{
if (parent->GetDefaultItem() == (wxButton*) this)
parent->SetDefaultItem(NULL);
}
if ( (ControlHandle) m_macControl )
{
// in case the callback might be called during destruction
::SetControlColorProc( (ControlHandle) m_macControl , NULL ) ;
::DisposeControl( (ControlHandle) m_macControl ) ;
m_macControl = NULL ;
}
}
void wxControl::SetLabel(const wxString& title)
{
m_label = wxStripMenuCodes(title) ;
if ( m_macControl )
{
UMASetControlTitle( (ControlHandle) m_macControl , m_label , m_font.GetEncoding() ) ;
}
Refresh() ;
}
wxSize wxControl::DoGetBestSize() const
{
if ( (ControlHandle) m_macControl == NULL )
return wxWindow::DoGetBestSize() ;
Rect bestsize = { 0 , 0 , 0 , 0 } ;
short baselineoffset ;
int bestWidth, bestHeight ;
::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
if ( EmptyRect( &bestsize ) )
{
baselineoffset = 0;
bestsize.left = bestsize.top = 0 ;
bestsize.right = 16 ;
bestsize.bottom = 16 ;
if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
{
bestsize.bottom = 16 ;
}
else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
{
bestsize.bottom = 24 ;
}
}
bestWidth = bestsize.right - bestsize.left ;
bestWidth += 2 * m_macHorizontalBorder ;
bestHeight = bestsize.bottom - bestsize.top ;
if ( bestHeight < 10 )
bestHeight = 13 ;
bestHeight += 2 * m_macVerticalBorder;
return wxSize(bestWidth, bestHeight);
}
bool wxControl::ProcessCommand (wxCommandEvent & event)
{
// Tries:
// 1) OnCommand, starting at this window and working up parent hierarchy
// 2) OnCommand then calls ProcessEvent to search the event tables.
return GetEventHandler()->ProcessEvent(event);
}
// ------------------------
wxList *wxWinMacControlList = NULL;
wxControl *wxFindControlFromMacControl(ControlHandle inControl )
{
wxNode *node = wxWinMacControlList->Find((long)inControl);
if (!node)
return NULL;
return (wxControl *)node->GetData();
}
void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
{
// adding NULL WindowRef is (first) surely a result of an error and
// (secondly) breaks menu command processing
wxCHECK_RET( inControl != (ControlHandle) NULL, wxT("attempt to add a NULL WindowRef to window list") );
if ( !wxWinMacControlList->Find((long)inControl) )
wxWinMacControlList->Append((long)inControl, control);
}
void wxRemoveMacControlAssociation(wxControl *control)
{
if ( wxWinMacControlList )
wxWinMacControlList->DeleteObject(control);
}
void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel )
{
m_label = label ;
// These sizes will be adjusted in MacPostControlCreate
m_width = size.x ;
m_height = size.y ;
m_x = pos.x ;
m_y = pos.y ;
((Rect*)outBounds)->top = -10;
((Rect*)outBounds)->left = -10;
((Rect*)outBounds)->bottom = 0;
((Rect*)outBounds)->right = 0;
wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ;
}
void wxControl::MacPostControlCreate()
{
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
DoSetWindowVariant( m_windowVariant ) ;
/*
if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
{
// no font
}
else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
{
ControlFontStyleRec controlstyle ;
controlstyle.flags = kControlUseFontMask ;
controlstyle.font = kControlFontSmallBoldSystemFont ;
::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
}
else
{
ControlFontStyleRec controlstyle ;
controlstyle.flags = kControlUseFontMask ;
if (IsKindOf( CLASSINFO( wxButton ) ) )
controlstyle.font = kControlFontBigSystemFont ; // eventually kControlFontBigSystemFont ;
else
controlstyle.font = kControlFontSmallSystemFont ;
::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
}
*/
ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
::EmbedControl( (ControlHandle) m_macControl , container ) ;
m_macControlIsShown = MacIsReallyShown() ;
wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
if ( wxMacSetupControlBackgroundUPP == NULL )
{
wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
}
if ( wxMacControlActionUPP == NULL )
{
wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ;
}
// The following block of code is responsible for crashes when switching
// back to windows, which can be seen in the dialogs sample.
// It is disabled until a proper solution can be found.
#if 0
#if TARGET_CARBON
/*
only working under classic carbon
m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
(**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ;
*/
#else
m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
cdefHandle cdef ;
cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ;
if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL )
{
(**cdef).instruction = 0x4EF9; /* JMP instruction */
(**cdef).function = (void(*)()) wxMacControlActionUPP;
(**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ;
}
#endif
#endif
SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
// Adjust the controls size and position
wxPoint pos(m_x, m_y);
wxSize best_size( DoGetBestSize() );
wxSize new_size( m_width, m_height );
m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control
if (new_size.x == -1) {
new_size.x = best_size.x;
}
if (new_size.y == -1) {
new_size.y = best_size.y;
}
SetSize(pos.x, pos.y, new_size.x, new_size.y);
#if wxUSE_UNICODE
UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ;
#endif
if ( m_macControlIsShown )
UMAShowControl( (ControlHandle) m_macControl ) ;
SetCursor( *wxSTANDARD_CURSOR ) ;
Refresh() ;
}
void wxControl::MacAdjustControlRect()
{
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
if ( m_width == -1 || m_height == -1 )
{
Rect bestsize = { 0 , 0 , 0 , 0 } ;
short baselineoffset ;
::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
if ( EmptyRect( &bestsize ) )
{
baselineoffset = 0;
bestsize.left = bestsize.top = 0 ;
bestsize.right = 16 ;
bestsize.bottom = 16 ;
if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
{
bestsize.bottom = 16 ;
}
else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
{
bestsize.bottom = 24 ;
}
}
if ( m_width == -1 )
{
if ( IsKindOf( CLASSINFO( wxButton ) ) )
{
m_width = m_label.Length() * 8 + 12 ;
if ( m_width < 70 )
m_width = 70 ;
}
else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
{
m_width = m_label.Length() * 8 ;
}
else
m_width = bestsize.right - bestsize.left ;
m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
}
if ( m_height == -1 )
{
m_height = bestsize.bottom - bestsize.top ;
if ( m_height < 10 )
m_height = 13 ;
m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
}
MacUpdateDimensions() ;
}
}
WXWidget wxControl::MacGetContainerForEmbedding()
{
if ( m_macControl )
return m_macControl ;
return wxWindow::MacGetContainerForEmbedding() ;
}
void wxControl::MacUpdateDimensions()
{
// actually in the current systems this should never be possible, but later reparenting
// may become a reality
if ( (ControlHandle) m_macControl == NULL )
return ;
if ( GetParent() == NULL )
return ;
WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
if ( rootwindow == NULL )
return ;
Rect oldBounds ;
GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;
int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ;
int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ;
GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
if ( doMove || doResize )
{
InvalWindowRect( rootwindow, &oldBounds ) ;
if ( doMove )
{
UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
}
if ( doResize )
{
UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
}
}
}
void wxControl::MacSuperChangedPosition()
{
MacUpdateDimensions() ;
wxWindow::MacSuperChangedPosition() ;
}
void wxControl::MacSuperEnabled( bool enabled )
{
Refresh(FALSE) ;
wxWindow::MacSuperEnabled( enabled ) ;
}
void wxControl::MacSuperShown( bool show )
{
if ( (ControlHandle) m_macControl )
{
if ( !show )
{
if ( m_macControlIsShown )
{
::UMAHideControl( (ControlHandle) m_macControl ) ;
m_macControlIsShown = false ;
}
}
else
{
if ( MacIsReallyShown() && !m_macControlIsShown )
{
::UMAShowControl( (ControlHandle) m_macControl ) ;
m_macControlIsShown = true ;
}
}
}
wxWindow::MacSuperShown( show ) ;
}
void wxControl::DoSetSize(int x, int y,
int width, int height,
int sizeFlags )
{
wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
#if 0
{
Rect meta , control ;
GetControlBounds( (ControlHandle) m_macControl , &control ) ;
RgnHandle rgn = NewRgn() ;
GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ;
GetRegionBounds( rgn , &meta ) ;
if ( !EmptyRect( &meta ) )
{
wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ;
wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ;
wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ;
wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ;
}
DisposeRgn( rgn ) ;
}
#endif
return ;
}
bool wxControl::Show(bool show)
{
if ( !wxWindow::Show( show ) )
return FALSE ;
if ( (ControlHandle) m_macControl )
{
if ( !show )
{
if ( m_macControlIsShown )
{
::UMAHideControl( (ControlHandle) m_macControl ) ;
m_macControlIsShown = false ;
}
}
else
{
if ( MacIsReallyShown() && !m_macControlIsShown )
{
::UMAShowControl( (ControlHandle) m_macControl ) ;
m_macControlIsShown = true ;
}
}
}
return TRUE ;
}
bool wxControl::Enable(bool enable)
{
if ( !wxWindow::Enable(enable) )
return FALSE;
if ( (ControlHandle) m_macControl )
{
if ( enable )
UMAActivateControl( (ControlHandle) m_macControl ) ;
else
UMADeactivateControl( (ControlHandle) m_macControl ) ;
}
return TRUE ;
}
void wxControl::Refresh(bool eraseBack, const wxRect *rect)
{
wxWindow::Refresh( eraseBack , rect ) ;
}
void wxControl::MacRedrawControl()
{
if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown )
{
wxClientDC dc(this) ;
wxMacPortSetter helper(&dc) ;
wxMacWindowClipper clipper(this) ;
wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
UMADrawControl( (ControlHandle) m_macControl ) ;
}
}
void wxControl::OnPaint(wxPaintEvent& event)
{
if ( (ControlHandle) m_macControl )
{
wxPaintDC dc(this) ;
wxMacPortSetter helper(&dc) ;
wxMacWindowClipper clipper(this) ;
wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
UMADrawControl( (ControlHandle) m_macControl ) ;
}
else
{
event.Skip() ;
}
}
void wxControl::OnEraseBackground(wxEraseEvent& event)
{
wxWindow::OnEraseBackground( event ) ;
}
void wxControl::OnKeyDown( wxKeyEvent &event )
{
if ( (ControlHandle) m_macControl == NULL )
return ;
#if TARGET_CARBON
char charCode ;
UInt32 keyCode ;
UInt32 modifiers ;
GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ;
#else
EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
short keycode ;
short keychar ;
keychar = short(ev->message & charCodeMask);
keycode = short(ev->message & keyCodeMask) >> 8 ;
::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
#endif
}
void wxControl::OnMouseEvent( wxMouseEvent &event )
{
if ( (ControlHandle) m_macControl == NULL )
{
event.Skip() ;
return ;
}
if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
{
int x = event.m_x ;
int y = event.m_y ;
MacClientToRootWindow( &x , &y ) ;
ControlHandle control ;
Point localwhere ;
SInt16 controlpart ;
localwhere.h = x ;
localwhere.v = y ;
short modifiers = 0;
if ( !event.m_leftDown && !event.m_rightDown )
modifiers |= btnState ;
if ( event.m_shiftDown )
modifiers |= shiftKey ;
if ( event.m_controlDown )
modifiers |= controlKey ;
if ( event.m_altDown )
modifiers |= optionKey ;
if ( event.m_metaDown )
modifiers |= cmdKey ;
{
control = (ControlHandle) m_macControl ;
if ( control && ::IsControlActive( control ) )
{
{
controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
wxTheApp->s_lastMouseDown = 0 ;
if ( control && controlpart != kControlNoPart )
{
MacHandleControlClick( control , controlpart , false /* mouse not down anymore */ ) ;
}
}
}
}
}
else
{
event.Skip() ;
}
}
bool wxControl::MacCanFocus() const
{
if ( (ControlHandle) m_macControl == NULL )
return true ;
else
return false ;
}
void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
{
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
}
void wxControl::DoSetWindowVariant( wxWindowVariant variant )
{
if ( m_macControl == NULL )
{
wxWindow::SetWindowVariant( variant ) ;
return ;
}
m_windowVariant = variant ;
ControlSize size ;
ControlFontStyleRec fontStyle;
fontStyle.flags = kControlUseFontMask ;
// we will get that from the settings later
// and make this NORMAL later, but first
// we have a few calculations that we must fix
if ( variant == wxWINDOW_VARIANT_DEFAULT )
{
if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
variant = wxWINDOW_VARIANT_NORMAL ;
else
variant = wxWINDOW_VARIANT_SMALL ;
}
switch ( variant )
{
case wxWINDOW_VARIANT_NORMAL :
size = kControlSizeNormal;
fontStyle.font = kControlFontBigSystemFont;
break ;
case wxWINDOW_VARIANT_SMALL :
size = kControlSizeSmall;
fontStyle.font = kControlFontSmallSystemFont;
break ;
case wxWINDOW_VARIANT_MINI :
if (UMAGetSystemVersion() >= 0x1030 )
{
size = 3 ; // not always defined in the header
fontStyle.font = -5 ; // not always defined in the header
}
else
{
size = kControlSizeSmall;
fontStyle.font = kControlFontSmallSystemFont;
}
break;
break ;
case wxWINDOW_VARIANT_LARGE :
size = kControlSizeLarge;
fontStyle.font = kControlFontBigSystemFont;
break ;
default:
wxFAIL_MSG(_T("unexpected window variant"));
break ;
}
::SetControlData( (ControlHandle) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size );
::SetControlFontStyle( (ControlHandle) m_macControl , &fontStyle );
}

159
src/mac/classic/corersrc.r Normal file
View File

@@ -0,0 +1,159 @@
#ifdef __UNIX__
#include <Carbon.r>
#else
#include <Types.r>
#if UNIVERSAL_INTERFACES_VERSION > 0x320
#include <ControlDefinitions.r>
#endif
#endif
resource 'ldes' ( 128 )
{
versionZero
{
0 ,
0 ,
0 ,
0 ,
hasVertScroll ,
noHorizScroll ,
0 ,
noGrowSpace ,
}
} ;
resource 'ldes' ( 129 )
{
versionZero
{
0 ,
0 ,
0 ,
0 ,
hasVertScroll ,
hasHorizScroll ,
0 ,
noGrowSpace ,
}
} ;
data 'CURS' (10) {
$"0000 03E0 0630 0808 1004 31C6 2362 2222"
$"2362 31C6 1004 0808 0630 03E0 0000 0000"
$"0000 03E0 07F0 0FF8 1FFC 3FFE 3FFE 3FFE"
$"3FFE 3FFE 1FFC 0FF8 07F0 03E0 0000 0000"
$"0007 0008"
};
data 'CURS' (11) {
$"0000 0000 0000 0000 0000 0000 0000 0000"
$"0000 0000 0000 0000 0000 0000 0000 0000"
$"0000 0000 0000 0000 0000 0000 0000 0000"
$"0000 0000 0000 0000 0000 0000 0000 0000"
$"0000 0000"
};
data 'CURS' (12) {
$"00F0 0088 0108 0190 0270 0220 0440 0440"
$"0880 0880 1100 1E00 1C00 1800 1000 0000"
$"00F0 00F8 01F8 01F0 03F0 03E0 07C0 07C0"
$"0F80 0F80 1F00 1E00 1C00 1800 1000 0000"
$"000E 0003"
};
data 'CURS' (13) {
$"0000 1E00 2100 4080 4080 4080 4080 2180"
$"1FC0 00E0 0070 0038 001C 000E 0006 0000"
$"3F00 7F80 FFC0 FFC0 FFC0 FFC0 FFC0 7FC0"
$"3FE0 1FF0 00F8 007C 003E 001F 000F 0007"
$"0004 0004"
};
data 'CURS' (14) {
$"0000 07E0 1FF0 3838 3C0C 6E0E 6706 6386"
$"61C6 60E6 7076 303C 1C1C 0FF8 07E0 0000"
$"0540 0FF0 3FF8 3C3C 7E0E FF0F 6F86 E7C7"
$"63E6 E1F7 70FE 707E 3C3C 1FFC 0FF0 0540"
$"0007 0007"
};
data 'CURS' (15) {
$"0000 0380 0380 0380 0380 0380 0380 0FE0"
$"1FF0 1FF0 0000 1FF0 1FF0 1550 1550 1550"
$"07C0 07C0 07C0 07C0 07C0 07C0 0FE0 1FF0"
$"3FF8 3FF8 3FF8 3FF8 3FF8 3FF8 3FF8 3FF8"
$"000B 0007"
};
data 'CURS' (16) {
$"00C0 0140 0640 08C0 3180 47FE 8001 8001"
$"81FE 8040 01C0 0040 03C0 C080 3F80 0000"
$"00C0 01C0 07C0 0FC0 3F80 7FFE FFFF FFFF"
$"FFFE FFC0 FFC0 FFC0 FFC0 FF80 3F80 0000"
$"0006 000F"
};
data 'CURS' (17) {
$"0100 0280 0260 0310 018C 7FE3 8000 8000"
$"7F80 0200 0380 0200 03C0 0107 01F8 0000"
$"0100 0380 03E0 03F0 01FC 7FFF FFFF FFFF"
$"FFFF 03FF 03FF 03FF 03FF 01FF 01F8 0000"
$"0006 0000"
};
data 'CURS' (18) {
$"0000 4078 60FC 71CE 7986 7C06 7E0E 7F1C"
$"7FB8 7C30 6C30 4600 0630 0330 0300 0000"
$"C078 E0FC F1FE FBFF FFCF FF8F FF1F FFBE"
$"FFFC FE78 FF78 EFF8 CFF8 87F8 07F8 0300"
$"0001 0001"
};
data 'CURS' (19) {
$"0000 0002 0006 000E 001E 003E 007E 00FE"
$"01FE 003E 0036 0062 0060 00C0 00C0 0000"
$"0003 0007 000F 001F 003F 007F 00FF 01FF"
$"03FF 07FF 007F 00F7 00F3 01E1 01E0 01C0"
$"0001 000E"
};
data 'CURS' (20) {
$"0000 0080 01C0 03E0 0080 0080 0080 1FFC"
$"1FFC 0080 0080 0080 03E0 01C0 0080 0000"
$"0080 01C0 03E0 07F0 0FF8 01C0 3FFE 3FFE"
$"3FFE 3FFE 01C0 0FF8 07F0 03E0 01C0 0080"
$"0007 0008"
};
data 'CURS' (21) {
$"0000 0080 01C0 03E0 0080 0888 188C 3FFE"
$"188C 0888 0080 03E0 01C0 0080 0000 0000"
$"0080 01C0 03E0 07F0 0BE8 1DDC 3FFE 7FFF"
$"3FFE 1DDC 0BE8 07F0 03E0 01C0 0080 0000"
$"0007 0008"
};
data 'CURS' (22) {
$"0000 001E 000E 060E 0712 03A0 01C0 00E0"
$"0170 1238 1C18 1C00 1E00 0000 0000 0000"
$"007F 003F 0E1F 0F0F 0F97 07E3 03E1 21F0"
$"31F8 3A7C 3C3C 3E1C 3F00 3F80 0000 0000"
$"0006 0009"
};
data 'CURS' (23) {
$"0000 7800 7000 7060 48E0 05C0 0380 0700"
$"0E80 1C48 1838 0038 0078 0000 0000 0000"
$"FE00 FC00 F870 F0F0 E9F0 C7E0 87C0 0F84"
$"1F8C 3E5C 3C3C 387C 00FC 01FC 0000 0000"
$"0006 0006"
};
data 'CURS' (24) {
$"0006 000E 001C 0018 0020 0040 00F8 0004"
$"1FF4 200C 2AA8 1FF0 1F80 3800 6000 8000"
$"000F 001F 003E 007C 0070 00E0 01FC 3FF6"
$"7FF6 7FFE 7FFC 7FF8 3FF0 7FC0 F800 E000"
$"000A 0006"
};

505
src/mac/classic/cursor.cpp Normal file
View File

@@ -0,0 +1,505 @@
/////////////////////////////////////////////////////////////////////////////
// Name: cursor.cpp
// Purpose: wxCursor class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "cursor.h"
#endif
#include "wx/defs.h"
#include "wx/app.h"
#include "wx/cursor.h"
#include "wx/icon.h"
#include "wx/image.h"
#include "wx/xpmdecod.h"
#include "wx/mac/private.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
#endif
const short kwxCursorBullseye = 10 ;
const short kwxCursorBlank = 11 ;
const short kwxCursorPencil = 12 ;
const short kwxCursorMagnifier = 13 ;
const short kwxCursorNoEntry = 14 ;
const short kwxCursorPaintBrush = 15 ;
const short kwxCursorPointRight = 16 ;
const short kwxCursorPointLeft = 17 ;
const short kwxCursorQuestionArrow = 18 ;
const short kwxCursorRightArrow = 19 ;
const short kwxCursorSizeNS = 20 ;
const short kwxCursorSize = 21 ;
const short kwxCursorSizeNESW = 22 ;
const short kwxCursorSizeNWSE = 23 ;
const short kwxCursorRoller = 24 ;
wxCursor gMacCurrentCursor ;
wxCursorRefData::wxCursorRefData()
{
m_width = 16;
m_height = 16;
m_hCursor = NULL ;
m_disposeHandle = false ;
m_releaseHandle = false ;
m_isColorCursor = false ;
m_themeCursor = -1 ;
}
wxCursorRefData::~wxCursorRefData()
{
if ( m_isColorCursor )
{
::DisposeCCursor( (CCrsrHandle) m_hCursor ) ;
}
else if ( m_disposeHandle )
{
::DisposeHandle( (Handle ) m_hCursor ) ;
}
else if ( m_releaseHandle )
{
// we don't release the resource since it may already
// be in use again
}
}
// Cursors
wxCursor::wxCursor()
{
}
wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height),
int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[])
{
}
wxCursor::wxCursor( const wxImage &image )
{
CreateFromImage( image ) ;
}
wxCursor::wxCursor(const char **bits)
{
(void) CreateFromXpm(bits);
}
wxCursor::wxCursor(char **bits)
{
(void) CreateFromXpm((const char **)bits);
}
bool wxCursor::CreateFromXpm(const char **bits)
{
wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid cursor data") )
wxXPMDecoder decoder;
wxImage img = decoder.ReadData(bits);
wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid cursor data") )
CreateFromImage( img ) ;
return TRUE;
}
short GetCTabIndex( CTabHandle colors , RGBColor *col )
{
short retval = 0 ;
unsigned long bestdiff = 0xFFFF ;
for ( int i = 0 ; i < (**colors).ctSize ; ++i )
{
unsigned long diff = abs(col->red - (**colors).ctTable[i].rgb.red ) +
abs(col->green - (**colors).ctTable[i].rgb.green ) +
abs(col->blue - (**colors).ctTable[i].rgb.blue ) ;
if ( diff < bestdiff )
{
bestdiff = diff ;
retval = (**colors).ctTable[i].value ;
}
}
return retval ;
}
void wxCursor::CreateFromImage(const wxImage & image)
{
m_refData = new wxCursorRefData;
wxImage image16 = image.Scale(16,16) ;
unsigned char * rgbBits = image16.GetData();
int w = image16.GetWidth() ;
int h = image16.GetHeight() ;
bool bHasMask = image16.HasMask() ;
int hotSpotX = image16.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
int hotSpotY = image16.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
if (hotSpotX < 0 || hotSpotX >= w)
hotSpotX = 0;
if (hotSpotY < 0 || hotSpotY >= h)
hotSpotY = 0;
#if 0
// monochrome implementation
M_CURSORDATA->m_hCursor = NewHandle( sizeof( Cursor ) ) ;
M_CURSORDATA->m_disposeHandle = true ;
HLock( (Handle) M_CURSORDATA->m_hCursor ) ;
CursPtr cp = *(CursHandle)M_CURSORDATA->m_hCursor ;
memset( cp->data , 0 , sizeof( Bits16 ) ) ;
memset( cp->mask , 0 , sizeof( Bits16 ) ) ;
unsigned char mr = image16.GetMaskRed() ;
unsigned char mg = image16.GetMaskGreen() ;
unsigned char mb = image16.GetMaskBlue() ;
for ( int y = 0 ; y < h ; ++y )
{
short rowbits = 0 ;
short maskbits = 0 ;
for ( int x = 0 ; x < w ; ++x )
{
long pos = (y * w + x) * 3;
unsigned char r = rgbBits[pos] ;
unsigned char g = rgbBits[pos+1] ;
unsigned char b = rgbBits[pos+2] ;
if ( bHasMask && r==mr && g==mg && b==mb )
{
// masked area, does not appear anywhere
}
else
{
if ( (int)r + (int)g + (int)b < 0x0200 )
{
rowbits |= ( 1 << (15-x) ) ;
}
maskbits |= ( 1 << (15-x) ) ;
}
}
cp->data[y] = rowbits ;
cp->mask[y] = maskbits ;
}
if ( !bHasMask )
{
memcpy( cp->mask , cp->data , sizeof( Bits16) ) ;
}
cp->hotSpot.h = hotSpotX ;
cp->hotSpot.v = hotSpotY ;
HUnlock( (Handle) M_CURSORDATA->m_hCursor ) ;
#else
PixMapHandle pm = (PixMapHandle) NewHandleClear( sizeof (PixMap)) ;
short extent = 16 ;
short bytesPerPixel = 1 ;
short depth = 8 ;
Rect bounds = { 0 , 0 , extent , extent } ;
CCrsrHandle ch = (CCrsrHandle) NewHandleClear ( sizeof( CCrsr ) ) ;
CTabHandle newColors = GetCTable( 8 ) ;
HandToHand((Handle *) &newColors);
// set the values to the indices
for ( int i = 0 ; i < (**newColors).ctSize ; ++i )
{
(**newColors).ctTable[i].value = i ;
}
HLock( (Handle) ch) ;
(**ch).crsrType = 0x8001 ; // color cursors
(**ch).crsrMap = pm ;
short bytesPerRow = bytesPerPixel * extent ;
(**pm).baseAddr = 0;
(**pm).rowBytes = bytesPerRow | 0x8000;
(**pm).bounds = bounds;
(**pm).pmVersion = 0;
(**pm).packType = 0;
(**pm).packSize = 0;
(**pm).hRes = 0x00480000; /* 72 DPI default res */
(**pm).vRes = 0x00480000; /* 72 DPI default res */
(**pm).pixelSize = depth;
(**pm).pixelType = 0;
(**pm).cmpCount = 1;
(**pm).cmpSize = depth;
(**pm).pmTable = newColors;
(**ch).crsrData = NewHandleClear( extent * bytesPerRow ) ;
(**ch).crsrXData = NULL ;
(**ch).crsrXValid = 0;
(**ch).crsrXHandle = NULL;
(**ch).crsrHotSpot.h = hotSpotX ;
(**ch).crsrHotSpot.v = hotSpotY ;
(**ch).crsrXTable = NULL ;
(**ch).crsrID = GetCTSeed() ;
memset( (**ch).crsr1Data , 0 , sizeof( Bits16 ) ) ;
memset( (**ch).crsrMask , 0 , sizeof( Bits16 ) ) ;
unsigned char mr = image16.GetMaskRed() ;
unsigned char mg = image16.GetMaskGreen() ;
unsigned char mb = image16.GetMaskBlue() ;
for ( int y = 0 ; y < h ; ++y )
{
short rowbits = 0 ;
short maskbits = 0 ;
for ( int x = 0 ; x < w ; ++x )
{
long pos = (y * w + x) * 3;
unsigned char r = rgbBits[pos] ;
unsigned char g = rgbBits[pos+1] ;
unsigned char b = rgbBits[pos+2] ;
RGBColor col = { 0xFFFF ,0xFFFF, 0xFFFF } ;
if ( bHasMask && r==mr && g==mg && b==mb )
{
// masked area, does not appear anywhere
}
else
{
if ( (int)r + (int)g + (int)b < 0x0200 )
{
rowbits |= ( 1 << (15-x) ) ;
}
maskbits |= ( 1 << (15-x) ) ;
col = *((RGBColor*) wxColor( r , g , b ).GetPixel()) ;
}
*((*(**ch).crsrData) + y * bytesPerRow + x) =
GetCTabIndex( newColors , &col) ;
}
(**ch).crsr1Data[y] = rowbits ;
(**ch).crsrMask[y] = maskbits ;
}
if ( !bHasMask )
{
memcpy( (**ch).crsrMask , (**ch).crsr1Data , sizeof( Bits16) ) ;
}
HUnlock((Handle) ch) ;
M_CURSORDATA->m_hCursor = ch ;
M_CURSORDATA->m_isColorCursor = true ;
#endif
}
wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
{
m_refData = new wxCursorRefData;
if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
{
Str255 theName ;
wxMacStringToPascal( cursor_file , theName ) ;
wxStAppResource resload ;
Handle resHandle = ::GetNamedResource( 'crsr' , theName ) ;
if ( resHandle )
{
short theId = -1 ;
OSType theType ;
GetResInfo( resHandle , &theId , &theType , theName ) ;
ReleaseResource( resHandle ) ;
M_CURSORDATA->m_hCursor = GetCCursor( theId ) ;
if ( M_CURSORDATA->m_hCursor )
M_CURSORDATA->m_isColorCursor = true ;
}
else
{
Handle resHandle = ::GetNamedResource( 'CURS' , theName ) ;
if ( resHandle )
{
short theId = -1 ;
OSType theType ;
GetResInfo( resHandle , &theId , &theType , theName ) ;
ReleaseResource( resHandle ) ;
M_CURSORDATA->m_hCursor = GetCursor( theId ) ;
if ( M_CURSORDATA->m_hCursor )
M_CURSORDATA->m_releaseHandle = true ;
}
}
}
else
{
wxImage image ;
image.LoadFile( cursor_file , flags ) ;
if( image.Ok() )
{
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,hotSpotX ) ;
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,hotSpotY ) ;
delete m_refData ;
CreateFromImage(image) ;
}
}
}
// Cursors by stock number
wxCursor::wxCursor(int cursor_type)
{
m_refData = new wxCursorRefData;
switch (cursor_type)
{
case wxCURSOR_COPY_ARROW:
M_CURSORDATA->m_themeCursor = kThemeCopyArrowCursor ;
break;
case wxCURSOR_WAIT:
M_CURSORDATA->m_themeCursor = kThemeWatchCursor ;
break;
case wxCURSOR_IBEAM:
M_CURSORDATA->m_themeCursor = kThemeIBeamCursor ;
break;
case wxCURSOR_CROSS:
M_CURSORDATA->m_themeCursor = kThemeCrossCursor;
break;
case wxCURSOR_SIZENWSE:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorSizeNWSE);
}
break;
case wxCURSOR_SIZENESW:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorSizeNESW);
}
break;
case wxCURSOR_SIZEWE:
{
M_CURSORDATA->m_themeCursor = kThemeResizeLeftRightCursor;
}
break;
case wxCURSOR_SIZENS:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorSizeNS);
}
break;
case wxCURSOR_SIZING:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorSize);
}
break;
case wxCURSOR_HAND:
{
M_CURSORDATA->m_themeCursor = kThemePointingHandCursor;
}
break;
case wxCURSOR_BULLSEYE:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorBullseye);
}
break;
case wxCURSOR_PENCIL:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorPencil);
}
break;
case wxCURSOR_MAGNIFIER:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorMagnifier);
}
break;
case wxCURSOR_NO_ENTRY:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorNoEntry);
}
break;
case wxCURSOR_WATCH:
{
M_CURSORDATA->m_themeCursor = kThemeWatchCursor;
break;
}
case wxCURSOR_PAINT_BRUSH:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorPaintBrush);
break;
}
case wxCURSOR_POINT_LEFT:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorPointLeft);
break;
}
case wxCURSOR_POINT_RIGHT:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorPointRight);
break;
}
case wxCURSOR_QUESTION_ARROW:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorQuestionArrow);
break;
}
case wxCURSOR_BLANK:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorBlank);
break;
}
case wxCURSOR_RIGHT_ARROW:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorRightArrow);
break;
}
case wxCURSOR_SPRAYCAN:
{
wxStAppResource resload ;
M_CURSORDATA->m_hCursor = ::GetCursor(kwxCursorRoller);
break;
}
case wxCURSOR_CHAR:
case wxCURSOR_ARROW:
case wxCURSOR_LEFT_BUTTON:
case wxCURSOR_RIGHT_BUTTON:
case wxCURSOR_MIDDLE_BUTTON:
default:
M_CURSORDATA->m_themeCursor = kThemeArrowCursor ;
break;
}
if ( M_CURSORDATA->m_themeCursor == -1 )
M_CURSORDATA->m_releaseHandle = true ;
}
void wxCursor::MacInstall() const
{
gMacCurrentCursor = *this ;
if ( m_refData && M_CURSORDATA->m_themeCursor != -1 )
{
SetThemeCursor( M_CURSORDATA->m_themeCursor ) ;
}
else if ( m_refData && M_CURSORDATA->m_hCursor )
{
if ( M_CURSORDATA->m_isColorCursor )
::SetCCursor( (CCrsrHandle) M_CURSORDATA->m_hCursor ) ;
else
::SetCursor( * (CursHandle) M_CURSORDATA->m_hCursor ) ;
}
else
{
SetThemeCursor( kThemeArrowCursor ) ;
}
}
wxCursor::~wxCursor()
{
}
// Global cursor setting
void wxSetCursor(const wxCursor& cursor)
{
cursor.MacInstall() ;
}

25
src/mac/classic/data.cpp Normal file
View File

@@ -0,0 +1,25 @@
/////////////////////////////////////////////////////////////////////////////
// Name: mac/data.cpp
// Purpose: Various global Mac-specific data
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/event.h"
#if wxUSE_SHARED_LIBRARY
///// Event tables (also must be in one, statically-linked file for shared libraries)
// This is the base, wxEvtHandler 'bootstrap' code which is expanded manually here
const wxEventTable *wxEvtHandler::GetEventTable() const { return &wxEvtHandler::sm_eventTable; }
const wxEventTable wxEvtHandler::sm_eventTable =
{ NULL, &wxEvtHandler::sm_eventTableEntries[0] };
const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { { 0, 0, 0, NULL } };
#endif

308
src/mac/classic/dataobj.cpp Normal file
View File

@@ -0,0 +1,308 @@
///////////////////////////////////////////////////////////////////////////////
// Name: mac/dataobj.cpp
// Purpose: implementation of wxDataObject class
// Author: Stefan Csomor
// Modified by:
// Created: 10/21/99
// RCS-ID: $Id$
// Copyright: (c) 1999 Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// 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"
#include "wx/mac/private.h"
#include <Scrap.h>
// ----------------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxDataFormat
// ----------------------------------------------------------------------------
wxDataFormat::wxDataFormat()
{
m_type = wxDF_INVALID;
m_format = 0;
}
wxDataFormat::wxDataFormat( wxDataFormatId vType )
{
SetType(vType);
}
wxDataFormat::wxDataFormat( const wxChar* zId)
{
SetId(zId);
}
wxDataFormat::wxDataFormat( const wxString& rId)
{
SetId(rId);
}
wxDataFormat::wxDataFormat( NativeFormat vFormat)
{
SetId(vFormat);
}
void wxDataFormat::SetType( wxDataFormatId Type )
{
m_type = Type;
if (m_type == wxDF_TEXT )
m_format = kScrapFlavorTypeText;
else if (m_type == wxDF_UNICODETEXT )
m_format = kScrapFlavorTypeUnicode ;
else if (m_type == wxDF_BITMAP || m_type == wxDF_METAFILE )
m_format = kScrapFlavorTypePicture;
else if (m_type == wxDF_FILENAME)
m_format = kDragFlavorTypeHFS ;
else
{
wxFAIL_MSG( wxT("invalid dataformat") );
// this is '????' but it can't be used in the code because ??' is
// parsed as a trigraph!
m_format = 0x3f3f3f3f;
}
}
wxString wxDataFormat::GetId() const
{
// note that m_format is not a pointer to string, it *is* itself a 4
// character string
char text[5] ;
strncpy( text , (char*) &m_format , 4 ) ;
text[4] = 0 ;
return wxString::FromAscii( text ) ;
}
void wxDataFormat::SetId( NativeFormat format )
{
m_format = format;
if (m_format == kScrapFlavorTypeText)
m_type = wxDF_TEXT;
else if (m_format == kScrapFlavorTypeUnicode )
m_type = wxDF_UNICODETEXT;
else if (m_format == kScrapFlavorTypePicture)
m_type = wxDF_BITMAP;
else if (m_format == kDragFlavorTypeHFS )
m_type = wxDF_FILENAME;
else
m_type = wxDF_PRIVATE;
}
void wxDataFormat::SetId( const wxChar* zId )
{
m_type = wxDF_PRIVATE;
m_format = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), 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
)
{
m_filenames.Empty();
AddFile(wxString::FromAscii((char*)pBuf));
return TRUE;
}
void wxFileDataObject::AddFile(
const wxString& rFilename
)
{
m_filenames.Add(rFilename);
}
// ----------------------------------------------------------------------------
// wxBitmapDataObject
// ----------------------------------------------------------------------------
wxBitmapDataObject::wxBitmapDataObject()
{
Init();
}
wxBitmapDataObject::wxBitmapDataObject(
const wxBitmap& rBitmap
)
: wxBitmapDataObjectBase(rBitmap)
{
Init();
if ( m_bitmap.Ok() )
{
m_pictHandle = m_bitmap.GetPict( &m_pictCreated ) ;
}
}
wxBitmapDataObject::~wxBitmapDataObject()
{
Clear();
}
void wxBitmapDataObject::SetBitmap(
const wxBitmap& rBitmap
)
{
Clear();
wxBitmapDataObjectBase::SetBitmap(rBitmap);
if ( m_bitmap.Ok() )
{
m_pictHandle = m_bitmap.GetPict( &m_pictCreated ) ;
}
}
void wxBitmapDataObject::Init()
{
m_pictHandle = NULL ;
m_pictCreated = false ;
}
void wxBitmapDataObject::Clear()
{
if ( m_pictCreated && m_pictHandle )
{
KillPicture( (PicHandle) m_pictHandle ) ;
}
m_pictHandle = NULL ;
}
bool wxBitmapDataObject::GetDataHere(
void* pBuf
) const
{
if (!m_pictHandle)
{
wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
return FALSE;
}
memcpy(pBuf, *(Handle)m_pictHandle, GetHandleSize((Handle)m_pictHandle));
return TRUE;
}
size_t wxBitmapDataObject::GetDataSize() const
{
return GetHandleSize((Handle)m_pictHandle) ;
}
bool wxBitmapDataObject::SetData(
size_t nSize
, const void* pBuf
)
{
Clear();
PicHandle picHandle = (PicHandle) NewHandle( nSize ) ;
memcpy( *picHandle , pBuf , nSize ) ;
m_pictHandle = picHandle ;
m_pictCreated = false ;
Rect frame = (**picHandle).picFrame ;
m_bitmap.SetPict( picHandle ) ;
m_bitmap.SetWidth( frame.right - frame.left ) ;
m_bitmap.SetHeight( frame.bottom - frame.top ) ;
return m_bitmap.Ok();
}

2297
src/mac/classic/dc.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,175 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcclient.cpp
// Purpose: wxClientDC class
// Author: Stefan Csomor
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcclient.h"
#endif
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#include "wx/region.h"
#include "wx/window.h"
#include "wx/toplevel.h"
#include <math.h>
#include "wx/mac/private.h"
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
#define RAD2DEG 57.2957795131
//-----------------------------------------------------------------------------
// wxPaintDC
//-----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
#endif
/*
* wxWindowDC
*/
#include "wx/mac/uma.h"
wxWindowDC::wxWindowDC()
{
m_window = NULL ;
}
wxWindowDC::wxWindowDC(wxWindow *window)
{
m_window = window ;
wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
int x , y ;
x = y = 0 ;
window->MacWindowToRootWindow( &x , &y ) ;
m_macLocalOrigin.x = x ;
m_macLocalOrigin.y = y ;
CopyRgn( (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
m_macPort = UMAGetWindowPort( windowref ) ;
m_ok = TRUE ;
SetBackground(window->MacGetBackgroundBrush());
}
wxWindowDC::~wxWindowDC()
{
}
void wxWindowDC::DoGetSize( int* width, int* height ) const
{
wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
m_window->GetSize(width, height);
}
/*
* wxClientDC
*/
wxClientDC::wxClientDC()
{
m_window = NULL ;
}
wxClientDC::wxClientDC(wxWindow *window)
{
m_window = window ;
wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
if (!rootwindow)
return;
WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
wxPoint origin = window->GetClientAreaOrigin() ;
wxSize size = window->GetClientSize() ;
int x , y ;
x = origin.x ;
y = origin.y ;
window->MacWindowToRootWindow( &x , &y ) ;
m_macLocalOrigin.x = x ;
m_macLocalOrigin.y = y ;
SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
m_macPort = UMAGetWindowPort( windowref ) ;
m_ok = TRUE ;
SetBackground(window->MacGetBackgroundBrush());
SetFont( window->GetFont() ) ;
}
wxClientDC::~wxClientDC()
{
}
void wxClientDC::DoGetSize(int *width, int *height) const
{
wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
m_window->GetClientSize( width, height );
}
/*
* wxPaintDC
*/
wxPaintDC::wxPaintDC()
{
m_window = NULL ;
}
wxPaintDC::wxPaintDC(wxWindow *window)
{
m_window = window ;
wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
wxPoint origin = window->GetClientAreaOrigin() ;
wxSize size = window->GetClientSize() ;
int x , y ;
x = origin.x ;
y = origin.y ;
window->MacWindowToRootWindow( &x , &y ) ;
m_macLocalOrigin.x = x ;
m_macLocalOrigin.y = y ;
SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
m_macPort = UMAGetWindowPort( windowref ) ;
m_ok = TRUE ;
SetBackground(window->MacGetBackgroundBrush());
SetFont( window->GetFont() ) ;
}
wxPaintDC::~wxPaintDC()
{
}
void wxPaintDC::DoGetSize(int *width, int *height) const
{
wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
m_window->GetClientSize( width, height );
}

View File

@@ -0,0 +1,100 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcmemory.cpp
// Purpose: wxMemoryDC class
// Author: Stefan Csomor
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcmemory.h"
#endif
#include "wx/dcmemory.h"
#include "wx/mac/private.h"
//-----------------------------------------------------------------------------
// wxMemoryDC
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC)
wxMemoryDC::wxMemoryDC(void)
: m_selected()
{
m_ok = TRUE;
SetBackground(*wxWHITE_BRUSH);
SetBrush(*wxWHITE_BRUSH);
SetPen(*wxBLACK_PEN);
m_ok = FALSE;
};
wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
: m_selected()
{
m_ok = TRUE;
SetBackground(*wxWHITE_BRUSH);
SetBrush(*wxWHITE_BRUSH);
SetPen(*wxBLACK_PEN);
m_ok = FALSE;
};
wxMemoryDC::~wxMemoryDC()
{
if ( m_selected.Ok() )
{
UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
}
};
void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
{
if ( m_selected.Ok() )
{
UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
}
m_selected = bitmap;
if (m_selected.Ok())
{
if ( m_selected.GetHBITMAP() )
{
m_macPort = (GrafPtr) m_selected.GetHBITMAP() ;
LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ;
wxMask * mask = bitmap.GetMask() ;
if ( mask )
{
m_macMask = mask->GetMaskBitmap() ;
}
SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
m_ok = TRUE ;
}
else
{
m_ok = FALSE;
}
}
else
{
m_ok = FALSE;
}
}
void wxMemoryDC::DoGetSize( int *width, int *height ) const
{
if (m_selected.Ok())
{
if (width) (*width) = m_selected.GetWidth();
if (height) (*height) = m_selected.GetHeight();
}
else
{
if (width) (*width) = 0;
if (height) (*height) = 0;
}
}

416
src/mac/classic/dcprint.cpp Normal file
View File

@@ -0,0 +1,416 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcprint.cpp
// Purpose: wxPrinterDC class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// 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 "wx/msgdlg.h"
#include <math.h>
#include "wx/mac/uma.h"
#include "wx/mac/private/print.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxPrinterDC, wxDC)
#endif
class wxNativePrinterDC
{
public :
wxNativePrinterDC() {}
virtual ~wxNativePrinterDC() {}
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) = 0;
virtual void EndDoc( wxPrinterDC* dc ) = 0;
virtual void StartPage( wxPrinterDC* dc ) = 0;
virtual void EndPage( wxPrinterDC* dc ) = 0;
virtual wxCoord GetMaxX() const = 0 ;
virtual wxCoord GetMaxY() const = 0 ;
// returns 0 in case of no Error, otherwise platform specific error codes
virtual wxUint32 GetStatus() const = 0 ;
bool Ok() { return GetStatus() == 0 ; }
static wxNativePrinterDC* Create(wxPrintData* data) ;
} ;
#if TARGET_CARBON
class wxMacCarbonPrinterDC : public wxNativePrinterDC
{
public :
wxMacCarbonPrinterDC( wxPrintData* data ) ;
~wxMacCarbonPrinterDC() ;
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) ;
virtual void EndDoc( wxPrinterDC* dc ) ;
virtual void StartPage( wxPrinterDC* dc ) ;
virtual void EndPage( wxPrinterDC* dc ) ;
virtual wxCoord GetMaxX() const { return m_maxX ; }
virtual wxCoord GetMaxY() const { return m_maxY ; }
virtual wxUint32 GetStatus() const { return m_err ; }
private :
GrafPtr m_macPrintFormerPort ;
wxCoord m_maxX ;
wxCoord m_maxY ;
OSStatus m_err ;
} ;
wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data )
{
::GetPort( & m_macPrintFormerPort ) ;
m_err = noErr ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) data->m_nativePrintData ;
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( m_err != noErr )
return;
m_maxX = wxCoord(rPage.right - rPage.left) ;
m_maxY = wxCoord(rPage.bottom - rPage.top);
}
wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC()
{
// nothing to release from print data, as wxPrinterDC has all data in its wxPrintData member
::SetPort( m_macPrintFormerPort ) ;
}
wxNativePrinterDC* wxNativePrinterDC::Create(wxPrintData* data)
{
return new wxMacCarbonPrinterDC(data) ;
}
bool wxMacCarbonPrinterDC::StartDoc( wxPrinterDC* dc , const wxString& WXUNUSED(message) )
{
if ( m_err )
return false ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionBeginDocument(native->m_macPrintSession,
native->m_macPrintSettings,
native->m_macPageFormat);
if ( m_err != noErr )
return false;
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( m_err != noErr )
return false;
m_maxX = (wxCoord)(rPage.right - rPage.left);
m_maxY = (wxCoord)(rPage.bottom - rPage.top);
return true ;
}
void wxMacCarbonPrinterDC::EndDoc( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionEndDocument(native->m_macPrintSession);
}
void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionBeginPage(native->m_macPrintSession,
native->m_macPageFormat,
nil);
if ( m_err == noErr )
{
m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
nil,
(void**) &dc->m_macPort );
}
if ( m_err != noErr )
{
PMSessionEndPage(native->m_macPrintSession);
PMSessionEndDocument(native->m_macPrintSession);
}
else
{
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( !m_err )
{
dc->m_macLocalOrigin.x = (int) rPage.left;
dc->m_macLocalOrigin.y = (int) rPage.top;
}
// since this is a non-critical error, we set the flag back
m_err = noErr ;
}
}
void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionEndPage(native->m_macPrintSession);
if ( m_err != noErr )
{
PMSessionEndDocument(native->m_macPrintSession);
}
}
#else
class wxMacClassicPrinterDC : public wxNativePrinterDC
{
public :
wxMacClassicPrinterDC( wxPrintData* data ) ;
~wxMacClassicPrinterDC() ;
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) ;
virtual void EndDoc( wxPrinterDC* dc ) ;
virtual void StartPage( wxPrinterDC* dc ) ;
virtual void EndPage( wxPrinterDC* dc ) ;
virtual wxCoord GetMaxX() const { return m_maxX ; }
virtual wxCoord GetMaxY() const { return m_maxY ; }
virtual wxUint32 GetStatus() const { return m_err ; }
private :
GrafPtr m_macPrintFormerPort ;
TPPrPort m_macPrintingPort ;
OSErr m_err ;
long m_maxX ;
long m_maxY ;
} ;
wxNativePrinterDC* wxNativePrinterDC::Create(wxPrintData* data)
{
return new wxMacClassicPrinterDC(data) ;
}
wxMacClassicPrinterDC::wxMacClassicPrinterDC(wxPrintData* data)
{
::GetPort( &m_macPrintFormerPort ) ;
m_err = noErr ;
::UMAPrOpen() ;
m_err = PrError() ;
if ( m_err != noErr )
return;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) data->m_nativePrintData ;
if ( ::PrValidate( native->m_macPrintSettings ) )
{
// the driver has changed in the mean time, should we pop up a page setup dialog ?
if ( !::PrStlDialog( native->m_macPrintSettings ) )
{
m_err = -1 ;
return;
}
}
m_err = PrError() ;
if ( m_err == noErr )
{
m_maxX = (**native->m_macPrintSettings).prInfo.rPage.right - (**native->m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**native->m_macPrintSettings).prInfo.rPage.bottom - (**native->m_macPrintSettings).prInfo.rPage.top ;
}
}
wxMacClassicPrinterDC::~wxMacClassicPrinterDC()
{
::UMAPrClose() ;
::SetPort( LMGetWMgrPort() ) ;
}
bool wxMacClassicPrinterDC::StartDoc( wxPrinterDC* dc , const wxString& WXUNUSED(message) )
{
if ( m_err )
return false ;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) dc->GetPrintData().m_nativePrintData ;
m_macPrintingPort = ::PrOpenDoc( native->m_macPrintSettings , NULL , NULL ) ;
m_err = PrError() ;
if ( m_err )
return false ;
// sets current port
dc->m_macPort = (GrafPtr ) m_macPrintingPort ;
m_maxX = (**native->m_macPrintSettings).prInfo.rPage.right - (**native->m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**native->m_macPrintSettings).prInfo.rPage.bottom - (**native->m_macPrintSettings).prInfo.rPage.top ;
return true ;
}
void wxMacClassicPrinterDC::EndDoc( wxPrinterDC* dc )
{
if ( m_err )
return ;
PrCloseDoc( m_macPrintingPort ) ;
m_err = PrError() ;
}
void wxMacClassicPrinterDC::StartPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) dc->GetPrintData().m_nativePrintData ;
PrOpenPage( m_macPrintingPort , NULL ) ;
dc->m_macLocalOrigin.x = (**native->m_macPrintSettings).rPaper.left ;
dc->m_macLocalOrigin.y = (**native->m_macPrintSettings).rPaper.top ;
// m_macPrintingPort is now the current port
Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
::ClipRect( &clip ) ;
m_err = PrError() ;
if ( m_err != noErr )
::PrCloseDoc( m_macPrintingPort ) ;
}
void wxMacClassicPrinterDC::EndPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
PrClosePage( m_macPrintingPort ) ;
m_err = PrError() ;
if ( m_err != noErr )
::PrCloseDoc( m_macPrintingPort ) ;
}
#endif
wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
{
m_ok = FALSE ;
m_printData = printdata ;
m_printData.ConvertToNative() ;
m_nativePrinterDC = wxNativePrinterDC::Create( &m_printData ) ;
if ( m_nativePrinterDC )
{
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
message.Printf( wxT("Print Error %u"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
}
}
wxPrinterDC::~wxPrinterDC(void)
{
delete m_nativePrinterDC ;
}
bool wxPrinterDC::StartDoc( const wxString& message )
{
wxASSERT_MSG( Ok() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ;
if ( !m_ok )
return false ;
if ( m_nativePrinterDC->StartDoc(this, message ) )
{
// in case we have to do additional things when successful
}
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
message.Printf( wxT("Print Error %u"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
return m_ok ;
}
void wxPrinterDC::EndDoc(void)
{
if ( !m_ok )
return ;
m_nativePrinterDC->EndDoc( this ) ;
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
message.Printf( wxT("Print Error %u"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
}
void wxPrinterDC::StartPage(void)
{
if ( !m_ok )
return ;
m_logicalFunction = wxCOPY;
// m_textAlignment = wxALIGN_TOP_LEFT;
m_backgroundMode = wxTRANSPARENT;
m_textForegroundColour = *wxBLACK;
m_textBackgroundColour = *wxWHITE;
m_pen = *wxBLACK_PEN;
m_font = *wxNORMAL_FONT;
m_brush = *wxTRANSPARENT_BRUSH;
m_backgroundBrush = *wxWHITE_BRUSH;
m_macFontInstalled = false ;
m_macBrushInstalled = false ;
m_macPenInstalled = false ;
m_nativePrinterDC->StartPage(this) ;
m_ok = m_nativePrinterDC->Ok() ;
}
void wxPrinterDC::EndPage(void)
{
if ( !m_ok )
return ;
m_nativePrinterDC->EndPage(this) ;
m_ok = m_nativePrinterDC->Ok() ;
}
void wxPrinterDC::DoGetSize(int *width, int *height) const
{
wxCHECK_RET( m_ok , _T("GetSize() doesn't work without a valid wxPrinterDC") );
if ( width )
* width = m_nativePrinterDC->GetMaxX() ;
if ( height )
* height = m_nativePrinterDC->GetMaxY() ;
}

View File

@@ -0,0 +1,63 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcscreen.cpp
// Purpose: wxScreenDC class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcscreen.h"
#endif
#include "wx/dcscreen.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
#endif
// Create a DC representing the whole screen
wxScreenDC::wxScreenDC()
{
#if TARGET_CARBON
m_macPort = GetQDGlobalsThePort() ;
GrafPtr port ;
GetPort( &port ) ;
SetPort( (GrafPtr) m_macPort ) ;
Point pt = { 0,0 } ;
LocalToGlobal( &pt ) ;
SetPort( port ) ;
m_macLocalOrigin.x = -pt.h ;
m_macLocalOrigin.y = -pt.v ;
#else
m_macPort = LMGetWMgrPort() ;
m_macLocalOrigin.x = 0 ;
m_macLocalOrigin.y = 0 ;
#endif
m_ok = TRUE ;
BitMap screenBits;
GetQDGlobalsScreenBits( &screenBits );
m_minX = screenBits.bounds.left ;
#if TARGET_CARBON
SInt16 height ;
GetThemeMenuBarHeight( &height ) ;
m_minY = screenBits.bounds.top + height ;
#else
m_minY = screenBits.bounds.top + LMGetMBarHeight() ;
#endif
m_maxX = screenBits.bounds.right ;
m_maxY = screenBits.bounds.bottom ;
MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
}
wxScreenDC::~wxScreenDC()
{
// TODO
}

268
src/mac/classic/dialog.cpp Normal file
View File

@@ -0,0 +1,268 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dialog.cpp
// Purpose: wxDialog class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dialog.h"
#endif
#include "wx/dialog.h"
#include "wx/utils.h"
#include "wx/frame.h"
#include "wx/app.h"
#include "wx/settings.h"
#include "wx/mac/uma.h"
// Lists to keep track of windows, so we can disable/enable them
// for modal dialogs
wxList wxModalDialogs;
//wxList wxModelessWindows; // Frames and modeless dialogs
extern wxList wxPendingDelete;
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_CHAR_HOOK(wxDialog::OnCharHook)
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
#endif
wxDialog::wxDialog()
{
m_isShown = FALSE;
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
}
bool wxDialog::Create(wxWindow *parent, wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
MacCreateRealWindow( title , pos , size , MacRemoveBordersFromStyle(style) & ~(wxYES|wxOK|wxNO|wxCANCEL) , name ) ;
m_macWindowBackgroundTheme = kThemeBrushDialogBackgroundActive ;
SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
return TRUE;
}
void wxDialog::SetModal(bool flag)
{
if ( flag )
{
m_windowStyle |= wxDIALOG_MODAL;
wxModelessWindows.DeleteObject(this);
#if TARGET_CARBON
SetWindowModality( (WindowRef) MacGetWindowRef() , kWindowModalityAppModal , NULL ) ;
#endif
}
else
{
m_windowStyle &= ~wxDIALOG_MODAL;
wxModelessWindows.Append(this);
}
}
wxDialog::~wxDialog()
{
m_isBeingDeleted = TRUE;
Show(FALSE);
}
// By default, pressing escape cancels the dialog , on mac command-stop does the same thing
void wxDialog::OnCharHook(wxKeyEvent& event)
{
if (( event.m_keyCode == WXK_ESCAPE ||
( event.m_keyCode == '.' && event.MetaDown() ) )
&& FindWindow(wxID_CANCEL) )
{
// Behaviour changed in 2.0: we'll send a Cancel message
// to the dialog instead of Close.
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent);
return;
}
// We didn't process this event.
event.Skip();
}
bool wxDialog::IsModal() const
{
return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0;
}
bool wxDialog::IsModalShowing() const
{
return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
}
bool wxDialog::Show(bool show)
{
if ( !wxDialogBase::Show(show) )
{
// nothing to do
return FALSE;
}
if ( show )
{
// usually will result in TransferDataToWindow() being called
InitDialog();
}
if ( IsModal() )
{
if ( show )
{
DoShowModal();
}
else // end of modal dialog
{
// this will cause IsModalShowing() return FALSE and our local
// message loop will terminate
wxModalDialogs.DeleteObject(this);
}
}
return TRUE;
}
#if !TARGET_CARBON
extern bool s_macIsInModalLoop ;
#endif
void wxDialog::DoShowModal()
{
wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
wxModalDialogs.Append(this);
#if TARGET_CARBON
BeginAppModalStateForWindow( (WindowRef) MacGetWindowRef()) ;
#else
// TODO : test whether parent gets disabled
bool formerModal = s_macIsInModalLoop ;
s_macIsInModalLoop = true ;
#endif
while ( IsModalShowing() )
{
wxTheApp->MacDoOneEvent() ;
// calls process idle itself
}
#if TARGET_CARBON
EndAppModalStateForWindow( (WindowRef) MacGetWindowRef() ) ;
#else
// TODO probably reenable the parent window if any
s_macIsInModalLoop = formerModal ;
#endif
}
// Replacement for Show(TRUE) for modal dialogs - returns return code
int wxDialog::ShowModal()
{
if ( !IsModal() )
{
SetModal(TRUE);
}
Show(TRUE);
return GetReturnCode();
}
// NB: this function (surprizingly) may be called for both modal and modeless
// dialogs and should work for both of them
void wxDialog::EndModal(int retCode)
{
SetReturnCode(retCode);
Show(FALSE);
}
// Standard buttons
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
if ( Validate() && TransferDataFromWindow() )
{
EndModal(wxID_OK);
}
}
void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
{
if (Validate())
TransferDataFromWindow();
// TODO probably need to disable the Apply button until things change again
}
void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
{
EndModal(wxID_CANCEL);
}
void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
// We'll send a Cancel message by default,
// which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close().
// We wouldn't want to destroy the dialog by default, since the dialog may have been
// created on the stack.
// However, this does mean that calling dialog->Close() won't delete the dialog
// unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
// sure to destroy the dialog.
// The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
static wxList closing;
if ( closing.Member(this) )
return;
closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
closing.DeleteObject(this);
}
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
Refresh();
}

146
src/mac/classic/dirdlg.cpp Normal file
View File

@@ -0,0 +1,146 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dirdlg.cpp
// Purpose: wxDirDialog
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dirdlg.h"
#endif
#include "wx/defs.h"
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/dirdlg.h"
#include "wx/cmndata.h"
#include "wx/mac/private.h"
#ifdef __DARWIN__
#include <Carbon/Carbon.h>
#else
#include <Navigation.h>
#endif
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxDirDialog, wxDialog)
#endif
wxDirDialog::wxDirDialog(wxWindow *parent,
const wxString& message,
const wxString& defaultPath,
long style,
const wxPoint& WXUNUSED(pos),
const wxSize& WXUNUSED(size),
const wxString& WXUNUSED(name))
{
wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
m_message = message;
m_dialogStyle = style;
m_parent = parent;
m_path = defaultPath;
}
int wxDirDialog::ShowModal()
{
NavDialogOptions mNavOptions;
NavObjectFilterUPP mNavFilterUPP = NULL;
NavPreviewUPP mNavPreviewUPP = NULL ;
NavReplyRecord mNavReply;
AEDesc* mDefaultLocation = NULL ;
bool mSelectDefault = false ;
::NavGetDefaultDialogOptions(&mNavOptions);
mNavFilterUPP = nil;
mNavPreviewUPP = nil;
mSelectDefault = false;
mNavReply.validRecord = false;
mNavReply.replacing = false;
mNavReply.isStationery = false;
mNavReply.translationNeeded = false;
mNavReply.selection.descriptorType = typeNull;
mNavReply.selection.dataHandle = nil;
mNavReply.keyScript = smSystemScript;
mNavReply.fileTranslation = nil;
// Set default location, the location
// that's displayed when the dialog
// first appears
if ( mDefaultLocation ) {
if (mSelectDefault) {
mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
} else {
mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
}
}
OSErr err = ::NavChooseFolder(
mDefaultLocation,
&mNavReply,
&mNavOptions,
NULL,
mNavFilterUPP,
0L); // User Data
if ( (err != noErr) && (err != userCanceledErr) ) {
m_path = wxT("") ;
return wxID_CANCEL ;
}
if (mNavReply.validRecord) { // User chose a folder
FSSpec folderInfo;
FSSpec outFileSpec ;
AEDesc specDesc ;
OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
if ( err != noErr ) {
m_path = wxT("") ;
return wxID_CANCEL ;
}
folderInfo = **(FSSpec**) specDesc.dataHandle;
if (specDesc.dataHandle != nil) {
::AEDisposeDesc(&specDesc);
}
// mNavReply.GetFileSpec(folderInfo);
// The FSSpec from NavChooseFolder is NOT the file spec
// for the folder. The parID field is actually the DirID
// of the folder itself, not the folder's parent, and
// the name field is empty. We must call PBGetCatInfo
// to get the parent DirID and folder name
Str255 name;
CInfoPBRec thePB; // Directory Info Parameter Block
thePB.dirInfo.ioCompletion = nil;
thePB.dirInfo.ioVRefNum = folderInfo.vRefNum; // Volume is right
thePB.dirInfo.ioDrDirID = folderInfo.parID; // Folder's DirID
thePB.dirInfo.ioNamePtr = name;
thePB.dirInfo.ioFDirIndex = -1; // Lookup using Volume and DirID
err = ::PBGetCatInfoSync(&thePB);
if ( err != noErr ) {
m_path = wxT("") ;
return wxID_CANCEL ;
}
// Create cannonical FSSpec
::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
name, &outFileSpec);
// outFolderDirID = thePB.dirInfo.ioDrDirID;
m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
return wxID_OK ;
}
return wxID_CANCEL;
}

322
src/mac/classic/dirmac.cpp Normal file
View File

@@ -0,0 +1,322 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msw/dir.cpp
// Purpose: wxDir implementation for Mac
// Author: Stefan Csomor
// Modified by:
// Created: 08.12.99
// RCS-ID: $Id$
// Copyright: (c) 1999 Stefan Csomor <csomor@advanced.ch>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "dir.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/log.h"
#endif // PCH
#include "wx/dir.h"
#include "wx/filefn.h" // for wxPathExists()
#ifndef __DARWIN__
#include <windows.h>
#endif
#include "wx/mac/private.h"
#ifdef __DARWIN__
# include "MoreFilesX.h"
#else
# include "MoreFiles.h"
# include "MoreFilesExtras.h"
#endif
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
#ifndef MAX_PATH
#define MAX_PATH 260 // from VC++ headers
#endif
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#define M_DIR ((wxDirData *)m_data)
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
// this class stores everything we need to enumerate the files
class wxDirData
{
public:
wxDirData(const wxString& dirname);
~wxDirData();
void SetFileSpec(const wxString& filespec) { m_filespec = filespec; }
void SetFlags(int flags) { m_flags = flags; }
bool Read(wxString *filename); // reads the next
void Rewind() ;
const wxString& GetName() const { return m_dirname; }
bool Ok() const { return m_ok; }
private:
CInfoPBRec m_CPB ;
wxInt16 m_index ;
long m_dirId ;
Str255 m_name ;
Boolean m_isDir ;
wxString m_dirname;
wxString m_filespec;
int m_flags;
bool m_ok;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxDirData
// ----------------------------------------------------------------------------
wxDirData::wxDirData(const wxString& dirname)
: m_dirname(dirname)
{
m_ok = false;
OSErr err;
// throw away the trailing slashes
size_t n = m_dirname.length();
wxCHECK_RET( n, _T("empty dir name in wxDir") );
while ( n > 0 && wxIsPathSeparator(m_dirname[--n]) )
;
m_dirname.Truncate(n + 1);
#ifdef __DARWIN__
FSRef theRef;
// get the FSRef associated with the POSIX path
err = FSPathMakeRef((const UInt8 *) m_dirname.c_str(), &theRef, NULL);
FSGetVRefNum(&theRef, &(m_CPB.hFileInfo.ioVRefNum));
err = FSGetNodeID( &theRef , &m_dirId , &m_isDir ) ;
#else
FSSpec fsspec ;
wxMacFilename2FSSpec( m_dirname , &fsspec ) ;
m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ;
err = FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ;
#endif
//wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ;
if ( (err == noErr) || (err == nsvErr))
m_ok = true;
else
wxLogError(wxString(wxT("Error accessing directory ")) + m_dirname);
m_CPB.hFileInfo.ioNamePtr = m_name ;
m_index = 0 ;
}
wxDirData::~wxDirData()
{
}
void wxDirData::Rewind()
{
m_index = 0 ;
}
bool wxDirData::Read(wxString *filename)
{
if ( !m_isDir )
return FALSE ;
wxString result;
short err = noErr ;
while ( err == noErr )
{
m_index++ ;
m_CPB.dirInfo.ioFDirIndex = m_index;
m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */
err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB);
if ( err != noErr )
break ;
// its hidden but we don't want it
if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) )
continue ;
#ifdef __DARWIN__
// under X, names that start with '.' are hidden
if ( ( m_name[1] == '.' ) && !(m_flags & wxDIR_HIDDEN) )
continue;
#endif
#if TARGET_CARBON
// under X thats the way the mounting points look like
if ( ( m_CPB.dirInfo.ioDrDirID == 0 ) && ( m_flags & wxDIR_DIRS) )
break ;
#endif
// we have a directory
if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) )
break ;
// its a file but we don't want it
if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) )
continue ;
wxString file = wxMacMakeStringFromPascal( m_name ) ;
if ( m_filespec.IsEmpty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") )
{
}
else if ( m_filespec.Length() > 1 && m_filespec.Left(1) == wxT("*") )
{
if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() )
{
continue ;
}
}
else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == wxT("*") )
{
if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() )
{
continue ;
}
}
else if ( file.Upper() != m_filespec.Upper() )
{
continue ;
}
break ;
}
if ( err != noErr )
{
return FALSE ;
}
*filename = wxMacMakeStringFromPascal( m_name ) ;
return TRUE;
}
// ----------------------------------------------------------------------------
// wxDir helpers
// ----------------------------------------------------------------------------
/* static */
bool wxDir::Exists(const wxString& dir)
{
return wxPathExists(dir);
}
// ----------------------------------------------------------------------------
// wxDir construction/destruction
// ----------------------------------------------------------------------------
wxDir::wxDir(const wxString& dirname)
{
m_data = NULL;
(void)Open(dirname);
}
bool wxDir::Open(const wxString& dirname)
{
delete M_DIR;
m_data = new wxDirData(dirname);
if (m_data->Ok())
return TRUE;
else
{
delete m_data;
m_data = NULL;
return FALSE;
}
}
bool wxDir::IsOpened() const
{
return m_data != NULL;
}
wxString wxDir::GetName() const
{
wxString name;
if ( m_data )
{
name = M_DIR->GetName();
if ( !name.empty() && (name.Last() == _T('/')) )
{
// chop off the last (back)slash
name.Truncate(name.length() - 1);
}
}
return name;
}
wxDir::~wxDir()
{
if (M_DIR != NULL) {
delete M_DIR;
m_data = NULL;
}
}
// ----------------------------------------------------------------------------
// wxDir enumerating
// ----------------------------------------------------------------------------
bool wxDir::GetFirst(wxString *filename,
const wxString& filespec,
int flags) const
{
wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") );
M_DIR->Rewind();
M_DIR->SetFileSpec(filespec);
M_DIR->SetFlags(flags);
return GetNext(filename);
}
bool wxDir::GetNext(wxString *filename) const
{
wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") );
wxCHECK_MSG( filename, FALSE, _T("bad pointer in wxDir::GetNext()") );
return M_DIR->Read(filename);
}

446
src/mac/classic/display.cpp Normal file
View File

@@ -0,0 +1,446 @@
/////////////////////////////////////////////////////////////////////////////
// Name: display.cpp
// Purpose: Mac implementation of wxDisplay class
// Author: Brian Victor
// Modified by: Royce Mitchell III & Ryan Norton
// Created: 06/21/02
// RCS-ID: $Id$
// Copyright: (c) wxWindows team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "display.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_DISPLAY
#ifndef WX_PRECOMP
#include "wx/dynarray.h"
#include "wx/log.h"
#include "wx/msgdlg.h"
#endif
#ifdef __DARWIN__
#include <Carbon/Carbon.h>
#else
#include <Gestalt.h>
#include <Displays.h>
#include <Quickdraw.h>
#include <Video.h> //for VDSwitchInfoRec
#include <FixMath.h>
#endif
#include "wx/display.h"
#include "wx/gdicmn.h"
#include "wx/string.h"
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxDisplayMacPriv
{
public:
GDHandle m_hndl;
};
size_t wxDisplayBase::GetCount()
{
GDHandle hndl;
size_t num = 0;
hndl = DMGetFirstScreenDevice(true);
while(hndl)
{
num++;
hndl = DMGetNextScreenDevice(hndl, true);
}
return num;
}
int wxDisplayBase::GetFromPoint(const wxPoint &p)
{
GDHandle hndl;
size_t num = 0;
hndl = DMGetFirstScreenDevice(true);
while(hndl)
{
Rect screenrect = (*hndl)->gdRect;
if (p.x >= screenrect.left &&
p.x <= screenrect.right &&
p.y >= screenrect.top &&
p.y <= screenrect.bottom)
{
return num;
}
num++;
hndl = DMGetNextScreenDevice(hndl, true);
}
return -1;
}
wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ),
m_priv ( new wxDisplayMacPriv() )
{
GDHandle hndl;
hndl = DMGetFirstScreenDevice(true);
m_priv->m_hndl = NULL;
while(hndl)
{
if (index == 0)
{
m_priv->m_hndl = hndl;
}
index--;
hndl = DMGetNextScreenDevice(hndl, true);
}
}
wxRect wxDisplay::GetGeometry() const
{
if (!(m_priv)) return wxRect(0, 0, 0, 0);
if (!(m_priv->m_hndl)) return wxRect(0, 0, 0, 0);
Rect screenrect = (*(m_priv->m_hndl))->gdRect;
return wxRect( screenrect.left, screenrect.top,
screenrect.right - screenrect.left, screenrect.bottom - screenrect.top);
}
int wxDisplay::GetDepth() const
{
if (!(m_priv)) return 0;
if (!(m_priv->m_hndl)) return 0;
// This cryptic looking code is based on Apple's sample code:
// http://developer.apple.com/samplecode/Sample_Code/Graphics_2D/GDevVideo/Gen.cp.htm
//RN - according to the docs
//gdPMap is a bitmap-type representation of the GDevice, and all
//0x0000FFFF does is get the lower 16 bits of pixelSize. However,
//since pixelSize is only 16 bits (a short)...
return ((*(*(m_priv->m_hndl))->gdPMap)->pixelSize) & 0x0000FFFF;
}
wxString wxDisplay::GetName() const
{
// Macs don't name their displays...
return wxEmptyString;
}
struct DMModeIteratorRec
{
wxArrayVideoModes* pModes;
const wxVideoMode* pMatchMode;
};
pascal void DMModeListIteratorProc ( void* pData,
DMListIndexType nIndex,
DMDisplayModeListEntryPtr pInfo)
{
DMModeIteratorRec* pInfoData = (DMModeIteratorRec*) pData;
//Note that in testing the refresh rate is always 0 on my ibook - RN
int refresh = (int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate);
for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
{
#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
if (wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
(int) pInfo->displayModeResolutionInfo->csVerticalLines,
(int) pDBI->vpPixelSize,
refresh).Matches(*pInfoData->pMatchMode) )
{
pInfoData->pModes->Add(wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
(int) pInfo->displayModeResolutionInfo->csVerticalLines,
(int) pDBI->vpPixelSize,
refresh));
}
#undef pDBI
}
}
struct DMModeInfoRec
{
const wxVideoMode* pMode;
VDSwitchInfoRec sMode;
bool bMatched;
};
pascal void DMModeInfoProc ( void* pData,
DMListIndexType nIndex,
DMDisplayModeListEntryPtr pInfo)
{
DMModeInfoRec* pInfoData = (DMModeInfoRec*) pData;
Fixed refresh = Long2Fix(pInfoData->pMode->refresh);
for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
{
#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
if (pInfoData->pMode->w == (int&) pInfo->displayModeResolutionInfo->csHorizontalPixels &&
pInfoData->pMode->h == (int&) pInfo->displayModeResolutionInfo->csVerticalLines &&
pInfoData->pMode->bpp == (int) pDBI->vpPixelSize &&
refresh == pInfo->displayModeResolutionInfo->csRefreshRate)
{
memcpy(&pInfoData->sMode, pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo,
sizeof(VDSwitchInfoRec));
pInfoData->sMode.csMode = pDBI->vpPixelSize;
pInfoData->bMatched = true;
break;
}
#undef pDBI
}
}
struct DMModeTransRec
{
wxVideoMode Mode;
const VDSwitchInfoRec* psMode;
bool bMatched;
};
pascal void DMModeTransProc ( void* pData,
DMListIndexType nIndex,
DMDisplayModeListEntryPtr pInfo)
{
DMModeTransRec* pInfoData = (DMModeTransRec*) pData;
for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
{
#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
if (pInfoData->psMode->csData == pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo->csData)
{
pInfoData->Mode = wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
(int) pInfo->displayModeResolutionInfo->csVerticalLines,
(int) pDBI->vpPixelSize,
(int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate) );
pInfoData->bMatched = true;
break;
}
#undef pDBI
}
}
wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode& mode) const
{
wxArrayVideoModes Modes;
unsigned long dwDMVer;
Gestalt(gestaltDisplayMgrVers, (long*) &dwDMVer);
//Check DM version (for backward compatibility only - 7.5.3+ use 2.0)
if (dwDMVer >= 0x020000) //version 2?
{
DMListIndexType nNumModes;
DMListType pModes;
DMDisplayModeListIteratorUPP uppMLI;
DisplayIDType nDisplayID;
wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr);
//Create a new list...
wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr, wxT("Could not create a new display mode list") );
uppMLI = NewDMDisplayModeListIteratorUPP(DMModeListIteratorProc);
wxASSERT(uppMLI);
DMModeIteratorRec sModeInfo;
sModeInfo.pModes = &Modes;
sModeInfo.pMatchMode = &mode;
for (DMListIndexType i = 0; i < nNumModes; ++i)
{
wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
uppMLI, &sModeInfo) == noErr);
}
DisposeDMDisplayModeListIteratorUPP(uppMLI);
wxASSERT(DMDisposeList(pModes) == noErr);
}
else //DM 1.0, 1.2, 1.x
{
wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"),
(unsigned int) dwDMVer / 0x10000,
(dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) )
);
}
return Modes;
}
wxVideoMode wxDisplay::GetCurrentMode() const
{
unsigned long dwDMVer;
wxVideoMode RetMode;
Gestalt(gestaltDisplayMgrVers, (long*) &dwDMVer);
//Check DM version (for backward compatibility only - 7.5.3+ use 2.0)
if (dwDMVer >= 0x020000) //version 2?
{
VDSwitchInfoRec sMode; //Note - csMode member also contains the bit depth
if (DMGetDisplayMode(m_priv->m_hndl, &sMode) == noErr)
{
DMListIndexType nNumModes;
DMListType pModes;
DMDisplayModeListIteratorUPP uppMLI;
DisplayIDType nDisplayID;
wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr);
//Create a new list...
wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr,
wxT("Could not create a new display mode list") );
uppMLI = NewDMDisplayModeListIteratorUPP(DMModeTransProc);
wxASSERT(uppMLI);
DMModeTransRec sModeInfo;
sModeInfo.bMatched = false;
sModeInfo.psMode = &sMode;
for (DMListIndexType i = 0; i < nNumModes; ++i)
{
wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
uppMLI, &sModeInfo) == noErr);
if ( sModeInfo.bMatched == true )
{
RetMode = sModeInfo.Mode;
break;
}
}
DisposeDMDisplayModeListIteratorUPP(uppMLI);
wxASSERT(DMDisposeList(pModes) == noErr);
}
else //Can't get current mode?
{
wxLogSysError(wxString::Format(wxT("Couldn't obtain current display mode!!!\ndwDMVer:%u"),
(unsigned int) dwDMVer));
}
}
else //DM ver 1
{
wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"),
(unsigned int) dwDMVer / 0x10000,
(dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) )
);
}
return RetMode;
}
bool wxDisplay::ChangeMode(const wxVideoMode& mode)
{
unsigned long dwDMVer;
Gestalt(gestaltDisplayMgrVers, (long*)&dwDMVer);
if (GetCount() == 1 || dwDMVer >= 0x020000)
{
if (mode == wxDefaultVideoMode)
{
//#ifndef __DARWIN__
// Handle hDisplayState;
// if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
// {
// wxLogSysError(wxT("Could not lock display for display mode changing!"));
// return false;
// }
// wxASSERT( DMUseScreenPrefs(true, hDisplayState) == noErr);
// DMEndConfigureDisplays(hDisplayState);
// return true;
//#else
//hmmmmm....
return true;
//#endif
}
//0 & NULL for params 2 & 3 of DMSetVideoMode signal it to use defaults (current mode)
//DM 2.0+ doesn't use params 2 & 3 of DMSetDisplayMode
//so we have to use this icky structure
VDSwitchInfoRec sMode;
memset(&sMode, 0, sizeof(VDSwitchInfoRec) );
DMListIndexType nNumModes;
DMListType pModes;
DMDisplayModeListIteratorUPP uppMLI;
DisplayIDType nDisplayID;
wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr);
//Create a new list...
wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr,
wxT("Could not create a new display mode list") );
uppMLI = NewDMDisplayModeListIteratorUPP(DMModeInfoProc);
wxASSERT(uppMLI);
DMModeInfoRec sModeInfo;
sModeInfo.bMatched = false;
sModeInfo.pMode = &mode;
unsigned int i;
for(i = 0; i < nNumModes; ++i)
{
wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
uppMLI, &sModeInfo) == noErr);
if (sModeInfo.bMatched == true)
{
sMode = sModeInfo.sMode;
break;
}
}
if(i == nNumModes)
return false;
DisposeDMDisplayModeListIteratorUPP(uppMLI);
wxASSERT(DMDisposeList(pModes) == noErr);
// For the really paranoid -
// unsigned long flags;
// Boolean bok;
// wxASSERT(noErr == DMCheckDisplayMode(m_priv->m_hndl, sMode.csData,
// sMode.csMode, &flags, NULL, &bok));
// wxASSERT(bok);
Handle hDisplayState;
if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
{
wxLogSysError(wxT("Could not lock display for display mode changing!"));
return false;
}
unsigned long dwBPP = (unsigned long) mode.bpp;
if (DMSetDisplayMode(m_priv->m_hndl, sMode.csData,
(unsigned long*) &(dwBPP), NULL
//(unsigned long) &sMode
, hDisplayState
) != noErr)
{
DMEndConfigureDisplays(hDisplayState);
wxMessageBox(wxString::Format(wxT("Could not set the display mode")));
return false;
}
DMEndConfigureDisplays(hDisplayState);
}
else //DM 1.0, 1.2, 1.x
{
wxLogSysError(wxString::Format(wxT("Monitor gravitation not supported yet. dwDMVer:%u"),
(unsigned int) dwDMVer));
return false;
}
return true;
}
wxDisplay::~wxDisplay()
{
if ( m_priv )
{
delete m_priv;
m_priv = 0;
}
}
#endif // wxUSE_DISPLAY

607
src/mac/classic/dnd.cpp Normal file
View File

@@ -0,0 +1,607 @@
///////////////////////////////////////////////////////////////////////////////
// Name: dnd.cpp
// Purpose: wxDropTarget, wxDropSource, wxDataObject implementation
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) 1998 Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dnd.h"
#endif
#include "wx/defs.h"
#if wxUSE_DRAG_AND_DROP
#include "wx/dnd.h"
#include "wx/window.h"
#include "wx/toplevel.h"
#include "wx/app.h"
#include "wx/gdicmn.h"
#include "wx/mac/private.h"
// ----------------------------------------------------------------------------
// global
// ----------------------------------------------------------------------------
void wxMacEnsureTrackingHandlersInstalled() ;
typedef struct
{
wxWindow* m_currentTargetWindow ;
wxDropTarget* m_currentTarget ;
wxDropSource* m_currentSource ;
} MacTrackingGlobals ;
MacTrackingGlobals gTrackingGlobals ;
//----------------------------------------------------------------------------
// wxDropTarget
//----------------------------------------------------------------------------
wxDropTarget::wxDropTarget( wxDataObject *data )
: wxDropTargetBase( data )
{
wxMacEnsureTrackingHandlersInstalled() ;
}
wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
wxCoord WXUNUSED(y),
wxDragResult def )
{
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
}
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
{
if (!m_dataObject)
return FALSE;
return CurrentDragHasSupportedFormat() ;
}
wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxDragResult def )
{
if (!m_dataObject)
return wxDragNone;
if (!CurrentDragHasSupportedFormat())
return wxDragNone;
return GetData() ? def : wxDragNone;
}
bool wxDropTarget::CurrentDragHasSupportedFormat()
{
bool supported = false ;
if ( gTrackingGlobals.m_currentSource != NULL )
{
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
if ( data )
{
size_t formatcount = data->GetFormatCount() ;
wxDataFormat *array = new wxDataFormat[ formatcount ];
data->GetAllFormats( array );
for (size_t i = 0; !supported && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
if ( m_dataObject->IsSupported( format ) )
{
supported = true ;
break ;
}
}
delete[] array ;
}
}
if ( !supported )
{
UInt16 items ;
OSErr result;
CountDragItems((DragReference)m_currentDrag, &items);
for (UInt16 index = 1; index <= items && supported == false ; ++index)
{
ItemReference theItem;
FlavorType theType ;
UInt16 flavors = 0 ;
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) )
{
supported = true ;
break ;
}
}
}
}
return supported ;
}
bool wxDropTarget::GetData()
{
if (!m_dataObject)
return FALSE;
if ( !CurrentDragHasSupportedFormat() )
return FALSE ;
bool transferred = false ;
if ( gTrackingGlobals.m_currentSource != NULL )
{
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
if ( data )
{
size_t formatcount = data->GetFormatCount() ;
wxDataFormat *array = new wxDataFormat[ formatcount ];
data->GetAllFormats( array );
for (size_t i = 0; !transferred && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
if ( m_dataObject->IsSupported( format ) )
{
int size = data->GetDataSize( format );
transferred = true ;
if (size == 0)
{
m_dataObject->SetData(format , 0 , 0 ) ;
}
else
{
char *d = new char[size];
data->GetDataHere( format , (void*) d );
m_dataObject->SetData( format , size , d ) ;
delete[] d ;
}
}
}
delete[] array ;
}
}
if ( !transferred )
{
UInt16 items ;
OSErr result;
bool firstFileAdded = false ;
CountDragItems((DragReference)m_currentDrag, &items);
for (UInt16 index = 1; index <= items; ++index)
{
ItemReference theItem;
FlavorType theType ;
UInt16 flavors = 0 ;
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
wxDataFormat format(theType) ;
if ( m_dataObject->IsSupportedFormat( format ) )
{
FlavorFlags theFlags;
result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
if (result == noErr)
{
Size dataSize ;
Ptr theData ;
GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
if ( theType == 'TEXT' )
{
// this increment is only valid for allocating, on the next GetFlavorData
// call it is reset again to the original value
dataSize++ ;
}
theData = new char[dataSize];
GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
if( theType == 'TEXT' )
{
theData[dataSize]=0 ;
wxString convert( theData , wxConvLocal ) ;
m_dataObject->SetData( format, convert.Length() * sizeof(wxChar), (const wxChar*) convert );
}
else if ( theType == kDragFlavorTypeHFS )
{
HFSFlavor* theFile = (HFSFlavor*) theData ;
wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ;
if ( firstFileAdded )
((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
else
{
((wxFileDataObject*)m_dataObject)->SetData( 0 , name.c_str() ) ;
firstFileAdded = true ;
}
}
else
{
m_dataObject->SetData( format, dataSize, theData );
}
delete[] theData;
}
break ;
}
}
}
}
return TRUE ;
}
//-------------------------------------------------------------------------
// wxDropSource
//-------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// drag request
wxDropSource::wxDropSource(wxWindow *win,
const wxCursor &cursorCopy,
const wxCursor &cursorMove,
const wxCursor &cursorStop)
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{
wxMacEnsureTrackingHandlersInstalled() ;
m_window = win;
}
wxDropSource::wxDropSource(wxDataObject& data,
wxWindow *win,
const wxCursor &cursorCopy,
const wxCursor &cursorMove,
const wxCursor &cursorStop)
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{
wxMacEnsureTrackingHandlersInstalled() ;
SetData( data );
m_window = win;
}
wxDropSource::~wxDropSource()
{
}
wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
{
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
if (!m_data)
return (wxDragResult) wxDragNone;
if (m_data->GetFormatCount() == 0)
return (wxDragResult) wxDragNone;
OSErr result;
DragReference theDrag;
RgnHandle dragRegion;
if ((result = NewDrag(&theDrag)))
{
return wxDragNone ;
}
// add data to drag
size_t formatCount = m_data->GetFormatCount() ;
wxDataFormat *formats = new wxDataFormat[formatCount] ;
m_data->GetAllFormats( formats ) ;
ItemReference theItem = 1 ;
for ( size_t i = 0 ; i < formatCount ; ++i )
{
size_t dataSize = m_data->GetDataSize( formats[i] ) ;
Ptr dataPtr = new char[dataSize] ;
m_data->GetDataHere( formats[i] , dataPtr ) ;
OSType type = formats[i].GetFormatId() ;
if ( type == 'TEXT' )
{
dataSize-- ;
dataPtr[ dataSize ] = 0 ;
wxString st( (wxChar*) dataPtr ) ;
wxCharBuffer buf = st.mb_str( wxConvLocal) ;
AddDragItemFlavor(theDrag, theItem, type , buf.data(), strlen(buf), 0);
}
else if (type == kDragFlavorTypeHFS )
{
HFSFlavor theFlavor ;
OSErr err = noErr;
CInfoPBRec cat;
wxMacFilename2FSSpec( dataPtr , &theFlavor.fileSpec ) ;
cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
cat.hFileInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync(&cat);
if (err == noErr )
{
theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
if (theFlavor.fileSpec.parID == fsRtParID) {
theFlavor.fileCreator = 'MACS';
theFlavor.fileType = 'disk';
} else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0) {
theFlavor.fileCreator = 'MACS';
theFlavor.fileType = 'fold';
} else {
theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
}
AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);
}
}
else
{
AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
}
delete[] dataPtr ;
}
delete[] formats ;
dragRegion = NewRgn();
RgnHandle tempRgn = NewRgn() ;
EventRecord* ev = NULL ;
#if !TARGET_CARBON // TODO
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
#else
EventRecord rec ;
ev = &rec ;
wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
#endif
const short dragRegionOuterBoundary = 10 ;
const short dragRegionInnerBoundary = 9 ;
SetRectRgn( dragRegion , ev->where.h - dragRegionOuterBoundary ,
ev->where.v - dragRegionOuterBoundary ,
ev->where.h + dragRegionOuterBoundary ,
ev->where.v + dragRegionOuterBoundary ) ;
SetRectRgn( tempRgn , ev->where.h - dragRegionInnerBoundary ,
ev->where.v - dragRegionInnerBoundary ,
ev->where.h + dragRegionInnerBoundary ,
ev->where.v + dragRegionInnerBoundary ) ;
DiffRgn( dragRegion , tempRgn , dragRegion ) ;
DisposeRgn( tempRgn ) ;
// TODO:work with promises in order to return data only when drag
// was successfully completed
gTrackingGlobals.m_currentSource = this ;
result = TrackDrag(theDrag, ev , dragRegion);
DisposeRgn(dragRegion);
DisposeDrag(theDrag);
gTrackingGlobals.m_currentSource = NULL ;
KeyMap keymap;
GetKeys(keymap);
bool optionDown = keymap[1] & 4;
wxDragResult dndresult = optionDown ? wxDragCopy : wxDragMove;
return dndresult;
}
bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
{
const wxCursor& cursor = GetCursor(effect);
if ( cursor.Ok() )
{
cursor.MacInstall() ;
return TRUE;
}
else
{
return FALSE;
}
}
bool gTrackingGlobalsInstalled = false ;
// passing the globals via refcon is not needed by the CFM and later architectures anymore
// but I'll leave it in there, just in case...
pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
void *handlerRefCon, DragReference theDrag) ;
pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
DragReference theDrag) ;
void wxMacEnsureTrackingHandlersInstalled()
{
if( !gTrackingGlobalsInstalled )
{
OSErr result;
result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals);
wxASSERT( result == noErr ) ;
result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals);
wxASSERT( result == noErr ) ;
gTrackingGlobalsInstalled = true ;
}
}
pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
void *handlerRefCon, DragReference theDrag)
{
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
Point mouse, localMouse;
DragAttributes attributes;
GetDragAttributes(theDrag, &attributes);
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
KeyMap keymap;
GetKeys(keymap);
bool optionDown = keymap[1] & 4;
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
switch(theMessage)
{
case kDragTrackingEnterHandler:
break;
case kDragTrackingLeaveHandler:
break;
case kDragTrackingEnterWindow:
trackingGlobals->m_currentTargetWindow = NULL ;
trackingGlobals->m_currentTarget = NULL ;
break;
case kDragTrackingInWindow:
if (toplevel == NULL)
break;
GetDragMouse(theDrag, &mouse, 0L);
localMouse = mouse;
GlobalToLocal(&localMouse);
// if (attributes & kDragHasLeftSenderWindow)
{
wxPoint point(localMouse.h , localMouse.v) ;
wxWindow *win = NULL ;
toplevel->MacGetWindowFromPointSub( point , &win ) ;
int localx , localy ;
localx = localMouse.h ;
localy = localMouse.v ;
//TODO : should we use client coordinates
if ( win )
win->MacRootWindowToWindow( &localx , &localy ) ;
if ( win != trackingGlobals->m_currentTargetWindow )
{
if ( trackingGlobals->m_currentTargetWindow )
{
// this window is left
if ( trackingGlobals->m_currentTarget )
{
HideDragHilite(theDrag);
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnLeave() ;
trackingGlobals->m_currentTarget = NULL;
trackingGlobals->m_currentTargetWindow = NULL ;
}
}
if ( win )
{
// this window is entered
trackingGlobals->m_currentTargetWindow = win ;
trackingGlobals->m_currentTarget = win->GetDropTarget() ;
{
if ( trackingGlobals->m_currentTarget )
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
result = trackingGlobals->m_currentTarget->OnEnter(
localx , localy , result ) ;
}
if ( result != wxDragNone )
{
int x , y ;
x = y = 0 ;
win->MacWindowToRootWindow( &x , &y ) ;
RgnHandle hiliteRgn = NewRgn() ;
SetRectRgn( hiliteRgn , x , y , x+win->GetSize().x ,y+win->GetSize().y) ;
ShowDragHilite(theDrag, hiliteRgn, true);
DisposeRgn( hiliteRgn ) ;
}
}
}
}
else
{
if( trackingGlobals->m_currentTarget )
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnDragOver(
localx , localy , result ) ;
}
}
// set cursor for OnEnter and OnDragOver
if ( trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) == FALSE )
{
if ( trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) == FALSE )
{
switch( result )
{
case wxDragCopy :
{
wxCursor cursor(wxCURSOR_COPY_ARROW) ;
cursor.MacInstall() ;
}
break ;
case wxDragMove :
{
wxCursor cursor(wxCURSOR_ARROW) ;
cursor.MacInstall() ;
}
break ;
case wxDragNone :
{
wxCursor cursor(wxCURSOR_NO_ENTRY) ;
cursor.MacInstall() ;
}
break ;
case wxDragError:
case wxDragLink:
case wxDragCancel:
// put these here to make gcc happy
;
}
}
}
}
// MyTrackItemUnderMouse(localMouse, theWindow);
break;
case kDragTrackingLeaveWindow:
if (trackingGlobals->m_currentTarget)
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnLeave() ;
HideDragHilite(theDrag);
trackingGlobals->m_currentTarget = NULL ;
}
trackingGlobals->m_currentTargetWindow = NULL ;
break;
}
return(noErr);
}
pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow,
void *handlerRefCon,
DragReference theDrag)
{
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
if ( trackingGlobals->m_currentTarget )
{
Point mouse,localMouse ;
int localx,localy ;
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
GetDragMouse(theDrag, &mouse, 0L);
localMouse = mouse;
GlobalToLocal(&localMouse);
localx = localMouse.h ;
localy = localMouse.v ;
//TODO : should we use client coordinates
if ( trackingGlobals->m_currentTargetWindow )
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ;
if ( trackingGlobals->m_currentTarget->OnDrop( localx , localy ) )
{
KeyMap keymap;
GetKeys(keymap);
bool optionDown = keymap[1] & 4;
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ;
}
}
return(noErr);
}
#endif

647
src/mac/classic/filedlg.cpp Normal file
View File

@@ -0,0 +1,647 @@
/////////////////////////////////////////////////////////////////////////////
// Name: filedlg.cpp
// Purpose: wxFileDialog
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "filedlg.h"
#endif
#include "wx/defs.h"
#include "wx/app.h"
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/filedlg.h"
#include "wx/intl.h"
#include "wx/tokenzr.h"
#include "wx/filename.h"
#ifndef __DARWIN__
#include "PLStringFuncs.h"
#endif
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
#endif
// begin wxmac
#include "wx/mac/private.h"
#include <Navigation.h>
#ifdef __DARWIN__
# include "MoreFilesX.h"
#else
# include "MoreFiles.h"
# include "MoreFilesExtras.h"
#endif
extern bool gUseNavServices ;
// the data we need to pass to our standard file hook routine
// includes a pointer to the dialog, a pointer to the standard
// file reply record (so we can inspect the current selection)
// and a copy of the "previous" file spec of the reply record
// so we can see if the selection has changed
struct OpenUserDataRec {
int currentfilter ;
bool saveMode ;
wxArrayString name ;
wxArrayString extensions ;
wxArrayLong filtermactypes ;
wxString defaultLocation;
#if TARGET_CARBON
CFArrayRef menuitems ;
#else
NavMenuItemSpecArrayHandle menuitems ;
#endif
};
typedef struct OpenUserDataRec
OpenUserDataRec, *OpenUserDataRecPtr;
static pascal void NavEventProc(
NavEventCallbackMessage inSelector,
NavCBRecPtr ioParams,
NavCallBackUserData ioUserData);
#if TARGET_CARBON
static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
#else
static NavEventUPP sStandardNavEventFilter = NewNavEventProc(NavEventProc);
#endif
static pascal void
NavEventProc(
NavEventCallbackMessage inSelector,
NavCBRecPtr ioParams,
NavCallBackUserData ioUserData )
{
OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ;
if (inSelector == kNavCBEvent) {
#if TARGET_CARBON
#else
wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event);
#endif
}
else if ( inSelector == kNavCBStart )
{
#if TARGET_CARBON
if (data && !(data->defaultLocation).IsEmpty())
{
// Set default location for the modern Navigation APIs
// Apple Technical Q&A 1151
FSSpec theFSSpec;
wxMacFilename2FSSpec(data->defaultLocation, &theFSSpec);
AEDesc theLocation = {typeNull, NULL};
if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation))
::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation);
}
#else
if ( data->menuitems )
NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &(*data->menuitems)[data->currentfilter]);
#endif
}
else if ( inSelector == kNavCBPopupMenuSelect )
{
NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ;
#if TARGET_CARBON
#else
if ( menu->menuCreator == 'WXNG' )
#endif
{
data->currentfilter = menu->menuType ;
if ( data->saveMode )
{
int i = menu->menuType ;
wxString extension = data->extensions[i].AfterLast('.') ;
extension.MakeLower() ;
wxString sfilename ;
#if TARGET_CARBON
wxMacCFStringHolder cfString( NavDialogGetSaveFileName( ioParams->context ) , false );
sfilename = cfString.AsString() ;
#else
Str255 filename ;
// get the current filename
NavCustomControl(ioParams->context, kNavCtlGetEditFileName, &filename);
sfilename = wxMacMakeStringFromPascal( filename ) ;
#endif
int pos = sfilename.Find('.', true) ;
if ( pos != wxNOT_FOUND )
{
sfilename = sfilename.Left(pos+1)+extension ;
#if TARGET_CARBON
cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ;
NavDialogSetSaveFileName( ioParams->context , cfString ) ;
#else
wxMacStringToPascal( sfilename , filename ) ;
NavCustomControl(ioParams->context, kNavCtlSetEditFileName, &filename);
#endif
}
}
}
}
}
void MakeUserDataRec(OpenUserDataRec *myData , const wxString& filter )
{
myData->menuitems = NULL ;
myData->currentfilter = 0 ;
myData->saveMode = false ;
if ( filter && filter[0] )
{
wxString filter2(filter) ;
int filterIndex = 0;
bool isName = true ;
wxString current ;
for( unsigned int i = 0; i < filter2.Len() ; i++ )
{
if( filter2.GetChar(i) == wxT('|') )
{
if( isName ) {
myData->name.Add( current ) ;
}
else {
myData->extensions.Add( current.MakeUpper() ) ;
++filterIndex ;
}
isName = !isName ;
current = wxEmptyString ;
}
else
{
current += filter2.GetChar(i) ;
}
}
// we allow for compatibility reason to have a single filter expression (like *.*) without
// an explanatory text, in that case the first part is name and extension at the same time
wxASSERT_MSG( filterIndex == 0 || !isName , wxT("incorrect format of format string") ) ;
if ( current.IsEmpty() )
myData->extensions.Add( myData->name[filterIndex] ) ;
else
myData->extensions.Add( current.MakeUpper() ) ;
if ( filterIndex == 0 || isName )
myData->name.Add( current.MakeUpper() ) ;
++filterIndex ;
const size_t extCount = myData->extensions.GetCount();
for ( size_t i = 0 ; i < extCount; i++ )
{
wxUint32 fileType;
wxUint32 creator;
wxString extension = myData->extensions[i];
if (extension.GetChar(0) == '*')
extension = extension.Mid(1); // Remove leading *
if (extension.GetChar(0) == '.')
{
extension = extension.Mid(1); // Remove leading .
}
if (wxFileName::MacFindDefaultTypeAndCreator( extension, &fileType, &creator ))
{
myData->filtermactypes.Add( (OSType)fileType );
}
else
{
myData->filtermactypes.Add( '****' ) ; // We'll fail safe if it's not recognized
}
}
}
}
static Boolean CheckFile( const wxString &filename , OSType type , OpenUserDataRecPtr data)
{
wxString file(filename) ;
file.MakeUpper() ;
if ( data->extensions.GetCount() > 0 )
{
//for ( int i = 0 ; i < data->numfilters ; ++i )
int i = data->currentfilter ;
if ( data->extensions[i].Right(2) == wxT(".*") )
return true ;
{
if ( type == (OSType)data->filtermactypes[i] )
return true ;
wxStringTokenizer tokenizer( data->extensions[i] , wxT(";") ) ;
while( tokenizer.HasMoreTokens() )
{
wxString extension = tokenizer.GetNextToken() ;
if ( extension.GetChar(0) == '*' )
extension = extension.Mid(1) ;
if ( file.Len() >= extension.Len() && extension == file.Right(extension.Len() ) )
return true ;
}
}
return false ;
}
return true ;
}
#ifndef __DARWIN__
static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr)
{
OpenUserDataRecPtr data = (OpenUserDataRecPtr) dataPtr ;
// return true if this item is invisible or a file
Boolean visibleFlag;
Boolean folderFlag;
visibleFlag = ! (myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible);
folderFlag = (myCInfoPBPtr->hFileInfo.ioFlAttrib & 0x10);
// because the semantics of the filter proc are "true means don't show
// it" we need to invert the result that we return
if ( !visibleFlag )
return true ;
if ( !folderFlag )
{
wxString file = wxMacMakeStringFromPascal( myCInfoPBPtr->hFileInfo.ioNamePtr ) ;
return !CheckFile( file , myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdType , data ) ;
}
return false ;
}
#endif
// end wxmac
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
long style, const wxPoint& pos)
:wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
{
wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
}
pascal Boolean CrossPlatformFilterCallback (
AEDesc *theItem,
void *info,
void *callBackUD,
NavFilterModes filterMode
)
{
bool display = true;
OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ;
if (filterMode == kNavFilteringBrowserList)
{
NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ;
if ( !theInfo->isFolder )
{
if (theItem->descriptorType == typeFSS )
{
FSSpec spec;
memcpy( &spec , *theItem->dataHandle , sizeof(FSSpec) ) ;
wxString file = wxMacMakeStringFromPascal( spec.name ) ;
display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
}
#if TARGET_CARBON
else if ( theItem->descriptorType == typeFSRef )
{
FSRef fsref ;
memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ;
CFURLRef fullURLRef;
fullURLRef = ::CFURLCreateFromFSRef(NULL, &fsref);
#ifdef __UNIX__
CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
#else
CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
#endif
CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
::CFRelease( fullURLRef ) ;
wxString file = wxMacCFStringHolder(cfString).AsString(wxFont::GetDefaultEncoding());
display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
}
#endif
}
}
return display;
}
int wxFileDialog::ShowModal()
{
#if TARGET_CARBON
OSErr err;
NavDialogCreationOptions dialogCreateOptions;
// set default options
::NavGetDefaultDialogCreationOptions(&dialogCreateOptions);
// this was always unset in the old code
dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation;
wxMacCFStringHolder message(m_message, m_font.GetEncoding());
dialogCreateOptions.windowTitle = message;
wxMacCFStringHolder defaultFileName(m_fileName, m_font.GetEncoding());
dialogCreateOptions.saveFileName = defaultFileName;
NavDialogRef dialog;
NavObjectFilterUPP navFilterUPP = NULL;
CFArrayRef cfArray = NULL; // for popupExtension
OpenUserDataRec myData;
myData.defaultLocation = m_dir;
if (m_dialogStyle & wxSAVE)
{
dialogCreateOptions.optionFlags |= kNavNoTypePopup;
dialogCreateOptions.optionFlags |= kNavDontAutoTranslate;
dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems;
// The extension is important
dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension;
err = ::NavCreatePutFileDialog(&dialogCreateOptions,
'TEXT',
'TEXT',
sStandardNavEventFilter,
&myData, // for defaultLocation
&dialog);
}
else
{
MakeUserDataRec(&myData , m_wildCard);
size_t numfilters = myData.extensions.GetCount();
if (numfilters > 0)
{
CFMutableArrayRef popup = CFArrayCreateMutable( kCFAllocatorDefault ,
numfilters , &kCFTypeArrayCallBacks ) ;
dialogCreateOptions.popupExtension = popup ;
myData.menuitems = dialogCreateOptions.popupExtension ;
for ( size_t i = 0 ; i < numfilters ; ++i )
{
CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] , m_font.GetEncoding() ) ) ;
}
}
navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback);
err = ::NavCreateGetFileDialog(&dialogCreateOptions,
NULL, // NavTypeListHandle
sStandardNavEventFilter,
NULL, // NavPreviewUPP
navFilterUPP,
(void *) &myData, // inClientData
&dialog);
}
if (err == noErr)
err = ::NavDialogRun(dialog);
// clean up filter related data, etc.
if (navFilterUPP)
::DisposeNavObjectFilterUPP(navFilterUPP);
if (cfArray)
::CFRelease(cfArray);
if (err != noErr)
return wxID_CANCEL;
NavReplyRecord navReply;
err = ::NavDialogGetReply(dialog, &navReply);
if (err == noErr && navReply.validRecord)
{
AEKeyword theKeyword;
DescType actualType;
Size actualSize;
FSRef theFSRef;
wxString thePath ;
long count;
::AECountItems(&navReply.selection , &count);
for (long i = 1; i <= count; ++i)
{
err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType,
&theFSRef, sizeof(theFSRef), &actualSize);
if (err != noErr)
break;
CFURLRef fullURLRef;
if (m_dialogStyle & wxSAVE)
{
CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
if (parentURLRef)
{
fullURLRef =
::CFURLCreateCopyAppendingPathComponent(NULL,
parentURLRef,
navReply.saveFileName,
false);
::CFRelease(parentURLRef);
}
}
else
{
fullURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
}
#ifdef __UNIX__
CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
#else
CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
#endif
CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
thePath = wxMacCFStringHolder(cfString).AsString(m_font.GetEncoding());
if (!thePath)
{
::NavDisposeReply(&navReply);
return wxID_CANCEL;
}
m_path = thePath;
m_paths.Add(m_path);
m_fileName = wxFileNameFromPath(m_path);
m_fileNames.Add(m_fileName);
}
// set these to the first hit
m_path = m_paths[0];
m_fileName = wxFileNameFromPath(m_path);
m_dir = wxPathOnly(m_path);
}
::NavDisposeReply(&navReply);
return (err == noErr) ? wxID_OK : wxID_CANCEL;
#else // TARGET_CARBON
NavDialogOptions mNavOptions;
NavObjectFilterUPP mNavFilterUPP = NULL;
NavPreviewUPP mNavPreviewUPP = NULL ;
NavReplyRecord mNavReply;
AEDesc mDefaultLocation ;
bool mSelectDefault = false ;
OSStatus err = noErr ;
// setup dialog
mNavFilterUPP = nil;
mNavPreviewUPP = nil;
mSelectDefault = false;
mDefaultLocation.descriptorType = typeNull;
mDefaultLocation.dataHandle = nil;
NavGetDefaultDialogOptions(&mNavOptions);
wxMacStringToPascal( m_message , (StringPtr)mNavOptions.message ) ;
wxMacStringToPascal( m_fileName , (StringPtr)mNavOptions.savedFileName ) ;
// Set default location, the location
// that's displayed when the dialog
// first appears
FSSpec location ;
wxMacFilename2FSSpec( m_dir , &location ) ;
err = ::AECreateDesc(typeFSS, &location, sizeof(FSSpec), &mDefaultLocation );
if ( mDefaultLocation.dataHandle )
{
if (mSelectDefault)
{
mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
} else {
mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
}
}
memset( &mNavReply , 0 , sizeof( mNavReply ) ) ;
mNavReply.validRecord = false;
mNavReply.replacing = false;
mNavReply.isStationery = false;
mNavReply.translationNeeded = false;
mNavReply.selection.descriptorType = typeNull;
mNavReply.selection.dataHandle = nil;
mNavReply.keyScript = smSystemScript;
mNavReply.fileTranslation = nil;
mNavReply.version = kNavReplyRecordVersion ;
// zero all data
m_path = wxEmptyString ;
m_fileName = wxEmptyString ;
m_paths.Empty();
m_fileNames.Empty();
OpenUserDataRec myData;
MakeUserDataRec( &myData , m_wildCard ) ;
myData.currentfilter = m_filterIndex ;
if ( myData.extensions.GetCount() > 0 )
{
mNavOptions.popupExtension = (NavMenuItemSpecArrayHandle) NewHandle( sizeof( NavMenuItemSpec ) * myData.extensions.GetCount() ) ;
myData.menuitems = mNavOptions.popupExtension ;
for ( size_t i = 0 ; i < myData.extensions.GetCount() ; ++i )
{
(*mNavOptions.popupExtension)[i].version = kNavMenuItemSpecVersion ;
(*mNavOptions.popupExtension)[i].menuCreator = 'WXNG' ;
// TODO : according to the new docs -1 to 10 are reserved for the OS
(*mNavOptions.popupExtension)[i].menuType = i ;
wxMacStringToPascal( myData.name[i] , (StringPtr)(*mNavOptions.popupExtension)[i].menuItemName ) ;
}
}
if ( m_dialogStyle & wxSAVE )
{
myData.saveMode = true ;
mNavOptions.dialogOptionFlags |= kNavDontAutoTranslate ;
mNavOptions.dialogOptionFlags |= kNavDontAddTranslateItems ;
err = ::NavPutFile(
&mDefaultLocation,
&mNavReply,
&mNavOptions,
sStandardNavEventFilter ,
NULL,
kNavGenericSignature,
&myData); // User Data
m_filterIndex = myData.currentfilter ;
}
else
{
myData.saveMode = false ;
mNavFilterUPP = NewNavObjectFilterUPP( CrossPlatformFilterCallback ) ;
if ( m_dialogStyle & wxMULTIPLE )
mNavOptions.dialogOptionFlags |= kNavAllowMultipleFiles ;
else
mNavOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles ;
err = ::NavGetFile(
&mDefaultLocation,
&mNavReply,
&mNavOptions,
sStandardNavEventFilter ,
mNavPreviewUPP,
mNavFilterUPP,
NULL ,
&myData);
m_filterIndex = myData.currentfilter ;
}
DisposeNavObjectFilterUPP(mNavFilterUPP);
if ( mDefaultLocation.dataHandle != nil )
{
::AEDisposeDesc(&mDefaultLocation);
}
if ( (err != noErr) && (err != userCanceledErr) ) {
return wxID_CANCEL ;
}
if (mNavReply.validRecord)
{
FSSpec outFileSpec ;
AEDesc specDesc ;
AEKeyword keyWord ;
long count ;
::AECountItems( &mNavReply.selection , &count ) ;
for ( long i = 1 ; i <= count ; ++i )
{
OSErr err = ::AEGetNthDesc( &mNavReply.selection , i , typeFSS, &keyWord , &specDesc);
if ( err != noErr )
{
m_path = wxT("") ;
return wxID_CANCEL ;
}
outFileSpec = **(FSSpec**) specDesc.dataHandle;
if (specDesc.dataHandle != nil) {
::AEDisposeDesc(&specDesc);
}
m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
m_paths.Add( m_path ) ;
m_fileName = wxFileNameFromPath(m_path);
m_fileNames.Add(m_fileName);
}
// set these to the first hit
m_path = m_paths[ 0 ] ;
m_fileName = wxFileNameFromPath(m_path);
m_dir = wxPathOnly(m_path);
NavDisposeReply( &mNavReply ) ;
return wxID_OK ;
}
return wxID_CANCEL;
#endif // TARGET_CARBON
}

446
src/mac/classic/font.cpp Normal file
View File

@@ -0,0 +1,446 @@
/////////////////////////////////////////////////////////////////////////////
// Name: font.cpp
// Purpose: wxFont class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "font.h"
#endif
#include "wx/defs.h"
#include "wx/string.h"
#include "wx/font.h"
#include "wx/fontutil.h"
#include "wx/gdicmn.h"
#include "wx/utils.h"
#include "wx/fontutil.h"
#include "wx/mac/private.h"
#include <ATSUnicode.h>
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
#endif
class WXDLLEXPORT wxFontRefData: public wxGDIRefData
{
friend class WXDLLEXPORT wxFont;
public:
wxFontRefData()
: m_fontId(0)
, m_pointSize(10)
, m_family(wxDEFAULT)
, m_style(wxNORMAL)
, m_weight(wxNORMAL)
, m_underlined(FALSE)
, m_faceName(wxT("Geneva"))
, m_encoding(wxFONTENCODING_DEFAULT)
, m_macFontNum(0)
, m_macFontSize(0)
, m_macFontStyle(0)
, m_macATSUFontID()
{
Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
wxT("Geneva"), wxFONTENCODING_DEFAULT);
}
wxFontRefData(const wxFontRefData& data)
: wxGDIRefData()
, m_fontId(data.m_fontId)
, m_pointSize(data.m_pointSize)
, m_family(data.m_family)
, m_style(data.m_style)
, m_weight(data.m_weight)
, m_underlined(data.m_underlined)
, m_faceName(data.m_faceName)
, m_encoding(data.m_encoding)
, m_macFontNum(data.m_macFontNum)
, m_macFontSize(data.m_macFontSize)
, m_macFontStyle(data.m_macFontStyle)
, m_macATSUFontID(data.m_macATSUFontID)
{
Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
data.m_underlined, data.m_faceName, data.m_encoding);
}
wxFontRefData(int size,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding)
: m_fontId(0)
, m_pointSize(size)
, m_family(family)
, m_style(style)
, m_weight(weight)
, m_underlined(underlined)
, m_faceName(faceName)
, m_encoding(encoding)
, m_macFontNum(0)
, m_macFontSize(0)
, m_macFontStyle(0)
, m_macATSUFontID(0)
{
Init(size, family, style, weight, underlined, faceName, encoding);
}
virtual ~wxFontRefData();
void SetNoAntiAliasing( bool no = TRUE ) { m_noAA = no; }
bool GetNoAntiAliasing() { return m_noAA; }
protected:
// common part of all ctors
void Init(int size,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding);
// font characterstics
int m_fontId;
int m_pointSize;
int m_family;
int m_style;
int m_weight;
bool m_underlined;
wxString m_faceName;
wxFontEncoding m_encoding;
bool m_noAA; // No anti-aliasing
public:
short m_macFontNum;
short m_macFontSize;
unsigned char m_macFontStyle;
wxUint32 m_macATSUFontID;
wxNativeFontInfo m_info;
public:
void MacFindFont() ;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxFontRefData
// ----------------------------------------------------------------------------
void wxFontRefData::Init(int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding)
{
m_style = style;
m_pointSize = pointSize;
m_family = family;
m_style = style;
m_weight = weight;
m_underlined = underlined;
m_faceName = faceName;
m_encoding = encoding;
m_macFontNum = 0 ;
m_macFontSize = 0;
m_macFontStyle = 0;
m_fontId = 0;
m_noAA = FALSE;
}
wxFontRefData::~wxFontRefData()
{
}
void wxFontRefData::MacFindFont()
{
if( m_faceName.Length() == 0 )
{
switch( m_family )
{
case wxDEFAULT :
m_macFontNum = ::GetAppFont() ;
break ;
case wxDECORATIVE :
::GetFNum( "\pTimes" , &m_macFontNum) ;
break ;
case wxROMAN :
::GetFNum( "\pTimes" , &m_macFontNum) ;
break ;
case wxSCRIPT :
::GetFNum( "\pTimes" , &m_macFontNum) ;
break ;
case wxSWISS :
::GetFNum( "\pGeneva" , &m_macFontNum) ;
break ;
case wxMODERN :
::GetFNum( "\pMonaco" , &m_macFontNum) ;
break ;
}
Str255 name ;
GetFontName( m_macFontNum , name ) ;
m_faceName = wxMacMakeStringFromPascal( name ) ;
}
else
{
if ( m_faceName == wxT("systemfont") )
m_macFontNum = ::GetSysFont() ;
else if ( m_faceName == wxT("applicationfont") )
m_macFontNum = ::GetAppFont() ;
else
{
Str255 fontname ;
wxMacStringToPascal( m_faceName , fontname ) ;
::GetFNum( fontname, &m_macFontNum);
}
}
m_macFontStyle = 0;
if (m_weight == wxBOLD)
m_macFontStyle |= bold;
if (m_style == wxITALIC || m_style == wxSLANT)
m_macFontStyle |= italic;
if (m_underlined)
m_macFontStyle |= underline;
m_macFontSize = m_pointSize ;
//TODO:if we supply the style as an additional parameter we must make a testing
//sequence in order to degrade gracefully while trying to maintain most of the style
//information, meanwhile we just take the normal font and apply the features after
#ifdef __WXDEBUG__
OSStatus status =
#endif // __WXDEBUG__
::ATSUFONDtoFontID(m_macFontNum, normal /*qdStyle*/, (UInt32*)&m_macATSUFontID);
/*
status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
*/
wxASSERT_MSG( status == noErr , wxT("couldn't retrieve font identifier") ) ;
}
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
void wxFont::Init()
{
}
bool wxFont::Create(const wxNativeFontInfo& info)
{
return Create(info.pointSize, info.family, info.style, info.weight,
info.underlined, info.faceName, info.encoding);
}
wxFont::wxFont(const wxString& fontdesc)
{
wxNativeFontInfo info;
if ( info.FromString(fontdesc) )
(void)Create(info);
}
bool wxFont::Create(int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding)
{
UnRef();
m_refData = new wxFontRefData(pointSize, family, style, weight,
underlined, faceName, encoding);
RealizeResource();
return TRUE;
}
wxFont::~wxFont()
{
}
bool wxFont::RealizeResource()
{
M_FONTDATA->MacFindFont() ;
return TRUE;
}
void wxFont::SetEncoding(wxFontEncoding encoding)
{
Unshare();
M_FONTDATA->m_encoding = encoding;
RealizeResource();
}
void wxFont::Unshare()
{
// Don't change shared data
if (!m_refData)
{
m_refData = new wxFontRefData();
}
else
{
wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
UnRef();
m_refData = ref;
}
}
void wxFont::SetPointSize(int pointSize)
{
Unshare();
M_FONTDATA->m_pointSize = pointSize;
RealizeResource();
}
void wxFont::SetFamily(int family)
{
Unshare();
M_FONTDATA->m_family = family;
RealizeResource();
}
void wxFont::SetStyle(int style)
{
Unshare();
M_FONTDATA->m_style = style;
RealizeResource();
}
void wxFont::SetWeight(int weight)
{
Unshare();
M_FONTDATA->m_weight = weight;
RealizeResource();
}
void wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
M_FONTDATA->m_faceName = faceName;
RealizeResource();
}
void wxFont::SetUnderlined(bool underlined)
{
Unshare();
M_FONTDATA->m_underlined = underlined;
RealizeResource();
}
void wxFont::SetNoAntiAliasing( bool no )
{
Unshare();
M_FONTDATA->SetNoAntiAliasing( no );
RealizeResource();
}
// ----------------------------------------------------------------------------
// accessors
// ----------------------------------------------------------------------------
// TODO: insert checks everywhere for M_FONTDATA == NULL!
int wxFont::GetPointSize() const
{
return M_FONTDATA->m_pointSize;
}
int wxFont::GetFamily() const
{
return M_FONTDATA->m_family;
}
int wxFont::GetStyle() const
{
return M_FONTDATA->m_style;
}
int wxFont::GetWeight() const
{
return M_FONTDATA->m_weight;
}
bool wxFont::GetUnderlined() const
{
return M_FONTDATA->m_underlined;
}
wxString wxFont::GetFaceName() const
{
wxString str;
if ( M_FONTDATA )
str = M_FONTDATA->m_faceName ;
return str;
}
wxFontEncoding wxFont::GetEncoding() const
{
return M_FONTDATA->m_encoding;
}
bool wxFont::GetNoAntiAliasing()
{
return M_FONTDATA->m_noAA;
}
short wxFont::GetMacFontNum() const
{
return M_FONTDATA->m_macFontNum;
}
short wxFont::GetMacFontSize() const
{
return M_FONTDATA->m_macFontSize;
}
wxByte wxFont::GetMacFontStyle() const
{
return M_FONTDATA->m_macFontStyle;
}
wxUint32 wxFont::GetMacATSUFontID() const
{
return M_FONTDATA->m_macATSUFontID;
}
const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
M_FONTDATA->m_info.InitFromFont(*this);
return &(M_FONTDATA->m_info);
}

View File

@@ -0,0 +1,54 @@
/////////////////////////////////////////////////////////////////////////////
// Name: fontdlg.cpp
// Purpose: wxFontDialog class. NOTE: you can use the generic class
// if you wish, instead of implementing this.
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "fontdlg.h"
#endif
#include "wx/mac/fontdlg.h"
#include "wx/cmndata.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
#endif
/*
* wxFontDialog
*/
wxFontDialog::wxFontDialog()
{
m_dialogParent = NULL;
}
wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData& data)
{
Create(parent, data);
}
bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
{
m_dialogParent = parent;
m_fontData = data;
// TODO: you may need to do dialog creation here, unless it's
// done in ShowModal.
return TRUE;
}
int wxFontDialog::ShowModal()
{
// TODO: show (maybe create) the dialog
return wxID_CANCEL;
}

View File

@@ -0,0 +1,173 @@
///////////////////////////////////////////////////////////////////////////////
// Name: mac/fontenum.cpp
// Purpose: wxFontEnumerator class for MacOS
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "fontenum.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/font.h"
#endif
#include "wx/fontenum.h"
#include "wx/fontutil.h"
#include "wx/fontmap.h"
#include "wx/fontutil.h"
#include "wx/encinfo.h"
#include "wx/mac/private.h"
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxFontEnumeratorHelper
{
public:
wxFontEnumeratorHelper(wxFontEnumerator *fontEnum);
// control what exactly are we enumerating
bool SetEncoding(wxFontEncoding encoding);
void SetFixedOnly(bool fixedOnly)
{ m_fixedOnly = fixedOnly; }
// call to start enumeration
void DoEnumerate();
private:
// the object we forward calls to OnFont() to
wxFontEnumerator *m_fontEnum;
// if != -1, enum only fonts which have this encoding
int m_charset;
// if not empty, enum only the fonts with this facename
wxString m_facename;
// if TRUE, enum only fixed fonts
bool m_fixedOnly;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxFontEnumeratorHelper
// ----------------------------------------------------------------------------
wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
{
m_fontEnum = fontEnum;
m_charset = -1;
m_fixedOnly = FALSE;
}
bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
{
wxNativeEncodingInfo info;
if ( !wxGetNativeFontEncoding(encoding, &info) )
{
if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
{
// no such encodings at all
return FALSE;
}
}
m_charset = info.charset;
m_facename = info.facename;
return TRUE;
}
void wxFontEnumeratorHelper::DoEnumerate()
{
MenuHandle menu ;
Str255 p_name ;
short lines ;
menu = NewMenu( 32000 , "\pFont" ) ;
AppendResMenu( menu , 'FONT' ) ;
lines = CountMenuItems( menu ) ;
for ( int i = 1 ; i < lines+1 ; i ++ )
{
GetMenuItemText( menu , i , p_name ) ;
wxString c_name = wxMacMakeStringFromPascal(p_name) ;
/*
if ( m_fixedOnly )
{
// check that it's a fixed pitch font (there is *no* error here, the
// flag name is misleading!)
if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
{
// not a fixed pitch font
return TRUE;
}
}
if ( m_charset != -1 )
{
// check that we have the right encoding
if ( lf->lfCharSet != m_charset )
{
return TRUE;
}
}
*/
m_fontEnum->OnFacename( c_name ) ;
}
DisposeMenu( menu ) ;
}
// ----------------------------------------------------------------------------
// wxFontEnumerator
// ----------------------------------------------------------------------------
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
bool fixedWidthOnly)
{
wxFontEnumeratorHelper fe(this);
if ( fe.SetEncoding(encoding) )
{
fe.SetFixedOnly(fixedWidthOnly);
fe.DoEnumerate();
}
// else: no such fonts, unknown encoding
return TRUE;
}
bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
{
wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
return TRUE;
}

View File

@@ -0,0 +1,117 @@
///////////////////////////////////////////////////////////////////////////////
// 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 licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// 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/encinfo.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();
}
info->encoding = encoding ;
return TRUE;
}
bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
{
// basically we should be able to support every encoding via the OS
return true ;
}

338
src/mac/classic/frame.cpp Normal file
View File

@@ -0,0 +1,338 @@
/////////////////////////////////////////////////////////////////////////////
// Name: frame.cpp
// Purpose: wxFrame
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "frame.h"
#endif
#include "wx/frame.h"
#include "wx/statusbr.h"
#include "wx/toolbar.h"
#include "wx/menuitem.h"
#include "wx/menu.h"
#include "wx/dcclient.h"
#include "wx/dialog.h"
#include "wx/settings.h"
#include "wx/app.h"
#include "wx/mac/uma.h"
extern wxWindowList wxModelessWindows;
extern wxList wxPendingDelete;
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
EVT_ACTIVATE(wxFrame::OnActivate)
// EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
// EVT_IDLE(wxFrame::OnIdle)
// EVT_CLOSE(wxFrame::OnCloseWindow)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
#endif
#define WX_MAC_STATUSBAR_HEIGHT 15
// ----------------------------------------------------------------------------
// creation/destruction
// ----------------------------------------------------------------------------
void wxFrame::Init()
{
m_frameMenuBar = NULL;
#if wxUSE_TOOLBAR
m_frameToolBar = NULL ;
#endif
m_frameStatusBar = NULL;
m_winLastFocused = NULL ;
m_iconized = FALSE;
#if wxUSE_TOOLTIPS
m_hwndToolTip = 0;
#endif
}
wxPoint wxFrame::GetClientAreaOrigin() const
{
// on mac we are at position -1,-1 with the control
wxPoint pt(0, 0);
#if wxUSE_TOOLBAR
if ( GetToolBar() )
{
int w, h;
GetToolBar()->GetSize(& w, & h);
if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
{
pt.x += w - 1;
}
else
{
pt.y += h - 1 ;
}
}
#endif // wxUSE_TOOLBAR
return pt;
}
bool wxFrame::Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
wxModelessWindows.Append(this);
return TRUE;
}
wxFrame::~wxFrame()
{
m_isBeingDeleted = TRUE;
DeleteAllBars();
}
bool wxFrame::Enable(bool enable)
{
if ( !wxWindow::Enable(enable) )
return FALSE;
if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
{
int iMaxMenu = m_frameMenuBar->GetMenuCount();
for ( int i = 0 ; i < iMaxMenu ; ++ i )
{
m_frameMenuBar->EnableTop( i , enable ) ;
}
}
return TRUE;
}
wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
const wxString& name)
{
wxStatusBar *statusBar = NULL;
statusBar = new wxStatusBar(this, id,
style, name);
statusBar->SetSize( 100 , 15 ) ;
statusBar->SetFieldsCount(number);
return statusBar;
}
void wxFrame::PositionStatusBar()
{
if (m_frameStatusBar )
{
int w, h;
GetClientSize(&w, &h);
int sw, sh;
m_frameStatusBar->GetSize(&sw, &sh);
// Since we wish the status bar to be directly under the client area,
// we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
m_frameStatusBar->SetSize(0, h, w, sh);
}
}
// Responds to colour changes, and passes event on to children.
void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
Refresh();
if ( m_frameStatusBar )
{
wxSysColourChangedEvent event2;
event2.SetEventObject( m_frameStatusBar );
m_frameStatusBar->ProcessEvent(event2);
}
// Propagate the event to the non-top-level children
wxWindow::OnSysColourChanged(event);
}
// Default activation behaviour - set the focus for the first child
// subwindow found.
void wxFrame::OnActivate(wxActivateEvent& event)
{
if ( !event.GetActive() )
{
// remember the last focused child if it is our child
m_winLastFocused = FindFocus();
// so we NULL it out if it's a child from some other frame
wxWindow *win = m_winLastFocused;
while ( win )
{
if ( win->IsTopLevel() )
{
if ( win != this )
{
m_winLastFocused = NULL;
}
break;
}
win = win->GetParent();
}
event.Skip();
}
else
{
// restore focus to the child which was last focused
wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
: NULL;
if ( !parent )
{
parent = this;
}
wxSetFocusToChild(parent, &m_winLastFocused);
if ( m_frameMenuBar != NULL )
{
m_frameMenuBar->MacInstallMenuBar() ;
}
else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
{
// Trying toplevel frame menbar
if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
}
}
}
void wxFrame::DetachMenuBar()
{
if ( m_frameMenuBar )
{
m_frameMenuBar->UnsetInvokingWindow();
}
wxFrameBase::DetachMenuBar();
}
void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
{
wxFrameBase::AttachMenuBar(menuBar);
if (m_frameMenuBar)
{
m_frameMenuBar->SetInvokingWindow( this );
}
}
void wxFrame::DoGetClientSize(int *x, int *y) const
{
wxWindow::DoGetClientSize( x , y ) ;
#if wxUSE_STATUSBAR
if ( GetStatusBar() && y )
{
int statusX, statusY;
GetStatusBar()->GetClientSize(&statusX, &statusY);
*y -= statusY;
}
#endif // wxUSE_STATUSBAR
wxPoint pt(GetClientAreaOrigin());
if ( y )
*y -= pt.y;
if ( x )
*x -= pt.x;
}
void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
{
int currentclientwidth , currentclientheight ;
int currentwidth , currentheight ;
GetClientSize( &currentclientwidth , &currentclientheight ) ;
GetSize( &currentwidth , &currentheight ) ;
// find the current client size
// Find the difference between the entire window (title bar and all)
// and the client area; add this to the new client size to move the
// window
DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
}
#if wxUSE_TOOLBAR
wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
{
if ( wxFrameBase::CreateToolBar(style, id, name) )
{
PositionToolBar();
}
return m_frameToolBar;
}
void wxFrame::PositionToolBar()
{
int cw, ch;
cw = m_width ;
ch = m_height ;
if ( GetStatusBar() )
{
int statusX, statusY;
GetStatusBar()->GetClientSize(&statusX, &statusY);
ch -= statusY;
}
if (GetToolBar())
{
int tw, th;
GetToolBar()->GetSize(& tw, & th);
if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
{
// Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
// means, pretend we don't have toolbar/status bar, so we
// have the original client size.
GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
}
else
{
// Use the 'real' position
GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
}
}
}
#endif

95
src/mac/classic/gauge.cpp Normal file
View File

@@ -0,0 +1,95 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gauge.cpp
// Purpose: wxGauge class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "gauge.h"
#endif
#include "wx/gauge.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
#endif
#include "wx/mac/uma.h"
bool wxGauge::Create(wxWindow *parent, wxWindowID id,
int range,
const wxPoint& pos,
const wxSize& s,
long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxGaugeBase::Create(parent, id, range, pos, s, style, validator, name) )
return false;
wxSize size = s ;
Rect bounds ;
Str255 title ;
m_rangeMax = range ;
m_gaugePos = 0 ;
if ( size.x == wxDefaultSize.x && size.y == wxDefaultSize.y)
{
size = wxSize( 200 , 16 ) ;
}
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style & 0xE0FFFFFF /* no borders on mac */ , validator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , range,
kControlProgressBarProc , (long) this ) ;
MacPostControlCreate() ;
return TRUE;
}
void wxGauge::SetShadowWidth(int w)
{
}
void wxGauge::SetBezelFace(int w)
{
}
void wxGauge::SetRange(int r)
{
m_rangeMax = r;
::SetControl32BitMaximum( (ControlHandle) m_macControl , m_rangeMax ) ;
}
void wxGauge::SetValue(int pos)
{
m_gaugePos = pos;
::SetControl32BitValue( (ControlHandle) m_macControl , m_gaugePos ) ;
}
int wxGauge::GetShadowWidth() const
{
return 0;
}
int wxGauge::GetBezelFace() const
{
return 0;
}
int wxGauge::GetRange() const
{
return m_rangeMax;
}
int wxGauge::GetValue() const
{
return m_gaugePos;
}

View File

@@ -0,0 +1,22 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gdiobj.cpp
// Purpose: wxGDIObject class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "gdiobj.h"
#endif
#include "wx/gdiobj.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxGDIObject, wxObject)
#endif
// TODO: Nothing to do, unless you want to.

View File

@@ -0,0 +1,385 @@
/////////////////////////////////////////////////////////////////////////////
// Name: glcanvas.cpp
// Purpose: wxGLCanvas, for using OpenGL with wxWindows under Macintosh
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "glcanvas.h"
#endif
#include "wx/wxprec.h"
#if defined(__BORLANDC__)
#pragma hdrstop
#endif
#include "wx/setup.h"
#if wxUSE_GLCANVAS
#ifndef WX_PRECOMP
#include "wx/frame.h"
#endif
#include "wx/settings.h"
#include "wx/log.h"
#include "wx/glcanvas.h"
#include "wx/mac/uma.h"
// DLL options compatibility check:
#include "wx/build.h"
WX_CHECK_BUILD_OPTIONS("wxGL")
/*
* GLContext implementation
*/
wxGLContext::wxGLContext(
AGLPixelFormat fmt, wxGLCanvas *win,
const wxPalette& palette,
const wxGLContext *other /* for sharing display lists */
)
{
m_window = win;
m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow()));
m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL);
wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") );
GLboolean b;
b = aglSetDrawable(m_glContext, m_drawable);
wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") );
aglEnable(m_glContext , AGL_BUFFER_RECT ) ;
b = aglSetCurrentContext(m_glContext);
wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") );
}
wxGLContext::~wxGLContext()
{
if (m_glContext)
{
aglSetCurrentContext(NULL);
aglDestroyContext(m_glContext);
}
}
void wxGLContext::SwapBuffers()
{
if (m_glContext)
{
aglSwapBuffers(m_glContext);
}
}
void wxGLContext::SetCurrent()
{
if (m_glContext)
{
aglSetCurrentContext(m_glContext);
}
}
void wxGLContext::Update()
{
if (m_glContext)
{
aglUpdateContext(m_glContext);
}
}
void wxGLContext::SetColour(const wxChar *colour)
{
wxColour col = wxTheColourDatabase->Find(colour);
if (col.Ok())
{
float r = (float)(col.Red()/256.0);
float g = (float)(col.Green()/256.0);
float b = (float)(col.Blue()/256.0);
glColor3f( r, g, b);
}
}
/*
* wxGLCanvas implementation
*/
IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
EVT_SIZE(wxGLCanvas::OnSize)
END_EVENT_TABLE()
wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette)
{
Create(parent, NULL, id, pos, size, style, name, attribList, palette);
}
wxGLCanvas::wxGLCanvas( wxWindow *parent,
const wxGLContext *shared, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette )
{
Create(parent, shared, id, pos, size, style, name, attribList, palette);
}
wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette )
{
Create(parent, shared ? shared->GetContext() : NULL, id, pos, size, style, name, attribList, palette);
}
wxGLCanvas::~wxGLCanvas()
{
if (m_glContext != NULL) {
delete m_glContext;
m_glContext = NULL;
}
}
static AGLPixelFormat ChoosePixelFormat(const int *attribList)
{
GLint data[512];
GLint defaultAttribs[] = { AGL_RGBA,
AGL_DOUBLEBUFFER,
AGL_MINIMUM_POLICY,
AGL_DEPTH_SIZE, 1, // use largest available depth buffer
AGL_RED_SIZE, 1,
AGL_GREEN_SIZE, 1,
AGL_BLUE_SIZE, 1,
AGL_ALPHA_SIZE, 0,
AGL_NONE };
GLint *attribs;
if (!attribList)
{
attribs = defaultAttribs;
}
else
{
int arg=0, p=0;
data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX
while( (attribList[arg]!=0) && (p<512) )
{
switch( attribList[arg++] )
{
case WX_GL_RGBA: data[p++] = AGL_RGBA; break;
case WX_GL_BUFFER_SIZE:
data[p++]=AGL_BUFFER_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_LEVEL:
data[p++]=AGL_LEVEL; data[p++]=attribList[arg++]; break;
case WX_GL_DOUBLEBUFFER: data[p++] = AGL_DOUBLEBUFFER; break;
case WX_GL_STEREO: data[p++] = AGL_STEREO; break;
case WX_GL_AUX_BUFFERS:
data[p++]=AGL_AUX_BUFFERS; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_RED:
data[p++]=AGL_RED_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_GREEN:
data[p++]=AGL_GREEN_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_BLUE:
data[p++]=AGL_BLUE_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_ALPHA:
data[p++]=AGL_ALPHA_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_DEPTH_SIZE:
data[p++]=AGL_DEPTH_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_STENCIL_SIZE:
data[p++]=AGL_STENCIL_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_ACCUM_RED:
data[p++]=AGL_ACCUM_RED_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_ACCUM_GREEN:
data[p++]=AGL_ACCUM_GREEN_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_ACCUM_BLUE:
data[p++]=AGL_ACCUM_BLUE_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_ACCUM_ALPHA:
data[p++]=AGL_ACCUM_ALPHA_SIZE; data[p++]=attribList[arg++]; break;
default:
break;
}
}
data[p] = 0;
attribs = data;
}
return aglChoosePixelFormat(NULL, 0, attribs);
}
bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette)
{
wxWindow::Create( parent, id, pos, size, style, name );
AGLPixelFormat fmt = ChoosePixelFormat(attribList);
wxCHECK_MSG( fmt, false, wxT("Couldn't create OpenGl pixel format") );
m_glContext = new wxGLContext(fmt, this, palette, shared);
m_macCanvasIsShown = true ;
aglDestroyPixelFormat(fmt);
return true;
}
void wxGLCanvas::SwapBuffers()
{
if (m_glContext)
m_glContext->SwapBuffers();
}
void wxGLCanvas::UpdateContext()
{
if (m_glContext)
m_glContext->Update();
}
void wxGLCanvas::SetViewport()
{
// viewport is initially set to entire port
// adjust glViewport to just this window
int x = 0 ;
int y = 0 ;
wxWindow* iter = this ;
while( iter->GetParent() )
{
iter = iter->GetParent() ;
}
if ( iter && iter->IsTopLevel() )
{
MacClientToRootWindow( &x , &y ) ;
int width, height;
GetClientSize(& width, & height);
Rect bounds ;
GetWindowPortBounds( MAC_WXHWND(MacGetRootWindow()) , &bounds ) ;
GLint parms[4] ;
parms[0] = x ;
parms[1] = bounds.bottom - bounds.top - ( y + height ) ;
parms[2] = width ;
parms[3] = height ;
if ( !m_macCanvasIsShown )
parms[0] += 20000 ;
aglSetInteger( m_glContext->m_glContext , AGL_BUFFER_RECT , parms ) ;
}
}
void wxGLCanvas::OnSize(wxSizeEvent& event)
{
MacUpdateView() ;
}
void wxGLCanvas::MacUpdateView()
{
if (m_glContext)
{
UpdateContext();
m_glContext->SetCurrent();
SetViewport();
}
}
void wxGLCanvas::MacSuperChangedPosition()
{
MacUpdateView() ;
wxWindow::MacSuperChangedPosition() ;
}
void wxGLCanvas::MacTopLevelWindowChangedPosition()
{
MacUpdateView() ;
wxWindow::MacTopLevelWindowChangedPosition() ;
}
void wxGLCanvas::SetCurrent()
{
if (m_glContext)
{
m_glContext->SetCurrent();
}
}
void wxGLCanvas::SetColour(const wxChar *colour)
{
if (m_glContext)
m_glContext->SetColour(colour);
}
bool wxGLCanvas::Show(bool show)
{
if ( !wxWindow::Show( show ) )
return FALSE ;
if ( !show )
{
if ( m_macCanvasIsShown )
{
m_macCanvasIsShown = false ;
SetViewport() ;
}
}
else
{
if ( MacIsReallyShown() && !m_macCanvasIsShown )
{
m_macCanvasIsShown = true ;
SetViewport() ;
}
}
return TRUE ;
}
void wxGLCanvas::MacSuperShown( bool show )
{
if ( !show )
{
if ( m_macCanvasIsShown )
{
m_macCanvasIsShown = false ;
SetViewport() ;
}
}
else
{
if ( MacIsReallyShown() && !m_macCanvasIsShown )
{
m_macCanvasIsShown = true ;
SetViewport() ;
}
}
wxWindow::MacSuperShown( show ) ;
}
//---------------------------------------------------------------------------
// wxGLApp
//---------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLApp, wxApp)
bool wxGLApp::InitGLVisual(int *attribList)
{
AGLPixelFormat fmt = ChoosePixelFormat(attribList);
if (fmt != NULL) {
aglDestroyPixelFormat(fmt);
return true;
} else
return false;
}
wxGLApp::~wxGLApp(void)
{
}
#endif // wxUSE_GLCANVAS

1653
src/mac/classic/gsocket.c Normal file

File diff suppressed because it is too large Load Diff

181
src/mac/classic/gsockosx.c Normal file
View File

@@ -0,0 +1,181 @@
/* -------------------------------------------------------------------------
* Project: GSocket (Generic Socket) for WX
* Name: gsockosx.c
* Purpose: GSocket: Mac OS X mach-o part
* CVSID: $Id$
* Mac code by Brian Victor, February 2002. Email comments to bhv1@psu.edu
* ------------------------------------------------------------------------- */
#include "wx/setup.h"
#if wxUSE_SOCKETS
#include <stdlib.h>
#include "wx/gsocket.h"
#include "wx/unix/gsockunx.h"
#include <CoreFoundation/CoreFoundation.h>
#define ALL_CALLBACK_TYPES (kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack)
struct MacGSocketData
{
CFSocketRef socket;
CFRunLoopSourceRef source;
};
void Mac_Socket_Callback(CFSocketRef s, CFSocketCallBackType callbackType,
CFDataRef address, const void* data, void* info)
{
GSocket* socket = (GSocket*)info;
struct MacGSocketData* macdata;
macdata = (struct MacGSocketData*)socket->m_gui_dependent;
if (!macdata) return;
switch (callbackType)
{
case kCFSocketConnectCallBack:
assert(!socket->m_server);
socket->m_functions->Detected_Write(socket);
break;
case kCFSocketReadCallBack:
socket->m_functions->Detected_Read(socket);
break;
case kCFSocketWriteCallBack:
socket->m_functions->Detected_Write(socket);
break;
default:
break; /* We shouldn't get here. */
}
}
struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket)
{
/* If socket is already created, returns a pointer to the data */
/* Otherwise, creates socket and returns the pointer */
CFSocketContext cont;
struct MacGSocketData* data = (struct MacGSocketData*)socket->m_gui_dependent;
if (data && data->source) return data;
/* CFSocket has not been created, create it: */
if (socket->m_fd < 0 || !data) return NULL;
cont.version = 0; cont.retain = NULL;
cont.release = NULL; cont.copyDescription = NULL;
cont.info = socket;
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0);
assert(source);
socket->m_gui_dependent = (char*)data;
/* Keep the source and the socket around. */
data->source = source;
data->socket = cf;
return data;
}
int _GSocket_GUI_Init(void)
{
return 1;
}
void _GSocket_GUI_Cleanup(void)
{
}
int _GSocket_GUI_Init_Socket(GSocket *socket)
{
struct MacGSocketData *data = malloc(sizeof(struct MacGSocketData));
if (data)
{
socket->m_gui_dependent = (char*)data;
data->socket = NULL;
data->source = NULL;
return 1;
}
return 0;
}
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
{
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
if (data)
{
CFRelease(data->socket);
free(data);
}
}
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
{
int c;
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
switch (event)
{
case GSOCK_CONNECTION:
if(socket->m_server)
c = kCFSocketReadCallBack;
else
c = kCFSocketConnectCallBack;
break;
case GSOCK_LOST:
case GSOCK_INPUT:
c = kCFSocketReadCallBack;
break;
case GSOCK_OUTPUT:
c = kCFSocketWriteCallBack;
break;
default:
c = 0;
}
CFSocketEnableCallBacks(data->socket, c);
}
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
{
int c;
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
switch (event)
{
case GSOCK_CONNECTION:
if(socket->m_server)
c = kCFSocketReadCallBack;
else
c = kCFSocketConnectCallBack;
break;
case GSOCK_LOST:
case GSOCK_INPUT:
c = kCFSocketReadCallBack;
break;
case GSOCK_OUTPUT:
c = kCFSocketWriteCallBack;
break;
default:
c = 0;
}
CFSocketDisableCallBacks(data->socket, c);
}
void _GSocket_Enable_Events(GSocket *socket)
{
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode);
}
void _GSocket_Disable_Events(GSocket *socket)
{
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
/* CFSocketInvalidate does CFRunLoopRemoveSource anyway */
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes);
CFSocketInvalidate(data->socket);
}
#endif // wxUSE_SOCKETS

View File

@@ -0,0 +1,181 @@
/* -------------------------------------------------------------------------
* Project: GSocket (Generic Socket) for WX
* Name: gsockosx.c
* Purpose: GSocket: Mac OS X mach-o part
* CVSID: $Id$
* Mac code by Brian Victor, February 2002. Email comments to bhv1@psu.edu
* ------------------------------------------------------------------------- */
#include "wx/setup.h"
#if wxUSE_SOCKETS
#include <stdlib.h>
#include "wx/gsocket.h"
#include "wx/unix/gsockunx.h"
#include <CoreFoundation/CoreFoundation.h>
#define ALL_CALLBACK_TYPES (kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack)
struct MacGSocketData
{
CFSocketRef socket;
CFRunLoopSourceRef source;
};
void Mac_Socket_Callback(CFSocketRef s, CFSocketCallBackType callbackType,
CFDataRef address, const void* data, void* info)
{
GSocket* socket = (GSocket*)info;
struct MacGSocketData* macdata;
macdata = (struct MacGSocketData*)socket->m_gui_dependent;
if (!macdata) return;
switch (callbackType)
{
case kCFSocketConnectCallBack:
assert(!socket->m_server);
socket->m_functions->Detected_Write(socket);
break;
case kCFSocketReadCallBack:
socket->m_functions->Detected_Read(socket);
break;
case kCFSocketWriteCallBack:
socket->m_functions->Detected_Write(socket);
break;
default:
break; /* We shouldn't get here. */
}
}
struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket)
{
/* If socket is already created, returns a pointer to the data */
/* Otherwise, creates socket and returns the pointer */
CFSocketContext cont;
struct MacGSocketData* data = (struct MacGSocketData*)socket->m_gui_dependent;
if (data && data->source) return data;
/* CFSocket has not been created, create it: */
if (socket->m_fd < 0 || !data) return NULL;
cont.version = 0; cont.retain = NULL;
cont.release = NULL; cont.copyDescription = NULL;
cont.info = socket;
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0);
assert(source);
socket->m_gui_dependent = (char*)data;
/* Keep the source and the socket around. */
data->source = source;
data->socket = cf;
return data;
}
int _GSocket_GUI_Init(void)
{
return 1;
}
void _GSocket_GUI_Cleanup(void)
{
}
int _GSocket_GUI_Init_Socket(GSocket *socket)
{
struct MacGSocketData *data = malloc(sizeof(struct MacGSocketData));
if (data)
{
socket->m_gui_dependent = (char*)data;
data->socket = NULL;
data->source = NULL;
return 1;
}
return 0;
}
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
{
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
if (data)
{
CFRelease(data->socket);
free(data);
}
}
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
{
int c;
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
switch (event)
{
case GSOCK_CONNECTION:
if(socket->m_server)
c = kCFSocketReadCallBack;
else
c = kCFSocketConnectCallBack;
break;
case GSOCK_LOST:
case GSOCK_INPUT:
c = kCFSocketReadCallBack;
break;
case GSOCK_OUTPUT:
c = kCFSocketWriteCallBack;
break;
default:
c = 0;
}
CFSocketEnableCallBacks(data->socket, c);
}
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
{
int c;
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
switch (event)
{
case GSOCK_CONNECTION:
if(socket->m_server)
c = kCFSocketReadCallBack;
else
c = kCFSocketConnectCallBack;
break;
case GSOCK_LOST:
case GSOCK_INPUT:
c = kCFSocketReadCallBack;
break;
case GSOCK_OUTPUT:
c = kCFSocketWriteCallBack;
break;
default:
c = 0;
}
CFSocketDisableCallBacks(data->socket, c);
}
void _GSocket_Enable_Events(GSocket *socket)
{
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode);
}
void _GSocket_Disable_Events(GSocket *socket)
{
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
if (!data) return;
/* CFSocketInvalidate does CFRunLoopRemoveSource anyway */
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes);
CFSocketInvalidate(data->socket);
}
#endif // wxUSE_SOCKETS

View File

@@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////
// Name: helpxxxx.cpp
// Purpose: Help system: native implementation
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "helpxxxx.h"
#endif
#include "wx/stubs/helpxxxx.h"
#include <string.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxXXXXHelpController, wxHelpControllerBase)
#endif
wxXXXXHelpController::wxXXXXHelpController()
{
m_helpFile = "";
}
wxXXXXHelpController::~wxXXXXHelpController()
{
}
bool wxXXXXHelpController::Initialize(const wxString& filename)
{
m_helpFile = filename;
// TODO any other inits
return TRUE;
}
bool wxXXXXHelpController::LoadFile(const wxString& file)
{
m_helpFile = file;
// TODO
return TRUE;
}
bool wxXXXXHelpController::DisplayContents()
{
// TODO
return FALSE;
}
bool wxXXXXHelpController::DisplaySection(int section)
{
// TODO
return FALSE;
}
bool wxXXXXHelpController::DisplayBlock(long block)
{
// TODO
return FALSE;
}
bool wxXXXXHelpController::KeywordSearch(const wxString& k,
wxHelpSearchMode WXUNUSED(mode))
{
if (m_helpFile == "") return FALSE;
// TODO
return FALSE;
}
// Can't close the help window explicitly in WinHelp
bool wxXXXXHelpController::Quit()
{
// TODO
return FALSE;
}
void wxXXXXHelpController::OnQuit()
{
}

417
src/mac/classic/hid.cpp Normal file
View File

@@ -0,0 +1,417 @@
#include "hid.h"
#define wxFORCECHECK_MSG(arg, msg) \
{\
if (arg) \
{\
wxLogSysError(wxString::Format(wxT("Message:%s\nHID: %s failed!"), wxT(msg), wxT(#arg)));\
return false;\
}\
}
#define wxIOCHECK(arg, msg) wxFORCECHECK_MSG(arg != kIOReturnSuccess, msg)
#define wxKERNCHECK(arg, msg) wxFORCECHECK_MSG(arg != KERN_SUCCESS, msg)
#define wxSCHECK(arg, msg) wxFORCECHECK_MSG(arg != S_OK, msg)
void CFShowTypeIDDescription(CFTypeRef pData)
{
if(!pData)
{
wxMessageBox("AHHH!");
return;
}
wxMessageBox(
CFStringGetCStringPtr(
CFCopyTypeIDDescription(CFGetTypeID(pData)),CFStringGetSystemEncoding()
)
);
}
// ============================================================================
// implementation
// ============================================================================
bool wxHIDDevice::Create (const int& nClass, const int& nType)
{
//Create the mach port
wxIOCHECK(IOMasterPort(bootstrap_port, &m_pPort), "Could not create mach port");
//Dictionary that will hold first
//the matching dictionary for determining which kind of devices we want,
//then later some registry properties from an iterator (see below)
CFMutableDictionaryRef pDictionary;
//Create a dictionary
//The call to IOServiceMatching filters down the
//the services we want to hid services (and also eats the
//dictionary up for us (consumes one reference))
wxASSERT((pDictionary = IOServiceMatching(kIOHIDDeviceKey)) != NULL );
//Here we'll filter down the services to what we want
if (nType != -1)
{
CFNumberRef pType = CFNumberCreate(kCFAllocatorDefault,
kCFNumberIntType, &nType);
CFDictionarySetValue(pDictionary, CFSTR(kIOHIDPrimaryUsageKey), pType);
CFRelease(pType);
}
if (nClass != -1)
{
CFNumberRef pClass = CFNumberCreate(kCFAllocatorDefault,
kCFNumberIntType, &nClass);
CFDictionarySetValue(pDictionary, CFSTR(kIOHIDPrimaryUsagePageKey), pClass);
CFRelease(pClass);
}
//Now get the maching services
io_iterator_t pIterator;
wxIOCHECK(IOServiceGetMatchingServices(m_pPort, pDictionary, &pIterator), "No Matching HID Services");
wxASSERT(pIterator != NULL);
//Now we iterate through them
io_object_t pObject;
while ( (pObject = IOIteratorNext(pIterator)) != NULL)
{
wxASSERT(IORegistryEntryCreateCFProperties(pObject, &pDictionary,
kCFAllocatorDefault, kNilOptions) == KERN_SUCCESS);
//Just for sanity :)
wxASSERT(CFGetTypeID(CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey))) == CFStringGetTypeID());
//Get [product] name
m_szName = CFStringGetCStringPtr (
(CFStringRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey)),
CFStringGetSystemEncoding()
);
//
//Now the hard part - in order to scan things we need "cookies" -
//
wxCFArray CookieArray = CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDElementKey));
BuildCookies(CookieArray);
if (m_ppQueue != NULL)
wxASSERT((*m_ppQueue)->start(m_ppQueue) == S_OK);
//Create the interface (good grief - long function names!)
SInt32 nScore;
IOCFPlugInInterface** ppPlugin;
wxIOCHECK(IOCreatePlugInInterfaceForService(pObject, kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &ppPlugin, &nScore), "");
//Now, the final thing we can check before we fall back to asserts
//(because the dtor only checks if the device is ok, so if anything
//fails from now on the dtor will delete the device anyway, so we can't break from this).
//Get the HID interface from the plugin to the mach port
wxSCHECK((*ppPlugin)->QueryInterface(ppPlugin,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void**) &m_ppDevice), "");
//release the plugin
(*ppPlugin)->Release(ppPlugin);
//open the HID interface...
wxASSERT((*m_ppDevice)->open(m_ppDevice, 0) == S_OK);
//cleanup
CFRelease(pDictionary);
IOObjectRelease(pObject);
break;
}
//iterator cleanup
IOObjectRelease(pIterator);
return true;
}//end Create()
void wxHIDDevice::AddCookie(CFTypeRef Data, const int& i)
{
CFNumberGetValue(
(CFNumberRef) CFDictionaryGetValue ( (CFDictionaryRef) Data
, CFSTR(kIOHIDElementCookieKey)
),
kCFNumberIntType,
&m_pCookies[i]
);
}
void wxHIDDevice::AddCookieInQueue(CFTypeRef Data, const int& i)
{
AddCookie(Data, i);
wxASSERT((*m_ppQueue)->addElement(m_ppQueue, m_pCookies[i], 0) == S_OK);//3rd Param flags (none yet)
}
void wxHIDDevice::InitCookies(const size_t& dwSize, bool bQueue)
{
m_pCookies = new IOHIDElementCookie[dwSize];
if (bQueue)
{
wxASSERT( m_ppQueue != NULL);
wxASSERT( (m_ppQueue = (*m_ppDevice)->allocQueue(m_ppDevice)) != NULL);
wxASSERT( (*m_ppQueue)->create(m_ppQueue, 0, 512) == S_OK); //Param 2, flags, none yet
}
}
bool wxHIDDevice::IsActive(const int& nIndex)
{
wxASSERT(m_pCookies[nIndex] != NULL);
IOHIDEventStruct Event;
(*m_ppDevice)->getElementValue(m_ppDevice, m_pCookies[nIndex], &Event);
return !!Event.value;
}
wxHIDDevice::~wxHIDDevice()
{
if (m_ppDevice != NULL)
{
(*m_ppDevice)->close(m_ppDevice);
(*m_ppDevice)->Release(m_ppDevice);
mach_port_deallocate(mach_task_self(), m_pPort);
}
if (m_pCookies != NULL)
{
delete [] m_pCookies;
if (m_ppQueue != NULL)
{
(*m_ppQueue)->stop(m_ppQueue);
(*m_ppQueue)->dispose(m_ppQueue);
(*m_ppQueue)->Release(m_ppQueue);
}
}
}
/*
enum
{
kHIDUsage_KeyboardHyphen = 0x2D,
kHIDUsage_KeyboardEqualSign = 0x2E,
kHIDUsage_KeyboardOpenBracket = 0x2F,
kHIDUsage_KeyboardCloseBracket = 0x30,
kHIDUsage_KeyboardBackslash = 0x31, //* \ or | *
kHIDUsage_KeyboardNonUSPound = 0x32, /* Non-US # or _ *
kHIDUsage_KeyboardSemicolon = 0x33, /* ; or : *
kHIDUsage_KeyboardQuote = 0x34, /* ' or " *
kHIDUsage_KeyboardGraveAccentAndTilde = 0x35, /* Grave Accent and Tilde *
kHIDUsage_KeyboardComma = 0x36, /* , or < *
kHIDUsage_KeyboardPeriod = 0x37, /* . or > *
kHIDUsage_KeyboardSlash = 0x38, /* / or ? *
kHIDUsage_KeyboardCapsLock = 0x39, /* Caps Lock *
kHIDUsage_KeyboardPrintScreen = 0x46, /* Print Screen *
kHIDUsage_KeyboardScrollLock = 0x47, /* Scroll Lock *
kHIDUsage_KeyboardPause = 0x48, /* Pause *
kHIDUsage_KeyboardInsert = 0x49, /* Insert *
kHIDUsage_KeyboardHome = 0x4A, /* Home *
kHIDUsage_KeyboardDeleteForward = 0x4C, /* Delete Forward *
kHIDUsage_KeyboardUpArrow
kHIDUsage_KeypadNumLock
kHIDUsage_KeypadSlash
kHIDUsage_KeypadAsterisk
kHIDUsage_KeypadHyphen
kHIDUsage_KeypadPlus
kHIDUsage_KeypadEnter
kHIDUsage_KeypadPeriod
kHIDUsage_KeyboardNonUSBackslash
kHIDUsage_KeyboardApplication
kHIDUsage_KeyboardPower
kHIDUsage_KeypadEqualSign
};
/*
enum wxKeyCode
{
WXK_START = 300,
WXK_LBUTTON,
WXK_RBUTTON,
WXK_CANCEL,
WXK_MBUTTON,
WXK_CLEAR,
WXK_SHIFT,
WXK_ALT,
WXK_CONTROL,
WXK_MENU,
WXK_PAUSE,
WXK_PRIOR, * Page up *
WXK_NEXT, * Page down *
WXK_END,
WXK_HOME,
WXK_LEFT,
WXK_UP,
WXK_RIGHT,
WXK_DOWN,
WXK_SELECT,
WXK_PRINT,
WXK_EXECUTE,
WXK_SNAPSHOT,
WXK_INSERT,
WXK_HELP,
WXK_MULTIPLY,
WXK_ADD,
WXK_SEPARATOR,
WXK_SUBTRACT,
WXK_DECIMAL,
WXK_DIVIDE,
WXK_PAGEUP,
WXK_PAGEDOWN,
WXK_NUMPAD_SPACE,
WXK_NUMPAD_TAB,
WXK_NUMPAD_ENTER,
WXK_NUMPAD_HOME,
WXK_NUMPAD_LEFT,
WXK_NUMPAD_UP,
WXK_NUMPAD_RIGHT,
WXK_NUMPAD_DOWN,
WXK_NUMPAD_PRIOR,
WXK_NUMPAD_PAGEUP,
WXK_NUMPAD_NEXT,
WXK_NUMPAD_PAGEDOWN,
WXK_NUMPAD_END,
WXK_NUMPAD_BEGIN,
WXK_NUMPAD_INSERT,
WXK_NUMPAD_DELETE,
WXK_NUMPAD_EQUAL,
WXK_NUMPAD_MULTIPLY,
WXK_NUMPAD_ADD,
WXK_NUMPAD_SEPARATOR,
WXK_NUMPAD_SUBTRACT,
WXK_NUMPAD_DECIMAL,
WXK_NUMPAD_DIVIDE,
WXK_WINDOWS_LEFT,
WXK_WINDOWS_RIGHT,
WXK_WINDOWS_MENU ,
WXK_COMMAND
};
*/
enum
{
WXK_RSHIFT = 400,
WXK_RALT,
WXK_RCONTROL,
WXK_RMENU
};
bool wxHIDKeyboard::Create()
{
return wxHIDDevice::Create(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
}
void wxHIDKeyboard::BuildCookies(wxCFArray& Array)
{
Array = CFDictionaryGetValue((CFDictionaryRef)Array[0], CFSTR(kIOHIDElementKey));
InitCookies(500);
int i,
nUsage;
for (i = 0; i < Array.Count(); ++i)
{
CFNumberGetValue(
(CFNumberRef) CFDictionaryGetValue((CFDictionaryRef) Array[i], CFSTR(kIOHIDElementUsageKey)),
kCFNumberLongType, &nUsage);
if (nUsage >= kHIDUsage_KeyboardA && nUsage <= kHIDUsage_KeyboardZ)
AddCookie(Array[i], 'A' + (nUsage - kHIDUsage_KeyboardA) );
else if (nUsage >= kHIDUsage_Keyboard1 && nUsage <= kHIDUsage_Keyboard9)
AddCookie(Array[i], '1' + (nUsage - kHIDUsage_Keyboard1) );
else if (nUsage >= kHIDUsage_KeyboardF1 && nUsage <= kHIDUsage_KeyboardF12)
AddCookie(Array[i], WXK_F1 + (nUsage - kHIDUsage_KeyboardF1) );
else if (nUsage >= kHIDUsage_KeyboardF13 && nUsage <= kHIDUsage_KeyboardF24)
AddCookie(Array[i], WXK_F13 + (nUsage - kHIDUsage_KeyboardF13) );
else if (nUsage >= kHIDUsage_Keypad1 && nUsage <= kHIDUsage_Keypad9)
AddCookie(Array[i], WXK_NUMPAD1 + (nUsage - kHIDUsage_Keypad1) );
else switch (nUsage)
{
//0's (wx & ascii go 0-9, but HID goes 1-0)
case kHIDUsage_Keyboard0:
AddCookie(Array[i],'0');
break;
case kHIDUsage_Keypad0:
AddCookie(Array[i],WXK_NUMPAD0);
break;
//Basic
case kHIDUsage_KeyboardReturnOrEnter:
AddCookie(Array[i], WXK_RETURN);
break;
case kHIDUsage_KeyboardEscape:
AddCookie(Array[i], WXK_ESCAPE);
break;
case kHIDUsage_KeyboardDeleteOrBackspace:
AddCookie(Array[i], WXK_BACK);
break;
case kHIDUsage_KeyboardTab:
AddCookie(Array[i], WXK_TAB);
break;
case kHIDUsage_KeyboardSpacebar:
AddCookie(Array[i], WXK_SPACE);
break;
case kHIDUsage_KeyboardPageUp:
AddCookie(Array[i], WXK_PRIOR);
break;
case kHIDUsage_KeyboardEnd:
AddCookie(Array[i], WXK_END);
break;
case kHIDUsage_KeyboardPageDown:
AddCookie(Array[i], WXK_NEXT);
break;
case kHIDUsage_KeyboardRightArrow:
AddCookie(Array[i], WXK_RIGHT);
break;
case kHIDUsage_KeyboardLeftArrow:
AddCookie(Array[i], WXK_LEFT);
break;
case kHIDUsage_KeyboardDownArrow:
AddCookie(Array[i], WXK_DOWN);
break;
case kHIDUsage_KeyboardUpArrow:
AddCookie(Array[i], WXK_UP);
break;
//LEDS
case kHIDUsage_KeyboardCapsLock:
AddCookie(Array[i],WXK_CAPITAL);
break;
case kHIDUsage_KeypadNumLock:
AddCookie(Array[i],WXK_NUMLOCK);
break;
case kHIDUsage_KeyboardScrollLock:
AddCookie(Array[i],WXK_SCROLL);
break;
//Menu keys, Shift, other specials
case kHIDUsage_KeyboardLeftControl:
AddCookie(Array[i],WXK_CONTROL);
break;
case kHIDUsage_KeyboardLeftShift:
AddCookie(Array[i],WXK_SHIFT);
break;
case kHIDUsage_KeyboardLeftAlt:
AddCookie(Array[i],WXK_ALT);
break;
case kHIDUsage_KeyboardLeftGUI:
AddCookie(Array[i],WXK_MENU);
break;
case kHIDUsage_KeyboardRightControl:
AddCookie(Array[i],WXK_RCONTROL);
break;
case kHIDUsage_KeyboardRightShift:
AddCookie(Array[i],WXK_RSHIFT);
break;
case kHIDUsage_KeyboardRightAlt:
AddCookie(Array[i],WXK_RALT);
break;
case kHIDUsage_KeyboardRightGUI:
AddCookie(Array[i],WXK_RMENU);
break;
//Default
default:
//not in wx keycodes - do nothing....
break;
}
}
}//end buildcookies

132
src/mac/classic/icon.cpp Normal file
View File

@@ -0,0 +1,132 @@
/////////////////////////////////////////////////////////////////////////////
// Name: icon.cpp
// Purpose: wxIcon class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "icon.h"
#endif
#include "wx/icon.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
#endif
#include "wx/mac/private.h"
/*
* Icons
*/
wxIcon::wxIcon()
{
}
wxIcon::wxIcon(const char bits[], int width, int height) :
wxBitmap(bits, width, height)
{
}
wxIcon::wxIcon( const char **bits ) :
wxBitmap(bits)
{
}
wxIcon::wxIcon( char **bits ) :
wxBitmap(bits)
{
}
wxIcon::wxIcon(const wxString& icon_file, int flags,
int desiredWidth, int desiredHeight)
{
LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
}
wxIcon::~wxIcon()
{
}
bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
int desiredWidth, int desiredHeight)
{
UnRef();
m_refData = new wxBitmapRefData;
wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
if ( handler )
return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
else
return FALSE;
}
void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
{
wxIcon *icon = (wxIcon*)(&bmp);
*this = *icon;
}
IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight)
{
short theId = -1 ;
if ( name == wxT("wxICON_INFORMATION") )
{
theId = kNoteIcon ;
}
else if ( name == wxT("wxICON_QUESTION") )
{
theId = kCautionIcon ;
}
else if ( name == wxT("wxICON_WARNING") )
{
theId = kCautionIcon ;
}
else if ( name == wxT("wxICON_ERROR") )
{
theId = kStopIcon ;
}
else
{
Str255 theName ;
OSType theType ;
wxMacStringToPascal( name , theName ) ;
Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
if ( resHandle != 0L )
{
GetResInfo( resHandle , &theId , &theType , theName ) ;
ReleaseResource( resHandle ) ;
}
}
if ( theId != -1 )
{
CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
if ( theIcon )
{
M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
M_BITMAPHANDLERDATA->m_width = 32 ;
M_BITMAPHANDLERDATA->m_height = 32 ;
M_BITMAPHANDLERDATA->m_depth = 8 ;
M_BITMAPHANDLERDATA->m_ok = true ;
M_BITMAPHANDLERDATA->m_numColors = 256 ;
M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
return TRUE ;
}
}
return FALSE ;
}

View File

@@ -0,0 +1,286 @@
/////////////////////////////////////////////////////////////////////////////
// Name: joystick.cpp
// Purpose: wxJoystick class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "joystick.h"
#endif
#include "wx/setup.h"
#include "wx/joystick.h"
#if wxUSE_JOYSTICK
IMPLEMENT_DYNAMIC_CLASS(wxJoystick, wxObject)
// Attributes
////////////////////////////////////////////////////////////////////////////
wxPoint wxJoystick::GetPosition() const
{
// TODO
return wxPoint(0, 0);
}
int wxJoystick::GetZPosition() const
{
// TODO
return 0;
}
int wxJoystick::GetButtonState() const
{
// TODO
return 0;
}
int wxJoystick::GetPOVPosition() const
{
// TODO
return 0;
}
int wxJoystick::GetPOVCTSPosition() const
{
// TODO
return 0;
}
int wxJoystick::GetRudderPosition() const
{
// TODO
return 0;
}
int wxJoystick::GetUPosition() const
{
// TODO
return 0;
}
int wxJoystick::GetVPosition() const
{
// TODO
return 0;
}
int wxJoystick::GetMovementThreshold() const
{
// TODO
return 0;
}
void wxJoystick::SetMovementThreshold(int threshold)
{
// TODO
}
// Capabilities
////////////////////////////////////////////////////////////////////////////
bool wxJoystick::IsOk() const
{
// TODO
return FALSE;
}
int wxJoystick::GetNumberJoysticks() const
{
// TODO
return 0;
}
int wxJoystick::GetManufacturerId() const
{
// TODO
return 0;
}
int wxJoystick::GetProductId() const
{
// TODO
return 0;
}
wxString wxJoystick::GetProductName() const
{
// TODO
return wxString(wxT(""));
}
int wxJoystick::GetXMin() const
{
// TODO
return 0;
}
int wxJoystick::GetYMin() const
{
// TODO
return 0;
}
int wxJoystick::GetZMin() const
{
// TODO
return 0;
}
int wxJoystick::GetXMax() const
{
// TODO
return 0;
}
int wxJoystick::GetYMax() const
{
// TODO
return 0;
}
int wxJoystick::GetZMax() const
{
// TODO
return 0;
}
int wxJoystick::GetNumberButtons() const
{
// TODO
return 0;
}
int wxJoystick::GetNumberAxes() const
{
// TODO
return 0;
}
int wxJoystick::GetMaxButtons() const
{
// TODO
return 0;
}
int wxJoystick::GetMaxAxes() const
{
// TODO
return 0;
}
int wxJoystick::GetPollingMin() const
{
// TODO
return 0;
}
int wxJoystick::GetPollingMax() const
{
// TODO
return 0;
}
int wxJoystick::GetRudderMin() const
{
// TODO
return 0;
}
int wxJoystick::GetRudderMax() const
{
// TODO
return 0;
}
int wxJoystick::GetUMin() const
{
// TODO
return 0;
}
int wxJoystick::GetUMax() const
{
// TODO
return 0;
}
int wxJoystick::GetVMin() const
{
// TODO
return 0;
}
int wxJoystick::GetVMax() const
{
// TODO
return 0;
}
bool wxJoystick::HasRudder() const
{
// TODO
return FALSE;
}
bool wxJoystick::HasZ() const
{
// TODO
return FALSE;
}
bool wxJoystick::HasU() const
{
// TODO
return FALSE;
}
bool wxJoystick::HasV() const
{
// TODO
return FALSE;
}
bool wxJoystick::HasPOV() const
{
// TODO
return FALSE;
}
bool wxJoystick::HasPOV4Dir() const
{
// TODO
return FALSE;
}
bool wxJoystick::HasPOVCTS() const
{
// TODO
return FALSE;
}
// Operations
////////////////////////////////////////////////////////////////////////////
bool wxJoystick::SetCapture(wxWindow* win, int pollingFreq)
{
// TODO
return FALSE;
}
bool wxJoystick::ReleaseCapture()
{
// TODO
return FALSE;
}
#endif
// wxUSE_JOYSTICK

1023
src/mac/classic/listbox.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,162 @@
/* -------------------------------------------------------------------------
* Project: Mac Notifier Support
* Name: macnotfy.c
* Author: Stefan CSomor
* Purpose: Mac Notifier main file
* CVSID: $Id$
* -------------------------------------------------------------------------
*/
#include "wx/wx.h"
#include "wx/mac/private.h"
#include "wx/mac/macnotfy.h"
const short kMaxEvents = 1000 ;
struct wxMacNotificationEvents
{
short top ;
short bottom ;
wxMacNotificationProcPtr proc[kMaxEvents] ;
unsigned long events[kMaxEvents] ;
void* data[kMaxEvents] ;
} ;
typedef struct wxMacNotificationEvents wxMacNotificationEvents ;
static wxMacNotificationEvents gMacNotificationEvents ;
static ProcessSerialNumber gAppProcess ;
void wxMacWakeUp()
{
ProcessSerialNumber psn ;
Boolean isSame ;
psn.highLongOfPSN = 0 ;
psn.lowLongOfPSN = kCurrentProcess ;
SameProcess( &gAppProcess , &psn , &isSame ) ;
if ( isSame )
{
#if TARGET_CARBON
EventRef dummyEvent ;
OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(),
kEventAttributeNone, &dummyEvent);
if (err == noErr)
{
err = PostEventToQueue(GetMainEventQueue(), dummyEvent,
kEventPriorityHigh);
}
#else
PostEvent( nullEvent , 0 ) ;
#endif
}
else
{
WakeUpProcess( &gAppProcess ) ;
}
}
void wxMacCreateNotifierTable()
{
GetCurrentProcess(&gAppProcess);
gMacNotificationEvents.top = 0 ;
gMacNotificationEvents.bottom = 0 ;
for ( int i = 0 ; i < kMaxEvents ; ++i )
{
gMacNotificationEvents.proc[i] = NULL ;
gMacNotificationEvents.events[i] = NULL ;
gMacNotificationEvents.data[i] = NULL ;
}
}
void wxMacDestroyNotifierTable()
{
}
wxMacNotifierTableRef wxMacGetNotifierTable()
{
return (wxMacNotifierTableRef) &gMacNotificationEvents ;
}
void wxMacAddEvent(
wxMacNotifierTableRef table ,
wxMacNotificationProcPtr handler ,
unsigned long event ,
void* data ,
short wakeUp )
{
wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
wxASSERT_MSG( handler != NULL , wxT("illegal notification proc ptr") ) ;
/* this should be protected eventually */
short index = e->top++ ;
if ( e->top == kMaxEvents )
e->top = 0 ;
e->proc[index] = handler ;
e->events[index] = event ;
e->data[index] = data ;
if ( wakeUp )
wxMacWakeUp() ;
}
bool gInProcessing = false ;
void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table , void* data )
{
wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
/* this should be protected eventually */
short index = e->bottom ;
while ( e->top != index )
{
if ( e->data[index] == data )
e->data[index] = NULL ;
index++ ;
if ( index == kMaxEvents )
index = 0 ;
}
}
void wxMacProcessNotifierEvents()
{
// if ( gInProcessing )
// return ;
gInProcessing = true ;
if ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
{
// we only should process the notifiers that were here when we entered it
// otherwise we might never get out...
short count = gMacNotificationEvents.top - gMacNotificationEvents.bottom ;
if ( count < 0 )
count += kMaxEvents ;
while ( count-- )
{
// consume event at bottom
short index = gMacNotificationEvents.bottom++ ;
if ( gMacNotificationEvents.bottom == kMaxEvents )
gMacNotificationEvents.bottom = 0 ;
void* data = gMacNotificationEvents.data[index] ;
unsigned long event = gMacNotificationEvents.events[index] ;
wxMacNotificationProcPtr handler = gMacNotificationEvents.proc[index] ;
gMacNotificationEvents.data[index] = NULL ;
gMacNotificationEvents.events[index] = NULL ;
gMacNotificationEvents.proc[index] = NULL ;
if ( handler )
handler( event , data ) ;
}
}
gInProcessing = false ;
}
void wxMacProcessNotifierAndPendingEvents()
{
wxMacProcessNotifierEvents() ;
wxTheApp->ProcessPendingEvents() ;
}

12
src/mac/classic/main.cpp Normal file
View File

@@ -0,0 +1,12 @@
/////////////////////////////////////////////////////////////////////////////
// Name: main.cpp
// Purpose: Entry point
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// We don't put main() in the library any more. GD.

395
src/mac/classic/mdi.cpp Normal file
View File

@@ -0,0 +1,395 @@
/////////////////////////////////////////////////////////////////////////////
// Name: mdi.cpp
// Purpose: MDI classes
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "mdi.h"
#endif
#include "wx/mdi.h"
#include "wx/menu.h"
#include "wx/settings.h"
#include "wx/log.h"
#include "wx/mac/private.h"
#include "wx/mac/uma.h"
extern wxWindowList wxModelessWindows;
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
EVT_SCROLL(wxMDIClientWindow::OnScroll)
END_EVENT_TABLE()
#endif
static const int IDM_WINDOWTILE = 4001;
static const int IDM_WINDOWTILEHOR = 4001;
static const int IDM_WINDOWCASCADE = 4002;
static const int IDM_WINDOWICONS = 4003;
static const int IDM_WINDOWNEXT = 4004;
static const int IDM_WINDOWTILEVERT = 4005;
static const int IDM_WINDOWPREV = 4006;
// This range gives a maximum of 500 MDI children. Should be enough :-)
static const int wxFIRST_MDI_CHILD = 4100;
static const int wxLAST_MDI_CHILD = 4600;
// Status border dimensions
static const int wxTHICK_LINE_BORDER = 3;
// Parent frame
wxMDIParentFrame::wxMDIParentFrame()
{
m_clientWindow = NULL;
m_currentChild = NULL;
m_windowMenu = (wxMenu*) NULL;
m_parentFrameActive = TRUE;
}
bool wxMDIParentFrame::Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
m_clientWindow = NULL;
m_currentChild = NULL;
// this style can be used to prevent a window from having the standard MDI
// "Window" menu
if ( style & wxFRAME_NO_WINDOW_MENU )
{
m_windowMenu = (wxMenu *)NULL;
style -= wxFRAME_NO_WINDOW_MENU ;
}
else // normal case: we have the window menu, so construct it
{
m_windowMenu = new wxMenu;
m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade"));
m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally"));
m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically"));
m_windowMenu->AppendSeparator();
m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons"));
m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next"));
}
wxFrame::Create( parent , id , title , pos , size , style , name ) ;
m_parentFrameActive = TRUE;
OnCreateClient();
return TRUE;
}
wxMDIParentFrame::~wxMDIParentFrame()
{
DestroyChildren();
// already delete by DestroyChildren()
#if wxUSE_TOOLBAR
m_frameToolBar = NULL;
#endif
#if wxUSE_STATUSBAR
m_frameStatusBar = NULL;
#endif
m_clientWindow = NULL ;
if (m_windowMenu)
{
delete m_windowMenu;
m_windowMenu = (wxMenu*) NULL;
}
if ( m_clientWindow )
{
delete m_clientWindow;
m_clientWindow = NULL ;
}
}
void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
{
wxFrame::SetMenuBar( menu_bar ) ;
}
void wxMDIParentFrame::MacActivate(long timestamp, bool activating)
{
wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
if(activating)
{
if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this)
{
wxLogDebug(wxT("child had been scheduled for deactivation, rehighlighting"));
UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
wxLogDebug(wxT("done highliting child"));
s_macDeactivateWindow = NULL;
}
else if(s_macDeactivateWindow == this)
{
wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this);
s_macDeactivateWindow = NULL;
}
else // window to deactivate is NULL or is not us or one of our kids
{
// activate kid instead
if(m_currentChild)
m_currentChild->MacActivate(timestamp,activating);
else
wxFrame::MacActivate(timestamp,activating);
}
}
else
{
// We were scheduled for deactivation, and now we do it.
if(s_macDeactivateWindow==this)
{
s_macDeactivateWindow = NULL;
if(m_currentChild)
m_currentChild->MacActivate(timestamp,activating);
wxFrame::MacActivate(timestamp,activating);
}
else // schedule ourselves for deactivation
{
if(s_macDeactivateWindow)
wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
wxLogDebug(wxT("Scheduling delayed MDI Parent deactivation"));
s_macDeactivateWindow = this;
}
}
}
void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
{
event.Skip();
}
// Returns the active MDI child window
wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
{
return m_currentChild ;
}
// Create the client window class (don't Create the window,
// just return a new class)
wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
{
m_clientWindow = new wxMDIClientWindow( this );
return m_clientWindow;
}
// Responds to colour changes, and passes event on to children.
void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
{
// TODO
// Propagate the event to the non-top-level children
wxFrame::OnSysColourChanged(event);
}
// MDI operations
void wxMDIParentFrame::Cascade()
{
// TODO
}
void wxMDIParentFrame::Tile()
{
// TODO
}
void wxMDIParentFrame::ArrangeIcons()
{
// TODO
}
void wxMDIParentFrame::ActivateNext()
{
// TODO
}
void wxMDIParentFrame::ActivatePrevious()
{
// TODO
}
// Child frame
wxMDIChildFrame::wxMDIChildFrame()
{
Init() ;
}
void wxMDIChildFrame::Init()
{
}
bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
SetName(name);
if ( id > -1 )
m_windowId = id;
else
m_windowId = (int)NewControlId();
if (parent) parent->AddChild(this);
MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
wxModelessWindows.Append(this);
return FALSE;
}
wxMDIChildFrame::~wxMDIChildFrame()
{
wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
wxASSERT(mdiparent);
if(mdiparent->m_currentChild == this)
mdiparent->m_currentChild = NULL;
DestroyChildren();
// already delete by DestroyChildren()
#if wxUSE_TOOLBAR
m_frameToolBar = NULL;
#endif
#if wxUSE_STATUSBAR
m_frameStatusBar = NULL;
#endif
}
void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
{
return wxFrame::SetMenuBar( menu_bar ) ;
}
void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
{
wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
wxASSERT(mdiparent);
if(activating)
{
if(s_macDeactivateWindow == m_parent)
{
wxLogDebug(wxT("parent had been scheduled for deactivation, rehighlighting"));
UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
wxLogDebug(wxT("done highliting parent"));
s_macDeactivateWindow = NULL;
}
else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow)
mdiparent->wxFrame::MacActivate(timestamp,activating);
if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this)
mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false);
mdiparent->m_currentChild = this;
if(s_macDeactivateWindow==this)
{
wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this);
s_macDeactivateWindow=NULL;
}
else
wxFrame::MacActivate(timestamp, activating);
}
else
{
// We were scheduled for deactivation, and now we do it.
if(s_macDeactivateWindow==this)
{
s_macDeactivateWindow = NULL;
wxFrame::MacActivate(timestamp,activating);
if(mdiparent->m_currentChild==this)
mdiparent->wxFrame::MacActivate(timestamp,activating);
}
else // schedule ourselves for deactivation
{
if(s_macDeactivateWindow)
wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
wxLogDebug(wxT("Scheduling delayed deactivation"));
s_macDeactivateWindow = this;
}
}
}
// MDI operations
void wxMDIChildFrame::Maximize()
{
wxFrame::Maximize() ;
}
void wxMDIChildFrame::Restore()
{
wxFrame::Restore() ;
}
void wxMDIChildFrame::Activate()
{
}
//-----------------------------------------------------------------------------
// wxMDIClientWindow
//-----------------------------------------------------------------------------
wxMDIClientWindow::wxMDIClientWindow()
{
}
wxMDIClientWindow::~wxMDIClientWindow()
{
DestroyChildren();
}
bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
{
m_windowId = (int)NewControlId();
if ( parent )
{
parent->AddChild(this);
}
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
wxModelessWindows.Append(this);
return TRUE;
}
// Get size *available for subwindows* i.e. excluding menu bar.
void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
{
wxDisplaySize( x , y ) ;
}
// Explicitly call default scroll behaviour
void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
{
}

881
src/mac/classic/menu.cpp Normal file
View File

@@ -0,0 +1,881 @@
/////////////////////////////////////////////////////////////////////////////
// Name: menu.cpp
// Purpose: wxMenu, wxMenuBar, wxMenuItem
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "menu.h"
#pragma implementation "menuitem.h"
#endif
// ============================================================================
// headers & declarations
// ============================================================================
// wxWindows headers
// -----------------
#include "wx/app.h"
#include "wx/menu.h"
#include "wx/menuitem.h"
#include "wx/window.h"
#include "wx/log.h"
#include "wx/utils.h"
#include "wx/frame.h"
#include "wx/mac/uma.h"
// other standard headers
// ----------------------
#include <string.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
#endif
// the (popup) menu title has this special id
static const int idMenuTitle = -2;
static MenuItemIndex firstUserHelpMenuItem = 0 ;
const short kwxMacMenuBarResource = 1 ;
const short kwxMacAppleMenuId = 1 ;
// ============================================================================
// implementation
// ============================================================================
static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) ;
static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win );
// Menus
// Construct a menu with optional title (then use append)
#ifdef __DARWIN__
short wxMenu::s_macNextMenuId = 3 ;
#else
short wxMenu::s_macNextMenuId = 2 ;
#endif
void wxMenu::Init()
{
m_doBreak = FALSE;
m_startRadioGroup = -1;
// create the menu
m_macMenuId = s_macNextMenuId++;
m_hMenu = UMANewMenu(m_macMenuId, m_title, wxFont::GetDefaultEncoding() );
if ( !m_hMenu )
{
wxLogLastError(wxT("UMANewMenu failed"));
}
// if we have a title, insert it in the beginning of the menu
if ( !!m_title )
{
Append(idMenuTitle, m_title) ;
AppendSeparator() ;
}
}
wxMenu::~wxMenu()
{
if (MAC_WXHMENU(m_hMenu))
::DisposeMenu(MAC_WXHMENU(m_hMenu));
}
void wxMenu::Break()
{
// not available on the mac platform
}
void wxMenu::Attach(wxMenuBarBase *menubar)
{
wxMenuBase::Attach(menubar);
EndRadioGroup();
}
// function appends a new item or submenu to the menu
// append a new item or submenu to the menu
bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
{
wxASSERT_MSG( pItem != NULL, wxT("can't append NULL item to the menu") );
if ( pItem->IsSeparator() )
{
if ( pos == (size_t)-1 )
MacAppendMenu(MAC_WXHMENU(m_hMenu), "\p-");
else
MacInsertMenuItem(MAC_WXHMENU(m_hMenu), "\p-" , pos);
}
else
{
wxMenu *pSubMenu = pItem->GetSubMenu() ;
if ( pSubMenu != NULL )
{
wxASSERT_MSG( pSubMenu->m_hMenu != NULL , wxT("invalid submenu added"));
pSubMenu->m_menuParent = this ;
if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar)
{
pSubMenu->MacBeforeDisplay( true ) ;
}
if ( pos == (size_t)-1 )
UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding() , pSubMenu->m_macMenuId);
else
UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding() , pos, pSubMenu->m_macMenuId);
pItem->UpdateItemBitmap() ;
pItem->UpdateItemStatus() ;
}
else
{
if ( pos == (size_t)-1 )
{
UMAAppendMenuItem(MAC_WXHMENU(m_hMenu), wxT("a") , wxFont::GetDefaultEncoding() );
pos = CountMenuItems(MAC_WXHMENU(m_hMenu)) ;
}
else
{
// MacOS counts menu items from 1 and inserts after, therefore having the
// same effect as wx 0 based and inserting before, we must correct pos
// after however for updates to be correct
UMAInsertMenuItem(MAC_WXHMENU(m_hMenu), wxT("a"), wxFont::GetDefaultEncoding(), pos);
pos += 1 ;
}
SetMenuItemCommandID( MAC_WXHMENU(m_hMenu) , pos , pItem->GetId() ) ;
pItem->UpdateItemText() ;
pItem->UpdateItemBitmap() ;
pItem->UpdateItemStatus() ;
if ( pItem->GetId() == idMenuTitle )
{
UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , pos , false ) ;
}
}
}
// if we're already attached to the menubar, we must update it
if ( IsAttached() )
{
m_menuBar->Refresh();
}
return TRUE ;
}
void wxMenu::EndRadioGroup()
{
// we're not inside a radio group any longer
m_startRadioGroup = -1;
}
wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
{
wxCHECK_MSG( item, NULL, _T("NULL item in wxMenu::DoAppend") );
bool check = FALSE;
if ( item->GetKind() == wxITEM_RADIO )
{
int count = GetMenuItemCount();
if ( m_startRadioGroup == -1 )
{
// start a new radio group
m_startRadioGroup = count;
// for now it has just one element
item->SetAsRadioGroupStart();
item->SetRadioGroupEnd(m_startRadioGroup);
// ensure that we have a checked item in the radio group
check = TRUE;
}
else // extend the current radio group
{
// we need to update its end item
item->SetRadioGroupStart(m_startRadioGroup);
wxMenuItemList::Node *node = GetMenuItems().Item(m_startRadioGroup);
if ( node )
{
node->GetData()->SetRadioGroupEnd(count);
}
else
{
wxFAIL_MSG( _T("where is the radio group start item?") );
}
}
}
else // not a radio item
{
EndRadioGroup();
}
if ( !wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item) )
{
return NULL;
}
if ( check )
{
// check the item initially
item->Check(TRUE);
}
return item;
}
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
{
if (wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos))
return item;
else
return NULL;
}
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
{
// we need to find the items position in the child list
size_t pos;
wxMenuItemList::Node *node = GetMenuItems().GetFirst();
for ( pos = 0; node; pos++ )
{
if ( node->GetData() == item )
break;
node = node->GetNext();
}
// DoRemove() (unlike Remove) can only be called for existing item!
wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") );
::DeleteMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1);
if ( IsAttached() )
{
// otherwise, the change won't be visible
m_menuBar->Refresh();
}
// and from internal data structures
return wxMenuBase::DoRemove(item);
}
void wxMenu::SetTitle(const wxString& label)
{
m_title = label ;
UMASetMenuTitle(MAC_WXHMENU(m_hMenu) , label , wxFont::GetDefaultEncoding() ) ;
}
bool wxMenu::ProcessCommand(wxCommandEvent & event)
{
bool processed = FALSE;
// Try the menu's event handler
if ( !processed && GetEventHandler())
{
processed = GetEventHandler()->ProcessEvent(event);
}
// Try the window the menu was popped up from (and up through the
// hierarchy)
wxWindow *win = GetInvokingWindow();
if ( !processed && win )
processed = win->GetEventHandler()->ProcessEvent(event);
return processed;
}
// ---------------------------------------------------------------------------
// other
// ---------------------------------------------------------------------------
wxWindow *wxMenu::GetWindow() const
{
if ( m_invokingWindow != NULL )
return m_invokingWindow;
else if ( m_menuBar != NULL)
return (wxWindow *) m_menuBar->GetFrame();
return NULL;
}
// helper functions returning the mac menu position for a certain item, note that this is
// mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0
int wxMenu::MacGetIndexFromId( int id )
{
size_t pos;
wxMenuItemList::Node *node = GetMenuItems().GetFirst();
for ( pos = 0; node; pos++ )
{
if ( node->GetData()->GetId() == id )
break;
node = node->GetNext();
}
if (!node)
return 0;
return pos + 1 ;
}
int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem )
{
size_t pos;
wxMenuItemList::Node *node = GetMenuItems().GetFirst();
for ( pos = 0; node; pos++ )
{
if ( node->GetData() == pItem )
break;
node = node->GetNext();
}
if (!node)
return 0;
return pos + 1 ;
}
void wxMenu::MacEnableMenu( bool bDoEnable )
{
UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , 0 , bDoEnable ) ;
::DrawMenuBar() ;
}
// MacOS needs to know about submenus somewhere within this menu
// before it can be displayed , also hide special menu items like preferences
// that are handled by the OS
void wxMenu::MacBeforeDisplay( bool isSubMenu )
{
wxMenuItem* previousItem = NULL ;
size_t pos ;
wxMenuItemList::Node *node;
wxMenuItem *item;
for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
item = (wxMenuItem *)node->GetData();
wxMenu* subMenu = item->GetSubMenu() ;
if (subMenu)
{
subMenu->MacBeforeDisplay( true ) ;
}
else
{
#if TARGET_CARBON
if ( UMAGetSystemVersion() >= 0x1000 )
{
if ( item->GetId() == wxApp::s_macPreferencesMenuItemId || item->GetId() == wxApp::s_macExitMenuItemId)
{
ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ) , pos + 1, kMenuItemAttrHidden, 0 );
if ( GetMenuItems().GetCount() == pos + 1 &&
previousItem != NULL &&
previousItem->IsSeparator() )
{
ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ) , pos , kMenuItemAttrHidden, 0 );
}
}
}
#endif
}
previousItem = item ;
}
if ( isSubMenu )
::InsertMenu(MAC_WXHMENU( GetHMenu()), -1);
}
// undo all changes from the MacBeforeDisplay call
void wxMenu::MacAfterDisplay( bool isSubMenu )
{
if ( isSubMenu )
::DeleteMenu(MacGetMenuId());
wxMenuItem* previousItem = NULL ;
int pos ;
wxMenuItemList::Node *node;
wxMenuItem *item;
for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
item = (wxMenuItem *)node->GetData();
wxMenu* subMenu = item->GetSubMenu() ;
if (subMenu)
{
subMenu->MacAfterDisplay( true ) ;
}
else
{
// no need to undo hidings
}
previousItem = item ;
}
}
// Menu Bar
/*
Mac Implementation note :
The Mac has only one global menubar, so we attempt to install the currently
active menubar from a frame, we currently don't take into account mdi-frames
which would ask for menu-merging
Secondly there is no mac api for changing a menubar that is not the current
menubar, so we have to wait for preparing the actual menubar until the
wxMenubar is to be used
We can in subsequent versions use MacInstallMenuBar to provide some sort of
auto-merge for MDI in case this will be necessary
*/
wxMenuBar* wxMenuBar::s_macInstalledMenuBar = NULL ;
wxMenuBar* wxMenuBar::s_macCommonMenuBar = NULL ;
void wxMenuBar::Init()
{
m_eventHandler = this;
m_menuBarFrame = NULL;
m_invokingWindow = (wxWindow*) NULL;
}
wxMenuBar::wxMenuBar()
{
Init();
}
wxMenuBar::wxMenuBar( long WXUNUSED(style) )
{
Init();
}
wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[])
{
Init();
m_titles.Alloc(count);
for ( int i = 0; i < count; i++ )
{
m_menus.Append(menus[i]);
m_titles.Add(titles[i]);
menus[i]->Attach(this);
}
}
wxMenuBar::~wxMenuBar()
{
if (s_macCommonMenuBar == this)
s_macCommonMenuBar = NULL;
if (s_macInstalledMenuBar == this)
{
::ClearMenuBar();
s_macInstalledMenuBar = NULL;
}
}
void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect))
{
wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
DrawMenuBar();
}
void wxMenuBar::MacInstallMenuBar()
{
if ( s_macInstalledMenuBar == this )
return ;
wxStAppResource resload ;
Handle menubar = ::GetNewMBar( kwxMacMenuBarResource ) ;
wxString message ;
wxCHECK_RET( menubar != NULL, wxT("can't read MBAR resource") );
::SetMenuBar( menubar ) ;
#if TARGET_API_MAC_CARBON
::DisposeMenuBar( menubar ) ;
#else
::DisposeHandle( menubar ) ;
#endif
#if TARGET_API_MAC_OS8
MenuHandle menu = ::GetMenuHandle( kwxMacAppleMenuId ) ;
if ( CountMenuItems( menu ) == 2 )
{
::AppendResMenu(menu, 'DRVR');
}
#endif
// clean-up the help menu before adding new items
MenuHandle mh = NULL ;
if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr )
{
for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i )
{
DeleteMenuItem( mh , i ) ;
}
}
else
{
mh = NULL ;
}
#if TARGET_CARBON
if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId)
{
wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ;
if ( item == NULL || !(item->IsEnabled()) )
DisableMenuCommand( NULL , kHICommandPreferences ) ;
else
EnableMenuCommand( NULL , kHICommandPreferences ) ;
}
#endif
for (size_t i = 0; i < m_menus.GetCount(); i++)
{
wxMenuItemList::Node *node;
wxMenuItem *item;
int pos ;
wxMenu* menu = m_menus[i] , *subMenu = NULL ;
if( m_titles[i] == wxT("?") || m_titles[i] == wxT("&?") || m_titles[i] == wxApp::s_macHelpMenuTitleName )
{
if ( mh == NULL )
{
continue ;
}
for (pos = 0 , node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
item = (wxMenuItem *)node->GetData();
subMenu = item->GetSubMenu() ;
if (subMenu)
{
// we don't support hierarchical menus in the help menu yet
}
else
{
if ( item->IsSeparator() )
{
if ( mh )
MacAppendMenu(mh, "\p-" );
}
else
{
wxAcceleratorEntry* entry = wxGetAccelFromString( item->GetText() ) ;
if ( item->GetId() == wxApp::s_macAboutMenuItemId )
{
UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , item->GetText() , wxFont::GetDefaultEncoding() );
UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true );
SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , item->GetId() ) ;
UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ;
}
else
{
if ( mh )
{
UMAAppendMenuItem(mh, item->GetText() , wxFont::GetDefaultEncoding(), entry);
SetMenuItemCommandID( mh , CountMenuItems(mh) , item->GetId() ) ;
}
}
delete entry ;
}
}
}
}
else
{
UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], m_font.GetEncoding() ) ;
m_menus[i]->MacBeforeDisplay(false) ;
::InsertMenu(MAC_WXHMENU(m_menus[i]->GetHMenu()), 0);
}
}
::DrawMenuBar() ;
s_macInstalledMenuBar = this;
}
void wxMenuBar::EnableTop(size_t pos, bool enable)
{
wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
m_menus[pos]->MacEnableMenu( enable ) ;
Refresh();
}
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
{
wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
m_titles[pos] = label;
if ( !IsAttached() )
{
return;
}
m_menus[pos]->SetTitle( label ) ;
if (wxMenuBar::s_macInstalledMenuBar == this) // are we currently installed ?
{
::SetMenuBar( GetMenuBar() ) ;
::InvalMenuBar() ;
}
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
{
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
wxT("invalid menu index in wxMenuBar::GetLabelTop") );
return m_titles[pos];
}
int wxMenuBar::FindMenu(const wxString& title)
{
wxString menuTitle = wxStripMenuCodes(title);
size_t count = GetMenuCount();
for ( size_t i = 0; i < count; i++ )
{
wxString title = wxStripMenuCodes(m_titles[i]);
if ( menuTitle == title )
return i;
}
return wxNOT_FOUND;
}
// ---------------------------------------------------------------------------
// wxMenuBar construction
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// wxMenuBar construction
// ---------------------------------------------------------------------------
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
{
wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);
if ( !menuOld )
return FALSE;
m_titles[pos] = title;
if ( IsAttached() )
{
if (s_macInstalledMenuBar == this)
{
menuOld->MacAfterDisplay( false ) ;
::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
{
menu->MacBeforeDisplay( false ) ;
UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , m_font.GetEncoding() ) ;
if ( pos == m_menus.GetCount() - 1)
{
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
}
else
{
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , m_menus[pos+1]->MacGetMenuId() ) ;
}
}
}
Refresh();
}
return menuOld;
}
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
{
if ( !wxMenuBarBase::Insert(pos, menu, title) )
return FALSE;
m_titles.Insert(title, pos);
UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , m_font.GetEncoding() ) ;
if ( IsAttached() && s_macInstalledMenuBar == this )
{
if (s_macInstalledMenuBar == this)
{
menu->MacBeforeDisplay( false ) ;
if ( pos == (size_t) -1 || pos + 1 == m_menus.GetCount() )
{
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
}
else
{
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , m_menus[pos+1]->MacGetMenuId() ) ;
}
}
Refresh();
}
return TRUE;
}
wxMenu *wxMenuBar::Remove(size_t pos)
{
wxMenu *menu = wxMenuBarBase::Remove(pos);
if ( !menu )
return NULL;
if ( IsAttached() )
{
if (s_macInstalledMenuBar == this)
{
::DeleteMenu( menu->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
}
Refresh();
}
m_titles.RemoveAt(pos);
return menu;
}
bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
{
WXHMENU submenu = menu ? menu->GetHMenu() : 0;
wxCHECK_MSG( submenu, FALSE, wxT("can't append invalid menu to menubar") );
if ( !wxMenuBarBase::Append(menu, title) )
return FALSE;
m_titles.Add(title);
UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , m_font.GetEncoding() ) ;
if ( IsAttached() )
{
if (s_macInstalledMenuBar == this)
{
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
}
Refresh();
}
// m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
// adding menu later on.
if (m_invokingWindow)
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
return TRUE;
}
static void wxMenubarUnsetInvokingWindow( wxMenu *menu )
{
menu->SetInvokingWindow( (wxWindow*) NULL );
wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() );
node = node->GetNext();
}
}
static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win );
node = node->GetNext();
}
}
void wxMenuBar::UnsetInvokingWindow()
{
m_invokingWindow = (wxWindow*) NULL;
wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
wxMenu *menu = node->GetData();
wxMenubarUnsetInvokingWindow( menu );
node = node->GetNext();
}
}
void wxMenuBar::SetInvokingWindow(wxFrame *frame)
{
m_invokingWindow = frame;
wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
wxMenu *menu = node->GetData();
wxMenubarSetInvokingWindow( menu, frame );
node = node->GetNext();
}
}
void wxMenuBar::Detach()
{
wxMenuBarBase::Detach() ;
}
void wxMenuBar::Attach(wxFrame *frame)
{
wxMenuBarBase::Attach( frame ) ;
}
// ---------------------------------------------------------------------------
// wxMenuBar searching for menu items
// ---------------------------------------------------------------------------
// Find the itemString in menuString, and return the item id or wxNOT_FOUND
int wxMenuBar::FindMenuItem(const wxString& menuString,
const wxString& itemString) const
{
wxString menuLabel = wxStripMenuCodes(menuString);
size_t count = GetMenuCount();
for ( size_t i = 0; i < count; i++ )
{
wxString title = wxStripMenuCodes(m_titles[i]);
if ( menuString == title )
return m_menus[i]->FindItem(itemString);
}
return wxNOT_FOUND;
}
wxMenuItem *wxMenuBar::FindItem(int id, wxMenu **itemMenu) const
{
if ( itemMenu )
*itemMenu = NULL;
wxMenuItem *item = NULL;
size_t count = GetMenuCount();
for ( size_t i = 0; !item && (i < count); i++ )
{
item = m_menus[i]->FindItem(id, itemMenu);
}
return item;
}

View File

@@ -0,0 +1,283 @@
///////////////////////////////////////////////////////////////////////////////
// Name: menuitem.cpp
// Purpose: wxMenuItem implementation
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// headers & declarations
// ============================================================================
#include "wx/app.h"
#include "wx/menu.h"
#include "wx/menuitem.h"
#include "wx/mac/uma.h"
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// dynamic classes implementation
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
#endif //USE_SHARED_LIBRARY
// ----------------------------------------------------------------------------
// wxMenuItem
// ----------------------------------------------------------------------------
//
// ctor & dtor
// -----------
wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
int id,
const wxString& text,
const wxString& strHelp,
wxItemKind kind,
wxMenu *pSubMenu)
: wxMenuItemBase(pParentMenu, id, text, strHelp, kind, pSubMenu)
{
// TO DISCUSS on dev : whether we can veto id 0
// wxASSERT_MSG( id != 0 || pSubMenu != NULL , wxT("A MenuItem ID of Zero does not work under Mac") ) ;
// In other languages there is no difference in naming the Exit/Quit menu item between MacOS and Windows guidelines
// therefore these item must not be translated
if ( wxStripMenuCodes(m_text).Upper() == wxT("EXIT") )
{
m_text =wxT("Quit\tCtrl+Q") ;
}
m_radioGroup.start = -1;
m_isRadioGroupStart = FALSE;
}
wxMenuItem::~wxMenuItem()
{
}
// change item state
// -----------------
void wxMenuItem::SetBitmap(const wxBitmap& bitmap)
{
m_bitmap = bitmap;
UpdateItemBitmap() ;
}
void wxMenuItem::UpdateItemBitmap()
{
if ( !m_parentMenu )
return ;
MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ;
MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ;
if( mhandle == NULL || index == 0)
return ;
if ( m_bitmap.Ok() )
{
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , m_bitmap , kControlContentCIconHandle ) ;
if ( info.contentType != kControlNoContent )
{
if ( info.contentType == kControlContentCIconHandle )
SetMenuItemIconHandle( mhandle , index ,
kMenuColorIconType , (Handle) info.u.cIconHandle ) ;
}
}
}
void wxMenuItem::UpdateItemStatus()
{
if ( !m_parentMenu )
return ;
#if TARGET_CARBON
if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macPreferencesMenuItemId)
{
if ( !IsEnabled() )
DisableMenuCommand( NULL , kHICommandPreferences ) ;
else
EnableMenuCommand( NULL , kHICommandPreferences ) ;
}
if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macExitMenuItemId)
{
if ( !IsEnabled() )
DisableMenuCommand( NULL , kHICommandQuit ) ;
else
EnableMenuCommand( NULL , kHICommandQuit ) ;
}
#endif
{
MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ;
MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ;
if( mhandle == NULL || index == 0)
return ;
UMAEnableMenuItem( mhandle , index , m_isEnabled ) ;
if ( IsCheckable() && IsChecked() )
::SetItemMark( mhandle , index , 0x12 ) ; // checkmark
else
::SetItemMark( mhandle , index , 0 ) ; // no mark
UMASetMenuItemText( mhandle , index , m_text , wxFont::GetDefaultEncoding() ) ;
wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ;
UMASetMenuItemShortcut( mhandle , index , entry ) ;
delete entry ;
}
}
void wxMenuItem::UpdateItemText()
{
if ( !m_parentMenu )
return ;
MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ;
MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ;
if( mhandle == NULL || index == 0)
return ;
UMASetMenuItemText( mhandle , index , m_text , wxFont::GetDefaultEncoding() ) ;
wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ;
UMASetMenuItemShortcut( mhandle , index , entry ) ;
delete entry ;
}
void wxMenuItem::Enable(bool bDoEnable)
{
if ( m_isEnabled != bDoEnable )
{
wxMenuItemBase::Enable( bDoEnable ) ;
UpdateItemStatus() ;
}
}
void wxMenuItem::UncheckRadio()
{
if ( m_isChecked )
{
wxMenuItemBase::Check( false ) ;
UpdateItemStatus() ;
}
}
void wxMenuItem::Check(bool bDoCheck)
{
wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
if ( m_isChecked != bDoCheck )
{
if ( GetKind() == wxITEM_RADIO )
{
if ( bDoCheck )
{
wxMenuItemBase::Check( bDoCheck ) ;
UpdateItemStatus() ;
// get the index of this item in the menu
const wxMenuItemList& items = m_parentMenu->GetMenuItems();
int pos = items.IndexOf(this);
wxCHECK_RET( pos != wxNOT_FOUND,
_T("menuitem not found in the menu items list?") );
// get the radio group range
int start,
end;
if ( m_isRadioGroupStart )
{
// we already have all information we need
start = pos;
end = m_radioGroup.end;
}
else // next radio group item
{
// get the radio group end from the start item
start = m_radioGroup.start;
end = items.Item(start)->GetData()->m_radioGroup.end;
}
// also uncheck all the other items in this radio group
wxMenuItemList::Node *node = items.Item(start);
for ( int n = start; n <= end && node; n++ )
{
if ( n != pos )
{
((wxMenuItem*)node->GetData())->UncheckRadio();
}
node = node->GetNext();
}
}
}
else
{
wxMenuItemBase::Check( bDoCheck ) ;
UpdateItemStatus() ;
}
}
}
void wxMenuItem::SetText(const wxString& text)
{
// don't do anything if label didn't change
if ( m_text == text )
return;
wxMenuItemBase::SetText(text);
UpdateItemText() ;
}
// radio group stuff
// -----------------
void wxMenuItem::SetAsRadioGroupStart()
{
m_isRadioGroupStart = TRUE;
}
void wxMenuItem::SetRadioGroupStart(int start)
{
wxASSERT_MSG( !m_isRadioGroupStart,
_T("should only be called for the next radio items") );
m_radioGroup.start = start;
}
void wxMenuItem::SetRadioGroupEnd(int end)
{
wxASSERT_MSG( m_isRadioGroupStart,
_T("should only be called for the first radio item") );
m_radioGroup.end = end;
}
// ----------------------------------------------------------------------------
// wxMenuItemBase
// ----------------------------------------------------------------------------
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{
return wxStripMenuCodes(text);
}
wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
int id,
const wxString& name,
const wxString& help,
wxItemKind kind,
wxMenu *subMenu)
{
return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}

View File

@@ -0,0 +1,219 @@
/////////////////////////////////////////////////////////////////////////////
// Name: metafile.cpp
// Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "metafile.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/setup.h"
#endif
#if wxUSE_METAFILE
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/app.h"
#endif
#include "wx/metafile.h"
#include "wx/clipbrd.h"
#include "wx/mac/private.h"
#include <stdio.h>
#include <string.h>
extern bool wxClipboardIsOpen;
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
#endif
/*
* Metafiles
* Currently, the only purpose for making a metafile is to put
* it on the clipboard.
*/
wxMetafileRefData::wxMetafileRefData(void)
{
m_metafile = 0;
}
wxMetafileRefData::~wxMetafileRefData(void)
{
if (m_metafile)
{
KillPicture( (PicHandle) m_metafile ) ;
m_metafile = 0;
}
}
wxMetaFile::wxMetaFile(const wxString& file)
{
m_refData = new wxMetafileRefData;
M_METAFILEDATA->m_metafile = 0;
wxASSERT_MSG( file.IsEmpty() , wxT("no file based metafile support yet") ) ;
/*
if (!file.IsNull() && (file.Cmp("") == 0))
M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
*/
}
wxMetaFile::~wxMetaFile()
{
}
bool wxMetaFile::SetClipboard(int width, int height)
{
#if wxUSE_DRAG_AND_DROP
//TODO finishi this port , we need the data obj first
if (!m_refData)
return FALSE;
bool alreadyOpen=wxTheClipboard->IsOpened() ;
if (!alreadyOpen)
{
wxTheClipboard->Open();
wxTheClipboard->Clear();
}
wxDataObject *data =
new wxMetafileDataObject( *this) ;
bool success = wxTheClipboard->SetData(data);
if (!alreadyOpen)
wxTheClipboard->Close();
return (bool) success;
#endif
return TRUE ;
}
void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
{
if (!m_refData)
m_refData = new wxMetafileRefData;
if ( M_METAFILEDATA->m_metafile )
KillPicture( (PicHandle) M_METAFILEDATA->m_metafile ) ;
M_METAFILEDATA->m_metafile = mf;
}
bool wxMetaFile::Play(wxDC *dc)
{
if (!m_refData)
return FALSE;
if (!dc->Ok() )
return FALSE;
{
wxMacPortSetter helper( dc ) ;
PicHandle pict = (PicHandle) GetHMETAFILE() ;
DrawPicture( pict , &(**pict).picFrame ) ;
}
return TRUE;
}
wxSize wxMetaFile::GetSize() const
{
wxSize size = wxDefaultSize ;
if ( Ok() )
{
PicHandle pict = (PicHandle) GetHMETAFILE() ;
Rect &r = (**pict).picFrame ;
size.x = r.right - r.left ;
size.y = r.bottom - r.top ;
}
return size;
}
/*
* Metafile device context
*
*/
// New constructor that takes origin and extent. If you use this, don't
// give origin/extent arguments to wxMakeMetaFilePlaceable.
wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
int width , int height ,
const wxString& WXUNUSED(description) )
{
wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
wxASSERT_MSG( filename.IsEmpty() , _T("no file based metafile support yet")) ;
m_metaFile = new wxMetaFile(filename) ;
Rect r={0,0,height,width} ;
RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
::GetPort( (GrafPtr*) &m_macPort ) ;
m_ok = TRUE ;
SetMapMode(wxMM_TEXT);
}
wxMetaFileDC::~wxMetaFileDC()
{
}
void wxMetaFileDC::DoGetSize(int *width, int *height) const
{
wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
wxSize sz = m_metaFile->GetSize() ;
if (width) (*width) = sz.x;
if (height) (*height) = sz.y;
}
wxMetaFile *wxMetaFileDC::Close()
{
ClosePicture() ;
return m_metaFile;
}
#if wxUSE_DATAOBJ
size_t wxMetafileDataObject::GetDataSize() const
{
return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
}
bool wxMetafileDataObject::GetDataHere(void *buf) const
{
memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
return true ;
}
bool wxMetafileDataObject::SetData(size_t len, const void *buf)
{
Handle handle = NewHandle( len ) ;
SetHandleSize( handle , len ) ;
memcpy( *handle , buf , len ) ;
m_metafile.SetHMETAFILE( handle ) ;
return true ;
}
#endif
#endif

View File

@@ -0,0 +1,228 @@
/////////////////////////////////////////////////////////////////////////////
// Name: mac/mimetype.cpp
// Purpose: classes and functions to manage MIME types
// Author: Vadim Zeitlin
// Modified by:
// Created: 23.09.98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence (part of wxExtra library)
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "mimetype.h"
#endif
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#endif
#ifndef WX_PRECOMP
#include "wx/string.h"
#if wxUSE_GUI
#include "wx/icon.h"
#endif
#endif //WX_PRECOMP
#include "wx/log.h"
#include "wx/file.h"
#include "wx/intl.h"
#include "wx/dynarray.h"
#include "wx/confbase.h"
#include "wx/mac/mimetype.h"
// other standard headers
#include <ctype.h>
// in case we're compiling in non-GUI mode
class WXDLLEXPORT wxIcon;
bool wxFileTypeImpl::SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt)
{
return FALSE;
}
bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon, int index)
{
return FALSE;
}
bool wxFileTypeImpl::GetCommand(wxString *command, const char *verb) const
{
return FALSE;
}
// @@ this function is half implemented
bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions)
{
return FALSE;
}
bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const
{
if ( m_strFileType.Length() > 0 )
{
*mimeType = m_strFileType ;
return TRUE ;
}
else
return FALSE;
}
bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const
{
wxString s;
if (GetMimeType(&s))
{
mimeTypes.Clear();
mimeTypes.Add(s);
return TRUE;
}
else
return FALSE;
}
bool wxFileTypeImpl::GetIcon(wxIconLocation *WXUNUSED(icon)) const
{
// no such file type or no value or incorrect icon entry
return FALSE;
}
bool wxFileTypeImpl::GetDescription(wxString *desc) const
{
return FALSE;
}
size_t
wxFileTypeImpl::GetAllCommands(wxArrayString * verbs, wxArrayString * commands,
const wxFileType::MessageParameters& params) const
{
wxFAIL_MSG( _T("wxFileTypeImpl::GetAllCommands() not yet implemented") );
return 0;
}
void
wxMimeTypesManagerImpl::Initialize(int mailcapStyles, const wxString& extraDir)
{
wxFAIL_MSG( _T("wxMimeTypesManagerImpl::Initialize() not yet implemented") );
}
void
wxMimeTypesManagerImpl::ClearData()
{
wxFAIL_MSG( _T("wxMimeTypesManagerImpl::ClearData() not yet implemented") );
}
// extension -> file type
wxFileType *
wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e)
{
wxString ext = e ;
ext = ext.Lower() ;
if ( ext == wxT("txt") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("text/text"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("htm") || ext == wxT("html") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("text/html"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("gif") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("image/gif"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("png" ))
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("image/png"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("jpg" )|| ext == wxT("jpeg") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("image/jpeg"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("bmp") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("image/bmp"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("tif") || ext == wxT("tiff") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("image/tiff"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("xpm") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("image/xpm"));
fileType->m_impl->SetExt(ext);
return fileType;
}
else if ( ext == wxT("xbm") )
{
wxFileType *fileType = new wxFileType;
fileType->m_impl->SetFileType(wxT("image/xbm"));
fileType->m_impl->SetExt(ext);
return fileType;
}
// unknown extension
return NULL;
}
// MIME type -> extension -> file type
wxFileType *
wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
{
return NULL;
}
size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes)
{
// VZ: don't know anything about this for Mac
wxFAIL_MSG( _T("wxMimeTypesManagerImpl::EnumAllFileTypes() not yet implemented") );
return 0;
}
wxFileType *
wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
{
wxFAIL_MSG( _T("wxMimeTypesManagerImpl::Associate() not yet implemented") );
return NULL;
}
bool
wxMimeTypesManagerImpl::Unassociate(wxFileType *ft)
{
return FALSE;
}

View File

@@ -0,0 +1,22 @@
/////////////////////////////////////////////////////////////////////////////
// Name: minifram.cpp
// Purpose: wxMiniFrame. Optional; identical to wxFrame if not supported.
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "minifram.h"
#endif
#include "wx/minifram.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame, wxFrame)
#endif

262
src/mac/classic/msgdlg.cpp Normal file
View File

@@ -0,0 +1,262 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msgdlg.cpp
// Purpose: wxMessageDialog
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "msgdlg.h"
#endif
#include "wx/app.h"
#include "wx/msgdlg.h"
#include "wx/intl.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
#endif
wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
long style, const wxPoint& pos)
{
m_caption = caption;
m_message = message;
m_dialogStyle = style;
m_parent = parent;
}
int wxMessageDialog::ShowModal()
{
int resultbutton = wxID_CANCEL ;
short result ;
wxASSERT_MSG( ( m_dialogStyle & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
AlertType alertType = kAlertPlainAlert ;
if (m_dialogStyle & wxICON_EXCLAMATION)
alertType = kAlertNoteAlert ;
else if (m_dialogStyle & wxICON_HAND)
alertType = kAlertStopAlert ;
else if (m_dialogStyle & wxICON_INFORMATION)
alertType = kAlertNoteAlert ;
else if (m_dialogStyle & wxICON_QUESTION)
alertType = kAlertCautionAlert ;
#if TARGET_CARBON
if ( UMAGetSystemVersion() >= 0x1000 )
{
AlertStdCFStringAlertParamRec param ;
wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;
wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
param.movable = true;
param.flags = 0 ;
bool skipDialog = false ;
if (m_dialogStyle & wxYES_NO)
{
if (m_dialogStyle & wxCANCEL)
{
param.defaultText = cfYesString ;
param.cancelText = (CFStringRef) kAlertDefaultCancelText;
param.otherText = cfNoString ;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = kAlertStdAlertCancelButton;
}
else
{
param.defaultText = cfYesString ;
param.cancelText = NULL;
param.otherText = cfNoString ;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = 0;
}
}
// the msw implementation even shows an ok button if it is not specified, we'll do the same
else
{
if (m_dialogStyle & wxCANCEL)
{
// thats a cancel missing
param.defaultText = (CFStringRef) kAlertDefaultOKText ;
param.cancelText = (CFStringRef) kAlertDefaultCancelText ;
param.otherText = NULL;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = 0;
}
else
{
param.defaultText = (CFStringRef) kAlertDefaultOKText ;
param.cancelText = NULL;
param.otherText = NULL;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = 0;
}
}
/*
else
{
skipDialog = true ;
}
*/
param.position = kWindowDefaultPosition;
if ( !skipDialog )
{
DialogRef alertRef ;
CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
RunStandardAlert( alertRef , NULL , &result ) ;
}
if ( skipDialog )
return wxID_CANCEL ;
}
else
#endif
{
AlertStdAlertParamRec param;
Str255 yesPString ;
Str255 noPString ;
Str255 pascalTitle ;
Str255 pascalText ;
wxMacStringToPascal( m_caption , pascalTitle ) ;
wxMacStringToPascal( _("Yes") , yesPString ) ;
wxMacStringToPascal( _("No") , noPString ) ;
wxMacStringToPascal( m_message , pascalText ) ;
param.movable = true;
param.filterProc = NULL ;
if (m_dialogStyle & wxYES_NO)
{
if (m_dialogStyle & wxCANCEL)
{
param.defaultText = yesPString ;
param.cancelText = (StringPtr) kAlertDefaultCancelText;
param.otherText = noPString ;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = kAlertStdAlertCancelButton;
}
else
{
param.defaultText = yesPString ;
param.cancelText = NULL;
param.otherText = noPString ;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = 0;
}
}
else if (m_dialogStyle & wxOK)
{
if (m_dialogStyle & wxCANCEL)
{
param.defaultText = (StringPtr) kAlertDefaultOKText ;
param.cancelText = (StringPtr) kAlertDefaultCancelText ;
param.otherText = NULL;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = 0;
}
else
{
param.defaultText = (StringPtr) kAlertDefaultOKText ;
param.cancelText = NULL;
param.otherText = NULL;
param.helpButton = false ;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = 0;
}
}
else
{
return resultbutton ;
}
param.position = 0;
StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
}
if (m_dialogStyle & wxOK)
{
if (m_dialogStyle & wxCANCEL)
{
//TODO add Cancelbutton
switch( result )
{
case 1 :
resultbutton = wxID_OK ;
break ;
case 2 :
break ;
case 3 :
break ;
}
}
else
{
switch( result )
{
case 1 :
resultbutton = wxID_OK ;
break ;
case 2 :
break ;
case 3 :
break ;
}
}
}
else if (m_dialogStyle & wxYES_NO)
{
if (m_dialogStyle & wxCANCEL)
{
switch( result )
{
case 1 :
resultbutton = wxID_YES ;
break ;
case 2 :
resultbutton = wxID_CANCEL ;
break ;
case 3 :
resultbutton = wxID_NO ;
break ;
}
}
else
{
switch( result )
{
case 1 :
resultbutton = wxID_YES ;
break ;
case 2 :
break ;
case 3 :
resultbutton = wxID_NO ;
break ;
}
}
}
return resultbutton ;
}

View File

@@ -0,0 +1,729 @@
///////////////////////////////////////////////////////////////////////////////
// Name: notebook.cpp
// Purpose: implementation of wxNotebook
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "notebook.h"
#endif
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/app.h"
#include "wx/string.h"
#include "wx/log.h"
#include "wx/imaglist.h"
#include "wx/image.h"
#include "wx/notebook.h"
#include "wx/mac/uma.h"
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// check that the page index is valid
#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
BEGIN_EVENT_TABLE(wxNotebook, wxControl)
EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
EVT_MOUSE_EVENTS(wxNotebook::OnMouse)
EVT_SIZE(wxNotebook::OnSize)
EVT_SET_FOCUS(wxNotebook::OnSetFocus)
EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
// ============================================================================
// implementation
// ============================================================================
// The Appearance Manager docs show using tab controls in either edge to edge
// mode, or inset. I think edge to edge conforms better to the other ports,
// and inset mode is better accomplished with space around the wxNotebook rather
// than within it. --Robin
// CS : had to switch off tight spacing due to 10.3 problems
#define wxMAC_EDGE_TO_EDGE 0
static inline int wxMacTabMargin(long nbStyle, long side)
{
static int tabMargin = -1;
static int otherMargin = -1;
if ( tabMargin == -1)
{
if ( UMAHasAquaLayout() )
{
tabMargin = 26; // From Appearance Manager docs for small tab control dimensions
#if wxMAC_EDGE_TO_EDGE
otherMargin = 0;
#else
// otherMargin = 20;
// JACS - this seems fine on 10.3; 20 is way too much
otherMargin = 8;
#endif
}
else
{
tabMargin = 30;
#if wxMAC_EDGE_TO_EDGE
otherMargin = 0;
#else
otherMargin = 16;
#endif
}
}
// If the style matches the side asked for then return the tab margin,
// but we have to special case wxNB_TOP since it is zero...
if ( side == wxNB_TOP)
{
if ( nbStyle != 0 && nbStyle & (wxNB_LEFT|wxNB_RIGHT|wxNB_BOTTOM))
{
return otherMargin;
}
else
{
return tabMargin;
}
}
else if ( nbStyle & side)
return tabMargin;
else
return otherMargin;
}
static inline int wxMacTabLeftMargin(long style)
{
return wxMacTabMargin(style, wxNB_LEFT);
}
static inline int wxMacTabTopMargin(long style)
{
return wxMacTabMargin(style, wxNB_TOP);
}
static inline int wxMacTabRightMargin(long style)
{
return wxMacTabMargin(style, wxNB_RIGHT);
}
static inline int wxMacTabBottomMargin(long style)
{
return wxMacTabMargin(style, wxNB_BOTTOM);
}
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
// common part of all ctors
void wxNotebook::Init()
{
if ( UMAHasAquaLayout() )
{
// Should these depend on wxMAC_EDGE_TO_EDGE too?
m_macHorizontalBorder = 7;
m_macVerticalBorder = 8;
}
m_nSelection = -1;
}
// default for dynamic class
wxNotebook::wxNotebook()
{
Init();
}
// the same arguments as for wxControl
wxNotebook::wxNotebook(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
Init();
Create(parent, id, pos, size, style, name);
}
// Create() function
bool wxNotebook::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
if ( !wxNotebookBase::Create(parent, id, pos, size, style, name) )
return false;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
int tabstyle = kControlTabSmallNorthProc ;
if ( HasFlag(wxNB_LEFT) )
tabstyle = kControlTabSmallWestProc ;
else if ( HasFlag( wxNB_RIGHT ) )
tabstyle = kControlTabSmallEastProc ;
else if ( HasFlag( wxNB_BOTTOM ) )
tabstyle = kControlTabSmallSouthProc ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
tabstyle , (long) this ) ;
MacPostControlCreate() ;
return TRUE ;
}
// dtor
wxNotebook::~wxNotebook()
{
}
// ----------------------------------------------------------------------------
// wxNotebook accessors
// ----------------------------------------------------------------------------
void wxNotebook::SetPadding(const wxSize& padding)
{
// unsupported by OS
}
void wxNotebook::SetTabSize(const wxSize& sz)
{
// unsupported by OS
}
void wxNotebook::SetPageSize(const wxSize& size)
{
SetSize( CalcSizeFromPage( size ) );
}
wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
{
wxSize sizeTotal = sizePage;
sizeTotal.x += 2 * m_macHorizontalBorder + wxMacTabLeftMargin(GetWindowStyle()) +
wxMacTabRightMargin(GetWindowStyle()) ;
sizeTotal.y += 2 * m_macVerticalBorder + wxMacTabTopMargin(GetWindowStyle()) +
wxMacTabBottomMargin(GetWindowStyle()) ;
return sizeTotal;
}
wxSize wxNotebook::DoGetBestSize() const
{
// calculate the max page size
wxSize size(0, 0);
size_t count = GetPageCount();
if ( count )
{
for ( size_t n = 0; n < count; n++ )
{
wxSize sizePage = m_pages[n]->GetSize();
if ( size.x < sizePage.x )
size.x = sizePage.x;
if ( size.y < sizePage.y )
size.y = sizePage.y;
}
}
else // no pages
{
// use some arbitrary default size
size.x =
size.y = 100;
}
return CalcSizeFromPage(size);
}
int wxNotebook::SetSelection(size_t nPage)
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
if ( int(nPage) != m_nSelection )
{
wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
event.SetSelection(nPage);
event.SetOldSelection(m_nSelection);
event.SetEventObject(this);
if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
{
// program allows the page change
event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
(void)GetEventHandler()->ProcessEvent(event);
ChangePage(m_nSelection, nPage);
}
}
return m_nSelection;
}
bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
{
wxASSERT( IS_VALID_PAGE(nPage) );
wxNotebookPage *page = m_pages[nPage];
page->SetLabel(strText);
MacSetupTabs();
return true;
}
wxString wxNotebook::GetPageText(size_t nPage) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
wxNotebookPage *page = m_pages[nPage];
return page->GetLabel();
}
int wxNotebook::GetPageImage(size_t nPage) const
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
return m_images[nPage];
}
bool wxNotebook::SetPageImage(size_t nPage, int nImage)
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") );
wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), FALSE,
_T("invalid image index in SetPageImage()") );
if ( nImage != m_images[nPage] )
{
// if the item didn't have an icon before or, on the contrary, did have
// it but has lost it now, its size will change - but if the icon just
// changes, it won't
m_images[nPage] = nImage;
MacSetupTabs() ;
}
return TRUE;
}
// ----------------------------------------------------------------------------
// wxNotebook operations
// ----------------------------------------------------------------------------
// remove one page from the notebook, without deleting the window
wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage)
{
wxCHECK( IS_VALID_PAGE(nPage), NULL );
wxNotebookPage* page = m_pages[nPage] ;
m_pages.RemoveAt(nPage);
MacSetupTabs();
if(m_nSelection >= (int)GetPageCount()) {
m_nSelection = GetPageCount() - 1;
}
if(m_nSelection >= 0) {
m_pages[m_nSelection]->Show(true);
}
return page;
}
// remove all pages
bool wxNotebook::DeleteAllPages()
{
WX_CLEAR_ARRAY(m_pages) ;
MacSetupTabs();
m_nSelection = -1 ;
return TRUE;
}
// same as AddPage() but does it at given position
bool wxNotebook::InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect,
int imageId)
{
if ( !wxNotebookBase::InsertPage(nPage, pPage, strText, bSelect, imageId) )
return false;
wxASSERT_MSG( pPage->GetParent() == this,
_T("notebook pages must have notebook as parent") );
// don't show pages by default (we'll need to adjust their size first)
pPage->Show( false ) ;
pPage->SetLabel(strText);
m_images.Insert(imageId, nPage);
MacSetupTabs();
wxRect rect = GetPageRect() ;
pPage->SetSize(rect);
if ( pPage->GetAutoLayout() ) {
pPage->Layout();
}
// now deal with the selection
// ---------------------------
// if the inserted page is before the selected one, we must update the
// index of the selected page
if ( int(nPage) <= m_nSelection )
{
m_nSelection++;
// while this still is the same page showing, we need to update the tabs
SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ;
}
// some page should be selected: either this one or the first one if there
// is still no selection
int selNew = -1;
if ( bSelect )
selNew = nPage;
else if ( m_nSelection == -1 )
selNew = 0;
if ( selNew != -1 )
SetSelection(selNew);
return true;
}
/* Added by Mark Newsam
* When a page is added or deleted to the notebook this function updates
* information held in the m_macControl so that it matches the order
* the user would expect.
*/
void wxNotebook::MacSetupTabs()
{
SetControl32BitMaximum( (ControlHandle) m_macControl , GetPageCount() ) ;
wxNotebookPage *page;
ControlTabInfoRec info;
const size_t countPages = GetPageCount();
for(size_t ii = 0; ii < countPages; ii++)
{
page = m_pages[ii];
info.version = 0;
info.iconSuiteID = 0;
wxMacStringToPascal( page->GetLabel() , info.name ) ;
SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabInfoTag,
sizeof( ControlTabInfoRec) , (char*) &info ) ;
SetTabEnabled( (ControlHandle) m_macControl , ii+1 , true ) ;
#if TARGET_CARBON
if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 )
{
// tab controls only support very specific types of images, therefore we are doing an odyssee
// accross the icon worlds (even Apple DTS did not find a shorter path)
// in order not to pollute the icon registry we put every icon into (OSType) 1 and immediately
// afterwards Unregister it (IconRef is ref counted, so it will stay on the tab even if we
// unregister it) in case this will ever lead to having the same icon everywhere add some kind
// of static counter
const wxBitmap* bmap = GetImageList()->GetBitmap( GetPageImage(ii ) ) ;
if ( bmap )
{
wxBitmap scaledBitmap ;
if ( bmap->GetWidth() != 16 || bmap->GetHeight() != 16 )
{
scaledBitmap = wxBitmap( bmap->ConvertToImage().Scale(16,16) ) ;
bmap = &scaledBitmap ;
}
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , *bmap , kControlContentPictHandle) ;
IconFamilyHandle iconFamily = (IconFamilyHandle) NewHandle(0) ;
OSErr err = SetIconFamilyData( iconFamily, 'PICT' , (Handle) info.u.picture ) ;
wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
IconRef iconRef ;
err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) 1, iconFamily, &iconRef ) ;
wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
info.contentType = kControlContentIconRef ;
info.u.iconRef = iconRef ;
SetControlData( (ControlHandle) m_macControl, ii+1,kControlTabImageContentTag,
sizeof( info ), (Ptr)&info );
wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ;
if ( UMAGetSystemVersion() < 0x1030 )
{
UnregisterIconRef( 'WXNG' , (OSType) 1 ) ;
}
ReleaseIconRef( iconRef ) ;
DisposeHandle( (Handle) iconFamily ) ;
}
}
#endif
}
Rect bounds;
GetControlBounds((ControlHandle)m_macControl, &bounds);
InvalWindowRect((WindowRef)MacGetRootWindow(), &bounds);
}
wxRect wxNotebook::GetPageRect() const
{
// fit the notebook page to the tab control's display area
int w, h;
GetSize(&w, &h);
return wxRect(
wxMacTabLeftMargin(GetWindowStyle()) + m_macHorizontalBorder,
wxMacTabTopMargin(GetWindowStyle()) + m_macVerticalBorder,
w - wxMacTabLeftMargin(GetWindowStyle()) - wxMacTabRightMargin(GetWindowStyle()) - 2*m_macHorizontalBorder,
h - wxMacTabTopMargin(GetWindowStyle()) - wxMacTabBottomMargin(GetWindowStyle()) - 2*m_macVerticalBorder);
}
// ----------------------------------------------------------------------------
// wxNotebook callbacks
// ----------------------------------------------------------------------------
// @@@ OnSize() is used for setting the font when it's called for the first
// time because doing it in ::Create() doesn't work (for unknown reasons)
void wxNotebook::OnSize(wxSizeEvent& event)
{
unsigned int nCount = m_pages.Count();
wxRect rect = GetPageRect() ;
for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
wxNotebookPage *pPage = m_pages[nPage];
pPage->SetSize(rect);
if ( pPage->GetAutoLayout() ) {
pPage->Layout();
}
}
// Processing continues to next OnSize
event.Skip();
}
void wxNotebook::OnSelChange(wxNotebookEvent& event)
{
// is it our tab control?
if ( event.GetEventObject() == this )
ChangePage(event.GetOldSelection(), event.GetSelection());
// we want to give others a chance to process this message as well
event.Skip();
}
void wxNotebook::OnSetFocus(wxFocusEvent& event)
{
// set focus to the currently selected page if any
if ( m_nSelection != -1 )
m_pages[m_nSelection]->SetFocus();
event.Skip();
}
void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
{
if ( event.IsWindowChange() ) {
// change pages
AdvanceSelection(event.GetDirection());
}
else {
// we get this event in 2 cases
//
// a) one of our pages might have generated it because the user TABbed
// out from it in which case we should propagate the event upwards and
// our parent will take care of setting the focus to prev/next sibling
//
// or
//
// b) the parent panel wants to give the focus to us so that we
// forward it to our selected page. We can't deal with this in
// OnSetFocus() because we don't know which direction the focus came
// from in this case and so can't choose between setting the focus to
// first or last panel child
wxWindow *parent = GetParent();
// the cast is here to fic a GCC ICE
if ( ((wxWindow*)event.GetEventObject()) == parent )
{
// no, it doesn't come from child, case (b): forward to a page
if ( m_nSelection != -1 )
{
// so that the page knows that the event comes from it's parent
// and is being propagated downwards
event.SetEventObject(this);
wxWindow *page = m_pages[m_nSelection];
if ( !page->GetEventHandler()->ProcessEvent(event) )
{
page->SetFocus();
}
//else: page manages focus inside it itself
}
else
{
// we have no pages - still have to give focus to _something_
SetFocus();
}
}
else
{
// it comes from our child, case (a), pass to the parent
if ( parent ) {
event.SetCurrentFocus(this);
parent->GetEventHandler()->ProcessEvent(event);
}
}
}
}
// ----------------------------------------------------------------------------
// wxNotebook base class virtuals
// ----------------------------------------------------------------------------
#if wxUSE_CONSTRAINTS
// override these 2 functions to do nothing: everything is done in OnSize
void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
{
// don't set the sizes of the pages - their correct size is not yet known
wxControl::SetConstraintSizes(FALSE);
}
bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
{
return TRUE;
}
#endif // wxUSE_CONSTRAINTS
void wxNotebook::Command(wxCommandEvent& event)
{
wxFAIL_MSG(wxT("wxNotebook::Command not implemented"));
}
// ----------------------------------------------------------------------------
// wxNotebook helper functions
// ----------------------------------------------------------------------------
// hide the currently active panel and show the new one
void wxNotebook::ChangePage(int nOldSel, int nSel)
{
if ( nOldSel != -1 )
{
m_pages[nOldSel]->Show(FALSE);
}
if ( nSel != -1 )
{
wxNotebookPage *pPage = m_pages[nSel];
pPage->Show(TRUE);
pPage->SetFocus();
}
m_nSelection = nSel;
SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ;
}
void wxNotebook::OnMouse( wxMouseEvent &event )
{
if ( (ControlHandle) m_macControl == NULL )
{
event.Skip() ;
return ;
}
if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
{
int x = event.m_x ;
int y = event.m_y ;
MacClientToRootWindow( &x , &y ) ;
ControlHandle control ;
Point localwhere ;
SInt16 controlpart ;
localwhere.h = x ;
localwhere.v = y ;
short modifiers = 0;
if ( !event.m_leftDown && !event.m_rightDown )
modifiers |= btnState ;
if ( event.m_shiftDown )
modifiers |= shiftKey ;
if ( event.m_controlDown )
modifiers |= controlKey ;
if ( event.m_altDown )
modifiers |= optionKey ;
if ( event.m_metaDown )
modifiers |= cmdKey ;
control = (ControlHandle) m_macControl ;
if ( control && ::IsControlActive( control ) )
{
{
wxNotebookEvent changing(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId,
::GetControl32BitValue(control) - 1, m_nSelection);
changing.SetEventObject(this);
GetEventHandler()->ProcessEvent(changing);
if(changing.IsAllowed())
{
controlpart = ::HandleControlClick(control, localwhere, modifiers,
(ControlActionUPP) -1);
wxTheApp->s_lastMouseDown = 0 ;
wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId,
::GetControl32BitValue(control) - 1, m_nSelection);
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
}
}
}
}
void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
{
#if 0
wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControl32BitValue((ControlHandle)m_macControl) - 1, m_nSelection);
event.SetEventObject(this);
ProcessEvent(event);
#endif
}

118
src/mac/classic/palette.cpp Normal file
View File

@@ -0,0 +1,118 @@
/////////////////////////////////////////////////////////////////////////////
// Name: palette.cpp
// Purpose: wxPalette
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "palette.h"
#endif
#include "wx/defs.h"
#if wxUSE_PALETTE
#include "wx/palette.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject)
#endif
/*
* Palette
*
*/
wxPaletteRefData::wxPaletteRefData()
{
m_palette = NULL ;
m_count = 0 ;
}
wxPaletteRefData::~wxPaletteRefData()
{
if (m_palette != NULL) {
delete[] m_palette ;
m_palette = NULL;
}
}
wxPalette::wxPalette()
{
}
wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
{
Create(n, red, green, blue);
}
wxPalette::~wxPalette()
{
}
bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
{
UnRef();
m_refData = new wxPaletteRefData;
M_PALETTEDATA->m_count = n ;
M_PALETTEDATA->m_palette = new wxColour[n] ;
for ( int i = 0 ; i < n ; ++i)
{
M_PALETTEDATA->m_palette[i].Set( red[i] , green[i] , blue[i] ) ;
}
return FALSE;
}
int wxPalette::GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const
{
if ( !m_refData )
return -1;
long bestdiff = 3 * 256 ;
long bestpos = 0 ;
long currentdiff ;
for ( int i = 0 ; i < M_PALETTEDATA->m_count ; ++i )
{
const wxColour& col = &M_PALETTEDATA->m_palette[i] ;
currentdiff = abs ( col.Red() - red ) + abs( col.Green() - green ) + abs ( col.Blue() - blue ) ;
if ( currentdiff < bestdiff )
{
bestdiff = currentdiff ;
bestpos = i ;
if ( bestdiff == 0 )
break ;
}
}
return bestpos;
}
bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const
{
if ( !m_refData )
return FALSE;
if (index < 0 || index >= M_PALETTEDATA->m_count)
return FALSE;
const wxColour& col = &M_PALETTEDATA->m_palette[index] ;
*red = col.Red() ;
*green = col.Green() ;
*blue = col.Blue() ;
return TRUE;
}
#endif
// wxUSE_PALETTE

186
src/mac/classic/pen.cpp Normal file
View File

@@ -0,0 +1,186 @@
/////////////////////////////////////////////////////////////////////////////
// Name: pen.cpp
// Purpose: wxPen
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "pen.h"
#endif
#include "wx/setup.h"
#include "wx/utils.h"
#include "wx/pen.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
#endif
wxPenRefData::wxPenRefData()
{
m_style = wxSOLID;
m_width = 1;
m_join = wxJOIN_ROUND ;
m_cap = wxCAP_ROUND ;
m_nbDash = 0 ;
m_dash = 0 ;
}
wxPenRefData::wxPenRefData(const wxPenRefData& data)
: wxGDIRefData()
{
m_style = data.m_style;
m_width = data.m_width;
m_join = data.m_join;
m_cap = data.m_cap;
m_nbDash = data.m_nbDash;
m_dash = data.m_dash;
m_colour = data.m_colour;
}
wxPenRefData::~wxPenRefData()
{
}
// Pens
wxPen::wxPen()
{
}
wxPen::~wxPen()
{
}
// Should implement Create
wxPen::wxPen(const wxColour& col, int Width, int Style)
{
m_refData = new wxPenRefData;
M_PENDATA->m_colour = col;
M_PENDATA->m_width = Width;
M_PENDATA->m_style = Style;
M_PENDATA->m_join = wxJOIN_ROUND ;
M_PENDATA->m_cap = wxCAP_ROUND ;
M_PENDATA->m_nbDash = 0 ;
M_PENDATA->m_dash = 0 ;
RealizeResource();
}
wxPen::wxPen(const wxBitmap& stipple, int Width)
{
m_refData = new wxPenRefData;
M_PENDATA->m_stipple = stipple;
M_PENDATA->m_width = Width;
M_PENDATA->m_style = wxSTIPPLE;
M_PENDATA->m_join = wxJOIN_ROUND ;
M_PENDATA->m_cap = wxCAP_ROUND ;
M_PENDATA->m_nbDash = 0 ;
M_PENDATA->m_dash = 0 ;
RealizeResource();
}
void wxPen::Unshare()
{
// Don't change shared data
if (!m_refData)
{
m_refData = new wxPenRefData();
}
else
{
wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
UnRef();
m_refData = ref;
}
}
void wxPen::SetColour(const wxColour& col)
{
Unshare();
M_PENDATA->m_colour = col;
RealizeResource();
}
void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
{
Unshare();
M_PENDATA->m_colour.Set(r, g, b);
RealizeResource();
}
void wxPen::SetWidth(int Width)
{
Unshare();
M_PENDATA->m_width = Width;
RealizeResource();
}
void wxPen::SetStyle(int Style)
{
Unshare();
M_PENDATA->m_style = Style;
RealizeResource();
}
void wxPen::SetStipple(const wxBitmap& Stipple)
{
Unshare();
M_PENDATA->m_stipple = Stipple;
M_PENDATA->m_style = wxSTIPPLE;
RealizeResource();
}
void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
{
Unshare();
M_PENDATA->m_nbDash = nb_dashes;
M_PENDATA->m_dash = (wxDash *)Dash;
RealizeResource();
}
void wxPen::SetJoin(int Join)
{
Unshare();
M_PENDATA->m_join = Join;
RealizeResource();
}
void wxPen::SetCap(int Cap)
{
Unshare();
M_PENDATA->m_cap = Cap;
RealizeResource();
}
bool wxPen::RealizeResource()
{
// nothing to do here for mac
return TRUE;
}

904
src/mac/classic/pnghand.cpp Normal file
View File

@@ -0,0 +1,904 @@
/////////////////////////////////////////////////////////////////////////////
// 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
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#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
#ifndef __DARWIN__
# include <windows.h>
#endif
#include "wx/msgdlg.h"
#include "wx/palette.h"
#include "wx/bitmap.h"
#include "wx/mac/pnghand.h"
#include "wx/mac/pngread.h"
#include "wx/mac/private.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 width , int height , int depth ) ;
extern void wxMacDestroyGWorld( GWorldPtr gw ) ;
void
ima_png_error(png_struct *png_ptr, char *message)
{
wxMessageBox(wxString::FromAscii(message), wxT("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;
m_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 = m_palette used
// Bit 2 = Color used
// Bit 3 = Alpha used
EfeWidth = 0; // Efective Width
lpbi = NULL;
bgindex = -1;
m_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);
delete m_palette;
m_palette = NULL;
delete[] RawImage;
RawImage = NULL;
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
}
lpbi = wxMacCreateGWorld( Width , Height , Depth);
if (lpbi)
{
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 ( )
{
if (RawImage != NULL) {
delete[] RawImage ;
RawImage = NULL;
}
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
lpbi = NULL;
}
if (m_palette != NULL) {
delete m_palette;
m_palette = NULL;
}
}
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 (m_palette) {
return m_palette->GetRGB(GetIndex(x, y), r, g, b);
/* PALETTEENTRY entry;
::GetPaletteEntries((HPALETTE) m_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 (!m_palette) return FALSE;
SetIndex(x, y, m_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)
{
delete m_palette ;
if (!colourmap)
return FALSE;
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
m_palette = new wxPalette( *colourmap );
return true ;
// return (DibSetUsage(lpbi, (HPALETTE) m_palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
}
bool
wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b)
{
delete m_palette ;
m_palette = new wxPalette();
if (!m_palette)
return FALSE;
if (!g) g = r;
if (!b) b = g;
m_palette->Create(n, r, g, b);
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
return true ;
// return (DibSetUsage(lpbi, (HPALETTE) m_palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
}
bool
wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct)
{
delete m_palette ;
m_palette = new wxPalette();
if (!m_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;
m_palette->Create(n, r, g, b);
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
return true ;
// return (DibSetUsage(lpbi, (HPALETTE) m_palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
}
void wxPNGReader::NullData()
{
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
lpbi = NULL;
}
if (m_palette != NULL) {
delete m_palette;
m_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 && m_palette )
bitmap->SetPalette(*m_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 ( m_palette )
{
HPALETTE oldPal = ::SelectPalette(dc, (HPALETTE) m_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 && m_palette )
bitmap->SetPalette(*m_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( 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( (GWorldPtr) 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 )
{
for ( size_t i = 0 ; i < info_ptr->width ; ++i )
{
png_color_struct* color ;
RGBColor col ;
int index = row_pointers[i] ;
color = &info_ptr->palette[index] ;
col.red = (((int)color->red) << 8) | ((int)color->red) ;
col.green = (((int)color->green) << 8) | ((int)color->green) ;
col.blue = (((int)color->blue) << 8) | ((int)color->blue) ;
SetCPixel( i, y, &col);
}
/*
png_color_struct* color ;
RGBColor col ;
unsigned char* p = &row_pointers[0] ;
PenNormal() ;
MoveTo( 0 , y ) ;
int index = *p ;
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 ;
RGBForeColor( &col ) ;
col.red = col.green = col.blue = 0xFFFF ;
RGBBackColor( &col ) ;
for ( int i = 0 ; i < info_ptr->width ; ++i , ++p)
{
if ( *p != index )
{
LineTo( i , y ) ;
index = *p ;
color = &info_ptr->palette[index] ;
col.red = (((int)color->red) << 8) | ((int)color->red) ;
col.green = (((int)color->green) << 8) | ((int)color->green) ;
col.blue = (((int)color->blue) << 8) | ((int)color->blue) ;
RGBForeColor( &col ) ;
}
}
LineTo( info_ptr->width , y ) ;
*/
}
else
{
for ( size_t 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 = (((int)color->red) << 8) | ((int)color->red) ;
col.green = (((int)color->green) << 8) | ((int)color->green) ;
col.blue = (((int)color->blue) << 8) | ((int)color->blue) ;
SetCPixel( i, y, &col);
}
}
}
else
{
for ( size_t i = 0 ; i < info_ptr->width ; ++i )
{
png_color_struct* color ;
RGBColor col ;
color =(png_color_struct*) (&row_pointers[i*3]) ;
col.red = (((int)color->red) << 8) | ((int)color->red) ;
col.green = (((int)color->green) << 8) | ((int)color->green) ;
col.blue = (((int)color->blue) << 8) | ((int)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
{
wxString str = wxString::FromAscii(filename) ;
wxStripExtension( str ) ;
strcpy(nameStr, str.ToAscii() );
}
if ( GetDepth() > 4 )
{
// Only a depth of 4 and below allowed
return FALSE;
}
if ( !GetPalette() )
return FALSE;
wxSTD 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.ToAscii() ) )
{
return reader.InstantiateBitmap(bitmap);
}
else
return FALSE;
}
bool wxPNGFileHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *pal)
{
return FALSE;
}

View File

@@ -0,0 +1,124 @@
/////////////////////////////////////////////////////////////////////////////
// Name: printdlg.cpp
// Purpose: wxPrintDialog, wxPageSetupDialog
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "printdlg.h"
#endif
#include "wx/object.h"
#include "wx/printdlg.h"
#include "wx/dcprint.h"
#include "wx/msgdlg.h"
#include "wx/mac/private/print.h"
// Use generic page setup dialog: use your own native one if one exists.
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
#endif
wxPrintDialog::wxPrintDialog()
{
m_dialogParent = NULL;
m_printerDC = NULL;
m_destroyDC = TRUE;
}
wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
{
Create(p, data);
}
wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data)
{
wxPrintDialogData data2;
if ( data )
data2 = *data;
Create(p, &data2);
}
bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
{
m_dialogParent = p;
m_printerDC = NULL;
m_destroyDC = TRUE;
if ( data )
m_printDialogData = *data;
return TRUE;
}
wxPrintDialog::~wxPrintDialog()
{
if (m_destroyDC && m_printerDC) {
delete m_printerDC;
m_printerDC = NULL;
}
}
int wxPrintDialog::ShowModal()
{
m_printDialogData.ConvertToNative() ;
int result = m_printDialogData.GetPrintData().m_nativePrintData->ShowPrintDialog() ;
if ( result == wxID_OK )
m_printDialogData.ConvertFromNative() ;
return result ;
}
wxDC *wxPrintDialog::GetPrintDC()
{
return new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
}
/*
* wxPageSetupDialog
*/
wxPageSetupDialog::wxPageSetupDialog():
wxDialog()
{
m_dialogParent = NULL;
}
wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data):
wxDialog()
{
Create(p, data);
}
bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
{
m_dialogParent = p;
if (data)
m_pageSetupData = (*data);
return TRUE;
}
wxPageSetupDialog::~wxPageSetupDialog()
{
}
int wxPageSetupDialog::ShowModal()
{
m_pageSetupData.ConvertToNative() ;
int result = m_pageSetupData.GetPrintData().m_nativePrintData->ShowPageSetupDialog() ;
if (result == wxID_OK )
m_pageSetupData.ConvertFromNative() ;
return result ;
}

View File

@@ -0,0 +1,781 @@
/////////////////////////////////////////////////////////////////////////////
// Name: printwin.cpp
// Purpose: wxMacPrinter framework
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#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/uma.h"
#include "wx/mac/printmac.h"
#include "wx/mac/private/print.h"
#define mm2pt 2.83464566929
#define pt2mm 0.352777777778
#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
#if TARGET_CARBON
wxNativePrintData* wxNativePrintData::Create()
{
return new wxMacCarbonPrintData() ;
}
wxMacCarbonPrintData::wxMacCarbonPrintData()
{
m_macPageFormat = kPMNoPageFormat;
m_macPrintSettings = kPMNoPrintSettings;
m_macPrintSession = kPMNoReference ;
ValidateOrCreate() ;
}
wxMacCarbonPrintData::~wxMacCarbonPrintData()
{
if (m_macPageFormat != kPMNoPageFormat)
{
(void)PMRelease(m_macPageFormat);
m_macPageFormat = kPMNoPageFormat;
}
if (m_macPrintSettings != kPMNoPrintSettings)
{
(void)PMRelease(m_macPrintSettings);
m_macPrintSettings = kPMNoPrintSettings;
}
if ( m_macPrintSession != kPMNoReference )
{
(void)PMRelease(m_macPrintSession);
m_macPrintSession = kPMNoReference;
}
}
void wxMacCarbonPrintData::ValidateOrCreate()
{
OSStatus err = noErr ;
if ( m_macPrintSession == kPMNoReference )
{
err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
}
// Set up a valid PageFormat object.
if ( m_macPageFormat == kPMNoPageFormat)
{
err = PMCreatePageFormat((PMPageFormat *) &m_macPageFormat);
// Note that PMPageFormat is not session-specific, but calling
// PMSessionDefaultPageFormat assigns values specific to the printer
// associated with the current printing session.
if ((err == noErr) &&
( m_macPageFormat != kPMNoPageFormat))
{
err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat);
}
}
else
{
err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat,
kPMDontWantBoolean);
}
// Set up a valid PrintSettings object.
if ( m_macPrintSettings == kPMNoPrintSettings)
{
err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings);
// Note that PMPrintSettings is not session-specific, but calling
// PMSessionDefaultPrintSettings assigns values specific to the printer
// associated with the current printing session.
if ((err == noErr) &&
( m_macPrintSettings != kPMNoPrintSettings))
{
err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings);
}
}
else
{
err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings,
kPMDontWantBoolean);
}
}
void wxMacCarbonPrintData::TransferFrom( wxPrintData* data )
{
ValidateOrCreate() ;
PMSetCopies( (PMPrintSettings) m_macPrintSettings , data->GetNoCopies() , false ) ;
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data->GetOrientation() == wxLANDSCAPE ) ?
kPMLandscape : kPMPortrait , false ) ;
// collate cannot be set
#if 0 // not yet tested
if ( m_printerName.Length() > 0 )
PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
#endif
PMColorMode color ;
PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
if ( data->GetColour() )
{
if ( color == kPMBlackAndWhite )
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
}
else
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
}
void wxMacCarbonPrintData::TransferTo( wxPrintData* data )
{
OSStatus err = noErr ;
UInt32 copies ;
err = PMGetCopies( m_macPrintSettings , &copies ) ;
if ( err == noErr )
data->SetNoCopies( copies ) ;
PMOrientation orientation ;
err = PMGetOrientation( m_macPageFormat , &orientation ) ;
if ( err == noErr )
{
if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
data->SetOrientation( wxPORTRAIT );
else
data->SetOrientation( wxLANDSCAPE );
}
// collate cannot be set
#if 0
{
wxMacCFStringHolder name ;
PMPrinter printer ;
PMSessionGetCurrentPrinter( m_macPrintSession ,
&printer ) ;
m_printerName = name.AsString() ;
}
#endif
PMColorMode color ;
err = PMGetColorMode( m_macPrintSettings, &color ) ;
if ( err == noErr )
data->SetColour( !(color == kPMBlackAndWhite) ) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
PMRect rPaper;
err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
if ( err == noErr )
{
data->SetPaperSize( wxSize (
(int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
(int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) ) );
}
}
void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *data )
{
// should we setup the page rect here ?
// since MacOS sometimes has two same paper rects with different
// page rects we could make it roundtrip safe perhaps
#if TARGET_CARBON
#else
#endif
}
void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data )
{
PMRect rPaper;
OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
if ( err == noErr )
{
PMRect rPage ;
err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
if ( err == noErr )
{
data->SetMinMarginTopLeft( wxPoint (
(int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
(int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;
data->SetMinMarginBottomRight( wxPoint (
(wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm),
(wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ;
}
}
}
void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data )
{
UInt32 minPage , maxPage ;
PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ;
data->SetMinPage( minPage ) ;
data->SetMaxPage( maxPage ) ;
UInt32 copies ;
PMGetCopies( m_macPrintSettings , &copies ) ;
data->SetNoCopies( copies ) ;
UInt32 from , to ;
PMGetFirstPage( m_macPrintSettings , &from ) ;
PMGetLastPage( m_macPrintSettings , &to ) ;
data->SetFromPage( from ) ;
data->SetToPage( to ) ;
}
void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
{
PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;
int toPage = data->GetToPage();
if (toPage < 1)
toPage = data->GetFromPage();
PMSetLastPage( m_macPrintSettings , toPage , false ) ;
}
void wxMacCarbonPrintData::CopyFrom( wxNativePrintData* d )
{
wxMacCarbonPrintData *data = (wxMacCarbonPrintData*) d ;
if ( data->m_macPrintSession != kPMNoReference )
PMRetain( data->m_macPrintSession ) ;
if ( m_macPrintSession != kPMNoReference )
{
PMRelease( m_macPrintSession ) ;
m_macPrintSession = kPMNoReference ;
}
if ( data->m_macPrintSession != kPMNoReference )
m_macPrintSession = data->m_macPrintSession ;
if ( data->m_macPrintSettings != kPMNoPrintSettings )
PMRetain( data->m_macPrintSettings ) ;
if ( m_macPrintSettings != kPMNoPrintSettings )
{
PMRelease( m_macPrintSettings ) ;
m_macPrintSettings = kPMNoPrintSettings ;
}
if ( data->m_macPrintSettings != kPMNoPrintSettings )
m_macPrintSettings = data->m_macPrintSettings ;
if ( data->m_macPageFormat != kPMNoPageFormat )
PMRetain( data->m_macPageFormat ) ;
if ( m_macPageFormat != kPMNoPageFormat )
{
PMRelease( m_macPageFormat ) ;
m_macPageFormat = kPMNoPageFormat ;
}
if ( data->m_macPageFormat != kPMNoPageFormat )
m_macPageFormat = data->m_macPageFormat ;
}
int wxMacCarbonPrintData::ShowPrintDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
Boolean accepted;
{
// Display the Print dialog.
if (err == noErr)
{
err = PMSessionPrintDialog( m_macPrintSession,
m_macPrintSettings,
m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
if ( err == noErr )
{
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
return result ;
}
int wxMacCarbonPrintData::ShowPageSetupDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
Boolean accepted;
{
// Display the Page Setup dialog.
if (err == noErr)
{
err = PMSessionPageSetupDialog( m_macPrintSession,
m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
// If the user did not cancel, flatten and save the PageFormat object
// with our document.
if (err == noErr) {
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
return result ;
}
#else
wxNativePrintData* wxNativePrintData::Create()
{
return new wxMacClassicPrintData() ;
}
wxMacClassicPrintData::wxMacClassicPrintData()
{
m_macPrintSettings = NULL ;
ValidateOrCreate() ;
}
wxMacClassicPrintData::~wxMacClassicPrintData()
{
wxASSERT( m_macPrintSettings );
DisposeHandle( (Handle) m_macPrintSettings ) ;
}
void wxMacClassicPrintData::ValidateOrCreate()
{
if ( m_macPrintSettings == NULL )
{
m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) );
(**m_macPrintSettings).iPrVersion = 0; // something invalid
(**m_macPrintSettings).prInfo.iHRes = 72;
(**m_macPrintSettings).prInfo.iVRes = 72;
Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
(**m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0)
Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 };
(**m_macPrintSettings).rPaper = r2;
(**m_macPrintSettings).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch
(**m_macPrintSettings).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch
}
else
{
}
}
void wxMacClassicPrintData::TransferFrom( wxPrintData* data )
{
ValidateOrCreate() ;
(**m_macPrintSettings).prJob.iCopies = data->GetNoCopies() ;
// on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
// if all printing data is consolidated in on structure we will be able to set additional infos about pages
}
void wxMacClassicPrintData::TransferTo( wxPrintData* data )
{
data->SetNoCopies( (**m_macPrintSettings).prJob.iCopies );
data->SetPaperSize( wxSize(
((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).rPaper.left ) * pt2mm ,
((double) (**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
}
void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data )
{
}
void wxMacClassicPrintData::TransferTo( wxPageSetupData* data )
{
data->SetMinMarginTopLeft( wxPoint(
((double) (**m_macPrintSettings).prInfo.rPage.left -(**m_macPrintSettings).rPaper.left ) * pt2mm ,
((double) (**m_macPrintSettings).prInfo.rPage.top -(**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
data->SetMinMarginBottomRight( wxPoint(
((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).prInfo.rPage.right ) * pt2mm ,
((double)(**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm ) ) ;
}
void wxMacClassicPrintData::TransferFrom( wxPrintDialogData* data )
{
int toPage = data->GetToPage();
if (toPage < 1)
toPage = data->GetFromPage();
(**m_macPrintSettings).prJob.iFstPage = data->GetFromPage() ;
(**m_macPrintSettings).prJob.iLstPage = toPage;
}
void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data )
{
data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ;
data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ;
}
void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data )
{
DisposeHandle( (Handle) m_macPrintSettings ) ;
m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings;
HandToHand( (Handle*) &m_macPrintSettings );
}
int wxMacClassicPrintData::ShowPrintDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
err = ::UMAPrOpen() ;
if ( err == noErr )
{
if ( ::PrJobDialog( m_macPrintSettings ) )
{
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose() ;
return result ;
}
int wxMacClassicPrintData::ShowPageSetupDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
err = ::UMAPrOpen() ;
if ( err == noErr )
{
if ( ::PrStlDialog( m_macPrintSettings ) )
{
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose() ;
return result ;
}
#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);
if (m_printDialogData.GetMinPage() < 1)
m_printDialogData.SetMinPage(1);
if (m_printDialogData.GetMaxPage() < 1)
m_printDialogData.SetMaxPage(9999);
// Create a suitable device context
wxDC *dc = NULL;
if (prompt)
{
wxPrintDialog dialog(parent, & m_printDialogData);
if (dialog.ShowModal() == wxID_OK)
{
dc = dialog.GetPrintDC();
m_printDialogData = dialog.GetPrintDialogData();
}
}
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;
wxCoord 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();
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)
{
wxEndBusyCursor();
return FALSE;
}
// Only set min and max, because from and to have been
// set by the user
m_printDialogData.SetMinPage(minPage);
m_printDialogData.SetMaxPage(maxPage);
wxWindow *win = CreateAbortWindow(parent, printout);
wxSafeYield(win,true);
if (!win)
{
wxEndBusyCursor();
wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
delete dc;
return FALSE;
}
sm_abortWindow = win;
sm_abortWindow->Show(TRUE);
wxSafeYield(win,true);
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(wxT("Could not start printing."), wxT("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
{
#if TARGET_CARBON
if ( UMAGetSystemVersion() >= 0x1000 )
#endif
{
GrafPtr thePort ;
GetPort( &thePort ) ;
wxSafeYield(win,true);
SetPort( thePort ) ;
}
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)
{
int screenWidth , screenHeight ;
wxDisplaySize( &screenWidth , &screenHeight ) ;
m_previewPrintout->SetPPIScreen( 72 , 72 ) ;
m_previewPrintout->SetPPIPrinter( 72 , 72 ) ;
m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) );
m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
m_pageWidth = 8 * 72 ;
m_pageHeight = 11 * 72 ;
m_previewScale = 1 ;
// Get a device context for the currently selected printer
wxPrinterDC printerDC(m_printDialogData.GetPrintData());
if (printerDC.Ok())
{
int x , y ;
wxCoord ww, hh;
printerDC.GetSizeMM(&ww, &hh);
printerDC.GetSize( &x , &y ) ;
m_previewPrintout->SetPageSizeMM((int)ww, (int)hh);
m_previewPrintout->SetPageSizePixels( x , y) ;
m_pageWidth = x ;
m_pageHeight = y ;
m_isOk = true ;
}
else
{
m_isOk = false ;
}
// 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)printerXRes);
m_previewScale = 1 ;
}

View File

@@ -0,0 +1,580 @@
/////////////////////////////////////////////////////////////////////////////
// Name: radiobox.cpp
// Purpose: wxRadioBox
// Author: Stefan Csomor
// Modified by: JS Lair (99/11/15) first implementation
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "radioboxbase.h"
#pragma implementation "radiobox.h"
#endif
//-------------------------------------------------------------------------------------
// headers
//-------------------------------------------------------------------------------------
#include "wx/defs.h"
#include "wx/arrstr.h"
#include "wx/radiobox.h"
#include "wx/radiobut.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
#endif
//-------------------------------------------------------------------------------------
// <20> wxRadioBox()
//-------------------------------------------------------------------------------------
// Default constructor
BEGIN_EVENT_TABLE(wxRadioBox, wxControl)
EVT_RADIOBUTTON( -1 , wxRadioBox::OnRadioButton )
END_EVENT_TABLE()
void wxRadioBox::OnRadioButton( wxCommandEvent &outer )
{
if ( outer.IsChecked() )
{
wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
int i = GetSelection() ;
event.SetInt( i );
event.SetString( GetString( i ) );
event.SetEventObject( this );
ProcessCommand(event);
}
}
wxRadioBox::wxRadioBox()
{
m_noItems = 0;
m_noRowsOrCols = 0;
m_majorDim = 0 ;
m_radioButtonCycle = NULL;
}
//-------------------------------------------------------------------------------------
// <20> wxRadioBox(wxWindow*, wxWindowID, const wxString&, const wxPoint&,
// const wxSize&, int, const wxString[], int, long,
// const wxValidator&, const wxString&)
//-------------------------------------------------------------------------------------
// Contructor, creating and showing a radiobox
//
// inline defined
//
//-------------------------------------------------------------------------------------
// <20> ~wxRadioBox
//-------------------------------------------------------------------------------------
// Destructor, destroying the radiobox item
wxRadioBox::~wxRadioBox()
{
m_isBeingDeleted = TRUE;
wxRadioButton *next,*current;
current=m_radioButtonCycle->NextInCycle();
next=current->NextInCycle();
while (current!=m_radioButtonCycle) {
delete current;
current=next;
next=current->NextInCycle();
}
delete current;
}
//-------------------------------------------------------------------------------------
// <20> Create
//-------------------------------------------------------------------------------------
// Create the radiobox for two-step construction
bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
const wxPoint& pos, const wxSize& size,
const wxArrayString& choices,
int majorDim, long style,
const wxValidator& val, const wxString& name)
{
wxCArrayString chs(choices);
return Create(parent, id, label, pos, size, chs.GetCount(),
chs.GetStrings(), majorDim, style, val, name);
}
bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
const wxPoint& pos, const wxSize& size,
int n, const wxString choices[],
int majorDim, long style,
const wxValidator& val, const wxString& name)
{
if ( !wxControl::Create(parent, id, pos, size, style, val, name) )
return false;
int i;
m_noItems = n;
m_noRowsOrCols = majorDim;
m_radioButtonCycle = NULL;
if (majorDim==0)
m_majorDim = n ;
else
m_majorDim = majorDim ;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , wxStripMenuCodes(label) , pos , size ,style, val , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
kControlGroupBoxTextTitleProc , (long) this ) ;
for (i = 0; i < n; i++)
{
wxRadioButton *radBtn = new wxRadioButton
(
this,
wxID_ANY,
wxStripMenuCodes(choices[i]),
wxPoint(5,20*i+10),
wxDefaultSize,
i == 0 ? wxRB_GROUP : 0
);
if ( i == 0 )
m_radioButtonCycle = radBtn ;
// m_radioButtonCycle=radBtn->AddInCycle(m_radioButtonCycle);
}
SetSelection(0);
MacPostControlCreate() ;
return TRUE;
}
//-------------------------------------------------------------------------------------
// <20> Enable(bool)
//-------------------------------------------------------------------------------------
// Enables or disables the entire radiobox
bool wxRadioBox::Enable(bool enable)
{
int i;
wxRadioButton *current;
if (!wxControl::Enable(enable))
return false;
current = m_radioButtonCycle;
for (i = 0; i < m_noItems; i++) {
current->Enable(enable);
current = current->NextInCycle();
}
return true;
}
//-------------------------------------------------------------------------------------
// <20> Enable(int, bool)
//-------------------------------------------------------------------------------------
// Enables or disables an given button
void wxRadioBox::Enable(int item, bool enable)
{
int i;
wxRadioButton *current;
if ((item < 0) || (item >= m_noItems))
return;
i = 0;
current = m_radioButtonCycle;
while (i != item) {
i++;
current = current->NextInCycle();
}
current->Enable(enable);
}
//-------------------------------------------------------------------------------------
// <20> GetLabel()
//-------------------------------------------------------------------------------------
// Returns the radiobox label
wxString wxRadioBox::GetLabel() const
{
return wxControl::GetLabel();
}
//-------------------------------------------------------------------------------------
// <20> GetLabel(int)
//-------------------------------------------------------------------------------------
// Returns the label for the given button
wxString wxRadioBox::GetString(int item) const
{
int i;
wxRadioButton *current;
if ((item < 0) || (item >= m_noItems))
return wxEmptyString;
i = 0;
current = m_radioButtonCycle;
while (i != item) {
i++;
current = current->NextInCycle();
}
return current->GetLabel();
}
//-------------------------------------------------------------------------------------
// <20> GetSelection
//-------------------------------------------------------------------------------------
// Returns the zero-based position of the selected button
int wxRadioBox::GetSelection() const
{
int i;
wxRadioButton *current;
i=0;
current=m_radioButtonCycle;
while (!current->GetValue()) {
i++;
current=current->NextInCycle();
}
return i;
}
//-------------------------------------------------------------------------------------
// <20> Number
//-------------------------------------------------------------------------------------
// Returns the number of buttons in the radiobox
//
// inline defined
//
//-------------------------------------------------------------------------------------
// <20> SetLabel(const wxString&)
//-------------------------------------------------------------------------------------
// Sets the radiobox label
void wxRadioBox::SetLabel(const wxString& label)
{
return wxControl::SetLabel(label);
}
//-------------------------------------------------------------------------------------
// <20> SetLabel(int, const wxString&)
//-------------------------------------------------------------------------------------
// Sets the label of a given button
void wxRadioBox::SetString(int item,const wxString& label)
{
int i;
wxRadioButton *current;
if ((item < 0) || (item >= m_noItems))
return;
i=0;
current=m_radioButtonCycle;
while (i!=item) {
i++;
current=current->NextInCycle();
}
return current->SetLabel(label);
}
//-------------------------------------------------------------------------------------
// <20> SetSelection
//-------------------------------------------------------------------------------------
// Sets a button by passing the desired position. This does not cause
// wxEVT_COMMAND_RADIOBOX_SELECTED event to get emitted
void wxRadioBox::SetSelection(int item)
{
int i;
wxRadioButton *current;
if ((item < 0) || (item >= m_noItems))
return;
i=0;
current=m_radioButtonCycle;
while (i!=item) {
i++;
current=current->NextInCycle();
}
current->SetValue(true);
}
//-------------------------------------------------------------------------------------
// <20> Show(bool)
//-------------------------------------------------------------------------------------
// Shows or hides the entire radiobox
bool wxRadioBox::Show(bool show)
{
int i;
wxRadioButton *current;
wxControl::Show(show);
current=m_radioButtonCycle;
for (i=0;i<m_noItems;i++) {
current->Show(show);
current=current->NextInCycle();
}
return true;
}
//-------------------------------------------------------------------------------------
// <20> Show(int, bool)
//-------------------------------------------------------------------------------------
// Shows or hides the given button
void wxRadioBox::Show(int item, bool show)
{
int i;
wxRadioButton *current;
if ((item < 0) || (item >= m_noItems))
return;
i=0;
current=m_radioButtonCycle;
while (i!=item) {
i++;
current=current->NextInCycle();
}
current->Show(show);
}
//-------------------------------------------------------------------------------------
// <20> Command
//-------------------------------------------------------------------------------------
// Simulates the effect of the user issuing a command to the item
void wxRadioBox::Command (wxCommandEvent & event)
{
SetSelection (event.GetInt());
ProcessCommand (event);
}
//-------------------------------------------------------------------------------------
// <20> SetFocus
//-------------------------------------------------------------------------------------
// Sets the selected button to receive keyboard input
void wxRadioBox::SetFocus()
{
int i;
wxRadioButton *current;
i=0;
current=m_radioButtonCycle;
while (!current->GetValue()) {
i++;
current=current->NextInCycle();
}
current->SetFocus();
}
//-------------------------------------------------------------------------------------
// <20> DoSetSize
//-------------------------------------------------------------------------------------
// Simulates the effect of the user issuing a command to the item
#define RADIO_SIZE 20
void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
int i;
wxRadioButton *current;
// define the position
int x_current, y_current;
int x_offset,y_offset;
int widthOld, heightOld;
GetSize(&widthOld, &heightOld);
x_offset = x;
y_offset = y;
GetPosition(&x_current, &y_current);
if ((x == -1) && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x_offset = x_current;
if ((y == -1)&& !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y_offset = y_current;
// define size
int charWidth,charHeight;
int maxWidth,maxHeight;
int eachWidth[128],eachHeight[128];
int totWidth,totHeight;
SetFont(GetParent()->GetFont());
GetTextExtent(wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &charWidth, &charHeight);
charWidth/=52;
maxWidth=-1;
maxHeight=-1;
for (i = 0 ; i < m_noItems; i++)
{
GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i]);
eachWidth[i] = (int)(eachWidth[i] + RADIO_SIZE);
eachHeight[i] = (int)((3*eachHeight[i])/2);
if (maxWidth<eachWidth[i]) maxWidth = eachWidth[i];
if (maxHeight<eachHeight[i]) maxHeight = eachHeight[i];
}
totHeight = GetRowCount() * (maxHeight + charHeight/2) + charHeight ;
totWidth = GetColumnCount() * (maxWidth + charWidth) + charWidth;
// only change our width/height if asked for
if ( width == -1 )
{
if ( sizeFlags & wxSIZE_AUTO_WIDTH )
width = totWidth ;
else
width = widthOld;
}
if ( height == -1 )
{
if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
height = totHeight ;
else
height = heightOld;
}
wxControl::DoSetSize(x_offset,y_offset,width,height,wxSIZE_AUTO);
// arrange radiobuttons
int x_start,y_start;
x_start = charWidth;
y_start = 15 ;
if ( UMAGetSystemVersion() >= 0x1030 )
{
//need to add a few more pixels for the top border on panther
y_start = y_start + 5; //how many exactly should this be to meet the HIG?
}
x_offset = x_start;
y_offset = y_start;
current=m_radioButtonCycle;
for ( i = 0 ; i < m_noItems; i++)
{
if (i&&((i%m_majorDim)==0)) // not to do for the zero button!
{
if (m_windowStyle & wxRA_VERTICAL)
{
x_offset += maxWidth + charWidth;
y_offset = y_start;
}
else
{
x_offset = x_start;
y_offset += maxHeight ; /*+ charHeight/2;*/
}
}
current->SetSize(x_offset,y_offset,eachWidth[i],eachHeight[i]);
current=current->NextInCycle();
if (m_windowStyle & wxRA_SPECIFY_ROWS)
y_offset += maxHeight ; /*+ charHeight/2;*/
else
x_offset += maxWidth + charWidth;
}
}
wxSize wxRadioBox::DoGetBestSize() const
{
int charWidth, charHeight;
int maxWidth, maxHeight;
int eachWidth, eachHeight;
int totWidth, totHeight;
wxFont font = GetParent()->GetFont();
GetTextExtent(wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
&charWidth, &charHeight, NULL, NULL, &font);
charWidth /= 52;
maxWidth = -1;
maxHeight = -1;
for (int i = 0 ; i < m_noItems; i++)
{
GetTextExtent(GetString(i), &eachWidth, &eachHeight);
eachWidth = (int)(eachWidth + RADIO_SIZE) ;
eachHeight = (int)((3 * eachHeight) / 2);
if (maxWidth < eachWidth) maxWidth = eachWidth;
if (maxHeight < eachHeight) maxHeight = eachHeight;
}
totHeight = GetRowCount() * (maxHeight + charHeight/2) + charHeight ;
totWidth = GetColumnCount() * (maxWidth + charWidth) + charWidth;
if ( UMAGetSystemVersion() >= 0x1030 )
{
//need to add a few more pixels for the static boxborder on panther
totHeight = totHeight + 10; //how many exactly should this be to meet the HIG?
}
// handle radio box title as well
GetTextExtent(GetTitle(), &eachWidth, NULL);
eachWidth = (int)(eachWidth + RADIO_SIZE) + 3 * charWidth ;
if (totWidth < eachWidth)
totWidth = eachWidth;
return wxSize(totWidth, totHeight);
}
//-------------------------------------------------------------------------------------
// <20> GetNumVer
//-------------------------------------------------------------------------------------
// return the number of buttons in the vertical direction
int wxRadioBox::GetRowCount() const
{
if ( m_windowStyle & wxRA_SPECIFY_ROWS )
{
return m_majorDim;
}
else
{
return (m_noItems + m_majorDim - 1)/m_majorDim;
}
}
//-------------------------------------------------------------------------------------
// <20> GetNumHor
//-------------------------------------------------------------------------------------
// return the number of buttons in the horizontal direction
int wxRadioBox::GetColumnCount() const
{
if ( m_windowStyle & wxRA_SPECIFY_ROWS )
{
return (m_noItems + m_majorDim - 1)/m_majorDim;
}
else
{
return m_majorDim;
}
}

View File

@@ -0,0 +1,150 @@
/////////////////////////////////////////////////////////////////////////////
// Name: radiobut.cpp
// Purpose: wxRadioButton
// Author: AUTHOR
// Modified by: JS Lair (99/11/15) adding the cyclic groupe notion for radiobox
// Created: ??/??/98
// RCS-ID: $Id$
// Copyright: (c) AUTHOR
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "radiobut.h"
#endif
#include "wx/defs.h"
#include "wx/radiobut.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
#endif
#include "wx/mac/uma.h"
bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
return false;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
kControlRadioButtonProc , (long) this ) ;
MacPostControlCreate() ;
m_cycle = this ;
if (HasFlag(wxRB_GROUP))
{
AddInCycle( NULL ) ;
}
else
{
/* search backward for last group start */
wxRadioButton *chief = (wxRadioButton*) NULL;
wxWindowList::Node *node = parent->GetChildren().GetLast();
while (node)
{
wxWindow *child = node->GetData();
if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
{
chief = (wxRadioButton*) child;
if (child->HasFlag(wxRB_GROUP)) break;
}
node = node->GetPrevious();
}
AddInCycle( chief ) ;
}
return TRUE;
}
void wxRadioButton::SetValue(bool val)
{
wxRadioButton *cycle;
if ( GetControl32BitValue( (ControlHandle) m_macControl ) == val )
return ;
::SetControl32BitValue( (ControlHandle) m_macControl , val ) ;
if (val)
{
cycle=this->NextInCycle();
if (cycle!=NULL) {
while (cycle!=this) {
cycle->SetValue(false);
cycle=cycle->NextInCycle();
}
}
}
MacRedrawControl() ;
}
bool wxRadioButton::GetValue() const
{
return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
}
void wxRadioButton::Command (wxCommandEvent & event)
{
SetValue ( (event.GetInt() != 0) );
ProcessCommand (event);
}
void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
{
if ( GetValue() )
return ;
wxRadioButton *cycle, *old = NULL ;
cycle=this->NextInCycle();
if (cycle!=NULL) {
while (cycle!=this) {
if ( cycle->GetValue() ) {
old = cycle ;
cycle->SetValue(false);
}
cycle=cycle->NextInCycle();
}
}
SetValue(true) ;
if ( old ) {
wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
event.SetEventObject(old);
event.SetInt( false );
old->ProcessCommand(event);
}
wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
event2.SetEventObject(this);
event2.SetInt( true );
ProcessCommand(event2);
}
wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
{
wxRadioButton *next,*current;
if (cycle==NULL) {
m_cycle=this;
return(this);
}
else {
current=cycle;
while ((next=current->m_cycle)!=cycle)
current=current->m_cycle;
m_cycle=cycle;
current->m_cycle=this;
return(cycle);
}
}

437
src/mac/classic/region.cpp Normal file
View File

@@ -0,0 +1,437 @@
/////////////////////////////////////////////////////////////////////////////
// File: region.cpp
// Purpose: Region class
// Author: Stefan Csomor
// Created: Fri Oct 24 10:46:34 MET 1997
// RCS-ID: $Id$
// Copyright: (c) 1997 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "region.h"
#endif
#include "wx/region.h"
#include "wx/gdicmn.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject)
#endif
//-----------------------------------------------------------------------------
// wxRegionRefData implementation
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxRegionRefData : public wxGDIRefData {
public:
wxRegionRefData()
{
m_macRgn = NewRgn() ;
}
wxRegionRefData(const wxRegionRefData& data)
: wxGDIRefData()
{
m_macRgn = NewRgn() ;
CopyRgn( data.m_macRgn , m_macRgn ) ;
}
~wxRegionRefData()
{
DisposeRgn( m_macRgn ) ;
}
RgnHandle m_macRgn ;
};
#define M_REGION (((wxRegionRefData*)m_refData)->m_macRgn)
#define OTHER_M_REGION(a) (((wxRegionRefData*)(a.m_refData))->m_macRgn)
//-----------------------------------------------------------------------------
// wxRegion
//-----------------------------------------------------------------------------
/*!
* Create an empty region.
*/
wxRegion::wxRegion()
{
m_refData = new wxRegionRefData;
}
wxRegion::wxRegion(WXHRGN hRegion )
{
m_refData = new wxRegionRefData;
CopyRgn( (RgnHandle) hRegion , (RgnHandle) M_REGION ) ;
}
wxRegion::wxRegion(long x, long y, long w, long h)
{
m_refData = new wxRegionRefData;
SetRectRgn( (RgnHandle) M_REGION , x , y , x+w , y+h ) ;
}
wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight)
{
m_refData = new wxRegionRefData;
SetRectRgn( (RgnHandle) M_REGION , topLeft.x , topLeft.y , bottomRight.x , bottomRight.y ) ;
}
wxRegion::wxRegion(const wxRect& rect)
{
m_refData = new wxRegionRefData;
SetRectRgn( (RgnHandle) M_REGION , rect.x , rect.y , rect.x+rect.width , rect.y+rect.height ) ;
}
/*!
* Destroy the region.
*/
wxRegion::~wxRegion()
{
// m_refData unrefed in ~wxObject
}
//-----------------------------------------------------------------------------
//# Modify region
//-----------------------------------------------------------------------------
//! Clear current region
void wxRegion::Clear()
{
UnRef();
}
//! Combine rectangle (x, y, w, h) with this.
bool wxRegion::Combine(long x, long y, long width, long height, wxRegionOp op)
{
// Don't change shared data
if (!m_refData)
{
m_refData = new wxRegionRefData();
}
else if (m_refData->GetRefCount() > 1)
{
wxRegionRefData* ref = (wxRegionRefData*)m_refData;
UnRef();
m_refData = new wxRegionRefData(*ref);
}
RgnHandle rgn = NewRgn() ;
SetRectRgn( rgn , x , y, x+width,y + height ) ;
switch (op)
{
case wxRGN_AND:
SectRgn( M_REGION , rgn , M_REGION ) ;
break ;
case wxRGN_OR:
UnionRgn( M_REGION , rgn , M_REGION ) ;
break ;
case wxRGN_XOR:
XorRgn( M_REGION , rgn , M_REGION ) ;
break ;
case wxRGN_DIFF:
DiffRgn( M_REGION , rgn , M_REGION ) ;
break ;
case wxRGN_COPY:
default:
CopyRgn( rgn ,M_REGION ) ;
break ;
}
DisposeRgn( rgn ) ;
return TRUE;
}
//! Union /e region with this.
bool wxRegion::Combine(const wxRegion& region, wxRegionOp op)
{
if (region.Empty())
return FALSE;
// Don't change shared data
if (!m_refData) {
m_refData = new wxRegionRefData();
}
else if (m_refData->GetRefCount() > 1)
{
wxRegionRefData* ref = (wxRegionRefData*)m_refData;
UnRef();
m_refData = new wxRegionRefData(*ref);
}
switch (op)
{
case wxRGN_AND:
SectRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ;
break ;
case wxRGN_OR:
UnionRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ;
break ;
case wxRGN_XOR:
XorRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ;
break ;
case wxRGN_DIFF:
DiffRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ;
break ;
case wxRGN_COPY:
default:
CopyRgn( OTHER_M_REGION(region) ,M_REGION ) ;
break ;
}
return TRUE;
}
bool wxRegion::Combine(const wxRect& rect, wxRegionOp op)
{
return Combine(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), op);
}
//-----------------------------------------------------------------------------
//# Information on region
//-----------------------------------------------------------------------------
// Outer bounds of region
void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const
{
if (m_refData)
{
Rect box ;
GetRegionBounds( M_REGION , &box ) ;
x = box.left ;
y = box.top ;
w = box.right - box.left ;
h = box.bottom - box.top ;
}
else
{
x = y = w = h = 0;
}
}
wxRect wxRegion::GetBox() const
{
wxCoord x, y, w, h;
GetBox(x, y, w, h);
return wxRect(x, y, w, h);
}
// Is region empty?
bool wxRegion::Empty() const
{
return EmptyRgn( M_REGION ) ;
}
const WXHRGN wxRegion::GetWXHRGN() const
{
return M_REGION ;
}
//-----------------------------------------------------------------------------
//# Tests
//-----------------------------------------------------------------------------
// Does the region contain the point (x,y)?
wxRegionContain wxRegion::Contains(long x, long y) const
{
if (!m_refData)
return wxOutRegion;
// TODO. Return wxInRegion if within region.
if (0)
return wxInRegion;
return wxOutRegion;
}
// Does the region contain the point pt?
wxRegionContain wxRegion::Contains(const wxPoint& pt) const
{
if (!m_refData)
return wxOutRegion;
Point p = { pt.y , pt.x } ;
if (PtInRgn( p , M_REGION ) )
return wxInRegion;
return wxOutRegion;
}
// Does the region contain the rectangle (x, y, w, h)?
wxRegionContain wxRegion::Contains(long x, long y, long w, long h) const
{
if (!m_refData)
return wxOutRegion;
Rect rect = { y , x , y + h , x + w } ;
if (RectInRgn( &rect , M_REGION ) )
return wxInRegion;
else
return wxOutRegion;
}
// Does the region contain the rectangle rect
wxRegionContain wxRegion::Contains(const wxRect& rect) const
{
if (!m_refData)
return wxOutRegion;
long x, y, w, h;
x = rect.x;
y = rect.y;
w = rect.GetWidth();
h = rect.GetHeight();
return Contains(x, y, w, h);
}
///////////////////////////////////////////////////////////////////////////////
// //
// wxRegionIterator //
// //
///////////////////////////////////////////////////////////////////////////////
/*!
* Initialize empty iterator
*/
wxRegionIterator::wxRegionIterator()
: m_current(0), m_numRects(0), m_rects(NULL)
{
}
wxRegionIterator::~wxRegionIterator()
{
if (m_rects) {
delete[] m_rects;
m_rects = NULL;
}
}
wxRegionIterator::wxRegionIterator(const wxRegionIterator& iterator)
: wxObject()
, m_current(iterator.m_current)
, m_numRects(0)
, m_rects(NULL)
{
SetRects(iterator.m_numRects, iterator.m_rects);
}
wxRegionIterator& wxRegionIterator::operator=(const wxRegionIterator& iterator)
{
m_current = iterator.m_current;
SetRects(iterator.m_numRects, iterator.m_rects);
return *this;
}
/*!
* Set iterator rects for region
*/
void wxRegionIterator::SetRects(long numRects, wxRect *rects)
{
if (m_rects) {
delete[] m_rects;
m_rects = NULL;
}
if (rects)
{
int i;
m_rects = new wxRect[numRects];
for (i = 0; i < numRects; i++)
m_rects[i] = rects[i];
}
m_numRects = numRects;
}
/*!
* Initialize iterator for region
*/
wxRegionIterator::wxRegionIterator(const wxRegion& region)
{
m_rects = NULL;
Reset(region);
}
/*!
* Reset iterator for a new /e region.
*/
void wxRegionIterator::Reset(const wxRegion& region)
{
m_current = 0;
m_region = region;
if (m_rects) {
delete[] m_rects;
m_rects = NULL;
}
if (m_region.Empty())
m_numRects = 0;
else
{
// we cannot dissolve it into rects on mac
m_rects = new wxRect[1];
Rect rect ;
GetRegionBounds( OTHER_M_REGION( region ) , &rect ) ;
m_rects[0].x = rect.left;
m_rects[0].y = rect.top;
m_rects[0].width = rect.right - rect.left;
m_rects[0].height = rect.bottom - rect.top;
m_numRects = 1;
}
}
/*!
* Increment iterator. The rectangle returned is the one after the
* incrementation.
*/
wxRegionIterator& wxRegionIterator::operator ++ ()
{
if (m_current < m_numRects)
++m_current;
return *this;
}
/*!
* Increment iterator. The rectangle returned is the one before the
* incrementation.
*/
wxRegionIterator wxRegionIterator::operator ++ (int)
{
wxRegionIterator previous(*this);
if (m_current < m_numRects)
++m_current;
return previous;
}
long wxRegionIterator::GetX() const
{
if (m_current < m_numRects)
return m_rects[m_current].x;
return 0;
}
long wxRegionIterator::GetY() const
{
if (m_current < m_numRects)
return m_rects[m_current].y;
return 0;
}
long wxRegionIterator::GetW() const
{
if (m_current < m_numRects)
return m_rects[m_current].width ;
return 0;
}
long wxRegionIterator::GetH() const
{
if (m_current < m_numRects)
return m_rects[m_current].height;
return 0;
}

View File

@@ -0,0 +1,283 @@
///////////////////////////////////////////////////////////////////////////////
// Name: mac/renderer.cpp
// Purpose: implementation of wxRendererNative for Mac
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.07.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// 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/dc.h"
#include "wx/bitmap.h"
#include "wx/settings.h"
#endif //WX_PRECOMP
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// wxRendererMac: our wxRendererNative implementation
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
{
public:
// draw the header control button (used by wxListCtrl)
virtual void DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
// draw the expanded/collapsed icon for a tree control item
virtual void DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
// draw a (vertical) sash
virtual void DrawSplitterSash(wxWindow *win,
wxDC& dc,
const wxSize& size,
wxCoord position,
wxOrientation orient,
int flags = 0);
private:
// the tree buttons
wxBitmap m_bmpTreeExpanded,
m_bmpTreeCollapsed;
};
// ----------------------------------------------------------------------------
// Aqua arrows
// ----------------------------------------------------------------------------
/* XPM */
static const char *aqua_arrow_right_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" b ",
" ddb ",
" cccdb ",
" cccccd ",
" ccccccdb ",
" ccccccccd",
" ccccccdb ",
" cccccb ",
" cccdb ",
" ddb ",
" b "
};
/* XPM */
static const char *aqua_arrow_down_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" ",
" ",
" bdcccccccdb ",
" dcccccccd ",
" bcccccccb ",
" dcccccd ",
" bcccccb ",
" bcccd ",
" dcd ",
" bcb ",
" d "
};
// ============================================================================
// implementation
// ============================================================================
/* static */
wxRendererNative& wxRendererNative::GetDefault()
{
static wxRendererMac s_rendererMac;
return s_rendererMac;
}
void
wxRendererMac::DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int WXUNUSED(flags))
{
const int CORNER = 1;
const wxCoord x = rect.x-1,
y = rect.y-1,
w = rect.width,
h = rect.height;
int major,minor;
wxGetOsVersion( &major, &minor );
dc.SetBrush( *wxTRANSPARENT_BRUSH );
if (major >= 10)
{
dc.SetPen( wxPen( wxColour( 0xC5 , 0xC5 , 0xC5 ) , 1 , wxSOLID ) );
dc.DrawRectangle( x, y+CORNER, 1, h-CORNER ); // left
// The right border is overdrawn by the left border of the right neighbouring
// header (to maintain a proper single pixel border). Except for the
// rightmost header of the listctrl.
dc.DrawRectangle( x+w+(CORNER*2), y+CORNER, 1, h-CORNER ); // right
dc.SetPen( wxPen( wxColour( 0xB1 , 0xB1 , 0xB1 ) , 1 , wxSOLID ) );
dc.DrawRectangle( x, y+h, w+(CORNER*3), 1 ); // bottom
dc.DrawRectangle( x, y, w+(CORNER*3), 1 ); // top
// Do a fill of the interior for background:
dc.SetPen( wxPen( wxColour( 0xF6 , 0xF6 , 0xF6 ) , 1 , wxSOLID ) );
dc.DrawRectangle( x+CORNER, y+CORNER, w+CORNER, h-CORNER );
// Do the gradient fill:
static int grayValues[] =
{
0xF6, 0xF2, 0xEF, 0xED, 0xED, 0xEB, 0xEA, 0xEA, 0xE8,
0xE8, 0xE2, 0xE5, 0xE8, 0xEB, 0xEF, 0xF2, 0xFD
};
int i;
for (i=0; i < h && i < (int)WXSIZEOF(grayValues); i++)
{
dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
1 , wxSOLID ) );
dc.DrawRectangle( x+CORNER, y+CORNER+i, w+CORNER, 1 );
}
}
else
{
dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
dc.SetPen( pen );
dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
dc.SetPen( *wxWHITE_PEN );
dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
dc.DrawRectangle( x, y, 1, h ); // left (outer)
dc.DrawLine( x, y+h-1, x+1, y+h-1 );
dc.DrawLine( x+w-1, y, x+w-1, y+1 );
}
}
void
wxRendererMac::DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
// init the buttons on demand
if ( !m_bmpTreeExpanded.Ok() )
{
m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
}
// draw them
// VZ: this is the old code from treectlg.cpp which apparently doesn't work
// but I kept it here just in case it is needed -- if not, please
// remove it
#if 0 // def __WXMAC__
wxMacPortSetter helper(&dc) ;
wxMacWindowClipper clipper(this) ;
wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
int loc_x = x - 5 ;
int loc_y = y_mid - 6 ;
MacWindowToRootWindow( & loc_x , & loc_y ) ;
Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
kThemeAdornmentNone };
DrawThemeButton( &bounds, kThemeDisclosureButton ,
&info , NULL , NULL , NULL , NULL ) ;
#else // 1
dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded
: m_bmpTreeCollapsed,
rect.x, rect.y, true /* use mask */);
#endif // 0/1
}
void
wxRendererMac::DrawSplitterSash(wxWindow *win,
wxDC& dc,
const wxSize& size,
wxCoord position,
wxOrientation orient,
int WXUNUSED(flags))
{
// VZ: we have to somehow determine if we're drawing a normal sash or
// a brushed metal one as they look quite differently... this is
// completely bogus anyhow, of course (TODO)
#if 0
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
if ( orient == wxVERTICAL )
dc.DrawRectangle(position, 0, 7, size.y);
else
dc.DrawRectangle(0, position, size.x, 7);
#else
// Do the gradient fill:
static int grayValues[] =
{
0xA0, 0xF6, 0xED, 0xE4, 0xE2, 0xD0, 0xA0
};
dc.SetBrush( *wxTRANSPARENT_BRUSH );
if ( orient == wxVERTICAL )
{
int i;
for (i=0; i < (int)WXSIZEOF(grayValues); i++)
{
dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
1 , wxSOLID ) );
dc.DrawRectangle( position+i, 0, 1, size.y );
}
}
else
{
int i;
for (i=0; i < (int)WXSIZEOF(grayValues); i++)
{
dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
1 , wxSOLID ) );
dc.DrawRectangle( 0, position+i, size.x, 1 );
}
}
#endif
}

View File

@@ -0,0 +1,184 @@
/////////////////////////////////////////////////////////////////////////////
// Name: scrolbar.cpp
// Purpose: wxScrollBar
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "scrolbar.h"
#endif
#include "wx/defs.h"
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/log.h"
#endif // WX_PRECOMP
#include "wx/scrolbar.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
END_EVENT_TABLE()
#endif
extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
// Scrollbar
bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
return FALSE;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
m_macControl = ::NewControl(MAC_WXHWND(parent->MacGetRootWindow()) ,
&bounds , title , false , 0 , 0 , 100,
kControlScrollBarLiveProc , (long) this) ;
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
MacPostControlCreate() ;
return TRUE;
}
wxScrollBar::~wxScrollBar()
{
}
void wxScrollBar::SetThumbPosition(int viewStart)
{
::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ;
}
int wxScrollBar::GetThumbPosition() const
{
return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
}
void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
bool refresh)
{
m_pageSize = pageSize;
m_viewSize = thumbSize;
m_objectSize = range;
int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ;
SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ;
SetControl32BitValue( (ControlHandle) m_macControl , position ) ;
if ( UMAGetAppearanceVersion() >= 0x0110 )
{
if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
{
SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ;
}
}
if ( refresh )
MacRedrawControl() ;
}
void wxScrollBar::Command(wxCommandEvent& event)
{
SetThumbPosition(event.m_commandInt);
ProcessCommand(event);
}
void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
{
if ( (ControlHandle) m_macControl == NULL )
return ;
int position = GetControl32BitValue( (ControlHandle) m_macControl) ;
int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ;
int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ;
wxEventType scrollEvent = wxEVT_NULL;
int nScrollInc = 0;
// all events have already been reported during mouse down, except for THUMBRELEASE
if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
return ;
switch( controlpart )
{
case kControlUpButtonPart :
nScrollInc = -1;
scrollEvent = wxEVT_SCROLL_LINEUP;
break ;
case kControlDownButtonPart :
nScrollInc = 1;
scrollEvent = wxEVT_SCROLL_LINEDOWN;
break ;
case kControlPageUpPart :
nScrollInc = -m_pageSize;
scrollEvent = wxEVT_SCROLL_PAGEUP;
break ;
case kControlPageDownPart :
nScrollInc = m_pageSize;
scrollEvent = wxEVT_SCROLL_PAGEDOWN;
break ;
case kControlIndicatorPart :
nScrollInc = 0 ;
if ( mouseStillDown )
scrollEvent = wxEVT_SCROLL_THUMBTRACK;
else
scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
break ;
default :
wxFAIL_MSG(wxT("illegal scrollbar selector"));
break ;
}
int new_pos = position + nScrollInc;
if (new_pos < minPos)
new_pos = minPos;
if (new_pos > maxPos)
new_pos = maxPos;
if ( nScrollInc )
SetThumbPosition(new_pos);
wxScrollEvent event(scrollEvent, m_windowId);
if ( m_windowStyle & wxHORIZONTAL )
{
event.SetOrientation( wxHORIZONTAL ) ;
}
else
{
event.SetOrientation( wxVERTICAL ) ;
}
event.SetPosition(new_pos);
event.SetEventObject( this );
wxWindow* window = GetParent() ;
if (window && window->MacIsWindowScrollbar(this) )
{
// this is hardcoded
window->MacOnScroll(event);
}
else
GetEventHandler()->ProcessEvent(event);
}

View File

@@ -0,0 +1,279 @@
/////////////////////////////////////////////////////////////////////////////
// Name: settings.cpp
// Purpose: wxSettings
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "settings.h"
#endif
#include "wx/settings.h"
#include "wx/gdicmn.h"
#include "wx/utils.h"
#include "wx/mac/uma.h"
// ----------------------------------------------------------------------------
// wxSystemSettingsNative
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// colours
// ----------------------------------------------------------------------------
wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
{
int major,minor;
wxGetOsVersion( &major, &minor );
switch( index )
{
case wxSYS_COLOUR_SCROLLBAR :
case wxSYS_COLOUR_BACKGROUND:
case wxSYS_COLOUR_ACTIVECAPTION:
case wxSYS_COLOUR_INACTIVECAPTION:
case wxSYS_COLOUR_MENU:
case wxSYS_COLOUR_WINDOW:
case wxSYS_COLOUR_WINDOWFRAME:
case wxSYS_COLOUR_ACTIVEBORDER:
case wxSYS_COLOUR_INACTIVEBORDER:
case wxSYS_COLOUR_BTNFACE:
case wxSYS_COLOUR_MENUBAR:
return wxColor( 0xDD , 0xDD , 0xDD ) ;
break ;
case wxSYS_COLOUR_LISTBOX :
{
if (major >= 10)
return *wxWHITE ;
else
return wxColor( 0xEE , 0xEE , 0xEE ) ;
break ;
}
case wxSYS_COLOUR_BTNSHADOW:
if (major >= 10)
return wxColor( 0xBE , 0xBE , 0xBE ) ;
else
return wxColor( 0x44 , 0x44 , 0x44 ) ;
break ;
case wxSYS_COLOUR_BTNTEXT:
case wxSYS_COLOUR_MENUTEXT:
case wxSYS_COLOUR_WINDOWTEXT:
case wxSYS_COLOUR_CAPTIONTEXT:
case wxSYS_COLOUR_INFOTEXT:
case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
return *wxBLACK;
break ;
case wxSYS_COLOUR_HIGHLIGHT:
{
RGBColor hilite ;
LMGetHiliteRGB(&hilite) ;
return wxColor( hilite.red >> 8 , hilite.green >> 8 , hilite.blue >> 8 ) ;
}
break ;
case wxSYS_COLOUR_BTNHIGHLIGHT:
case wxSYS_COLOUR_GRAYTEXT:
return wxColor( 0xCC , 0xCC , 0xCC ) ;
break ;
case wxSYS_COLOUR_3DDKSHADOW:
return wxColor( 0x44 , 0x44 , 0x44 ) ;
break ;
case wxSYS_COLOUR_3DLIGHT:
return wxColor( 0xCC , 0xCC , 0xCC ) ;
break ;
case wxSYS_COLOUR_HIGHLIGHTTEXT :
{
RGBColor hilite ;
LMGetHiliteRGB(&hilite) ;
if ( ( hilite.red + hilite.green + hilite.blue ) == 0 )
return *wxWHITE ;
else
return *wxBLACK ;
}
break ;
case wxSYS_COLOUR_INFOBK :
case wxSYS_COLOUR_APPWORKSPACE:
return *wxWHITE ;
break ;
case wxSYS_COLOUR_HOTLIGHT:
case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
case wxSYS_COLOUR_MENUHILIGHT:
// TODO
return *wxBLACK;
case wxSYS_COLOUR_MAX:
wxFAIL_MSG( _T("unknown system colour index") );
break ;
}
return *wxWHITE;
}
// ----------------------------------------------------------------------------
// fonts
// ----------------------------------------------------------------------------
wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
{
switch (index)
{
case wxSYS_ANSI_VAR_FONT :
case wxSYS_SYSTEM_FONT :
case wxSYS_DEVICE_DEFAULT_FONT :
case wxSYS_DEFAULT_GUI_FONT :
{
return *wxSMALL_FONT ;
} ;
break ;
case wxSYS_OEM_FIXED_FONT :
case wxSYS_ANSI_FIXED_FONT :
case wxSYS_SYSTEM_FIXED_FONT :
default :
{
return *wxNORMAL_FONT ;
} ;
break ;
}
return *wxNORMAL_FONT;
}
// ----------------------------------------------------------------------------
// system metrics/features
// ----------------------------------------------------------------------------
// Get a system metric, e.g. scrollbar size
int wxSystemSettingsNative::GetMetric(wxSystemMetric index)
{
int value;
switch ( index)
{
case wxSYS_MOUSE_BUTTONS:
// we emulate a two button mouse (ctrl + click = right button )
return 2;
case wxSYS_BORDER_X:
// TODO
return 0;
case wxSYS_BORDER_Y:
// TODO
return 0;
case wxSYS_CURSOR_X:
// TODO
return 0;
case wxSYS_CURSOR_Y:
// TODO
return 0;
case wxSYS_DCLICK_X:
// TODO
return 0;
case wxSYS_DCLICK_Y:
// TODO
return 0;
case wxSYS_DRAG_X:
// TODO
return 0;
case wxSYS_DRAG_Y:
// TODO
return 0;
case wxSYS_EDGE_X:
// TODO
return 0;
case wxSYS_EDGE_Y:
// TODO
return 0;
case wxSYS_HSCROLL_ARROW_X:
return 16;
case wxSYS_HSCROLL_ARROW_Y:
return 16;
case wxSYS_HTHUMB_X:
return 16;
case wxSYS_ICON_X:
// TODO
return 0;
case wxSYS_ICON_Y:
// TODO
return 0;
case wxSYS_ICONSPACING_X:
// TODO
return 0;
case wxSYS_ICONSPACING_Y:
// TODO
return 0;
case wxSYS_WINDOWMIN_X:
// TODO
return 0;
case wxSYS_WINDOWMIN_Y:
// TODO
return 0;
case wxSYS_SCREEN_X:
wxDisplaySize(&value, NULL);
return value;
case wxSYS_SCREEN_Y:
wxDisplaySize(NULL, &value);
return value;
case wxSYS_FRAMESIZE_X:
// TODO
return 0;
case wxSYS_FRAMESIZE_Y:
// TODO
return 0;
case wxSYS_SMALLICON_X:
// TODO
return 0;
case wxSYS_SMALLICON_Y:
// TODO
return 0;
case wxSYS_HSCROLL_Y:
return 16;
case wxSYS_VSCROLL_X:
return 16;
case wxSYS_VSCROLL_ARROW_X:
return 16;
case wxSYS_VSCROLL_ARROW_Y:
return 16;
case wxSYS_VTHUMB_Y:
return 16;
case wxSYS_CAPTION_Y:
// TODO
return 0;
case wxSYS_MENU_Y:
// TODO
return 0;
case wxSYS_NETWORK_PRESENT:
// TODO
return 0;
case wxSYS_PENWINDOWS_PRESENT:
return 0;
case wxSYS_SHOW_SOUNDS:
// TODO
return 0;
case wxSYS_SWAP_BUTTONS:
return 0;
default:
return 0;
}
return 0;
}
bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
{
switch (index)
{
case wxSYS_CAN_ICONIZE_FRAME:
case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
return TRUE;
default:
return FALSE;
}
}

433
src/mac/classic/slider.cpp Normal file
View File

@@ -0,0 +1,433 @@
/////////////////////////////////////////////////////////////////////////////
// Name: slider.cpp
// Purpose: wxSlider
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "slider.h"
#endif
#include "wx/slider.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
BEGIN_EVENT_TABLE(wxSlider, wxControl)
END_EVENT_TABLE()
#endif
// The dimensions of the different styles of sliders (From Aqua document)
#define wxSLIDER_DIMENSIONACROSS 15
#define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 24
#define wxSLIDER_DIMENSIONACROSS_ARROW 18
// Distance between slider and text
#define wxSLIDER_BORDERTEXT 5
/* NB! The default orientation for a slider is horizontal however if the user specifies
* some slider styles but dosen't specify the orientation we have to assume he wants a
* horizontal one. Therefore in this file when testing for the sliders orientation
* vertical is tested for if this is not set then we use the horizontal one
* eg. if(GetWindowStyle() & wxSL_VERTICAL) {} else { horizontal case }>
*/
// Slider
wxSlider::wxSlider()
{
m_pageSize = 1;
m_lineSize = 1;
m_rangeMax = 0;
m_rangeMin = 0;
m_tickFreq = 0;
}
extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
bool wxSlider::Create(wxWindow *parent, wxWindowID id,
int value, int minValue, int maxValue,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
return false;
Rect bounds ;
Str255 title ;
SInt16 procID;
m_macMinimumStatic = NULL ;
m_macMaximumStatic = NULL ;
m_macValueStatic = NULL ;
m_lineSize = 1;
m_tickFreq = 0;
m_rangeMax = maxValue;
m_rangeMin = minValue;
m_pageSize = (int)((maxValue-minValue)/10);
MacPreControlCreate( parent, id, wxEmptyString, pos, size, style,
validator, name, &bounds, title );
procID = kControlSliderProc + kControlSliderLiveFeedback;
if(style & wxSL_AUTOTICKS) {
procID += kControlSliderHasTickMarks;
}
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, title, false,
value, minValue, maxValue, procID, (long) this);
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
if(style & wxSL_LABELS)
{
m_macMinimumStatic = new wxStaticText( this, -1, wxEmptyString );
m_macMaximumStatic = new wxStaticText( this, -1, wxEmptyString );
m_macValueStatic = new wxStaticText( this, -1, wxEmptyString );
SetRange(minValue, maxValue);
SetValue(value);
}
else {
m_macMinimumStatic = NULL ;
m_macMaximumStatic = NULL ;
m_macValueStatic = NULL ;
}
if(style & wxSL_VERTICAL) {
SetSizeHints(10, -1, 10, -1); // Forces SetSize to use the proper width
}
else {
SetSizeHints(-1, 10, -1, 10); // Forces SetSize to use the proper height
}
// NB! SetSizeHints is overloaded by wxSlider and will substitute 10 with the
// proper dimensions, it also means other people cannot bugger the slider with
// other values
MacPostControlCreate() ;
return true;
}
wxSlider::~wxSlider()
{
}
int wxSlider::GetValue() const
{
return GetControl32BitValue( (ControlHandle) m_macControl) ;
}
void wxSlider::SetValue(int value)
{
wxString valuestring ;
valuestring.Printf( wxT("%d") , value ) ;
if ( m_macValueStatic )
m_macValueStatic->SetLabel( valuestring ) ;
SetControl32BitValue( (ControlHandle) m_macControl , value ) ;
}
void wxSlider::SetRange(int minValue, int maxValue)
{
wxString value;
m_rangeMin = minValue;
m_rangeMax = maxValue;
SetControl32BitMinimum( (ControlHandle) m_macControl, m_rangeMin);
SetControl32BitMaximum( (ControlHandle) m_macControl, m_rangeMax);
if(m_macMinimumStatic) {
value.Printf(wxT("%d"), m_rangeMin);
m_macMinimumStatic->SetLabel(value);
}
if(m_macMaximumStatic) {
value.Printf(wxT("%d"), m_rangeMax);
m_macMaximumStatic->SetLabel(value);
}
SetValue(m_rangeMin);
}
// For trackbars only
void wxSlider::SetTickFreq(int n, int pos)
{
// TODO
m_tickFreq = n;
}
void wxSlider::SetPageSize(int pageSize)
{
// TODO
m_pageSize = pageSize;
}
int wxSlider::GetPageSize() const
{
return m_pageSize;
}
void wxSlider::ClearSel()
{
// TODO
}
void wxSlider::ClearTicks()
{
// TODO
}
void wxSlider::SetLineSize(int lineSize)
{
m_lineSize = lineSize;
// TODO
}
int wxSlider::GetLineSize() const
{
// TODO
return 0;
}
int wxSlider::GetSelEnd() const
{
// TODO
return 0;
}
int wxSlider::GetSelStart() const
{
// TODO
return 0;
}
void wxSlider::SetSelection(int minPos, int maxPos)
{
// TODO
}
void wxSlider::SetThumbLength(int len)
{
// TODO
}
int wxSlider::GetThumbLength() const
{
// TODO
return 0;
}
void wxSlider::SetTick(int tickPos)
{
// TODO
}
void wxSlider::Command (wxCommandEvent & event)
{
SetValue (event.GetInt());
ProcessCommand (event);
}
void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart, bool mouseStillDown )
{
SInt16 value = ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
SetValue( value ) ;
wxEventType scrollEvent = wxEVT_NULL ;
if ( mouseStillDown )
scrollEvent = wxEVT_SCROLL_THUMBTRACK;
else
scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
wxScrollEvent event(scrollEvent, m_windowId);
event.SetPosition(value);
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId );
cevent.SetInt( value );
cevent.SetEventObject( this );
GetEventHandler()->ProcessEvent( cevent );
}
/* This is overloaded in wxSlider so that the proper width/height will always be used
* for the slider different values would cause redrawing and mouse detection problems */
void wxSlider::SetSizeHints( int minW, int minH,
int maxW , int maxH ,
int incW , int incH )
{
wxSize size = GetBestSize();
if(GetWindowStyle() & wxSL_VERTICAL) {
wxWindow::SetSizeHints(size.x, minH, size.x, maxH, incW, incH);
}
else {
wxWindow::SetSizeHints(minW, size.y, maxW, size.y, incW, incH);
}
}
wxSize wxSlider::DoGetBestSize() const
{
wxSize size;
int textwidth, textheight;
if(GetWindowStyle() & wxSL_LABELS)
{
wxString text;
int ht, wd;
// Get maximum text label width and height
text.Printf(wxT("%d"), m_rangeMin);
GetTextExtent(text, &textwidth, &textheight);
text.Printf(wxT("%d"), m_rangeMax);
GetTextExtent(text, &wd, &ht);
if(ht > textheight) {
textheight = ht;
}
if (wd > textwidth) {
textwidth = wd;
}
}
if(GetWindowStyle() & wxSL_VERTICAL)
{
if(GetWindowStyle() & wxSL_AUTOTICKS) {
size.x = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS;
}
else {
size.x = wxSLIDER_DIMENSIONACROSS_ARROW;
}
if(GetWindowStyle() & wxSL_LABELS) {
size.x += textwidth + wxSLIDER_BORDERTEXT;
}
size.y = 150;
}
else
{
if(GetWindowStyle() & wxSL_AUTOTICKS) {
size.y = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS;
}
else {
size.y = wxSLIDER_DIMENSIONACROSS_ARROW;
}
if(GetWindowStyle() & wxSL_LABELS) {
size.y += textheight + wxSLIDER_BORDERTEXT;
}
size.x = 150;
}
return size;
}
void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
wxControl::DoSetSize( x, y , width , height ,sizeFlags ) ;
}
void wxSlider::MacUpdateDimensions()
{
// actually in the current systems this should never be possible, but later reparenting
// may become a reality
if ( (ControlHandle) m_macControl == NULL )
return ;
if ( GetParent() == NULL )
return ;
WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
if ( rootwindow == NULL )
return ;
int xborder, yborder;
int minValWidth, maxValWidth, textwidth, textheight;
int sliderBreadth;
xborder = yborder = 0;
if (GetWindowStyle() & wxSL_LABELS)
{
wxString text;
int ht;
// Get maximum text label width and height
text.Printf(wxT("%d"), m_rangeMin);
GetTextExtent(text, &minValWidth, &textheight);
text.Printf(wxT("%d"), m_rangeMax);
GetTextExtent(text, &maxValWidth, &ht);
if(ht > textheight) {
textheight = ht;
}
textwidth = (minValWidth > maxValWidth ? minValWidth : maxValWidth);
xborder = textwidth + wxSLIDER_BORDERTEXT;
yborder = textheight + wxSLIDER_BORDERTEXT;
// Get slider breadth
if(GetWindowStyle() & wxSL_AUTOTICKS) {
sliderBreadth = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS;
}
else {
sliderBreadth = wxSLIDER_DIMENSIONACROSS_ARROW;
}
if(GetWindowStyle() & wxSL_VERTICAL)
{
m_macMinimumStatic->Move(sliderBreadth + wxSLIDER_BORDERTEXT,
m_height - yborder - textheight);
m_macMaximumStatic->Move(sliderBreadth + wxSLIDER_BORDERTEXT, 0);
m_macValueStatic->Move(0, m_height - textheight);
}
else
{
m_macMinimumStatic->Move(0, sliderBreadth + wxSLIDER_BORDERTEXT);
m_macMaximumStatic->Move(m_width - xborder - maxValWidth / 2,
sliderBreadth + wxSLIDER_BORDERTEXT);
m_macValueStatic->Move(m_width - textwidth, 0);
}
}
Rect oldBounds ;
GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;
int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder - xborder ;
int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder - yborder ;
GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
if ( doMove || doResize )
{
InvalWindowRect( rootwindow, &oldBounds ) ;
if ( doMove )
{
UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
}
if ( doResize )
{
UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
}
}
}
void wxSlider::DoMoveWindow(int x, int y, int width, int height)
{
wxControl::DoMoveWindow(x,y,width,height) ;
}

243
src/mac/classic/sound.cpp Normal file
View File

@@ -0,0 +1,243 @@
/////////////////////////////////////////////////////////////////////////////
// Name: sound.cpp
// Purpose: wxSound class implementation: optional
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "sound.h"
#endif
#include "wx/object.h"
#include "wx/string.h"
#include "wx/sound.h"
#if wxUSE_SOUND
#ifdef __WXMAC__
#include "wx/mac/private.h"
#ifndef __DARWIN__
#include <Sound.h>
#endif
#endif
wxSound::wxSound()
: m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
{
}
wxSound::wxSound(const wxString& sFileName, bool isResource)
: m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
{
Create(sFileName, isResource);
}
wxSound::~wxSound()
{
FreeData();
}
wxSound::wxSound(int size, const wxByte* data)
: m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(false)
{
//TODO convert data
}
bool wxSound::Create(const wxString& fileName, bool isResource)
{
bool ret = false;
m_sndname = fileName;
m_isResource = isResource;
if (m_isResource)
ret = true;
else
{ /*
if (sndChan)
{ // we're playing
FSClose(SndRefNum);
SndRefNum = 0;
SndDisposeChannel(sndChan, TRUE);
free(sndChan);
sndChan = 0;
KillTimer(0,timerID);
}
if (!lpSnd)
return true;
if (_access(lpSnd,0)) // no file, no service
return false;
// Allocate SndChannel
sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
if (!sndChan)
return false;
sndChan->qLength = 128;
if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
{
free(sndChan);
sndChan = 0;
return false;
}
if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
{
SndDisposeChannel(sndChan, TRUE);
free(sndChan);
sndChan = 0;
return false;
}
bool async = false;
if (fdwSound & SND_ASYNC)
async = true;
if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
{
FSClose (SndRefNum);
SndRefNum = 0;
SndDisposeChannel (sndChan, TRUE);
free (sndChan);
sndChan = 0;
return false;
}
if (async)
{ // haven't finish yet
timerID = SetTimer(0, 0, 250, TimerCallBack);
}
else
{
FSClose (SndRefNum);
SndRefNum = 0;
SndDisposeChannel (sndChan, TRUE);
free (sndChan);
sndChan = 0;
}*/
}
return ret;
}
//don't know what to do with looped, wth
bool wxSound::DoPlay(unsigned flags) const
{
bool ret = false;
if (m_isResource)
{
Str255 snd ;
wxMacStringToPascal( m_sndname , snd ) ;
SndListHandle hSnd;
hSnd = (SndListHandle) GetNamedResource('snd ', snd);
if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, (flags & wxSOUND_ASYNC)) == noErr))
ret = true;
}
return ret;
}
bool wxSound::FreeData()
{
bool ret = false;
if (m_isResource)
{
m_sndname.Empty();
ret = true;
}
else
{
//TODO,
}
return ret;
}
//code below is from an old implementation used for telinfo with MSVC crossplatform support
//technology proceeds, so it would be the wisest to drop this code, but it's left here just
//for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
/*static short MacOpenSndFile (char * path)
{
VolumeParam vp;
FSSpec fspec;
Str255 name;
char *c;
// first, get the volume reference number for the file. Start by
// making a Pstring with just the volume name
strcpy ((char *) name, path);
if (c = strchr ((char *) name, ':'))
{
c++;
*c = '\0';
}
c2pstr ((char *) name);
vp.ioCompletion = 0;
vp.ioVolIndex = -1;
vp.ioNamePtr = name;
vp.ioVRefNum = 0;
if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
return 0;
// next, buld an FSSpec for the file
strcpy ((char *) name, path);
c2pstr ((char *) name);
if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
return 0;
short frefnum;
// now open the file, and return it's reference number
if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
return 0;
return frefnum;
}
void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
if(!sndChan)
{
KillTimer(0,timerID);
return;
}
SCStatus scstat;
if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
if (scstat.scChannelPaused || scstat.scChannelBusy)
return; // not done yet
}
// either error or done.
FSClose (SndRefNum);
SndRefNum = 0;
SndDisposeChannel (sndChan, TRUE);
free (sndChan);
sndChan = 0;
KillTimer(0,timerID);
}*/
#endif

View File

@@ -0,0 +1,182 @@
/////////////////////////////////////////////////////////////////////////////
// Name: spinbutt.cpp
// Purpose: wxSpinButton
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "spinbutt.h"
#pragma implementation "spinbuttbase.h"
#endif
#include "wx/spinbutt.h"
#include "wx/mac/uma.h"
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
#endif
wxSpinButton::wxSpinButton()
: wxSpinButtonBase()
{
}
bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name)
{
if ( !wxSpinButtonBase::Create(parent, id, pos, size,
style, wxDefaultValidator, name) )
return false;
m_min = 0;
m_max = 100;
if (!parent)
return FALSE;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100,
kControlLittleArrowsProc , (long) this ) ;
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
MacPostControlCreate() ;
return TRUE;
}
wxSpinButton::~wxSpinButton()
{
}
// Attributes
////////////////////////////////////////////////////////////////////////////
int wxSpinButton::GetMin() const
{
return m_min;
}
int wxSpinButton::GetMax() const
{
return m_max;
}
int wxSpinButton::GetValue() const
{
return m_value;
}
void wxSpinButton::SetValue(int val)
{
m_value = val ;
}
void wxSpinButton::SetRange(int minVal, int maxVal)
{
m_min = minVal;
m_max = maxVal;
SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ;
SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ;
}
void wxSpinButton::MacHandleValueChanged( int inc )
{
wxEventType scrollEvent = wxEVT_NULL;
int oldValue = m_value ;
m_value = oldValue + inc;
if (m_value < m_min)
{
if ( m_windowStyle & wxSP_WRAP )
m_value = m_max;
else
m_value = m_min;
}
if (m_value > m_max)
{
if ( m_windowStyle & wxSP_WRAP )
m_value = m_min;
else
m_value = m_max;
}
if ( m_value - oldValue == -1 )
scrollEvent = wxEVT_SCROLL_LINEDOWN ;
else if ( m_value - oldValue == 1 )
scrollEvent = wxEVT_SCROLL_LINEUP ;
else
scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
wxSpinEvent event(scrollEvent, m_windowId);
event.SetPosition(m_value);
event.SetEventObject( this );
if ((GetEventHandler()->ProcessEvent( event )) &&
!event.IsAllowed() )
{
m_value = oldValue ;
}
SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ;
/* always send a thumbtrack event */
if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
{
scrollEvent = wxEVT_SCROLL_THUMBTRACK;
wxSpinEvent event2( scrollEvent, GetId());
event2.SetPosition( m_value );
event2.SetEventObject( this );
GetEventHandler()->ProcessEvent( event2 );
}
}
void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
{
if ( (ControlHandle) m_macControl == NULL )
return ;
int nScrollInc = 0;
switch( controlpart )
{
case kControlUpButtonPart :
nScrollInc = 1;
break ;
case kControlDownButtonPart :
nScrollInc = -1;
break ;
}
MacHandleValueChanged( nScrollInc ) ;
}
// ----------------------------------------------------------------------------
// size calculation
// ----------------------------------------------------------------------------
wxSize wxSpinButton::DoGetBestSize() const
{
return wxSize(16,24);
}

View File

@@ -0,0 +1,333 @@
/////////////////////////////////////////////////////////////////////////////
// Name: spinbutt.cpp
// Purpose: wxSpinCtrl
// Author: Robert
// Modified by: Mark Newsam (Based on GTK file)
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "spinctlg.h"
#endif
#include "wx/defs.h"
#ifndef WX_PRECOMP
#include "wx/textctrl.h"
#endif //WX_PRECOMP
#if wxUSE_SPINCTRL
#include "wx/spinbutt.h"
#include "wx/spinctrl.h"
#include "wx/spinctrl.h"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// the margin between the text control and the spin
static const wxCoord MARGIN = 2;
// ----------------------------------------------------------------------------
// wxSpinCtrlText: text control used by spin control
// ----------------------------------------------------------------------------
class wxSpinCtrlText : public wxTextCtrl
{
public:
wxSpinCtrlText(wxSpinCtrl *spin, const wxString& value)
: wxTextCtrl(spin , -1, value)
{
m_spin = spin;
}
protected:
void OnTextChange(wxCommandEvent& event)
{
int val;
if ( m_spin->GetTextValue(&val) )
{
m_spin->GetSpinButton()->SetValue(val);
}
event.Skip();
}
bool ProcessEvent(wxEvent &event)
{
// Hand button down events to wxSpinCtrl. Doesn't work.
if (event.GetEventType() == wxEVT_LEFT_DOWN && m_spin->ProcessEvent( event ))
return TRUE;
return wxTextCtrl::ProcessEvent( event );
}
private:
wxSpinCtrl *m_spin;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxSpinCtrlText, wxTextCtrl)
EVT_TEXT(-1, wxSpinCtrlText::OnTextChange)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// wxSpinCtrlButton: spin button used by spin control
// ----------------------------------------------------------------------------
class wxSpinCtrlButton : public wxSpinButton
{
public:
wxSpinCtrlButton(wxSpinCtrl *spin, int style)
: wxSpinButton(spin )
{
m_spin = spin;
SetWindowStyle(style | wxSP_VERTICAL);
}
protected:
void OnSpinButton(wxSpinEvent& eventSpin)
{
#if defined(__WXMAC__) || defined(__WXMOTIF__)
m_spin->SetTextValue(eventSpin.GetPosition());
wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, m_spin->GetId());
event.SetEventObject(m_spin);
event.SetInt(eventSpin.GetPosition());
m_spin->GetEventHandler()->ProcessEvent(event);
#else
m_spin->SetTextValue(eventSpin.GetPosition());
eventSpin.Skip();
#endif
}
private:
wxSpinCtrl *m_spin;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxSpinCtrlButton, wxSpinButton)
EVT_SPIN(-1, wxSpinCtrlButton::OnSpinButton)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxSpinCtrl creation
// ----------------------------------------------------------------------------
void wxSpinCtrl::Init()
{
m_text = NULL;
m_btn = NULL;
}
bool wxSpinCtrl::Create(wxWindow *parent,
wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
long style,
int min,
int max,
int initial,
const wxString& name)
{
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style,
wxDefaultValidator, name) )
{
return FALSE;
}
// the string value overrides the numeric one (for backwards compatibility
// reasons and also because it is simpler to satisfy the string value which
// comes much sooner in the list of arguments and leave the initial
// parameter unspecified)
if ( !value.empty() )
{
long l;
if ( value.ToLong(&l) )
initial = l;
}
wxSize csize = size ;
m_text = new wxSpinCtrlText(this, value);
m_btn = new wxSpinCtrlButton(this, style);
m_btn->SetRange(min, max);
m_btn->SetValue(initial);
if ( size.y == -1 ) {
csize.y = m_text->GetSize().y ;
}
DoSetSize(pos.x , pos.y , csize.x, csize.y);
return TRUE;
}
wxSpinCtrl::~wxSpinCtrl()
{
// delete the controls now, don't leave them alive even though they would
// still be eventually deleted by our parent - but it will be too late, the
// user code expects them to be gone now
delete m_text;
m_text = NULL ;
delete m_btn;
m_btn = NULL ;
}
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
wxSize wxSpinCtrl::DoGetBestSize() const
{
wxSize sizeBtn = m_btn->GetBestSize(),
sizeText = m_text->GetBestSize();
return wxSize(sizeBtn.x + sizeText.x + MARGIN, sizeText.y);
}
void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height)
{
wxControl::DoMoveWindow(x, y, width, height);
// position the subcontrols inside the client area
wxSize sizeBtn = m_btn->GetSize();
wxCoord wText = width - sizeBtn.x;
m_text->SetSize(0, 0, wText, height);
m_btn->SetSize(0 + wText + MARGIN, 0, -1, -1);
}
// ----------------------------------------------------------------------------
// operations forwarded to the subcontrols
// ----------------------------------------------------------------------------
bool wxSpinCtrl::Enable(bool enable)
{
if ( !wxControl::Enable(enable) )
return FALSE;
return TRUE;
}
bool wxSpinCtrl::Show(bool show)
{
if ( !wxControl::Show(show) )
return FALSE;
return TRUE;
}
// ----------------------------------------------------------------------------
// value and range access
// ----------------------------------------------------------------------------
bool wxSpinCtrl::GetTextValue(int *val) const
{
long l;
if ( !m_text->GetValue().ToLong(&l) )
{
// not a number at all
return FALSE;
}
if ( l < GetMin() || l > GetMax() )
{
// out of range
return FALSE;
}
*val = l;
return TRUE;
}
int wxSpinCtrl::GetValue() const
{
return m_btn ? m_btn->GetValue() : 0;
}
int wxSpinCtrl::GetMin() const
{
return m_btn ? m_btn->GetMin() : 0;
}
int wxSpinCtrl::GetMax() const
{
return m_btn ? m_btn->GetMax() : 0;
}
// ----------------------------------------------------------------------------
// changing value and range
// ----------------------------------------------------------------------------
void wxSpinCtrl::SetTextValue(int val)
{
wxCHECK_RET( m_text, _T("invalid call to wxSpinCtrl::SetTextValue") );
m_text->SetValue(wxString::Format(_T("%d"), val));
// select all text
m_text->SetSelection(0, -1);
// and give focus to the control!
// m_text->SetFocus(); Why???? TODO.
}
void wxSpinCtrl::SetValue(int val)
{
wxCHECK_RET( m_btn, _T("invalid call to wxSpinCtrl::SetValue") );
SetTextValue(val);
m_btn->SetValue(val);
}
void wxSpinCtrl::SetValue(const wxString& text)
{
wxCHECK_RET( m_text, _T("invalid call to wxSpinCtrl::SetValue") );
long val;
if ( text.ToLong(&val) && ((val > INT_MIN) && (val < INT_MAX)) )
{
SetValue((int)val);
}
else // not a number at all or out of range
{
m_text->SetValue(text);
m_text->SetSelection(0, -1);
}
}
void wxSpinCtrl::SetRange(int min, int max)
{
wxCHECK_RET( m_btn, _T("invalid call to wxSpinCtrl::SetRange") );
m_btn->SetRange(min, max);
}
void wxSpinCtrl::SetSelection(long from, long to)
{
// if from and to are both -1, it means (in wxWindows) that all text should
// be selected
if ( (from == -1) && (to == -1) )
{
from = 0;
}
m_text->SetSelection(from, to);
}
#endif // wxUSE_SPINCTRL

View File

@@ -0,0 +1,86 @@
/////////////////////////////////////////////////////////////////////////////
// Name: statbmp.cpp
// Purpose: wxStaticBitmap
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "statbmp.h"
#endif
#include "wx/defs.h"
#include "wx/statbmp.h"
#include "wx/dcclient.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
#endif
/*
* wxStaticBitmap
*/
BEGIN_EVENT_TABLE(wxStaticBitmap, wxStaticBitmapBase)
EVT_PAINT(wxStaticBitmap::OnPaint)
END_EVENT_TABLE()
bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
const wxBitmap& bitmap,
const wxPoint& pos,
const wxSize& s,
long style,
const wxString& name)
{
SetName(name);
wxSize size = s ;
if ( bitmap.Ok() )
{
if ( size.x == -1 )
size.x = bitmap.GetWidth() ;
if ( size.y == -1 )
size.y = bitmap.GetHeight() ;
}
m_backgroundColour = parent->GetBackgroundColour() ;
m_foregroundColour = parent->GetForegroundColour() ;
m_bitmap = bitmap;
if ( id == -1 )
m_windowId = (int)NewControlId();
else
m_windowId = id;
m_windowStyle = style;
bool ret = wxControl::Create( parent, id, pos, size, style , wxDefaultValidator , name );
SetBestSize( size ) ;
return ret;
}
void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
{
m_bitmap = bitmap;
SetSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
Refresh() ;
}
void wxStaticBitmap::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
PrepareDC(dc);
dc.DrawBitmap( m_bitmap , 0 , 0 , TRUE ) ;
}
wxSize wxStaticBitmap::DoGetBestSize() const
{
return wxWindow::DoGetBestSize() ;
}

View File

@@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////
// Name: statbox.cpp
// Purpose: wxStaticBox
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "statbox.h"
#endif
#include "wx/defs.h"
#include "wx/statbox.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
END_EVENT_TABLE()
#endif
/*
* Static box
*/
bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
if ( !wxControl::Create(parent, id, pos, size,
style, wxDefaultValidator, name) )
return false;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , label , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
kControlGroupBoxTextTitleProc , (long) this ) ;
MacPostControlCreate() ;
return TRUE;
}

View File

@@ -0,0 +1,155 @@
///////////////////////////////////////////////////////////////////////////////
// Name: statbar.cpp
// Purpose: native implementation of wxStatusBar (optional)
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) 1998 Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "statbrma.h"
#endif
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/statusbr.h"
#include "wx/dc.h"
#include "wx/dcclient.h"
BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBarGeneric)
EVT_PAINT(wxStatusBarMac::OnPaint)
END_EVENT_TABLE()
#ifdef __WXMAC__
#include "wx/mac/private.h"
#endif
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxStatusBarMac class
// ----------------------------------------------------------------------------
wxStatusBarMac::wxStatusBarMac()
{
SetParent(NULL);
}
wxStatusBarMac::~wxStatusBarMac()
{
}
bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id,
long style ,
const wxString& name)
{
return wxStatusBarGeneric::Create( parent , id , style , name ) ;
}
void wxStatusBarMac::DrawFieldText(wxDC& dc, int i)
{
int leftMargin = 2;
wxRect rect;
GetFieldRect(i, rect);
if ( !IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) )
{
dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ;
}
wxString text(GetStatusText(i));
long x, y;
dc.GetTextExtent(text, &x, &y);
int xpos = rect.x + leftMargin + 1 ;
int ypos = 1 ;
dc.SetClippingRegion(rect.x, 0, rect.width, m_height);
dc.DrawText(text, xpos, ypos);
dc.DestroyClippingRegion();
}
void wxStatusBarMac::DrawField(wxDC& dc, int i)
{
DrawFieldText(dc, i);
}
void wxStatusBarMac::SetStatusText(const wxString& text, int number)
{
wxCHECK_RET( (number >= 0) && (number < m_nFields),
_T("invalid status bar field index") );
m_statusStrings[number] = text;
wxRect rect;
GetFieldRect(number, rect);
rect.y=0;
rect.height = m_height ;
Refresh( TRUE , &rect ) ;
Update();
}
void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
dc.Clear() ;
int major,minor;
wxGetOsVersion( &major, &minor );
if ( IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) )
{
wxPen white( wxWHITE , 1 , wxSOLID ) ;
if (major >= 10)
{
//Finder statusbar border color: (Project builder similar is 9B9B9B)
dc.SetPen(wxPen(wxColour(0xB1,0xB1,0xB1),1,wxSOLID));
}
else
{
wxPen black( wxBLACK , 1 , wxSOLID ) ;
dc.SetPen(black);
}
dc.DrawLine(0, 0 ,
m_width , 0);
dc.SetPen(white);
dc.DrawLine(0, 1 ,
m_width , 1);
}
else
{
if (major >= 10)
//Finder statusbar border color: (Project builder similar is 9B9B9B)
dc.SetPen(wxPen(wxColour(0xB1,0xB1,0xB1),1,wxSOLID));
else
dc.SetPen(wxPen(wxColour(0x80,0x80,0x80),1,wxSOLID));
dc.DrawLine(0, 0 ,
m_width , 0);
}
int i;
if ( GetFont().Ok() )
dc.SetFont(GetFont());
dc.SetBackgroundMode(wxTRANSPARENT);
for ( i = 0; i < m_nFields; i ++ )
DrawField(dc, i);
}
void wxStatusBarMac::MacSuperEnabled( bool enabled )
{
Refresh(FALSE) ;
wxWindow::MacSuperEnabled( enabled ) ;
}

View 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;
}

View File

@@ -0,0 +1,67 @@
/////////////////////////////////////////////////////////////////////////////
// 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"
#include "wx/mac/uma.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 ( !wxStaticLineBase::Create(parent, id, pos, size,
style, wxDefaultValidator, name) )
return false;
Rect bounds ;
Str255 title ;
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
kControlSeparatorLineProc , (long) this ) ;
MacPostControlCreate() ;
return TRUE;
}

View File

@@ -0,0 +1,262 @@
/////////////////////////////////////////////////////////////////////////////
// Name: stattext.cpp
// Purpose: wxStaticText
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "stattext.h"
#endif
#include "wx/app.h"
#include "wx/stattext.h"
#include "wx/notebook.h"
#include "wx/tabctrl.h"
#include "wx/dc.h"
#include "wx/dcclient.h"
#include "wx/utils.h"
#include "wx/settings.h"
#include <stdio.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
#endif
#include "wx/mac/uma.h"
BEGIN_EVENT_TABLE(wxStaticText, wxStaticTextBase)
EVT_PAINT(wxStaticText::OnPaint)
END_EVENT_TABLE()
bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
m_label = wxStripMenuCodes(label) ;
if ( !wxControl::Create( parent, id, pos, size, style,
wxDefaultValidator , name ) )
{
return false;
}
SetBestSize( size ) ;
return true;
}
const wxString punct = wxT(" ,.-;:!?");
void wxStaticText::DrawParagraph(wxDC &dc, wxString paragraph, int &y)
{
long width, height ;
if (paragraph.Length() == 0)
{
// empty line
dc.GetTextExtent( wxT("H"), &width, &height );
y += height;
return;
}
int x = 0 ;
bool linedrawn = true;
while( paragraph.Length() > 0 )
{
dc.GetTextExtent( paragraph , &width , &height ) ;
if ( width > m_width )
{
for ( size_t p = paragraph.Length() - 1 ; p > 0 ; --p )
{
if ((punct.Find(paragraph[p]) != wxNOT_FOUND) || !linedrawn)
{
int blank = (paragraph[p] == ' ') ? 0 : 1;
dc.GetTextExtent( paragraph.Left(p + blank) , &width , &height ) ;
if ( width <= m_width )
{
int pos = x ;
if ( HasFlag( wxALIGN_CENTER ) )
{
pos += ( m_width - width ) / 2 ;
}
else if ( HasFlag( wxALIGN_RIGHT ) )
{
pos += ( m_width - width ) ;
}
dc.DrawText( paragraph.Left(p + blank), pos , y) ;
y += height ;
paragraph = paragraph.Mid(p+1) ;
linedrawn = true;
break ;
}
}
}
linedrawn = false;
}
else
{
int pos = x ;
if ( HasFlag( wxALIGN_CENTER ) )
{
pos += ( m_width - width ) / 2 ;
}
else if ( HasFlag( wxALIGN_RIGHT ) )
{
pos += ( m_width - width ) ;
}
dc.DrawText( paragraph, pos , y) ;
paragraph=wxEmptyString;
y += height ;
}
}
}
void wxStaticText::OnDraw( wxDC &dc )
{
if (m_width <= 0 || m_height <= 0)
return;
/*
dc.Clear() ;
wxRect rect(0,0,m_width,m_height) ;
dc.SetFont(*wxSMALL_FONT) ;
dc.DrawRectangle(rect) ;
*/
if ( !IsWindowHilited( (WindowRef) MacGetRootWindow() ) &&
( GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE )
|| GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) )
{
dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ;
}
else
{
dc.SetTextForeground( GetForegroundColour() ) ;
}
wxString paragraph;
size_t i = 0 ;
wxString text = m_label;
int y = 0 ;
while (i < text.Length())
{
if (text[i] == 13 || text[i] == 10)
{
DrawParagraph(dc, paragraph,y);
paragraph = wxEmptyString ;
}
else
{
paragraph += text[i];
}
++i;
}
if (paragraph.Length() > 0)
DrawParagraph(dc, paragraph,y);
}
void wxStaticText::OnPaint( wxPaintEvent & WXUNUSED(event) )
{
wxPaintDC dc(this);
OnDraw( dc ) ;
}
wxSize wxStaticText::DoGetBestSize() const
{
int widthTextMax = 0, widthLine,
heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
wxString curLine;
for ( const wxChar *pc = m_label; ; pc++ )
{
if ( *pc == wxT('\n') || *pc == wxT('\r') || *pc == wxT('\0') )
{
if ( !curLine )
{
// we can't use GetTextExtent - it will return 0 for both width
// and height and an empty line should count in height
// calculation
if ( !heightLineDefault )
heightLineDefault = heightLine;
if ( !heightLineDefault )
GetTextExtent(_T("W"), NULL, &heightLineDefault);
heightTextTotal += heightLineDefault;
heightTextTotal++; // FIXME: why is this necessary?
}
else
{
GetTextExtent(curLine, &widthLine, &heightLine);
if ( widthLine > widthTextMax )
widthTextMax = widthLine;
heightTextTotal += heightLine;
heightTextTotal++; // FIXME: why is this necessary?
}
if ( *pc == wxT('\n') || *pc == wxT('\r')) {
curLine.Empty();
}
else {
// the end of string
break;
}
}
else {
curLine += *pc;
}
}
return wxSize(widthTextMax, heightTextTotal);
}
void wxStaticText::SetLabel(const wxString& st )
{
SetTitle( st ) ;
m_label = st ;
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
{
// temporary fix until layout measurement and drawing are in synch again
Refresh() ;
SetSize( GetBestSize() ) ;
}
Refresh() ;
Update() ;
}
bool wxStaticText::SetFont(const wxFont& font)
{
bool ret = wxControl::SetFont(font);
if ( ret )
{
// adjust the size of the window to fit to the label unless autoresizing is
// disabled
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
{
// temporary fix until layout measurement and drawing are in synch again
Refresh() ;
SetSize( GetBestSize() );
}
}
return ret;
}

206
src/mac/classic/tabctrl.cpp Normal file
View File

@@ -0,0 +1,206 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tabctrl.cpp
// Purpose: wxTabCtrl
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "tabctrl.h"
#endif
#include "wx/defs.h"
#include "wx/control.h"
#include "wx/tabctrl.h"
#include "wx/mac/uma.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxTabCtrl, wxControl)
BEGIN_EVENT_TABLE(wxTabCtrl, wxControl)
END_EVENT_TABLE()
#endif
wxTabCtrl::wxTabCtrl()
{
m_imageList = NULL;
}
bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name)
{
if ( !wxControl::Create(parent, id, pos, size,
style, wxDefaultValidator, name) )
return false;
Rect bounds ;
Str255 title ;
m_imageList = NULL;
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
kControlTabSmallProc , (long) this ) ;
MacPostControlCreate() ;
return TRUE ;
}
wxTabCtrl::~wxTabCtrl()
{
}
void wxTabCtrl::Command(wxCommandEvent& event)
{
}
// Delete all items
bool wxTabCtrl::DeleteAllItems()
{
// TODO
return FALSE;
}
// Delete an item
bool wxTabCtrl::DeleteItem(int item)
{
// TODO
return FALSE;
}
// Get the selection
int wxTabCtrl::GetSelection() const
{
// TODO
return 0;
}
// Get the tab with the current keyboard focus
int wxTabCtrl::GetCurFocus() const
{
// TODO
return 0;
}
// Get the associated image list
wxImageList* wxTabCtrl::GetImageList() const
{
return m_imageList;
}
// Get the number of items
int wxTabCtrl::GetItemCount() const
{
// TODO
return 0;
}
// Get the rect corresponding to the tab
bool wxTabCtrl::GetItemRect(int item, wxRect& wxrect) const
{
// TODO
return FALSE;
}
// Get the number of rows
int wxTabCtrl::GetRowCount() const
{
// TODO
return 0;
}
// Get the item text
wxString wxTabCtrl::GetItemText(int item) const
{
// TODO
return wxEmptyString;
}
// Get the item image
int wxTabCtrl::GetItemImage(int item) const
{
// TODO
return 0;
}
// Get the item data
void* wxTabCtrl::GetItemData(int item) const
{
// TODO
return NULL;
}
// Hit test
int wxTabCtrl::HitTest(const wxPoint& pt, long& flags)
{
// TODO
return 0;
}
// Insert an item
bool wxTabCtrl::InsertItem(int item, const wxString& text, int imageId, void* data)
{
// TODO
return FALSE;
}
// Set the selection
int wxTabCtrl::SetSelection(int item)
{
// TODO
return 0;
}
// Set the image list
void wxTabCtrl::SetImageList(wxImageList* imageList)
{
// TODO
}
// Set the text for an item
bool wxTabCtrl::SetItemText(int item, const wxString& text)
{
// TODO
return FALSE;
}
// Set the image for an item
bool wxTabCtrl::SetItemImage(int item, int image)
{
// TODO
return FALSE;
}
// Set the data for an item
bool wxTabCtrl::SetItemData(int item, void* data)
{
// TODO
return FALSE;
}
// Set the size for a fixed-width tab control
void wxTabCtrl::SetItemSize(const wxSize& size)
{
// TODO
}
// Set the padding between tabs
void wxTabCtrl::SetPadding(const wxSize& padding)
{
// TODO
}
// Tab event
IMPLEMENT_DYNAMIC_CLASS(wxTabEvent, wxCommandEvent)
wxTabEvent::wxTabEvent(wxEventType commandType, int id):
wxCommandEvent(commandType, id)
{
}

1810
src/mac/classic/textctrl.cpp Normal file

File diff suppressed because it is too large Load Diff

127
src/mac/classic/tglbtn.cpp Normal file
View File

@@ -0,0 +1,127 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/mac/tglbtn.cpp
// Purpose: Definition of the wxToggleButton class, which implements a
// toggle button under wxMac.
// Author: Stefan Csomor
// Modified by:
// Created: 08.02.01
// RCS-ID: $Id$
// Copyright: (c) 2000 Johnny C. Norris II
// License: Rocketeer license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declatations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "button.h"
#endif
#include "wx/defs.h"
#include "wx/tglbtn.h"
#if wxUSE_TOGGLEBTN
#include "wx/mac/uma.h"
// Button
static const int kMacOSXHorizontalBorder = 2 ;
static const int kMacOSXVerticalBorder = 4 ;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxToggleButton
// ----------------------------------------------------------------------------
// Single check box item
bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
return false;
Rect bounds ;
Str255 title ;
if ( UMAHasAquaLayout() )
{
m_macHorizontalBorder = kMacOSXHorizontalBorder;
m_macVerticalBorder = kMacOSXVerticalBorder;
}
MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , kControlBehaviorToggles , 1,
kControlBevelButtonNormalBevelProc , (long) this ) ;
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
MacPostControlCreate() ;
return TRUE;
}
wxSize wxToggleButton::DoGetBestSize() const
{
int wBtn = 70 ;
int hBtn = 20 ;
int lBtn = m_label.Length() * 8 + 12 ;
if (lBtn > wBtn)
wBtn = lBtn;
if ( UMAHasAquaLayout() )
{
wBtn += 2 * kMacOSXHorizontalBorder ;
hBtn += 2 * kMacOSXVerticalBorder ;
}
return wxSize ( wBtn , hBtn ) ;
}
void wxToggleButton::SetValue(bool val)
{
::SetControl32BitValue( (ControlHandle) m_macControl , val ) ;
}
bool wxToggleButton::GetValue() const
{
return GetControl32BitValue( (ControlHandle) m_macControl ) ;
}
void wxToggleButton::Command(wxCommandEvent & event)
{
SetValue((event.GetInt() != 0));
ProcessCommand(event);
}
void wxToggleButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
{
if ( controlpart != kControlNoPart )
{
wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
event.SetInt(GetValue());
event.SetEventObject(this);
ProcessCommand(event);
}
}
#endif // wxUSE_TOGGLEBTN

921
src/mac/classic/thread.cpp Normal file
View File

@@ -0,0 +1,921 @@
/////////////////////////////////////////////////////////////////////////////
// Name: thread.cpp
// Purpose: wxThread Implementation
// Author: Original from Wolfram Gloger/Guilhem Lavaux/Vadim Zeitlin
// Modified by: Stefan Csomor
// Created: 04/22/98
// RCS-ID: $Id$
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998),
// Vadim Zeitlin (1999) , Stefan Csomor (2000)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "thread.h"
#endif
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#if defined(__BORLANDC__)
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#if wxUSE_THREADS
#include "wx/module.h"
#include "wx/thread.h"
#ifdef __WXMAC__
#include <Threads.h>
#include "wx/mac/uma.h"
#include "wx/mac/macnotfy.h"
#include <Timer.h>
#endif
#define INFINITE 0xFFFFFFFF
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// the possible states of the thread ("=>" shows all possible transitions from
// this state)
enum wxThreadState
{
STATE_NEW, // didn't start execution yet (=> RUNNING)
STATE_RUNNING, // thread is running (=> PAUSED, CANCELED)
STATE_PAUSED, // thread is temporarily suspended (=> RUNNING)
STATE_CANCELED, // thread should terminate a.s.a.p. (=> EXITED)
STATE_EXITED // thread is terminating
};
// ----------------------------------------------------------------------------
// this module globals
// ----------------------------------------------------------------------------
static ThreadID gs_idMainThread = kNoThreadID ;
static bool gs_waitingForThread = FALSE ;
size_t g_numberOfThreads = 0;
// ============================================================================
// MacOS implementation of thread classes
// ============================================================================
class wxMacStCritical
{
public :
wxMacStCritical()
{
if ( UMASystemIsInitialized() )
ThreadBeginCritical() ;
}
~wxMacStCritical()
{
if ( UMASystemIsInitialized() )
ThreadEndCritical() ;
}
};
// ----------------------------------------------------------------------------
// wxMutex implementation
// ----------------------------------------------------------------------------
class wxMutexInternal
{
public:
wxMutexInternal(wxMutexType WXUNUSED(mutexType))
{
m_owner = kNoThreadID ;
m_locked = 0;
}
~wxMutexInternal()
{
if ( m_locked > 0 )
{
wxLogDebug(_T("Warning: freeing a locked mutex (%ld locks)."), m_locked);
}
}
bool IsOk() const { return true; }
wxMutexError Lock() ;
wxMutexError TryLock() ;
wxMutexError Unlock();
public:
ThreadID m_owner ;
wxArrayLong m_waiters ;
long m_locked ;
};
wxMutexError wxMutexInternal::Lock()
{
wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
OSErr err ;
ThreadID current = kNoThreadID;
err = ::MacGetCurrentThread(&current);
// if we are not the owner, add this thread to the list of waiting threads, stop this thread
// and invoke the scheduler to continue executing the owner's thread
while ( m_owner != kNoThreadID && m_owner != current)
{
m_waiters.Add(current);
err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_owner);
err = ::ThreadBeginCritical();
}
m_owner = current;
}
m_locked++;
return wxMUTEX_NO_ERROR;
}
wxMutexError wxMutexInternal::TryLock()
{
wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
ThreadID current = kNoThreadID;
::MacGetCurrentThread(&current);
// if we are not the owner, give an error back
if ( m_owner != kNoThreadID && m_owner != current )
return wxMUTEX_BUSY;
m_owner = current;
}
m_locked++;
return wxMUTEX_NO_ERROR;
}
wxMutexError wxMutexInternal::Unlock()
{
if ( UMASystemIsInitialized() )
{
OSErr err;
err = ::ThreadBeginCritical();
if (m_locked > 0)
m_locked--;
// this mutex is not owned by anybody anmore
m_owner = kNoThreadID;
// now pass on to the first waiting thread
ThreadID firstWaiting = kNoThreadID;
bool found = false;
while (!m_waiters.IsEmpty() && !found)
{
firstWaiting = m_waiters[0];
err = ::SetThreadState(firstWaiting, kReadyThreadState, kNoThreadID);
// in case this was not successful (dead thread), we just loop on and reset the id
found = (err != threadNotFoundErr);
if ( !found )
firstWaiting = kNoThreadID ;
m_waiters.RemoveAt(0) ;
}
// now we have a valid firstWaiting thread, which has been scheduled to run next, just end the
// critical section and invoke the scheduler
err = ::SetThreadStateEndCritical(kCurrentThreadID, kReadyThreadState, firstWaiting);
}
else
{
if (m_locked > 0)
m_locked--;
}
return wxMUTEX_NO_ERROR;
}
// --------------------------------------------------------------------------
// wxSemaphore
// --------------------------------------------------------------------------
// TODO not yet implemented
class wxSemaphoreInternal
{
public:
wxSemaphoreInternal(int initialcount, int maxcount);
~wxSemaphoreInternal();
bool IsOk() const { return true ; }
wxSemaError Wait() { return WaitTimeout(INFINITE); }
wxSemaError TryWait() { return WaitTimeout(0); }
wxSemaError WaitTimeout(unsigned long milliseconds);
wxSemaError Post();
private:
};
wxSemaphoreInternal::wxSemaphoreInternal(int initialcount, int maxcount)
{
if ( maxcount == 0 )
{
// make it practically infinite
maxcount = INT_MAX;
}
}
wxSemaphoreInternal::~wxSemaphoreInternal()
{
}
wxSemaError wxSemaphoreInternal::WaitTimeout(unsigned long milliseconds)
{
return wxSEMA_MISC_ERROR;
}
wxSemaError wxSemaphoreInternal::Post()
{
return wxSEMA_MISC_ERROR;
}
// ----------------------------------------------------------------------------
// wxCondition implementation
// ----------------------------------------------------------------------------
// TODO this is not yet completed
class wxConditionInternal
{
public:
wxConditionInternal(wxMutex& mutex) : m_mutex(mutex)
{
m_excessSignals = 0 ;
}
~wxConditionInternal()
{
}
bool IsOk() const { return m_mutex.IsOk() ; }
wxCondError Wait()
{
return WaitTimeout(0xFFFFFFFF );
}
wxCondError WaitTimeout(unsigned long msectimeout)
{
wxMacStCritical critical ;
if ( m_excessSignals > 0 )
{
--m_excessSignals ;
return wxCOND_NO_ERROR ;
}
else if ( msectimeout == 0 )
{
return wxCOND_MISC_ERROR ;
}
else
{
}
/*
waiters++;
// FIXME this should be MsgWaitForMultipleObjects() as well probably
DWORD rc = ::WaitForSingleObject(event, timeout);
waiters--;
return rc != WAIT_TIMEOUT;
*/
return wxCOND_NO_ERROR ;
}
wxCondError Signal()
{
wxMacStCritical critical ;
return wxCOND_NO_ERROR;
}
wxCondError Broadcast()
{
wxMacStCritical critical ;
return wxCOND_NO_ERROR;
}
wxArrayLong m_waiters ;
wxInt32 m_excessSignals ;
wxMutex& m_mutex;
};
// ----------------------------------------------------------------------------
// wxCriticalSection implementation
// ----------------------------------------------------------------------------
// it's implemented as a mutex on mac os, so it is defined in the headers
// ----------------------------------------------------------------------------
// wxThread implementation
// ----------------------------------------------------------------------------
// wxThreadInternal class
// ----------------------
class wxThreadInternal
{
public:
wxThreadInternal()
{
m_tid = kNoThreadID ;
m_state = STATE_NEW;
m_priority = WXTHREAD_DEFAULT_PRIORITY;
}
~wxThreadInternal()
{
}
void Free()
{
}
// create a new (suspended) thread (for the given thread object)
bool Create(wxThread *thread, unsigned int stackSize);
// suspend/resume/terminate
bool Suspend();
bool Resume();
void Cancel() { m_state = STATE_CANCELED; }
// thread state
void SetState(wxThreadState state) { m_state = state; }
wxThreadState GetState() const { return m_state; }
// thread priority
void SetPriority(unsigned int priority);
unsigned int GetPriority() const { return m_priority; }
void SetResult( void *res ) { m_result = res ; }
void *GetResult() { return m_result ; }
// thread handle and id
ThreadID GetId() const { return m_tid; }
// thread function
static pascal void* MacThreadStart(wxThread* arg);
private:
wxThreadState m_state; // state, see wxThreadState enum
unsigned int m_priority; // thread priority in "wx" units
ThreadID m_tid; // thread id
void* m_result;
static ThreadEntryUPP s_threadEntry ;
};
static wxArrayPtrVoid s_threads ;
ThreadEntryUPP wxThreadInternal::s_threadEntry = NULL ;
pascal void* wxThreadInternal::MacThreadStart(wxThread *thread)
{
// first of all, check whether we hadn't been cancelled already
if ( thread->m_internal->GetState() == STATE_EXITED )
{
return (void*)-1;
}
void* rc = thread->Entry();
// enter m_critsect before changing the thread state
thread->m_critsect.Enter();
bool wasCancelled = thread->m_internal->GetState() == STATE_CANCELED;
thread->m_internal->SetState(STATE_EXITED);
thread->m_critsect.Leave();
thread->OnExit();
// if the thread was cancelled (from Delete()), then it the handle is still
// needed there
if ( thread->IsDetached() && !wasCancelled )
{
// auto delete
delete thread;
}
//else: the joinable threads handle will be closed when Wait() is done
return rc;
}
void wxThreadInternal::SetPriority(unsigned int priority)
{
// Priorities don't exist on Mac
}
bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize)
{
if ( s_threadEntry == NULL )
{
s_threadEntry = NewThreadEntryUPP( (ThreadEntryProcPtr) MacThreadStart ) ;
}
OSErr err = NewThread( kCooperativeThread,
s_threadEntry,
(void*) thread,
stackSize,
kNewSuspend,
&m_result,
&m_tid );
if ( err != noErr )
{
wxLogSysError(_("Can't create thread"));
return FALSE;
}
if ( m_priority != WXTHREAD_DEFAULT_PRIORITY )
{
SetPriority(m_priority);
}
m_state = STATE_NEW;
return TRUE;
}
bool wxThreadInternal::Suspend()
{
OSErr err ;
::ThreadBeginCritical();
if ( m_state != STATE_RUNNING )
{
::ThreadEndCritical() ;
wxLogSysError(_("Can not suspend thread %x"), m_tid);
return FALSE;
}
m_state = STATE_PAUSED;
err = ::SetThreadStateEndCritical(m_tid, kStoppedThreadState, kNoThreadID);
return TRUE;
}
bool wxThreadInternal::Resume()
{
ThreadID current ;
OSErr err ;
err = MacGetCurrentThread( &current ) ;
wxASSERT( err == noErr ) ;
wxASSERT( current != m_tid ) ;
::ThreadBeginCritical();
if ( m_state != STATE_PAUSED && m_state != STATE_NEW )
{
::ThreadEndCritical() ;
wxLogSysError(_("Can not resume thread %x"), m_tid);
return FALSE;
}
err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID);
wxASSERT( err == noErr ) ;
m_state = STATE_RUNNING;
::ThreadEndCritical() ;
::YieldToAnyThread() ;
return TRUE;
}
// static functions
// ----------------
wxThread *wxThread::This()
{
wxMacStCritical critical ;
ThreadID current ;
OSErr err ;
err = MacGetCurrentThread( &current ) ;
for ( size_t i = 0 ; i < s_threads.Count() ; ++i )
{
if ( ( (wxThread*) s_threads[i] )->GetId() == current )
return (wxThread*) s_threads[i] ;
}
wxLogSysError(_("Couldn't get the current thread pointer"));
return NULL;
}
bool wxThread::IsMain()
{
ThreadID current ;
OSErr err ;
err = MacGetCurrentThread( &current ) ;
return current == gs_idMainThread;
}
#ifdef Yield
#undef Yield
#endif
void wxThread::Yield()
{
::YieldToAnyThread() ;
}
void wxThread::Sleep(unsigned long milliseconds)
{
UnsignedWide start, now;
Microseconds(&start);
double mssleep = milliseconds * 1000 ;
double msstart, msnow ;
msstart = (start.hi * 4294967296.0 + start.lo) ;
do
{
YieldToAnyThread();
Microseconds(&now);
msnow = (now.hi * 4294967296.0 + now.lo) ;
} while( msnow - msstart < mssleep );
}
int wxThread::GetCPUCount()
{
// we will use whatever MP API will be used for the new MP Macs
return 1;
}
unsigned long wxThread::GetCurrentId()
{
ThreadID current ;
MacGetCurrentThread( &current ) ;
return (unsigned long)current;
}
bool wxThread::SetConcurrency(size_t level)
{
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
// ok only for the default one
if ( level == 0 )
return 0;
// how many CPUs have we got?
if ( GetCPUCount() == 1 )
{
// don't bother with all this complicated stuff - on a single
// processor system it doesn't make much sense anyhow
return level == 1;
}
return TRUE ;
}
// ctor and dtor
// -------------
wxThread::wxThread(wxThreadKind kind)
{
g_numberOfThreads++;
m_internal = new wxThreadInternal();
m_isDetached = kind == wxTHREAD_DETACHED;
s_threads.Add( (void*) this ) ;
}
wxThread::~wxThread()
{
if (g_numberOfThreads>0)
{
g_numberOfThreads--;
}
#ifdef __WXDEBUG__
else
{
wxFAIL_MSG(wxT("More threads deleted than created."));
}
#endif
s_threads.Remove( (void*) this ) ;
if (m_internal != NULL) {
delete m_internal;
m_internal = NULL;
}
}
// create/start thread
// -------------------
wxThreadError wxThread::Create(unsigned int stackSize)
{
wxCriticalSectionLocker lock(m_critsect);
if ( !m_internal->Create(this, stackSize) )
return wxTHREAD_NO_RESOURCE;
return wxTHREAD_NO_ERROR;
}
wxThreadError wxThread::Run()
{
wxCriticalSectionLocker lock(m_critsect);
if ( m_internal->GetState() != STATE_NEW )
{
// actually, it may be almost any state at all, not only STATE_RUNNING
return wxTHREAD_RUNNING;
}
// the thread has just been created and is still suspended - let it run
return Resume();
}
// suspend/resume thread
// ---------------------
wxThreadError wxThread::Pause()
{
wxCriticalSectionLocker lock(m_critsect);
return m_internal->Suspend() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR;
}
wxThreadError wxThread::Resume()
{
wxCriticalSectionLocker lock(m_critsect);
return m_internal->Resume() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR;
}
// stopping thread
// ---------------
wxThread::ExitCode wxThread::Wait()
{
// although under MacOS we can wait for any thread, it's an error to
// wait for a detached one in wxWin API
wxCHECK_MSG( !IsDetached(), (ExitCode)-1,
_T("can't wait for detached thread") );
ExitCode rc = (ExitCode)-1;
(void)Delete(&rc);
m_internal->Free();
return rc;
}
wxThreadError wxThread::Delete(ExitCode *pRc)
{
ExitCode rc = 0;
// Delete() is always safe to call, so consider all possible states
// has the thread started to run?
bool shouldResume = FALSE;
{
wxCriticalSectionLocker lock(m_critsect);
if ( m_internal->GetState() == STATE_NEW )
{
// WinThreadStart() will see it and terminate immediately
m_internal->SetState(STATE_EXITED);
shouldResume = TRUE;
}
}
// is the thread paused?
if ( shouldResume || IsPaused() )
Resume();
// does is still run?
if ( IsRunning() )
{
if ( IsMain() )
{
// set flag for wxIsWaitingForThread()
gs_waitingForThread = TRUE;
#if wxUSE_GUI
wxBeginBusyCursor();
#endif // wxUSE_GUI
}
// ask the thread to terminate
{
wxCriticalSectionLocker lock(m_critsect);
m_internal->Cancel();
}
#if wxUSE_GUI
// simply wait for the thread to terminate
while( TestDestroy() )
{
::YieldToAnyThread() ;
}
#else // !wxUSE_GUI
// simply wait for the thread to terminate
while( TestDestroy() )
{
::YieldToAnyThread() ;
}
#endif // wxUSE_GUI/!wxUSE_GUI
if ( IsMain() )
{
gs_waitingForThread = FALSE;
#if wxUSE_GUI
wxEndBusyCursor();
#endif // wxUSE_GUI
}
}
if ( IsDetached() )
{
// if the thread exits normally, this is done in WinThreadStart, but in
// this case it would have been too early because
// MsgWaitForMultipleObject() would fail if the therad handle was
// closed while we were waiting on it, so we must do it here
delete this;
}
if ( pRc )
*pRc = rc;
return rc == (ExitCode)-1 ? wxTHREAD_MISC_ERROR : wxTHREAD_NO_ERROR;
}
wxThreadError wxThread::Kill()
{
if ( !IsRunning() )
return wxTHREAD_NOT_RUNNING;
// if ( !::TerminateThread(m_internal->GetHandle(), (DWORD)-1) )
{
wxLogSysError(_("Couldn't terminate thread"));
return wxTHREAD_MISC_ERROR;
}
m_internal->Free();
if ( IsDetached() )
{
delete this;
}
return wxTHREAD_NO_ERROR;
}
void wxThread::Exit(ExitCode status)
{
m_internal->Free();
if ( IsDetached() )
{
delete this;
}
m_internal->SetResult( status ) ;
/*
#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500))
_endthreadex((unsigned)status);
#else // !VC++
::ExitThread((DWORD)status);
#endif // VC++/!VC++
*/
wxFAIL_MSG(wxT("Couldn't return from ExitThread()!"));
}
// priority setting
// ----------------
// since all these calls are execute cooperatively we don't have to use the critical section
void wxThread::SetPriority(unsigned int prio)
{
m_internal->SetPriority(prio);
}
unsigned int wxThread::GetPriority() const
{
return m_internal->GetPriority();
}
unsigned long wxThread::GetId() const
{
return (unsigned long)m_internal->GetId();
}
bool wxThread::IsRunning() const
{
return m_internal->GetState() == STATE_RUNNING;
}
bool wxThread::IsAlive() const
{
return (m_internal->GetState() == STATE_RUNNING) ||
(m_internal->GetState() == STATE_PAUSED);
}
bool wxThread::IsPaused() const
{
return m_internal->GetState() == STATE_PAUSED;
}
bool wxThread::TestDestroy()
{
return m_internal->GetState() == STATE_CANCELED;
}
// ----------------------------------------------------------------------------
// Automatic initialization for thread module
// ----------------------------------------------------------------------------
class wxThreadModule : public wxModule
{
public:
virtual bool OnInit();
virtual void OnExit();
private:
DECLARE_DYNAMIC_CLASS(wxThreadModule)
};
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
bool wxThreadModule::OnInit()
{
long response;
bool hasThreadManager ;
hasThreadManager = Gestalt( gestaltThreadMgrAttr, &response) == noErr && response & 1;
#if !TARGET_CARBON
#if GENERATINGCFM
// verify presence of shared library
hasThreadManager = hasThreadManager && ((Ptr)NewThread != (Ptr)kUnresolvedCFragSymbolAddress);
#endif
#endif
if ( !hasThreadManager )
{
wxLogSysError( wxT("Thread Support is not available on this System") );
return FALSE ;
}
// no error return for GetCurrentThreadId()
MacGetCurrentThread( &gs_idMainThread ) ;
return TRUE;
}
void wxThreadModule::OnExit()
{
}
// ----------------------------------------------------------------------------
// under MacOS we don't have currently preemptive threads, so any thread may access
// the GUI at any time
// ----------------------------------------------------------------------------
void WXDLLEXPORT wxMutexGuiEnter()
{
}
void WXDLLEXPORT wxMutexGuiLeave()
{
}
void WXDLLEXPORT wxMutexGuiLeaveOrEnter()
{
}
bool WXDLLEXPORT wxGuiOwnedByMainThread()
{
return false ;
}
// wake up the main thread
void WXDLLEXPORT wxWakeUpMainThread()
{
wxMacWakeUp() ;
}
bool WXDLLEXPORT wxIsWaitingForThread()
{
return false ;
}
#include "wx/thrimpl.cpp"
#endif // wxUSE_THREADS

143
src/mac/classic/timer.cpp Normal file
View File

@@ -0,0 +1,143 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.cpp
// Purpose: wxTimer implementation
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "timer.h"
#endif
#include "wx/timer.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
#endif
#ifdef __WXMAC__
#include "wx/mac/private.h"
#endif
#ifndef __DARWIN__
#include <Timer.h>
#endif
#include "wx/dynarray.h"
typedef struct MacTimerInfo
{
TMTask m_task;
wxMacNotifierTableRef m_table ;
wxTimer* m_timer ;
} ;
static void wxProcessTimer( unsigned long event , void *data ) ;
static pascal void MacTimerProc( TMTask * t )
{
MacTimerInfo * tm = (MacTimerInfo*) t ;
wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ;
}
// we need this array to track timers that are being deleted within the Notify procedure
// adding the timer before the Notify call and checking after whether it still is in there
// as the destructor would have removed it from the array
wxArrayPtrVoid gTimersInProcess ;
static void wxProcessTimer( unsigned long event , void *data )
{
if ( !data )
return ;
wxTimer* timer = (wxTimer*) data ;
if ( timer->IsOneShot() )
timer->Stop() ;
gTimersInProcess.Add( timer ) ;
timer->Notify();
int index = gTimersInProcess.Index( timer ) ;
if ( index != wxNOT_FOUND )
{
gTimersInProcess.RemoveAt( index ) ;
if ( !timer->IsOneShot() && timer->m_info->m_task.tmAddr )
{
PrimeTime( (QElemPtr) &timer->m_info->m_task , timer->GetInterval() ) ;
}
}
}
void wxTimer::Init()
{
m_info = new MacTimerInfo() ;
m_info->m_task.tmAddr = NULL ;
m_info->m_task.tmWakeUp = 0 ;
m_info->m_task.tmReserved = 0 ;
m_info->m_task.qType = 0 ;
m_info->m_table = wxMacGetNotifierTable() ;
m_info->m_timer = this ;
}
bool wxTimer::IsRunning() const
{
// as the qType may already indicate it is elapsed, but it
// was not handled internally yet
return ( m_info->m_task.tmAddr != NULL ) ;
}
wxTimer::~wxTimer()
{
Stop();
if (m_info != NULL) {
delete m_info ;
m_info = NULL ;
}
int index = gTimersInProcess.Index( this ) ;
if ( index != wxNOT_FOUND )
gTimersInProcess.RemoveAt( index ) ;
}
bool wxTimer::Start(int milliseconds,bool mode)
{
(void)wxTimerBase::Start(milliseconds, mode);
wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeout") );
wxCHECK_MSG( m_info->m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") );
#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
m_info->m_task.tmAddr = NewTimerUPP( MacTimerProc ) ;
#else
m_info->m_task.tmAddr = NewTimerProc( MacTimerProc ) ;
#endif
m_info->m_task.tmWakeUp = 0 ;
m_info->m_task.tmReserved = 0 ;
m_info->m_task.qType = 0 ;
m_info->m_timer = this ;
InsXTime((QElemPtr) &m_info->m_task ) ;
PrimeTime( (QElemPtr) &m_info->m_task , m_milli ) ;
return TRUE;
}
void wxTimer::Stop()
{
if ( m_info->m_task.tmAddr )
{
RmvTime( (QElemPtr) &m_info->m_task ) ;
DisposeTimerUPP(m_info->m_task.tmAddr) ;
m_info->m_task.tmAddr = NULL ;
}
wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;
}

620
src/mac/classic/toolbar.cpp Normal file
View File

@@ -0,0 +1,620 @@
/////////////////////////////////////////////////////////////////////////////
// Name: toolbar.cpp
// Purpose: wxToolBar
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: The wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "toolbar.h"
#endif
#include "wx/wx.h"
#if wxUSE_TOOLBAR
#include "wx/toolbar.h"
#include "wx/notebook.h"
#include "wx/tabctrl.h"
#include "wx/bitmap.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
EVT_MOUSE_EVENTS( wxToolBar::OnMouse )
EVT_PAINT( wxToolBar::OnPaint )
END_EVENT_TABLE()
#endif
#include "wx/mac/uma.h"
#include "wx/geometry.h"
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxToolBarTool : public wxToolBarToolBase
{
public:
wxToolBarTool(wxToolBar *tbar,
int id,
const wxString& label,
const wxBitmap& bmpNormal,
const wxBitmap& bmpDisabled,
wxItemKind kind,
wxObject *clientData,
const wxString& shortHelp,
const wxString& longHelp) ;
wxToolBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
Init() ;
}
~wxToolBarTool()
{
if ( m_controlHandle )
DisposeControl( m_controlHandle ) ;
}
ControlHandle GetControlHandle() { return m_controlHandle ; }
void SetControlHandle( ControlHandle handle ) { m_controlHandle = handle ; }
void SetSize(const wxSize& size) ;
void SetPosition( const wxPoint& position ) ;
wxSize GetSize() const
{
if ( IsControl() )
{
return GetControl()->GetSize() ;
}
else if ( IsButton() )
{
return GetToolBar()->GetToolSize() ;
}
else
{
wxSize sz = GetToolBar()->GetToolSize() ;
sz.x /= 4 ;
sz.y /= 4 ;
return sz ;
}
}
wxPoint GetPosition() const
{
return wxPoint(m_x, m_y);
}
private :
void Init()
{
m_controlHandle = NULL ;
}
ControlHandle m_controlHandle ;
wxCoord m_x;
wxCoord m_y;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxToolBarTool
// ----------------------------------------------------------------------------
void wxToolBarTool::SetSize(const wxSize& size)
{
if ( IsControl() )
{
GetControl()->SetSize( size ) ;
}
}
void wxToolBarTool::SetPosition(const wxPoint& position)
{
m_x = position.x;
m_y = position.y;
if ( IsButton() )
{
int x , y ;
x = y = 0 ;
WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetRootWindow() ;
GetToolBar()->MacWindowToRootWindow( &x , &y ) ;
int mac_x = x + position.x ;
int mac_y = y + position.y ;
Rect contrlRect ;
GetControlBounds( m_controlHandle , &contrlRect ) ;
int former_mac_x = contrlRect.left ;
int former_mac_y = contrlRect.top ;
wxSize sz = GetToolBar()->GetToolSize() ;
if ( mac_x != former_mac_x || mac_y != former_mac_y )
{
{
Rect inval = { former_mac_y , former_mac_x , former_mac_y + sz.y , former_mac_x + sz.x } ;
InvalWindowRect( rootwindow , &inval ) ;
}
UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
{
Rect inval = { mac_y , mac_x , mac_y + sz.y , mac_x + sz.x } ;
InvalWindowRect( rootwindow , &inval ) ;
}
}
}
else if ( IsControl() )
{
GetControl()->Move( position ) ;
}
}
const short kwxMacToolBarToolDefaultWidth = 24 ;
const short kwxMacToolBarToolDefaultHeight = 22 ;
const short kwxMacToolBarTopMargin = 2 ;
const short kwxMacToolBarLeftMargin = 2 ;
wxToolBarTool::wxToolBarTool(wxToolBar *tbar,
int id,
const wxString& label,
const wxBitmap& bmpNormal,
const wxBitmap& bmpDisabled,
wxItemKind kind,
wxObject *clientData,
const wxString& shortHelp,
const wxString& longHelp)
: wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
clientData, shortHelp, longHelp)
{
Init();
if (id == wxID_SEPARATOR) return;
WindowRef window = (WindowRef) tbar->MacGetRootWindow() ;
wxSize toolSize = tbar->GetToolSize() ;
Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ;
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , GetNormalBitmap() ) ;
SInt16 behaviour = kControlBehaviorOffsetContents ;
if ( CanBeToggled() )
behaviour += kControlBehaviorToggles ;
if ( info.contentType != kControlNoContent )
{
m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 ,
behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
::SetControlData( m_controlHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
}
else
{
m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 ,
behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
}
UMAShowControl( m_controlHandle ) ;
if ( !IsEnabled() )
{
UMADeactivateControl( m_controlHandle ) ;
}
if ( CanBeToggled() && IsToggled() )
{
::SetControl32BitValue( m_controlHandle , 1 ) ;
}
else
{
::SetControl32BitValue( m_controlHandle , 0 ) ;
}
ControlHandle container = (ControlHandle) tbar->MacGetContainerForEmbedding() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
::EmbedControl( m_controlHandle , container ) ;
}
wxToolBarToolBase *wxToolBar::CreateTool(int id,
const wxString& label,
const wxBitmap& bmpNormal,
const wxBitmap& bmpDisabled,
wxItemKind kind,
wxObject *clientData,
const wxString& shortHelp,
const wxString& longHelp)
{
return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
clientData, shortHelp, longHelp);
}
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
{
return new wxToolBarTool(this, control);
}
void wxToolBar::Init()
{
m_maxWidth = -1;
m_maxHeight = -1;
m_defaultWidth = kwxMacToolBarToolDefaultWidth;
m_defaultHeight = kwxMacToolBarToolDefaultHeight;
}
bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name)
{
int x = pos.x;
int y = pos.y;
int width = size.x;
int height = size.y;
if (width <= 0)
width = 100;
if (height <= 0)
height = 30;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
SetName(name);
m_windowStyle = style;
parent->AddChild(this);
m_backgroundColour = parent->GetBackgroundColour() ;
m_foregroundColour = parent->GetForegroundColour() ;
if (id == -1)
m_windowId = NewControlId();
else
m_windowId = id;
{
m_width = size.x ;
m_height = size.y ;
int x = pos.x ;
int y = pos.y ;
AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING);
m_x = x ;
m_y = y ;
}
return TRUE;
}
wxToolBar::~wxToolBar()
{
// we must refresh the frame size when the toolbar is deleted but the frame
// is not - otherwise toolbar leaves a hole in the place it used to occupy
}
bool wxToolBar::Realize()
{
if (m_tools.GetCount() == 0)
return FALSE;
int x = m_xMargin + kwxMacToolBarLeftMargin ;
int y = m_yMargin + kwxMacToolBarTopMargin ;
int tw, th;
GetSize(& tw, & th);
int maxWidth = 0 ;
int maxHeight = 0 ;
int maxToolWidth = 0;
int maxToolHeight = 0;
// Find the maximum tool width and height
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while ( node )
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
wxSize sz = tool->GetSize() ;
if ( sz.x > maxToolWidth )
maxToolWidth = sz.x ;
if (sz.y> maxToolHeight)
maxToolHeight = sz.y;
node = node->GetNext();
}
node = m_tools.GetFirst();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
wxSize cursize = tool->GetSize() ;
// for the moment we just do a single row/column alignement
if ( x + cursize.x > maxWidth )
maxWidth = x + cursize.x ;
if ( y + cursize.y > maxHeight )
maxHeight = y + cursize.y ;
tool->SetPosition( wxPoint( x , y ) ) ;
if ( GetWindowStyleFlag() & wxTB_VERTICAL )
{
y += cursize.y ;
}
else
{
x += cursize.x ;
}
node = node->GetNext();
}
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{
if ( m_maxRows == 0 )
{
// if not set yet, only one row
SetRows(1);
}
maxWidth = tw ;
maxHeight += m_yMargin + kwxMacToolBarTopMargin;
m_maxHeight = maxHeight ;
}
else
{
if ( GetToolsCount() > 0 && m_maxRows == 0 )
{
// if not set yet, have one column
SetRows(GetToolsCount());
}
maxHeight = th ;
maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
m_maxWidth = maxWidth ;
}
SetSize(maxWidth, maxHeight);
return TRUE;
}
void wxToolBar::SetToolBitmapSize(const wxSize& size)
{
m_defaultWidth = size.x+4; m_defaultHeight = size.y+4;
}
// The button size is bigger than the bitmap size
wxSize wxToolBar::GetToolSize() const
{
return wxSize(m_defaultWidth + 4, m_defaultHeight + 4);
}
void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
{
wxToolBarToolsList::Node *node;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ;
if ( tool->IsButton() )
{
if( tool->GetControlHandle() == control )
{
if ( tool->CanBeToggled() )
{
tool->Toggle( GetControl32BitValue( (ControlHandle) control ) ) ;
}
OnLeftClick( tool->GetId() , tool -> IsToggled() ) ;
break ;
}
}
}
}
void wxToolBar::SetRows(int nRows)
{
if ( nRows == m_maxRows )
{
// avoid resizing the frame uselessly
return;
}
m_maxRows = nRows;
}
void wxToolBar::MacSuperChangedPosition()
{
wxWindow::MacSuperChangedPosition() ;
Realize() ;
}
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
{
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ;
if ( r.Contains( wxPoint( x , y ) ) )
{
return tool;
}
node = node->GetNext();
}
return (wxToolBarToolBase *)NULL;
}
wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
{
wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
if ( tool )
{
return tool->GetShortHelp() ;
}
return wxEmptyString ;
}
void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
{
if (!IsShown())
return ;
wxToolBarTool *tool = (wxToolBarTool *)t;
if ( tool->IsControl() )
{
tool->GetControl()->Enable( enable ) ;
}
else if ( tool->IsButton() )
{
if ( enable )
UMAActivateControl( tool->GetControlHandle() ) ;
else
UMADeactivateControl( tool->GetControlHandle() ) ;
}
}
void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
{
if (!IsShown())
return ;
wxToolBarTool *tool = (wxToolBarTool *)t;
if ( tool->IsButton() )
{
::SetControl32BitValue( tool->GetControlHandle() , toggle ) ;
}
}
bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
wxToolBarToolBase *tool)
{
// nothing special to do here - we relayout in Realize() later
tool->Attach(this);
return TRUE;
}
void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
{
wxFAIL_MSG( _T("not implemented") );
}
bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
{
wxToolBarToolsList::Node *node;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarToolBase *tool2 = node->GetData();
if ( tool2 == tool )
{
// let node point to the next node in the list
node = node->GetNext();
break;
}
}
wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
tool->Detach();
// and finally reposition all the controls after this one
for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
{
wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
wxPoint pt = tool2->GetPosition() ;
if ( GetWindowStyleFlag() & wxTB_VERTICAL )
{
pt.y -= sz.y ;
}
else
{
pt.x -= sz.x ;
}
tool2->SetPosition( pt ) ;
}
return TRUE ;
}
void wxToolBar::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this) ;
wxMacPortSetter helper(&dc) ;
Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
dc.YLOG2DEVMAC(m_height) , dc.XLOG2DEVMAC(m_width) } ;
UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
{
wxToolBarToolsList::Node *node;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ;
if ( tool->IsButton() )
{
UMADrawControl( tool->GetControlHandle() ) ;
}
}
}
}
void wxToolBar::OnMouse( wxMouseEvent &event )
{
if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
{
int x = event.m_x ;
int y = event.m_y ;
MacClientToRootWindow( &x , &y ) ;
ControlHandle control ;
Point localwhere ;
SInt16 controlpart ;
WindowRef window = (WindowRef) MacGetRootWindow() ;
localwhere.h = x ;
localwhere.v = y ;
short modifiers = 0;
if ( !event.m_leftDown && !event.m_rightDown )
modifiers |= btnState ;
if ( event.m_shiftDown )
modifiers |= shiftKey ;
if ( event.m_controlDown )
modifiers |= controlKey ;
if ( event.m_altDown )
modifiers |= optionKey ;
if ( event.m_metaDown )
modifiers |= cmdKey ;
controlpart = ::FindControl( localwhere , window , &control ) ;
{
if ( control && ::IsControlActive( control ) )
{
{
controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
wxTheApp->s_lastMouseDown = 0 ;
if ( control && controlpart != kControlNoPart ) // otherwise we will get the event twice
{
MacHandleControlClick( control , controlpart , false /* not down anymore */ ) ;
}
}
}
}
}
}
#endif // wxUSE_TOOLBAR

408
src/mac/classic/tooltip.cpp Normal file
View File

@@ -0,0 +1,408 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tooltip.cpp
// Purpose: wxToolTip implementation
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "tooltip.h"
#endif
#include "wx/defs.h"
#if wxUSE_TOOLTIPS
#include "wx/app.h"
#include "wx/dc.h"
#include "wx/window.h"
#include "wx/tooltip.h"
#include "wx/timer.h"
#include "wx/geometry.h"
#include "wx/mac/uma.h"
//-----------------------------------------------------------------------------
// global data
//-----------------------------------------------------------------------------
class wxMacToolTipTimer ;
class wxMacToolTip
{
public :
wxMacToolTip( ) ;
~wxMacToolTip() ;
void Setup( WindowRef window , const wxString& text , wxPoint localPosition ) ;
long GetMark() { return m_mark ; }
void Draw() ;
void Clear() ;
bool IsShown() { return m_shown ; }
private :
wxString m_label ;
wxPoint m_position ;
Rect m_rect ;
WindowRef m_window ;
PicHandle m_backpict ;
bool m_shown ;
long m_mark ;
wxMacToolTipTimer* m_timer ;
#if TARGET_CARBON
wxMacCFStringHolder m_helpTextRef ;
#endif
} ;
class wxMacToolTipTimer : public wxTimer
{
public:
wxMacToolTipTimer() {} ;
wxMacToolTipTimer(wxMacToolTip* tip, int iMilliseconds) ;
virtual ~wxMacToolTipTimer() {} ;
void Notify()
{
if ( m_mark == m_tip->GetMark() )
m_tip->Draw() ;
}
protected:
wxMacToolTip* m_tip;
long m_mark ;
};
//-----------------------------------------------------------------------------
// wxToolTip
//-----------------------------------------------------------------------------
static long s_ToolTipDelay = 500 ;
static bool s_ShowToolTips = true ;
static wxMacToolTip s_ToolTip ;
static wxWindow* s_LastWindowEntered = NULL ;
static wxRect2DInt s_ToolTipArea ;
static WindowRef s_ToolTipWindowRef = NULL ;
IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
wxToolTip::wxToolTip( const wxString &tip )
{
m_text = tip;
m_window = (wxWindow*) NULL;
}
wxToolTip::~wxToolTip()
{
}
void wxToolTip::SetTip( const wxString &tip )
{
m_text = tip;
if ( m_window )
{
/*
// update it immediately
wxToolInfo ti(GetHwndOf(m_window));
ti.lpszText = (wxChar *)m_text.c_str();
(void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
*/
}
}
void wxToolTip::SetWindow( wxWindow *win )
{
m_window = win ;
}
void wxToolTip::Enable( bool flag )
{
if ( s_ShowToolTips != flag )
{
s_ShowToolTips = flag ;
if ( s_ShowToolTips )
{
}
else
{
s_ToolTip.Clear() ;
}
}
}
void wxToolTip::SetDelay( long msecs )
{
s_ToolTipDelay = msecs ;
}
void wxToolTip::RelayEvent( wxWindow *win , wxMouseEvent &event )
{
if ( s_ShowToolTips )
{
if ( event.GetEventType() == wxEVT_LEAVE_WINDOW )
{
s_ToolTip.Clear() ;
}
else if (event.GetEventType() == wxEVT_ENTER_WINDOW || event.GetEventType() == wxEVT_MOTION )
{
wxPoint2DInt where( event.m_x , event.m_y ) ;
if ( s_LastWindowEntered == win && s_ToolTipArea.Contains( where ) )
{
}
else
{
s_ToolTip.Clear() ;
s_ToolTipArea = wxRect2DInt( event.m_x - 2 , event.m_y - 2 , 4 , 4 ) ;
s_LastWindowEntered = win ;
WindowRef window = MAC_WXHWND( win->MacGetRootWindow() ) ;
int x = event.m_x ;
int y = event.m_y ;
wxPoint local( x , y ) ;
win->MacClientToRootWindow( &x, &y ) ;
wxPoint windowlocal( x , y ) ;
s_ToolTip.Setup( window , win->MacGetToolTipString( local ) , windowlocal ) ;
}
}
}
}
void wxToolTip::RemoveToolTips()
{
s_ToolTip.Clear() ;
}
// --- mac specific
wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip *tip , int msec )
{
m_tip = tip;
m_mark = tip->GetMark() ;
Start(msec, true);
}
wxMacToolTip::wxMacToolTip()
{
m_window = NULL ;
m_backpict = NULL ;
m_mark = 0 ;
m_shown = false ;
m_timer = NULL ;
}
void wxMacToolTip::Setup( WindowRef win , const wxString& text , wxPoint localPosition )
{
m_mark++ ;
Clear() ;
m_position = localPosition ;
m_label = text ;
m_window =win;
s_ToolTipWindowRef = m_window ;
m_backpict = NULL ;
if ( m_timer )
delete m_timer ;
m_timer = new wxMacToolTipTimer( this , s_ToolTipDelay ) ;
}
wxMacToolTip::~wxMacToolTip()
{
if ( m_timer ) {
delete m_timer ;
m_timer = NULL;
}
if ( m_backpict )
Clear() ;
}
const short kTipBorder = 2 ;
const short kTipOffset = 5 ;
void wxMacToolTip::Draw()
{
if ( m_label.Length() == 0 )
return ;
if ( m_window == s_ToolTipWindowRef )
{
m_shown = true ;
#if TARGET_CARBON
HMHelpContentRec tag ;
tag.version = kMacHelpVersion;
SetRect( &tag.absHotRect , m_position.x - 2 , m_position.y - 2 , m_position.x + 2 , m_position.y + 2 ) ;
GrafPtr port ;
GetPort( &port ) ;
SetPortWindowPort(m_window) ;
LocalToGlobal( (Point *) &tag.absHotRect.top );
LocalToGlobal( (Point *) &tag.absHotRect.bottom );
SetPort( port );
m_helpTextRef.Assign( m_label , wxFONTENCODING_DEFAULT ) ;
tag.content[kHMMinimumContentIndex].contentType = kHMCFStringContent ;
tag.content[kHMMinimumContentIndex].u.tagCFString = m_helpTextRef ;
tag.content[kHMMaximumContentIndex].contentType = kHMCFStringContent ;
tag.content[kHMMaximumContentIndex].u.tagCFString = m_helpTextRef ;
tag.tagSide = kHMDefaultSide;
HMDisplayTag( &tag );
#else
wxMacPortStateHelper help( (GrafPtr) GetWindowPort( m_window ) );
FontFamilyID fontId ;
Str255 fontName ;
SInt16 fontSize ;
Style fontStyle ;
GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
GetFNum( fontName, &fontId );
TextFont( fontId ) ;
TextSize( fontSize ) ;
TextFace( fontStyle ) ;
FontInfo fontInfo;
::GetFontInfo(&fontInfo);
short lineh = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
short height = 0 ;
int i = 0 ;
int length = m_label.Length() ;
int width = 0 ;
int thiswidth = 0 ;
int laststop = 0 ;
wxCharBuffer text = m_label.mb_str( wxConvLocal) ;
while( i < length )
{
if( text[i] == 13 || text[i] == 10)
{
thiswidth = ::TextWidth( text , laststop , i - laststop ) ;
if ( thiswidth > width )
width = thiswidth ;
height += lineh ;
laststop = i+1 ;
}
i++ ;
}
if ( i - laststop > 0 )
{
thiswidth = ::TextWidth( text , laststop , i - laststop ) ;
if ( thiswidth > width )
width = thiswidth ;
height += lineh ;
}
m_rect.left = m_position.x + kTipOffset;
m_rect.top = m_position.y + kTipOffset;
m_rect.right = m_rect.left + width + 2 * kTipBorder;
m_rect.bottom = m_rect.top + height + 2 * kTipBorder;
Rect r ;
GetPortBounds( GetWindowPort( m_window ) , &r ) ;
if ( m_rect.top < 0 )
{
m_rect.bottom += -m_rect.top ;
m_rect.top = 0 ;
}
if ( m_rect.left < 0 )
{
m_rect.right += -m_rect.left ;
m_rect.left = 0 ;
}
if ( m_rect.right > r.right )
{
m_rect.left -= (m_rect.right - r.right ) ;
m_rect.right = r.right ;
}
if ( m_rect.bottom > r.bottom )
{
m_rect.top -= (m_rect.bottom - r.bottom) ;
m_rect.bottom = r.bottom ;
}
ClipRect( &m_rect ) ;
BackColor( whiteColor ) ;
ForeColor(blackColor ) ;
GWorldPtr port ;
NewGWorld( &port , wxDisplayDepth() , &m_rect , NULL , NULL , 0 ) ;
CGrafPtr origPort ;
GDHandle origDevice ;
GetGWorld( &origPort , &origDevice ) ;
SetGWorld( port , NULL ) ;
m_backpict = OpenPicture(&m_rect);
CopyBits(GetPortBitMapForCopyBits(GetWindowPort(m_window)),
GetPortBitMapForCopyBits(port),
&m_rect,
&m_rect,
srcCopy,
NULL);
ClosePicture();
SetGWorld( origPort , origDevice ) ;
DisposeGWorld( port ) ;
PenNormal() ;
RGBColor tooltipbackground = { 0xFFFF , 0xFFFF , 0xC000 } ;
BackColor( whiteColor ) ;
RGBForeColor( &tooltipbackground ) ;
PaintRect( &m_rect ) ;
ForeColor(blackColor ) ;
FrameRect( &m_rect ) ;
SetThemeTextColor(kThemeTextColorNotification,wxDisplayDepth(),true) ;
::MoveTo( m_rect.left + kTipBorder , m_rect.top + fontInfo.ascent + kTipBorder);
i = 0 ;
laststop = 0 ;
height = 0 ;
while( i < length )
{
if( text[i] == 13 || text[i] == 10)
{
::DrawText( text , laststop , i - laststop ) ;
height += lineh ;
::MoveTo( m_rect.left + kTipBorder , m_rect.top + fontInfo.ascent + kTipBorder + height );
laststop = i+1 ;
}
i++ ;
}
::DrawText( text , laststop , i - laststop ) ;
::TextMode( srcOr ) ;
#endif
}
}
void wxToolTip::NotifyWindowDelete( WXHWND win )
{
if ( win == s_ToolTipWindowRef )
{
s_ToolTipWindowRef = NULL ;
}
}
void wxMacToolTip::Clear()
{
m_mark++ ;
if ( m_timer )
{
delete m_timer ;
m_timer = NULL ;
}
if ( !m_shown )
return ;
#if TARGET_CARBON
HMHideTag() ;
m_helpTextRef.Release() ;
#else
if ( m_window == s_ToolTipWindowRef && m_backpict )
{
wxMacPortStateHelper help( (GrafPtr) GetWindowPort(m_window) ) ;
m_shown = false ;
BackColor( whiteColor ) ;
ForeColor(blackColor ) ;
DrawPicture(m_backpict, &m_rect);
KillPicture(m_backpict);
m_backpict = NULL ;
}
#endif
}
#endif

1463
src/mac/classic/toplevel.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,419 @@
/////////////////////////////////////////////////////////////////////////////
// Name: treectrl.cpp
// Purpose: wxTreeCtrl. See also Robert's generic wxTreeCtrl.
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "treectrl.h"
#endif
#include "wx/stubs/textctrl.h"
#include "wx/treebase.h"
#include "wx/stubs/treectrl.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject)
#endif
wxTreeCtrl::wxTreeCtrl()
{
m_imageListNormal = NULL;
m_imageListState = NULL;
m_textCtrl = NULL;
}
bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxValidator& validator, const wxString& name)
{
SetName(name);
SetValidator(validator);
m_imageListNormal = NULL;
m_imageListState = NULL;
m_textCtrl = NULL;
m_windowStyle = style;
SetParent(parent);
m_windowId = (id == -1) ? NewControlId() : id;
if (parent) parent->AddChild(this);
// TODO create tree control
return FALSE;
}
wxTreeCtrl::~wxTreeCtrl()
{
if (m_textCtrl)
{
delete m_textCtrl;
}
}
// Attributes
int wxTreeCtrl::GetCount() const
{
// TODO
return 0;
}
int wxTreeCtrl::GetIndent() const
{
// TODO
return 0;
}
void wxTreeCtrl::SetIndent(int indent)
{
// TODO
}
wxImageList *wxTreeCtrl::GetImageList(int which) const
{
if ( which == wxIMAGE_LIST_NORMAL )
{
return m_imageListNormal;
}
else if ( which == wxIMAGE_LIST_STATE )
{
return m_imageListState;
}
return NULL;
}
void wxTreeCtrl::SetImageList(wxImageList *imageList, int which)
{
if ( which == wxIMAGE_LIST_NORMAL )
{
m_imageListNormal = imageList;
}
else if ( which == wxIMAGE_LIST_STATE )
{
m_imageListState = imageList;
}
// TODO
}
long wxTreeCtrl::GetNextItem(long item, int code) const
{
// TODO
return 0;
}
bool wxTreeCtrl::ItemHasChildren(long item) const
{
// TODO
return FALSE;
}
long wxTreeCtrl::GetChild(long item) const
{
// TODO
return 0;
}
long wxTreeCtrl::GetItemParent(long item) const
{
// TODO
return 0;
}
long wxTreeCtrl::GetFirstVisibleItem() const
{
// TODO
return 0;
}
long wxTreeCtrl::GetNextVisibleItem(long item) const
{
// TODO
return 0;
}
long wxTreeCtrl::GetSelection() const
{
// TODO
return 0;
}
long wxTreeCtrl::GetRootItem() const
{
// TODO
return 0;
}
bool wxTreeCtrl::GetItem(wxTreeItem& info) const
{
// TODO
return FALSE;
}
bool wxTreeCtrl::SetItem(wxTreeItem& info)
{
// TODO
return FALSE;
}
int wxTreeCtrl::GetItemState(long item, long stateMask) const
{
wxTreeItem info;
info.m_mask = wxTREE_MASK_STATE ;
info.m_stateMask = stateMask;
info.m_itemId = item;
if (!GetItem(info))
return 0;
return info.m_state;
}
bool wxTreeCtrl::SetItemState(long item, long state, long stateMask)
{
wxTreeItem info;
info.m_mask = wxTREE_MASK_STATE ;
info.m_state = state;
info.m_stateMask = stateMask;
info.m_itemId = item;
return SetItem(info);
}
bool wxTreeCtrl::SetItemImage(long item, int image, int selImage)
{
wxTreeItem info;
info.m_mask = wxTREE_MASK_IMAGE ;
info.m_image = image;
if ( selImage > -1)
{
info.m_selectedImage = selImage;
info.m_mask |= wxTREE_MASK_SELECTED_IMAGE;
}
info.m_itemId = item;
return SetItem(info);
}
wxString wxTreeCtrl::GetItemText(long item) const
{
wxTreeItem info;
info.m_mask = wxTREE_MASK_TEXT ;
info.m_itemId = item;
if (!GetItem(info))
return wxString("");
return info.m_text;
}
void wxTreeCtrl::SetItemText(long item, const wxString& str)
{
wxTreeItem info;
info.m_mask = wxTREE_MASK_TEXT ;
info.m_itemId = item;
info.m_text = str;
SetItem(info);
}
long wxTreeCtrl::GetItemData(long item) const
{
wxTreeItem info;
info.m_mask = wxTREE_MASK_DATA ;
info.m_itemId = item;
if (!GetItem(info))
return 0;
return info.m_data;
}
bool wxTreeCtrl::SetItemData(long item, long data)
{
wxTreeItem info;
info.m_mask = wxTREE_MASK_DATA ;
info.m_itemId = item;
info.m_data = data;
return SetItem(info);
}
bool wxTreeCtrl::GetItemRect(long item, wxRect& rect, bool textOnly) const
{
// TODO
return FALSE;
}
wxTextCtrl* wxTreeCtrl::GetEditControl() const
{
return m_textCtrl;
}
// Operations
bool wxTreeCtrl::DeleteItem(long item)
{
// TODO
return FALSE;
}
bool wxTreeCtrl::ExpandItem(long item, int action)
{
// TODO
switch ( action )
{
case wxTREE_EXPAND_EXPAND:
break;
case wxTREE_EXPAND_COLLAPSE:
break;
case wxTREE_EXPAND_COLLAPSE_RESET:
break;
case wxTREE_EXPAND_TOGGLE:
break;
default:
wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
}
bool bOk = FALSE; // TODO expand item
// May not send messages, so emulate them
if ( bOk ) {
wxTreeEvent event(wxEVT_NULL, m_windowId);
event.m_item.m_itemId = item;
event.m_item.m_mask =
event.m_item.m_stateMask = 0xffff; // get all
GetItem(event.m_item);
bool bIsExpanded = (event.m_item.m_state & wxTREE_STATE_EXPANDED) != 0;
event.m_code = action;
event.SetEventObject(this);
// @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
event.SetEventType(bIsExpanded ? wxEVT_COMMAND_TREE_ITEM_EXPANDING
: wxEVT_COMMAND_TREE_ITEM_COLLAPSING);
GetEventHandler()->ProcessEvent(event);
event.SetEventType(bIsExpanded ? wxEVT_COMMAND_TREE_ITEM_EXPANDED
: wxEVT_COMMAND_TREE_ITEM_COLLAPSED);
GetEventHandler()->ProcessEvent(event);
}
return bOk;
}
long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter)
{
// TODO
return 0;
}
long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image, int selImage,
long insertAfter)
{
wxTreeItem info;
info.m_text = label;
info.m_mask = wxTREE_MASK_TEXT;
if ( image > -1 )
{
info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
info.m_image = image;
if ( selImage == -1 )
info.m_selectedImage = image;
else
info.m_selectedImage = selImage;
}
return InsertItem(parent, info, insertAfter);
}
bool wxTreeCtrl::SelectItem(long item)
{
// TODO
return FALSE;
}
bool wxTreeCtrl::ScrollTo(long item)
{
// TODO
return FALSE;
}
bool wxTreeCtrl::DeleteAllItems()
{
// TODO
return FALSE;
}
wxTextCtrl* wxTreeCtrl::EditLabel(long item, wxClassInfo* textControlClass)
{
// TODO
return NULL;
}
// End label editing, optionally cancelling the edit
bool wxTreeCtrl::EndEditLabel(bool cancel)
{
// TODO
return FALSE;
}
long wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
{
// TODO
return 0;
}
bool wxTreeCtrl::SortChildren(long item)
{
// TODO
return FALSE;
}
bool wxTreeCtrl::EnsureVisible(long item)
{
// TODO
return FALSE;
}
// Tree item structure
wxTreeItem::wxTreeItem()
{
m_mask = 0;
m_itemId = 0;
m_state = 0;
m_stateMask = 0;
m_image = -1;
m_selectedImage = -1;
m_children = 0;
m_data = 0;
}
// Tree event
IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
wxTreeEvent::wxTreeEvent(wxEventType commandType, int id):
wxCommandEvent(commandType, id)
{
m_code = 0;
m_oldItem = 0;
}

815
src/mac/classic/uma.cpp Normal file
View File

@@ -0,0 +1,815 @@
/////////////////////////////////////////////////////////////////////////////
// Name: uma.cpp
// Purpose: UMA support
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: The wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/defs.h"
#if wxUSE_GUI
#include "wx/dc.h"
#include <MacTextEditor.h>
#ifndef __DARWIN__
# include <Navigation.h>
# if defined(TARGET_CARBON)
# if PM_USE_SESSION_APIS
# include <PMCore.h>
# endif
# include <PMApplication.h>
# else
# include <Printing.h>
# endif
#endif
#ifndef __DARWIN__
#include <Scrap.h>
#endif
#include "wx/mac/uma.h"
// since we have decided that we only support 8.6 upwards we are
// checking for these minimum requirements in the startup code of
// the application so all wxWindows code can safely assume that appearance 1.1
// windows manager, control manager, navigation services etc. are
// present
static bool sUMAHasAppearance = false ;
static long sUMAAppearanceVersion = 0 ;
static long sUMASystemVersion = 0 ;
static bool sUMAHasAquaLayout = false ;
static bool sUMAHasInittedAppearance = false;
extern int gAGABackgroundColor ;
bool UMAHasAppearance() { return sUMAHasAppearance ; }
long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
long UMAGetSystemVersion() { return sUMASystemVersion ; }
static bool sUMAHasWindowManager = false ;
static long sUMAWindowManagerAttr = 0 ;
bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; }
void UMACleanupToolbox()
{
if (sUMAHasInittedAppearance)
{
UnregisterAppearanceClient() ;
}
if ( NavServicesAvailable() )
{
NavUnload() ;
}
if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress )
TXNTerminateTextension( ) ;
}
void UMAInitToolbox( UInt16 inMoreMastersCalls, bool isEmbedded )
{
#if !TARGET_CARBON
::MaxApplZone();
for (long i = 1; i <= inMoreMastersCalls; i++)
::MoreMasters();
if (!isEmbedded)
{
::InitGraf(&qd.thePort);
::InitFonts();
::InitMenus();
::TEInit();
::InitDialogs(0L);
::FlushEvents(everyEvent, 0);
}
long total,contig;
PurgeSpace(&total, &contig);
#endif
::InitCursor();
if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr)
sUMASystemVersion = 0x0000 ;
long theAppearance ;
if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
{
sUMAHasAppearance = true ;
OSStatus status = RegisterAppearanceClient();
// If status equals appearanceProcessRegisteredErr it means the
// appearance client already was registered (For example if we run
// embedded, the host might have registered it). In such a case
// we don't unregister it later on.
if (status != appearanceProcessRegisteredErr)
{
// Appearance client wasn't registered yet.
sUMAHasInittedAppearance = true;
}
if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
{
sUMAAppearanceVersion = theAppearance ;
}
else
{
sUMAAppearanceVersion = 0x0100 ;
}
}
if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr )
{
sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ;
}
#if TARGET_CARBON
// Call currently implicitely done : InitFloatingWindows() ;
#else
if (!isEmbedded)
{
if ( sUMAHasWindowManager )
InitFloatingWindows() ;
else
InitWindows();
}
#endif
if ( NavServicesAvailable() )
{
NavLoad() ;
}
long menuMgrAttr ;
Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ;
if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask )
sUMAHasAquaLayout = true ;
if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress )
{
FontFamilyID fontId ;
Str255 fontName ;
SInt16 fontSize ;
Style fontStyle ;
GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
GetFNum( fontName, &fontId );
TXNMacOSPreferredFontDescription fontDescriptions[] =
{
{ fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding }
} ;
int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ;
// kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke
#if 0
// leads to unexpected content for clients, TODO configurable
OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ;
#else
OptionBits options = 0 ;
#endif
#if TARGET_CARBON
if ( !UMAHasAquaLayout() )
#endif
{
options |= kTXNAlwaysUseQuickDrawTextMask ;
}
TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
}
UMASetSystemIsInitialized(true);
}
/*
Boolean CanUseATSUI()
{
long result;
OSErr err = Gestalt(gestaltATSUVersion, &result);
return (err == noErr);
}
*/
// 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
MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
{
wxString str = wxStripMenuCodes( title ) ;
MenuRef menu ;
#if TARGET_CARBON
CreateNewMenu( id , 0 , &menu ) ;
SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ;
#else
Str255 ptitle ;
wxMacStringToPascal( str , ptitle ) ;
menu = ::NewMenu( id , ptitle ) ;
#endif
return menu ;
}
void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding)
{
wxString str = wxStripMenuCodes( title ) ;
#if TARGET_CARBON
SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ;
#else
Str255 ptitle ;
wxMacStringToPascal( str , ptitle ) ;
SetMenuTitle( menu , ptitle ) ;
#endif
}
void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title , wxFontEncoding encoding)
{
wxString str = wxStripMenuCodes( title ) ;
#if TARGET_CARBON
SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
#else
Str255 ptitle ;
wxMacStringToPascal( str , ptitle ) ;
SetMenuItemText( menu , item , ptitle ) ;
#endif
}
UInt32 UMAMenuEvent( EventRecord *inEvent )
{
return MenuEvent( inEvent ) ;
}
void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
{
if ( enable )
EnableMenuItem( inMenu , inItem ) ;
else
DisableMenuItem( inMenu , inItem ) ;
}
void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
{
MacAppendMenu(menu, "\pA");
UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
}
void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
{
MacInsertMenuItem(menu, "\pA" , item);
UMASetMenuItemText(menu, item , title , encoding);
SetMenuItemHierarchicalID( menu , item , id ) ;
}
void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
{
if ( !entry )
return ;
UInt8 modifiers = 0 ;
SInt16 key = entry->GetKeyCode() ;
if ( key )
{
bool explicitCommandKey = false ;
if ( entry->GetFlags() & wxACCEL_CTRL )
{
explicitCommandKey = true ;
}
if (entry->GetFlags() & wxACCEL_ALT )
{
modifiers |= kMenuOptionModifier ;
}
if (entry->GetFlags() & wxACCEL_SHIFT)
{
modifiers |= kMenuShiftModifier ;
}
SInt16 glyph = 0 ;
SInt16 macKey = key ;
if ( key >= WXK_F1 && key <= WXK_F15 )
{
// for some reasons this must be 0 right now
// everything else leads to just the first function key item
// to be selected. Thanks to Ryan Wilcox for finding out.
macKey = 0 ;
glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
if ( key >= WXK_F13 )
glyph += 13 ;
if ( !explicitCommandKey )
modifiers |= kMenuNoCommandModifier ;
}
else
{
switch( key )
{
case WXK_BACK :
macKey = kBackspaceCharCode ;
glyph = kMenuDeleteLeftGlyph ;
break ;
case WXK_TAB :
macKey = kTabCharCode ;
glyph = kMenuTabRightGlyph ;
break ;
case kEnterCharCode :
macKey = kEnterCharCode ;
glyph = kMenuEnterGlyph ;
break ;
case WXK_RETURN :
macKey = kReturnCharCode ;
glyph = kMenuReturnGlyph ;
break ;
case WXK_ESCAPE :
macKey = kEscapeCharCode ;
glyph = kMenuEscapeGlyph ;
break ;
case WXK_SPACE :
macKey = ' ' ;
glyph = kMenuSpaceGlyph ;
break ;
case WXK_DELETE :
macKey = kDeleteCharCode ;
glyph = kMenuDeleteRightGlyph ;
break ;
case WXK_CLEAR :
macKey = kClearCharCode ;
glyph = kMenuClearGlyph ;
break ;
case WXK_PRIOR : // PAGE UP
macKey = kPageUpCharCode ;
glyph = kMenuPageUpGlyph ;
break ;
case WXK_NEXT :
macKey = kPageDownCharCode ;
glyph = kMenuPageDownGlyph ;
break ;
case WXK_LEFT :
macKey = kLeftArrowCharCode ;
glyph = kMenuLeftArrowGlyph ;
break ;
case WXK_UP :
macKey = kUpArrowCharCode ;
glyph = kMenuUpArrowGlyph ;
break ;
case WXK_RIGHT :
macKey = kRightArrowCharCode ;
glyph = kMenuRightArrowGlyph ;
break ;
case WXK_DOWN :
macKey = kDownArrowCharCode ;
glyph = kMenuDownArrowGlyph ;
break ;
}
}
SetItemCmd( menu, item , macKey );
SetMenuItemModifiers(menu, item , modifiers ) ;
if ( glyph )
SetMenuItemKeyGlyph(menu, item , glyph ) ;
}
}
void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
{
MacAppendMenu(menu, "\pA");
UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
}
void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
{
MacInsertMenuItem( menu , "\pA" , item) ;
UMASetMenuItemText(menu, item+1 , title , encoding );
UMASetMenuItemShortcut( menu , item+1 , entry ) ;
}
// quickdraw
#if !TARGET_CARBON
int gPrOpenCounter = 0 ;
OSStatus UMAPrOpen()
{
OSErr err = noErr ;
++gPrOpenCounter ;
if ( gPrOpenCounter == 1 )
{
PrOpen() ;
err = PrError() ;
wxASSERT( err == noErr ) ;
}
return err ;
}
OSStatus UMAPrClose()
{
OSErr err = noErr ;
wxASSERT( gPrOpenCounter >= 1 ) ;
if ( gPrOpenCounter == 1 )
{
PrClose() ;
err = PrError() ;
wxASSERT( err == noErr ) ;
}
--gPrOpenCounter ;
return err ;
}
pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
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);
SetCursor (*watchFob);
#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 (GrafPtr) GetWindowPort( inWindowRef ) ;
#else
return (GrafPtr) inWindowRef ;
#endif
}
void UMADisposeWindow( WindowRef inWindowRef )
{
wxASSERT( inWindowRef != NULL ) ;
DisposeWindow( inWindowRef ) ;
}
void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding)
{
#if TARGET_CARBON
SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
#else
Str255 ptitle ;
wxMacStringToPascal( title , ptitle ) ;
SetWTitle( inWindowRef , ptitle ) ;
#endif
}
// appearance additions
void UMASetControlTitle( ControlHandle inControl , const wxString& title , wxFontEncoding encoding)
{
#if TARGET_CARBON
SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
#else
Str255 ptitle ;
wxMacStringToPascal( title , ptitle ) ;
SetControlTitle( inControl , ptitle ) ;
#endif
}
void UMAActivateControl( ControlHandle inControl )
{
// we have to add the control after again to the update rgn
// otherwise updates get lost
if ( !IsControlActive( inControl ) )
{
bool visible = IsControlVisible( inControl ) ;
if ( visible )
SetControlVisibility( inControl , false , false ) ;
::ActivateControl( inControl ) ;
if ( visible ) {
SetControlVisibility( inControl , true , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
}
}
void UMADrawControl( ControlHandle inControl )
{
WindowRef theWindow = GetControlOwner(inControl) ;
wxMacPortStateHelper help( (GrafPtr) GetWindowPort(theWindow) ) ;
RgnHandle updateRgn = NewRgn() ;
GetWindowUpdateRgn( theWindow , updateRgn ) ;
Point zero = { 0 , 0 } ;
LocalToGlobal( &zero ) ;
OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
::DrawControlInCurrentPort( inControl ) ;
InvalWindowRgn( theWindow, updateRgn) ;
DisposeRgn( updateRgn ) ;
}
void UMAMoveControl( ControlHandle inControl , short x , short y )
{
bool visible = IsControlVisible( inControl ) ;
if ( visible ) {
SetControlVisibility( inControl , false , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
::MoveControl( inControl , x , y ) ;
if ( visible ) {
SetControlVisibility( inControl , true , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
}
void UMASizeControl( ControlHandle inControl , short x , short y )
{
bool visible = IsControlVisible( inControl ) ;
if ( visible ) {
SetControlVisibility( inControl , false , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
::SizeControl( inControl , x , y ) ;
if ( visible ) {
SetControlVisibility( inControl , true , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
}
void UMADeactivateControl( ControlHandle inControl )
{
// we have to add the control after again to the update rgn
// otherwise updates get lost
bool visible = IsControlVisible( inControl ) ;
if ( visible )
SetControlVisibility( inControl , false , false ) ;
::DeactivateControl( inControl ) ;
if ( visible ) {
SetControlVisibility( inControl , true , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
}
// shows the control and adds the region to the update region
void UMAShowControl (ControlHandle inControl)
{
SetControlVisibility( inControl , true , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
// shows the control and adds the region to the update region
void UMAHideControl (ControlHandle inControl)
{
SetControlVisibility( inControl , false , false ) ;
Rect ctrlBounds ;
InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
}
// keyboard focus
OSErr UMASetKeyboardFocus (WindowPtr inWindow,
ControlHandle inControl,
ControlFocusPart inPart)
{
OSErr err = noErr;
GrafPtr port ;
GetPort( &port ) ;
SetPortWindowPort( inWindow ) ;
err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
SetPort( port ) ;
return err ;
}
// events
void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
{
wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) inWindow) ) ;
RgnHandle updateRgn = NewRgn() ;
GetWindowUpdateRgn( inWindow , updateRgn ) ;
Point zero = { 0 , 0 } ;
LocalToGlobal( &zero ) ;
OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
UpdateControls( inWindow , inRgn ) ;
InvalWindowRgn( inWindow, updateRgn) ;
DisposeRgn( updateRgn ) ;
}
bool UMAIsWindowFloating( WindowRef inWindow )
{
WindowClass cl ;
GetWindowClass( inWindow , &cl ) ;
return cl == kFloatingWindowClass ;
}
bool UMAIsWindowModal( WindowRef inWindow )
{
WindowClass cl ;
GetWindowClass( inWindow , &cl ) ;
return cl < kFloatingWindowClass ;
}
// others
void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
{
if ( inWindowRef )
{
// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
// if ( inActivate != isHightlited )
GrafPtr port ;
GetPort( &port ) ;
SetPortWindowPort( inWindowRef ) ;
HiliteWindow( inWindowRef , inActivate ) ;
ControlHandle control = NULL ;
::GetRootControl( inWindowRef , & control ) ;
if ( control )
{
if ( inActivate )
UMAActivateControl( control ) ;
else
UMADeactivateControl( control ) ;
}
SetPort( port ) ;
}
}
OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
{
return ::DrawThemePlacard( inRect , inState ) ;
}
#if !TARGET_CARBON
static OSStatus helpMenuStatus = noErr ;
static MenuItemIndex firstCustomItemIndex = 0 ;
#endif
OSStatus UMAGetHelpMenu(
MenuRef * outHelpMenu,
MenuItemIndex * outFirstCustomItemIndex)
{
#if TARGET_CARBON
return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
#else
MenuRef helpMenuHandle ;
helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
{
firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
}
if ( outFirstCustomItemIndex )
{
*outFirstCustomItemIndex = firstCustomItemIndex ;
}
*outHelpMenu = helpMenuHandle ;
return helpMenuStatus ;
#endif
}
wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
{
m_clip = NULL ;
Setup( newport ) ;
}
wxMacPortStateHelper::wxMacPortStateHelper()
{
m_clip = NULL ;
}
void wxMacPortStateHelper::Setup( GrafPtr newport )
{
GetPort( &m_oldPort ) ;
SetPort( newport ) ;
SetOrigin(0,0);
wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
m_clip = NewRgn() ;
GetClip( m_clip );
m_textFont = GetPortTextFont( (CGrafPtr) newport);
m_textSize = GetPortTextSize( (CGrafPtr) newport);
m_textStyle = GetPortTextFace( (CGrafPtr) newport);
m_textMode = GetPortTextMode( (CGrafPtr) newport);
GetThemeDrawingState( &m_drawingState ) ;
m_currentPort = newport ;
}
void wxMacPortStateHelper::Clear()
{
if ( m_clip )
{
DisposeRgn( m_clip ) ;
DisposeThemeDrawingState( m_drawingState ) ;
m_clip = NULL ;
}
}
wxMacPortStateHelper::~wxMacPortStateHelper()
{
if ( m_clip )
{
SetPort( m_currentPort ) ;
SetClip( m_clip ) ;
DisposeRgn( m_clip ) ;
TextFont( m_textFont );
TextSize( m_textSize );
TextFace( m_textStyle );
TextMode( m_textMode );
SetThemeDrawingState( m_drawingState , true ) ;
SetPort( m_oldPort ) ;
}
}
OSStatus UMAPutScrap( Size size , OSType type , void *data )
{
OSStatus err = noErr ;
#if !TARGET_CARBON
err = PutScrap( size , type , data ) ;
#else
ScrapRef scrap;
err = GetCurrentScrap (&scrap);
if ( !err )
{
err = PutScrapFlavor (scrap, type , 0, size, data);
}
#endif
return err ;
}
#endif // wxUSE_GUI
#if wxUSE_BASE
static bool sUMASystemInitialized = false ;
bool UMASystemIsInitialized()
{
return sUMASystemInitialized ;
}
void UMASetSystemIsInitialized(bool val)
{
sUMASystemInitialized = val;
}
#endif // wxUSE_BASE

1395
src/mac/classic/utils.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,223 @@
/////////////////////////////////////////////////////////////////////////////
// Name: utilsexec.cpp
// Purpose: Execution-related utilities
// Author: Stefan Csomor
// Modified by: David Elliott
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
//#pragma implementation
#endif
#include "wx/log.h"
#include "wx/utils.h"
#ifdef __DARWIN__
#include "wx/unix/execute.h"
#include <unistd.h>
#include <sys/wait.h>
extern "C" {
#include <mach/mach.h>
}
#include <CoreFoundation/CFMachPort.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __DARWIN__
#define wxEXECUTE_WIN_MESSAGE 10000
#include "wx/mac/private.h"
/*
Below FinderLaunch function comes from:
http://developer.apple.com/technotes/tn/tn1002.html#fndrask
*/
/* FinderLaunch converts a list of nTargets FSSpec records
pointed to by the targetList parameter and converts the
list to an Apple Event. It then sends that event to the
Finder. The array of FSSpec records pointed to by the
targetList parameter may contain references to files,
folders, or applications. The net effect of this command
is equivalent to the user selecting an icon in one of the
Finder's windows and then choosing the open command from
the Finder's file menu. */
static OSErr FinderLaunch(long nTargets, FSSpec *targetList) {
OSErr err;
AppleEvent theAEvent, theReply;
AEAddressDesc fndrAddress;
AEDescList targetListDesc;
OSType fndrCreator;
Boolean wasChanged;
AliasHandle targetAlias;
long index;
/* set up locals */
AECreateDesc(typeNull, NULL, 0, &theAEvent);
AECreateDesc(typeNull, NULL, 0, &fndrAddress);
AECreateDesc(typeNull, NULL, 0, &theReply);
AECreateDesc(typeNull, NULL, 0, &targetListDesc);
targetAlias = NULL;
fndrCreator = 'MACS';
/* verify parameters */
if ((nTargets == 0) || (targetList == NULL)) {
err = paramErr;
goto bail;
}
/* create an open documents event targeting the
finder */
err = AECreateDesc(typeApplSignature, (Ptr) &fndrCreator,
sizeof(fndrCreator), &fndrAddress);
if (err != noErr) goto bail;
err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
&fndrAddress, kAutoGenerateReturnID,
kAnyTransactionID, &theAEvent);
if (err != noErr) goto bail;
/* create the list of files to open */
err = AECreateList(NULL, 0, false, &targetListDesc);
if (err != noErr) goto bail;
for ( index=0; index < nTargets; index++) {
if (targetAlias == NULL)
err = NewAlias(NULL, (targetList + index),
&targetAlias);
else err = UpdateAlias(NULL, (targetList + index),
targetAlias, &wasChanged);
if (err != noErr) goto bail;
HLock((Handle) targetAlias);
err = AEPutPtr(&targetListDesc, (index + 1),
typeAlias, *targetAlias,
GetHandleSize((Handle) targetAlias));
HUnlock((Handle) targetAlias);
if (err != noErr) goto bail;
}
/* add the file list to the Apple Event */
err = AEPutParamDesc(&theAEvent, keyDirectObject,
&targetListDesc);
if (err != noErr) goto bail;
/* send the event to the Finder */
err = AESend(&theAEvent, &theReply, kAENoReply,
kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
/* clean up and leave */
bail:
if (targetAlias != NULL) DisposeHandle((Handle) targetAlias);
AEDisposeDesc(&targetListDesc);
AEDisposeDesc(&theAEvent);
AEDisposeDesc(&fndrAddress);
AEDisposeDesc(&theReply);
return err;
}
long wxExecute(const wxString& command, int flags, wxProcess *WXUNUSED(handler))
{
wxASSERT_MSG( flags == wxEXEC_ASYNC,
wxT("wxExecute: Only wxEXEC_ASYNC is supported") );
FSSpec fsSpec;
wxMacFilename2FSSpec(command, &fsSpec);
// 0 means execution failed. Returning non-zero is a PID, but not
// on Mac where PIDs are 64 bits and won't fit in a long, so we
// return a dummy value for now.
return ( FinderLaunch(1 /*one file*/, &fsSpec) == noErr ) ? -1 : 0;
}
#endif
#ifdef __DARWIN__
void wxMAC_MachPortEndProcessDetect(CFMachPortRef port, void *data)
{
wxEndProcessData *proc_data = (wxEndProcessData*)data;
wxLogDebug(wxT("Wow.. this actually worked!"));
int status = 0;
int rc = waitpid(abs(proc_data->pid), &status, WNOHANG);
if(!rc)
{
wxLogDebug(wxT("Mach port was invalidated, but process hasn't terminated!"));
return;
}
if((rc != -1) && WIFEXITED(status))
proc_data->exitcode = WEXITSTATUS(status);
else
proc_data->exitcode = -1;
wxHandleProcessTermination(proc_data);
}
int wxAddProcessCallbackForPid(wxEndProcessData *proc_data, int pid)
{
if(pid < 1)
return -1;
kern_return_t kernResult;
mach_port_t taskOfOurProcess;
mach_port_t machPortForProcess;
taskOfOurProcess = mach_task_self();
if(taskOfOurProcess == MACH_PORT_NULL)
{
wxLogDebug(wxT("No mach_task_self()"));
return -1;
}
wxLogDebug(wxT("pid=%d"),pid);
kernResult = task_for_pid(taskOfOurProcess,pid, &machPortForProcess);
if(kernResult != KERN_SUCCESS)
{
wxLogDebug(wxT("no task_for_pid()"));
// try seeing if it is already dead or something
// FIXME: a better method would be to call the callback function
// from idle time until the process terminates. Of course, how
// likely is it that it will take more than 0.1 seconds for the
// mach terminate event to make its way to the BSD subsystem?
usleep(100); // sleep for 0.1 seconds
wxMAC_MachPortEndProcessDetect(NULL, (void*)proc_data);
return -1;
}
CFMachPortContext termcb_contextinfo;
termcb_contextinfo.version = NULL;
termcb_contextinfo.info = (void*)proc_data;
termcb_contextinfo.retain = NULL;
termcb_contextinfo.release = NULL;
termcb_contextinfo.copyDescription = NULL;
CFMachPortRef CFMachPortForProcess;
Boolean ShouldFreePort;
CFMachPortForProcess = CFMachPortCreateWithPort(NULL, machPortForProcess, NULL, &termcb_contextinfo, &ShouldFreePort);
if(!CFMachPortForProcess)
{
wxLogDebug(wxT("No CFMachPortForProcess"));
mach_port_deallocate(taskOfOurProcess, machPortForProcess);
return -1;
}
if(ShouldFreePort)
{
kernResult = mach_port_deallocate(taskOfOurProcess, machPortForProcess);
if(kernResult!=KERN_SUCCESS)
{
wxLogDebug(wxT("Couldn't deallocate mach port"));
return -1;
}
}
CFMachPortSetInvalidationCallBack(CFMachPortForProcess, &wxMAC_MachPortEndProcessDetect);
CFRunLoopSourceRef runloopsource;
runloopsource = CFMachPortCreateRunLoopSource(NULL,CFMachPortForProcess, (CFIndex)0);
if(!runloopsource)
{
wxLogDebug(wxT("Couldn't create runloopsource"));
return -1;
}
CFRelease(CFMachPortForProcess);
CFRunLoopAddSource(CFRunLoopGetCurrent(),runloopsource,kCFRunLoopDefaultMode);
CFRelease(runloopsource);
wxLogDebug(wxT("Successfully added notification to the runloop"));
return 0;
}
#endif

2096
src/mac/classic/window.cpp Normal file

File diff suppressed because it is too large Load Diff

BIN
src/mac/classic/wxmac.icns Normal file

Binary file not shown.