"\n" doesn't not work on windows ? Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

"\n" doesn't not work on windows ?

Post by Maeglix »

Hey !

I am building a wxTreeCtrl and i would like that some of the item to be on multiple line.
So i use "\n" in the wxString i want to be on multiple line.

It works perfectly on linux but on windows it just ignore the "\n". For example "test\ntest" becomes "testtest".

So did i do something wrong or is this normal ? Is there any workaround ?

Thanks for your help.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: "\n" doesn't not work on windows ?

Post by PB »

Perhaps the native undlerlying control on MSW (tree view) does not support multiline text of its nodes?
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: "\n" doesn't not work on windows ?

Post by Maeglix »

I don't know. In this case i would like to know if there is an other way to do what i want.
lfjking
Earned some good credits
Earned some good credits
Posts: 102
Joined: Mon Nov 14, 2016 1:35 pm

Re: "\n" doesn't not work on windows ?

Post by lfjking »

Maeglix wrote:Hey !

I am building a wxTreeCtrl and i would like that some of the item to be on multiple line.
So i use "\n" in the wxString i want to be on multiple line.

It works perfectly on linux but on windows it just ignore the "\n". For example "test\ntest" becomes "testtest".

So did i do something wrong or is this normal ? Is there any workaround ?

Thanks for your help.

You can try to use "\r\n"
"\n" should be valid on the command line
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: "\n" doesn't not work on windows ?

Post by Maeglix »

I tried, it didn't work.
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: "\n" doesn't not work on windows ?

Post by Maeglix »

Nobody ?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: "\n" doesn't not work on windows ?

Post by doublemax »

PB wrote:Perhaps the native undlerlying control on MSW (tree view) does not support multiline text of its nodes?
Altough i couldn't find any "official" confirmation on MSDN, i'm pretty sure this is the case. I can't remember to have ever seen a multi-line text in a standard tree control under Windows.
Use the source, Luke!
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: "\n" doesn't not work on windows ?

Post by Maeglix »

Ok thank you so i will try to find another way.
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 469
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: "\n" doesn't not work on windows ?

Post by New Pagodi »

Maeglix wrote:Ok thank you so i will try to find another way.
Maybe the generic tree control would work. I don't remember how to use it on windows though.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: "\n" doesn't not work on windows ?

Post by PB »

wxGenericTreeCtrl does not properly support multiline node labels either (they overlap).

Code: Select all

#include <wx/wx.h>
#include <wx/treectrl.h>
#include <wx/generic/treectlg.h>

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY, _("Test"))
    {
        wxGenericTreeCtrl* ctrl = new wxGenericTreeCtrl(this, wxID_ANY);
        ctrl->AddRoot("Root\r\nLine2");
        ctrl->AppendItem(ctrl->GetRootItem(), "Item 1\r\nLine2");
        ctrl->AppendItem(ctrl->GetRootItem(), "Item 2\r\nLine2");
        ctrl->ExpandAll();
    }	
};

class MyApp : public wxApp
{
public:	
    bool OnInit()
    {
        (new MyFrame())->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
wxDataViewTreeCtrl does not seem to support the feature too but I never used the class so I may have not used it properly

Code: Select all

#include <wx/wx.h>
#include <wx/dataview.h>

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY, _("Test"), wxDefaultPosition, wxSize(200,200))
    {
        wxDataViewTreeCtrl* treeCtrl = new wxDataViewTreeCtrl(this, wxID_ANY);
        wxDataViewItem rootItem = treeCtrl->AppendItem(wxDataViewItem(0), "Root\nLine2");        
    }
};

class MyApp : public wxApp
{
public:	
    bool OnInit()
    {
        (new MyFrame())->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
Post Reply