Remove private wxDisclosureTriangle control.
Remove the private and undocumented control and it's usage in wxGenericCollapsiblePane. The class used a low resolution bitmap which looks bad on high resolution displays. The generic implementation using wxRendererNative::DrawCollapseButton() is better fit even on OS X.
This commit is contained in:
@@ -14,9 +14,6 @@
|
|||||||
// forward declared
|
// forward declared
|
||||||
class WXDLLIMPEXP_FWD_CORE wxCollapsibleHeaderCtrl;
|
class WXDLLIMPEXP_FWD_CORE wxCollapsibleHeaderCtrl;
|
||||||
class WXDLLIMPEXP_FWD_CORE wxStaticLine;
|
class WXDLLIMPEXP_FWD_CORE wxStaticLine;
|
||||||
#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxDisclosureTriangle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wx/containr.h"
|
#include "wx/containr.h"
|
||||||
|
|
||||||
@@ -82,11 +79,7 @@ protected:
|
|||||||
int GetBorder() const;
|
int GetBorder() const;
|
||||||
|
|
||||||
// child controls
|
// child controls
|
||||||
#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
|
|
||||||
wxDisclosureTriangle *m_pButton;
|
|
||||||
#else
|
|
||||||
wxCollapsibleHeaderCtrl *m_pButton;
|
wxCollapsibleHeaderCtrl *m_pButton;
|
||||||
#endif
|
|
||||||
wxStaticLine *m_pStaticLine;
|
wxStaticLine *m_pStaticLine;
|
||||||
wxWindow *m_pPane;
|
wxWindow *m_pPane;
|
||||||
wxSizer *m_sz;
|
wxSizer *m_sz;
|
||||||
|
@@ -56,40 +56,4 @@ protected:
|
|||||||
wxDECLARE_DYNAMIC_CLASS(wxButton);
|
wxDECLARE_DYNAMIC_CLASS(wxButton);
|
||||||
};
|
};
|
||||||
|
|
||||||
// OS X specific class, not part of public wx API
|
|
||||||
class WXDLLIMPEXP_CORE wxDisclosureTriangle : public wxControl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
wxDisclosureTriangle(wxWindow *parent,
|
|
||||||
wxWindowID id,
|
|
||||||
const wxString& label = wxEmptyString,
|
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
|
||||||
const wxSize& size = wxDefaultSize,
|
|
||||||
long style = wxBORDER_NONE,
|
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
|
||||||
const wxString& name = wxButtonNameStr)
|
|
||||||
{
|
|
||||||
Create(parent, id, label, pos, size, style, validator, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Create(wxWindow *parent,
|
|
||||||
wxWindowID id,
|
|
||||||
const wxString& label = wxEmptyString,
|
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
|
||||||
const wxSize& size = wxDefaultSize,
|
|
||||||
long style = wxBORDER_NONE,
|
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
|
||||||
const wxString& name = wxButtonNameStr);
|
|
||||||
|
|
||||||
void SetOpen( bool open );
|
|
||||||
bool IsOpen() const;
|
|
||||||
|
|
||||||
// osx specific event handling common for all osx-ports
|
|
||||||
|
|
||||||
virtual bool OSXHandleClicked( double timestampsec );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual wxSize DoGetBestSize() const ;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _WX_OSX_BUTTON_H_
|
#endif // _WX_OSX_BUTTON_H_
|
||||||
|
@@ -81,20 +81,16 @@ bool wxGenericCollapsiblePane::Create(wxWindow *parent,
|
|||||||
// sizer containing the expand button and possibly a static line
|
// sizer containing the expand button and possibly a static line
|
||||||
m_sz = new wxBoxSizer(wxVERTICAL);
|
m_sz = new wxBoxSizer(wxVERTICAL);
|
||||||
|
|
||||||
#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
|
|
||||||
// on Mac we use the special disclosure triangle button
|
|
||||||
m_pStaticLine = NULL;
|
|
||||||
m_pButton = new wxDisclosureTriangle(this, wxID_ANY, label);
|
|
||||||
m_sz->Add(m_pButton);
|
|
||||||
#else
|
|
||||||
// create children and lay them out using a wxBoxSizer
|
// create children and lay them out using a wxBoxSizer
|
||||||
// (so that we automatically get RTL features)
|
// (so that we automatically get RTL features)
|
||||||
m_pButton = new wxCollapsibleHeaderCtrl(this, wxID_ANY, label, wxPoint(0, 0),
|
m_pButton = new wxCollapsibleHeaderCtrl(this, wxID_ANY, label, wxPoint(0, 0),
|
||||||
wxDefaultSize);
|
wxDefaultSize);
|
||||||
m_pStaticLine = new wxStaticLine(this, wxID_ANY);
|
|
||||||
|
|
||||||
// on other platforms we put the static line and the button horizontally
|
// on other platforms we put the static line and the button horizontally
|
||||||
m_sz->Add(m_pButton, 0, wxLEFT|wxTOP|wxBOTTOM, GetBorder());
|
m_sz->Add(m_pButton, 0, wxLEFT|wxTOP|wxBOTTOM, GetBorder());
|
||||||
|
|
||||||
|
#if !defined( __WXMAC__ ) || defined(__WXUNIVERSAL__)
|
||||||
|
m_pStaticLine = new wxStaticLine(this, wxID_ANY);
|
||||||
m_sz->Add(m_pStaticLine, 0, wxEXPAND, GetBorder());
|
m_sz->Add(m_pStaticLine, 0, wxEXPAND, GetBorder());
|
||||||
m_pStaticLine->Hide();
|
m_pStaticLine->Hide();
|
||||||
#endif
|
#endif
|
||||||
@@ -183,14 +179,11 @@ void wxGenericCollapsiblePane::Collapse(bool collapse)
|
|||||||
// update our state
|
// update our state
|
||||||
m_pPane->Show(!collapse);
|
m_pPane->Show(!collapse);
|
||||||
|
|
||||||
// update button label
|
// update button
|
||||||
#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
|
|
||||||
m_pButton->SetOpen( !collapse );
|
|
||||||
#else
|
|
||||||
// NB: this must be done after updating our "state"
|
// NB: this must be done after updating our "state"
|
||||||
m_pButton->SetCollapsed(collapse);
|
m_pButton->SetCollapsed(collapse);
|
||||||
|
if ( m_pStaticLine )
|
||||||
m_pStaticLine->Show(!collapse);
|
m_pStaticLine->Show(!collapse);
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
OnStateChange(GetBestSize());
|
OnStateChange(GetBestSize());
|
||||||
@@ -198,12 +191,8 @@ void wxGenericCollapsiblePane::Collapse(bool collapse)
|
|||||||
|
|
||||||
void wxGenericCollapsiblePane::SetLabel(const wxString &label)
|
void wxGenericCollapsiblePane::SetLabel(const wxString &label)
|
||||||
{
|
{
|
||||||
#ifdef __WXMAC__
|
|
||||||
m_pButton->SetLabel(label);
|
|
||||||
#else
|
|
||||||
m_pButton->SetLabel(label);
|
m_pButton->SetLabel(label);
|
||||||
m_pButton->SetInitialSize();
|
m_pButton->SetInitialSize();
|
||||||
#endif
|
|
||||||
|
|
||||||
Layout();
|
Layout();
|
||||||
}
|
}
|
||||||
|
@@ -138,57 +138,3 @@ wxSize wxButtonBase::GetDefaultSize()
|
|||||||
{
|
{
|
||||||
return wxAnyButton::GetDefaultSize();
|
return wxAnyButton::GetDefaultSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------
|
|
||||||
// wxDisclosureTriangle
|
|
||||||
//-------------------------------------------------------
|
|
||||||
|
|
||||||
bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label,
|
|
||||||
const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name )
|
|
||||||
{
|
|
||||||
DontCreatePeer();
|
|
||||||
if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() ));
|
|
||||||
|
|
||||||
MacPostControlCreate( pos, size );
|
|
||||||
// passing the text in the param doesn't seem to work, so let's do it again
|
|
||||||
SetLabel( label );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxDisclosureTriangle::SetOpen( bool open )
|
|
||||||
{
|
|
||||||
GetPeer()->SetValue( open ? 1 : 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxDisclosureTriangle::IsOpen() const
|
|
||||||
{
|
|
||||||
return GetPeer()->GetValue() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) )
|
|
||||||
{
|
|
||||||
// Just emit button event for now
|
|
||||||
wxCommandEvent event(wxEVT_BUTTON, m_windowId);
|
|
||||||
event.SetEventObject(this);
|
|
||||||
ProcessCommand(event);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxSize wxDisclosureTriangle::DoGetBestSize() const
|
|
||||||
{
|
|
||||||
wxSize size = wxWindow::DoGetBestSize();
|
|
||||||
|
|
||||||
// under Carbon the base class GetBestSize() implementation doesn't seem to
|
|
||||||
// take the label into account at all, correct for it here
|
|
||||||
#if wxOSX_USE_CARBON
|
|
||||||
size.x += GetTextExtent(GetLabel()).x;
|
|
||||||
#endif // wxOSX_USE_CARBON
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -361,155 +361,3 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_BMPBUTTON
|
#endif // wxUSE_BMPBUTTON
|
||||||
|
|
||||||
//
|
|
||||||
// wxDisclosureButton implementation
|
|
||||||
//
|
|
||||||
|
|
||||||
@interface wxDisclosureNSButton : NSButton
|
|
||||||
{
|
|
||||||
|
|
||||||
BOOL isOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) updateImage;
|
|
||||||
|
|
||||||
- (void) toggle;
|
|
||||||
|
|
||||||
+ (NSImage *)rotateImage: (NSImage *)image;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
static const char * disc_triangle_xpm[] = {
|
|
||||||
"10 9 4 1",
|
|
||||||
" c None",
|
|
||||||
". c #737373",
|
|
||||||
"+ c #989898",
|
|
||||||
"- c #c6c6c6",
|
|
||||||
" .- ",
|
|
||||||
" ..+- ",
|
|
||||||
" ....+ ",
|
|
||||||
" ......- ",
|
|
||||||
" .......- ",
|
|
||||||
" ......- ",
|
|
||||||
" ....+ ",
|
|
||||||
" ..+- ",
|
|
||||||
" .- ",
|
|
||||||
};
|
|
||||||
|
|
||||||
@implementation wxDisclosureNSButton
|
|
||||||
|
|
||||||
+ (void)initialize
|
|
||||||
{
|
|
||||||
static BOOL initialized = NO;
|
|
||||||
if (!initialized)
|
|
||||||
{
|
|
||||||
initialized = YES;
|
|
||||||
wxOSXCocoaClassAddWXMethods( self );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithFrame:(NSRect) frame
|
|
||||||
{
|
|
||||||
self = [super initWithFrame:frame];
|
|
||||||
isOpen = NO;
|
|
||||||
[self setImagePosition:NSImageLeft];
|
|
||||||
[self updateImage];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int) intValue
|
|
||||||
{
|
|
||||||
return isOpen ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setIntValue: (int) v
|
|
||||||
{
|
|
||||||
isOpen = ( v != 0 );
|
|
||||||
[self updateImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) toggle
|
|
||||||
{
|
|
||||||
isOpen = !isOpen;
|
|
||||||
[self updateImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
wxCFRef<NSImage*> downArray ;
|
|
||||||
|
|
||||||
- (void) updateImage
|
|
||||||
{
|
|
||||||
static wxBitmap trianglebm(disc_triangle_xpm);
|
|
||||||
if ( downArray.get() == NULL )
|
|
||||||
{
|
|
||||||
downArray.reset( [[wxDisclosureNSButton rotateImage:trianglebm.GetNSImage()] retain] );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isOpen )
|
|
||||||
[self setImage:(NSImage*)downArray.get()];
|
|
||||||
else
|
|
||||||
[self setImage:trianglebm.GetNSImage()];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSImage *)rotateImage: (NSImage *)image
|
|
||||||
{
|
|
||||||
NSSize imageSize = [image size];
|
|
||||||
NSSize newImageSize = NSMakeSize(imageSize.height, imageSize.width);
|
|
||||||
NSImage* newImage = [[NSImage alloc] initWithSize: newImageSize];
|
|
||||||
|
|
||||||
[newImage lockFocus];
|
|
||||||
|
|
||||||
NSAffineTransform* tm = [NSAffineTransform transform];
|
|
||||||
[tm translateXBy:newImageSize.width/2 yBy:newImageSize.height/2];
|
|
||||||
[tm rotateByDegrees:-90];
|
|
||||||
[tm translateXBy:-newImageSize.width/2 yBy:-newImageSize.height/2];
|
|
||||||
[tm concat];
|
|
||||||
|
|
||||||
|
|
||||||
[image drawInRect:NSMakeRect(0,0,newImageSize.width, newImageSize.height)
|
|
||||||
fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
|
|
||||||
|
|
||||||
[newImage unlockFocus];
|
|
||||||
return [newImage autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
class wxDisclosureTriangleCocoaImpl : public wxWidgetCocoaImpl
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
wxDisclosureTriangleCocoaImpl(wxWindowMac* peer , WXWidget w) :
|
|
||||||
wxWidgetCocoaImpl(peer, w)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~wxDisclosureTriangleCocoaImpl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void controlAction(WXWidget slf, void* _cmd, void *sender) wxOVERRIDE
|
|
||||||
{
|
|
||||||
wxDisclosureNSButton* db = (wxDisclosureNSButton*)m_osxView;
|
|
||||||
[db toggle];
|
|
||||||
wxWidgetCocoaImpl::controlAction(slf, _cmd, sender );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer,
|
|
||||||
wxWindowMac* WXUNUSED(parent),
|
|
||||||
wxWindowID winid,
|
|
||||||
const wxString& label,
|
|
||||||
const wxPoint& pos,
|
|
||||||
const wxSize& size,
|
|
||||||
long style,
|
|
||||||
long WXUNUSED(extraStyle))
|
|
||||||
{
|
|
||||||
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
|
|
||||||
wxDisclosureNSButton* v = [[wxDisclosureNSButton alloc] initWithFrame:r];
|
|
||||||
if ( !label.empty() )
|
|
||||||
[v setTitle:wxCFStringRef(label).AsNSString()];
|
|
||||||
|
|
||||||
SetBezelStyleFromBorderFlags(v, style, winid, label);
|
|
||||||
|
|
||||||
return new wxDisclosureTriangleCocoaImpl( wxpeer, v );
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user