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.
paste date to wxDatePickerCtrl from clipboard
Re: paste date to wxDatePickerCtrl from clipboard
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
- 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!
Re: paste date to wxDatePickerCtrl from clipboard
Thanks it worked. I used IsMouseInWindow() to check if mouse is on the DatePicker. Is there a better way?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
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?
Re: paste date to wxDatePickerCtrl from clipboard
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.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?
The method i described works for pasting a whole date string, it won't work to paste individual numbers.
Use the source, Luke!
Re: paste date to wxDatePickerCtrl from clipboard
That's a shame.doublemax wrote: ↑Sat Sep 18, 2021 4:38 pmNo. But why do you need that? If the control has keyboard focus and you press Ctrl-V, it should be sent to the pickerctrl.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?
The method i described works for pasting a whole date string, it won't work to paste individual numbers.
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.
Re: paste date to wxDatePickerCtrl from clipboard
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
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