virtual bool DoHandleMouseEvent(NSEvent *event);
virtual bool DoHandleKeyEvent(NSEvent *event);
+ virtual void DoNotifyFocusEvent(bool receivedFocus);
protected:
WXWidget m_osxView;
// common code snippets for cocoa implementations
// later to be done using injection in method table
- #define WXCOCOAIMPL_COMMON_MOUSE_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
+ #define WXCOCOAIMPL_COMMON_EVENTS_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
-(void)rightMouseDown:(NSEvent *)event ;\
-(void)otherMouseDown:(NSEvent *)event ;\
-(void)mouseUp:(NSEvent *)event ;\
- (void)keyDown:(NSEvent *)event;\
- (void)keyUp:(NSEvent *)event;\
- (void)flagsChanged:(NSEvent *)event;\
+ - (BOOL) becomeFirstResponder;\
+ - (BOOL) resignFirstResponder;
- #define WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
+ #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super mouseDown:event];\
{\
if ( !impl->DoHandleKeyEvent(event) )\
[super flagsChanged:event];\
+ }\
+ - (BOOL) becomeFirstResponder\
+ {\
+ BOOL r = [super becomeFirstResponder];\
+ if ( r )\
+ impl->DoNotifyFocusEvent( true );\
+ return r;\
+ }\
+ - (BOOL) resignFirstResponder\
+ {\
+ BOOL r = [super resignFirstResponder];\
+ if ( r )\
+ impl->DoNotifyFocusEvent( false );\
+ return r;\
}
#define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
- (wxWidgetCocoaImpl*) implementation;\
- (BOOL) isFlipped;\
- WXCOCOAIMPL_COMMON_MOUSE_INTERFACE
+ WXCOCOAIMPL_COMMON_EVENTS_INTERFACE
- #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION \
+ #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
{\
impl = theImplementation;\
return YES;\
}\
+ #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
+ - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
+ {\
+ impl = theImplementation;\
+ }\
+ - (wxWidgetCocoaImpl*) implementation\
+ {\
+ return impl;\
+ }\
+ - (BOOL) isFlipped\
+ {\
+ return NO;\
+ }\
+
// used for many wxControls
@interface wxNSButton : NSButton
@implementation wxNSBox
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
+WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED
@end
void wxNSTextFieldControl::SetEditable(bool editable)
{
+ [(wxNSTextField*) m_osxView setEditable:editable];
}
void wxNSTextFieldControl::GetSelection( long* from, long* to) const
#include "wx/osx/private.h"
#endif
+#if wxUSE_CARET
+ #include "wx/caret.h"
+#endif
+
NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
{
int x, y, w, h ;
WXCOCOAIMPL_COMMON_INTERFACE
-- (BOOL) becomeFirstResponder;
-- (BOOL) resignFirstResponder;
- (BOOL) canBecomeKeyView;
@end // wxNSView
- (void)setImage:(NSImage *)image;
- (void)setControlSize:(NSControlSize)size;
+
+- (id)contentView;
@end
long wxOSXTranslateCocoaKey(unsigned short code, int unichar )
WXCOCOAIMPL_COMMON_IMPLEMENTATION
-- (BOOL) becomeFirstResponder
-{
- BOOL r = [super becomeFirstResponder];
- if ( r )
- {
- }
- return r;
-}
-
-- (BOOL) resignFirstResponder
-{
- BOOL r = [super resignFirstResponder];
- if ( r )
- {
- }
- return r;
-}
-
- (BOOL) canBecomeKeyView
{
return YES;
void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
{
+ wxWindowMac* parent = GetWXPeer()->GetParent();
+ // under Cocoa we might have a contentView in the wxParent to which we have to
+ // adjust the coordinates
+ if (parent)
+ {
+ wxPoint pt(parent->GetClientAreaOrigin());
+ x -= pt.x;
+ y -= pt.y;
+ }
NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
[m_osxView setFrame:r];
}
void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
{
- left = top = 0;
- GetSize( width, height );
+ if ( [m_osxView respondsToSelector:@selector(contentView) ] )
+ {
+ NSView* cv = [m_osxView contentView];
+
+ NSRect bounds = [m_osxView bounds];
+ NSRect rect = [cv frame];
+
+ int y = rect.origin.y;
+ int x = rect.origin.x;
+ if ( ![ m_osxView isFlipped ] )
+ y = bounds.size.height - (rect.origin.y + rect.size.height);
+ left = x;
+ top = y;
+ width = rect.size.width;
+ height = rect.size.height;
+ }
+ else
+ {
+ left = top = 0;
+ GetSize( width, height );
+ }
}
void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
return GetWXPeer()->HandleWindowEvent(wxevent);
}
+void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
+{
+ wxWindow* thisWindow = GetWXPeer();
+ if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
+ {
+ thisWindow->MacInvalidateBorders();
+ }
+
+ if ( receivedFocus )
+ {
+ wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
+ wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
+ thisWindow->HandleWindowEvent(eventFocus);
+
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnSetFocus();
+#endif
+
+ wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ // TODO how to find out the targetFocusWindow ?
+ // event.SetWindow(targetFocusWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ }
+ else // !receivedFocuss
+ {
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnKillFocus();
+#endif
+
+ wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
+
+ wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ // TODO how to find out the targetFocusWindow ?
+ // event.SetWindow(targetFocusWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ }
+}
+
//
// Factory methods
{
GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] );
eachWidth[i] = (int)(eachWidth[i] + RADIO_SIZE);
- eachHeight[i] = (int)((3 * eachHeight[i]) / 2);
+ eachHeight[i] = (int) eachHeight[i];
if (maxWidth < eachWidth[i])
maxWidth = eachWidth[i];
maxHeight = eachHeight[i];
}
- totHeight = GetRowCount() * maxHeight;
+ totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * maxHeight / 2;
totWidth = GetColumnCount() * (maxWidth + charWidth);
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ;
-
+
// change the width / height only when specified
if ( width == wxDefaultCoord )
{
// arrange radio buttons
int x_start, y_start;
- x_start = 0;
- y_start = 0;
+ x_start = ( width - sz.x ) / 2;
+ y_start = ( height - sz.y ) / 2;
x_offset = x_start;
y_offset = y_start;
else
{
x_offset = x_start;
- y_offset += maxHeight ; //+ charHeight / 2
+ y_offset += 3 * maxHeight / 2 ; //+ charHeight / 2
}
}
current = current->NextInCycle();
if (m_windowStyle & wxRA_SPECIFY_ROWS)
- y_offset += maxHeight ; // + charHeight / 2
+ y_offset += 3 * maxHeight / 2 ; // + charHeight / 2
else
x_offset += maxWidth + charWidth;
}
{
GetTextExtent(GetString(i), &eachWidth, &eachHeight, NULL, NULL, &font );
eachWidth = (int)(eachWidth + RADIO_SIZE);
- eachHeight = (int)((3 * eachHeight) / 2);
+ eachHeight = (int)eachHeight;
if (maxWidth < eachWidth)
maxWidth = eachWidth;
if (maxHeight < eachHeight)
maxHeight = eachHeight;
}
- totHeight = GetRowCount() * maxHeight;
+ totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * maxHeight / 2;
totWidth = GetColumnCount() * (maxWidth + charWidth);
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) );
totWidth = sz.x;
totHeight = sz.y;
+
+ // optimum size is an additional 5 pt border to all sides
+ totWidth += 10;
+ totHeight += 10;
// handle radio box title as well
GetTextExtent( GetLabel(), &eachWidth, NULL );
m_peer->GetContentArea( left, top, innerwidth, innerheight );
m_peer->GetSize( outerwidth, outerheight );
- sizeTotal.x += left + (outerwidth-innerwidth);
- sizeTotal.y += top + (outerheight-innerheight);
+ sizeTotal.x += outerwidth-innerwidth;
+ sizeTotal.y += outerheight-innerheight;
sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;