Keeping an eye on the clipboard

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
leiradella
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Sep 07, 2008 9:49 pm
Location: Rio de Janeiro, Brazil

Keeping an eye on the clipboard

Post by leiradella » Mon Aug 17, 2009 2:11 am

Hi All,

My app uses a timer in order to check if the clipboard contains compatible data that it can paste:

Code: Select all

void
Shader::OnTimer(wxTimerEvent& evt)
{
	m_MenuBar->Enable(wxID_PASTE, wxTheClipboard->IsSupported(wxDataFormat(wxT("igFragmentShader/Selection"))));
}
It works fine, but it feels like a waste of resources having the app regularly check the contents of the clipboard.

Is there any event that is fired when the clipboard content is changed?

Thanks,

Andre

ZuLuuuuuu
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Jun 21, 2009 8:48 am

Post by ZuLuuuuuu » Mon Aug 17, 2009 7:07 am

I haven't used yet but as far as I know, wxWidgets sends wxUpdateUIEvent events when it becomes idle so that you can check if anything needs to be updated when the application is idle (like if a menu item should become unavailable):

http://docs.wxwidgets.org/stable/wx_wxu ... ateuievent

Also, if you use standard identifiers like wxID_CUT, wxID_COPY or wxID_PASTE for your menus they should be automatically disabled according to the data on clipboard.

leiradella
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Sep 07, 2008 9:49 pm
Location: Rio de Janeiro, Brazil

Post by leiradella » Tue Aug 18, 2009 4:50 am

ZuLuuuuuu wrote:I haven't used yet but as far as I know, wxWidgets sends wxUpdateUIEvent events when it becomes idle so that you can check if anything needs to be updated when the application is idle (like if a menu item should become unavailable):

http://docs.wxwidgets.org/stable/wx_wxu ... ateuievent
Thanks, I'll take a look at it.
ZuLuuuuuu wrote:Also, if you use standard identifiers like wxID_CUT, wxID_COPY or wxID_PASTE for your menus they should be automatically disabled according to the data on clipboard.
I don't think wxID_CUT and wxID_COPY can be handled automatically because weather there's an object selected to be cut or copied is application dependent.

As for wxID_PASTE, I hope wxWidgets doesn't handle it for me as I only wanted it to be enabled if the clipboard's content is compatible with what my app expects. And from experience I think it's the app's responsibility to enable/disable it.

Thanks!

Andre

Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas » Tue Aug 18, 2009 8:06 am

Hello,

If we are talking about windows only project, then there is a function you might read about: SetClipboardViewer. However, if the project is multiplatform, I cannot help you :)
Everything requires a line of code.

leiradella
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Sep 07, 2008 9:49 pm
Location: Rio de Janeiro, Brazil

Post by leiradella » Tue Aug 18, 2009 1:56 pm

Romas wrote:Hello,

If we are talking about windows only project, then there is a function you might read about: SetClipboardViewer. However, if the project is multiplatform, I cannot help you :)
Thanks, but although the app is not multiplatform I don't want to tie it to any OS.

Cheers,

Andre

Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas » Wed Aug 19, 2009 11:49 am

You can write multiplaform class and tie with this function :P use your imagination
Everything requires a line of code.

Post Reply