Archicad C++ API
About Archicad add-on development using the C++ API.

[SOLVED] How to interact to TabControl(NormalTab) controls

Anonymous
Not applicable
Hi

I have a NormalTab control in my dialog.
There is a TextEdit control in NormalTab.
First I want to know to how I should declare the controls of the NormalTab and second get the TextEdit data in TestSettingsPageObserver class.

Here is my code.

resource file
'GDLG'	32511	Modal 	0	0	 444  174  "Upload IFC" {
/* [  1] */ NormalTab			  0   0  428 148
								  32512 NoIcon "New" 
								  32513 NoIcon "Existing"
/* [  2] */  Button				260  106	  75   23  LargePlain		"Cancel"
/* [  3] */  Button				341  106	  75   23  LargePlain		"Upload" 
}

'DLGH'  32511  DLG_32511_Upload_IFC {
1	""							uploadTabControl
2	""							btnUpload
3	""							btnCancel
}

'GDLG'  32512    TabPage  0    0 428  100  "" {
/* [  4] */  LeftText           13   23   84   13  LargePlain		"Model file name:"
/* [  5] */  TextEdit			104  18   293  20  LargePlain		256
/* [  6] */  Separator		    13   53   385  1
}
'DLGH'  32512  TabPage_32512 {
4	""							lblModelName_New
5	""							txtModelName
6	""							seperator_2
}

'GDLG'  32513    TabPage  0    0 428  100  "" {
/* [  7] */  LeftText           13   23   84   13  LargePlain		"Model file name:"
/* [  8] */  PopupControl		104  18   293  20  144 0
/* [  9] */  Separator		    13   53   385  1

}
'DLGH'  32513  TabPage_32512 {
	7	""							lblModelName_Existing
	8	""							comboModelName
	9	""							seperator_2
}
ExportDialog.h


#define IID_EXPORT						32511
#define IDT_NORMALTAB					1
#define IDB_BTN_CANCEL   				2
#define IDB_BTN_UPLOAD				        3

#define IDT_MODELNAME					5
#define IDC_EXISTING_MODEL				8

class ExportDialog : public DG::ModalDialog
{

	friend class TabControlObserver; 

private:
	DG::NormalTab   m_TabControl;
	DG::TextEdit	m_txtModelName;
	DG::Button		m_btnCancel;
	DG::Button		m_btnSave;
	DG::PopUp		m_comboModelName;

	TabControlObserver *tabControl;
	 
public:
	ExportDialog();
	~ExportDialog();
private:
	
protected:

private:
	ExportDialog(const ExportDialog&);
	const	ExportDialog& operator=(const ExportDialog&); //Disabled


};

// ----------------------------------------------- TabControlObserver ----------------------------------------------- 


class TabControlObserver :  public DG::PanelObserver, 
               public DG::NormalTabObserver, 
               public DG::ButtonItemObserver, 
               public DG::CompoundItemObserver 
{ 
private: 
   ExportDialog*      mDialog; 
   

protected: 
   // DG::PanelObserver 
   virtual void   PanelOpened (const DG::PanelOpenEvent& ev) override; 

   // DG::ButtonItemObserver 
   virtual void   ButtonClicked (const DG::ButtonClickEvent& ev) override; 

public: 
   explicit      TabControlObserver (ExportDialog* mainDialog); 
   ~TabControlObserver (); 
}; 
ExportDialog.cpp
ExportDialog::ExportDialog() : 
ModalDialog (ACAPI_GetOwnResModule (), IID_EXPORT, InvalidResModule),
m_TabControl(GetReference (), IDT_NORMALTAB),
m_txtModelName(GetReference (), IDT_MODELNAME),
m_btnCancel(GetReference (), IDB_BTN_CANCEL),
m_btnSave(GetReference (), IDB_BTN_UPLOAD),
m_comboModelName(GetReference (), IDC_EXISTING_MODEL)
{
	tabControl = new TabControlObserver(this);
	m_TabControl.Attach(*tabControl); 
}

