#include using namespace std; #include #include #include #include #include #include #include class MainFrame : public TGMainFrame { private: TGComboBox* m_Options; TGGroupFrame* m_OptionsFrame; TGCompositeFrame* m_OptionsSubFrame; public: MainFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~MainFrame(); void Create(); void UpdateOptions(); bool ProcessMessage(long Message, long Parameter1, long Parameter2); ClassDef(MainFrame, 0) }; MainFrame::MainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h) { // Create main frame m_OptionsSubFrame = 0; Create(); } MainFrame::~MainFrame() { // Clean up main frame... Cleanup(); } void MainFrame::Create() { TGLayoutHints* LayoutL1 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterX, 20, 20, 10, 10); TGCompositeFrame* BeamTypeFrame = new TGCompositeFrame(this, 100, 100, kHorizontalFrame); AddFrame(BeamTypeFrame, LayoutL1); TGLabel* BeamTypeLabel = new TGLabel(BeamTypeFrame, "Options:"); BeamTypeFrame->AddFrame(BeamTypeLabel, LayoutL1); m_Options = new TGComboBox(BeamTypeFrame); for (int b = 0; b <= 10; ++b) { TString E("Entries: "); E += b; m_Options->AddEntry(E, b); } m_Options->Associate(this); m_Options->Resize(100, 20); m_Options->Select(10); BeamTypeFrame->AddFrame(m_Options, LayoutL1); m_OptionsFrame = new TGGroupFrame(this, "Options frame"); AddFrame(m_OptionsFrame, LayoutL1); UpdateOptions(); MapSubwindows(); MapWindow(); Layout(); } void MainFrame::UpdateOptions() { TGLayoutHints* Default = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX, 0, 0, 0, 0); if (m_OptionsSubFrame != 0) { m_OptionsSubFrame->UnmapWindow(); m_OptionsFrame->RemoveAll(); delete m_OptionsSubFrame; } m_OptionsSubFrame = new TGCompositeFrame(m_OptionsFrame); for (int i = 0; i < m_Options->GetSelected(); ++i) { TString Text("Added "); Text += i+1; Text += "/"; Text += m_Options->GetSelected(); TGLabel* Label = new TGLabel(m_OptionsSubFrame, Text); m_OptionsSubFrame->AddFrame(Label); } m_OptionsFrame->AddFrame(m_OptionsSubFrame, Default); // Give this element the default size of its content: Resize(GetDefaultWidth(), GetDefaultHeight()); MapSubwindows(); MapWindow(); Layout(); } bool MainFrame::ProcessMessage(long Message, long Parameter1, long) { // Process the messages for this application, mainly the scollbar moves: switch (GET_MSG(Message)) { case kC_COMMAND: switch (GET_SUBMSG(Message)) { case kCM_CHECKBUTTON: break; case kCM_COMBOBOX: UpdateOptions(); break; case kCM_BUTTON: case kCM_MENU: switch (Parameter1) { default: break; } break; default: break; } break; default: break; } return true; } void Problem() { new MainFrame(gClient->GetRoot(), 300, 200); }