Problem using wxTextCtrl

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Oromis_32
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon May 17, 2010 4:14 pm
Contact:

Problem using wxTextCtrl

Post by Oromis_32 » Mon May 17, 2010 4:34 pm

Hi @all,

I'm writing a config dialog for my wxWidgets Application which saves its data in a XML-File. Thats not the problem, it works well.
What does not work is the simple wxTextCtrl. It's embarrassing that I have to post a problem with such an all-day class here, but I don't know how to make it work.
The problem is that the textCtrl is not editable. I definetly haven't set the wxTE_READONLY flag, but if I try to type sth into the Ctrl, the Text doesn't change.
here's my code:

Code: Select all

        // Extract of the constructor of my dialog class (inherited from wxDialog)
 
        // Coordinates for the controls
        int aiX[12];
	int aiY[12];
	aiX[0] = aiX[4] = aiX[8] = 10;
	aiX[1] = aiX[5] = aiX[9] = 200;
	aiX[2] = aiX[6] = aiX[10] = 390;
	aiX[3] = aiX[7] = aiX[11] = 580;

	aiY[0] = aiY[1] = aiY[2] = aiY[3] = 10;
	aiY[4] = aiY[5] = aiY[6] = aiY[7] = 130;
	aiY[8] = aiY[9] = aiY[10] = aiY[11] = 250;

	map<string, CItem*>::iterator it = itemMap.begin();
	for(int i = 0; i < 12; i++) {
		stringstream str("");
		str << "F" << (i+1);
                // Some explaining texts
		m_apHeadlines[i]   = new wxStaticText(this, -1, _T(str.str().c_str()), wxPoint(aiX[i], aiY[i]));
		m_apNameLabels[i]  = new wxStaticText(this, -1, _T("Name"), wxPoint(aiX[i], aiY[i] + BT_HEIGHT + 5));
		m_apPriceLabels[i] = new wxStaticText(this, -1, _T("Preis"), wxPoint(aiX[i], aiY[i] + 2 * (BT_HEIGHT + 5)));

		string sDefName = "", sDefPrice = "";
		float fDefPrice = 0.0f;
		if(it != itemMap.end()) {
			sDefName = (*it).second->GetName();
			fDefPrice = (*it).second->GetPrice();
			str.str("");
			str << fDefPrice;
			sDefPrice = str.str();
		}
                /******************************************\
                * Here is the problem                      *
                * these wxTextCtrls are not editable. why? *
                \******************************************/
		m_apNameInputs[i]  = new wxTextCtrl(this, wxID_ANY, sDefName, wxPoint(aiX[i] + 45, aiY[i] + BT_HEIGHT + 5), wxDefaultSize, 0);
		m_apPriceInputs[i] = new wxTextCtrl(this, wxID_ANY, sDefPrice, wxPoint(aiX[i] + 45, aiY[i] + 2 * (BT_HEIGHT + 5)), wxDefaultSize, 0);

		if(it != itemMap.end()) it++;
	}
thanks for your help!

Oromis_32

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Mon May 17, 2010 4:57 pm

Hi,

what is the parent ("this" in this code)?
I don't see anything obviously wrong, if you can post a copmpilable sample that'd help
"Keyboard not detected. Press F1 to continue"
-- Windows

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Mon May 17, 2010 4:58 pm

Is there any event handler associated to these textctrls?

Oromis_32
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon May 17, 2010 4:14 pm
Contact:

Post by Oromis_32 » Mon May 17, 2010 6:34 pm

OK, here's the whole constructor:

Code: Select all

