首页 > 解决方案 > 3.1.3 上的 wxWidgets mac 剪贴板坏了?

问题描述

我不确定我是否在做一些非常愚蠢的事情,但我对剪贴板的调用从 3.1.3 开始就停止了。我进入了代码,这一切都在较低的级别上工作(wxClipboard::AddData 返回 true)。这在 3.1.2 下工作,我在 macOS 10.12.6 Sierra 上构建,配置如下:

configure --disable-shared --enable-unicode --prefix="$(pwd)" --enable-ipc --enable-base64 --enable-exceptions --enable-fontenum --enable-fs_archive --enable-stdpaths --enable-sysoptions --enable-threads --enable-url --enable-aui  --enable-graphics_ctx  --enable-printarch --enable-timer --enable-ribbon --enable-webview --enable-display --enable-splash --enable-snglinst --enable-printfposparam --with-opengl --with-osx_cocoa --with-expat=builtin --with-cxx=11 --enable-cxx11 --enable-stl --enable-std_iostreams --enable-std_string --enable-ftp --enable-http --enable-fileproto --enable-sockets --enable-ipv6 --enable-dataobj --enable-ipc --enable-any --enable-arcstream --enable-backtrace --enable-cmdline --enable-datetime --enable-debugreport --enable-dynamicloader --enable-exceptions --enable-ffile --enable-file --enable-filehistory --enable-filesystem --enable-fontmap --enable-fs_inet --enable-fs_zip --enable-fsvolume --enable-fswatcher --enable-geometry --enable-sound --enable-stopwatch --enable-streams --enable-tarstream --enable-textbuf --enable-textfile --enable-variant --enable-zipstream --enable-protocol --enable-protocol-http --enable-protocol-ftp --enable-protocol-file --enable-html --enable-htmlhelp --enable-propgrid --enable-svg --enable-clipboard --enable-dnd --enable-accel --with-osx_cocoa  --disable-debug_flag --with-libpng=builtin --with-libjpeg=builtin --with-zlib=builtin

我知道基础 SDK 已经从以前的 (10.4?) 迁移到 (10.9),并且我没有明确指定它,因此我将使用 3.1.3 的默认值。

对于我使用以下配置选项构建的同一系统下的 wxWidgets 3.1.3:

configure --disable-shared --enable-unicode --prefix="$(pwd)" --enable-stc --enable-ipc --enable-base64 --enable-exceptions --enable-fontenum --enable-fs_archive --enable-stdpaths --enable-sysoptions --enable-threads --enable-url --enable-aui  --enable-graphics_ctx  --enable-printarch --enable-timer --enable-ribbon --enable-webview --enable-display --enable-splash --enable-snglinst --enable-printfposparam --with-opengl --with-osx_cocoa --with-expat=builtin --with-cxx=11 --enable-cxx11 --enable-stl --enable-std_iostreams --enable-std_string --enable-ftp --enable-http --enable-fileproto --enable-sockets --enable-ipv6 --enable-dataobj --enable-ipc --enable-any --enable-arcstream --enable-backtrace --enable-cmdline --enable-datetime --enable-debugreport --enable-dynamicloader --enable-exceptions --enable-ffile --enable-file --enable-filehistory --enable-filesystem --enable-fontmap --enable-fs_inet --enable-fs_zip --enable-fsvolume --enable-fswatcher --enable-geometry --enable-sound --enable-stopwatch --enable-streams --enable-tarstream --enable-textbuf --enable-textfile --enable-variant --enable-zipstream --enable-protocol --enable-protocol-http --enable-protocol-ftp --enable-protocol-file --enable-html --enable-htmlhelp --enable-propgrid --enable-svg --enable-clipboard --enable-dnd --enable-accel --with-osx_cocoa  --disable-debug_flag --with-libpng=builtin --with-libjpeg=builtin --with-zlib=builtin --with-libtiff=builtin

我已经编写了一个示例测试应用程序来测试它,剪贴板似乎已经失效。如果我使用剪贴板示例,则粘贴按钮被禁用。

这是一个测试应用程序:

#include <wx/wx.h>
#include <wx/app.h>
#include <wx/clipbrd.h>

class MainFrame : public wxFrame
{
protected:
  wxStaticText* label;
public:
  MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL )
  : wxFrame(parent, id, title, pos, size, style)
  {
    this->SetSizeHints( wxDefaultSize, wxDefaultSize );
    wxBoxSizer* bSizer1;
    bSizer1 = new wxBoxSizer( wxVERTICAL );
    label = new wxStaticText( this, wxID_ANY, wxT("<pasted text should go here>"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT|wxST_NO_AUTORESIZE );
    label->Wrap( -1 );
    bSizer1->Add( label, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
    this->SetSizer( bSizer1 );
    this->Layout();
    this->Centre( wxBOTH );

    if (wxTheClipboard->Open())
    {
      wxTheClipboard->SetData(new wxTextDataObject("Hello this is pasted text"));
      wxTheClipboard->Close();
    }
    if (wxTheClipboard->Open())
    {
      if (wxTheClipboard->IsSupported( wxDF_TEXT ))
      {
        wxTextDataObject data;
        wxTheClipboard->GetData(data);
        label->SetLabel(data.GetText());
      }
      wxTheClipboard->Close();
    }
  }
  virtual ~MainFrame() { }
};

class demoApp: public wxApp
{
  MainFrame *frame = nullptr;
public:
  demoApp();
  virtual ~demoApp() { }
  virtual bool OnInit() override;
};

IMPLEMENT_APP(demoApp)
//#include <ApplicationServices/ApplicationServices.h>
demoApp::demoApp()
{
  //ProcessSerialNumber PSN;
  //GetCurrentProcess(&PSN);
  //TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
}
bool demoApp::OnInit()
{
  frame = new MainFrame(nullptr);
  frame->Show();
  SetTopWindow(frame);
  SetExitOnFrameDelete(true);
  return true;
}

你可以用类似的东西来构建它

g++ clipboard.cpp -o clipboard -std=gnu++11 -I/DeveloperLibs/wxWidgets-3.1.3/build-debug/lib/wx/include/osx_cocoa-unicode-static-3.1/ -I/DeveloperLibs/wxWidgets-3.1.3/include -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__ -D_DEBUG=1-stdlib=libc++ -L/DeveloperLibs/wxWidgets-3.1.3/build-debug/lib/ -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -lwx_baseu-3.1 -lwx_osx_cocoau_adv-3.1 -lwx_osx_cocoau_core-3.1 -liconv -lz -headerpad_max_install_names -lwxregexu-3.1 -lwx_osx_cocoau_qa-3.1 -framework Quartz -lwx_baseu_xml-3.1 -lwxjpeg-3.1 -lwxpng-3.1 -lwxzlib-3.1 -lwxexpat-3.1 -lwxtiff-3.1 -llzma

我完全看不出有什么问题??我应该注意到,相同的应用程序无法在 Mojave 下运行(使用 Sierra 系统中的二进制文件,或者甚至使用我的 Mojave 系统上的 wxWidgets 在 Mojave 下构建的二进制文件)。

标签: c++wxwidgets

解决方案


是的,不幸的是,在 3.1.3 发布前不久,复制到剪贴板的操作就被破坏了。在此提交中不久就修复了它,您应该能够在本地挑选 - 或者您可以更新到最新的主人。


推荐阅读