diff --git a/src/cube/MainMenuController.cpp b/src/cube/MainMenuController.cpp index 7d5e2a8f2..23b29513e 100644 --- a/src/cube/MainMenuController.cpp +++ b/src/cube/MainMenuController.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,7 @@ void MainMenuController::OnMainWindowCreated(Window* window) void MainMenuController::ConnectMenuHandlers() { this->fileExit->Activated.connect(this, &MainMenuController::OnFileExit); + this->filePreferences->Activated.connect(this, &MainMenuController::OnFilePreferences); this->helpAbout->Activated.connect(this, &MainMenuController::OnHelpAbout); this->fileAddLibraryLocal->Activated.connect(this,&MainMenuController::OnAddLibraryLocal); this->fileAddLibraryRemote->Activated.connect(this,&MainMenuController::OnAddLibraryRemote); @@ -82,6 +84,16 @@ void MainMenuController::OnFileExit(MenuItemRef menuItem) Application::Instance().Terminate(); } +void MainMenuController::OnFilePreferences(MenuItemRef menuItem) +{ + win32cpp::TopLevelWindow preferencesDialog(_(_T("mC2 Preferences"))); + preferencesDialog.SetMinimumSize(Size(700, 500)); + + dialog::PreferencesController filePreferences(preferencesDialog); + + preferencesDialog.ShowModal(&this->mainWindow); +} + void MainMenuController::OnAddLibraryLocal(MenuItemRef menuItem) { win32cpp::TopLevelWindow popupDialog(_(_T("Add local library"))); @@ -111,44 +123,6 @@ void MainMenuController::OnHelpAbout(MenuItemRef menuItem) dialog::HelpAboutController helpAbout(aboutDialog); aboutDialog.ShowModal(&this->mainWindow); - - return; - - // randomize the contribuitors' names - std::vector names; - names.push_back(_T(" - avatar\n")); - names.push_back(_T(" - bjorn\n")); - names.push_back(_T(" - doep\n")); - names.push_back(_T(" - naaina\n")); - names.push_back(_T(" - Jooles\n")); - - std::random_shuffle(names.begin(), names.end()); - - uistring randomNames; - for (std::vector::iterator it = names.begin(); it != names.end(); it++) - { - randomNames += *it; - } - - uistring message = - _T("mC2 are copyright (c) mC2 Team 2007-2008\n") - _T("win32cpp are copyright (c) Casey Langen 2007-2008\n\n") - _T("Credits:\n") - _T("%1%\n") - _T("mC2 wouldn't be possible without these file projects:\n") - _T(" - tuniac (http://tuniac.sf.net)\n") - _T(" - boost (http://www.boost.org)\n") - _T(" - sqlite3 (http://www.sqlite.org)\n") - _T(" - taglib (http://developer.kde.org/~wheeler/taglib)\n\n") - _T("Version 2 developer milestone 1"); - - message = (boost::wformat(message.c_str()) % randomNames).str(); - - ::MessageBox( - this->mainWindow.Handle(), - message.c_str(), - _T("mC2 - About"), - MB_ICONINFORMATION | MB_OK); } void MainMenuController::OnNewPlaylist(MenuItemRef menuItem){ @@ -168,28 +142,30 @@ MenuRef MainMenuController::CreateMenu() this->tags = mainItems.Append(MenuItem::Create(_(_T("&Tags")))); this->help = mainItems.Append(MenuItem::Create(_(_T("&Help")))); - // file menu - this->fileMenu = Menu::Create(); - MenuItemCollection& fileItems = this->fileMenu->Items(); - // - this->file->SetSubMenu(this->fileMenu); + // file menu + this->fileMenu = Menu::Create(); + MenuItemCollection& fileItems = this->fileMenu->Items(); + // + this->file->SetSubMenu(this->fileMenu); - MenuItemRef addLibraryMenu = fileItems.Append(MenuItem::Create(_(_T("&New Library")))); - MenuRef addLibrarySubmenu = Menu::Create(); - this->fileAddLibraryLocal = addLibrarySubmenu->Items().Append(MenuItem::Create(_(_T("&Local library")))); - this->fileAddLibraryRemote = addLibrarySubmenu->Items().Append(MenuItem::Create(_(_T("&Remote library")))); - addLibraryMenu->SetSubMenu(addLibrarySubmenu); + MenuItemRef addLibraryMenu = fileItems.Append(MenuItem::Create(_(_T("&New Library")))); + MenuRef addLibrarySubmenu = Menu::Create(); + this->fileAddLibraryLocal = addLibrarySubmenu->Items().Append(MenuItem::Create(_(_T("&Local library")))); + this->fileAddLibraryRemote = addLibrarySubmenu->Items().Append(MenuItem::Create(_(_T("&Remote library")))); + addLibraryMenu->SetSubMenu(addLibrarySubmenu); - this->fileNewPlaylist = fileItems.Append(MenuItem::Create(_(_T("&New Playlist")))); + this->fileNewPlaylist = fileItems.Append(MenuItem::Create(_(_T("&New Playlist")))); - this->fileExit = fileItems.Append(MenuItem::Create(_(_T("E&xit")))); + this->filePreferences = fileItems.Append(MenuItem::Create(_(_T("&Preferences")))); - // help menu - this->helpMenu = Menu::Create(); - MenuItemCollection& helpItems = this->helpMenu->Items(); - // - this->help->SetSubMenu(this->helpMenu); - this->helpAbout = helpItems.Append(MenuItem::Create(_(_T("&About")))); + this->fileExit = fileItems.Append(MenuItem::Create(_(_T("E&xit")))); + + // help menu + this->helpMenu = Menu::Create(); + MenuItemCollection& helpItems = this->helpMenu->Items(); + // + this->help->SetSubMenu(this->helpMenu); + this->helpAbout = helpItems.Append(MenuItem::Create(_(_T("&About")))); this->ConnectMenuHandlers(); diff --git a/src/cube/MainMenuController.hpp b/src/cube/MainMenuController.hpp index 6e6021224..333e996d3 100644 --- a/src/cube/MainMenuController.hpp +++ b/src/cube/MainMenuController.hpp @@ -58,27 +58,32 @@ namespace musik { namespace cube { class MainMenuController: public EventHandler { - public: - MainMenuController(TopLevelWindow& mainWindow); - ~MainMenuController(); +public: + MainMenuController(TopLevelWindow& mainWindow); + ~MainMenuController(); - protected: - void OnMainWindowCreated(Window* window); - MenuRef CreateMenu(); - void ConnectMenuHandlers(); +protected: + void OnMainWindowCreated(Window* window); + MenuRef CreateMenu(); + void ConnectMenuHandlers(); - // - void OnFileExit(MenuItemRef menuItem); - void OnHelpAbout(MenuItemRef menuItem); - void OnAddLibraryLocal(MenuItemRef menuItem); - void OnAddLibraryRemote(MenuItemRef menuItem); - void OnNewPlaylist(MenuItemRef menuItem); + // + void OnFileExit(MenuItemRef menuItem); + void OnFilePreferences(MenuItemRef menuItem); + void OnHelpAbout(MenuItemRef menuItem); + void OnAddLibraryLocal(MenuItemRef menuItem); + void OnAddLibraryRemote(MenuItemRef menuItem); + void OnNewPlaylist(MenuItemRef menuItem); - private: - TopLevelWindow& mainWindow; - MenuRef mainMenu, fileMenu, helpMenu; - MenuItemRef file, view, audio, tags, help; - MenuItemRef fileExit, helpAbout, fileAddLibraryRemote, fileAddLibraryLocal, fileNewPlaylist; +private: + TopLevelWindow& mainWindow; + + MenuRef mainMenu; + MenuRef fileMenu, helpMenu; + + MenuItemRef file, view, audio, tags, help; + MenuItemRef fileExit, fileAddLibraryRemote, fileAddLibraryLocal, fileNewPlaylist, filePreferences; + MenuItemRef helpAbout; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/src/cube/cube.vcproj b/src/cube/cube.vcproj index db4564576..23ef34e56 100644 --- a/src/cube/cube.vcproj +++ b/src/cube/cube.vcproj @@ -514,6 +514,38 @@ > + + + + + + + + + + + + + + + + view = new HelpAboutView; this->mainWindow.AddChild(this->view); - + this->view->Created.connect(this, &HelpAboutController::OnViewCreated); // Start drawing thread diff --git a/src/cube/dialog/PreferencesCategoriesModel.cpp b/src/cube/dialog/PreferencesCategoriesModel.cpp new file mode 100644 index 000000000..ba0119cce --- /dev/null +++ b/src/cube/dialog/PreferencesCategoriesModel.cpp @@ -0,0 +1,101 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, mC2 Team +// +// Sources and Binaries of: mC2 +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#include "pch.hpp" +#include +#include + +////////////////////////////////////////////////////////////////////////////// + +using namespace musik::cube::dialog; + +////////////////////////////////////////////////////////////////////////////// + +PreferencesCategoriesModel::PreferencesCategoriesModel() +{ + // Fill category tree with data + PreferencesCategory items[] = { + /* title level identifier (for inserts etc.) */ + {_(_T("Libraries")), 0, Categories::Libraries}, + {_(_T("Client/Server")), 0, Categories::ClientServer}, + {_(_T("Audio Settings")), 0, Categories::AudioSettings}, + {_(_T("Output")), 1, Categories::AudioSettings_Output}, + {_(_T("Display")), 0, Categories::Display}, + {_(_T("Ordering")), 1, Categories::Display_Ordering}, + {_(_T("Tray settings")), 1, Categories::Display_TraySettings}, + {_(_T("Show tray icon")), 2, Categories::Display_TraySettings_ShowTrayIcon}, + {_(_T("Minimize to tray")), 2, Categories::Display_TraySettings_MinimizeToTray} + }; + + for(int i = 0; i < sizeof(items) / sizeof(PreferencesCategory); i++) { + categoryTree.push_back(items[i]); + } + +} + +int PreferencesCategoriesModel::ItemCount() +{ + return (int)categoryTree.size(); +} + +int PreferencesCategoriesModel::ItemToIndent(int index) +{ + if(index >= 0 && index < categoryTree.size()) { + return categoryTree[index].indent; + } + + return 0; +} + +uistring PreferencesCategoriesModel::ItemToString(int index) +{ + if(index >= 0 && index < categoryTree.size()) { + return categoryTree[index].title; + } + + return uistring(); +} + +LPARAM PreferencesCategoriesModel::ItemToExtendedData(int index) +{ + if(index >= 0 && index < categoryTree.size()) { + return categoryTree[index].data; + } + + return 0; +} \ No newline at end of file diff --git a/src/cube/dialog/PreferencesCategoriesModel.hpp b/src/cube/dialog/PreferencesCategoriesModel.hpp new file mode 100644 index 000000000..2eb6a163c --- /dev/null +++ b/src/cube/dialog/PreferencesCategoriesModel.hpp @@ -0,0 +1,82 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, Casey Langen, André Wösten +// +// Sources and Binaries of: mC2, win32cpp +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////// + +using namespace win32cpp; + +namespace musik { namespace cube { namespace dialog { + +////////////////////////////////////////////////////////////////////////////// +// PreferencesCategoriesModel +////////////////////////////////////////////////////////////////////////////// +class PreferencesCategoriesModel : public ComboBox::Model +{ +private: + typedef std::vector categoryTreeVector; + categoryTreeVector categoryTree; +public: + enum Categories { + Libraries = 0x1000, + ClientServer = 0x2000, + AudioSettings = 0x3000, + AudioSettings_Output, + Display = 0x4000, + Display_Ordering, + Display_TraySettings, + Display_TraySettings_ShowTrayIcon, + Display_TraySettings_MinimizeToTray + }; + + PreferencesCategoriesModel(); + + virtual int ItemCount(); + virtual int ItemToIndent(int index); + virtual uistring ItemToString(int index); + virtual LPARAM ItemToExtendedData(int index); +}; + +////////////////////////////////////////////////////////////////////////////// + +} } } // musik::cube::dialog diff --git a/src/cube/dialog/PreferencesCategory.hpp b/src/cube/dialog/PreferencesCategory.hpp new file mode 100644 index 000000000..783967adc --- /dev/null +++ b/src/cube/dialog/PreferencesCategory.hpp @@ -0,0 +1,59 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, Casey Langen, André Wösten +// +// Sources and Binaries of: mC2, win32cpp +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +////////////////////////////////////////////////////////////////////////////// + +using namespace win32cpp; + +namespace musik { namespace cube { namespace dialog { + +////////////////////////////////////////////////////////////////////////////// +// PreferencesCategory +////////////////////////////////////////////////////////////////////////////// +struct PreferencesCategory +{ + uistring title; + int indent; + LPARAM data; +}; + +////////////////////////////////////////////////////////////////////////////// + +} } } // musik::cube::dialog diff --git a/src/cube/dialog/PreferencesController.cpp b/src/cube/dialog/PreferencesController.cpp new file mode 100644 index 000000000..d124cdcc6 --- /dev/null +++ b/src/cube/dialog/PreferencesController.cpp @@ -0,0 +1,87 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, mC2 Team +// +// Sources and Binaries of: mC2, win32cpp +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#include "pch.hpp" +#include +#include +#include +#include +#include + +#include +#include + +////////////////////////////////////////////////////////////////////////////// + +using namespace musik::cube::dialog; +using namespace win32cpp; + +////////////////////////////////////////////////////////////////////////////// + +PreferencesController::PreferencesController(win32cpp::TopLevelWindow &mainWindow) +:mainWindow(mainWindow) +,view(NULL) +{ + this->view = new PreferencesView; + this->mainWindow.AddChild(this->view); + + this->mainWindow.Resized.connect(this->view, &PreferencesView::OnMainWindowResized); + + this->view->Handle() + ? this->OnViewCreated(this->view) + : this->view->Created.connect(this, &PreferencesController::OnViewCreated); +} + +PreferencesController::~PreferencesController() +{ +} + +void PreferencesController::OnViewCreated(Window* window) +{ + this->view->okButton->Pressed.connect(this, &PreferencesController::OnOK); + + this->view->categoryList->SetModel(ComboBox::ModelRef(new PreferencesCategoriesModel)); + + // registering of inner dialog templates + //this->view->categoryModel->RegisterView(PreferencesCategoriesModel::Categories::Display, +} + +void PreferencesController::OnOK(win32cpp::Button* button) +{ + this->mainWindow.Close(); +} diff --git a/src/cube/dialog/PreferencesController.hpp b/src/cube/dialog/PreferencesController.hpp new file mode 100644 index 000000000..6bb6781c9 --- /dev/null +++ b/src/cube/dialog/PreferencesController.hpp @@ -0,0 +1,74 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, mC2 Team +// +// Sources and Binaries of: mC2 +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +////////////////////////////////////////////////////////////////////////////// +// Forward declare +namespace win32cpp{ + class Window; + class Button; +} + +////////////////////////////////////////////////////////////////////////////// + +namespace musik { namespace cube { namespace dialog { + +////////////////////////////////////////////////////////////////////////////// + +class PreferencesView; // forward +////////////////////////////////////////////////////////////////////////////// + +class PreferencesController : public win32cpp::EventHandler +{ +public: + PreferencesController(win32cpp::TopLevelWindow &mainWindow); + ~PreferencesController(); + +private: + void OnViewCreated(win32cpp::Window* window); + void OnOK(win32cpp::Button* button); + + PreferencesView* view; + + win32cpp::TopLevelWindow &mainWindow; +}; + +////////////////////////////////////////////////////////////////////////////// + +} } } diff --git a/src/cube/dialog/PreferencesView.cpp b/src/cube/dialog/PreferencesView.cpp new file mode 100644 index 000000000..06b20d0b1 --- /dev/null +++ b/src/cube/dialog/PreferencesView.cpp @@ -0,0 +1,97 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright 2008, mC2 Team +// +// Sources and Binaries of: mC2, win32cpp +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#include "pch.hpp" +#include +#include +#include +#include +#include + + +////////////////////////////////////////////////////////////////////////////// + +using namespace musik::cube::dialog; +using namespace win32cpp; + +////////////////////////////////////////////////////////////////////////////// + +PreferencesView::PreferencesView() +: Frame(NULL,FramePadding(5)) +{ +} + +void PreferencesView::OnCreated() +{ + // Main Layout: + // - Row 1: ColumnLayout with CategoryList and Dialog + // - Row 2: ColumnLayout with Buttons to cancel and apply + this->mainLayout = new LinearLayout(LinearRowLayout); + this->mainLayout->SetDefaultChildFill(true); + this->mainLayout->SetSizeConstraints(LayoutFillParent, LayoutFillParent); + { + // Row 1 + LinearLayout* settingsLayout = new LinearLayout(LinearColumnLayout); + { + this->categoryList = new ComboBox(ComboBox::DisplayType_Simple); + + settingsLayout->AddChild(this->categoryList); + settingsLayout->SetFlexibleChild(this->categoryList); + settingsLayout->SetDefaultChildFill(true); + settingsLayout->SetSizeConstraints(LayoutFillParent, LayoutFillParent); + } + this->mainLayout->AddChild(settingsLayout); + this->mainLayout->SetFlexibleChild(settingsLayout); + + // Row 2 + LinearLayout* buttonLayout = new LinearLayout(LinearColumnLayout); + buttonLayout->SetDefaultChildFill(true); + { + this->okButton = buttonLayout->AddChild(new Button(_T("OK"))); + this->cancelButton = buttonLayout->AddChild(new Button(_T("Cancel"))); + } + this->mainLayout->AddChild(buttonLayout); + this->mainLayout->SetChildAlignment(buttonLayout, ChildAlignRight); + } + this->AddChild(this->mainLayout); +} + +void PreferencesView::OnMainWindowResized(Window* window, win32cpp::Size newSize) +{ + this->Resize(newSize); +} \ No newline at end of file diff --git a/src/cube/dialog/PreferencesView.hpp b/src/cube/dialog/PreferencesView.hpp new file mode 100644 index 000000000..0937fb568 --- /dev/null +++ b/src/cube/dialog/PreferencesView.hpp @@ -0,0 +1,88 @@ +////////////////////////////////////////////////////////////////////////////// +// +// License Agreement: +// +// The following are Copyright © 2008, mC2 Team +// +// Sources and Binaries of: mC2, win32cpp +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// +#pragma once + +////////////////////////////////////////////////////////////////////////////// +// Forward declare +namespace win32cpp{ + class Button; + class Frame; + class ComboBox; +} +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////// + +using namespace win32cpp; + +namespace musik { namespace cube { namespace dialog { + +////////////////////////////////////////////////////////////////////////////// +// forward +class PreferencesController; +////////////////////////////////////////////////////////////////////////////// + +class PreferencesView: public Frame { +private: + typedef Frame base; + + Button* okButton; + Button* cancelButton; + ComboBox* categoryList; + LinearLayout* mainLayout; + +public: + PreferencesView(); + + virtual void OnCreated(); + virtual void OnMainWindowResized(Window* window, Size newSize); + + ComboBox::ModelRef categoryModel; + + friend class PreferencesController; +}; + +////////////////////////////////////////////////////////////////////////////// + +} } } + diff --git a/src/win32cpp/ComboBox.cpp b/src/win32cpp/ComboBox.cpp index 512d4e8bf..b465a5248 100644 --- a/src/win32cpp/ComboBox.cpp +++ b/src/win32cpp/ComboBox.cpp @@ -43,10 +43,15 @@ using namespace win32cpp; +const LPCWSTR ComboBox::BoxType_Standard = WC_COMBOBOX; +const LPCWSTR ComboBox::BoxType_Extended = WC_COMBOBOXEX; + ComboBox::ModelRef ComboBox::sNullModel(new ComboBox::NullModel()); -ComboBox::ComboBox() : -model(ComboBox::sNullModel) +ComboBox::ComboBox(DisplayType displayType, LPCWSTR boxType) : +model(ComboBox::sNullModel), +displayType(displayType), +boxType(boxType) { } @@ -70,12 +75,12 @@ HWND ComboBox::Create(Window* parent) * must be adapted to a send/retrieve behaviour or we must implement a * callback behaviour with CBEN_GETDISPINFO. (as it is in the ListView) */ - DWORD style = WS_CHILD | WS_VISIBLE | WS_BORDER | CBS_DROPDOWNLIST; + DWORD style = WS_CHILD | WS_VISIBLE | WS_BORDER | displayType; // Create the ComboBox HWND hwnd = CreateWindowEx( NULL, // ExStyle - WC_COMBOBOXEX, // Class name + boxType, // Class name _T(""), // Window name style, // Style 0, // X @@ -90,6 +95,10 @@ HWND ComboBox::Create(Window* parent) return hwnd; } +bool ComboBox::Info(PCOMBOBOXINFO pcbi) +{ + return !!(::GetComboBoxInfo(this->windowHandle, pcbi)); +} void ComboBox::SetModel(ModelRef model) { diff --git a/src/win32cpp/ComboBox.hpp b/src/win32cpp/ComboBox.hpp index fd67c0750..9b0adc945 100644 --- a/src/win32cpp/ComboBox.hpp +++ b/src/win32cpp/ComboBox.hpp @@ -57,20 +57,32 @@ namespace win32cpp { // ComboBox ////////////////////////////////////////////////////////////////////////////// -class ComboBox : public Window + class ComboBox : public Window { public: + enum DisplayType { + DisplayType_Simple = CBS_SIMPLE, + DisplayType_DropDownList = CBS_DROPDOWNLIST + }; + + static const LPCWSTR BoxType_Standard; + static const LPCWSTR BoxType_Extended; + class Model; typedef boost::shared_ptr ModelRef; typedef sigslot::signal1 SelectionChangedEvent; - ComboBox(); + ComboBox( + DisplayType displayType = DisplayType_DropDownList, + LPCWSTR boxType = BoxType_Extended + ); ~ComboBox(); void SetModel(ModelRef model); int Selected(); void Select(int index); + bool Info(PCOMBOBOXINFO pcbi); protected: ModelRef model; @@ -82,6 +94,8 @@ protected: private: typedef Window base; class NullModel; + DisplayType displayType; + LPCWSTR boxType; }; ////////////////////////////////////////////////////////////////////////////// @@ -112,8 +126,12 @@ public: return NULL; } + virtual int ItemToImageListIndex(int index) + { + return -1; + } + virtual uistring ItemToString(int index) = 0; - virtual int ItemToImageListIndex(int index) = 0; virtual int ItemToIndent(int index) = 0; virtual LPARAM ItemToExtendedData(int index) = 0; }; diff --git a/src/win32cpp/Frame.cpp b/src/win32cpp/Frame.cpp index ab86ecd8e..664130a02 100644 --- a/src/win32cpp/Frame.cpp +++ b/src/win32cpp/Frame.cpp @@ -135,7 +135,9 @@ void Frame::OnResized(const Size& newSize) { if (this->child && (! isResizingHACK)) { - this->child->Resize(this->ClientSize()); + Size size = this->ClientSize(); + + this->child->Resize(size); this->child->MoveTo(0, 0); } } @@ -154,10 +156,10 @@ void Frame::OnChildResized(Window* window, Size newSize) void Frame::ResizeFromChild() { Size size = this->child->WindowSize(); - - size.width += (this->padding.left + this->padding.right); - size.height += (this->padding.top + this->padding.bottom); - // + + size.width += (this->padding.left + this->padding.right); + size.height += (this->padding.top + this->padding.bottom); + this->isResizingHACK = true; this->Resize(size); this->isResizingHACK = false; @@ -208,4 +210,3 @@ LRESULT Frame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) return base::WindowProc(message, wParam, lParam); } - diff --git a/src/win32cpp/Frame.hpp b/src/win32cpp/Frame.hpp index 2afd5f5e8..088f74576 100644 --- a/src/win32cpp/Frame.hpp +++ b/src/win32cpp/Frame.hpp @@ -142,8 +142,10 @@ protected: // methods virtual void OnResized(const Size& newSize); virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); -private: // instance data +protected: // instance data FramePadding padding; + +private: // instance data Window* child; bool isResizingHACK; }; diff --git a/src/win32cpp/Window.cpp b/src/win32cpp/Window.cpp index 9bf986168..cc806c418 100644 --- a/src/win32cpp/Window.cpp +++ b/src/win32cpp/Window.cpp @@ -795,7 +795,7 @@ bool Window::Resize(const Size& size) } return (result == TRUE); - } + } return false; }