CCfgDialog::CCfgDialog(wxWindow* pParent, string sName, bool bModal, string sCfgFile) :
wxDialog(pParent, _T(sName.c_str()), bModal, wxDefaultCoord, wxDefaultCoord, DLG_WIDTH, DLG_HEIGHT) {

	m_pOK = new wxButton(this, BTID_OK, _T("OK"), wxPoint(DLG_WIDTH - BT_WIDTH * 2 - 40, DLG_HEIGHT - BT_HEIGHT - 33), wxSize(BT_WIDTH, BT_HEIGHT));
	m_pAbort = new wxButton(this, BTID_ABORT, _T("Abbrechen"), wxPoint(DLG_WIDTH - BT_WIDTH - 20, DLG_HEIGHT - BT_HEIGHT - 33), wxSize(BT_WIDTH, BT_HEIGHT));

	m_sFilename = sCfgFile;
	wxXmlDocument xml(_T(sCfgFile.c_str()));
	if(!xml.IsOk()) 
		return;

	map<string, CItem*> itemMap;
	wxXmlNode* pNode = xml.GetRoot();
	pNode = pNode->GetChildren();
	while(pNode) {
		wxXmlNode* pInnerNode = pNode->GetChildren();
		string sName = "", sPrice = "";
		while(pInnerNode) {
			if(pInnerNode->GetName() == wxT("name")) {
				sName = pInnerNode->GetChildren()->GetContent().c_str();
			} else if(pInnerNode->GetName() == wxT("price")) {
				sPrice = pInnerNode->GetChildren()->GetContent().c_str();
			}
			pInnerNode = pInnerNode->GetNext();
		}
		float fPrice = 0.0f;
		try {
			stringstream str("");
			str << sPrice;
			str >> fPrice;
		} catch(exception e) {
			wxMessageBox(e.what());
		}
		itemMap[pNode->GetName().c_str()] = new CItem(sName, fPrice);
		pNode = pNode->GetNext();
	}

	int aiX[12];
	int aiY[12];
	aiX[0] = aiX[4] = aiX[8] = 10;
	aiX[1] = aiX[5] = aiX[9] = 200;
	aiX[2] = aiX[6] = aiX[10] = 390;
	aiX[3] = aiX[7] = aiX[11] = 580;

	aiY[0] = aiY[1] = aiY[2] = aiY[3] = 10;
	aiY[4] = aiY[5] = aiY[6] = aiY[7] = 130;
	aiY[8] = aiY[9] = aiY[10] = aiY[11] = 250;

	map<string, CItem*>::iterator it = itemMap.begin();
	for(int i = 0; i < 12; i++) {
		stringstream str("");
		str << "F" << (i+1);
		m_apHeadlines[i]   = new wxStaticText(this, -1, _T(str.str().c_str()), wxPoint(aiX[i], aiY[i]));
		m_apNameLabels[i]  = new wxStaticText(this, -1, _T("Name"), wxPoint(aiX[i], aiY[i] + BT_HEIGHT + 5));
		m_apPriceLabels[i] = new wxStaticText(this, -1, _T("Preis"), wxPoint(aiX[i], aiY[i] + 2 * (BT_HEIGHT + 5)));

		string sDefName = "", sDefPrice = "";
		float fDefPrice = 0.0f;
		if(it != itemMap.end()) {
			sDefName = (*it).second->GetName();
			fDefPrice = (*it).second->GetPrice();
			str.str("");
			str << fDefPrice;
			sDefPrice = str.str();
		}
		m_apNameInputs[i]  = new wxTextCtrl(this, wxID_ANY, _T(sDefName.c_str()), wxPoint(aiX[i] + 45, aiY[i] + BT_HEIGHT + 5), wxDefaultSize, 0);
		m_apPriceInputs[i] = new wxTextCtrl(this, wxID_ANY, sDefPrice, wxPoint(aiX[i] + 45, aiY[i] + 2 * (BT_HEIGHT + 5)), wxDefaultSize, 0);

		if(it != itemMap.end()) it++;
	}

	for(it = itemMap.begin(); it != itemMap.end(); it++) {
		if((*it).second) 
			delete (*it).second;
	}
	itemMap.clear();
}
@TrV: No, there's no EventHandler. Should there be one?

