#include "TRootDialog.h"
#include "TRootContextMenu.h"
#include "TContextMenu.h"
#include "TClassMenuItem.h"
#include "TList.h"
#include "TGLabel.h"
#include "TGTextEntry.h"
#include "TGButton.h"
#include "TObjString.h"
extern TGTextEntry *gBlinkingEntry;
ClassImp(TRootDialog)
TRootDialog::TRootDialog(TRootContextMenu *cmenu, const TGWindow *main,
const char *title, Bool_t okB, Bool_t cancelB, Bool_t applyB) :
TGTransientFrame(gClient->GetRoot(), main, 200, 100)
{
fMenu = cmenu;
fOk = okB;
fCancel = cancelB;
fApply = applyB;
fWidgets = new TList;
fL1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 0, 0, 5, 0);
fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
SetWindowName(title);
SetIconName(title);
SetEditDisabled(kEditDisable);
}
TRootDialog::~TRootDialog()
{
fWidgets->Delete();
delete fWidgets;
delete fL1;
delete fL2;
}
void TRootDialog::Add(const char *argname, const char *value, const char *type)
{
TGLabel *l = new TGLabel(this, argname);
TGTextBuffer *b = new TGTextBuffer(20); b->AddText(0, value);
TGTextEntry *t = new TGTextEntry(this, b);
t->Connect("TabPressed()", "TRootDialog", this, "TabPressed()");
t->Associate(fMenu);
t->Resize(260, t->GetDefaultHeight());
AddFrame(l, fL1);
AddFrame(t, fL2);
fWidgets->Add(l);
fWidgets->Add(t);
fWidgets->Add(new TObjString(type));
}
const char *TRootDialog::GetParameters()
{
static char params[1024];
char param[256];
TObjString *str;
TObject *obj;
Int_t selfobjpos;
if (fMenu->GetContextMenu()->GetSelectedMenuItem())
selfobjpos = fMenu->GetContextMenu()->GetSelectedMenuItem()->GetSelfObjectPos();
else
selfobjpos = -1;
params[0] = 0;
TIter next(fWidgets);
Int_t nparam = 0;
while ((obj = next())) {
if (obj->IsA() != TGLabel::Class()) break;
obj = next();
str = (TObjString *) next();
nparam++;
const char *type = str->GetString().Data();
const char *data = 0;
if (obj->IsA() == TGTextEntry::Class())
data = ((TGTextEntry *) obj)->GetBuffer()->GetString();
if (selfobjpos == nparam-1) {
if (params[0]) strcat(params, ",");
sprintf(param,"(TObject*)0x%lx",
(Long_t)fMenu->GetContextMenu()->GetSelectedObject());
strcat(params,param);
}
if (params[0]) strcat(params, ",");
if (data) {
if (!strncmp(type, "char*", 5))
sprintf(param, "\"%s\"", data);
else
strcpy(param, data);
} else
strcpy(param, "0");
strcat(params, param);
}
if (selfobjpos == nparam) {
if (params[0]) strcat(params, ",");
sprintf(param,"(TObject*)0x%lx",
(Long_t)fMenu->GetContextMenu()->GetSelectedObject());
strcat(params, param);
}
return params;
}
void TRootDialog::Popup()
{
UInt_t nb = 0, width = 0, height = 0;
TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
TGLayoutHints *l1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
fWidgets->Add(l1);
TGTextButton *b;
if (fOk) {
b = new TGTextButton(hf, "&OK", 1);
fWidgets->Add(b);
b->Associate(fMenu);
hf->AddFrame(b, l1);
height = b->GetDefaultHeight();
width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
}
if (fApply) {
b = new TGTextButton(hf, "&Apply", 2);
fWidgets->Add(b);
b->Associate(fMenu);
hf->AddFrame(b, l1);
height = b->GetDefaultHeight();
width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
}
if (fCancel) {
b = new TGTextButton(hf, "&Cancel", 3);
fWidgets->Add(b);
b->Associate(fMenu);
hf->AddFrame(b, l1);
height = b->GetDefaultHeight();
width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
}
l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
fWidgets->Add(l1);
fWidgets->Add(hf);
AddFrame(hf, l1);
hf->Resize((width + 20) * nb, height);
MapSubwindows();
width = GetDefaultWidth();
height = GetDefaultHeight();
Resize(width, height);
CenterOnParent();
SetWMSize(width, height);
SetWMSizeHints(width, height, width, height, 0, 0);
SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
kMWMDecorMinimize | kMWMDecorMenu,
kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
kMWMFuncMinimize,
kMWMInputModeless);
MapWindow();
fClient->WaitFor(this);
}
void TRootDialog::CloseWindow()
{
SendMessage(fMenu, MK_MSG(kC_COMMAND, kCM_BUTTON), 3, 0);
}
void TRootDialog::TabPressed()
{
Bool_t setNext = kFALSE;
TIter next(fWidgets);
while ( TObject* obj = next() ) {
if ( obj->IsA() == TGTextEntry::Class() ) {
TGTextEntry *entry = (TGTextEntry*) obj;
if ( entry == gBlinkingEntry ) {
setNext = kTRUE;
} else if ( setNext ) {
entry->SetFocus();
entry->End();
return;
}
}
}
next.Reset();
while ( TObject* obj = next() ) {
if ( obj->IsA() == TGTextEntry::Class() ) {
TGTextEntry *entry = (TGTextEntry*) obj;
entry->SetFocus();
entry->End();
return;
}
}
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.