cocoa implementation files

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55203 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2008-08-23 12:55:54 +00:00
parent e53b3d16de
commit f033830e25
9 changed files with 985 additions and 0 deletions

49
src/osx/cocoa/bmpbuttn.mm Normal file
View File

@ -0,0 +1,49 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/mac/carbon/bmpbuttn.cpp
// Purpose: wxBitmapButton
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id: bmpbuttn.cpp 54820 2008-07-29 20:04:11Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#if wxUSE_BMPBUTTON
#include "wx/bmpbuttn.h"
#include "wx/image.h"
#ifndef WX_PRECOMP
#include "wx/dcmemory.h"
#endif
#include "wx/osx/private.h"
wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxBitmap& bitmap,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
[v setBezelStyle:NSRegularSquareBezelStyle];
[v setButtonType:NSMomentaryPushInButton];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
#endif

267
src/osx/cocoa/button.mm Normal file
View File

@ -0,0 +1,267 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/button.mm
// Purpose: wxButton
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id: button.cpp 54845 2008-07-30 14:52:41Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#include "wx/button.h"
#ifndef WX_PRECOMP
#include "wx/panel.h"
#include "wx/toplevel.h"
#include "wx/dcclient.h"
#endif
#include "wx/stockitem.h"
#include "wx/osx/private.h"
wxSize wxButton::DoGetBestSize() const
{
if ( GetId() == wxID_HELP )
return wxSize( 20 , 20 ) ;
wxSize sz = GetDefaultSize() ;
switch (GetWindowVariant())
{
case wxWINDOW_VARIANT_NORMAL:
case wxWINDOW_VARIANT_LARGE:
sz.y = 20 ;
break;
case wxWINDOW_VARIANT_SMALL:
sz.y = 17 ;
break;
case wxWINDOW_VARIANT_MINI:
sz.y = 15 ;
break;
default:
break;
}
#if wxOSX_USE_CARBON
Rect bestsize = { 0 , 0 , 0 , 0 } ;
m_peer->GetBestRect( &bestsize ) ;
int wBtn;
if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) )
{
Point bounds;
ControlFontStyleRec controlFont;
OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
verify_noerr( err );
wxCFStringRef str( m_label, GetFont().GetEncoding() );
#if wxOSX_USE_ATSU_TEXT
SInt16 baseline;
if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
{
err = GetThemeTextDimensions(
(!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
verify_noerr( err );
}
else
#endif
{
wxClientDC dc(const_cast<wxButton*>(this));
wxCoord width, height ;
dc.GetTextExtent( m_label , &width, &height);
bounds.h = width;
bounds.v = height;
}
wBtn = bounds.h + sz.y;
}
else
{
wBtn = bestsize.right - bestsize.left ;
// non 'normal' window variants don't return the correct height
// sz.y = bestsize.bottom - bestsize.top ;
}
if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
sz.x = wBtn;
#endif
return sz ;
}
wxSize wxButton::GetDefaultSize()
{
int wBtn = 70 ;
int hBtn = 20 ;
return wxSize(wBtn, hBtn);
}
@implementation wxNSButton
- (id)initWithFrame:(NSRect)frame
{
[super initWithFrame:frame];
m_impl = NULL;
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
return self;
}
- (void) clickedAction: (id) sender
{
if ( m_impl )
{
wxButton* wxpeer = (wxButton*) m_impl->GetWXPeer();
if ( wxpeer )
wxpeer->HandleClicked(0);
}
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
{
m_impl = theImplementation;
}
- (wxWidgetImpl*) implementation
{
return m_impl;
}
- (BOOL) isFlipped
{
return YES;
}
- (int) intValue
{
switch ( [self state] )
{
case NSOnState:
return 1;
case NSMixedState:
return 2;
default:
return 0;
}
}
- (void) setIntValue: (int) v
{
switch( v )
{
case 2:
[self setState:NSMixedState];
break;
case 1:
[self setState:NSOnState];
break;
default :
[self setState:NSOffState];
break;
}
}
@end
wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
if ( id == wxID_HELP )
{
[v setBezelStyle:NSHelpButtonBezelStyle];
}
else
{
[v setBezelStyle:NSRoundedBezelStyle];
}
[v setButtonType:NSMomentaryPushInButton];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
/*
OSStatus err;
Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
wxMacControl* peer = new wxMacControl(wxpeer) ;
if ( id == wxID_HELP )
{
ControlButtonContentInfo info ;
info.contentType = kControlContentIconRef ;
GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef);
err = CreateRoundButtonControl(
MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
&bounds, kControlRoundButtonNormalSize,
&info, peer->GetControlRefAddr() );
}
else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
{
// Button height is static in Mac, can't be changed, so we need to force it here
int maxHeight;
switch (wxpeer->GetWindowVariant() )
{
case wxWINDOW_VARIANT_NORMAL:
case wxWINDOW_VARIANT_LARGE:
maxHeight = 20 ;
break;
case wxWINDOW_VARIANT_SMALL:
maxHeight = 17;
case wxWINDOW_VARIANT_MINI:
maxHeight = 15;
default:
break;
}
bounds.bottom = bounds.top + maxHeight ;
wxpeer->SetMaxSize( wxSize( wxpeer->GetMaxWidth() , maxHeight ));
err = CreatePushButtonControl(
MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
&bounds, CFSTR(""), peer->GetControlRefAddr() );
}
else
{
ControlButtonContentInfo info ;
info.contentType = kControlNoContent ;
err = CreateBevelButtonControl(
MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, CFSTR(""),
kControlBevelButtonLargeBevel, kControlBehaviorPushbutton,
&info, 0, 0, 0, peer->GetControlRefAddr() );
}
verify_noerr( err );
return peer;
*/
}
void wxWidgetCocoaImpl::SetDefaultButton( bool isDefault )
{
[m_osxView setKeyEquivalent: isDefault ? @"\r" : nil ];
// SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) isDefault ) ;
}
void wxWidgetCocoaImpl::PerformClick()
{
}
// TODO for the disclosure button : NSDisclosureBezelStyle and the button type to NSOnOffButton.

44
src/osx/cocoa/checkbox.mm Normal file
View File

@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/checkbox.mm
// Purpose: wxCheckBox
// Author: Stefan Csomor
// Modified by:
// Created: 2008-08-20
// RCS-ID: $Id: checkbox.mm 54129 2008-06-11 19:30:52Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#if wxUSE_CHECKBOX
#include "wx/checkbox.h"
#include "wx/osx/private.h"
wxWidgetImplType* wxWidgetImpl::CreateCheckBox( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
[v setButtonType:NSSwitchButton];
if (style & wxCHK_3STATE)
[v setAllowsMixedState:YES];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
#endif

217
src/osx/cocoa/notebook.mm Normal file
View File

@ -0,0 +1,217 @@
///////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/notebook.mm
// Purpose: implementation of wxNotebook
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id: notebmac.cpp 55079 2008-08-13 14:56:42Z PC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#if wxUSE_NOTEBOOK
#include "wx/notebook.h"
#ifndef WX_PRECOMP
#include "wx/string.h"
#include "wx/log.h"
#include "wx/app.h"
#include "wx/image.h"
#endif
#include "wx/string.h"
#include "wx/imaglist.h"
#include "wx/osx/private.h"
@interface wxNSTabView : NSTabView
{
wxWidgetImpl* m_impl;
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
- (wxWidgetImpl*) implementation;
- (BOOL) isFlipped;
- (int) intValue;
- (void) setIntValue:(int) v;
@end
@implementation wxNSTabView
- (void)setImplementation: (wxWidgetImpl *) theImplementation
{
m_impl = theImplementation;
}
- (wxWidgetImpl*) implementation
{
return m_impl;
}
- (BOOL) isFlipped
{
return YES;
}
- (int) intValue
{
NSTabViewItem* selectedItem = [self selectedTabViewItem];
if ( selectedItem == nil )
return 0;
else
return [self indexOfTabViewItem:selectedItem]+1;
}
- (void) setIntValue:(int) v
{
[self selectTabViewItemAtIndex:(v-1)];
}
@end
/*
#if 0
Rect bounds = wxMacGetBoundsForControl( this, pos, size );
if ( bounds.right <= bounds.left )
bounds.right = bounds.left + 100;
if ( bounds.bottom <= bounds.top )
bounds.bottom = bounds.top + 100;
UInt16 tabstyle = kControlTabDirectionNorth;
if ( HasFlag(wxBK_LEFT) )
tabstyle = kControlTabDirectionWest;
else if ( HasFlag( wxBK_RIGHT ) )
tabstyle = kControlTabDirectionEast;
else if ( HasFlag( wxBK_BOTTOM ) )
tabstyle = kControlTabDirectionSouth;
ControlTabSize tabsize;
switch (GetWindowVariant())
{
case wxWINDOW_VARIANT_MINI:
tabsize = 3 ;
break;
case wxWINDOW_VARIANT_SMALL:
tabsize = kControlTabSizeSmall;
break;
default:
tabsize = kControlTabSizeLarge;
break;
}
m_peer = new wxMacControl( this );
OSStatus err = CreateTabsControl(
MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() );
verify_noerr( err );
#endif
*/
wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
/* if ( bounds.right <= bounds.left )
bounds.right = bounds.left + 100;
if ( bounds.bottom <= bounds.top )
bounds.bottom = bounds.top + 100;
*/
NSTabViewType tabstyle = NSTopTabsBezelBorder;
if ( style & wxBK_LEFT )
tabstyle = NSLeftTabsBezelBorder;
else if ( style & wxBK_RIGHT )
tabstyle = NSRightTabsBezelBorder;
else if ( style & wxBK_BOTTOM )
tabstyle = NSBottomTabsBezelBorder;
wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
[sv addSubview:v];
[v setTabViewType:tabstyle];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& notebook)
{
int pcount = notebook.GetPageCount();
int cocoacount = [ (wxNSTabView*) m_osxView numberOfTabViewItems ];
if ( pcount > cocoacount )
{
for ( int i = cocoacount ; i < pcount ; ++i )
{
NSTabViewItem* item = [[NSTabViewItem alloc] init];
[(wxNSTabView*) m_osxView addTabViewItem:item];
[item release];
}
}
else if ( pcount < cocoacount )
{
for ( int i = cocoacount -1 ; i >= pcount ; --i )
{
NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
[(wxNSTabView*) m_osxView removeTabViewItem:item];
}
}
for ( int i = 0 ; i < pcount ; ++i )
{
wxNotebookPage* page = notebook.GetPage(i);
NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
[item setLabel:wxCFStringRef( page->GetLabel() , notebook.GetFont().GetEncoding() ).AsNSString()];
}
/*
SetMaximum( GetPageCount() ) ;
wxNotebookPage *page;
ControlTabInfoRecV1 info;
const size_t countPages = GetPageCount();
for (size_t ii = 0; ii < countPages; ii++)
{
page = (wxNotebookPage*) notebook->GetPage[ii];
info.version = kControlTabInfoVersionOne;
info.iconSuiteID = 0;
wxCFStringRef cflabel( page->GetLabel(), GetFont().GetEncoding() ) ;
info.name = cflabel ;
SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
if ( GetImageList() && GetPageImage(ii) >= 0 )
{
const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ;
if ( bmap.Ok() )
{
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info, bmap ) ;
OSStatus err = SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
if ( err != noErr )
{
wxFAIL_MSG("Error when setting icon on tab");
}
wxMacReleaseBitmapButton( &info ) ;
}
}
SetTabEnabled( ii + 1, true ) ;
}
*/
}
#endif

42
src/osx/cocoa/radiobut.mm Normal file
View File

@ -0,0 +1,42 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/radiobut.mm
// Purpose: wxRadioButton
// Author: Stefan Csomor
// Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox
// Created: ??/??/98
// RCS-ID: $Id: radiobut.cpp 54129 2008-06-11 19:30:52Z SC $
// Copyright: (c) AUTHOR
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#if wxUSE_RADIOBTN
#include "wx/radiobut.h"
#include "wx/osx/private.h"
wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
[v setButtonType:NSRadioButton];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
#endif

40
src/osx/cocoa/statbox.mm Normal file
View File

@ -0,0 +1,40 @@
/////////////////////////////////////////////////////////////////////////////
// Name: statbox.cpp
// Purpose: wxStaticBox
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id: statbox.cpp 54129 2008-06-11 19:30:52Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#if wxUSE_STATBOX
#include "wx/statbox.h"
#include "wx/osx/private.h"
wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
#endif // wxUSE_STATBOX

74
src/osx/cocoa/statline.mm Normal file
View File

@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/statline.mm
// Purpose: wxStaticLine class
// Author: Stefan Csomor
// Created: 28.06.99
// Version: $Id: statline.mm 54129 2008-06-11 19:30:52Z SC $
// Copyright: (c) 2008 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_STATLINE
#include "wx/statline.h"
#ifndef WX_PRECOMP
#include "wx/statbox.h"
#endif
#include "wx/osx/private.h"
@implementation wxNSBox
- (void)setImplementation: (wxWidgetImpl *) theImplementation
{
m_impl = theImplementation;
}
- (wxWidgetImpl*) implementation
{
return m_impl;
}
- (BOOL) isFlipped
{
return YES;
}
@end
wxWidgetImplType* wxWidgetImpl::CreateStaticLine( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
#endif //wxUSE_STATLINE

177
src/osx/cocoa/stattext.mm Normal file
View File

@ -0,0 +1,177 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/stattext.mm
// Purpose: wxStaticText
// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#if wxUSE_STATTEXT
#include "wx/stattext.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/utils.h"
#include "wx/dc.h"
#include "wx/dcclient.h"
#include "wx/settings.h"
#endif // WX_PRECOMP
#include "wx/notebook.h"
#include "wx/tabctrl.h"
#include "wx/osx/private.h"
#include <stdio.h>
wxSize wxStaticText::DoGetBestSize() const
{
Point bounds;
#if wxOSX_USE_CARBON
Rect bestsize = { 0 , 0 , 0 , 0 } ;
// try the built-in best size if available
Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag);
m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
m_peer->GetBestRect( &bestsize ) ;
m_peer->SetData( kControlStaticTextIsMultilineTag, former );
if ( !EmptyRect( &bestsize ) )
{
bounds.h = bestsize.right - bestsize.left ;
bounds.v = bestsize.bottom - bestsize.top ;
}
else
#endif
{
#if wxOSX_USE_CARBON
ControlFontStyleRec controlFont;
OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
verify_noerr( err );
wxCFStringRef str( m_label, GetFont().GetEncoding() );
#if wxOSX_USE_ATSU_TEXT
SInt16 baseline;
if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
{
err = GetThemeTextDimensions(
(!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
verify_noerr( err );
}
else
#endif
#endif
{
wxClientDC dc(const_cast<wxStaticText*>(this));
wxCoord width, height ;
dc.GetTextExtent( m_label , &width, &height);
bounds.h = width;
bounds.v = height;
}
if ( m_label.empty() )
bounds.h = 0;
}
bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
return wxSize( bounds.h, bounds.v );
}
// for wxST_ELLIPSIZE_* support:
/*
FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
to allow correct dynamic ellipsizing of the label
*/
@interface wxNSTextField : NSTextField
{
wxWidgetImpl* m_impl;
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
- (wxWidgetImpl*) implementation;
- (BOOL) isFlipped;
@end
@implementation wxNSTextField
- (void)setImplementation: (wxWidgetImpl *) theImplementation
{
m_impl = theImplementation;
}
- (wxWidgetImpl*) implementation
{
return m_impl;
}
- (BOOL) isFlipped
{
return YES;
}
// use our common calls
- (void) setTitle:(NSString *) title
{
[self setStringValue: title];
}
@end
wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
[sv addSubview:v];
[v setBezeled:NO];
[v setEditable:NO];
[v setDrawsBackground:NO];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
/*
Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
wxMacControl* peer = new wxMacControl( wxpeer );
OSStatus err = CreateStaticTextControl(
MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
&bounds, NULL, NULL, peer->GetControlRefAddr() );
verify_noerr( err );
if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
{
TruncCode tCode = truncEnd;
if ( style & wxST_ELLIPSIZE_MIDDLE )
tCode = truncMiddle;
err = peer->SetData( kControlStaticTextTruncTag, tCode );
err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
}
return peer;
*/
}
#endif //if wxUSE_STATTEXT

75
src/osx/cocoa/tglbtn.mm Normal file
View File

@ -0,0 +1,75 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/tglbtn.mm
// 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: tglbtn.cpp 54129 2008-06-11 19:30:52Z SC $
// Copyright: (c) Stefan Csomor
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declatations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/wxprec.h"
#if wxUSE_TOGGLEBTN
#include "wx/tglbtn.h"
#include "wx/osx/private.h"
wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
[v setBezelStyle:NSRoundedBezelStyle];
[v setButtonType:NSOnOffButton];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
const wxBitmap& label,
const wxPoint& pos,
const wxSize& size,
long style,
long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
[v setBezelStyle:NSRegularSquareBezelStyle];
[v setButtonType:NSOnOffButton];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
#endif // wxUSE_TOGGLEBTN