fixing controls with content areas, correcting radiobox layout

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58113 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2009-01-15 11:31:02 +00:00
parent 9c4cb61167
commit 0c530e5a67
6 changed files with 130 additions and 38 deletions

View File

@@ -119,6 +119,7 @@ public :
virtual bool DoHandleMouseEvent(NSEvent *event); virtual bool DoHandleMouseEvent(NSEvent *event);
virtual bool DoHandleKeyEvent(NSEvent *event); virtual bool DoHandleKeyEvent(NSEvent *event);
virtual void DoNotifyFocusEvent(bool receivedFocus);
protected: protected:
WXWidget m_osxView; WXWidget m_osxView;
@@ -199,7 +200,7 @@ protected :
// common code snippets for cocoa implementations // common code snippets for cocoa implementations
// later to be done using injection in method table // 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)rightMouseDown:(NSEvent *)event ;\
-(void)otherMouseDown:(NSEvent *)event ;\ -(void)otherMouseDown:(NSEvent *)event ;\
-(void)mouseUp:(NSEvent *)event ;\ -(void)mouseUp:(NSEvent *)event ;\
@@ -208,8 +209,10 @@ protected :
- (void)keyDown:(NSEvent *)event;\ - (void)keyDown:(NSEvent *)event;\
- (void)keyUp:(NSEvent *)event;\ - (void)keyUp:(NSEvent *)event;\
- (void)flagsChanged:(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) )\ if ( !impl->DoHandleMouseEvent(event) )\
[super mouseDown:event];\ [super mouseDown:event];\
@@ -253,6 +256,20 @@ protected :
{\ {\
if ( !impl->DoHandleKeyEvent(event) )\ if ( !impl->DoHandleKeyEvent(event) )\
[super flagsChanged: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; #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
@@ -261,9 +278,9 @@ protected :
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\ - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
- (wxWidgetCocoaImpl*) implementation;\ - (wxWidgetCocoaImpl*) implementation;\
- (BOOL) isFlipped;\ - (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\ - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
{\ {\
impl = theImplementation;\ impl = theImplementation;\
@@ -277,6 +294,20 @@ protected :
return YES;\ 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 // used for many wxControls
@interface wxNSButton : NSButton @interface wxNSButton : NSButton

View File

@@ -18,7 +18,7 @@
@implementation wxNSBox @implementation wxNSBox
WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED
@end @end

View File

@@ -149,6 +149,7 @@ bool wxNSTextFieldControl::CanPaste() const
void wxNSTextFieldControl::SetEditable(bool editable) void wxNSTextFieldControl::SetEditable(bool editable)
{ {
[(wxNSTextField*) m_osxView setEditable:editable];
} }
void wxNSTextFieldControl::GetSelection( long* from, long* to) const void wxNSTextFieldControl::GetSelection( long* from, long* to) const

View File

@@ -19,6 +19,10 @@
#include "wx/osx/private.h" #include "wx/osx/private.h"
#endif #endif
#if wxUSE_CARET
#include "wx/caret.h"
#endif
NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
{ {
int x, y, w, h ; int x, y, w, h ;
@@ -39,8 +43,6 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const
WXCOCOAIMPL_COMMON_INTERFACE WXCOCOAIMPL_COMMON_INTERFACE
- (BOOL) becomeFirstResponder;
- (BOOL) resignFirstResponder;
- (BOOL) canBecomeKeyView; - (BOOL) canBecomeKeyView;
@end // wxNSView @end // wxNSView
@@ -63,6 +65,8 @@ WXCOCOAIMPL_COMMON_INTERFACE
- (void)setImage:(NSImage *)image; - (void)setImage:(NSImage *)image;
- (void)setControlSize:(NSControlSize)size; - (void)setControlSize:(NSControlSize)size;
- (id)contentView;
@end @end
long wxOSXTranslateCocoaKey(unsigned short code, int unichar ) long wxOSXTranslateCocoaKey(unsigned short code, int unichar )
@@ -356,24 +360,6 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
WXCOCOAIMPL_COMMON_IMPLEMENTATION 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 - (BOOL) canBecomeKeyView
{ {
return YES; return YES;
@@ -434,6 +420,15 @@ void wxWidgetCocoaImpl::ScrollRect( const wxRect *rect, int dx, int dy )
void wxWidgetCocoaImpl::Move(int x, int y, int width, int height) 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) ); NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
[m_osxView setFrame:r]; [m_osxView setFrame:r];
} }
@@ -454,8 +449,27 @@ void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
{ {
left = top = 0; if ( [m_osxView respondsToSelector:@selector(contentView) ] )
GetSize( width, height ); {
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 ) void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
@@ -670,6 +684,48 @@ bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
return GetWXPeer()->HandleWindowEvent(wxevent); 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 // Factory methods

View File

@@ -399,7 +399,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] ); GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] );
eachWidth[i] = (int)(eachWidth[i] + RADIO_SIZE); eachWidth[i] = (int)(eachWidth[i] + RADIO_SIZE);
eachHeight[i] = (int)((3 * eachHeight[i]) / 2); eachHeight[i] = (int) eachHeight[i];
if (maxWidth < eachWidth[i]) if (maxWidth < eachWidth[i])
maxWidth = eachWidth[i]; maxWidth = eachWidth[i];
@@ -407,11 +407,11 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
maxHeight = eachHeight[i]; maxHeight = eachHeight[i];
} }
totHeight = GetRowCount() * maxHeight; totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * maxHeight / 2;
totWidth = GetColumnCount() * (maxWidth + charWidth); totWidth = GetColumnCount() * (maxWidth + charWidth);
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ; wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ;
// change the width / height only when specified // change the width / height only when specified
if ( width == wxDefaultCoord ) if ( width == wxDefaultCoord )
{ {
@@ -434,8 +434,8 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
// arrange radio buttons // arrange radio buttons
int x_start, y_start; int x_start, y_start;
x_start = 0; x_start = ( width - sz.x ) / 2;
y_start = 0; y_start = ( height - sz.y ) / 2;
x_offset = x_start; x_offset = x_start;
y_offset = y_start; y_offset = y_start;
@@ -454,7 +454,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
else else
{ {
x_offset = x_start; x_offset = x_start;
y_offset += maxHeight ; //+ charHeight / 2 y_offset += 3 * maxHeight / 2 ; //+ charHeight / 2
} }
} }
@@ -462,7 +462,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
current = current->NextInCycle(); current = current->NextInCycle();
if (m_windowStyle & wxRA_SPECIFY_ROWS) if (m_windowStyle & wxRA_SPECIFY_ROWS)
y_offset += maxHeight ; // + charHeight / 2 y_offset += 3 * maxHeight / 2 ; // + charHeight / 2
else else
x_offset += maxWidth + charWidth; x_offset += maxWidth + charWidth;
} }
@@ -489,19 +489,23 @@ wxSize wxRadioBox::DoGetBestSize() const
{ {
GetTextExtent(GetString(i), &eachWidth, &eachHeight, NULL, NULL, &font ); GetTextExtent(GetString(i), &eachWidth, &eachHeight, NULL, NULL, &font );
eachWidth = (int)(eachWidth + RADIO_SIZE); eachWidth = (int)(eachWidth + RADIO_SIZE);
eachHeight = (int)((3 * eachHeight) / 2); eachHeight = (int)eachHeight;
if (maxWidth < eachWidth) if (maxWidth < eachWidth)
maxWidth = eachWidth; maxWidth = eachWidth;
if (maxHeight < eachHeight) if (maxHeight < eachHeight)
maxHeight = eachHeight; maxHeight = eachHeight;
} }
totHeight = GetRowCount() * maxHeight; totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * maxHeight / 2;
totWidth = GetColumnCount() * (maxWidth + charWidth); totWidth = GetColumnCount() * (maxWidth + charWidth);
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ); wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) );
totWidth = sz.x; totWidth = sz.x;
totHeight = sz.y; totHeight = sz.y;
// optimum size is an additional 5 pt border to all sides
totWidth += 10;
totHeight += 10;
// handle radio box title as well // handle radio box title as well
GetTextExtent( GetLabel(), &eachWidth, NULL ); GetTextExtent( GetLabel(), &eachWidth, NULL );

View File

@@ -674,8 +674,8 @@ wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
m_peer->GetContentArea( left, top, innerwidth, innerheight ); m_peer->GetContentArea( left, top, innerwidth, innerheight );
m_peer->GetSize( outerwidth, outerheight ); m_peer->GetSize( outerwidth, outerheight );
sizeTotal.x += left + (outerwidth-innerwidth); sizeTotal.x += outerwidth-innerwidth;
sizeTotal.y += top + (outerheight-innerheight); sizeTotal.y += outerheight-innerheight;
sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;