catalin
Moderator
Moderator
Posts: 1575
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin » Mon May 17, 2010 7:57 pm

How did you try to find what's wrong?
May I suggest http://www.catb.org/~esr/faqs/smart-que ... tml#volume ? IOW, in that constructor, what happens if you comment everything but one text ctrl? Is it still read-only? If yes, then the posted snippet is not very helpful.

I'd say that it could be from having some controls overlapped (you have 2x12=24 text ctrls...), or having somewhere else an OnPaint event handler where you do not instantiate a wxPaintDC, or something else...

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Mon May 17, 2010 9:33 pm

Oromis_32 wrote:@TrV: No, there's no EventHandler. Should there be one?
Not necessarily. I asked to be sure there was no EVT_TEXT event which could eventually process text and prevent it from being displayed.

I suppose there is no text validator either (see 7th parameter of wxTextCtrl())?

Oromis_32
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon May 17, 2010 4:14 pm
Contact:

Post by Oromis_32 » Tue May 18, 2010 6:12 pm

@catalin: sorry about my way of posting, I'm from Germany and have enough to do to produce english texts which you can understand.

@TrV: There really is no text validator. Btw I don't know what that is...

I added an image to this post so that you can figure out what the dialog looks like.

Code: Select all

class CCfgDialog : public wxDialog {
public:
	CCfgDialog(wxWindow* pParent, string sName, bool bModal, string sCfgFile);

	void OnOK(wxCommandEvent &event);
	void OnAbort(wxCommandEvent &event);

	void SetSystemPath(string sPath);

protected:
	DECLARE_EVENT_TABLE()
private:
	enum {
		BTID_OK = 400,
		BTID_ABORT,
	};

	string m_sFilename;
	string m_sSysPath;

	wxButton*	m_pOK;
	wxButton*	m_pAbort;

	wxStaticText* m_apHeadlines[12];
	wxStaticText* m_apNameLabels[12];
	wxStaticText* m_apPriceLabels[12];

	wxTextCtrl*	m_apNameInputs[12];
	wxTextCtrl* m_apPriceInputs[12];
};	
That's the class code. I don't know what else to post, cause everything is just too normal to go wrong :-(

Ah, here's the EventTable:

Code: Select all

BEGIN_EVENT_TABLE(CCfgDialog, wxDialog)
	EVT_BUTTON(BTID_OK, CCfgDialog::OnOK)
	EVT_BUTTON(BTID_ABORT, CCfgDialog::OnAbort)
END_EVENT_TABLE()
thanks in advance!
Attachments
Auswahlscreen.jpg

catalin
Moderator
Moderator
Posts: 1575
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin » Tue May 18, 2010 7:42 pm

Oromis_32 wrote:@catalin: sorry about my way of posting, I'm from Germany and have enough to do to produce english texts which you can understand.
no-no, there's nothing wrong with your English.
My questions refer to the code you posted, and your last post does not answer them I'm afraid...

dlchnr
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Tue Jan 27, 2009 6:45 pm
Location: Germany
Contact:

Post by dlchnr » Fri May 21, 2010 10:15 am

Hallo Oromis_32,

ich schreib Dir, weil's wesentlich schneller geht, gleich auf Deutsch :-)

Ich hatte in einem von wxDialog abgeleiteten Dialog ein Problem mit einem nervigen "Piep" in Verbindung mit einem wxSpinCtrl, welches sich nur dadurch lösen lies,
meine ganzen Controls in ein wxPanel zu packen (vorletzter Eintrag):
http://forums.wxwidgets.org/viewtopic.p ... highlight=

Ich hab' den Eindruck, dass im wxPanel ein paar Dinge besser gelöst sind, als im wxDialog (der sich ja zusätzlich mit dem Ok- und Cancel-Button rumschlagen muss,
welche den Focus haben können ...) - vielleicht ist es einen Versuch wert, ob sich damit auch Dein Problem lösen lässt.

