Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » How to catch and overwrite child control event?
How to catch and overwrite child control event? [message #13673] Mon, 21 January 2008 01:39 Go to next message
kompotFX is currently offline  kompotFX
Messages: 7
Registered: January 2008
Promising Member
Hi,

I'm new in upp. The "not-well-documented" documentation can't help me so much in my simple task.

What I want:
I want to make port for short tool (I wrote in MFC some time ago) in order to use it on linux. I made a choice to use upp bcs it seems to be very simple, straight forward.
The main functionality I try to achieve is to catch DocEdit control key input events (child control of my dialog) and modify them. E.g. when user types "A", it appear as "B", "a" -> "b" etc. So, basically tool must make key filtering and convertion.
In MFC it was done very simple - all key events to child was modified by parent wnd by using PreTranslateMessage event.
In upp I tried use method Key(dword key, int count) of dialog - but no effect. The key user pressed was forwarded to control.
For myDocEdit <<= THISBACK(ModifyKey); - same thing Sad
I tried also derrive my own control from DocEdit - compiler returns an error from lay file:
error: 'MyClassX' does not name a type
In function 'void InitLayout(Upp::Ctrl&, L&, D&, MyAppLayout__layid&)...etc

What to do?
Re: How to catch and overwrite child control event? [message #13674 is a reply to message #13673] Mon, 21 January 2008 02:00 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
One more general (maybe application wide) way is to use a "keyhook".
I assume you derive your class from Ctrl or a Ctrl derived class (as usual in U++):

Define a KeyHook.

Below is the code of a key hook for intercepting Ctrl+Home key:


class foo : public Ctrl
{
// some other declarations...
// some other declarations...
 
	static bool CtrlKeyHook(Ctrl* ctrl, dword key, int count)	{ if(key == K_CTRL_HOME && ctrl == &myctrl) // here goes the intercepting function or method... // ; return true; }
}


As You can see in the above declaration, you can identify the "Ctrl" which sends the message too.

in the class implementation:
foo::foo()
{
	InstallKeyHook(&foo::CtrlKeyHook);
}

foo::~foo()
{
	DeinstallKeyHook(&foo::CtrlKeyHook);
}



(Two things: don't forget to return true (and dont forget to "Deinstall" hook...)

You can find more info about other hook types (mouse, state) in CtrlCore/Src/Ctrl section of the Help Topics of TheIDE Wink

Ps: I don't know why your code didn't work (I should work), but I uploaded a Key() virtual function version below. I Hope It'll help...
  • Attachment: KeyTest.rar
    (Size: 0.83KB, Downloaded 303 times)


[Updated on: Mon, 21 January 2008 02:21]

Report message to a moderator

Re: How to catch and overwrite child control event? [message #13675 is a reply to message #13673] Mon, 21 January 2008 09:56 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
Quote:

I tried also derrive my own control from DocEdit - compiler returns an error from lay file:
error: 'MyClassX' does not name a type


Before including the layout file, create a line in your sourcefile:
class MyClassX;

[Updated on: Mon, 21 January 2008 09:57]

Report message to a moderator

Re: How to catch and overwrite child control event? [message #13683 is a reply to message #13673] Tue, 22 January 2008 00:38 Go to previous messageGo to next message
kompotFX is currently offline  kompotFX
Messages: 7
Registered: January 2008
Promising Member
Ok guys, thank you for quick response.

1. I have tested including class MyClassX; before .lay lines. Same errors. I'm using upp 712-dev1. I included code in TestUpp.zip file, you can try to review it. Im try to derrive DocEditEx class from DocEdit control.
Compiler says:
In file included from C:\upp\uppsrc/CtrlCore/lay.h:22,
from C:\upp\examples\TestUpp\/TestUpp.h:11,
from C:\upp\examples\TestUpp\main.cpp:1:
C:\upp\examples/TestUpp/TestUpp.lay:2: error: field 'editTest' has incomplete type
C:\upp\examples/TestUpp/TestUpp.lay: In function 'void InitLayout(Upp::Ctrl&, L&, D&, TestUppLayout__layid&)
[with L = TestUpp, D = TestUpp]':


2. 2Oblivion:
Yes your suggestion in KeyTest code works, but gives no result, I expected. I need to control user input, not only observe changes.
I uploaded TestMfc_bin.zip - simple example made using MFC which changes user input "z"->"y" and "y"->"z" letters during typing.
Here also source in TestMfc_src.zip Check the CTestMfcDlg::PreTranslateMessage method which doing this functionality.

How can I achieve the same effect in UPP?

[Updated on: Tue, 22 January 2008 00:39]

Report message to a moderator

Re: How to catch and overwrite child control event? [message #13685 is a reply to message #13683] Tue, 22 January 2008 07:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
#ifndef _TestUpp_TestUpp_h
#define _TestUpp_TestUpp_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class DocEditEx : public DocEdit
{
	virtual bool Key(dword key, int count) {
		return DocEdit::Key(key < 65536 ? ToUpper((wchar)key) : key, count);
	}
};

#define LAYOUTFILE <TestUpp/TestUpp.lay>
#include <CtrlCore/lay.h>

class TestUpp : public WithTestUppLayout<TopWindow> {
public:
	typedef TestUpp CLASSNAME;
	TestUpp();
};

#endif


The problem is that class you use in .lay has to be defined before including .lay file.

Note that there is another workaround possible too: leave type field in .lay empty, then add the field in the final class, as public member. Of course, perhaps you do not need a .lay at all, for such simple case...

Mirek
Re: How to catch and overwrite child control event? [message #13687 is a reply to message #13673] Tue, 22 January 2008 10:04 Go to previous message
kompotFX is currently offline  kompotFX
Messages: 7
Registered: January 2008
Promising Member
Yes! It works!
Thanks for great support!
Previous Topic: BUG in UVS2 2384 release
Next Topic: Bug in UVS2 2399 release
Goto Forum:
  


Current Time: Fri Mar 29 01:43:45 CET 2024

Total time taken to generate the page: 0.01187 seconds