#include <fxkeys.h>
#include <netedit/GNEApplicationWindow.h>
#include <netedit/GNEInternalTest.h>
#include <utils/gui/div/GUIDesigns.h>
#include "GNEDialog.h"
FXDEFMAP(GNEDialog) MFXDialogBoxMap[] = {
FXMAPFUNC(SEL_KEYPRESS, 0, GNEDialog::onKeyPress),
FXMAPFUNC(SEL_KEYRELEASE, 0, GNEDialog::onKeyRelease),
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_ACCEPT, GNEDialog::onCmdAccept),
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_CANCEL, GNEDialog::onCmdCancel),
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_RESET, GNEDialog::onCmdReset),
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_RUN, GNEDialog::onCmdRun),
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_BACK, GNEDialog::onCmdBack),
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_ADVANCED, GNEDialog::onCmdAdvanced),
FXMAPFUNC(SEL_CLOSE, 0, GNEDialog::onCmdAbort),
FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_ESC, GNEDialog::onCmdAbort),
FXMAPFUNC(SEL_CHORE, MID_GNE_ABORT, GNEDialog::onCmdAbort),
FXMAPFUNC(SEL_TIMEOUT, MID_GNE_ABORT, GNEDialog::onCmdAbort),
FXMAPFUNC(SEL_COMMAND, MID_GNE_ABORT, GNEDialog::onCmdAbort),
};
FXIMPLEMENT_ABSTRACT(GNEDialog, FXDialogBox, MFXDialogBoxMap, ARRAYNUMBER(MFXDialogBoxMap))
GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType,
ResizeMode resizeMode) :
FXDialogBox(applicationWindow->getApp(), name.c_str(),
(resizeMode == ResizeMode::STATIC) ? GUIDesignGNEDialogStatic : GUIDesignGNEDialogResizable,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
myApplicationWindow(applicationWindow),
myType(type),
myOpenType(openType) {
buildDialog(titleIcon, buttons);
}
GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType,
ResizeMode resizeMode, const int width, const int height) :
FXDialogBox(applicationWindow->getApp(), name.c_str(),
(resizeMode == ResizeMode::STATIC) ? GUIDesignGNEDialogStaticExplicit : GUIDesignGNEDialogResizableExplicit,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
myApplicationWindow(applicationWindow),
myType(type),
myOpenType(openType) {
buildDialog(titleIcon, buttons);
resize(width, height);
}
GNEDialog::Result
GNEDialog::getResult() const {
return myResult;
}
GNEApplicationWindow*
GNEDialog::getApplicationWindow() const {
return myApplicationWindow;
}
FXVerticalFrame*
GNEDialog::getContentFrame() const {
return myContentFrame;
}
long
GNEDialog::onCmdAccept(FXObject*, FXSelector, void*) {
return closeDialogAccepting();
}
long
GNEDialog::onCmdCancel(FXObject*, FXSelector, void*) {
return closeDialogCanceling();
}
long
GNEDialog::onCmdAbort(FXObject*, FXSelector, void*) {
return closeDialogAborting();
}
long
GNEDialog::onCmdReset(FXObject*, FXSelector, void*) {
throw ProcessError("onCmdReset function must be reimplemented in GNEDialog children");
}
long
GNEDialog::onCmdRun(FXObject*, FXSelector, void*) {
throw ProcessError("onCmdRun function must be reimplemented in GNEDialog children");
}
long
GNEDialog::onCmdBack(FXObject*, FXSelector, void*) {
throw ProcessError("onCmdBack function must be reimplemented in GNEDialog children");
}
long
GNEDialog::onCmdAdvanced(FXObject*, FXSelector, void*) {
throw ProcessError("onCmdAdvanced function must be reimplemented in GNEDialog children");
}
long
GNEDialog::onKeyPress(FXObject* obj, FXSelector sel, void* ptr) {
if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
return 1;
} else {
FXEvent* event = (FXEvent*)ptr;
if (event->code == KEY_Escape) {
return closeDialogAborting();
} else {
return FXDialogBox::onKeyPress(obj, sel, ptr);
}
}
}
long
GNEDialog::onKeyRelease(FXObject* obj, FXSelector sel, void* ptr) {
if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
return 1;
} else {
return FXDialogBox::onKeyRelease(obj, sel, ptr);
}
}
void
GNEDialog::openDialog(FXWindow* focusableElement) {
create();
if (focusableElement) {
focusableElement->setFocus();
} else {
myFocusButton->setFocus();
}
show(PLACEMENT_OWNER);
const auto internalTest = myApplicationWindow->getInternalTest();
if (internalTest) {
myTesting = true;
bool closeDialog = false;
while (internalTest->getCurrentStep() && !closeDialog &&
(internalTest->getCurrentStep()->getCategory() == InternalTestStep::Category::DIALOG) &&
(internalTest->getCurrentStep()->getDialogArgument()->getType() == myType)) {
const auto testStep = internalTest->setNextStep();
switch (testStep->getDialogArgument()->getAction()) {
case InternalTestStep::DialogArgument::Action::ACCEPT:
onCmdAccept(internalTest, 0, nullptr);
closeDialog = true;
break;
case InternalTestStep::DialogArgument::Action::CANCEL:
onCmdCancel(internalTest, 0, nullptr);
closeDialog = true;
break;
case InternalTestStep::DialogArgument::Action::RESET:
onCmdReset(internalTest, 0, nullptr);
break;
case InternalTestStep::DialogArgument::Action::ABORT:
onCmdAbort(nullptr, 0, nullptr);
break;
default:
runInternalTest(testStep->getDialogArgument());
break;
}
}
} else {
myTesting = false;
if (myOpenType == OpenType::MODAL) {
getApp()->runModalFor(this);
}
}
}
long
GNEDialog::closeDialogAccepting() {
if (!myTesting && (myOpenType == OpenType::MODAL)) {
getApp()->stopModal(this, TRUE);
}
hide();
myResult = Result::ACCEPT;
myApplicationWindow->setFocus();
return 1;
}
long
GNEDialog::closeDialogCanceling() {
if (!myTesting && (myOpenType == OpenType::MODAL)) {
getApp()->stopModal(this, TRUE);
}
hide();
myResult = Result::CANCEL;
myApplicationWindow->setFocus();
return 0;
}
long
GNEDialog::closeDialogAborting() {
if (!myTesting && (myOpenType == OpenType::MODAL)) {
getApp()->stopModal(this, TRUE);
}
hide();
myResult = Result::ABORT;
myApplicationWindow->setFocus();
return 0;
}
void
GNEDialog::updateTitle(const std::string& newTitle) {
setTitle(newTitle.c_str());
}
void
GNEDialog::updateIcon(GUIIcon newIcon) {
setIcon(GUIIconSubSys::getIcon(newIcon));
}
void
GNEDialog::buildDialog(GUIIcon titleIcon, GNEDialog::Buttons buttons) {
setIcon(GUIIconSubSys::getIcon(titleIcon));
auto mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignDialogContentFrame);
new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignDialogButtonsHorizontalFrame);
new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
switch (buttons) {
case Buttons::OK: {
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
GUIIconSubSys::getIcon(GUIIcon::YES), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
case Buttons::YES_NO: {
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
GUIIconSubSys::getIcon(GUIIcon::YES), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
GUIIconSubSys::getIcon(GUIIcon::NO), this,
MID_GNE_BUTTON_CANCEL, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
case Buttons::YES_NO_CANCEL: {
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
GUIIconSubSys::getIcon(GUIIcon::YES), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
GUIIconSubSys::getIcon(GUIIcon::NO), this,
MID_GNE_BUTTON_CANCEL, GUIDesignButtonDialog);
myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
GUIIconSubSys::getIcon(GUIIcon::CANCEL), this,
MID_GNE_ABORT, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
case Buttons::SAVE_DONTSAVE_CANCEL: {
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Save"), "", TL("Save"),
GUIIconSubSys::getIcon(GUIIcon::SAVE), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Don't Save"), "", TL("Don't Save"),
GUIIconSubSys::getIcon(GUIIcon::NO), this,
MID_GNE_BUTTON_CANCEL, GUIDesignButtonDialog);
myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
GUIIconSubSys::getIcon(GUIIcon::CANCEL), this,
MID_GNE_ABORT, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
case Buttons::ACCEPT: {
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
GUIIconSubSys::getIcon(GUIIcon::YES), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
case Buttons::ACCEPT_CANCEL: {
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
GUIIconSubSys::getIcon(GUIIcon::YES), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
GUIIconSubSys::getIcon(GUIIcon::NO), this,
MID_GNE_BUTTON_CANCEL, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
case Buttons::ACCEPT_CANCEL_RESET: {
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
GUIIconSubSys::getIcon(GUIIcon::YES), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
GUIIconSubSys::getIcon(GUIIcon::NO), this,
MID_GNE_BUTTON_CANCEL, GUIDesignButtonDialog);
myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
GUIIconSubSys::getIcon(GUIIcon::RESET), this,
MID_GNE_BUTTON_RESET, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
case Buttons::RUN_CANCEL_RESET: {
myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
GUIIconSubSys::getIcon(GUIIcon::START), this,
MID_GNE_BUTTON_RUN, GUIDesignButtonDialog);
myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
GUIIconSubSys::getIcon(GUIIcon::NO), this,
MID_GNE_BUTTON_CANCEL, GUIDesignButtonDialog);
myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
GUIIconSubSys::getIcon(GUIIcon::RESET), this,
MID_GNE_BUTTON_RESET, GUIDesignButtonDialog);
myFocusButton = myRunButton;
break;
}
case Buttons::RUN_ADVANCED_CANCEL: {
myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
GUIIconSubSys::getIcon(GUIIcon::START), this,
MID_GNE_BUTTON_RUN, GUIDesignButtonDialog);
myAdvancedButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Advanced"), "", TL("Advanced options"),
GUIIconSubSys::getIcon(GUIIcon::OPTIONS), this,
MID_GNE_BUTTON_ADVANCED, GUIDesignButtonDialog);
myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
GUIIconSubSys::getIcon(GUIIcon::CANCEL), this,
MID_GNE_BUTTON_CANCEL, GUIDesignButtonDialog);
myFocusButton = myRunButton;
break;
}
case Buttons::RERUN_BACK_CLOSE: {
myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("Rerun tool"),
GUIIconSubSys::getIcon(GUIIcon::RESET), this,
MID_GNE_BUTTON_RUN, GUIDesignButtonDialog);
myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("Back to tool dialog"),
GUIIconSubSys::getIcon(GUIIcon::BACK), this,
MID_GNE_BUTTON_BACK, GUIDesignButtonDialog);
myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Close"), "", TL("Close"),
GUIIconSubSys::getIcon(GUIIcon::YES), this,
MID_GNE_BUTTON_ACCEPT, GUIDesignButtonDialog);
myFocusButton = myAcceptButton;
break;
}
default:
throw ProcessError("Invalid buttons combination in GNEDialog");
}
new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
}