Use the native placeholder text functionality on OS X

This commit is contained in:
Thomas Goyne 2012-10-10 08:53:15 -07:00
parent 7ca2c5cb65
commit daf28e2005
4 changed files with 22 additions and 4 deletions

View File

@ -24,6 +24,7 @@
#include "config.h"
#include <wx/window.h>
#include <wx/osx/core/cfstring.h>
#import <AppKit/AppKit.h>
@ -54,3 +55,11 @@ void SetFloatOnParent(wxWindow *window) {
queue:nil
usingBlock:^(NSNotification *) { [nsWindow setLevel:NSFloatingWindowLevel]; }];
}
void SetPlaceholderText(wxWindow *window, wxString const& placeholder) {
id nsWindow = window->GetHandle();
if ([nsWindow respondsToSelector:@selector(cell)]) {
NSTextFieldCell *cell = [nsWindow cell];
cell.placeholderString = wxCFStringRef(placeholder).AsNSString();
}
}

View File

@ -42,6 +42,7 @@ class Placeholder : public BaseCtrl {
BaseCtrl::Create(parent, -1, placeholder, wxDefaultPosition, size, style);
}
#ifndef __WXOSX__
/// Focus gained event handler
void OnSetFocus(wxFocusEvent& evt) {
evt.Skip();
@ -104,6 +105,16 @@ public:
return "";
return BaseCtrl::GetValue();
}
#else
public:
Placeholder(wxWindow *parent, wxString const& placeholder, wxSize const& size, long style, wxString const& tooltip)
: placeholder(placeholder)
{
Create(parent, size, style);
BaseCtrl::SetToolTip(tooltip);
SetPlaceholderText(this, placeholder);
}
#endif
};
template<> inline void Placeholder<wxComboBox>::Create(wxWindow *parent, wxSize const& size, long style) {

View File

@ -316,10 +316,6 @@ void SubsEditBox::PopulateActorList() {
if (AssDialogue *diag = dynamic_cast<AssDialogue*>(*it))
actors.insert(diag->Actor);
}
#ifdef __APPLE__
// OSX doesn't like combo boxes that are empty.
actors.insert("Actor");
#endif
actors.erase("");
wxArrayString arrstr;
arrstr.reserve(actors.size());

View File

@ -99,6 +99,8 @@ void AddFullScreenButton(wxWindow *window);
void SetFloatOnParent(wxWindow *window);
void SetPlaceholderText(wxWindow *window, wxString const& placeholder);
/// Forward a mouse wheel event to the window under the mouse if needed
/// @param source The initial target of the wheel event
/// @param evt The event