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++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » Ctrl * GetCallbackCtrl()
Ctrl * GetCallbackCtrl() [message #6110] Tue, 31 October 2006 08:56 Go to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Hi!

Now in upp isn't possible to obtain ctrl address in its callback method eg:

Button btn;
btn <<= THISBACK(Action);

void Action()
{
//What ctrl is calling this action??
Ctrl * ctrl = GetCallbackCtrl();
}

Such method should work at least for default WhenAction (with such a restriction it can be coded at Ctrl class level)

I need it for my grid. I just have to move cursor to the proper line of grid - line where clicked ctrl is. Because now child control grabs all events the underlying grid dosn't recieve any messages from system and for examle LeftDown is not called (where I set the cursor line)

Is adding such a method possible?
Re: Ctrl * GetCallbackCtrl() [message #6113 is a reply to message #6110] Tue, 31 October 2006 11:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I think we already have a better option:

Button btn;
btn <<= THISBACK1(Action, line);

void Action(int line)
{
...
}

Of course to what degree this is applicable to your problem is debatable (but I think GetCallbackCtrl does not solve this problem as well).

In ArrayCtrl, the issue is solved using ChildGotFocus...

Mirek
Re: Ctrl * GetCallbackCtrl() [message #6117 is a reply to message #6113] Tue, 31 October 2006 13:08 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

luzr wrote on Tue, 31 October 2006 05:34

I think we already have a better option:

Button btn;
btn <<= THISBACK1(Action, line);

void Action(int line)
{
...
}



Line number is unknown until ctrl is clicked...

Quote:



Of course to what degree this is applicable to your problem is debatable (but I think GetCallbackCtrl does not solve this problem as well).

In ArrayCtrl, the issue is solved using ChildGotFocus...

Mirek


ChildGotFocus is not enough. Option, Button, DropList don't get focus when you click on them using left mouse button...
It works fine only for Edit*

Try:

void MakeDropList(One<Ctrl>& ctrl)
{
ctrl.Create<DropList>()
.Add(0, "None")
.Add(1, "Minimal")
.Add(2, "Full");
}

void MakeButton(One<Ctrl>& ctrl)
{
ctrl.Create<Button>();
ctrl->WantFocus();
}

void MakeEdit(One<Ctrl>& ctrl)
{
ctrl.Create<EditString>();
ctrl->WantFocus();
}

arr.AddColumn("1").Ctrls(MakeDropList);
arr.AddColumn("2").Ctrls(MakeButton);
arr.AddColumn("3").Ctrls(MakeEdit);


and click at columns with button or droplist. Cursor wont change its position.
Re: Ctrl * GetCallbackCtrl() [message #6119 is a reply to message #6117] Tue, 31 October 2006 13:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
unodgs wrote on Tue, 31 October 2006 07:08

luzr wrote on Tue, 31 October 2006 05:34

I think we already have a better option:

Button btn;
btn <<= THISBACK1(Action, line);

void Action(int line)
{
...
}



Line number is unknown until ctrl is clicked...



How so? You do not know on which line you have placed the Button?

Anyway, instead of int line, you can use Ctrl *ctrl and THISBACK1(Action, &btn).

Quote:


ChildGotFocus is not enough. Option, Button, DropList don't get focus when you click on them using left mouse button...
It works fine only for Edit*



Of course. That is what I expect from the ArrayCtrl (moving focus moves cursor).

Actually, what I wanted to say is that perhaps not even WhenAction is enough here.... but OTOH all depends on what you really expect.

Quote:


and click at columns with button or droplist. Cursor wont change its position.



Yes.

Mirek
Re: Ctrl * GetCallbackCtrl() [message #6120 is a reply to message #6119] Tue, 31 October 2006 13:46 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

How so? You do not know on which line you have placed the Button?

Anyway, instead of int line, you can use Ctrl *ctrl and THISBACK1(Action, &btn).


Yes, you're right, line is constant for ctrl..
Second solution is even better, I already thought about that.

Quote:

Of course. That is what I expect from the ArrayCtrl (moving focus moves cursor).

Actually, what I wanted to say is that perhaps not even WhenAction is enough here.... but OTOH all depends on what you really expect.


The problem is that in my case cursor should always change line if click is in another place. It is connected with callbacks
WhenUpdateRow, WhenUpdateCell mostly used to updating a database. If I click option ctrl in cell the value of cell is changed - WhenUpdateCell should be called and cursor should be moved to this row - to update provious row and to be prepare to call WhenUpdateRow at the new row.
Moving cursor for all controls is more logical to me. Wide used developer express grid behave the same.
Re: Ctrl * GetCallbackCtrl() [message #6121 is a reply to message #6120] Tue, 31 October 2006 14:01 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

Anyway, instead of int line, you can use Ctrl *ctrl and THISBACK1(Action, &btn).


Ok, I used similar form, and it works perfectly. I wonder why I didn't wanted to do it earlier...
Re: Ctrl * GetCallbackCtrl() [message #6193 is a reply to message #6121] Thu, 02 November 2006 09:36 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Ok, it's not so perfect... Wink Because if I change cursor in ChildGotFocus for edits the cursor change its place immediately on left click. For rest of controls cursor change place in WhenAction routine and it happens mostly on left mouse up.
Anyway I patched a little bit CtrlCore Wink and I hope you'll accept this. What I've done is:

CtrlCore.h : Ctrl class

virtual void ChildMouseAction(Ctrl * ctrl, int event, Point p) {}


CtrlMouse.cpp

Image Ctrl::DispatchMouseEvent(int e, Point p, int zd) {
	if(!IsEnabled())
		return Image::Arrow();
	if(captureCtrl && captureCtrl != this && captureCtrl->IsMouseActive())
		return captureCtrl->MEvent0(e, p + GetScreenRect().TopLeft() -
		                            captureCtrl->GetScreenRect().TopLeft(), zd);
	Ctrl *top = this;
	if(e == MOUSEWHEEL && !GetParent()) {
		Ctrl *w = GetFocusCtrl();
		if(w) {
			top = w->GetTopCtrl();
			p = GetMousePos() - top->GetScreenRect().TopLeft();
		}
	}
	Ctrl *q = top->ChildFromPoint(p);
	if(parent)
		parent->ChildMouseAction(q, e, p);
	return q ? q->DispatchMouseEvent(e, p, zd) : top->MEvent0(e, p, zd);
}

This line was added:
if(parent) parent->ChildMouseAction(q, e, p);


With such a simple modification I can override ChildMouseActtion in my grid ctrl and has control over mouse events before they go to any child contol.

What do you think about it?
Re: Ctrl * GetCallbackCtrl() [message #6194 is a reply to message #6193] Thu, 02 November 2006 09:41 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

There should be
if(parent && q)
	parent->ChildMouseAction(q, e, p);


ChildMouseAction should be renamed to ChildMouseEvent I think..

[Updated on: Thu, 02 November 2006 09:43]

Report message to a moderator

Re: Ctrl * GetCallbackCtrl() [message #6196 is a reply to message #6193] Thu, 02 November 2006 14:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
unodgs wrote on Thu, 02 November 2006 03:36

Ok, it's not so perfect... Wink



Smile

Quote:


Because if I change cursor in ChildGotFocus for edits the cursor change its place immediately on left click. For rest of controls cursor change place in WhenAction routine and it happens mostly on left mouse up.
Anyway I patched a little bit CtrlCore Wink and I hope you'll accept this. What I've done is:

CtrlCore.h : Ctrl class

virtual void ChildMouseAction(Ctrl * ctrl, int event, Point p) {}


CtrlMouse.cpp

Image Ctrl::DispatchMouseEvent(int e, Point p, int zd) {
	if(!IsEnabled())
		return Image::Arrow();
	if(captureCtrl && captureCtrl != this && captureCtrl->IsMouseActive())
		return captureCtrl->MEvent0(e, p + GetScreenRect().TopLeft() -
		                            captureCtrl->GetScreenRect().TopLeft(), zd);
	Ctrl *top = this;
	if(e == MOUSEWHEEL && !GetParent()) {
		Ctrl *w = GetFocusCtrl();
		if(w) {
			top = w->GetTopCtrl();
			p = GetMousePos() - top->GetScreenRect().TopLeft();
		}
	}
	Ctrl *q = top->ChildFromPoint(p);
	if(parent)
		parent->ChildMouseAction(q, e, p);
	return q ? q->DispatchMouseEvent(e, p, zd) : top->MEvent0(e, p, zd);
}

This line was added:
if(parent) parent->ChildMouseAction(q, e, p);


With such a simple modification I can override ChildMouseActtion in my grid ctrl and has control over mouse events before they go to any child contol.

What do you think about it?



Have you tested? This does not seemt to be correct to me; if I remember well, parent is always NULL here.... (DispatchMouseEvent is called by host platform for TopWindow).

Anyway, I think the requirement itself is sound.

Mirek
Re: Ctrl * GetCallbackCtrl() [message #6198 is a reply to message #6196] Thu, 02 November 2006 14:51 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

Have you tested? This does not seemt to be correct to me; if I remember well, parent is always NULL here.... (DispatchMouseEvent is called by host platform for TopWindow).

Well, it works at least in my gridtest. Grid instance is recieving children mouse messages.
Quote:


Anyway, I think the requirement itself is sound.


Does it mean something similar will be delivered Surprised ? If yes that would be great! Hope to see this very soon... Wink
Re: Ctrl * GetCallbackCtrl() [message #6199 is a reply to message #6198] Thu, 02 November 2006 14:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Should not the default implementation call ChildMouseEvent for parent?

Also, check MouseHook (you could implement the same thing most likely with hooking mouse messages, but with a bit more trouble...).

Mirek
Re: Ctrl * GetCallbackCtrl() [message #6200 is a reply to message #6199] Thu, 02 November 2006 15:11 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

luzr wrote on Thu, 02 November 2006 08:55

Should not the default implementation call ChildMouseEvent for parent?



I don't understand. In my modification it is just called for parent!

Quote:


Also, check MouseHook (you could implement the same thing most likely with hooking mouse messages, but with a bit more trouble...).


I'm aware of MouseHook, but it's too general. It's ok for tooltips but not for specific cases.
Re: Ctrl * GetCallbackCtrl() [message #6202 is a reply to message #6200] Thu, 02 November 2006 15:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member

virtual void ChildMouseAction(Ctrl * ctrl, int event, Point p)
{
   if(parent) parent->ChildMouseAction(ctrl, event, p);
}


Mirek
Re: Ctrl * GetCallbackCtrl() [message #6205 is a reply to message #6202] Thu, 02 November 2006 15:52 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

luzr wrote on Thu, 02 November 2006 09:15


virtual void ChildMouseAction(Ctrl * ctrl, int event, Point p)
{
   if(parent) parent->ChildMouseAction(ctrl, event, p);
}


Mirek

Good question. I have to think it over.
Re: Ctrl * GetCallbackCtrl() [message #6224 is a reply to message #6205] Thu, 02 November 2006 22:48 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

unodgs wrote on Thu, 02 November 2006 09:52

luzr wrote on Thu, 02 November 2006 09:15


virtual void ChildMouseAction(Ctrl * ctrl, int event, Point p)
{
   if(parent) parent->ChildMouseAction(ctrl, event, p);
}


Mirek

Good question. I have to think it over.


It seems that is unnecessary. I have created custom ctrl with StaticRect and Option in this rect. Then I add it to grid for each row (Ctrls()). Even if I was clicking most inner ctrl grid was recieving mouse events of this ctrl. It seems that one call in DispatchMouseEvent is enough as it sends events throug full ctrls chain.
Re: Ctrl * GetCallbackCtrl() [message #6225 is a reply to message #6224] Thu, 02 November 2006 22:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
unodgs wrote on Thu, 02 November 2006 16:48

unodgs wrote on Thu, 02 November 2006 09:52

luzr wrote on Thu, 02 November 2006 09:15


virtual void ChildMouseAction(Ctrl * ctrl, int event, Point p)
{
   if(parent) parent->ChildMouseAction(ctrl, event, p);
}


Mirek

Good question. I have to think it over.


It seems that is unnecessary. I have created custom ctrl with StaticRect and Option in this rect. Then I add it to grid for each row (Ctrls()). Even if I was clicking most inner ctrl grid was recieving mouse events of this ctrl. It seems that one call in DispatchMouseEvent is enough as it sends events throug full ctrls chain.



If that is true, something is wrong Smile

(My bet is that "wrong" is implementation - DispatchMouseEvent really is not the right place).

Mirek
Re: Ctrl * GetCallbackCtrl() [message #6226 is a reply to message #6225] Thu, 02 November 2006 23:08 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

If that is true, something is wrong

(My bet is that "wrong" is implementation - DispatchMouseEvent really is not the right place).


I've only tried to solve my problem and my first thought was that DispatchMouseEvent is the right place. If you know better / more correct solution please implement it! I really need it.
Previous Topic: Debugger error
Next Topic: Copy and Paste changes colors in Icon Edit [BUG]
Goto Forum:
  


Current Time: Tue Apr 30 04:33:48 CEST 2024

Total time taken to generate the page: 0.07557 seconds