From daf28e200516954061f768859b0912d27c6c6f5c Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 10 Oct 2012 08:53:15 -0700 Subject: [PATCH] Use the native placeholder text functionality on OS X --- aegisub/src/osx_utils.mm | 9 +++++++++ aegisub/src/placeholder_ctrl.h | 11 +++++++++++ aegisub/src/subs_edit_box.cpp | 4 ---- aegisub/src/utils.h | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/aegisub/src/osx_utils.mm b/aegisub/src/osx_utils.mm index 12f0edd6b..8134d51d9 100644 --- a/aegisub/src/osx_utils.mm +++ b/aegisub/src/osx_utils.mm @@ -24,6 +24,7 @@ #include "config.h" #include +#include #import @@ -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(); + } +} diff --git a/aegisub/src/placeholder_ctrl.h b/aegisub/src/placeholder_ctrl.h index 98f5e2496..f6c068727 100644 --- a/aegisub/src/placeholder_ctrl.h +++ b/aegisub/src/placeholder_ctrl.h @@ -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::Create(wxWindow *parent, wxSize const& size, long style) { diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index eeec0a584..cddeb813e 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -316,10 +316,6 @@ void SubsEditBox::PopulateActorList() { if (AssDialogue *diag = dynamic_cast(*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()); diff --git a/aegisub/src/utils.h b/aegisub/src/utils.h index 763b9e0f9..cb4daf760 100644 --- a/aegisub/src/utils.h +++ b/aegisub/src/utils.h @@ -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