Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2011-10

Request to add clipboard operation messages

12 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luiz Americo Pereira Camara

Hi,

In order to implement LM_CLEAR, LM_CUT, LM_PASTE and LM_COPY under LCL/Qt is necessary to notify the widgetset when those actions occurs.

I could not find a native way of doing so. AFAIK using QObject::connect it should be notified after the method (slot? - i'm c++ noob) is executed and is necessary that the message be sent before the Text is changed. Also it would be good the possibility to filter the action, i.e, if filtered in event::Filter the action should not occur.

I come with the following idea (i tried to compile under unix but got errors while using qmake so could not create a patch)

-Add constants for custom events (>QEvent::User): QEventClear, QEventCut, QEventPaste, QEventCopy
-Create create descendants to QLineEdit and QTextEdit -Override clear, cut, copy, paste methods for these descendants in those methods do (in pseudo code):

if not eventFilter(Self, QEventPaste/Clear/Cut/Copy) then
   inherited;
//maybe use QApplication.PostEvent instead of eventFilter?

-Return an instance of those descendants in QLine/TextEdit_create so the overloaded methods are used

As i said i dont program with c++ even could not build the qt wrapper, so maybe you can come with a better schema

Luiz

Reply by email

zeljko
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote
Hi, In order to implement LM_CLEAR, LM_CUT, LM_PASTE and LM_COPY under LCL/Qt is necessary to notify the widgetset when those actions occurs.

Why ? or better eg: if LCL sent LM_COPY to Qt ws, what happened before a) LCL already maded copy ?
b) LCL wants to copy something ?

Show quoted text 26 lines
I could not find a native way of doing so. AFAIK using QObject::connect it should be notified after the method (slot? - i'm c++ noob) is executed and is necessary that the message be sent before the Text is changed. Also it would be good the possibility to filter the action, i.e, if filtered in event::Filter the action should not occur. I come with the following idea (i tried to compile under unix but got errors while using qmake so could not create a patch) -Add constants for custom events (>QEvent::User): QEventClear, QEventCut, QEventPaste, QEventCopy -Create create descendants to QLineEdit and QTextEdit -Override clear, cut, copy, paste methods for these descendants in those methods do (in pseudo code): if not eventFilter(Self, QEventPaste/Clear/Cut/Copy) then inherited; //maybe use QApplication.PostEvent instead of eventFilter? -Return an instance of those descendants in QLine/TextEdit_create so the overloaded methods are used As i said i dont program with c++ even could not build the qt wrapper, so maybe you can come with a better schema

I can do that, just answer me on above questions.

zeljko

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/qt/attachments/20111013/04f5633b/attachment.html>

Reply by email

Felipe Monteiro de Carvalho
to zeljko

2011/10/13 zeljko :

Why ? or better eg: if LCL sent LM_COPY to Qt ws, what happened before

I think that this reffers to this bug (which is for Carbon, but seams to happen in Qt too): http://bugs.freepascal.org/view.php?id=20394

Basically I do Ctrl+C / Ctrl+V as a user in a TEdit and the TEdit does not receive LM_CLEAR, LM_CUT, LM_PASTE and LM_COPY

This impacts TDBEdit which wants to see this events and react to them.

Carbon has the same problem. In Carbon this is implemented, but does not get called =( I haven't yet figured what is wrong.

Felipe Monteiro de Carvalho

Reply by email

Luiz Americo Pereira Camara
to zeljko: Why ? or better eg: if LCL sent LM_COPY to Qt ws, what happened before a) LCL already…
zeljko wrote 14 lines
On Thursday 13 of October 2011 08:17:27 Luiz Americo Pereira Camara wrote: > Hi, > > In order to implement LM_CLEAR, LM_CUT, LM_PASTE and LM_COPY under > LCL/Qt is necessary to notify the widgetset when those actions occurs. Why ?

To fix the following bugs:

http://bugs.freepascal.org/view.php?id=20475
http://bugs.freepascal.org/view.php?id=20394
http://bugs.freepascal.org/view.php?id=20330

or better eg: if LCL sent LM_COPY to Qt ws, what happened before a) LCL already maded copy ?

No

b) LCL wants to copy something ?

Yes. Under Delphi you can even abort the copy

Under Qt those messages are not 're used to notify controls that a paste, copy, cut is about to occur. Delphi also allows to abort them. Lazarus currently does not allow that, but in win32 and gtk2 i can make also make abort. With the proposed i can make it work also on Qt

I attached a Delphi test program (switch CallInherited). You can also take a look at example in http://bugs.freepascal.org/view.php?id=20330

Under Lazarus it will not be possible to abort not calling inherited in all widgetsets but can be done using Message.Result at least in Qt, Gtk2 and Win32 like other events. Carbon does not was

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ConverterBackup.zip
Type: application/x-zip-compressed
Size: 1851 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/qt/attachments/20111013/215624d4/attachment.bin>

