Hi,
sorry but its an UI application. i began from scratch wirh a simple uiq UI appllication c++ project. i also dont want to capture key strokes at the moment, i want to get an button click event. the button is clicked via the touchscreen of my P1i.
any ideas?
thx in advance.
:edit:
i followed a hint with HandlePointerEventL and i came to an solution. this solution is not state of the art i think but useable for me. by throwing away the active object idea and overriding the event handler method i can now handle a button click this way:
Code:
// i simply override the event handler method in my view to get a pointer event of my touchscreen
void CTestView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if (aPointerEvent.iType == TPointerEvent::EButton1Up)
{
CEikTextButton* button = LocateControlByUniqueHandle<CEikTextButton>(ETestButtonCtrl);
if (button->Rect().Contains(aPointerEvent.iPosition))
{
_LIT(tt,"Clicked");
button->SetTextL(tt,CEikCommandButtonBase::EFirst);
button->DrawNow();
}
}
CQikViewBase::HandlePointerEventL(aPointerEvent);
}
You can see how i determine which control was clicked. I ask myself, isnt there a better way to do this? Lets imagine a view that has a huge amount of buttons. In this view i have to loop over this->Controls() to get the control that was clicked. in other programming languages i can use ControlFromPoint() or something like that to determine the control at the specific point. Isnt there a function in symbian c++?
Second question is, how can i "override" the HandlePointerEventL method of my button? In other languages like delphi i do something like
button.HandlePointerEventL = MyEventHandlerMethod;
When i do this in symbian c++ i get an error message that i fogot a "&" which is true in this case, but when i insert a & in front of MyEventHandlerMethod i get an error that in ISO C++ i cannot do this. Whats the trick here?
Perhaps i should create a new class derived from a button class and then override the method. But again, here i dont get a clue how to insert a button with my own class in the resource file.
i also found a way to handle a button click with a command button (it also works with other button types i think) and without using coordinates. just override the HandleControlEventL() method of the view. heres my solution (the example shows a click handler that toggles the dimmed state of the button):
Code:
void CTestView::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType)
{
switch(aEventType)
{
case EEventStateChanged:
case EEventInteractionRefused:
{
if (aControl->UniqueHandle() == ETestButtonCtrl3)
{
CEikCommandButton* b = LocateControlByUniqueHandle<CEikCommandButton>(ETestButtonCtrl3);
TBool d = !b->IsDimmed();
b->SetDimmed(d);
b->DrawNow();
}
break;
}
default:
CQikViewBase::HandleControlEventL(aControl, aEventType);
break;
}
}
Thx for helping.
:edit2:
i finally managed to achieve my goal by rethinking the idea of creating a own class for my button (thx to sander for guiding me to the correct path). here are the steps:
1. define a new class for your button derived from e.g. CEikTextButton
2. override HandlePointerEventL() and handle your stuff in here
3. create an instance of the button in ViewConstructL() of a view
now we have 3 solutions . anyway, if somebody can explain one of the things mentioned in this thread:
1. how i can assign a event handler to an existing button object
2. how can the active scheduler call a RunL() method of an CActive object when no reference of the concering object is passed on requesting an event
thx for helping.