From f1d40eef93220d502fca94667a64188f7f9fe094 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Thu, 19 Sep 2002 09:47:18 -0400 Subject: Initial import of wxWindows dialog --- Source/WXDialog/CMakeLists.txt | 33 + Source/WXDialog/cmWXCacheProperty.cxx | 358 ++++++++ Source/WXDialog/cmWXCacheProperty.h | 130 +++ Source/WXDialog/cmWXCommandLineInfo.cxx | 133 +++ Source/WXDialog/cmWXCommandLineInfo.h | 65 ++ Source/WXDialog/cmWXMainFrame.cxx | 1384 +++++++++++++++++++++++++++++++ Source/WXDialog/cmWXMainFrame.h | 229 +++++ Source/WXDialog/wxCMakeSetup.cxx | 174 ++++ Source/WXDialog/wxincludes.h | 52 ++ 9 files changed, 2558 insertions(+) create mode 100644 Source/WXDialog/CMakeLists.txt create mode 100644 Source/WXDialog/cmWXCacheProperty.cxx create mode 100644 Source/WXDialog/cmWXCacheProperty.h create mode 100644 Source/WXDialog/cmWXCommandLineInfo.cxx create mode 100644 Source/WXDialog/cmWXCommandLineInfo.h create mode 100644 Source/WXDialog/cmWXMainFrame.cxx create mode 100644 Source/WXDialog/cmWXMainFrame.h create mode 100644 Source/WXDialog/wxCMakeSetup.cxx create mode 100644 Source/WXDialog/wxincludes.h diff --git a/Source/WXDialog/CMakeLists.txt b/Source/WXDialog/CMakeLists.txt new file mode 100644 index 0000000..779411c --- /dev/null +++ b/Source/WXDialog/CMakeLists.txt @@ -0,0 +1,33 @@ +INCLUDE (${CMAKE_ROOT}/Modules/FindwxWindows.cmake) + +IF ( CMAKE_WX_CAN_COMPILE ) + + SET( WX_SRCS + cmWXCacheProperty.cxx + cmWXCommandLineInfo.cxx + cmWXMainFrame.cxx + wxCMakeSetup.cxx + ) + + IF(WXWINDOWS_INCLUDE_PATH) + INCLUDE_DIRECTORIES(${WXWINDOWS_INCLUDE_PATH}) + ENDIF(WXWINDOWS_INCLUDE_PATH) + + IF(CMAKE_WX_CXX_FLAGS) + SET(CMAKE_CXX_FLAGS "${CMAKE_WX_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") + ENDIF(CMAKE_WX_CXX_FLAGS) + + INCLUDE_DIRECTORIES(${CMake_SOURCE_DIR}/Source) + + ADD_EXECUTABLE(wxCMakeSetup ${WX_SRCS}) + TARGET_LINK_LIBRARIES(wxCMakeSetup ${WXWINDOWS_LIBRARY}) + TARGET_LINK_LIBRARIES(wxCMakeSetup CMakeLib) + + INSTALL_TARGETS(/bin wxCMakeSetup) + +ELSE ( CMAKE_WX_CAN_COMPILE ) + + MESSAGE("Cannot find wxWindows libraries and/or header files") + MESSAGE("OLib: ${WXWINDOWS_LIBRARY} Inc: ${WXWINDOWS_INCLUDE_PATH} Flags: ${CMAKE_WX_CXX_FLAGS}") + +ENDIF ( CMAKE_WX_CAN_COMPILE ) diff --git a/Source/WXDialog/cmWXCacheProperty.cxx b/Source/WXDialog/cmWXCacheProperty.cxx new file mode 100644 index 0000000..c85a94e --- /dev/null +++ b/Source/WXDialog/cmWXCacheProperty.cxx @@ -0,0 +1,358 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +// cmCacheProperty.cxx : implementation file +// + +#include "cmWXCacheProperty.h" + +#include "cmSystemTools.h" +#include "cmWXMainFrame.h" + +static int GetClientHeight(wxWindow* w) +{ + wxSize size = w->GetSize(); + return size.GetHeight(); +} + +#define cmMAX(x, y) (((x)>(y))?(x):(y)) + +cmCacheProperty::cmCacheProperty(cmMainFrame* mf, const std::string& name) : m_Name(name) +{ + this->m_HelpString = ""; + this->m_Value = ""; + this->m_NewValue = true; + this->m_Removed = false; + this->m_ItemType = cmCacheProperty::NOTHING; + this->m_MainFrame = mf; + this->m_Advanced = false; + + this->m_KeyWindow = 0; + this->m_ValueWindow = 0; + + this->m_TextControl = 0; +} + +cmCacheProperty::~cmCacheProperty() +{ +} + +int cmCacheProperty::Display(wxSizer* s, wxPanel* win) +{ + int maxheight = 0; + this->m_TextControl = 0; + wxPanel* panel = new wxPanel(win, -1); + wxPanel* panel1 = new wxPanel(panel, -1); + wxBoxSizer* sizer = 0; + wxColor bgcolor = panel->GetBackgroundColour(); + sizer = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer* sizer1 = new wxBoxSizer(wxHORIZONTAL); + wxStaticText* name = new wxStaticText(panel1, -1, this->m_Name.c_str()); + this->SetupMenu(name); + this->SetupMenu(panel1); + sizer1->Add(name, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + maxheight = cmMAX(maxheight, ::GetClientHeight(panel1)); + sizer->Add(5, 5, 0); + sizer->Add(panel1, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + + panel1->SetAutoLayout( TRUE ); + panel1->SetSizer(sizer1); + sizer1->Fit(panel1); + sizer1->SetSizeHints(panel1); + sizer1->Layout(); + + panel->SetAutoLayout( TRUE ); + panel->SetSizer(sizer); + sizer->Fit(panel); + sizer->SetSizeHints(panel); + sizer->Layout(); + wxControl* value = 0; + if ( this->m_NewValue ) + { + wxColor brightred = wxColor(252, 102, 100); + panel->SetBackgroundColour(brightred); + panel1->SetBackgroundColour(brightred); + name->SetBackgroundColour(brightred); + } + else + { + panel->SetBackgroundColour(*wxWHITE); + panel1->SetBackgroundColour(*wxWHITE); + name->SetBackgroundColour(*wxWHITE); + } + + this->m_KeyWindow = panel; + + panel = new wxPanel(win, -1); + sizer = new wxBoxSizer(wxHORIZONTAL); + panel->SetBackgroundColour(*wxWHITE); + //panel->SetBackgroundColour(*wxGREEN) + +#ifdef __APPLE__ + wxColor buttoncolor = *wxWHITE; +#else // __APPLE__ + wxColor buttoncolor = bgcolor; +#endif // __APPLE__ + + switch ( this->m_ItemType ) + { + case cmCacheProperty::CHECKBOX: + sizer->Add(5, 5, 0); + value = new wxCheckBox(panel, -1, ""); + this->ConnectEvent(value, wxEVT_COMMAND_CHECKBOX_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnPropertyChanged); + this->SetupMenu(value); + if ( strcmp(this->GetValue().c_str(), "ON") == 0 ) + { + static_cast(value)->SetValue(true); + } + break; + case cmCacheProperty::EDIT: + value = new wxTextCtrl(panel, -1, this->m_Value.c_str()); + maxheight = cmMAX(maxheight, ::GetClientHeight(value)); + this->ConnectEvent(value, wxEVT_COMMAND_TEXT_UPDATED, + (wxObjectEventFunction) &cmMainFrame::OnPropertyChanged); + this->SetupMenu(value); + break; + case cmCacheProperty::FILE: + sizer->Add(5, 5, 0); + value = new wxStaticText(panel, -1, this->m_Value.c_str()); + maxheight = cmMAX(maxheight, ::GetClientHeight(value)); + sizer->Add(value, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL ); + this->m_TextControl = value; + this->SetupMenu(value); + value = new wxButton(panel, -1, "...", wxDefaultPosition, + wxSize(20, maxheight - 4)); + maxheight = cmMAX(maxheight, ::GetClientHeight(value)); + value->SetBackgroundColour(buttoncolor); + sizer->Add(value, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL ); + this->ConnectEvent(value, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnPropertyChanged); + this->SetupMenu(value); + value = 0; + break; + case cmCacheProperty::PATH: + sizer->Add(5, 5, 0); + value = new wxStaticText(panel, -1, this->m_Value.c_str()); + maxheight = cmMAX(maxheight, ::GetClientHeight(value)); + sizer->Add(value, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL ); + this->m_TextControl = value; + this->SetupMenu(value); + value = new wxButton(panel, -1, "...", wxDefaultPosition, + wxSize(20, maxheight - 4)); + maxheight = cmMAX(maxheight, ::GetClientHeight(value)); + value->SetBackgroundColour(buttoncolor); + sizer->Add(value, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL ); + this->ConnectEvent(value, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnPropertyChanged); + this->SetupMenu(value); + value = 0; + break; + default: + value = new wxStaticText(panel, -1, this->m_Value.c_str()); + maxheight = cmMAX(maxheight, ::GetClientHeight(value)); + this->m_TextControl = value; + break; + } + //panel->Fit(); + this->m_ValueWindow = panel; + //panel->Fit(); + //win->Fit(); + if ( value ) + { + sizer->Add(value, 1, wxALIGN_LEFT | wxGROW | wxALL | wxALIGN_CENTER_VERTICAL); + } + + //s->Layout(); + + panel->SetAutoLayout( TRUE ); + panel->SetSizer(sizer); + sizer->Fit(panel); + sizer->SetSizeHints(panel); + sizer->Layout(); + + + if ( this->m_NewValue ) + { + s->Prepend(this->m_ValueWindow, 1, wxGROW | wxLEFT | wxRIGHT ); + s->Prepend(this->m_KeyWindow, 1, wxGROW | wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL ); + } + else + { + s->Add(this->m_KeyWindow, 1, wxGROW | wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL ); + s->Add(this->m_ValueWindow, 1, wxGROW | wxLEFT | wxRIGHT ); + } + + this->SetupMenu(this->m_KeyWindow); + this->SetupMenu(this->m_ValueWindow); + + int x1, x2, xm, s1, s2, sm; + win->GetSize(&xm, &sm); + this->m_KeyWindow->GetSize(&x1, &s1); + this->m_ValueWindow->GetSize(&x2, &s2); + int m = s1; + if ( s2 > m ) + { + m = s2; + } + this->m_KeyWindow->SetSize(x1, m); + this->m_ValueWindow->SetSize(x2, m); + //std::cout << "Size of panels: " << sm << "," << s1 << ", " << s2 << " max: " << maxheight<< std::endl; + return maxheight; +} + +void cmCacheProperty::Remove(wxSizer* sizer, wxPanel*) +{ + if ( this->m_KeyWindow ) + { + sizer->Remove(this->m_KeyWindow); + this->m_KeyWindow->Destroy(); + } + if ( this->m_ValueWindow ) + { + sizer->Remove(this->m_ValueWindow); + this->m_ValueWindow->Destroy(); + } + this->m_KeyWindow = 0; + this->m_ValueWindow = 0; + //sizer->Layout(); + //win->Fit(); +} + +void cmCacheProperty::ConnectEvent(wxWindow* win, wxEventType et, wxObjectEventFunction func) +{ + if ( !this->m_MainFrame ) + { + return; + } + win->SetClientData(this); + this->m_MainFrame->Connect(win->GetId(), et, func); +} + +void cmCacheProperty::ConnectEventTo(wxWindow* win, wxEventType et, + wxObjectEventFunction func) +{ + if ( !this->m_MainFrame ) + { + return; + } + win->SetClientData(this); + this->m_MainFrame->ConnectEventTo(win, et, func); +} + +void cmCacheProperty::OnPropertyChanged(wxEvent& event) +{ + if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) + { + } + else + { + switch ( this->m_ItemType ) + { + case cmCacheProperty::EDIT: this->OnEntryChanged(event); break; + case cmCacheProperty::FILE: this->OnFileBrowseButton(event); break; + case cmCacheProperty::CHECKBOX: this->OnCheckboxButton(event); break; + case cmCacheProperty::PATH: this->OnPathBrowseButton(event); break; + } + } +} + +void cmCacheProperty::OnFileBrowseButton(wxEvent&) +{ + std::string path = cmSystemTools::GetFilenamePath(this->m_Value); + std::string file = cmSystemTools::GetFilenameName(this->m_Value); + + if ( path == "NOTFOUND" ) + { + path = this->m_MainFrame->GetBuildDir(); + } + + wxFileDialog dialog ( + this->m_MainFrame, + _T("Select file"), + path.c_str(), + file.c_str(), + _T("All files|*.*") + ); + + if (dialog.ShowModal() == wxID_OK) + { + std::string str = ""; + if ( this->m_TextControl ) + { + str += dialog.GetPath().c_str(); + static_cast(this->m_TextControl)->SetLabel(str.c_str()); + } + this->SetValue(str.c_str()); + } +} + +void cmCacheProperty::OnPathBrowseButton(wxEvent&) +{ + std::string path = this->m_Value; + if ( path == "NOTFOUND" ) + { + path = this->m_MainFrame->GetBuildDir(); + } + + wxDirDialog dialog ( this->m_MainFrame, _T("Select directory"), path.c_str() ); + + if (dialog.ShowModal() == wxID_OK) + { + if ( this->m_TextControl ) + { + static_cast(this->m_TextControl)->SetLabel(dialog.GetPath()); + } + this->SetValue(dialog.GetPath().c_str()); + } +} + +void cmCacheProperty::OnCheckboxButton(wxEvent& event) +{ + wxCheckBox* widget = static_cast( event.GetEventObject() ); + if ( !widget ) + { + return; + } + int val = widget->GetValue(); + if ( val ) + { + this->SetValue("ON"); + } + else + { + this->SetValue("OFF"); + } +} + +void cmCacheProperty::OnEntryChanged(wxEvent& event) +{ + wxTextCtrl* widget = static_cast( event.GetEventObject() ); + if ( !widget ) + { + return; + } + this->SetValue(static_cast(widget->GetValue())); +} + +void cmCacheProperty::SetupMenu(wxWindow* win) +{ + this->ConnectEventTo(win, wxEVT_RIGHT_DOWN, + (wxObjectEventFunction) &cmMainFrame::OnPopupMenu); + this->ConnectEventTo(win, wxEVT_MOTION, + (wxObjectEventFunction) &cmMainFrame::OnCacheStatusBar); +} diff --git a/Source/WXDialog/cmWXCacheProperty.h b/Source/WXDialog/cmWXCacheProperty.h new file mode 100644 index 0000000..1ccff72 --- /dev/null +++ b/Source/WXDialog/cmWXCacheProperty.h @@ -0,0 +1,130 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef CMCACHEPROPERTY_H +#define CMCACHEPROPERTY_H + +#include "cmStandardIncludes.h" + +#include "wxincludes.h" + +class cmMainFrame; +class wxControl; +class wxPanel; +class wxSizer; +class wxWindow; + +/** \class cmCacheProperty + * \brief GUI Control class for cmake's cache property + * + * Stores cache property as displayed on GUI, caches its value, colors + * red when new. + * + */ +class cmCacheProperty +{ +public: + cmCacheProperty(cmMainFrame*, const std::string& name); + ~cmCacheProperty(); + const std::string& GetName() { return this->m_Name; } + + //! Get and set the value + const std::string& GetValue() { return this->m_Value; } + void SetValue(const std::string& s) { this->m_Value = s; } + + //! Get and set the help value + void SetHelp(const std::string& s) { this->m_HelpString = s; } + const std::string& GetHelp() { return this->m_HelpString; } + + //! Display the property in the window. Return the maximum height. + int Display(wxSizer*, wxPanel*); + + //! Remove the property from the window + void Remove(wxSizer*, wxPanel*); + + //! This method is called when property is changed + void OnPropertyChanged(wxEvent& event); + + //! Mark cache entry as being removed. + void MarkRemoved() { this->m_Removed = true; } + + //! Check if the entry was removed + bool IsRemoved() { return this->m_Removed; } + + //! Get and set the new flag. + void SetNewFlag(bool f) { this->m_NewValue = f; } + bool GetNewFlag() { return this->m_NewValue; } + + //! Mark cache entry as being removed. + void MarkAdvanced() { this->m_Advanced = true; } + + //! Check if the entry was removed + bool IsAdvanced() { return this->m_Advanced; } + + //! Set item type + void SetItemType(int t) { this->m_ItemType = t; } + + //! Get the main frame asociated with the cache property + cmMainFrame* GetMainFrame() { return this->m_MainFrame; } + + enum ItemType + { + NOTHING = 0, + EDIT, + FILE, + CHECKBOX, + PATH + }; + + enum + { + Menu_Popup_Ignore = 200, + Menu_Popup_Delete, + Menu_Popup_Help + }; + +protected: + bool m_NewValue; + bool m_Advanced; + int m_ItemType; + + wxWindow* m_KeyWindow; + wxWindow* m_ValueWindow; + + std::string m_Name; + std::string m_Value; + std::string m_HelpString; + bool m_Removed; + + //! The following methods set the events handling of widgets for the + // cache property. + void ConnectEvent(wxWindow* win, wxEventType et, wxObjectEventFunction func); + void ConnectEventTo(wxWindow* win, wxEventType et, wxObjectEventFunction func); + void SetupMenu(wxWindow* win); + + //! This are event callbacks for different events. + void OnFileBrowseButton(wxEvent& event); + void OnPathBrowseButton(wxEvent& event); + void OnCheckboxButton(wxEvent& event); + void OnEntryChanged(wxEvent& event); + +private: + cmMainFrame* m_MainFrame; + wxControl* m_TextControl; +}; + + +#endif diff --git a/Source/WXDialog/cmWXCommandLineInfo.cxx b/Source/WXDialog/cmWXCommandLineInfo.cxx new file mode 100644 index 0000000..5aba382 --- /dev/null +++ b/Source/WXDialog/cmWXCommandLineInfo.cxx @@ -0,0 +1,133 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +// cmCommandLineInfo.cpp : command line arguments +// + +#include "cmWXCommandLineInfo.h" + +#include "cmSystemTools.h" + +/////////////////////////////////////////////////////////////// +// cmCommandLineInfo + +cmCommandLineInfo::cmCommandLineInfo() +{ + this->m_WhereSource = ""; + this->m_WhereBuild = ""; + this->m_AdvancedValues = false; + this->m_GeneratorChoiceString = ""; + this->m_LastUnknownParameter = ""; + this->m_ValidArguments = ""; +} + +/////////////////////////////////////////////////////////////// +cmCommandLineInfo::~cmCommandLineInfo() +{ +} + +/////////////////////////////////////////////////////////////// +void cmCommandLineInfo::ParseCommandLine(int argc, char* argv[]) +{ + int cc; + for ( cc = 1; cc < argc; cc ++ ) + { + if ( strlen(argv[cc]) < 1 ) + { + continue; + } + bool valid = true; + std::string argument = argv[cc]; + if ( argument.size() > 1 && + this->m_ValidArguments.find(argument[1]) == std::string::npos ) + { + valid = false; + } + this->ParseParam(argument, valid, (cc + 1 == argc)); + } + this->m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]); +} + +/////////////////////////////////////////////////////////////// +int cmCommandLineInfo::GetBoolValue(const std::string& v) { + std::string value = cmSystemTools::LowerCase(v); + if (value == "1" || + value == "on" || + value == "true" || + value == "yes") + { + return 1; + } + else if (value == "0" || + value == "off" || + value == "false" || + value == "no") + { + return -1; + } + return 0; +} + +/////////////////////////////////////////////////////////////// +// Parse param + +void cmCommandLineInfo::ParseParam(const std::string& parameter, + bool know_about, bool last) +{ + if(!know_about) + { + this->m_LastUnknownParameter = parameter; + } + else + { + std::string sParam(parameter.c_str(), 1); + // Single letter valued flag like /B=value or /B:value + std::string value; + if (sParam[1] == '=' || sParam[1] == ':') + { + value = std::string(parameter.c_str()+2); + } + else + { + value = std::string(parameter.c_str()+1); + } + int res; + switch (sParam[0]) + { + case 'A': + res = cmCommandLineInfo::GetBoolValue(value); + if (res == 1) + { + this->m_AdvancedValues = true; + } + else if (res == -1) + { + this->m_AdvancedValues = false; + } + break; + case 'B': + this->m_WhereBuild = value; + break; + case 'G': + this->m_GeneratorChoiceString = value; + break; + case 'H': + this->m_WhereSource = value; + break; + } + } +} diff --git a/Source/WXDialog/cmWXCommandLineInfo.h b/Source/WXDialog/cmWXCommandLineInfo.h new file mode 100644 index 0000000..7831d19 --- /dev/null +++ b/Source/WXDialog/cmWXCommandLineInfo.h @@ -0,0 +1,65 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +// cmCommandLineInfo.h : main header file for the command line arguments +// + +#if !defined(CMAKECOMMANDLINEINFO_H) +#define CMAKECOMMANDLINEINFO_H + +#include "cmStandardIncludes.h" + +/////////////////////////////////////////////////////////////// +// cmCommandLineInfo: +// See cmCommandLineInfo.cxx for the implementation of this class +// + +class cmCommandLineInfo +{ + // Construction +public: + cmCommandLineInfo(); + virtual ~cmCommandLineInfo(); + + // Parse the command line + void ParseCommandLine(int argc, char* argv[]); + + // Set the valid arguments + void SetValidArguments(const std::string& va) { this->m_ValidArguments = va; } + + // Retrieve the path of executable + std::string GetPathToExecutable() { return this->m_ExecutablePath; } + + // Attributes +public: + std::string m_WhereSource; + std::string m_WhereBuild; + bool m_AdvancedValues; + std::string m_GeneratorChoiceString; + std::string m_LastUnknownParameter; + std::string m_ExecutablePath; + +protected: + // Parse one argument + void ParseParam(const std::string& parameter, bool know_about, bool last); + + // Return boolean value of the string + static int GetBoolValue(const std::string&); + + std::string m_ValidArguments; +}; + +#endif // !defined(CMAKECOMMANDLINEINFO_H) diff --git a/Source/WXDialog/cmWXMainFrame.cxx b/Source/WXDialog/cmWXMainFrame.cxx new file mode 100644 index 0000000..829b5c8 --- /dev/null +++ b/Source/WXDialog/cmWXMainFrame.cxx @@ -0,0 +1,1384 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "cmWXMainFrame.h" + +#include "cmCacheManager.h" +#include "cmWXCacheProperty.h" +#include "cmWXCommandLineInfo.h" +#include "cmake.h" + +cmMainFrame::cmMainFrame(const wxString& title, const wxSize& size) + : wxFrame((wxFrame*)NULL, cmMainFrame::ID_MainFrame, title, wxDefaultPosition, size) +{ + + cmSystemTools::SetErrorCallback(cmMainFrame::MessageCallback, this); + this->m_Clean = false; + this->m_BuildPathChanged = false; + this->m_WhereSource = ""; + this->m_WhereBuild = ""; + + this->m_CMakeInstance = 0; + this->m_Update = false; + this->m_Valid = false; + this->m_EntryRemoved = false; + this->m_CursorChanged = false; + + this->m_CacheEntries = new cmMainFrame::CacheMapType; + + this->CreateStatusBar(1); + this->SetStatusText("Welcome to CMakeSetup"); + + + this->m_MainPanel = new wxPanel(this, -1); + + this->SetBackgroundColour(this->m_MainPanel->GetBackgroundColour()); + + this->m_TopMostSizer = new wxBoxSizer(wxVERTICAL); + + this->m_TopMostSizer->Add( this->m_MainPanel, 1, wxGROW | wxALL, 5 ); + + wxFlexGridSizer* msizer = new wxFlexGridSizer(1, 5, 5); + msizer->AddGrowableRow(2); + msizer->AddGrowableCol(0); + this->m_MainSizer = msizer; + + wxFlexGridSizer* tgrid = new wxFlexGridSizer(7, 2, 2); + tgrid->AddGrowableCol(2); + this->m_TopGrid = tgrid; + + + this->m_TextSource = new wxStaticText(this->m_MainPanel, -1, "Where is the source code:"); + this->m_PathSource = new wxComboBox(this->m_MainPanel, -1, "PathSource"); + this->m_BrowseSource = new wxButton(this->m_MainPanel, -1, "Browse..."); + + this->m_GeneratorFrame = new wxBoxSizer(wxHORIZONTAL); + this->m_BuildFor = new wxStaticText(this->m_MainPanel, -1, "Build For:"); + this->m_GeneratorMenu = new wxComboBox(this->m_MainPanel, -1, "Generator", + wxDefaultPosition, wxDefaultSize, + 0, 0, wxCB_READONLY); + + this->m_GeneratorFrame->Add(this->m_BuildFor, 0, wxALIGN_LEFT); + this->m_GeneratorFrame->Add(5,5,0); + this->m_GeneratorFrame->Add(this->m_GeneratorMenu, 1, wxGROW | wxALL ); + + this->m_TextBinary = new wxStaticText(this->m_MainPanel, -1, + "Where to build the binaries:"); + this->m_PathBinary = new wxComboBox(this->m_MainPanel, -1, "PathBinary"); + this->m_BrowseBinary = new wxButton(this->m_MainPanel, -1, "Browse..."); + this->m_ShowAdvancedValues = new wxCheckBox(this->m_MainPanel, -1, + "Show Advanced Values"); + + this->m_TopGrid->Add(this->m_TextSource, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + this->m_TopGrid->Add(5, 5, 0); + this->m_TopGrid->Add(this->m_PathSource, 1, wxGROW | wxLEFT | wxRIGHT ); + this->m_TopGrid->Add(5, 5, 0); + this->m_TopGrid->Add(this->m_BrowseSource, 1, 0); + this->m_TopGrid->Add(5, 5, 0); + this->m_TopGrid->Add(this->m_GeneratorFrame, 1, 0); + this->m_TopGrid->Add(this->m_TextBinary, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + this->m_TopGrid->Add(5, 5, 0); + this->m_TopGrid->Add(this->m_PathBinary, 1, wxGROW | wxLEFT | wxRIGHT ); + this->m_TopGrid->Add(5, 5, 0); + this->m_TopGrid->Add(this->m_BrowseBinary, 1, 0); + this->m_TopGrid->Add(5, 5, 0); + this->m_TopGrid->Add(this->m_ShowAdvancedValues, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + + this->m_MainSizer->Add(5, 5, 0); + this->m_MainSizer->Add(this->m_TopGrid, 1, wxGROW | wxLEFT | wxRIGHT, 10 ); + + this->m_CacheValuesBox = new wxStaticBox(this->m_MainPanel, -1, "Cache Values"); + //this->m_CacheValuesBox->SetBackgroundColour(*wxWHITE); + this->m_CacheValuesFrame = new wxStaticBoxSizer(this->m_CacheValuesBox, + wxVERTICAL); + this->m_CacheValuesScroll = new wxScrolledWindow(this->m_MainPanel, -1, + wxDefaultPosition, wxDefaultSize, + wxVSCROLL); + this->m_CacheValuesScroll->SetBackgroundColour(*wxWHITE); + this->m_CacheValuesFrame->Add(this->m_CacheValuesScroll, 1, wxEXPAND | wxALL, 0 ); + this->m_CacheValuesPanel = new wxPanel(this->m_CacheValuesScroll, -1); + this->m_CacheValuesPanel->SetBackgroundColour(wxColor(150, 150, 150)); + wxFlexGridSizer* csizer = new wxFlexGridSizer(2, 1, 1); + csizer->AddGrowableCol(0); + csizer->AddGrowableCol(1); + this->m_CacheValuesSizer = csizer; + this->m_CacheValuesPanel->SetAutoLayout( TRUE ); + this->m_CacheValuesPanel->SetSizer(this->m_CacheValuesSizer); + //this->m_CacheValuesPanel->SetBackgroundColour(wxColour(10,10,10)); + this->m_CacheValuesSizer->Fit(this->m_CacheValuesPanel); + this->m_CacheValuesSizer->SetSizeHints(this->m_CacheValuesPanel); + + //this->m_CacheValuesScroll->SetScrollbars(0, 20, 0, 50); + //wxSize framesize = this->m_CacheValuesBox->GetSize(); + //this->m_CacheValuesBox->SetSize(framesize.GetWidth(), 100); + this->SetSizeHints(580, 340); + this->m_MainSizer->Add(this->m_CacheValuesFrame, 1, wxGROW | wxALL ); + wxString helpTextData = ""; + helpTextData.append + ("Right click on a cache value for additional options " + "(delete, ignore, and help).\n" + "Press Configure to update and display new values in red.\n" + "Press OK to generate selected build files and exit."); + this->m_HelpText = new wxStaticText(this->m_MainPanel, -1, helpTextData, + wxDefaultPosition, + wxDefaultSize, + wxTE_MULTILINE); + + this->m_MainSizer->Add(5, 5, 0); + this->m_MainSizer->Add(this->m_HelpText, 0, wxALIGN_CENTER_HORIZONTAL, 10); + + this->m_BottomButtonsFrame = new wxBoxSizer(wxHORIZONTAL); + + //this->m_VersionText = new wxStaticText(this->m_MainPanel, -1, + //"Version 1.5 - development"); + this->m_ConfigureButton = new wxButton(this->m_MainPanel, -1, "Configure"); + this->m_OKButton = new wxButton(this->m_MainPanel, -1, "OK"); + this->m_CancelButton = new wxButton(this->m_MainPanel, -1, "Cancel"); + this->m_HelpButton = new wxButton(this->m_MainPanel, -1, "Help"); + + + this->m_BottomButtonsFrame->Add(m_ConfigureButton, 0, wxALIGN_LEFT, 10); + this->m_BottomButtonsFrame->Add(5, 5, 0); + this->m_BottomButtonsFrame->Add(m_OKButton, 0, wxALIGN_LEFT, 10); + this->m_BottomButtonsFrame->Add(5, 5, 0); + this->m_BottomButtonsFrame->Add(m_CancelButton, 0, wxALIGN_LEFT, 10); + this->m_BottomButtonsFrame->Add(5, 5, 0); + this->m_BottomButtonsFrame->Add(m_HelpButton, 0, wxALIGN_LEFT, 10); + + this->m_MainSizer->Add(5, 5, 0); + this->m_MainSizer->Add(m_BottomButtonsFrame, 0, wxALIGN_CENTER_HORIZONTAL, 10); + this->m_MainSizer->Add(5, 5, 0); + + this->m_MainPanel->SetAutoLayout( TRUE ); + this->m_MainPanel->SetSizer(this->m_MainSizer); + this->m_MainSizer->Fit(this->m_MainPanel); + this->m_MainSizer->SetSizeHints(this->m_MainPanel); + + this->SetAutoLayout( TRUE ); + this->SetSizer(this->m_TopMostSizer); + this->m_TopMostSizer->Fit(this); + this->m_TopMostSizer->SetSizeHints(this); + + // Setup statusbar callbacks + + this->SetupStatusBarBinding(this->m_ConfigureButton); + this->SetupStatusBarBinding(this->m_OKButton); + this->SetupStatusBarBinding(this->m_CancelButton); + this->SetupStatusBarBinding(this->m_HelpButton); + this->SetupStatusBarBinding(this->m_PathSource); + this->SetupStatusBarBinding(this->m_BrowseSource); + this->SetupStatusBarBinding(this->m_PathBinary); + this->SetupStatusBarBinding(this->m_BrowseBinary); + this->SetupStatusBarBinding(this->m_GeneratorMenu); + this->SetupStatusBarBinding(this->m_ShowAdvancedValues); + + // Setup other callbacks + this->ConnectEvent( this->m_CancelButton, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnCancel ); + this->ConnectEvent( this->m_OKButton, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnOk ); + this->ConnectEvent( this->m_HelpButton, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnHelp ); + this->ConnectEvent( this->m_ConfigureButton, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnConfigure ); + this->ConnectEvent( this, wxEVT_SIZE, + (wxObjectEventFunction) &cmMainFrame::OnResize ); + this->ConnectEvent( this->m_ShowAdvancedValues, wxEVT_COMMAND_CHECKBOX_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnShowAdvancedValues ); + this->ConnectEvent( this->m_BrowseSource, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnBrowseSource ); + this->ConnectEvent( this->m_BrowseBinary, wxEVT_COMMAND_BUTTON_CLICKED, + (wxObjectEventFunction) &cmMainFrame::OnBrowseBinary ); + this->ConnectEvent( this->m_PathSource, wxEVT_COMMAND_COMBOBOX_SELECTED, + (wxObjectEventFunction) &cmMainFrame::OnSourceSelected ); + this->ConnectEvent( this->m_PathSource, wxEVT_COMMAND_TEXT_UPDATED, + (wxObjectEventFunction) &cmMainFrame::OnSourceSelected ); + this->ConnectEvent( this->m_PathBinary, wxEVT_COMMAND_COMBOBOX_SELECTED, + (wxObjectEventFunction) &cmMainFrame::OnBinarySelected ); + this->ConnectEvent( this->m_PathBinary, wxEVT_COMMAND_TEXT_UPDATED, + (wxObjectEventFunction) &cmMainFrame::OnBinarySelected ); + this->ConnectEvent( this->m_GeneratorMenu, wxEVT_COMMAND_COMBOBOX_SELECTED, + (wxObjectEventFunction) &cmMainFrame::OnGeneratorSelected ); + this->ConnectEvent( this->m_GeneratorMenu, wxEVT_COMMAND_TEXT_UPDATED, + (wxObjectEventFunction) &cmMainFrame::OnGeneratorSelected ); + + this->Connect(cmCacheProperty::Menu_Popup_Ignore, wxEVT_COMMAND_MENU_SELECTED, + (wxObjectEventFunction) &cmMainFrame::OnPopupMenuIgnore); + this->Connect(cmCacheProperty::Menu_Popup_Delete, wxEVT_COMMAND_MENU_SELECTED, + (wxObjectEventFunction) &cmMainFrame::OnPopupMenuDelete); + this->Connect(cmCacheProperty::Menu_Popup_Help, wxEVT_COMMAND_MENU_SELECTED, + (wxObjectEventFunction) &cmMainFrame::OnPopupMenuHelp); +} + +cmMainFrame::~cmMainFrame() +{ + cmMainFrame::CacheMapType* items = this->m_CacheEntries; + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); ++i) + { + cmCacheProperty* item = i->second; + delete item; + } + delete this->m_CacheEntries; + + delete this->m_CMakeInstance; + +} + +void cmMainFrame::MessageCallback(const char* m, const char* title, bool& nomore, + void* clientData) +{ + + if ( clientData ) + { + cmMainFrame* self = static_cast( clientData ); + self->DisplayMessage(m, title, nomore); + } + else + { + std::string message = "The following error happen without frame being set:\n\n"; + message += m; + message += "\n\n(Press Cancel to suppress any further messages.)"; + if(::wxMessageBox(message.c_str(), title, + wxICON_WARNING | wxOK | wxCANCEL ) == wxCANCEL) + { + nomore = true; + } + } + +} + +void cmMainFrame::DisplayMessage(const char* m, const char* title, bool& nomore) +{ + this->CursorNormal(false); + std::string message = m; + message += "\n\n(Press Cancel to suppress any further messages.)"; + if(::wxMessageBox(message.c_str(), title, + wxICON_WARNING | wxOK | wxCANCEL ) == wxCANCEL) + { + nomore = true; + } + if ( this->m_CursorChanged ) + { + this->CursorBusy(false); + } +} + +void cmMainFrame::ConnectEvent(wxWindow* win, wxEventType et, wxObjectEventFunction func) +{ +// + this->Connect((win?win->GetId():-1), et, func); +// +} + +void cmMainFrame::ConnectEventTo(wxWindow* win, wxEventType et, wxObjectEventFunction func) +{ +// + win->Connect(-1, et, func); +// +} + +void cmMainFrame::OnStatusBar(wxEvent& event) +{ + wxControl* eobject = static_cast(event.GetEventObject()); + if ( eobject && eobject->GetClientData() ) + { + cmMainFrame* self = static_cast(eobject->GetClientData()); + if ( eobject == self->m_OKButton ) + { + self->SetStatusText("Press OK to generate selected build files and exit."); + } + else if ( eobject == self->m_CancelButton ) + { + self->SetStatusText("Press Cancel to lose the changes and exit."); + } + else if ( eobject == self->m_ConfigureButton ) + { + self->SetStatusText("Press Configure to update and display new values in red."); + } + else if ( eobject == self->m_HelpButton ) + { + self->SetStatusText("Press Help to display help."); + } + else if ( eobject == self->m_ShowAdvancedValues ) + { + self->SetStatusText("Toggle between regular and advanced cache values."); + } + else if ( eobject == self->m_GeneratorMenu ) + { + self->SetStatusText("Set the generator to generate the build files."); + } + else if ( eobject == self->m_PathSource ) + { + self->SetStatusText("Enter the path to the source files."); + } + else if ( eobject == self->m_BrowseSource ) + { + self->SetStatusText("Browse the path to the source files."); + } + else if ( eobject == self->m_PathBinary ) + { + self->SetStatusText("Enter the path to the build files."); + } + else if ( eobject == self->m_BrowseBinary ) + { + self->SetStatusText("Browse the path to the build files."); + } + else + { + self->SetStatusText("CMakeSetup"); + } + } +} + +void cmMainFrame::OnCacheStatusBar(wxEvent& event) +{ + wxControl* eobject = static_cast(event.GetEventObject()); + if ( eobject && eobject->GetClientData() ) + { + cmCacheProperty* cprop = static_cast(eobject->GetClientData()); + cprop->GetMainFrame()->SetStatusText(cprop->GetHelp().c_str(), 0); + } +} + +void cmMainFrame::OnPopupMenu(wxMouseEvent& event) +{ + + // + wxControl* eobject = static_cast(event.GetEventObject()); + if ( eobject && eobject->GetClientData() ) + { + wxMenu menu; + menu.Append(cmCacheProperty::Menu_Popup_Ignore, "Ignore Cache Entry"); + menu.Append(cmCacheProperty::Menu_Popup_Delete, "Delete Cache Entry"); + menu.Append(cmCacheProperty::Menu_Popup_Help, "Help for Cache Entry"); + cmCacheProperty* cprop = static_cast(eobject->GetClientData()); + cmMainFrame* self = cprop->GetMainFrame(); + menu.SetClientData(eobject->GetClientData()); + this->PopupMenu(&menu, event.GetPosition()); + if ( self->m_EntryRemoved ) + { + self->UpdateCacheValuesDisplay(); + self->m_EntryRemoved = false; + } + } +} + +void cmMainFrame::OnPopupMenuIgnore(wxEvent& event) +{ +// + this->OnPopupMenuEntry(event, 0); +// +} + +void cmMainFrame::OnPopupMenuDelete(wxEvent& event) +{ +// + this->OnPopupMenuEntry(event, 1); +// +} + +void cmMainFrame::OnPopupMenuHelp(wxEvent& event) +{ +// + this->OnPopupMenuEntry(event, 2); +// +} + +void cmMainFrame::OnPopupMenuEntry(wxEvent& event, int idx) +{ + + wxMenu* eobject = static_cast(event.GetEventObject()); + if ( eobject && eobject->GetClientData() ) + { + cmCacheProperty* cprop = static_cast(eobject->GetClientData()); + switch ( idx ) + { + case 0: this->IgnoreCacheEntry(cprop->GetName().c_str()); + break; + case 1: this->RemoveCacheEntry(cprop); + break; + case 2: this->HelpCacheEntry(cprop->GetName().c_str(), cprop->GetHelp().c_str()); + break; + } + } +} + +void cmMainFrame::OnOk(wxCommandEvent&) +{ + + // enable error messages each time configure is pressed + cmSystemTools::EnableMessages(); + this->ClearDirty(); + this->RunCMake(true); + cmMainFrame::Close(TRUE); + +} + +void cmMainFrame::OnCancel(wxCommandEvent&) +{ + if ( this->IsDirty() ) + { + // Display dialog + if ( wxMessageBox( "You have changed options but not rebuild, " + "are you sure you want to exit?", + "Confirm Exit", wxICON_WARNING | wxYES_NO ) != wxYES ) + { + return; + } + } + cmMainFrame::Close(TRUE); + +} + +void cmMainFrame::OnConfigure(wxCommandEvent&) +{ + // enable error messages each time configure is pressed + cmSystemTools::EnableMessages(); + this->m_Update = true; + this->RunCMake(false); +} + +void cmMainFrame::OnHelp(wxCommandEvent&) +{ + + std::string message = + "CMake is used to configure and generate build files for software projects. The basic steps for configuring a\n" + "project are as follows:\n\n" + "1. Select the source directory for the project. This should contain the CMakeLists.txt files for the project.\n\n" + "2. Select the build directory for the project. This is the directory where the project will be built. It can\n" + "be the same or a different directory than the source directory. For easy clean up, a separate build directory\n" + "is recommended. CMake will create the directory if it does not exist.\n\n" + "3. Once the source and binary directories are selected, it is time to press the Configure button. This will cause\n" + "CMake to read all of the input files and discover all the variables used by the project. The first time a\n" + "variable is displayed it will be in Red. Users should inspect red variables making sure the values are correct.\n" + "For some projects the Configure process can be iterative, so continue to press the Configure button until there\n" + " are no longer red entries.\n\n" + "4. Once there are no longer red entries, you should click the OK button. This will write the build files to the\n" + "build directory and exit CMake."; + ::wxMessageBox(message.c_str(), "CMake Help", + wxICON_INFORMATION | wxOK ); + +} + +void cmMainFrame::OnPropertyChanged(wxEvent& event) +{ + + wxControl* eobject = static_cast(event.GetEventObject()); + if ( eobject && eobject->GetClientData() ) + { + cmCacheProperty* property = static_cast( + eobject->GetClientData() ); + property->OnPropertyChanged(event); + } +} + +void cmMainFrame::OnResize(wxSizeEvent& event) +{ + + this->wxFrame::OnSize(event); + // Expand inner pannel when window resizes + this->ResizeInternal(); + +} +void cmMainFrame::ResizeInternal() +{ + // Expand inner pannel when window resizes + int x, y; + this->m_CacheValuesScroll->GetClientSize(&x, &y); + wxSize size1 = this->m_CacheValuesPanel->GetSize(); + this->m_CacheValuesPanel->SetSize(wxSize(x, size1.GetHeight())); + //this->m_CacheValuesSizer->SetDimension(0,0,x,size1.GetHeight()); +} + +void cmMainFrame::OnBrowseSource(wxCommandEvent&) +{ + std::string path = this->m_PathSource->GetValue().c_str(); + if ( path == "PathSource" ) + { + path = cmSystemTools::CollapseFullPath(this->m_PathToExecutable.c_str()); + } + wxDirDialog dialog ( this, _T("Select path"), path.c_str() ); + + if (dialog.ShowModal() == wxID_OK) + { + this->SetSourceDir(dialog.GetPath()); + } +} + +void cmMainFrame::OnBrowseBinary(wxCommandEvent&) +{ + std::string path = this->m_PathBinary->GetValue().c_str(); + if ( path == "PathBinary" ) + { + path = this->m_PathSource->GetValue().c_str(); + if ( path == "PathSource" ) + { + path = cmSystemTools::CollapseFullPath(this->m_PathToExecutable.c_str()); + } + } + wxDirDialog dialog ( this, _T("Select path"), path.c_str() ); + + if (dialog.ShowModal() == wxID_OK) + { + if ( this->SetBinaryDir(dialog.GetPath()) ) + { + this->m_Update = true; + this->ChangeWhereBuild(); + } + } +} + +void cmMainFrame::Initialize(cmCommandLineInfo* cmdInfo) +{ + + this->m_PathToExecutable = cmdInfo->GetPathToExecutable(); + this->LoadFromRegistry(); + this->m_CMakeInstance = new cmake; // force a register of generators + std::vector names; + this->m_CMakeInstance->GetRegisteredGenerators(names); + for(std::vector::iterator i = names.begin(); + i != names.end(); ++i) + { + this->m_GeneratorMenu->Append(i->c_str()); + } + + //{{AFX_DATA_INIT(CMakeSetupDialog) + // Get the parameters from the command line info + // If an unknown parameter is found, try to interpret it too, since it + // is likely to be a file dropped on the shortcut :) + if (cmdInfo->m_LastUnknownParameter.empty()) + { + if ( cmdInfo->m_WhereSource.size() > 0 ) + { + this->SetSourceDir( cmdInfo->m_WhereSource.c_str() ); + } + if ( cmdInfo->m_WhereBuild.size() > 0 ) + { + this->SetBinaryDir( cmdInfo->m_WhereBuild.c_str() ); + } + if ( this->m_GeneratorMenu->GetSelection() >= 0 && + this->m_GeneratorMenu->GetValue().size() > 0 ) + { + this->SetGenerator(this->m_GeneratorMenu->GetValue().c_str()); + } + this->m_ShowAdvancedValues->SetValue(cmdInfo->m_AdvancedValues); + } + else + { + this->m_ShowAdvancedValues->SetValue(FALSE); + this->ChangeDirectoriesFromFile(cmdInfo->m_LastUnknownParameter.c_str()); + } + /* + this->UpdateSourceBuildMenus(); + */ + this->LoadCacheFromDiskToGUI(); + +} + +//! Set the current generator +void cmMainFrame::SetGenerator(const char* generator) +{ + if ( strlen(generator) > 0 ) + { + int pos = this->m_GeneratorMenu->FindString(generator); + if ( pos >= 0 ) + { + this->m_GeneratorMenu->SetSelection(pos); + } + } + +} + +//! Load cache file from m_WhereBuild and display in GUI editor +void cmMainFrame::LoadCacheFromDiskToGUI() +{ + cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); + if(this->GetBinaryDir().size() > 0 ) + { + cachem->LoadCache(this->m_WhereBuild.c_str()); + this->UpdateCacheValuesDisplay(); + cmCacheManager::CacheIterator it = cachem->NewIterator(); + if(it.Find("CMAKE_GENERATOR")) + { + std::string curGen = it.GetValue(); + if(this->m_GeneratorMenu->GetSelection() < 0 || + std::string(this->m_GeneratorMenu->GetValue().c_str()) != curGen) + { + this->SetGenerator(curGen.c_str()); + } + } + } + +} + + +// copy from the cache manager to the cache edit list box +void cmMainFrame::FillCacheGUIFromCacheManager() +{ + + //size_t size = 0; + //size_t size = this->m_CacheEntriesList.GetItems().size(); + //bool reverseOrder = false; + // if there are already entries in the cache, then + // put the new ones in the top, so they show up first + /* + if(size) + { + reverseOrder = true; + } + */ + + this->UpdateCacheValuesDisplay(); + +} + +void cmMainFrame::OnGeneratorSelected(wxEvent&) +{ + + +} + +void cmMainFrame::OnShowAdvancedValues(wxCommandEvent&) +{ + this->m_Update = false; + this->UpdateCacheValuesDisplay(); +} + +// Handle param or single dropped file. +// If the dropped file is a build directory or any file in a +// build directory, set the source dir from the cache file, +// otherwise set the source and build dirs to this file (or dir). + +void cmMainFrame::ChangeDirectoriesFromFile(const char* buffer) +{ + // Get the path to this file + + std::string path = buffer; + if (!cmSystemTools::FileIsDirectory(path.c_str())) + { + path = cmSystemTools::GetFilenamePath(path); + } + else + { + cmSystemTools::ConvertToUnixSlashes(path); + } + + // Check if it's a build dir and grab the cache + + std::string cache_file = path; + cache_file += "/CMakeCache.txt"; + + cmCacheManager *cache = this->m_CMakeInstance->GetCacheManager(); + cmCacheManager::CacheIterator it = cache->GetCacheIterator("CMAKE_HOME_DIRECTORY"); + if (cmSystemTools::FileExists(cache_file.c_str()) && + cache->LoadCache(path.c_str()) && + !it.IsAtEnd()) + { + path = cmSystemTools::ConvertToOutputPath(path.c_str()); + this->SetBinaryDir(path.c_str()); + + path = cmSystemTools::ConvertToOutputPath(it.GetValue()); + this->SetSourceDir(path.c_str()); + } + else + { + path = cmSystemTools::ConvertToOutputPath(path.c_str()); + this->SetSourceDir(path.c_str()); + this->SetBinaryDir(path.c_str()); + } + +} + +void cmMainFrame::UpdateSourceBuildMenus() +{ + + +} + +void cmMainFrame::RunCMake(bool generateProjectFiles) +{ + if(!cmSystemTools::FileExists(this->GetBinaryDir().c_str())) + { + std::string message = + "Build directory does not exist, should I create it?\n\n" + "Directory: "; + message += this->GetBinaryDir(); + if(wxMessageBox(message.c_str(), "Create Directory", wxICON_WARNING | wxOK | wxCANCEL) == wxOK) + { + cmSystemTools::MakeDirectory(this->GetBinaryDir().c_str()); + } + else + { + (void)wxMessageBox("Build Project aborted, nothing done.", "CMake Aborted", + wxICON_INFORMATION | wxOK); + + return; + } + } + // set the wait cursor + this->CursorBusy(true); + + + // get all the info from the dialog + //this->UpdateData(); + // always save the current gui values to disk + this->SaveCacheFromGUI(); + // Make sure we are working from the cache on disk + this->LoadCacheFromDiskToGUI(); + + + // + this->m_Valid = true; + this->m_OKButton->Enable(false); + + // setup the cmake instance + if (generateProjectFiles) + { + if(this->m_CMakeInstance->Generate() != 0) + { + cmSystemTools::Error( + "Error in generation process, project files may be invalid"); + } + } + else + { + this->m_CMakeInstance->SetHomeDirectory(this->GetSourceDir().c_str()); + this->m_CMakeInstance->SetStartDirectory(this->GetSourceDir().c_str()); + this->m_CMakeInstance->SetHomeOutputDirectory(this->GetBinaryDir().c_str()); + this->m_CMakeInstance->SetStartOutputDirectory(this->GetBinaryDir().c_str()); + this->m_CMakeInstance->SetGlobalGenerator( + this-> m_CMakeInstance->CreateGlobalGenerator(this->m_GeneratorMenu->GetValue())); + this->m_CMakeInstance->SetCMakeCommand(this->m_PathToExecutable.c_str()); + this->m_CMakeInstance->LoadCache(); + if(this->m_CMakeInstance->Configure() != 0) + { + cmSystemTools::Error( + "Error in configuration process, project files may be invalid"); + } + // update the GUI with any new values in the caused by the + // generation process + this->LoadCacheFromDiskToGUI(); + } + + // save source and build paths to registry + this->SaveToRegistry(); + // path is up-to-date now + this->m_BuildPathChanged = false; + // put the cursor back + this->CursorNormal(true); + cmSystemTools::ResetErrorOccuredFlag(); + +} + +//! Save GUI values to cmCacheManager and then save to disk. +void cmMainFrame::SaveCacheFromGUI() +{ + cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); + this->FillCacheManagerFromCacheGUI(); + if(this->GetBinaryDir() != "") + { + cachem->SaveCache(this->GetBinaryDir().c_str()); + } + +} + +// copy from the list box to the cache manager +void cmMainFrame::FillCacheManagerFromCacheGUI() +{ + + cmMainFrame::CacheMapType *items = this->m_CacheEntries; + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); ++i) + { + cmCacheProperty* item = i->second; + + cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); + cmCacheManager::CacheIterator it = cachem->GetCacheIterator(item->GetName().c_str()); + if (!it.IsAtEnd()) + { + // if value is enclosed in single quotes ('foo') then remove them + // they were used to enforce the fact that it had 'invisible' + // trailing stuff + std::string str = item->GetValue(); + if (str.size() >= 2 && + str[0] == '\'' && + str[str.size() - 1] == '\'') + { + it.SetValue(str.substr(1,str.size() - 2).c_str()); + } + else + { + it.SetValue(str.c_str()); + } + } + } + +} + +void cmMainFrame::UpdateCacheValuesDisplay() +{ + + cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); + + this->m_CacheValuesScroll->Scroll(0,0); + + if ( this->m_Update ) + { + // all the current values are not new any more + cmMainFrame::CacheMapType* items = this->m_CacheEntries; + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); ++i) + { + cmCacheProperty* item = i->second; + item->SetNewFlag( false ); + } + } + + // redraw the list + this->m_CacheValuesPanel->SetBackgroundColour(*wxWHITE); + cmMainFrame::CacheMapType* items = this->m_CacheEntries; + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); ++i) + { + cmCacheProperty* item = i->second; + item->Remove(this->m_CacheValuesSizer, this->m_CacheValuesPanel); + } + + //this->m_CacheValuesPanel->SetSize(5,5); + //this->m_CacheValuesPanel->Fit(); + + bool showadvancedvalues = this->m_ShowAdvancedValues->GetValue(); + + int x, y; + this->m_CacheValuesPanel->GetSize(&x, &y); + + for(cmCacheManager::CacheIterator i = cachem->NewIterator(); + !i.IsAtEnd(); i.Next()) + { + const char* key = i.GetName(); + cmMainFrame::CacheMapType::iterator cprop = this->m_CacheEntries->find(key); + cmCacheProperty *property = 0; + if ( cprop != this->m_CacheEntries->end() ) + { + property = cprop->second; + } + + std::string value = i.GetValue(); + + // if value has trailing space or tab, enclose it in single quotes + // to enforce the fact that it has 'invisible' trailing stuff + if (value.size() && + (value[value.size() - 1] == ' ' || + value[value.size() - 1] == '\t')) + { + value = '\'' + value + '\''; + } + + if ( i.GetType() != cmCacheManager::BOOL && + i.GetType() != cmCacheManager::FILEPATH && + i.GetType() != cmCacheManager::PATH && + i.GetType() != cmCacheManager::STRING || + !showadvancedvalues && i.GetPropertyAsBool("ADVANCED") ) + { + continue; + } + + if ( !property ) + { + property = new cmCacheProperty(this, key); + property->SetHelp( i.GetProperty("HELPSTRING") ); + (*this->m_CacheEntries)[key] = property; + } + + if(i.GetPropertyAsBool("ADVANCED")) + { + property->MarkAdvanced(); + } + if ( !property->IsRemoved() ) + { + property->SetValue(value); + switch(i.GetType() ) + { + case cmCacheManager::BOOL: + if(cmSystemTools::IsOn(value.c_str())) + { + property->SetValue("ON"); + } + else + { + property->SetValue("OFF"); + } + property->SetItemType( cmCacheProperty::CHECKBOX ); + break; + case cmCacheManager::PATH: + property->SetItemType( cmCacheProperty::PATH ); + break; + case cmCacheManager::FILEPATH: + property->SetItemType( cmCacheProperty::FILE ); + break; + case cmCacheManager::STRING: + property->SetItemType( cmCacheProperty::EDIT ); + break; + default: + property->MarkRemoved(); + } + } + } + + if(this->m_CacheEntries->size() > 0 && !cmSystemTools::GetErrorOccuredFlag()) + { + bool enable = true; + cmMainFrame::CacheMapType* items = this->m_CacheEntries; + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); i++) + { + cmCacheProperty* item = i->second; + if(item && item->GetNewFlag() && !item->IsRemoved()) + { + // if one new value then disable to OK button + enable = false; + this->m_Valid = false; + break; + } + } + this->m_OKButton->Enable(this->m_Valid); + this->m_CacheValuesPanel->SetBackgroundColour(wxColor(150, 150, 150)); + } + else + { + this->m_CacheValuesPanel->SetBackgroundColour(*wxWHITE); + } + + int max = 0; + int count = 0; + wxSize size1 = this->m_CacheValuesPanel->GetSize(); + size1.SetHeight(1); + this->m_CacheValuesPanel->SetSize(size1); + int height = 0; + // redraw the list + cmMainFrame::CacheMapType::iterator nexti; + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); i = nexti) + { + cmCacheProperty* item = i->second; + nexti = i; + nexti++; + if ( item->IsRemoved() ) + { + delete item; + items->erase(i); + } + } + + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); i++) + { + cmCacheProperty* item = i->second; + if((showadvancedvalues || !item->IsAdvanced()) && !item->GetNewFlag() ) + { + int nm = item->Display(this->m_CacheValuesSizer, this->m_CacheValuesPanel); + height += nm + 1; + count ++; + if ( nm > max ) + { + max = nm; + } + } + } + for(cmMainFrame::CacheMapType::reverse_iterator i = items->rbegin(); + i != items->rend(); i++) + { + cmCacheProperty* item = i->second; + if((showadvancedvalues || !item->IsAdvanced()) && item->GetNewFlag()) + { + int nm = item->Display(this->m_CacheValuesSizer, this->m_CacheValuesPanel); + height += nm + 1; + count ++; + if ( nm > max ) + { + max = nm; + } + } + } + if ( count > 0 ) + { + this->m_CacheValuesPanel->SetBackgroundColour(wxColor(150, 150, 150)); + } + else + { + this->m_CacheValuesPanel->SetBackgroundColour(*wxWHITE); + } + this->m_CacheValuesSizer->Layout(); + + //max += 1; + + // Fix size + int sx, sy; + int total = max * count + 4; + wxSize sizersize = this->m_CacheValuesSizer->GetSize(); + + this->m_CacheValuesScroll->GetClientSize(&sx, &sy); + wxSize size2 = this->m_CacheValuesPanel->GetSize(); + sy = size2.GetHeight(); + this->m_CacheValuesPanel->SetSize(wxSize(sx, height)); + this->m_CacheValuesSizer->Layout(); + this->m_CacheValuesScroll->SetScrollbars(0, 2, 0, height/2); + + this->ResizeInternal(); + +} + +void cmMainFrame::RemoveAdvancedValues() +{ + + cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); + cmMainFrame::CacheMapType* items = this->m_CacheEntries; + + for(cmCacheManager::CacheIterator i = cachem->NewIterator(); + !i.IsAtEnd(); i.Next()) + { + const char* key = i.GetName(); + //const cmCacheManager::CacheEntry& value = i.GetEntry(); + if(i.GetPropertyAsBool("ADVANCED")) + { + cmCacheProperty* property = (*items)[key]; + property->Remove(this->m_CacheValuesSizer, this->m_CacheValuesPanel); + } + } + +} + +void cmMainFrame::ChangeWhereBuild() +{ + + std::string path(this->m_PathBinary->GetValue().c_str()); + cmSystemTools::ConvertToUnixSlashes(path); + std::string cache_file = path; + cache_file += "/CMakeCache.txt"; + + if ( !this->m_CMakeInstance ) + { + + return; + } + + cmCacheManager *cache = this->m_CMakeInstance->GetCacheManager(); + cmCacheManager::CacheIterator it = cache->NewIterator(); + + if (cmSystemTools::FileExists(cache_file.c_str()) && + cache->LoadCache(path.c_str()) && + it.Find("CMAKE_HOME_DIRECTORY")) + { + path = cmSystemTools::ConvertToOutputPath(it.GetValue()); + + if ( this->SetSourceDir(path.c_str()) ) + { + this->ChangeWhereSource(); + } + } + + this->ClearCache(); + this->LoadCacheFromDiskToGUI(); + this->m_BuildPathChanged = true; + +} + +void cmMainFrame::ChangeWhereSource() +{ + + + +} + +bool cmMainFrame::SetSourceDir(const char* dir) +{ + if ( this->m_WhereSource == dir || strlen(dir) == 0 ) + { + return false; + } + if ( this->m_PathSource->FindString(dir) < 0 ) + { + this->m_PathSource->Append(dir); + } + this->m_PathSource->SetValue(dir); + this->m_WhereSource = dir; + this->m_Valid = false; + + return true; +} + +bool cmMainFrame::SetBinaryDir(const char* dir) +{ + if ( this->m_WhereBuild == dir || strlen(dir) == 0 ) + { + + return false; + } + if ( this->m_PathBinary->FindString(dir) < 0 ) + { + this->m_PathBinary->Append(dir); + } + this->m_PathBinary->SetValue(dir); + this->m_WhereBuild = dir; + this->m_Valid = false; + + return true; +} + +void cmMainFrame::ClearCache() +{ + cmMainFrame::CacheMapType* items = this->m_CacheEntries; + for(cmMainFrame::CacheMapType::iterator i = items->begin(); + i != items->end(); ++i) + { + cmCacheProperty* item = i->second; + item->Remove(this->m_CacheValuesSizer, this->m_CacheValuesPanel); + } + + items->erase(items->begin(), items->end()); + +} + +void cmMainFrame::OnBinarySelected(wxCommandEvent&) +{ + if ( this->BuildDirectoryChanged() ) + { + this->m_WhereBuild = this->GetBinaryDir(); + this->ChangeWhereBuild(); + } + +} + +void cmMainFrame::OnSourceSelected(wxCommandEvent&) +{ + if ( this->SourceDirectoryChanged() ) + { + this->m_WhereSource = this->GetSourceDir(); + } + +} + +std::string cmMainFrame::GetBinaryDir() +{ + return std::string(this->m_PathBinary->GetValue().c_str()); +} + +std::string cmMainFrame::GetSourceDir() +{ + return std::string(this->m_PathSource->GetValue().c_str()); +} + +bool cmMainFrame::SourceDirectoryChanged() +{ + return (this->m_WhereSource != this->GetSourceDir()); +} + +bool cmMainFrame::BuildDirectoryChanged() +{ + return (this->m_WhereBuild != this->GetBinaryDir()); +} + +void cmMainFrame::OnRandomEvent(wxEvent& event) +{ + + if ( event.GetEventType() == wxEVT_UPDATE_UI ) + { + } + else + { + std::cout << "Random event: " << event.GetEventType() << std::endl; + } + +} + +void cmMainFrame::IgnoreCacheEntry(const char* key) +{ + std::cout << "IgnoreCacheEntry " << key << std::endl; +} + +void cmMainFrame::RemoveCacheEntry(cmCacheProperty* cprop) +{ + this->m_Valid = false; + this->m_CMakeInstance->GetCacheManager()->RemoveCacheEntry(cprop->GetName().c_str()); + cprop->MarkRemoved(); + this->m_EntryRemoved = true; +} + +void cmMainFrame::HelpCacheEntry(const char* key, const char* help) +{ + wxMessageBox( help, key, wxICON_INFORMATION | wxOK ); +} + +void cmMainFrame::LoadFromRegistry() +{ +//wxConfigBase *conf = (wxConfigBase*) wxConfigBase::Get();//new wxConfig("CMakeSetup"); + wxConfig *conf = new wxConfig("CMakeSetup"); + conf->SetPath("Settings/StartPath"); + + int cc; + char keyName[1024]; + wxString regvalue; + for ( cc = 1; cc <= 10; cc ++ ) + { + sprintf(keyName, "WhereSource%i", cc); + regvalue = ""; + conf->Read(keyName, ®value); + if ( regvalue.size() > 0 ) + { + if ( cc == 1 ) + { + this->SetSourceDir(regvalue.c_str()); + } + else + { + this->m_PathSource->Append(regvalue); + } + } + sprintf(keyName, "WhereBuild%i", cc); + regvalue = ""; + conf->Read(keyName, ®value); + if ( regvalue.size() > 0 ) + { + if ( cc == 1 ) + { + this->SetBinaryDir(regvalue.c_str()); + } + else + { + this->m_PathBinary->Append(regvalue); + } + } + } + + delete conf; + +} + +void cmMainFrame::SaveToRegistry() +{ + + //wxConfigBase *conf = (wxConfigBase*) wxConfigBase::Get();//new wxConfig("CMakeSetup"); + wxConfig *conf = new wxConfig("CMakeSetup"); + conf->SetPath("Settings/StartPath"); + + wxString regvalue; + if ( !conf->Read("WhereSource1", ®value) ) + { + regvalue = ""; + } + int shiftEnd = 9; + if(this->m_WhereSource != regvalue.c_str()) + { + char keyName[1024]; + char keyName2[1024]; + int i; + for (i = 2; i < 10; ++i) + { + regvalue = ""; + sprintf(keyName,"WhereSource%i",i); + conf->Read(keyName, ®value); + // check for short circuit, if the new value is already in + // the list then we stop + if (this->m_WhereSource == regvalue.c_str()) + { + shiftEnd = i - 1; + } + } + + for (i = shiftEnd; i; --i) + { + regvalue = ""; + sprintf(keyName,"WhereSource%i",i); + sprintf(keyName2,"WhereSource%i",i+1); + + conf->Read(keyName, ®value); + if (strlen(regvalue.c_str())) + { + conf->Write(keyName2, wxString(regvalue.c_str())); + } + } + conf->Write("WhereSource1", wxString(this->m_WhereSource.c_str())); + } + + conf->Read("WhereBuild1", ®value); + if(m_WhereBuild != regvalue.c_str()) + { + int i; + char keyName[1024]; + char keyName2[1024]; + for (i = 2; i < 10; ++i) + { + regvalue = ""; + sprintf(keyName,"WhereBuild%i",i); + conf->Read(keyName, ®value); + // check for short circuit, if the new value is already in + // the list then we stop + if (m_WhereBuild == regvalue.c_str()) + { + shiftEnd = i - 1; + } + } + for (i = shiftEnd; i; --i) + { + regvalue = ""; + sprintf(keyName,"WhereBuild%i",i); + sprintf(keyName2,"WhereBuild%i",i+1); + + conf->Read(keyName, ®value); + if (strlen(regvalue.c_str())) + { + conf->Write(keyName2, wxString(regvalue.c_str())); + } + } + conf->Write("WhereBuild1", wxString(this->m_WhereBuild.c_str())); + } + delete conf; + +} + +void cmMainFrame::SetupStatusBarBinding(wxWindow* win) +{ + win->SetClientData(this); + this->ConnectEventTo(win, wxEVT_MOTION, + (wxObjectEventFunction) &cmMainFrame::OnStatusBar); +} + +void cmMainFrame::SetStatusText(const wxString& text, int number) +{ + this->wxFrame::SetStatusText("________________________________________________"); + this->wxFrame::SetStatusText(text, number); +} + +void cmMainFrame::CursorBusy(bool s) +{ + wxSetCursor(*wxHOURGLASS_CURSOR); + if ( s ) + { + this->m_CursorChanged = true; + } +} + +void cmMainFrame::CursorNormal(bool s) +{ + wxSetCursor(*wxSTANDARD_CURSOR); + if ( s ) + { + this->m_CursorChanged = false; + } +} + diff --git a/Source/WXDialog/cmWXMainFrame.h b/Source/WXDialog/cmWXMainFrame.h new file mode 100644 index 0000000..110e081 --- /dev/null +++ b/Source/WXDialog/cmWXMainFrame.h @@ -0,0 +1,229 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __cmMainFrame__h__ +#define __cmMainFrame__h__ + +#include "cmStandardIncludes.h" + +#include "wxincludes.h" + +class cmCacheProperty; +class cmCommandLineInfo; +class cmake; +class wxButton; +class wxCheckBox; +class wxComboBox; +class wxMenu; +class wxPanel; +class wxScrolledWindow; +class wxSizer; +class wxStaticBox; +class wxStaticText; + +/** \class cmMainFrame + * \brief GUI for CMake with wxWindows toolkit + * + * The main dialog for the CMake + * + */ +class cmMainFrame : public wxFrame +{ +public: + cmMainFrame(const wxString& title, const wxSize& size); + ~cmMainFrame(); + + //! Initialize the paths and read the cache. + void Initialize(cmCommandLineInfo*); + + //! Different callbacks for events + void OnOk(wxCommandEvent& event); + void OnConfigure(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + void OnHelp(wxCommandEvent& event); + void OnBrowseSource(wxCommandEvent& event); + void OnSourceSelected(wxCommandEvent& event); + void OnBrowseBinary(wxCommandEvent& event); + void OnBinarySelected(wxCommandEvent& event); + void OnShowAdvancedValues(wxCommandEvent& event); + void OnResize(wxSizeEvent& event); + void OnPropertyChanged(wxEvent& event); + void OnRandomEvent(wxEvent& event); + void OnGeneratorSelected(wxEvent& event); + void OnPopupMenu(wxMouseEvent& event); + void OnCacheStatusBar(wxEvent& event); + void OnStatusBar(wxEvent& event); + + //! Callbacks for menu events + void OnPopupMenuIgnore(wxEvent& event); + void OnPopupMenuDelete(wxEvent& event); + void OnPopupMenuHelp(wxEvent& event); + void OnPopupMenuEntry(wxEvent& event, int idx); + + // Connect widget and event with method. + void ConnectEvent(wxWindow*, wxEventType, wxObjectEventFunction); + void ConnectEventTo(wxWindow*, wxEventType, wxObjectEventFunction); + + //! Callback for the error message. + static void MessageCallback(const char* m, const char* title, bool& nomore, void* cd); + void DisplayMessage(const char* m, const char* title, bool& nomore); + + //! Retrieve the current build directory. + const std::string& GetBuildDir() { return this->m_WhereBuild; } + +private: + //! Load cache file from m_WhereBuild and display in GUI editor + void LoadCacheFromDiskToGUI(); + + //! Save GUI values to cmCacheManager and then save to disk. + void SaveCacheFromGUI(); + + // copy from the cache manager to the cache edit list box + void FillCacheGUIFromCacheManager(); + + // copy from the list box to the cache manager + void FillCacheManagerFromCacheGUI(); + + // set the current generator + void SetGenerator(const char* generator); + + // Set the status bar binding. + void SetupStatusBarBinding(wxWindow*); + + // set the current source and binary dir + bool SetSourceDir(const char* dir); + std::string GetSourceDir(); + bool SetBinaryDir(const char* dir); + std::string GetBinaryDir(); + + void ChangeDirectoriesFromFile(const char* buffer); + + // update source and binary menus. + void UpdateSourceBuildMenus(); + + // Check wether cache is dirty. + bool IsDirty() { return !this->m_Clean; } + void ClearDirty() { this->m_Clean = true; } + + // Run the CMake + void RunCMake(bool generateProjectFiles); + + void RemoveAdvancedValues(); + void UpdateCacheValuesDisplay(); + + // Change the build directory. + void ChangeWhereSource(); + void ChangeWhereBuild(); + bool SourceDirectoryChanged(); + bool BuildDirectoryChanged(); + + // Clear the Cache + void ClearCache(); + + void RemoveCacheEntry(cmCacheProperty*); + void IgnoreCacheEntry(const char* key); + void HelpCacheEntry(const char* key, const char* help); + + void LoadFromRegistry(); + void SaveToRegistry(); + virtual void SetStatusText(const wxString& text, int number = 0); + void ResizeInternal(); + + //! Change the type of mouse cursor. Set argument to true to store + // the type. + void CursorBusy(bool s=false); + void CursorNormal(bool s=false); + + // Main panel + wxPanel* m_MainPanel; + wxSizer* m_TopMostSizer; + + // Main sizer + wxSizer* m_MainSizer; + + // Top row of main sizer + wxSizer* m_TopGrid; + + // Top line: + wxStaticText* m_TextSource; + wxComboBox* m_PathSource; + wxButton* m_BrowseSource; + + // Top line end frame: + wxSizer* m_GeneratorFrame; + wxStaticText* m_BuildFor; + wxComboBox* m_GeneratorMenu; + + // Bottom line: + wxStaticText* m_TextBinary; + wxComboBox* m_PathBinary; + wxButton* m_BrowseBinary; + wxCheckBox* m_ShowAdvancedValues; + + // Cache values: + wxStaticBox* m_CacheValuesBox; + wxSizer* m_CacheValuesFrame; + wxScrolledWindow* m_CacheValuesScroll; + wxPanel* m_CacheValuesPanel; + wxSizer* m_CacheValuesSizer; + + // Help text: + wxStaticText* m_HelpText; + + // Buttons: + wxSizer* m_BottomButtonsFrame; + wxStaticText* m_VersionText; + wxButton* m_ConfigureButton; + wxButton* m_OKButton; + wxButton* m_CancelButton; + wxButton* m_HelpButton; + + // This is set when the cache has to be updated. + bool m_Update; + + // This is to detect when cache is not valid such as when cache + // entry is removed or when some new entries are present. You have + // to rerun cmake to set valid to true. + bool m_Valid; + + // This is needed for mac, because on mac dialog has to be redrawn + // after the menu is removed. + bool m_EntryRemoved; + + std::string m_WhereSource; + std::string m_WhereBuild; + std::string m_PathToExecutable; + bool m_Clean; + bool m_BuildPathChanged; + bool m_CursorChanged; + + typedef std::map CacheMapType; + + CacheMapType* m_CacheEntries; + cmake* m_CMakeInstance; + + enum Events { + ID_MainFrame, + ID_Resize, + ID_OKButton, + ID_ConfigureButton, + ID_CancelButton, + ID_HelpButton, + ID_AdvancedValues + }; +}; + +#endif // __cmMainFrame__h__ diff --git a/Source/WXDialog/wxCMakeSetup.cxx b/Source/WXDialog/wxCMakeSetup.cxx new file mode 100644 index 0000000..6097681 --- /dev/null +++ b/Source/WXDialog/wxCMakeSetup.cxx @@ -0,0 +1,174 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +// wxCMakeSetup.cxx : implementation file +// +#include "cmSystemTools.h" +#include "cmWXCommandLineInfo.h" +#include "cmWXMainFrame.h" + +class wxCMakeSetup : public wxApp +{ +public: + virtual bool OnInit(); + virtual int OnExit(); +}; + +class testFrame : public wxFrame +{ +public: + testFrame(const wxString& title, const wxSize& size) + : wxFrame((wxFrame*)NULL, 0, title, wxDefaultPosition, size) + { + wxPanel *panel = new wxPanel(this, -1); + wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); + wxWindow *value = new wxStaticText(panel, -1, "Some label"); + sizer->Add(value, 1, wxALIGN_CENTER_VERTICAL ); + value = new wxButton(panel, -1, "Button", wxDefaultPosition, wxSize(25, 0)); + sizer->Add(value, 0, wxALIGN_RIGHT); + + panel->SetAutoLayout( TRUE ); + panel->SetSizer(sizer); + sizer->Fit(panel); + sizer->SetSizeHints(panel); + sizer->Layout(); + } +}; + +class testFrame1 : public wxFrame +{ +public: + testFrame1(const wxString& title, const wxSize& size) + : wxFrame((wxFrame*)NULL, 0, title, wxDefaultPosition, size) + { + wxPanel *panel = new wxPanel(this, -1); + panel->SetBackgroundColour(*wxRED); + wxSizer *sizer = new wxFlexGridSizer(2, 5, 5); + wxWindow *value = 0; + int cc; + for ( cc = 0; cc < 4; cc ++ ) + { + char buffer[200]; + sprintf(buffer, "Long, Long Label; this label should be " + "bigger than button %d",cc); + value = new wxStaticText(panel, -1, buffer); + sizer->Add(value, 1, wxGROW | wxALL ); + sprintf(buffer, "Button %d", cc); + value = new wxButton(panel, -1, buffer); + sizer->Add(value, 1, wxGROW | wxALL ); + } + panel->SetAutoLayout( TRUE ); + panel->SetSizer(sizer); + sizer->Fit(panel); + sizer->SetSizeHints(panel); + sizer->Layout(); + } +}; + +class testFrame2 : public wxFrame +{ +public: + testFrame2(const wxString& title, const wxSize& size) + : wxFrame((wxFrame*)NULL, 0, title, wxDefaultPosition, size) + { + wxPanel *panel = new wxPanel(this, -1); + panel->SetBackgroundColour(*wxRED); + wxTextCtrl * text = new wxTextCtrl(panel, -1, "Test", wxPoint(40, 5)); + wxButton * bt = new wxButton(panel, -1, "Test", wxPoint(-1, 5)); + } +}; + +class testFrame3 : public wxFrame +{ +public: + testFrame3(const wxString& title, const wxSize& size) + : wxFrame((wxFrame*)NULL, 0, title, wxDefaultPosition, size) + { + this->CreateStatusBar(); + this->SetSizeHints(300, 300); + wxPanel *panel = new wxPanel(this, -1); + wxSizer *sizer = new wxFlexGridSizer(2, 5, 5); + wxWindow *value = 0; + int cc; + for ( cc = 0; cc < 10; cc ++ ) + { + char buffer[200]; + sprintf(buffer, "Label %d",cc); + value = new wxStaticText(panel, -1, buffer); + sizer->Add(value, 1, wxGROW | wxALL ); + sprintf(buffer, "Button %d", cc); + value = new wxButton(panel, -1, buffer); + sizer->Add(value, 1, wxGROW | wxALL ); + value->SetClientData(this); + value->Connect(-1, wxEVT_MOTION, + (wxObjectEventFunction) &testFrame3::OnStatusBar); + } + panel->SetAutoLayout( TRUE ); + panel->SetSizer(sizer); + sizer->Fit(panel); + sizer->SetSizeHints(panel); + sizer->Layout(); + } + void OnStatusBar(wxEvent& event) + { + wxControl* eobject = static_cast(event.GetEventObject()); + testFrame3* self = static_cast(eobject->GetClientData()); + wxString str; + const char* chars = "|-\\/jg@_^"; + char ch = chars[((int)eobject)/1024 % strlen(chars)]; + int cc; + for ( cc = 0; cc < 10; cc ++ ) + { + str += ch; + } + self->SetStatusText(str); + } +}; + +bool wxCMakeSetup::OnInit() +{ + cmSystemTools::DisableRunCommandOutput(); + cmCommandLineInfo cm; + cm.SetValidArguments("ABGH"); + cm.ParseCommandLine(wxApp::argc, wxApp::argv); + + this->SetVendorName("Andy"); + this->SetAppName("CMakeSetup"); + + cmMainFrame *frame = new cmMainFrame("CMake", wxSize(200, 100)); + frame->Initialize(&cm); + //wxFrame *frame = new testFrame("CMake", wxSize(200, 100)); + //wxFrame *frame = new testFrame1("Frame", wxSize(200, 100)); + //wxFrame *frame = new testFrame2("Frame", wxSize(200, 100)); + //wxFrame *frame = new testFrame3("Frame", wxSize(200, 100)); + frame->Show(TRUE); + this->SetTopWindow(frame); + + return TRUE; +} + +int wxCMakeSetup::OnExit() +{ + // clean up: Set() returns the active config object as Get() does, but unlike + // Get() it doesn't try to create one if there is none (definitely not what + // we want here!) + //delete wxConfigBase::Set((wxConfigBase *) NULL); + + return 0; +} + +IMPLEMENT_APP(wxCMakeSetup) diff --git a/Source/WXDialog/wxincludes.h b/Source/WXDialog/wxincludes.h new file mode 100644 index 0000000..be5b4e6 --- /dev/null +++ b/Source/WXDialog/wxincludes.h @@ -0,0 +1,52 @@ +#ifdef WIN32 + +#define __WIN32 +#define _WINDOWS +#define __WINDOWS__ +#define __WXMSW__ +#define __WIN32__ +#define WINVER 0x0400 +#define STRICT + + +#include "wx/defs.h" +#include "wx/app.h" +#include "wx/button.h" +#include "wx/checkbox.h" +#include "wx/combobox.h" +#include "wx/config.h" +#include "wx/control.h" +#include "wx/dirdlg.h" +#include "wx/filedlg.h" +#include "wx/menu.h" +#include "wx/msgdlg.h" +#include "wx/scrolwin.h" +#include "wx/sizer.h" +#include "wx/statbox.h" +#include "wx/stattext.h" +#include "wx/textctrl.h" + +#pragma hdrstop("wxincludes.pch") + +#else + + +#include "wx/app.h" +#include "wx/button.h" +#include "wx/checkbox.h" +#include "wx/combobox.h" +#include "wx/config.h" +#include "wx/control.h" +#include "wx/dirdlg.h" +#include "wx/filedlg.h" +#include "wx/menu.h" +#include "wx/msgdlg.h" +#include "wx/scrolwin.h" +#include "wx/sizer.h" +#include "wx/statbox.h" +#include "wx/stattext.h" +#include "wx/textctrl.h" + +#endif + +#undef FileExists -- cgit v0.12