Reply by email

Felipe Monteiro de Carvalho
to Luiz Americo Pereira Camara

2011/10/13 Luiz Americo Pereira Camara :

They're used to notify controls that a paste, copy, cut is about to occur. Delphi also allows to abort them. Lazarus currently does not allow that, but in win32 and gtk2 i can make also make abort. With the proposed i can make it work also on Qt

Do you really need to abort them? ... I though you only wanted to get the notification.

I would recommend not depending on the abort possibility, I doubt about this will be possible to implement everywhere. But the notification should work, in principle.

Felipe Monteiro de Carvalho

Reply by email

Luiz Americo Pereira Camara
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 8 lines
2011/10/13 Luiz Americo Pereira Camara: > They're used to notify controls that a paste, copy, cut is about to occur. > Delphi also allows to abort them. Lazarus currently does not allow that, but > in win32 and gtk2 i can make also make abort. With the proposed i can make > it work also on Qt Do you really need to abort them? ... I though you only wanted to get the notification.

Delphi allows that. See the example i attached in previous mail. I can do currently with win32 and gtk2. Qt would be possible with my proposition.

It keeps carbon/cocoa.

I would recommend not depending on the abort possibility, I doubt about this will be possible to implement everywhere. But the notification should work, in principle.

If its not possible there's no problem (it can go to restrictions). Receiving the messages, preferentially before the text is changed, is enough to work properly.

Luiz

Reply by email

zeljko
to Luiz Americo Pereira Camara: To fix the following bugs: http://bugs.freepascal.org/view.php?id=20475…
Show quoted text 9 lines
Yes. Under Delphi you can even abort the copy Under Qt those messages are not handled at all. They're used to notify controls that a paste, copy, cut is about to occur. Delphi also allows to abort them. Lazarus currently does not allow that, but in win32 and gtk2 i can make also make abort. With the proposed i can make it work also on Qt

Ok, but then, we are talking about 2 different things. 1st: LCL clipboard msgs => ws ... lcl want to do something with clip ok, that's easy task IMO, adding QtLM_COPY,QtLM_PASTE... etc and process them shouldn't be a big task.

2nd: you want to abort standard clipboard ops over text controls like QLineEdit by intercepting widgetset ? If yes then I don't know level of complications about this.
Qt have default actions menu over such controls (QLineEdit, QTextEdit .. and others where QLineEdit or QTextEdit are inherited, like QComboBox, QSpinBox etc), so basically QEvent::Action/QEvent::Shortcut have to be intercepted and stopped if LCL wants so ... but I'm not sure if this will work ... must dig into qt code to see how is this implemented.

zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/qt/attachments/20111013/c1a9f9de/attachment-0001.html>

Reply by email

Luiz Americo Pereira Camara
to zeljko
zeljko wrote 12 lines
2nd: you want to abort standard clipboard ops over text controls like QLineEdit by intercepting widgetset ? If yes then I don't know level of complications about this. Qt have default actions menu over such controls (QLineEdit, QTextEdit .. and others where QLineEdit or QTextEdit are inherited, like QComboBox, QSpinBox etc), so basically QEvent::Action/QEvent::Shortcut have to be intercepted and stopped if LCL wants so ... but I'm not sure if this will work ... must dig into qt code to see how is this implemented.

[ sorry zeljko, somehow Thunderbird "Send to List" got confused]

It's not difficult nor requires much code, since Qt maps those actions to, e.g., QLineEdit:paste (i looked the callstack when context menu is used). Just do in c++ qt wrapper (pascalized code)

procedure QExLineEdit.paste; //override QLineEdit.paste
var
   AnEvent: QEvent;
begin
    AnEvent := QEvent.Create(QtPaste);
    if not eventFilter(self, AnEvent) then
       inherited paste;
end;

With this:
1) Qt WidgetSet will be notified before the text is changed
2) if the event is filtered no text is changed

If this does not work no need to more complicated trials. Only item 01 is required.

Luiz

Reply by email

zeljko
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote 34 lines
On 13/10/2011 09:40, zeljko wrote: > 2nd: you want to abort standard clipboard ops over text controls like > QLineEdit by intercepting widgetset ? If yes then I don't know level > of complications about this. > > Qt have default actions menu over such controls (QLineEdit, QTextEdit > .. and others where QLineEdit or QTextEdit are inherited, like > QComboBox, QSpinBox etc), so basically QEvent::Action/QEvent::Shortcut > have to be intercepted and stopped if LCL wants so ... but I'm not > sure if this will work ... must dig into qt code to see how is this > implemented. [ sorry zeljko, somehow Thunderbird "Send to List" got confused] It's not difficult nor requires much code, since Qt maps those actions to, e.g., QLineEdit:paste (i looked the callstack when context menu is used). Just do in c++ qt wrapper (pascalized code) procedure QExLineEdit.paste; //override QLineEdit.paste var AnEvent: QEvent; begin AnEvent := QEvent.Create(QtPaste); if not eventFilter(self, AnEvent) then inherited paste; end; With this: 1) Qt WidgetSet will be notified before the text is changed 2) if the event is filtered no text is changed If this does not work no need to more complicated trials. Only item 01 is required.