dlchnr
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Tue Jan 27, 2009 6:45 pm
Location: Germany
Contact:

Post by dlchnr » Fri May 21, 2010 10:28 am

Ach ja, noch ein kleiner Tip - wenn Du ein JPG stärker komprimierst (z.B. mit IrfanView, "Qualität" einfach auf ca. 25 stellen), so dass es nur noch ca. 25kByte gross ist, wird es sowohl im Firefox wie auch im IE wesentlich grösser dargestellt, weiß der Geier, warum:

http://forums.wxwidgets.org/viewtopic.p ... highlight=

dlchnr
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Tue Jan 27, 2009 6:45 pm
Location: Germany
Contact:

Post by dlchnr » Fri May 21, 2010 11:05 am

Vor einem Versuch mit dem wxPanel wäre es sicherlich sinnvoll, erst mal catalins Vorschlag zu folgen und zu schauen, was passiert, wenn die XML/map-Teile auskommentiert werden - also:

Code: Select all

CCfgDialog::CCfgDialog(wxWindow* pParent, string sName, bool bModal, string sCfgFile) :
wxDialog(pParent, _T(sName.c_str()), bModal, wxDefaultCoord, wxDefaultCoord, DLG_WIDTH, DLG_HEIGHT) {

        m_pOK = new wxButton(this, BTID_OK, _T("OK"), wxPoint(DLG_WIDTH - BT_WIDTH * 2 - 40, DLG_HEIGHT - BT_HEIGHT - 33), wxSize(BT_WIDTH, BT_HEIGHT));
        m_pAbort = new wxButton(this, BTID_ABORT, _T("Abbrechen"), wxPoint(DLG_WIDTH - BT_WIDTH - 20, DLG_HEIGHT - BT_HEIGHT - 33), wxSize(BT_WIDTH, BT_HEIGHT));

        /*m_sFilename = sCfgFile;
        wxXmlDocument xml(_T(sCfgFile.c_str()));
        if(!xml.IsOk())
                return;

        map<string, CItem*> itemMap;
        wxXmlNode* pNode = xml.GetRoot();
        pNode = pNode->GetChildren();
        while(pNode) {
                wxXmlNode* pInnerNode = pNode->GetChildren();
                string sName = "", sPrice = "";
                while(pInnerNode) {
                        if(pInnerNode->GetName() == wxT("name")) {
                                sName = pInnerNode->GetChildren()->GetContent().c_str();
                        } else if(pInnerNode->GetName() == wxT("price")) {
                                sPrice = pInnerNode->GetChildren()->GetContent().c_str();
                        }
                        pInnerNode = pInnerNode->GetNext();
                }
                float fPrice = 0.0f;
                try {
                        stringstream str("");
                        str << sPrice;
                        str >> fPrice;
                } catch(exception e) {
                        wxMessageBox(e.what());
                }
                itemMap[pNode->GetName().c_str()] = new CItem(sName, fPrice);
                pNode = pNode->GetNext();
        }*/

        int aiX[12];
        int aiY[12];
        aiX[0] = aiX[4] = aiX[8] = 10;
        aiX[1] = aiX[5] = aiX[9] = 200;
        aiX[2] = aiX[6] = aiX[10] = 390;
        aiX[3] = aiX[7] = aiX[11] = 580;

        aiY[0] = aiY[1] = aiY[2] = aiY[3] = 10;
        aiY[4] = aiY[5] = aiY[6] = aiY[7] = 130;
        aiY[8] = aiY[9] = aiY[10] = aiY[11] = 250;

        //map<string, CItem*>::iterator it = itemMap.begin();
        for(int i = 0; i < 1; i++) {
                stringstream str("");
                str << "F" << (i+1);
                m_apHeadlines[i]   = new wxStaticText(this, -1, _T(str.str().c_str()), wxPoint(aiX[i], aiY[i]));
                m_apNameLabels[i]  = new wxStaticText(this, -1, _T("Name"), wxPoint(aiX[i], aiY[i] + BT_HEIGHT + 5));
                m_apPriceLabels[i] = new wxStaticText(this, -1, _T("Preis"), wxPoint(aiX[i], aiY[i] + 2 * (BT_HEIGHT + 5)));

                /*string sDefName = "", sDefPrice = "";
                float fDefPrice = 0.0f;
                if(it != itemMap.end()) {
                        sDefName = (*it).second->GetName();
                        fDefPrice = (*it).second->GetPrice();
                        str.str("");
                        str << fDefPrice;
                        sDefPrice = str.str();
                }*/
                m_apNameInputs[i]  = new wxTextCtrl(this, wxID_ANY, _T("Sorte"), wxPoint(aiX[i] + 45, aiY[i] + BT_HEIGHT + 5), wxDefaultSize, 0);
                m_apPriceInputs[i] = new wxTextCtrl(this, wxID_ANY, _T("1.0"), wxPoint(aiX[i] + 45, aiY[i] + 2 * (BT_HEIGHT + 5)), wxDefaultSize, 0);

                //if(it != itemMap.end()) it++;
        }

        /*for(it = itemMap.begin(); it != itemMap.end(); it++) {
                if((*it).second)
                        delete (*it).second;
        }
        itemMap.clear();*/
}
Wie zeigst Du den Dialog an - mit ShowModal()?

