wxwidget

3

First you need to see to this bug "PLT-19966", it is a bug which only appear in linux GUI(Tachyon and Tflex). It exist in our SetupTree, Usage Monitor, RET Seting... You can easily get it when you select some text in a wxTextCtrl and then swich cursor to other empty textctrl. Then the text you selected will just 'disappear'

alt text

after select part of the text and switch cursor to other textCtrl alt text

It cost me lots of time to debug and find out the root cause of this bug. Maybe you wouldn’t believe it cause by a general function which we use frequently: Disalbe() & Enable()

Here I get a demo app to reproduce this bug:

I get a frame which have controls as you see , 2 buttons and 2 textCtrl.

After click Btn1 , it will start a timer and Disable the whole frame by invoke Diable;

void MyFrame::OnBtn1Click( wxCommandEvent& event )
{
     m_timer.Start(2000,true);
     Disable();
}

And after 2s, the timer is timeout and will invoke Enable() to enable the frame again.

void MyFrame::OnTimer( wxTimerEvent& event )
{
    wxLogDebug("Time out");
     Enable();
     wxLogDebug("Enable");
}

then you can select the text "st" int "test", switch to the textCtrl beside it and then 'st' disappear. The disgustind bug came out again.

alt text

You can test it in frame, dialog, and even panel which contain wxTextCtrl.

If you really want to enable all controls in a frame,dialog, and panel, you can use below code instead. It will loop all its children and invoke child's enable function one by one(it won't cause problem).

void MyFrame::EnableAllChild( bool enable )
{
    for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
        node;
        node = node->GetNext() )
    {
        wxWindow *child = node->GetData();
        child->Enable(enable);
    }

}

After dig into the wxWidgets source code in GTK version, I find maybe cause by the gtk function " gtk_widget_set_sensitive" which maybe can't resume all event correctly .

bool wxWindowGTK::Enable( bool enable )
{
    wxCHECK_MSG( (m_widget != NULL), false, wxT("invalid window") );

    if (!wxWindowBase::Enable(enable))
    {
        // nothing to do
        return false;
    }

    gtk_widget_set_sensitive( m_widget, enable );
    if ( m_wxwindow )
        gtk_widget_set_sensitive( m_wxwindow, enable );

    wxWindowNotifyEnable(this, enable);

    return true;
}

I don't exactly whether it is a bug of GTK or wxWidgets. And want to remind you:

Be careful next time when you want to use Disable and Enable(false) function to disable a whole frame,dialog or other windows contains controls like panel.

Thanks.

report

asked Sep 24 '13 at 13:25

junbin's gravatar image

junbin
510615

closed Jan 16 at 17:00

Echo's gravatar image

Echo
861825

Great work! Thanks!

(Sep 24 '13 at 13:44) liangzhao

So the finial solution is to call EnableAllChild instead of Enable? I'm still confused why this can fix the bug.

(Sep 24 '13 at 13:57) liangzhao

The question has been closed for the following reason "Other" by Echo Jan 16 at 17:00


4 Answers:
2

text ctrl bug

This bug is fixed in the latest wxWidget.

But nobody know why, they just simply removed wxTextCtrl::OnEnabled(),that is OnParentEnable() function in v2.8.9.

Replacing Enable() with EnableAllChild() is buggy, we should upgrade the wxwidget now.

link | award points | report

answered Jan 15 at 17:46

miliao's gravatar image

miliao
1.9k836

edited Jan 15 at 17:46

1

We can disable our controls in a frame or dialog one by one,it won't cause any problem. But we can't use frame->Disable() to disable all controls in that frame.

Though frame->Disable() will also loop all controls and disable them one by one, but it also invoke

 gtk_widget_set_sensitive( m_widget, enable );

as you can see in the function above:

bool wxWindowGTK::Enable( bool enable )

It seem there's something wrong with this GTK function, because I don't familiar with GTK programming , so I also don't why. Calling EnableAllChild is a function loop all controls and disable them one by one , and it don't invoke gtk_widget_set_sensitive.

link | award points | report

answered Sep 24 '13 at 14:13

junbin's gravatar image

junbin
510615

Good work!I can image it is not easy to find out all these. This bug is weird. Maybe we can do some more test on the Enable/Disable to locate the correct behavior, or at least what is the real cause on earth.

After all, Eanble() and EnableAllChild() are different and thus have different effect. Simply replacing Enable() with EnableAllChild() is not a perfect solution I think.

And this still can not explain everything,eg, why we have to set other textctrl empty to reproduce this bug, and the lose-focus issue.

I guess there is something more in it.

(Sep 25 '13 at 01:08) miliao
0

Be careful, this bug will also cause by using 'SetBackgroundColour', like:

//m_typeTC is a wxTextCtrl 
m_typeTC->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));

you can easily write a demo to test it in linux.

link | award points | report

answered Oct 08 '13 at 17:11

junbin's gravatar image

junbin
510615

0

For this issue, the simplest/safe solution is to write our own TextCtrl.
For example, TyTextCtrl, which will derive from wxTextCtrl, and make virtual function 'OnParentEnable(bool)' empty (Use default behavior)

class TyTextCtrl : public wxTextCtrl
{
public:
    TyTextCtrl() { }
    TyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value = wxEmptyString,
         const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = 0,
         const wxValidator& validator = wxDefaultValidator, const wxString &name = wxTextCtrlNameStr)
    : wxTextCtrl(parent, id, value, pos, size, style, validator, name)
    { }
#ifdef _LINUX_GUI_
    virtual void OnParentEnable(bool) { } // leave it empty
#endif
};

Already tested, above solution works.

link | award points | report

answered Jan 16 at 19:36

Zero's gravatar image

Zero
4.4k19109

Follow this question

By Email:

You are not subscribed to this question.

subscribe me

(you can adjust your notification settings on yourprofile)

By RSS:

 Answers

 Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

wxwidgets ×46

Asked: Sep 24 '13 at 13:25

Seen: 48 times

Last updated: Jan 16 at 19:36

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值