No, that cannot work. You cannot override C++ class in pascal, for your needs we need overrided QLineEdit in QtPas4 C library (eg. QLCLLineEdit), but I'm against it.Also another problem raises with QLineEdit members of QComboBOx,QSpinBox and others, all of them must be overrided with QLCLLineEdit in that case.

As I said, I'll try to intercept actions (since there it can be stopped), if that won't work then we must change bindings.

zeljko

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/qt/attachments/20111013/56455a21/attachment.html>

Reply by email

Luiz Americo Pereira Camara
to zeljko
zeljko wrote 76 lines
On Thursday 13 of October 2011 15:17:09 Luiz Americo Pereira Camara wrote: > On 13/10/2011 09:40, zeljko wrote: > > 2nd: you want to abort standard clipboard ops over text controls like > > QLineEdit by intercepting widgetset ? If yes then I don't know level > > of complications about this. > > > > Qt have default actions menu over such controls (QLineEdit, QTextEdit > > .. and others where QLineEdit or QTextEdit are inherited, like > > QComboBox, QSpinBox etc), so basically QEvent::Action/QEvent::Shortcut > > have to be intercepted and stopped if LCL wants so ... but I'm not > > sure if this will work ... must dig into qt code to see how is this > > implemented. > > [ sorry zeljko, somehow Thunderbird "Send to List" got confused] > > It's not difficult nor requires much code, since Qt maps those actions > to, e.g., QLineEdit:paste (i looked the callstack when context menu is > used). Just do in c++ qt wrapper (pascalized code) > > procedure QExLineEdit.paste; //override QLineEdit.paste > var > AnEvent: QEvent; > begin > AnEvent := QEvent.Create(QtPaste); > if not eventFilter(self, AnEvent) then > inherited paste; > end; > > > With this: > 1) Qt WidgetSet will be notified before the text is changed > 2) if the event is filtered no text is changed > > If this does not work no need to more complicated trials. Only item 01 > is required. No, that cannot work. You cannot override C++ class in pascal, for your needs we need overrided QLineEdit in QtPas4 C library (eg. QLCLLineEdit), but I'm against it.

I said "Just do in c++ qt wrapper"

I'm not saying to override in pascal (i just used pascal like language because i dont know how c++ inherited call works). I'm proposing to override in C++ wrapper. Most specifically in qlineedit_c.cpp.

After implementing the descendant (QExLineEdit) overriding paste, cut, clear, copy the only change required would be the below. No more changes. The same would apply to QTextEdit

C_EXPORT QLineEditH QLineEdit_create(QWidgetH parent) {

     return (QLineEditH) new QExLineEdit((QWidget*)parent);

}

Show quoted text 5 lines
Also another problem raises with QLineEdit members of QComboBOx,QSpinBox and others, all of them must be overrided with QLCLLineEdit in that case.

No need to do that changes in pascal side. Also no need to add TExQtLineEdit.

Just add the message constants (QEventPaste etc) and handle the messages/events in TQtLineEdit.EventFilter

As I said, I'll try to intercept actions (since there it can be stopped), if that won't work then we must change bindings.

Ok. Let me know when you get something

Luiz

Reply by email

zeljko
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote 6 lines
> Also another problem raises with QLineEdit members of > QComboBOx,QSpinBox and others, all of them must be overrided with > QLCLLineEdit in that case. No need to do that changes in pascal side. Also no need to add TExQtLineEdit.

O yes, you're wrong about this. If we don't override QLineEdit of QComboBox/QSpinBox etc then it'll use qt's implementation and no messaging.

zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/qt/attachments/20111013/0d8aa499/attachment.html>

Reply by email

Luiz Americo Pereira Camara
to zeljko
zeljko wrote 21 lines
On Thursday 13 of October 2011 16:13:10 Luiz Americo Pereira Camara wrote: > > Also another problem raises with QLineEdit members of > > QComboBOx,QSpinBox and others, all of them must be overrided with > > QLCLLineEdit in that case. > > No need to do that changes in pascal side. Also no need to add > TExQtLineEdit. O yes, you're wrong about this. If we don't override QLineEdit of QComboBox/QSpinBox etc then it'll use qt's implementation and no messaging.

Yes you are right.

Anyway i managed to build the binding and after a c++ crash curse on net i created a QLineEdit derived. Unfortunately paste, cut, copy methods are not virtual so cannot be overriden.

I hope you can get a way to intercept those actions before text is changed. Don't bother if you cant abort the action since is not fundamental to get things working in LCL

Luiz

Reply by email