dlchnr
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Tue Jan 27, 2009 6:45 pm
Location: Germany
Contact:

Post by dlchnr » Fri May 21, 2010 11:27 am

Jetzt fällt mir bei der Initializer-List noch was auf, wo ich keine sinnvolle Zuordnung finden kann (versteh' gar nicht, das der Compiler damit klar kommt?):

Code: Select all

 : wxDialog(pParent, _T(sName.c_str()), bModal, wxDefaultCoord, wxDefaultCoord, DLG_WIDTH, DLG_HEIGHT)

wxDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = "dialogBox")
Oder gibt es weitere, nicht dokumentierte Konstruktoren?

dlchnr
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Tue Jan 27, 2009 6:45 pm
Location: Germany
Contact:

Post by dlchnr » Fri May 21, 2010 11:54 am

Hab's gefunden - scheint doch in Ordnung zu sein!

Code: Select all

#if WXWIN_COMPATIBILITY_2_6
    // use the other ctor
    wxDEPRECATED( wxDialog(wxWindow *parent,
             const wxString& title, bool modal,
             int x = wxDefaultCoord, int y = wxDefaultCoord, int width = 500, int height = 500,
             long style = wxDEFAULT_DIALOG_STYLE,
             const wxString& name = wxDialogNameStr) );

    // just call Show() or ShowModal()
    wxDEPRECATED( void SetModal(bool flag) );

    // use IsModal()
    wxDEPRECATED( bool IsModalShowing() const );
#endif // WXWIN_COMPATIBILITY_2_6

Oromis_32
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon May 17, 2010 4:14 pm
Contact:

Post by Oromis_32 » Sun May 23, 2010 9:50 am

OK, danke schonmal für die Vorschläge!

Um auch anderen die Chance zu geben, mir zu helfen, wechsle ich wieder auf englisch:

Its no use to comment out everything connected with the xml-Files. Inserting an wxPanel Didn't solute the problem either.

And yes, the dialog is shown by ShowModal().

Has anyone any further ideas?

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sun May 23, 2010 3:47 pm

Oromis_32 wrote:OK, danke schonmal für die Vorschläge!

Um auch anderen die Chance zu geben, mir zu helfen, wechsle ich wieder auf englisch:

Its no use to comment out everything connected with the xml-Files. Inserting an wxPanel Didn't solute the problem either.

And yes, the dialog is shown by ShowModal().

Has anyone any further ideas?
Well I don't speak German, so I have no idea what has been said.
I still hold that posting a minimal compilable sample demonstrating the problem is the best way to help us help you
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply