paste date to wxDatePickerCtrl from 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
praudmur
Earned a small fee
Earned a small fee
Posts: 16
Joined: Sat Sep 18, 2021 7:55 am

paste date to wxDatePickerCtrl from clipboard

Post by praudmur »

Hello!
Is there a way to make wxDatePickerCtrl accept date from clipboard?
Desired behaviour:

I copy text "05.05.2021", then click on wxDatePickerCtrl element, press "CTRL+V" and new date appears in the field.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: paste date to wxDatePickerCtrl from clipboard

Post by doublemax »

It should be possible. Unfortunately wxDatePickerCtrl doesn't support wxClipboardTextEvent, so you'd have to handle that yourself:

- catch wxEVT_CHAR key event on the wxDatePickerCtrl

- in the event handler, check if CTRL-V was pressed

- if yes, check if the clipboard contains any text
https://docs.wxwidgets.org/trunk/classwx_clipboard.html

- if yes, use wxDateTime::ParseDate to try to convert it to a data
https://docs.wxwidgets.org/trunk/classw ... b11391c962

- if that was successfull, set new value to wxDatePickerCtrl
Use the source, Luke!
praudmur
Earned a small fee
Earned a small fee
Posts: 16
Joined: Sat Sep 18, 2021 7:55 am

Re: paste date to wxDatePickerCtrl from clipboard

Post by praudmur »

doublemax wrote: Sat Sep 18, 2021 11:12 am It should be possible. Unfortunately wxDatePickerCtrl doesn't support wxClipboardTextEvent, so you'd have to handle that yourself:

- catch wxEVT_CHAR key event on the wxDatePickerCtrl

- in the event handler, check if CTRL-V was pressed

- if yes, check if the clipboard contains any text
https://docs.wxwidgets.org/trunk/classwx_clipboard.html

- if yes, use wxDateTime::ParseDate to try to convert it to a data
https://docs.wxwidgets.org/trunk/classw ... b11391c962

- if that was successfull, set new value to wxDatePickerCtrl
Thanks it worked. I used IsMouseInWindow() to check if mouse is on the DatePicker. Is there a better way?
For instance - the date is 05/06/2021.
I click on "05"(it's highlighted) and move the mouse the other way. Is there a way to detect if "05" is highlighted?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: paste date to wxDatePickerCtrl from clipboard

Post by doublemax »

praudmur wrote: Sat Sep 18, 2021 3:53 pm Thanks it worked. I used IsMouseInWindow() to check if mouse is on the DatePicker. Is there a better way?
For instance - the date is 05/06/2021.
I click on "05"(it's highlighted) and move the mouse the other way. Is there a way to detect if "05" is highlighted?
No. But why do you need that? If the control has keyboard focus and you press Ctrl-V, it should be sent to the pickerctrl.

The method i described works for pasting a whole date string, it won't work to paste individual numbers.
Use the source, Luke!
praudmur
Earned a small fee
Earned a small fee
Posts: 16
Joined: Sat Sep 18, 2021 7:55 am

Re: paste date to wxDatePickerCtrl from clipboard

Post by praudmur »

doublemax wrote: Sat Sep 18, 2021 4:38 pm
praudmur wrote: Sat Sep 18, 2021 3:53 pm Thanks it worked. I used IsMouseInWindow() to check if mouse is on the DatePicker. Is there a better way?
For instance - the date is 05/06/2021.
I click on "05"(it's highlighted) and move the mouse the other way. Is there a way to detect if "05" is highlighted?
No. But why do you need that? If the control has keyboard focus and you press Ctrl-V, it should be sent to the pickerctrl.

The method i described works for pasting a whole date string, it won't work to paste individual numbers.
That's a shame.
At the moment I have to hover the cursor over the Date picker in order to detect to what Date picker I need to paste from clipboard. This isn't always convenient.
Anyway - thank again for your help.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: paste date to wxDatePickerCtrl from clipboard

Post by ONEEYEMAN »

Hi,
How many pickers do you have?
The Ctrl+V shortcut is working on the control that has the focus. If you want to use mouse and the context menu - you need to handle it.

Thank you
Post Reply