Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » ArrayCtrl: Edit doesn't like Option
ArrayCtrl: Edit doesn't like Option [message #29516] |
Mon, 25 October 2010 17:15 |
cbpporter
Messages: 1401 Registered: September 2007
|
Ultimate Contributor |
|
|
Let me start by saying that this is the first time I used ArrayCtrl. I tried it before, but it seemed overkill and I have been using ColumnList up until now and it served my needs quite well.
But now I need it and I'm having a problem with it. I have some columns with Edit(someEditor). Like EditString. Works fine. But when adding Ctrls<Option> to some other columns, Edit no longer works for the previous ones. Probably related to the way the embedded Option gets focused. It had huge troubles with Option and OptionTree and was wondering if there is a solution for this without having to go through all that trouble again.
|
|
|
|
Re: ArrayCtrl: Edit doesn't like Option [message #30071 is a reply to message #29522] |
Tue, 07 December 2010 09:37 |
|
kohait00
Messages: 939 Registered: July 2009 Location: Germany
|
Experienced Contributor |
|
|
i've got another problem, which is similar to yours, so i just reuse your thread
problem: ArrayCtrl has got Option's as Editors, and some EditInt's.. everytime changes are made, i need to forward them in a custim action..(OnAction)
ArrayCtrl ac;
...
Ctrl* p = new Option();
p->WhenAction = THISBACK(OnAction);
SetCtrl(k, 1, p);
++k;
...
p = new EditInt();
p->WhenAction = THISBACK(OnAction);
ac.SetCtrl(k, 1, p);
...
void MyClass::OnAction()
{
DoWork(ac.Get(0), ac.Get(1));
}
this works fine for EditInt, because the cursor is set properly, when EditInt is 'selected' to be edited, because EditField has SetFocus somewhere in it.. with Option, no cursor is set, when i cklick it, so the OnAction fails with an ASSERT.
when i manually select the row, clicking on the right remaining spot, that belongs to arrayctrl, and then, on the Option, it works..
any help, how to make Option be Focus aware? i dont like to mess with the upp code.. maybe i'm doing sth wrong ..
[Updated on: Tue, 07 December 2010 09:59] Report message to a moderator
|
|
|
Re: ArrayCtrl: Edit doesn't like Option [message #30072 is a reply to message #30071] |
Tue, 07 December 2010 11:08 |
|
You could use GridCtrl it moves cursor always. However if you prefer ArrayCtrl just make your own control that derives from ArrayCtrl and override ChildGotFocus() method. In this method place the cursor in the correct location (row). This method is called before control's action callback so everything should work.
|
|
|
|
Re: ArrayCtrl: Edit doesn't like Option [message #30075 is a reply to message #30074] |
Tue, 07 December 2010 12:37 |
|
Sorry. I made a mistake I meant overriding void ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags). I use this method in GridCtrl to move cursor if embedded control is clicked and it works perfectly.
|
|
|
|
Re: ArrayCtrl: Edit doesn't like Option [message #30078 is a reply to message #30076] |
Tue, 07 December 2010 13:14 |
|
kohait00 wrote on Tue, 07 December 2010 06:39 |
wouldn't it be better to also implement this for ArrayCtrl?
|
Well, moving cursor is IMO the correct way to deal with embedded controls and most of grids works this way otherwise you break consistency in control's callbacks. On the other hand Mirek has different opinion here. If I remember correctly he wanted to be able to type the text in one row without loosing focus by clicking option/button/droplist in another row or the same row but in another column. Cursor is moved only if you click on edit control. Actually I don't know in which scenario this can be useful .
|
|
|
|
Re: ArrayCtrl: Edit doesn't like Option [message #30090 is a reply to message #30080] |
Wed, 08 December 2010 09:51 |
|
kohait00
Messages: 939 Registered: July 2009 Location: Germany
|
Experienced Contributor |
|
|
do you have any code already as a fix for ArrayCtrl?
i mean a ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags) based one, just to have a base for mirek to talk about
EDIT:
ok, i stiched an add to ArrayCtrl, in a similar manner like you did in GridCtrl, now it's up on Mirek to decide if this goes well..thankyou for yor support
ArrayCtrl.h:38
virtual void ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags);
ArrayCtrl.cpp:713
void ArrayCtrl::ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags)
{
if(child != GetFocusCtrl())
{
if(event == LEFTDOWN || event == RIGHTDOWN || event == MOUSEWHEEL)
{
Point p = FindCellCtrl(child);
if(!IsNull(p))
{
if(nocursor)
ScrollInto(p.y);
else
SetCursor(p.y);
}
}
}
Ctrl::ChildMouseEvent(child, event, p, zdelta, keyflags);
}
[Updated on: Wed, 08 December 2010 11:19] Report message to a moderator
|
|
|
|
Re: ArrayCtrl: Edit doesn't like Option [message #30354 is a reply to message #30103] |
Sun, 26 December 2010 01:12 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
kohait00 wrote on Thu, 09 December 2010 03:31 | there is a
function, that enables Option and others to have SetFocus functionality, so ArrayCtrl changes Cursor right.
but the general question as stated above remains..
|
IMO, you might not want to move focus in ArrayCtrl for the same reason you might not want to move it in general dialog. (Well, as unodgs stated, it always seemed illogical to me. I really dislike those focus rectangles on buttons, options and switches
Also, note there is even a global setting, call Ctrl::ClickFocus(true) and you are done...
Mirek
|
|
|
|
Re: ArrayCtrl: Edit doesn't like Option [message #34970 is a reply to message #29522] |
Thu, 22 December 2011 02:43 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello.
While reading uppdev sources, I found ArrayOption example.
I think, it could be used here, like follows:
Toggle Spoiler
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class App : public TopWindow {
private:
int toggle_count;
LabelBase *toggle_label;
public:
typedef App CLASSNAME;
App();
// Ctrls
ArrayCtrl list;
ArrayOption option;
EditString text;
// Bars
void ArrayBar(Bar& bar);
// Methods
void FillWithData();
void ToggleCount(bool value);
void ToggleOption();
void ToggleHeaderOption();
// Events
void OnHeaderClick();
void OnOptionClick();
};
App::App() : toggle_count(0)
{
Title("ArrayOption example");
CenterScreen().Sizeable().MinimizeBox().MaximizeBox();
const Size sz(320, 240);
SetMinSize(sz); SetRect(sz);
list.AutoHideSb();
// Initialize ArrayOption column and assign label address
toggle_label = &option.AddColumn(list).HeaderTab().Fixed(30).SetAlign(ALIGN_CENTER);
// Initialize ArrayCtrl column
list.AddColumn("Content", 120).Edit(text);
// Assign callbacks
list.HeaderTab(0).WhenAction = THISBACK(OnHeaderClick);
list.WhenBar = THISBACK(ArrayBar);
option.WhenAction = THISBACK(OnOptionClick);
Add(list.VSizePosZ(4, 4).HSizePosZ(4, 4));
}
// Bars
void App::ArrayBar(Bar& bar)
{
if (list.HasFocus() && list.IsCursor())
bar.AddKey(K_SPACE, THISBACK(ToggleOption));
list.StdBar(bar);
}
// Methods
void App::FillWithData()
{
GuiLock __;
list.Clear();
for (int i = 1; i <= 10; ++i)
list.Add(i % 2 == 0, FormatIntRoman(i, true));
toggle_count = 5;
ToggleHeaderOption();
}
void App::ToggleCount(bool value)
{
if (value)
++toggle_count;
else
--toggle_count;
}
void App::ToggleOption()
{
GuiLock __;
list.Set(0, !list.Get(0));
ToggleCount(list.Get(0));
ToggleHeaderOption();
}
void App::ToggleHeaderOption()
{
static bool changed = true;
if (toggle_count == list.GetCount()) {
toggle_label->SetImage(CtrlsImg::Get(CtrlsImg::I_O1), 2);
changed = true;
}
else if (changed) {
toggle_label->SetImage(CtrlsImg::Get(CtrlsImg::I_O0), 2);
changed = false;
}
}
// Events
void App::OnHeaderClick()
{
GuiLock __;
bool value = true;
const int count = list.GetCount();
if (toggle_count == count) {
value = false;
toggle_count = 0;
}
else
toggle_count = count;
for (int i = 0; i < count; ++i)
if (list.Get(i, 0) != value)
list.Set(i, 0, value);
ToggleHeaderOption();
}
void App::OnOptionClick()
{
ToggleCount(list.Get(0));
ToggleHeaderOption();
PromptOK(String().Cat() << "{{1:2:3@L [* Index:: Option:: Content]::! "
<< list.GetCursor() << ":: " << FormatBool(list.Get(0)) << ":: " << list.Get(1) << " }}");
}
GUI_APP_MAIN
{
Ctrl::GlobalBackPaint();
App app;
app.FillWithData();
app.Run();
}
[Updated on: Fri, 23 December 2011 21:08] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon May 06 04:20:07 CEST 2024
Total time taken to generate the page: 0.02624 seconds
|