ExportDialog::~ExportDialog()
{
	//delete tabControl;
}
 
//-------------------------- Class TabControlObserver ----------------------- 

TabControlObserver::TabControlObserver (ExportDialog* mainDialog): 
   mDialog (mainDialog)
{ 
   mDialog->Attach (*this); 
   AttachToAllItems (*mDialog); 
} 


TabControlObserver::~TabControlObserver () 
{ 
   mDialog->Detach (*this); 
   DetachFromAllItems (*mDialog); 
} 


void TabControlObserver::PanelOpened (const DG::PanelOpenEvent& /*ev*/) 
{ 
   mDialog->SetClientSize (mDialog->GetOriginalClientWidth (), mDialog->GetOriginalClientHeight ()); 
   mDialog->m_TabControl.SetClientSize(mDialog->GetOriginalClientWidth (),(mDialog->GetOriginalClientHeight () / 2) - mDialog->m_btnCancel.GetHeight());
} 


void TabControlObserver::ButtonClicked (const DG::ButtonClickEvent& ev) 
{ 
   // Close dialog with acceptance 
	if (ev.GetSource () == &mDialog->m_btnCancel) { 

      mDialog->PostCloseRequest (DG::ModalDialog::Accept); 
	  

    }  
	else if ( ev.GetSource() == &mDialog->m_btnSave ) 
	{
		//here I need to get mDialog->m_txtModelName text
		GS::UniString temp =  mDialog->m_txtModelName.GetText(); // this value always comes empty
	}
} 
My goal is to get mDialog->m_txtModelName information in ButtonClicked function.
3 REPLIES 3
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

In GRC resource file the ID of the items are sequence numbers in a resource scope.
So please modify your GRC resource file like this:
'GDLG'	32511	Modal 	0	0	 444  174  "Upload IFC" { 
/* [  1] */ NormalTab			  0   0  428 148 
								  32512 NoIcon "New"  
								  32513 NoIcon "Existing" 
/* [  2] */  Button				260  106	  75   23  LargePlain		"Cancel" 
/* [  3] */  Button				341  106	  75   23  LargePlain		"Upload"  
} 
 
'DLGH'  32511  DLG_32511_Upload_IFC { 
1	""							uploadTabControl 
2	""							btnUpload 
3	""							btnCancel 
} 
 
'GDLG'  32512    TabPage  0    0 428  100  "" { 
/* [  1] */  LeftText           13   23   84   13  LargePlain		"Model file name:" 
/* [  2] */  TextEdit			104  18   293  20  LargePlain		256 
/* [  3] */  Separator		    13   53   385  1 
} 
'DLGH'  32512  TabPage_32512 { 
1	""							lblModelName_New 
2	""							txtModelName 
3	""							seperator_2 
} 
 
'GDLG'  32513    TabPage  0    0 428  100  "" { 
/* [  1] */  LeftText           13   23   84   13  LargePlain		"Model file name:" 
/* [  2] */  PopupControl		104  18   293  20  144 0 
/* [  3] */  Separator		    13   53   385  1 
 
} 
'DLGH'  32513  TabPage_32513 { 
	1	""							lblModelName_Existing 
	2	""							comboModelName 
	3	""							seperator_2 
}


And don't forget to change the IDs in ExportDialog.h header file also!

Regards,
Tibor
Anonymous
Not applicable
Thank you for the response, but your answer is not helpful because I changed but it again doesn't work and also is it correct to have two control with the same ID in a class ?
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
ggiloyan wrote:
is it correct to have two control with the same ID in a class?


No, each item must have unique ID in a class.

BUT you must define a new class for each 'GDLG' resource!
So if you have 1 Modal dialog and 2 TabPage in your GRC file, then you should have 3 classes.

The example code from Tamás Zolnai in the other topic (How to create a TabControl) is imperfect.
I will fix that code, please be patient!