Bug?

Help
2004-10-01
2013-04-15
  • Steven Weiss

    Steven Weiss - 2004-10-01

    Hi,
    perhaps I discovered a new bug:
    I have a tree_ctrl on a dialog and if you do this

    wnd<tree_ctrl> tree = child<tree_ctrl> (IDC_TREE_FOLDER);   
    tree->add_root_item(tv_item().text("test_string"));

    everything is ok and I'm happy :-).
    but if you do this

    wnd<tree_ctrl> tree = child<tree_ctrl> (IDC_TREE_FOLDER);   
    tree->del_all_items();
    tree->add_root_item(tv_item().text("test_string"));

    it should first delete all items and the insert a new rootitem but you can't see the item's text! I checked the TVM_-messages with the spy and the tree indeed receives all the necessary messages.

    can you check this please or am I doing something wrong?

     
    • Steven Weiss

      Steven Weiss - 2004-10-01

      another bug related to tree_ctrl:

      string item_text = item(hItem, TVIF_TEXT).text();

      will give you the text of the item, BUT what's really annoying is that the string is something like this (i put some hex after the readable string):

      "some_text" 00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ....

      you know what i mean...the string is 128 chars long and you can't just do
      item_text += "some_string_to_append";

      you would first have to strip the garbage away which is annoying. responsible for this is this function:

      template<class result_type, class self_type> void get_item_ex(result_type & result, const self_type & self, UINT msg, WPARAM wparam, int text_tag) {
              if ( result.m_raw.mask & text_tag)

                  result.m_text.resize(128, ' ');  // <-- this line!
      ...

      here's the fix:
      put

      string::size_type null_pos = result.m_text.find('\0');
      result.m_text.erase(null_pos, string::npos);

      at the end of the
      "if ( result.m_raw.mask & hd_item::text_tag) {"-block

      greetz steven

       
      • John Torjo

        John Torjo - 2004-10-02

        I'm not sure about this.

        I took another look at the code, and I think it's ok.
        I even tried some simple code, and it works as expected.

        Could you give me an example when my code fails?
        Thanks.

        Best,
        John

         
        • Steven Weiss

          Steven Weiss - 2004-10-03

          it fails everytime...look, i write this code

          wnd<tree_ctrl> tree = child<tree_ctrl> (IDC_FOLDER_TREE);
          string strPath = tree->item(hItem, TVIF_TEXT).text();
          strPath += "\\test.txt";

          the \\test.txt will indeed be appended to the string, BUT after the 00 20 20 20 20 20 20 .... and that's not the expected behaviour.

          i'm using the STL coming with vc++ toolkit 2003

           
    • John Torjo

      John Torjo - 2004-10-02

      Yup, you're right - it's a but of the treectrl alright (that is M$'s bug)

      Check out:
      https://bugs.eclipse.org/bugs/show_bug.cgi?id=24273

      So, you can do something like this:

              child<m_tree>()->set_redraw(false);
              child<m_tree>()->del_all_items();
              child<m_tree>()->set_redraw(true);

      Also, I've updated my code, so in v1.5 it'll happen by default.

      Best,
      John

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks