committing current cocoa state just to be safe ...
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55366 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
		@@ -33,8 +33,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 | 
			
		||||
    
 | 
			
		||||
    [v setBezelStyle:NSRegularSquareBezelStyle];
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,7 @@ wxSize wxButton::DoGetBestSize() const
 | 
			
		||||
    {
 | 
			
		||||
        case wxWINDOW_VARIANT_NORMAL:
 | 
			
		||||
        case wxWINDOW_VARIANT_LARGE:
 | 
			
		||||
            sz.y = 20 ;
 | 
			
		||||
            sz.y = 23 ;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case wxWINDOW_VARIANT_SMALL:
 | 
			
		||||
@@ -49,6 +49,21 @@ wxSize wxButton::DoGetBestSize() const
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    wxRect r ;
 | 
			
		||||
        
 | 
			
		||||
    m_peer->GetBestRect(&r);
 | 
			
		||||
 | 
			
		||||
    if ( r.GetWidth() == 0 && r.GetHeight() == 0 )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    sz.x = r.GetWidth();
 | 
			
		||||
    sz.y = r.GetHeight();
 | 
			
		||||
 | 
			
		||||
    int wBtn = 96;
 | 
			
		||||
    
 | 
			
		||||
    if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
 | 
			
		||||
        sz.x = wBtn;
 | 
			
		||||
 | 
			
		||||
#if wxOSX_USE_CARBON
 | 
			
		||||
    Rect    bestsize = { 0 , 0 , 0 , 0 } ;
 | 
			
		||||
    m_peer->GetBestRect( &bestsize ) ;
 | 
			
		||||
@@ -111,7 +126,7 @@ wxSize wxButton::GetDefaultSize()
 | 
			
		||||
- (id)initWithFrame:(NSRect)frame
 | 
			
		||||
{
 | 
			
		||||
    [super initWithFrame:frame];
 | 
			
		||||
    m_impl = NULL;
 | 
			
		||||
    impl = NULL;
 | 
			
		||||
    [self setTarget: self];
 | 
			
		||||
    [self setAction: @selector(clickedAction:)];
 | 
			
		||||
    return self;
 | 
			
		||||
@@ -119,9 +134,9 @@ wxSize wxButton::GetDefaultSize()
 | 
			
		||||
 | 
			
		||||
- (void) clickedAction: (id) sender
 | 
			
		||||
{
 | 
			
		||||
    if ( m_impl )
 | 
			
		||||
    if ( impl )
 | 
			
		||||
    {
 | 
			
		||||
        wxButton* wxpeer = (wxButton*) m_impl->GetWXPeer();
 | 
			
		||||
        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleClicked(0);
 | 
			
		||||
    }
 | 
			
		||||
@@ -129,12 +144,12 @@ wxSize wxButton::GetDefaultSize()
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    m_impl = theImplementation;
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return m_impl;
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
@@ -185,8 +200,7 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 | 
			
		||||
    
 | 
			
		||||
    if ( id == wxID_HELP )
 | 
			
		||||
@@ -256,12 +270,33 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetDefaultButton( bool isDefault )
 | 
			
		||||
{ 
 | 
			
		||||
    [m_osxView setKeyEquivalent: isDefault ? @"\r" : nil ];
 | 
			
		||||
//    SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) isDefault ) ;
 | 
			
		||||
    if ( [m_osxView isKindOfClass:[NSButton class]] )
 | 
			
		||||
        [(NSButton*)m_osxView setKeyEquivalent: isDefault ? @"\r" : nil ];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::PerformClick() 
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO for the disclosure button : NSDisclosureBezelStyle and the button type to NSOnOffButton.
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( 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 = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 | 
			
		||||
    [v setBezelStyle:NSDisclosureBezelStyle];
 | 
			
		||||
    [v setButtonType:NSOnOffButton];
 | 
			
		||||
    [v setTitle:wxCFStringRef( label).AsNSString()];
 | 
			
		||||
    [v setImagePosition:NSImageRight];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
 | 
			
		||||
    [v setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,8 +27,7 @@ wxWidgetImplType* wxWidgetImpl::CreateCheckBox( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 | 
			
		||||
 | 
			
		||||
    [v setButtonType:NSSwitchButton];    
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										105
									
								
								src/osx/cocoa/choice.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								src/osx/cocoa/choice.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,105 @@
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        src/osx/cocoa/choice.mm
 | 
			
		||||
// Purpose:     wxChoice
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by:
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: choice.cpp 54129 2008-06-11 19:30:52Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:     wxWindows licence
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#if wxUSE_CHOICE
 | 
			
		||||
 | 
			
		||||
#include "wx/choice.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WX_PRECOMP
 | 
			
		||||
    #include "wx/menu.h"
 | 
			
		||||
    #include "wx/dcclient.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
@interface wxNSPopUpButton : NSPopUpButton
 | 
			
		||||
{
 | 
			
		||||
    wxWidgetImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
 | 
			
		||||
- (wxWidgetImpl*) implementation;
 | 
			
		||||
- (BOOL) isFlipped;
 | 
			
		||||
- (void) clickedAction: (id) sender;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSPopUpButton
 | 
			
		||||
 | 
			
		||||
- (id)initWithFrame:(NSRect)frame pullsDown:(BOOL) pd
 | 
			
		||||
{
 | 
			
		||||
    [super initWithFrame:frame pullsDown:pd];
 | 
			
		||||
    impl = NULL;
 | 
			
		||||
    [self setTarget: self];
 | 
			
		||||
    [self setAction: @selector(clickedAction:)];
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) clickedAction: (id) sender
 | 
			
		||||
{
 | 
			
		||||
    if ( impl )
 | 
			
		||||
    {
 | 
			
		||||
        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleClicked(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
{
 | 
			
		||||
    return YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (int) intValue
 | 
			
		||||
{
 | 
			
		||||
   return [self indexOfSelectedItem];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) setIntValue: (int) v
 | 
			
		||||
{
 | 
			
		||||
    [self selectItemAtIndex:v];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer, 
 | 
			
		||||
                                    wxWindowMac* parent, 
 | 
			
		||||
                                    wxWindowID id, 
 | 
			
		||||
                                    wxMenu* menu,
 | 
			
		||||
                                    const wxPoint& pos, 
 | 
			
		||||
                                    const wxSize& size,
 | 
			
		||||
                                    long style, 
 | 
			
		||||
                                    long extraStylew)
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    [v setMenu: menu->GetHMenu()];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
 | 
			
		||||
    [v setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // wxUSE_CHOICE
 | 
			
		||||
@@ -26,6 +26,9 @@ extern wxList wxModalDialogs;
 | 
			
		||||
 | 
			
		||||
void wxDialog::DoShowModal()
 | 
			
		||||
{
 | 
			
		||||
    wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
 | 
			
		||||
 | 
			
		||||
    wxModalDialogs.Append(this);
 | 
			
		||||
 | 
			
		||||
    SetFocus() ;
 | 
			
		||||
/*
 | 
			
		||||
@@ -41,12 +44,12 @@ void wxDialog::DoShowModal()
 | 
			
		||||
        resetGroupParent = true;
 | 
			
		||||
    }
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
    NSWindow* theWindow = GetWXWindow();
 | 
			
		||||
    
 | 
			
		||||
    NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
 | 
			
		||||
    while (IsModal()) 
 | 
			
		||||
    {
 | 
			
		||||
        wxMacAutoreleasePool autoreleasepool;
 | 
			
		||||
        if ([NSApp runModalSession:session] != NSRunContinuesResponse)
 | 
			
		||||
            break;
 | 
			
		||||
        // TODO should we do some idle processing ?
 | 
			
		||||
 
 | 
			
		||||
@@ -50,6 +50,7 @@ void wxGUIEventLoop::WakeUp()
 | 
			
		||||
 | 
			
		||||
bool wxGUIEventLoop::Pending() const
 | 
			
		||||
{
 | 
			
		||||
    wxMacAutoreleasePool autoreleasepool;
 | 
			
		||||
    // a pointer to the event is returned if there is one, or nil if not
 | 
			
		||||
    return [[NSApplication sharedApplication]
 | 
			
		||||
            nextEventMatchingMask: NSAnyEventMask
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										124
									
								
								src/osx/cocoa/gauge.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								src/osx/cocoa/gauge.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,124 @@
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        gauge.mm
 | 
			
		||||
// Purpose:     wxGauge class
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by:
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: gauge.cpp 54820 2008-07-29 20:04:11Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:       wxWindows licence
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#if wxUSE_GAUGE
 | 
			
		||||
 | 
			
		||||
#include "wx/gauge.h"
 | 
			
		||||
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
@interface wxNSProgressIndicator : NSProgressIndicator
 | 
			
		||||
{
 | 
			
		||||
    wxWidgetImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
 | 
			
		||||
- (wxWidgetImpl*) implementation;
 | 
			
		||||
- (BOOL) isFlipped;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSProgressIndicator
 | 
			
		||||
 | 
			
		||||
- (id)initWithFrame:(NSRect)frame
 | 
			
		||||
{
 | 
			
		||||
    [super initWithFrame:frame];
 | 
			
		||||
    impl = NULL;
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
{
 | 
			
		||||
    return YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxOSXGaugeCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void SetMaximum(wxInt32 v)
 | 
			
		||||
    {
 | 
			
		||||
        SetDeterminateMode();
 | 
			
		||||
        wxWidgetCocoaImpl::SetMaximum( v ) ;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void SetValue(wxInt32 v)
 | 
			
		||||
    {
 | 
			
		||||
        SetDeterminateMode();
 | 
			
		||||
        wxWidgetCocoaImpl::SetValue( v ) ;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void PulseGauge()
 | 
			
		||||
    {
 | 
			
		||||
        if ( ![(wxNSProgressIndicator*)m_osxView isIndeterminate] )
 | 
			
		||||
        {
 | 
			
		||||
            [(wxNSProgressIndicator*)m_osxView setIndeterminate:YES];
 | 
			
		||||
            [(wxNSProgressIndicator*)m_osxView startAnimation:nil];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
protected:
 | 
			
		||||
    void SetDeterminateMode()
 | 
			
		||||
    {
 | 
			
		||||
       // switch back to determinate mode if necessary
 | 
			
		||||
        if ( [(wxNSProgressIndicator*)m_osxView isIndeterminate]  )
 | 
			
		||||
        {
 | 
			
		||||
            [(wxNSProgressIndicator*)m_osxView stopAnimation:nil];
 | 
			
		||||
            [(wxNSProgressIndicator*)m_osxView setIndeterminate:NO];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer, 
 | 
			
		||||
                                    wxWindowMac* parent, 
 | 
			
		||||
                                    wxWindowID id, 
 | 
			
		||||
                                    wxInt32 value,
 | 
			
		||||
                                    wxInt32 minimum,
 | 
			
		||||
                                    wxInt32 maximum,
 | 
			
		||||
                                    const wxPoint& pos, 
 | 
			
		||||
                                    const wxSize& size,
 | 
			
		||||
                                    long style, 
 | 
			
		||||
                                    long extraStyle)
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSProgressIndicator* v = [[wxNSProgressIndicator alloc] initWithFrame:r];
 | 
			
		||||
 | 
			
		||||
    [v setMinValue: minimum];
 | 
			
		||||
    [v setMaxValue: maximum];
 | 
			
		||||
    [v setIndeterminate:FALSE];
 | 
			
		||||
    [v setDoubleValue: (double) value];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
 | 
			
		||||
    [v setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // wxUSE_GAUGE
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										617
									
								
								src/osx/cocoa/listbox.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										617
									
								
								src/osx/cocoa/listbox.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,617 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        src/osx/cocoa/listbox.mm
 | 
			
		||||
// Purpose:     wxListBox
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by:
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: listbox.cpp 54820 2008-07-29 20:04:11Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:     wxWindows licence
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#if wxUSE_LISTBOX
 | 
			
		||||
 | 
			
		||||
#include "wx/listbox.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WX_PRECOMP
 | 
			
		||||
    #include "wx/log.h"
 | 
			
		||||
    #include "wx/intl.h"
 | 
			
		||||
    #include "wx/utils.h"
 | 
			
		||||
    #include "wx/settings.h"
 | 
			
		||||
    #include "wx/arrstr.h"
 | 
			
		||||
    #include "wx/dcclient.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
// forward decls
 | 
			
		||||
 | 
			
		||||
class wxListWidgetCocoaImpl;
 | 
			
		||||
 | 
			
		||||
@interface wxNSTableDataSource : NSObject
 | 
			
		||||
{
 | 
			
		||||
    wxListWidgetCocoaImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (id)tableView:(NSTableView *)aTableView 
 | 
			
		||||
        objectValueForTableColumn:(NSTableColumn *)aTableColumn 
 | 
			
		||||
        row:(NSInteger)rowIndex;
 | 
			
		||||
 | 
			
		||||
- (id)tableView:(NSTableView *)aTableView 
 | 
			
		||||
        setObjectValue:(NSTableColumn *)aTableColumn 
 | 
			
		||||
        row:(NSInteger)rowIndex;
 | 
			
		||||
        
 | 
			
		||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView;
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation;
 | 
			
		||||
- (wxListWidgetCocoaImpl*) implementation;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@interface wxNSTableView : NSTableView
 | 
			
		||||
{
 | 
			
		||||
    wxListWidgetCocoaImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation;
 | 
			
		||||
- (wxListWidgetCocoaImpl*) implementation;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// table column
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
class wxCocoaTableColumn;
 | 
			
		||||
 | 
			
		||||
@interface wxNSTableColumn : NSTableColumn
 | 
			
		||||
{
 | 
			
		||||
    wxCocoaTableColumn* column;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) setColumn: (wxCocoaTableColumn*) col;
 | 
			
		||||
 | 
			
		||||
- (wxCocoaTableColumn*) column;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
class WXDLLIMPEXP_CORE wxCocoaTableColumn : public wxListWidgetColumn
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxCocoaTableColumn( wxNSTableColumn* column, bool editable ) 
 | 
			
		||||
        : m_column( column ), m_editable(editable)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    ~wxCocoaTableColumn()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    wxNSTableColumn* GetNSTableColumn() const { return m_column ; }
 | 
			
		||||
    
 | 
			
		||||
    bool IsEditable() const { return m_editable; }
 | 
			
		||||
    
 | 
			
		||||
protected :
 | 
			
		||||
    wxNSTableColumn* m_column;
 | 
			
		||||
    bool m_editable;
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
NSString* column1 = @"1";
 | 
			
		||||
 | 
			
		||||
class wxListWidgetCocoaImpl : public wxWidgetCocoaImpl, public wxListWidgetImpl
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data );
 | 
			
		||||
    
 | 
			
		||||
    ~wxListWidgetCocoaImpl();
 | 
			
		||||
    
 | 
			
		||||
    virtual wxListWidgetColumn*     InsertTextColumn( unsigned pos, const wxString& title, bool editable = false, 
 | 
			
		||||
                                wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1)  ;
 | 
			
		||||
    virtual wxListWidgetColumn*     InsertCheckColumn( unsigned pos , const wxString& title, bool editable = false, 
 | 
			
		||||
                                wxAlignment just = wxALIGN_LEFT , int defaultWidth =  -1)  ;
 | 
			
		||||
    
 | 
			
		||||
    // add and remove
 | 
			
		||||
    
 | 
			
		||||
    virtual void            ListDelete( unsigned int n ) ;    
 | 
			
		||||
    virtual void            ListInsert( unsigned int n ) ;
 | 
			
		||||
    virtual void            ListClear() ;
 | 
			
		||||
 | 
			
		||||
    // selecting
 | 
			
		||||
 | 
			
		||||
    virtual void            ListDeselectAll();
 | 
			
		||||
    
 | 
			
		||||
    virtual void            ListSetSelection( unsigned int n, bool select, bool multi ) ;
 | 
			
		||||
    virtual int             ListGetSelection() const ;
 | 
			
		||||
    
 | 
			
		||||
    virtual int             ListGetSelections( wxArrayInt& aSelections ) const ;
 | 
			
		||||
    
 | 
			
		||||
    virtual bool            ListIsSelected( unsigned int n ) const ;
 | 
			
		||||
    
 | 
			
		||||
    // display
 | 
			
		||||
 | 
			
		||||
    virtual void            ListScrollTo( unsigned int n ) ;
 | 
			
		||||
 | 
			
		||||
    // accessing content
 | 
			
		||||
 | 
			
		||||
    virtual unsigned int    ListGetCount() const ;
 | 
			
		||||
    
 | 
			
		||||
    int                     ListGetColumnType( int col )
 | 
			
		||||
    {
 | 
			
		||||
        return col;
 | 
			
		||||
    }
 | 
			
		||||
    virtual void            UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ;
 | 
			
		||||
    virtual void            UpdateLineToEnd( unsigned int n);
 | 
			
		||||
protected :
 | 
			
		||||
    wxNSTableView*          m_tableView ;
 | 
			
		||||
    
 | 
			
		||||
    wxNSTableDataSource*    m_dataSource;
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// implementations
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
@implementation wxNSTableColumn
 | 
			
		||||
 | 
			
		||||
- (id) init
 | 
			
		||||
{
 | 
			
		||||
    [super init];
 | 
			
		||||
    column = nil;
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) setColumn: (wxCocoaTableColumn*) col
 | 
			
		||||
{
 | 
			
		||||
    column = col;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxCocoaTableColumn*) column
 | 
			
		||||
{
 | 
			
		||||
    return column;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
class wxNSTableViewCellValue : public wxListWidgetCellValue
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxNSTableViewCellValue( id &v ) : value(v)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    virtual ~wxNSTableViewCellValue() {}
 | 
			
		||||
 | 
			
		||||
    virtual void Set( CFStringRef v )
 | 
			
		||||
    {
 | 
			
		||||
        value = [[(NSString*)v retain] autorelease];
 | 
			
		||||
    }
 | 
			
		||||
    virtual void Set( const wxString& value ) 
 | 
			
		||||
    {
 | 
			
		||||
        Set( (CFStringRef) wxCFStringRef( value ) );
 | 
			
		||||
    }
 | 
			
		||||
    virtual void Set( int v ) 
 | 
			
		||||
    {
 | 
			
		||||
        value = [NSNumber numberWithInt:v];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    virtual int GetIntValue() const 
 | 
			
		||||
    {
 | 
			
		||||
        if ( [value isKindOfClass:[NSNumber class]] )
 | 
			
		||||
            return [ (NSNumber*) value intValue ];
 | 
			
		||||
            
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    virtual wxString GetStringValue() const 
 | 
			
		||||
    {
 | 
			
		||||
        if ( [value isKindOfClass:[NSString class]] )
 | 
			
		||||
            return wxCFStringRef( (CFStringRef) [value retain] ).AsString();
 | 
			
		||||
            
 | 
			
		||||
        return wxEmptyString;
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
protected:
 | 
			
		||||
    id& value;
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
@implementation wxNSTableDataSource
 | 
			
		||||
 | 
			
		||||
- (id) init
 | 
			
		||||
{
 | 
			
		||||
    [super init];
 | 
			
		||||
    impl = nil;
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxListWidgetCocoaImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
 | 
			
		||||
{
 | 
			
		||||
    if ( impl )
 | 
			
		||||
        return impl->ListGetCount();
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (id)tableView:(NSTableView *)aTableView 
 | 
			
		||||
        objectValueForTableColumn:(NSTableColumn *)aTableColumn 
 | 
			
		||||
        row:(NSInteger)rowIndex
 | 
			
		||||
{
 | 
			
		||||
    wxNSTableColumn* tablecol = (wxNSTableColumn *)aTableColumn;
 | 
			
		||||
    wxListBox* lb = dynamic_cast<wxListBox*>(impl->GetWXPeer());
 | 
			
		||||
    wxCocoaTableColumn* col = [tablecol column];
 | 
			
		||||
    id value = nil;
 | 
			
		||||
    wxNSTableViewCellValue cellvalue(value);
 | 
			
		||||
    lb->GetValueCallback(rowIndex, col, cellvalue);
 | 
			
		||||
    return value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)tableView:(NSTableView *)aTableView 
 | 
			
		||||
        setObjectValue:(id)value forTableColumn:(NSTableColumn *)aTableColumn 
 | 
			
		||||
        row:(NSInteger)rowIndex
 | 
			
		||||
{
 | 
			
		||||
    wxNSTableColumn* tablecol = (wxNSTableColumn *)aTableColumn;
 | 
			
		||||
    wxListBox* lb = dynamic_cast<wxListBox*>(impl->GetWXPeer());
 | 
			
		||||
    wxCocoaTableColumn* col = [tablecol column];
 | 
			
		||||
    wxNSTableViewCellValue cellvalue(value);
 | 
			
		||||
    lb->SetValueCallback(rowIndex, col, cellvalue);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSTableView
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxListWidgetCocoaImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
wxListWidgetCocoaImpl::wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data ) :
 | 
			
		||||
    wxWidgetCocoaImpl( peer, view ), m_tableView(tableview), m_dataSource(data)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wxListWidgetCocoaImpl::~wxListWidgetCocoaImpl()
 | 
			
		||||
{
 | 
			
		||||
    [m_dataSource release];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int wxListWidgetCocoaImpl::ListGetCount() const 
 | 
			
		||||
{
 | 
			
		||||
    wxListBox* lb = dynamic_cast<wxListBox*> ( GetWXPeer() );
 | 
			
		||||
    return lb->GetCount();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// columns
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
wxListWidgetColumn* wxListWidgetCocoaImpl::InsertTextColumn( unsigned pos, const wxString& title, bool editable, 
 | 
			
		||||
                                wxAlignment just, int defaultWidth) 
 | 
			
		||||
{
 | 
			
		||||
    wxNSTableColumn* col1 = [[wxNSTableColumn alloc] init];
 | 
			
		||||
    [col1 setEditable:editable];
 | 
			
		||||
    
 | 
			
		||||
    unsigned formerColCount = [m_tableView numberOfColumns];
 | 
			
		||||
    
 | 
			
		||||
    // there's apparently no way to insert at a specific position
 | 
			
		||||
    [m_tableView addTableColumn:col1 ];
 | 
			
		||||
    if ( pos < formerColCount )
 | 
			
		||||
        [m_tableView moveColumn:formerColCount toColumn:pos];
 | 
			
		||||
        
 | 
			
		||||
    if ( defaultWidth >= 0 )
 | 
			
		||||
    {
 | 
			
		||||
        [col1 setMaxWidth:defaultWidth];
 | 
			
		||||
        [col1 setMinWidth:defaultWidth];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    wxCocoaTableColumn* wxcol = new wxCocoaTableColumn( col1, editable );
 | 
			
		||||
    [col1 setColumn:wxcol];
 | 
			
		||||
 | 
			
		||||
    // owned by the tableview
 | 
			
		||||
    [col1 release];
 | 
			
		||||
    return wxcol;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wxListWidgetColumn* wxListWidgetCocoaImpl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable, 
 | 
			
		||||
                                wxAlignment just, int defaultWidth ) 
 | 
			
		||||
{
 | 
			
		||||
   wxNSTableColumn* col1 = [[wxNSTableColumn alloc] init];
 | 
			
		||||
    [col1 setEditable:editable];
 | 
			
		||||
 
 | 
			
		||||
    // set your custom cell & set it up
 | 
			
		||||
    NSButtonCell* checkbox = [[NSButtonCell alloc] init];
 | 
			
		||||
    [checkbox setTitle:@""];
 | 
			
		||||
    [checkbox setButtonType:NSSwitchButton];
 | 
			
		||||
    [col1 setDataCell:checkbox] ;
 | 
			
		||||
    [checkbox release];
 | 
			
		||||
             
 | 
			
		||||
    unsigned formerColCount = [m_tableView numberOfColumns];
 | 
			
		||||
    
 | 
			
		||||
    // there's apparently no way to insert at a specific position
 | 
			
		||||
    [m_tableView addTableColumn:col1 ];
 | 
			
		||||
    if ( pos < formerColCount )
 | 
			
		||||
        [m_tableView moveColumn:formerColCount toColumn:pos];
 | 
			
		||||
        
 | 
			
		||||
    if ( defaultWidth >= 0 )
 | 
			
		||||
    {
 | 
			
		||||
        [col1 setMaxWidth:defaultWidth];
 | 
			
		||||
        [col1 setMinWidth:defaultWidth];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    wxCocoaTableColumn* wxcol = new wxCocoaTableColumn( col1, editable );
 | 
			
		||||
    [col1 setColumn:wxcol];
 | 
			
		||||
 | 
			
		||||
    // owned by the tableview
 | 
			
		||||
    [col1 release];
 | 
			
		||||
    return wxcol;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// inserting / removing lines
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
void wxListWidgetCocoaImpl::ListInsert( unsigned int n ) 
 | 
			
		||||
{
 | 
			
		||||
#if 0
 | 
			
		||||
    {
 | 
			
		||||
        wxListBoxCocoaLine* line = new wxListBoxCocoaLine();
 | 
			
		||||
        line->SetLabel(items[i]);
 | 
			
		||||
        if ( m_items.size() <= n+i )
 | 
			
		||||
            m_items.push_back( line );
 | 
			
		||||
        else
 | 
			
		||||
            m_items.insert(m_items.begin()+n, line);
 | 
			
		||||
/*
 | 
			
		||||
        NSMutableDictionary* line = [[NSMutableDictionary alloc] init];
 | 
			
		||||
        [line setObject:wxCFStringRef(items[i]).AsNSString() forKey:column1];
 | 
			
		||||
        NSMutableArray* array = [m_dataSource items];
 | 
			
		||||
        if ( [array count] <= n+i )
 | 
			
		||||
            [array addObject:line];
 | 
			
		||||
        else
 | 
			
		||||
            [array insertObject:line atIndex:n];
 | 
			
		||||
*/
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    [m_tableView reloadData];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxListWidgetCocoaImpl::ListDelete( unsigned int n ) 
 | 
			
		||||
{
 | 
			
		||||
    [m_tableView reloadData];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxListWidgetCocoaImpl::ListClear() 
 | 
			
		||||
{
 | 
			
		||||
    [m_tableView reloadData];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// selecting
 | 
			
		||||
 | 
			
		||||
void wxListWidgetCocoaImpl::ListDeselectAll()
 | 
			
		||||
{
 | 
			
		||||
    [m_tableView deselectAll:nil];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxListWidgetCocoaImpl::ListSetSelection( unsigned int n, bool select, bool multi ) 
 | 
			
		||||
{
 | 
			
		||||
    // TODO
 | 
			
		||||
    if ( select )
 | 
			
		||||
        [m_tableView selectRow: n byExtendingSelection:multi];
 | 
			
		||||
    else
 | 
			
		||||
        [m_tableView deselectRow: n];
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int wxListWidgetCocoaImpl::ListGetSelection() const 
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int wxListWidgetCocoaImpl::ListGetSelections( wxArrayInt& aSelections ) const 
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool wxListWidgetCocoaImpl::ListIsSelected( unsigned int n ) const 
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// display
 | 
			
		||||
 | 
			
		||||
void wxListWidgetCocoaImpl::ListScrollTo( unsigned int n ) 
 | 
			
		||||
{
 | 
			
		||||
    [m_tableView scrollRowToVisible:n];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
void wxListWidgetCocoaImpl::UpdateLine( unsigned int n, wxListWidgetColumn* col ) 
 | 
			
		||||
{
 | 
			
		||||
    // TODO optimize
 | 
			
		||||
    [m_tableView reloadData];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int n) 
 | 
			
		||||
{
 | 
			
		||||
    // TODO optimize
 | 
			
		||||
    [m_tableView reloadData];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// accessing content
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, 
 | 
			
		||||
                                    wxWindowMac* parent, 
 | 
			
		||||
                                    wxWindowID id, 
 | 
			
		||||
                                    const wxPoint& pos, 
 | 
			
		||||
                                    const wxSize& size,
 | 
			
		||||
                                    long style, 
 | 
			
		||||
                                    long extraStyle)
 | 
			
		||||
{
 | 
			
		||||
    NSView* superv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSScrollView* scrollview = [[NSScrollView alloc] initWithFrame:r];
 | 
			
		||||
    
 | 
			
		||||
    // use same scroll flags logic as msw
 | 
			
		||||
    
 | 
			
		||||
    [scrollview setHasVerticalScroller:YES];
 | 
			
		||||
    
 | 
			
		||||
    if ( style & wxLB_HSCROLL )
 | 
			
		||||
        [scrollview setHasHorizontalScroller:YES];
 | 
			
		||||
    
 | 
			
		||||
    [scrollview setAutohidesScrollers: ((style & wxLB_ALWAYS_SB) ? NO : YES)];
 | 
			
		||||
    
 | 
			
		||||
    // setting up the true table
 | 
			
		||||
    
 | 
			
		||||
    wxNSTableView* tableview = [[wxNSTableView alloc] init];
 | 
			
		||||
    [scrollview setDocumentView:tableview];
 | 
			
		||||
    [tableview release];
 | 
			
		||||
    
 | 
			
		||||
    // only one multi-select mode available
 | 
			
		||||
    if ( (style & wxLB_EXTENDED) || (style & wxLB_MULTIPLE) )
 | 
			
		||||
        [tableview setAllowsMultipleSelection:YES];
 | 
			
		||||
        
 | 
			
		||||
    // simple listboxes have no header row
 | 
			
		||||
    [tableview setHeaderView:nil];
 | 
			
		||||
    
 | 
			
		||||
    [tableview setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];
 | 
			
		||||
    wxNSTableDataSource* ds = [[ wxNSTableDataSource alloc] init];
 | 
			
		||||
    [tableview setDataSource:ds];
 | 
			
		||||
    [superv addSubview:scrollview];
 | 
			
		||||
    wxListWidgetCocoaImpl* c = new wxListWidgetCocoaImpl( wxpeer, scrollview, tableview, ds );
 | 
			
		||||
    [tableview setImplementation:c];
 | 
			
		||||
    [ds setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int wxListBox::DoListHitTest(const wxPoint& inpoint) const
 | 
			
		||||
{
 | 
			
		||||
#if wxOSX_USE_CARBON
 | 
			
		||||
    OSStatus err;
 | 
			
		||||
 | 
			
		||||
    // There are few reasons why this is complicated:
 | 
			
		||||
    // 1) There is no native HitTest function for Mac
 | 
			
		||||
    // 2) GetDataBrowserItemPartBounds only works on visible items
 | 
			
		||||
    // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight
 | 
			
		||||
    //    because what it returns is basically inaccurate in the context
 | 
			
		||||
    //    of the coordinates we want here, but we use this as a guess
 | 
			
		||||
    //    for where the first visible item lies
 | 
			
		||||
 | 
			
		||||
    wxPoint point = inpoint;
 | 
			
		||||
 | 
			
		||||
    // get column property ID (req. for call to itempartbounds)
 | 
			
		||||
    DataBrowserTableViewColumnID colId = 0;
 | 
			
		||||
    err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId);
 | 
			
		||||
    wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));
 | 
			
		||||
 | 
			
		||||
    // OK, first we need to find the first visible item we have -
 | 
			
		||||
    // this will be the "low" for our binary search. There is no real
 | 
			
		||||
    // easy way around this, as we will need to do a SLOW linear search
 | 
			
		||||
    // until we find a visible item, but we can do a cheap calculation
 | 
			
		||||
    // via the row height to speed things up a bit
 | 
			
		||||
    UInt32 scrollx, scrolly;
 | 
			
		||||
    err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly);
 | 
			
		||||
    wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition"));
 | 
			
		||||
 | 
			
		||||
    UInt16 height;
 | 
			
		||||
    err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height);
 | 
			
		||||
    wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));
 | 
			
		||||
 | 
			
		||||
    // these indices are 0-based, as usual, so we need to add 1 to them when
 | 
			
		||||
    // passing them to data browser functions which use 1-based indices
 | 
			
		||||
    int low = scrolly / height,
 | 
			
		||||
        high = GetCount() - 1;
 | 
			
		||||
 | 
			
		||||
    // search for the first visible item (note that the scroll guess above
 | 
			
		||||
    // is the low bounds of where the item might lie so we only use that as a
 | 
			
		||||
    // starting point - we should reach it within 1 or 2 iterations of the loop)
 | 
			
		||||
    while ( low <= high )
 | 
			
		||||
    {
 | 
			
		||||
        Rect bounds;
 | 
			
		||||
        err = GetDataBrowserItemPartBounds(
 | 
			
		||||
            m_peer->GetControlRef(), low + 1, colId,
 | 
			
		||||
            kDataBrowserPropertyEnclosingPart,
 | 
			
		||||
            &bounds); // note +1 to translate to Mac ID
 | 
			
		||||
        if ( err == noErr )
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        // errDataBrowserItemNotFound is expected as it simply means that the
 | 
			
		||||
        // item is not currently visible -- but other errors are not
 | 
			
		||||
        wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND,
 | 
			
		||||
                     wxT("Unexpected error from GetDataBrowserItemPartBounds") );
 | 
			
		||||
 | 
			
		||||
        low++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // NOW do a binary search for where the item lies, searching low again if
 | 
			
		||||
    // we hit an item that isn't visible
 | 
			
		||||
    while ( low <= high )
 | 
			
		||||
    {
 | 
			
		||||
        int mid = (low + high) / 2;
 | 
			
		||||
 | 
			
		||||
        Rect bounds;
 | 
			
		||||
        err = GetDataBrowserItemPartBounds(
 | 
			
		||||
            m_peer->GetControlRef(), mid + 1, colId,
 | 
			
		||||
            kDataBrowserPropertyEnclosingPart,
 | 
			
		||||
            &bounds); //note +1 to trans to mac id
 | 
			
		||||
        wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound,
 | 
			
		||||
                     wxNOT_FOUND,
 | 
			
		||||
                     wxT("Unexpected error from GetDataBrowserItemPartBounds") );
 | 
			
		||||
 | 
			
		||||
        if ( err == errDataBrowserItemNotFound )
 | 
			
		||||
        {
 | 
			
		||||
            // item not visible, attempt to find a visible one
 | 
			
		||||
            // search lower
 | 
			
		||||
            high = mid - 1;
 | 
			
		||||
        }
 | 
			
		||||
        else // visible item, do actual hitttest
 | 
			
		||||
        {
 | 
			
		||||
            // if point is within the bounds, return this item (since we assume
 | 
			
		||||
            // all x coords of items are equal we only test the x coord in
 | 
			
		||||
            // equality)
 | 
			
		||||
            if ((point.x >= bounds.left && point.x <= bounds.right) &&
 | 
			
		||||
                (point.y >= bounds.top && point.y <= bounds.bottom) )
 | 
			
		||||
            {
 | 
			
		||||
                // found!
 | 
			
		||||
                return mid;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ( point.y < bounds.top )
 | 
			
		||||
                // index(bounds) greater then key(point)
 | 
			
		||||
                high = mid - 1;
 | 
			
		||||
            else
 | 
			
		||||
                // index(bounds) less then key(point)
 | 
			
		||||
                low = mid + 1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    return wxNOT_FOUND;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // wxUSE_LISTBOX
 | 
			
		||||
							
								
								
									
										193
									
								
								src/osx/cocoa/menu.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										193
									
								
								src/osx/cocoa/menu.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,193 @@
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        src/osx/cocoa/menu.mm
 | 
			
		||||
// Purpose:     wxMenu, wxMenuBar, wxMenuItem
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by:
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:     wxWindows licence
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
// ============================================================================
 | 
			
		||||
// headers & declarations
 | 
			
		||||
// ============================================================================
 | 
			
		||||
 | 
			
		||||
// wxWidgets headers
 | 
			
		||||
// -----------------
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#include "wx/menu.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WX_PRECOMP
 | 
			
		||||
    #include "wx/log.h"
 | 
			
		||||
    #include "wx/app.h"
 | 
			
		||||
    #include "wx/utils.h"
 | 
			
		||||
    #include "wx/frame.h"
 | 
			
		||||
    #include "wx/menuitem.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
// other standard headers
 | 
			
		||||
// ----------------------
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
@class wxNSMenuItem;
 | 
			
		||||
 | 
			
		||||
@interface wxNSMenu : NSMenu
 | 
			
		||||
{
 | 
			
		||||
   wxMenuImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) setImplementation:(wxMenuImpl*) item;
 | 
			
		||||
- (wxMenuImpl*) implementation;
 | 
			
		||||
 | 
			
		||||
@end 
 | 
			
		||||
 | 
			
		||||
@implementation wxNSMenu
 | 
			
		||||
 | 
			
		||||
- (id) init
 | 
			
		||||
{
 | 
			
		||||
    [super init];
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxMenuImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxMenuImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@interface wxNSMenuController : NSObject
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)menuWillOpen:(NSMenu *)menu;
 | 
			
		||||
- (void)menuDidClose:(NSMenu *)menu;
 | 
			
		||||
- (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSMenuController
 | 
			
		||||
 | 
			
		||||
- (id) init
 | 
			
		||||
{
 | 
			
		||||
    [super init];
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)menuWillOpen:(NSMenu *)smenu
 | 
			
		||||
{
 | 
			
		||||
    wxNSMenu* menu = (wxNSMenu*) smenu;
 | 
			
		||||
    wxMenuImpl* menuimpl = [menu implementation];
 | 
			
		||||
    if ( menuimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer();
 | 
			
		||||
        wxpeer->HandleMenuOpened();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)menuDidClose:(NSMenu *)smenu
 | 
			
		||||
{
 | 
			
		||||
    wxNSMenu* menu = (wxNSMenu*) smenu;
 | 
			
		||||
    wxMenuImpl* menuimpl = [menu implementation];
 | 
			
		||||
    if ( menuimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer();
 | 
			
		||||
        wxpeer->HandleMenuClosed();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)menu:(NSMenu *)smenu willHighlightItem:(NSMenuItem *)item
 | 
			
		||||
{
 | 
			
		||||
    wxNSMenu* menu = (wxNSMenu*) smenu;
 | 
			
		||||
    wxMenuImpl* menuimpl = [menu implementation];
 | 
			
		||||
    if ( menuimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer();
 | 
			
		||||
        if ( [ item isKindOfClass:[wxNSMenuItem class] ] )
 | 
			
		||||
        {
 | 
			
		||||
            wxMenuItemImpl* menuitemimpl = (wxMenuItemImpl*) [ (wxNSMenuItem*) item implementation ];
 | 
			
		||||
            if ( wxpeer && menuitemimpl )
 | 
			
		||||
            {
 | 
			
		||||
                wxpeer->HandleMenuItemHighlighted( menuitemimpl->GetWXPeer() );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
class wxMenuCocoaImpl : public wxMenuImpl 
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxMenuCocoaImpl( wxMenu* peer , NSMenu* menu) : wxMenuImpl(peer), m_osxMenu(menu)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    virtual ~wxMenuCocoaImpl();
 | 
			
		||||
        
 | 
			
		||||
    virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) 
 | 
			
		||||
    {
 | 
			
		||||
        if ( pos == (size_t) -1 )
 | 
			
		||||
            [m_osxMenu addItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem() ];
 | 
			
		||||
        else
 | 
			
		||||
            [m_osxMenu insertItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem() atIndex:pos];
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
    virtual void Remove( wxMenuItem *pItem ) 
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxMenu removeItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem()];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    virtual void MakeRoot()
 | 
			
		||||
    {
 | 
			
		||||
        [NSApp setMainMenu:m_osxMenu];
 | 
			
		||||
        [NSApp setAppleMenu:[[m_osxMenu itemAtIndex:0] submenu]];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void Enable( bool enable )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    virtual void SetTitle( const wxString& text )
 | 
			
		||||
    {
 | 
			
		||||
        wxCFStringRef cfText(text);
 | 
			
		||||
        [m_osxMenu setTitle:cfText.AsNSString()];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WXHMENU GetHMenu() { return m_osxMenu; }
 | 
			
		||||
 | 
			
		||||
    static wxMenuImpl* Create( wxMenu* peer, const wxString& title );
 | 
			
		||||
    static wxMenuImpl* CreateRootMenu( wxMenu* peer );
 | 
			
		||||
protected :
 | 
			
		||||
    NSMenu* m_osxMenu;
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
wxMenuCocoaImpl::~wxMenuCocoaImpl()
 | 
			
		||||
{
 | 
			
		||||
    [m_osxMenu release];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wxMenuImpl* wxMenuImpl::Create( wxMenu* peer, const wxString& title )
 | 
			
		||||
{
 | 
			
		||||
    static wxNSMenuController* controller = NULL;
 | 
			
		||||
    if ( controller == NULL )
 | 
			
		||||
    {
 | 
			
		||||
        controller = [[wxNSMenuController alloc] init];
 | 
			
		||||
    }
 | 
			
		||||
    wxCFStringRef cfText( title );
 | 
			
		||||
    wxNSMenu* menu = [[wxNSMenu alloc] initWithTitle:cfText.AsNSString()];
 | 
			
		||||
    wxMenuImpl* c = new wxMenuCocoaImpl( peer, menu );
 | 
			
		||||
    [menu setDelegate:controller];
 | 
			
		||||
    [menu setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										274
									
								
								src/osx/cocoa/menuitem.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										274
									
								
								src/osx/cocoa/menuitem.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,274 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        src/osx/cocoa/menuitem.mm
 | 
			
		||||
// Purpose:     wxMenuItem implementation
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by:
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: menuitem.cpp 54129 2008-06-11 19:30:52Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:     wxWindows licence
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#include "wx/menuitem.h"
 | 
			
		||||
#include "wx/stockitem.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WX_PRECOMP
 | 
			
		||||
    #include "wx/app.h"
 | 
			
		||||
    #include "wx/menu.h"
 | 
			
		||||
#endif // WX_PRECOMP
 | 
			
		||||
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
@interface wxNSMenuItem : NSMenuItem
 | 
			
		||||
{
 | 
			
		||||
   wxMenuItemImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) setImplementation:(wxMenuItemImpl*) item;
 | 
			
		||||
- (wxMenuItemImpl*) implementation;
 | 
			
		||||
 | 
			
		||||
- (void) clickedAction: (id) sender;
 | 
			
		||||
- (BOOL)validateMenuItem:(NSMenuItem *) menuItem;
 | 
			
		||||
 | 
			
		||||
@end 
 | 
			
		||||
 | 
			
		||||
@implementation wxNSMenuItem
 | 
			
		||||
 | 
			
		||||
- (id) init
 | 
			
		||||
{
 | 
			
		||||
    [super init];
 | 
			
		||||
     return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) clickedAction: (id) sender
 | 
			
		||||
{
 | 
			
		||||
    if ( impl )
 | 
			
		||||
    {
 | 
			
		||||
        impl->GetWXPeer()->GetMenu()->HandleCommandProcess(impl->GetWXPeer());
 | 
			
		||||
     }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL)validateMenuItem:(NSMenuItem *) menuItem
 | 
			
		||||
{
 | 
			
		||||
    if( impl )
 | 
			
		||||
    {
 | 
			
		||||
        impl->GetWXPeer()->GetMenu()->HandleCommandUpdateStatus(impl->GetWXPeer());
 | 
			
		||||
        return impl->GetWXPeer()->IsEnabled();
 | 
			
		||||
    }
 | 
			
		||||
    return YES ;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxMenuItemImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxMenuItemImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
void wxMacCocoaMenuItemSetAccelerator( NSMenuItem* menuItem, wxAcceleratorEntry* entry )
 | 
			
		||||
{
 | 
			
		||||
    unsigned int modifiers = 0 ;
 | 
			
		||||
    int key = entry->GetKeyCode() ;
 | 
			
		||||
    if ( key )
 | 
			
		||||
    {
 | 
			
		||||
        if (entry->GetFlags() & wxACCEL_CTRL);
 | 
			
		||||
            modifiers |= NSCommandKeyMask;
 | 
			
		||||
 | 
			
		||||
        if (entry->GetFlags() & wxACCEL_ALT)
 | 
			
		||||
            modifiers |= NSAlternateKeyMask ;
 | 
			
		||||
 | 
			
		||||
        // this may be ignored later for alpha chars
 | 
			
		||||
 | 
			
		||||
        if (entry->GetFlags() & wxACCEL_SHIFT)
 | 
			
		||||
            modifiers |= NSShiftKeyMask ;
 | 
			
		||||
 | 
			
		||||
        unichar shortcut = 0;
 | 
			
		||||
        if ( key >= WXK_F1 && key <= WXK_F15 )
 | 
			
		||||
        {
 | 
			
		||||
            modifiers |= NSFunctionKeyMask ;
 | 
			
		||||
            shortcut = NSF1FunctionKey + ( key - WXK_F1 );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            switch ( key )
 | 
			
		||||
            {
 | 
			
		||||
/*
 | 
			
		||||
                // standard function keys from here
 | 
			
		||||
                case WXK_TAB :
 | 
			
		||||
                    modifiers |= NSFunctionKeyMask ;
 | 
			
		||||
                    shortcut = NSTabCharacter ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case kEnterCharCode :
 | 
			
		||||
                    modifiers |= NSFunctionKeyMask ;
 | 
			
		||||
                    cocoaKey = NSTabCharacter ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_RETURN :
 | 
			
		||||
                    modifiers |= NSFunctionKeyMask ;
 | 
			
		||||
                    cocoaKey = NSTabCharacter ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_ESCAPE :
 | 
			
		||||
                    modifiers |= NSFunctionKeyMask ;
 | 
			
		||||
                    cocoaKey = kEscapeCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_SPACE :
 | 
			
		||||
                    shortcut = ' ' ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                case WXK_CLEAR :
 | 
			
		||||
                    cocoaKey = kClearCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_PAGEUP :
 | 
			
		||||
                    cocoaKey = kPageUpCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_PAGEDOWN :
 | 
			
		||||
                    cocoaKey = kPageDownCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_LEFT :
 | 
			
		||||
                    cocoaKey = kLeftArrowCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_UP :
 | 
			
		||||
                    cocoaKey = kUpArrowCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_RIGHT :
 | 
			
		||||
                    cocoaKey = kRightArrowCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_DOWN :
 | 
			
		||||
                    cocoaKey = kDownArrowCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_HOME :
 | 
			
		||||
                    cocoaKey = kHomeCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
 | 
			
		||||
                case WXK_END :
 | 
			
		||||
                    cocoaKey = kEndCharCode ;
 | 
			
		||||
                    break ;
 | 
			
		||||
*/
 | 
			
		||||
                // TODO Test all above with their function key equiv.
 | 
			
		||||
                // from NSEvent.h
 | 
			
		||||
                default :
 | 
			
		||||
                    if(entry->GetFlags() & wxACCEL_SHIFT)
 | 
			
		||||
                        shortcut = toupper(key);
 | 
			
		||||
                    else
 | 
			
		||||
                        shortcut = tolower(key);
 | 
			
		||||
                    break ;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [menuItem setKeyEquivalent:[NSString stringWithCharacters:&shortcut length:1]];
 | 
			
		||||
        [menuItem setKeyEquivalentModifierMask:modifiers];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class wxMenuItemCocoaImpl : public wxMenuItemImpl 
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxMenuItemCocoaImpl( wxMenuItem* peer, NSMenuItem* item ) : wxMenuItemImpl(peer), m_osxMenuItem(item)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    ~wxMenuItemCocoaImpl();
 | 
			
		||||
        
 | 
			
		||||
    void SetBitmap( const wxBitmap& bitmap ) 
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxMenuItem setImage:bitmap.GetNSImage()];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void Enable( bool enable ) 
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxMenuItem setEnabled:enable];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void Check( bool check ) 
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxMenuItem setState:( check ?  NSOnState :  NSOffState) ];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void Hide( bool hide )
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxMenuItem setHidden:hide ];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void SetLabel( const wxString& text, wxAcceleratorEntry *entry ) 
 | 
			
		||||
    {
 | 
			
		||||
        wxCFStringRef cfText(text);
 | 
			
		||||
        [m_osxMenuItem setTitle:cfText.AsNSString()];
 | 
			
		||||
        
 | 
			
		||||
        if ( entry )
 | 
			
		||||
            wxMacCocoaMenuItemSetAccelerator( m_osxMenuItem, entry );
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void * GetHMenuItem() { return m_osxMenuItem; }
 | 
			
		||||
 | 
			
		||||
protected :
 | 
			
		||||
    NSMenuItem* m_osxMenuItem ;
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
wxMenuItemCocoaImpl::~wxMenuItemCocoaImpl()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer, wxMenu *pParentMenu,
 | 
			
		||||
                       int id,
 | 
			
		||||
                       const wxString& text,
 | 
			
		||||
                       wxAcceleratorEntry *entry,
 | 
			
		||||
                       const wxString& strHelp,
 | 
			
		||||
                       wxItemKind kind,
 | 
			
		||||
                       wxMenu *pSubMenu )
 | 
			
		||||
{
 | 
			
		||||
    wxMenuItemImpl* c = NULL;
 | 
			
		||||
    NSMenuItem* item = nil;
 | 
			
		||||
    
 | 
			
		||||
    if ( kind == wxITEM_SEPARATOR )
 | 
			
		||||
    {
 | 
			
		||||
        item = [[NSMenuItem separatorItem] retain];
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        wxCFStringRef cfText(text);
 | 
			
		||||
        wxNSMenuItem* temp = [ [ wxNSMenuItem alloc ] init ];
 | 
			
		||||
        if ( ! pParentMenu->GetNoEventsMode() )
 | 
			
		||||
        {
 | 
			
		||||
            [temp setTarget: temp];
 | 
			
		||||
            [temp setAction: @selector(clickedAction:)];
 | 
			
		||||
        }
 | 
			
		||||
        [temp setTitle:cfText.AsNSString()];
 | 
			
		||||
        if ( pSubMenu )
 | 
			
		||||
        {
 | 
			
		||||
            pSubMenu->GetPeer()->SetTitle( text );
 | 
			
		||||
            [temp setSubmenu:pSubMenu->GetHMenu()];
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if ( entry )
 | 
			
		||||
                wxMacCocoaMenuItemSetAccelerator( temp, entry );
 | 
			
		||||
        }
 | 
			
		||||
        item = temp;
 | 
			
		||||
    }
 | 
			
		||||
    c = new wxMenuItemCocoaImpl( peer, item );
 | 
			
		||||
    if ( kind != wxITEM_SEPARATOR )
 | 
			
		||||
    {
 | 
			
		||||
        [(wxNSMenuItem*)item setImplementation:c];
 | 
			
		||||
    }
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
@@ -21,9 +21,6 @@
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if wxOSX_USE_COCOA
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
NSRect wxToNSRect( NSView* parent, const wxRect& r )
 | 
			
		||||
{
 | 
			
		||||
    NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
 | 
			
		||||
@@ -64,6 +61,143 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
 | 
			
		||||
    return wxPoint( x, y);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// wx native implementation classes
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
@interface wxNSWindow : NSWindow
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    wxNonOwnedWindowCocoaImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation;
 | 
			
		||||
- (wxNonOwnedWindowCocoaImpl*) implementation;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSWindow
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxNonOwnedWindowCocoaImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@interface wxNSPanel : wxNSWindow
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSPanel 
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// controller
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
@interface wxNonOwnedWindowController : NSObject
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)windowDidResize:(NSNotification *)notification;
 | 
			
		||||
- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
 | 
			
		||||
- (void)windowDidResignMain:(NSNotification *)notification;
 | 
			
		||||
- (void)windowDidBecomeMain:(NSNotification *)notification;
 | 
			
		||||
- (void)windowDidMove:(NSNotification *)notification;
 | 
			
		||||
- (BOOL)windowShouldClose:(id)window;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNonOwnedWindowController
 | 
			
		||||
 | 
			
		||||
- (id) init
 | 
			
		||||
{
 | 
			
		||||
    [super init];
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL)windowShouldClose:(id)nwindow
 | 
			
		||||
{
 | 
			
		||||
    wxNSWindow* window = (wxNSWindow*) nwindow;
 | 
			
		||||
    wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
 | 
			
		||||
    if ( windowimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->Close();
 | 
			
		||||
    }
 | 
			
		||||
    return NO;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (NSSize)windowWillResize:(NSWindow *)window
 | 
			
		||||
                    toSize:(NSSize)proposedFrameSize
 | 
			
		||||
{
 | 
			
		||||
    // todo
 | 
			
		||||
    return proposedFrameSize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)windowDidResize:(NSNotification *)notification
 | 
			
		||||
{
 | 
			
		||||
    wxNSWindow* window = (wxNSWindow*) [notification object];
 | 
			
		||||
    wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
 | 
			
		||||
    if ( windowimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleResized(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)windowDidMove:(NSNotification *)notification
 | 
			
		||||
{
 | 
			
		||||
    wxNSWindow* window = (wxNSWindow*) [notification object];
 | 
			
		||||
    wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
 | 
			
		||||
    if ( windowimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleMoved(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)windowDidBecomeMain:(NSNotification *)notification
 | 
			
		||||
{
 | 
			
		||||
    wxNSWindow* window = (wxNSWindow*) [notification object];
 | 
			
		||||
    wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
 | 
			
		||||
    if ( windowimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleActivated(0, true);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)windowDidResignMain:(NSNotification *)notification
 | 
			
		||||
{
 | 
			
		||||
    wxNSWindow* window = (wxNSWindow*) [notification object];
 | 
			
		||||
    wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
 | 
			
		||||
    if ( windowimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleActivated(0, false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
 | 
			
		||||
 | 
			
		||||
wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) : 
 | 
			
		||||
@@ -92,12 +226,18 @@ void wxNonOwnedWindowCocoaImpl::Destroy()
 | 
			
		||||
void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
 | 
			
		||||
long style, long extraStyle, const wxString& name )
 | 
			
		||||
{
 | 
			
		||||
    static wxNonOwnedWindowController* controller = NULL;
 | 
			
		||||
    
 | 
			
		||||
    if ( !controller )
 | 
			
		||||
        controller =[[wxNonOwnedWindowController alloc] init];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    int windowstyle = NSBorderlessWindowMask;
 | 
			
		||||
    
 | 
			
		||||
    if ( style & wxFRAME_TOOL_WINDOW )
 | 
			
		||||
        m_macWindow = [NSPanel alloc];
 | 
			
		||||
        m_macWindow = [wxNSPanel alloc];
 | 
			
		||||
    else
 | 
			
		||||
        m_macWindow = [NSWindow alloc];
 | 
			
		||||
        m_macWindow = [wxNSWindow alloc];
 | 
			
		||||
    
 | 
			
		||||
    CGWindowLevel level = kCGNormalWindowLevelKey;
 | 
			
		||||
    
 | 
			
		||||
@@ -180,6 +320,8 @@ long style, long extraStyle, const wxString& name )
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
 | 
			
		||||
    
 | 
			
		||||
    [m_macWindow setImplementation:this];
 | 
			
		||||
    
 | 
			
		||||
    [m_macWindow initWithContentRect:r
 | 
			
		||||
        styleMask:windowstyle
 | 
			
		||||
        backing:NSBackingStoreBuffered
 | 
			
		||||
@@ -187,6 +329,9 @@ long style, long extraStyle, const wxString& name )
 | 
			
		||||
        ];
 | 
			
		||||
        
 | 
			
		||||
    [m_macWindow setLevel:level];
 | 
			
		||||
 | 
			
		||||
    [m_macWindow setDelegate:controller];
 | 
			
		||||
    
 | 
			
		||||
    // [m_macWindow makeKeyAndOrderFront:nil];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -373,4 +518,38 @@ bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long style)
 | 
			
		||||
void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int WXUNUSED(flags))
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
 | 
			
		||||
{
 | 
			
		||||
    wxPoint p((x ? *x : 0), (y ? *y : 0) );
 | 
			
		||||
    /*
 | 
			
		||||
    NSPoint nspt = wxToNSPoint( NULL, p );
 | 
			
		||||
    
 | 
			
		||||
    nspt = [[m_macWindow contentView] convertPoint:p toV:nil];
 | 
			
		||||
    p = wxFromNSPoint( 
 | 
			
		||||
    */
 | 
			
		||||
    if ( x )
 | 
			
		||||
        *x = p.x;
 | 
			
		||||
    if ( y )
 | 
			
		||||
        *y = p.y;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
 | 
			
		||||
{
 | 
			
		||||
    wxPoint p(  (x ? *x : 0), (y ? *y : 0) );
 | 
			
		||||
    /*
 | 
			
		||||
    p = [m_macWindow convertPoint:p toWindow:nil];
 | 
			
		||||
    */
 | 
			
		||||
    if ( x )
 | 
			
		||||
        *x = p.x;
 | 
			
		||||
    if ( y )
 | 
			
		||||
        *y = p.y;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
 | 
			
		||||
    long style, long extraStyle, const wxString& name )
 | 
			
		||||
{
 | 
			
		||||
    wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
 | 
			
		||||
    now->Create( parent, pos, size, style , extraStyle, name );
 | 
			
		||||
    return now;
 | 
			
		||||
}
 | 
			
		||||
@@ -26,29 +26,73 @@
 | 
			
		||||
#include "wx/imaglist.h"
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
@interface wxNSTabView : NSTabView
 | 
			
		||||
//
 | 
			
		||||
// controller
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
@interface wxTabViewController : NSObject
 | 
			
		||||
{
 | 
			
		||||
    wxWidgetImpl* m_impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
 | 
			
		||||
- (wxWidgetImpl*) implementation;
 | 
			
		||||
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem;
 | 
			
		||||
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@interface wxNSTabView : NSTabView
 | 
			
		||||
{
 | 
			
		||||
    wxWidgetCocoaImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
 | 
			
		||||
- (wxWidgetCocoaImpl*) implementation;
 | 
			
		||||
- (BOOL) isFlipped;
 | 
			
		||||
- (int) intValue;
 | 
			
		||||
- (void) setIntValue:(int) v;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxTabViewController
 | 
			
		||||
 | 
			
		||||
- (id) init
 | 
			
		||||
{
 | 
			
		||||
    [super init];
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
 | 
			
		||||
{
 | 
			
		||||
    wxNSTabView* view = (wxNSTabView*) tabView;
 | 
			
		||||
    wxWidgetCocoaImpl* viewimpl = [view implementation];
 | 
			
		||||
    if ( viewimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
 | 
			
		||||
    }
 | 
			
		||||
    return YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    wxNSTabView* view = (wxNSTabView*) tabView;
 | 
			
		||||
    wxWidgetCocoaImpl* viewimpl = [view implementation];
 | 
			
		||||
    if ( viewimpl )
 | 
			
		||||
    {
 | 
			
		||||
        wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
 | 
			
		||||
        wxpeer->HandleClicked(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSTabView
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    m_impl = theImplementation;
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
- (wxWidgetCocoaImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return m_impl;
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
@@ -56,21 +100,98 @@
 | 
			
		||||
    return YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (int) intValue
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
class wxCocoaTabView : public wxWidgetCocoaImpl
 | 
			
		||||
{
 | 
			
		||||
    NSTabViewItem* selectedItem = [self selectedTabViewItem];
 | 
			
		||||
public:
 | 
			
		||||
    wxCocoaTabView( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void GetContentArea( int &left , int &top , int &width , int &height ) const 
 | 
			
		||||
    {
 | 
			
		||||
        wxNSTabView* slf = (wxNSTabView*) m_osxView;
 | 
			
		||||
        NSRect r = [slf contentRect];
 | 
			
		||||
        left = r.origin.x;
 | 
			
		||||
        top = r.origin.y;
 | 
			
		||||
        width = r.size.width;
 | 
			
		||||
        height = r.size.height;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void SetValue( wxInt32 value ) 
 | 
			
		||||
    {
 | 
			
		||||
        wxNSTabView* slf = (wxNSTabView*) m_osxView;
 | 
			
		||||
        // avoid 'changed' events when setting the tab programmatically
 | 
			
		||||
        wxTabViewController* controller = [slf delegate];
 | 
			
		||||
        [slf setDelegate:nil];
 | 
			
		||||
        [slf selectTabViewItemAtIndex:(value-1)];
 | 
			
		||||
        [slf setDelegate:controller];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    wxInt32 GetValue() const
 | 
			
		||||
    {
 | 
			
		||||
        wxNSTabView* slf = (wxNSTabView*) m_osxView;
 | 
			
		||||
        NSTabViewItem* selectedItem = [slf selectedTabViewItem];
 | 
			
		||||
        if ( selectedItem == nil )
 | 
			
		||||
            return 0;
 | 
			
		||||
        else
 | 
			
		||||
        return [self indexOfTabViewItem:selectedItem]+1;
 | 
			
		||||
            return [slf indexOfTabViewItem:selectedItem]+1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
- (void) setIntValue:(int) v
 | 
			
		||||
    void SetMaximum( wxInt32 maximum )
 | 
			
		||||
    {
 | 
			
		||||
    [self selectTabViewItemAtIndex:(v-1)];
 | 
			
		||||
        wxNSTabView* slf = (wxNSTabView*) m_osxView;
 | 
			
		||||
        int cocoacount = [slf numberOfTabViewItems ];
 | 
			
		||||
        // avoid 'changed' events when setting the tab programmatically
 | 
			
		||||
        wxTabViewController* controller = [slf delegate];
 | 
			
		||||
        [slf setDelegate:nil];
 | 
			
		||||
        
 | 
			
		||||
        if ( maximum > cocoacount )
 | 
			
		||||
        {
 | 
			
		||||
            for ( int i = cocoacount ; i < maximum ; ++i )
 | 
			
		||||
            {
 | 
			
		||||
                NSTabViewItem* item = [[NSTabViewItem alloc] init];
 | 
			
		||||
                [slf addTabViewItem:item];
 | 
			
		||||
                [item release];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else if ( maximum < cocoacount )
 | 
			
		||||
        {
 | 
			
		||||
            for ( int i = cocoacount -1 ; i >= maximum ; --i )
 | 
			
		||||
            {
 | 
			
		||||
                NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
 | 
			
		||||
                [slf removeTabViewItem:item];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        [slf setDelegate:controller];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
    void SetupTabs( const wxNotebook& notebook)
 | 
			
		||||
    {
 | 
			
		||||
        int pcount = notebook.GetPageCount();
 | 
			
		||||
        
 | 
			
		||||
        SetMaximum( pcount );
 | 
			
		||||
        
 | 
			
		||||
        for ( int i = 0 ; i < pcount ; ++i )
 | 
			
		||||
        {
 | 
			
		||||
            wxNotebookPage* page = notebook.GetPage(i);
 | 
			
		||||
            NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i];
 | 
			
		||||
            [item setView:page->GetHandle() ];
 | 
			
		||||
            wxCFStringRef cf( page->GetLabel() , notebook.GetFont().GetEncoding() );
 | 
			
		||||
            [item setLabel:cf.AsNSString()];
 | 
			
		||||
            if ( notebook.GetImageList() && notebook.GetPageImage(i) >= 0 )
 | 
			
		||||
            {
 | 
			
		||||
                const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ;
 | 
			
		||||
                if ( bmap.Ok() )
 | 
			
		||||
                {
 | 
			
		||||
                    // TODO how to set an image on a tab
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
#if 0
 | 
			
		||||
@@ -120,15 +241,14 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
 | 
			
		||||
                                    long style, 
 | 
			
		||||
                                    long extraStyle)
 | 
			
		||||
{
 | 
			
		||||
    static wxTabViewController* controller = NULL;
 | 
			
		||||
 | 
			
		||||
    if ( !controller )
 | 
			
		||||
        controller =[[wxTabViewController alloc] init];
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    */
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    
 | 
			
		||||
    NSTabViewType tabstyle = NSTopTabsBezelBorder;
 | 
			
		||||
    if ( style & wxBK_LEFT )
 | 
			
		||||
@@ -141,77 +261,10 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
 | 
			
		||||
    wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    [v setTabViewType:tabstyle];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
 | 
			
		||||
    [v setImplementation:c];
 | 
			
		||||
    [v setDelegate: controller];
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
@@ -27,8 +27,7 @@ wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 | 
			
		||||
 | 
			
		||||
    [v setButtonType:NSRadioButton];    
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										123
									
								
								src/osx/cocoa/scrolbar.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								src/osx/cocoa/scrolbar.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,123 @@
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        src/osx/cocoa/scrolbar.mm
 | 
			
		||||
// Purpose:     wxScrollBar
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by:
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: scrolbar.cpp 54129 2008-06-11 19:30:52Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:       wxWindows licence
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#include "wx/scrolbar.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WX_PRECOMP
 | 
			
		||||
    #include "wx/intl.h"
 | 
			
		||||
    #include "wx/log.h"
 | 
			
		||||
    #include "wx/settings.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
@interface wxNSScroller : NSScroller
 | 
			
		||||
{
 | 
			
		||||
    wxWidgetImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
 | 
			
		||||
- (wxWidgetImpl*) implementation;
 | 
			
		||||
- (BOOL) isFlipped;
 | 
			
		||||
 - (void) clickedAction: (id) sender;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSScroller
 | 
			
		||||
 | 
			
		||||
- (id)initWithFrame:(NSRect)frame
 | 
			
		||||
{
 | 
			
		||||
    [super initWithFrame:frame];
 | 
			
		||||
    impl = NULL;
 | 
			
		||||
    [self setTarget: self];
 | 
			
		||||
    [self setAction: @selector(clickedAction:)];
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) clickedAction: (id) sender
 | 
			
		||||
{
 | 
			
		||||
    if ( impl )
 | 
			
		||||
    {
 | 
			
		||||
        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleClicked(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl ;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
{
 | 
			
		||||
    return YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void SetMaximum(wxInt32 v)
 | 
			
		||||
    {
 | 
			
		||||
        m_maximum = v;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    void    SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) 
 | 
			
		||||
    {
 | 
			
		||||
        double v = ((double) value)/m_maximum;
 | 
			
		||||
        double t = ((double) thumbSize)/m_maximum;
 | 
			
		||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
 | 
			
		||||
        [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
 | 
			
		||||
#else
 | 
			
		||||
        [(wxNSScroller*) m_osxView setDoubleValue:v];
 | 
			
		||||
        [(wxNSScroller*) m_osxView setKnobProportion:t];
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    wxInt32 GetValue() const
 | 
			
		||||
    {
 | 
			
		||||
        return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
 | 
			
		||||
    }
 | 
			
		||||
protected:
 | 
			
		||||
    wxInt32 m_maximum;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, 
 | 
			
		||||
                                    wxWindowMac* parent, 
 | 
			
		||||
                                    wxWindowID id, 
 | 
			
		||||
                                    const wxPoint& pos, 
 | 
			
		||||
                                    const wxSize& size,
 | 
			
		||||
                                    long style, 
 | 
			
		||||
                                    long extraStyle)
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
 | 
			
		||||
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
 | 
			
		||||
    [v setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										108
									
								
								src/osx/cocoa/slider.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								src/osx/cocoa/slider.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,108 @@
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        src/osx/cocoa/slider.mm
 | 
			
		||||
// Purpose:     wxSlider
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by:
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: slider.cpp 54129 2008-06-11 19:30:52Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:       wxWindows licence
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#if wxUSE_SLIDER
 | 
			
		||||
 | 
			
		||||
#include "wx/slider.h"
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
@interface wxNSSlider : NSSlider
 | 
			
		||||
{
 | 
			
		||||
    wxWidgetImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
 | 
			
		||||
- (wxWidgetImpl*) implementation;
 | 
			
		||||
- (BOOL) isFlipped;
 | 
			
		||||
 - (void) clickedAction: (id) sender;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@implementation wxNSSlider
 | 
			
		||||
 | 
			
		||||
- (id)initWithFrame:(NSRect)frame
 | 
			
		||||
{
 | 
			
		||||
    [super initWithFrame:frame];
 | 
			
		||||
    impl = NULL;
 | 
			
		||||
    [self setTarget: self];
 | 
			
		||||
    [self setAction: @selector(clickedAction:)];
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void) clickedAction: (id) sender
 | 
			
		||||
{
 | 
			
		||||
    if ( impl )
 | 
			
		||||
    {
 | 
			
		||||
        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
 | 
			
		||||
        if ( wxpeer )
 | 
			
		||||
            wxpeer->HandleClicked(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
{
 | 
			
		||||
    return YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, 
 | 
			
		||||
                                    wxWindowMac* parent, 
 | 
			
		||||
                                    wxWindowID id, 
 | 
			
		||||
                                    wxInt32 value,
 | 
			
		||||
                                    wxInt32 minimum,
 | 
			
		||||
                                    wxInt32 maximum,
 | 
			
		||||
                                    const wxPoint& pos, 
 | 
			
		||||
                                    const wxSize& size,
 | 
			
		||||
                                    long style, 
 | 
			
		||||
                                    long extraStyle)
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
 | 
			
		||||
 | 
			
		||||
    int tickMarks = 0;
 | 
			
		||||
    if ( style & wxSL_AUTOTICKS )
 | 
			
		||||
    {
 | 
			
		||||
        tickMarks = (maximum - minimum) + 1; // +1 for the 0 value
 | 
			
		||||
 | 
			
		||||
        // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast
 | 
			
		||||
        // it to a UInt16
 | 
			
		||||
        while (tickMarks > 20)
 | 
			
		||||
            tickMarks /= 5;
 | 
			
		||||
            
 | 
			
		||||
        [v setNumberOfTickMarks:tickMarks];
 | 
			
		||||
        [v setTickMarkPosition:NSTickMarkBelow];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [v setMinValue: minimum];
 | 
			
		||||
    [v setMaxValue: maximum];
 | 
			
		||||
    [v setFloatValue: (double) value];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
 | 
			
		||||
    [v setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // wxUSE_SLIDER
 | 
			
		||||
@@ -16,6 +16,25 @@
 | 
			
		||||
#include "wx/statbox.h"
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
 | 
			
		||||
@implementation wxNSBox
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
{
 | 
			
		||||
    return NO;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer, 
 | 
			
		||||
                                    wxWindowMac* parent, 
 | 
			
		||||
                                    wxWindowID id, 
 | 
			
		||||
@@ -27,8 +46,7 @@ wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
 | 
			
		||||
 
 | 
			
		||||
@@ -33,25 +33,6 @@
 | 
			
		||||
 | 
			
		||||
#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, 
 | 
			
		||||
@@ -62,8 +43,7 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticLine( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
 | 
			
		||||
 
 | 
			
		||||
@@ -92,43 +92,6 @@ wxSize wxStaticText::DoGetBestSize() const
 | 
			
		||||
          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, 
 | 
			
		||||
@@ -140,8 +103,7 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										138
									
								
								src/osx/cocoa/textctrl.mm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								src/osx/cocoa/textctrl.mm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,138 @@
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Name:        src/osx/cocoa/textctrl.mm
 | 
			
		||||
// Purpose:     wxTextCtrl
 | 
			
		||||
// Author:      Stefan Csomor
 | 
			
		||||
// Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
 | 
			
		||||
// Created:     1998-01-01
 | 
			
		||||
// RCS-ID:      $Id: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $
 | 
			
		||||
// Copyright:   (c) Stefan Csomor
 | 
			
		||||
// Licence:     wxWindows licence
 | 
			
		||||
/////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include "wx/wxprec.h"
 | 
			
		||||
 | 
			
		||||
#if wxUSE_TEXTCTRL
 | 
			
		||||
 | 
			
		||||
#include "wx/textctrl.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WX_PRECOMP
 | 
			
		||||
    #include "wx/intl.h"
 | 
			
		||||
    #include "wx/app.h"
 | 
			
		||||
    #include "wx/utils.h"
 | 
			
		||||
    #include "wx/dc.h"
 | 
			
		||||
    #include "wx/button.h"
 | 
			
		||||
    #include "wx/menu.h"
 | 
			
		||||
    #include "wx/settings.h"
 | 
			
		||||
    #include "wx/msgdlg.h"
 | 
			
		||||
    #include "wx/toplevel.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef __DARWIN__
 | 
			
		||||
    #include <sys/types.h>
 | 
			
		||||
    #include <sys/stat.h>
 | 
			
		||||
#else
 | 
			
		||||
    #include <stat.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if wxUSE_STD_IOSTREAM
 | 
			
		||||
    #if wxUSE_IOSTREAMH
 | 
			
		||||
        #include <fstream.h>
 | 
			
		||||
    #else
 | 
			
		||||
        #include <fstream>
 | 
			
		||||
    #endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "wx/filefn.h"
 | 
			
		||||
#include "wx/sysopt.h"
 | 
			
		||||
#include "wx/thread.h"
 | 
			
		||||
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
#include "wx/osx/carbon/private/mactext.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@implementation wxNSTextField
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
{
 | 
			
		||||
    return YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// use our common calls
 | 
			
		||||
- (void) setTitle:(NSString *) title
 | 
			
		||||
{
 | 
			
		||||
    [self setStringValue: title];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
class wxNSTextFieldControl : public wxMacTextControl
 | 
			
		||||
{
 | 
			
		||||
public :
 | 
			
		||||
    wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxMacTextControl(wxPeer, w)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
    virtual ~wxNSTextFieldControl()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void VisibilityChanged(bool shown){}
 | 
			
		||||
    virtual wxString GetStringValue() const 
 | 
			
		||||
    {
 | 
			
		||||
        wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] );
 | 
			
		||||
        return cf.AsString(m_wxPeer->GetFont().GetEncoding());
 | 
			
		||||
    }
 | 
			
		||||
    virtual void SetStringValue( const wxString &str) 
 | 
			
		||||
    {
 | 
			
		||||
        [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
 | 
			
		||||
    }
 | 
			
		||||
    virtual void Copy() {}
 | 
			
		||||
    virtual void Cut() {}
 | 
			
		||||
    virtual void Paste() {}
 | 
			
		||||
    virtual bool CanPaste() const { return false;}
 | 
			
		||||
    virtual void SetEditable(bool editable) {}
 | 
			
		||||
    virtual void GetSelection( long* from, long* to) const {}
 | 
			
		||||
    virtual void SetSelection( long from , long to ){}
 | 
			
		||||
    virtual void WriteText(const wxString& str) 
 | 
			
		||||
    {
 | 
			
		||||
        // temp hack to get logging working early
 | 
			
		||||
        wxString former = GetStringValue();
 | 
			
		||||
        SetStringValue( former + str );
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, 
 | 
			
		||||
                                    wxWindowMac* parent, 
 | 
			
		||||
                                    wxWindowID id, 
 | 
			
		||||
                                    const wxString& str,
 | 
			
		||||
                                    const wxPoint& pos, 
 | 
			
		||||
                                    const wxSize& size,
 | 
			
		||||
                                    long style, 
 | 
			
		||||
                                    long extraStyle)
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
 | 
			
		||||
    //[v setBezeled:NO];
 | 
			
		||||
    //[v setEditable:NO];
 | 
			
		||||
    //[v setDrawsBackground:NO];
 | 
			
		||||
    
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
 | 
			
		||||
    [v setImplementation:c];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // wxUSE_TEXTCTRL
 | 
			
		||||
@@ -36,8 +36,7 @@ wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
 | 
			
		||||
{
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 | 
			
		||||
    
 | 
			
		||||
    [v setBezelStyle:NSRoundedBezelStyle];    
 | 
			
		||||
@@ -59,8 +58,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
 | 
			
		||||
{    
 | 
			
		||||
    NSView* sv = (wxpeer->GetParent()->GetHandle() );
 | 
			
		||||
    
 | 
			
		||||
    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
 | 
			
		||||
    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 | 
			
		||||
    
 | 
			
		||||
    [v setBezelStyle:NSRegularSquareBezelStyle];
 | 
			
		||||
 
 | 
			
		||||
@@ -30,9 +30,7 @@
 | 
			
		||||
 | 
			
		||||
#if wxUSE_GUI
 | 
			
		||||
#if wxOSX_USE_COCOA_OR_CARBON
 | 
			
		||||
    #include "wx/osx/uma.h"
 | 
			
		||||
    #include <CoreServices/CoreServices.h>
 | 
			
		||||
    #include <Carbon/Carbon.h>
 | 
			
		||||
    #include "wx/osx/private/timer.h"
 | 
			
		||||
#endif
 | 
			
		||||
#endif // wxUSE_GUI
 | 
			
		||||
@@ -58,6 +56,17 @@ void wxMacWakeUp()
 | 
			
		||||
 | 
			
		||||
#endif // wxUSE_BASE
 | 
			
		||||
 
 | 
			
		||||
bool wxApp::DoInitGui()
 | 
			
		||||
{
 | 
			
		||||
    [NSApplication sharedApplication];
 | 
			
		||||
    [NSApp finishLaunching];
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxApp::DoCleanUp()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if wxUSE_GUI
 | 
			
		||||
 | 
			
		||||
void wxClientDisplayRect(int *x, int *y, int *width, int *height)
 | 
			
		||||
@@ -82,7 +91,7 @@ void wxGetMousePosition( int* x, int* y )
 | 
			
		||||
 | 
			
		||||
wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
 | 
			
		||||
{
 | 
			
		||||
    return new wxCarbonTimerImpl(timer);
 | 
			
		||||
    return new wxOSXTimerImpl(timer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int gs_wxBusyCursorCount = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -17,11 +17,20 @@
 | 
			
		||||
#include "wx/osx/private.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if wxOSX_USE_COCOA
 | 
			
		||||
NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
 | 
			
		||||
{
 | 
			
		||||
    int x, y, w, h ;
 | 
			
		||||
 | 
			
		||||
    window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
 | 
			
		||||
    wxRect bounds(x,y,w,h);
 | 
			
		||||
    NSView* sv = (window->GetParent()->GetHandle() );
 | 
			
		||||
 | 
			
		||||
    return wxToNSRect( sv, bounds );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@interface wxNSView : NSView
 | 
			
		||||
{
 | 
			
		||||
    wxWidgetImpl* m_impl;
 | 
			
		||||
    wxWidgetImpl* impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)drawRect: (NSRect) rect;
 | 
			
		||||
@@ -59,7 +68,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
 | 
			
		||||
    wxevent.m_altDown = modifiers & NSAlternateKeyMask;
 | 
			
		||||
    wxevent.m_metaDown = modifiers & NSCommandKeyMask;
 | 
			
		||||
    wxevent.m_clickCount = clickCount;
 | 
			
		||||
    wxevent.SetTimestamp( [nsEvent timestamp] ) ;
 | 
			
		||||
    wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
 | 
			
		||||
/*
 | 
			
		||||
    // a control click is interpreted as a right click
 | 
			
		||||
    bool thisButtonIsFakeRight = false ;
 | 
			
		||||
@@ -182,12 +191,15 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
 | 
			
		||||
 | 
			
		||||
@implementation wxNSView
 | 
			
		||||
 | 
			
		||||
#define OSX_DEBUG_DRAWING 0
 | 
			
		||||
 | 
			
		||||
- (void)drawRect: (NSRect) rect
 | 
			
		||||
{
 | 
			
		||||
    if ( m_impl )
 | 
			
		||||
    if ( impl )
 | 
			
		||||
    {
 | 
			
		||||
        CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
 | 
			
		||||
        CGContextSaveGState( context );
 | 
			
		||||
#if OSX_DEBUG_DRAWING
 | 
			
		||||
        CGContextBeginPath( context );
 | 
			
		||||
        CGContextMoveToPoint(context, 0, 0);
 | 
			
		||||
        NSRect bounds = [self bounds];
 | 
			
		||||
@@ -200,18 +212,32 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
 | 
			
		||||
        CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
 | 
			
		||||
        CGContextClosePath( context );
 | 
			
		||||
        CGContextStrokePath(context);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        if ( [ self isFlipped ] == NO )
 | 
			
		||||
        {
 | 
			
		||||
            CGContextTranslateCTM( context, 0,  [self bounds].size.height );
 | 
			
		||||
            CGContextScaleCTM( context, 1, -1 );
 | 
			
		||||
        }
 | 
			
		||||
        m_impl->GetWXPeer()->MacSetCGContextRef( context );
 | 
			
		||||
        
 | 
			
		||||
        wxRegion updateRgn;
 | 
			
		||||
        const NSRect *rects;
 | 
			
		||||
        int count ;
 | 
			
		||||
 | 
			
		||||
        [self getRectsBeingDrawn:&rects count:&count];
 | 
			
		||||
        for ( int i = 0 ; i < count ; ++i )
 | 
			
		||||
        {
 | 
			
		||||
            updateRgn.Union(wxFromNSRect(self, rects[i]) );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        wxWindow* wxpeer = impl->GetWXPeer();
 | 
			
		||||
        wxpeer->GetUpdateRegion() = updateRgn;
 | 
			
		||||
        wxpeer->MacSetCGContextRef( context );
 | 
			
		||||
        
 | 
			
		||||
        wxPaintEvent event;
 | 
			
		||||
        event.SetTimestamp(0); //  todo
 | 
			
		||||
        event.SetEventObject(m_impl->GetWXPeer());
 | 
			
		||||
        m_impl->GetWXPeer()->HandleWindowEvent(event);
 | 
			
		||||
        event.SetEventObject(wxpeer);
 | 
			
		||||
        wxpeer->HandleWindowEvent(event);
 | 
			
		||||
                
 | 
			
		||||
        CGContextRestoreGState( context );
 | 
			
		||||
    }
 | 
			
		||||
@@ -256,17 +282,17 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
 | 
			
		||||
    SetupMouseEvent( wxevent , event ) ;
 | 
			
		||||
    wxevent.m_x = pt.x;
 | 
			
		||||
    wxevent.m_y = pt.y;
 | 
			
		||||
    m_impl->GetWXPeer()->HandleWindowEvent(wxevent);
 | 
			
		||||
    impl->GetWXPeer()->HandleWindowEvent(wxevent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)setImplementation: (wxWidgetImpl *) theImplementation
 | 
			
		||||
{
 | 
			
		||||
    m_impl = theImplementation;
 | 
			
		||||
    impl = theImplementation;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (wxWidgetImpl*) implementation
 | 
			
		||||
{
 | 
			
		||||
    return m_impl;
 | 
			
		||||
    return impl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (BOOL) isFlipped
 | 
			
		||||
@@ -313,7 +339,14 @@ void wxWidgetCocoaImpl::Init()
 | 
			
		||||
 | 
			
		||||
wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
 | 
			
		||||
{
 | 
			
		||||
    if ( [m_osxView respondsToSelector:@selector(setImplementation:) ] )
 | 
			
		||||
        [m_osxView setImplementation:NULL];
 | 
			
		||||
    if ( !IsRootControl() )
 | 
			
		||||
    {
 | 
			
		||||
        NSView *sv = [m_osxView superview];
 | 
			
		||||
        if ( sv != nil )
 | 
			
		||||
            [m_osxView removeFromSuperview];
 | 
			
		||||
    }
 | 
			
		||||
    [m_osxView release];
 | 
			
		||||
}
 | 
			
		||||
    
 | 
			
		||||
@@ -322,6 +355,11 @@ bool wxWidgetCocoaImpl::IsVisible() const
 | 
			
		||||
    return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetVisibility( bool visible )
 | 
			
		||||
{
 | 
			
		||||
    [m_osxView setHidden:(visible ? NO:YES)];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::Raise()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -354,7 +392,7 @@ void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
 | 
			
		||||
    height = rect.size.height;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height )
 | 
			
		||||
void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
 | 
			
		||||
{
 | 
			
		||||
    left = top = 0;
 | 
			
		||||
    GetSize( width, height );
 | 
			
		||||
@@ -373,19 +411,23 @@ bool wxWidgetCocoaImpl::GetNeedsDisplay() const
 | 
			
		||||
    return [m_osxView needsDisplay];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::CanFocus() const
 | 
			
		||||
bool wxWidgetCocoaImpl::CanFocus() const
 | 
			
		||||
{
 | 
			
		||||
    return [m_osxView acceptsFirstResponder] == YES;
 | 
			
		||||
    return [m_osxView canBecomeKeyView] == YES;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool wxWidgetCocoaImpl::HasFocus() const
 | 
			
		||||
{
 | 
			
		||||
    return [m_osxView isFirstResponder] == YES;
 | 
			
		||||
    return ( [[m_osxView window] firstResponder] == m_osxView );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool wxWidgetCocoaImpl::SetFocus() 
 | 
			
		||||
{
 | 
			
		||||
    [m_osxView makeKeyWindow] ;
 | 
			
		||||
    if ( [m_osxView canBecomeKeyView] == NO )
 | 
			
		||||
        return false;
 | 
			
		||||
        
 | 
			
		||||
    [[m_osxView window] makeFirstResponder: m_osxView] ;
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -401,18 +443,121 @@ void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
 | 
			
		||||
    [container addSubview:m_osxView];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
 | 
			
		||||
{
 | 
			
		||||
    // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
 | 
			
		||||
{
 | 
			
		||||
    if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
 | 
			
		||||
    {
 | 
			
		||||
        wxCFStringRef cf( title , m_wxPeer->GetFont().GetEncoding() );
 | 
			
		||||
        [m_osxView setTitle:cf.AsNSString()];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
void  wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
 | 
			
		||||
{
 | 
			
		||||
    NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
 | 
			
		||||
    p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ]; 
 | 
			
		||||
    *pt = wxFromNSPoint( to->GetWXWidget(), p );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wxInt32 wxWidgetCocoaImpl::GetValue() const 
 | 
			
		||||
{
 | 
			
		||||
    return [(NSControl*)m_osxView intValue];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetValue( wxInt32 v ) 
 | 
			
		||||
{
 | 
			
		||||
    if (  [m_osxView respondsToSelector:@selector(setIntValue:)] )
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxView setIntValue:v];
 | 
			
		||||
    }
 | 
			
		||||
    else if (  [m_osxView respondsToSelector:@selector(setFloatValue:)] )
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxView setFloatValue:(double)v];
 | 
			
		||||
    }
 | 
			
		||||
    else if (  [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxView setDoubleValue:(double)v];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetMinimum( wxInt32 v ) 
 | 
			
		||||
{
 | 
			
		||||
    if (  [m_osxView respondsToSelector:@selector(setMinValue:)] )
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxView setMinValue:(double)v];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetMaximum( wxInt32 v ) 
 | 
			
		||||
{
 | 
			
		||||
    if (  [m_osxView respondsToSelector:@selector(setMaxValue:)] )
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxView setMaxValue:(double)v];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
 | 
			
		||||
{
 | 
			
		||||
    if (  [m_osxView respondsToSelector:@selector(setImage:)] )
 | 
			
		||||
    {
 | 
			
		||||
        [m_osxView setImage:bitmap.GetNSImage()];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& notebook)
 | 
			
		||||
{
 | 
			
		||||
    // implementation in subclass
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
 | 
			
		||||
{
 | 
			
		||||
    r->x = r->y = r->width = r->height = 0;
 | 
			
		||||
//    if (  [m_osxView isKindOfClass:[NSControl class]] )
 | 
			
		||||
    if (  [m_osxView respondsToSelector:@selector(sizeToFit)] )
 | 
			
		||||
    {
 | 
			
		||||
        NSRect former = [m_osxView frame];
 | 
			
		||||
        [m_osxView sizeToFit];
 | 
			
		||||
        NSRect best = [m_osxView frame];
 | 
			
		||||
        [m_osxView setFrame:former];
 | 
			
		||||
        r->width = best.size.width;
 | 
			
		||||
        r->height = best.size.height;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool wxWidgetCocoaImpl::IsEnabled() const
 | 
			
		||||
{
 | 
			
		||||
    return [m_osxView enable];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::Enable( bool enable )
 | 
			
		||||
{
 | 
			
		||||
    [m_osxView setEnabled:enable];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::PulseGauge()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 val, wxInt32 view )
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Factory methods
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, const wxPoint& pos, const wxSize& size,
 | 
			
		||||
                            long style, long extraStyle, const wxString& name)
 | 
			
		||||
wxWidgetImpl* wxWidgetImpl::CreateUserPane( 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 ) ;
 | 
			
		||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
			
		||||
    wxNSView* v = [[wxNSView alloc] initWithFrame:r];
 | 
			
		||||
    [sv addSubview:v];
 | 
			
		||||
    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
 | 
			
		||||
@@ -429,6 +574,3 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
 | 
			
		||||
    [tlw setContentView:v];
 | 
			
		||||
    return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user