- Checkin of first version of preferences

- Fixed some ComboBox-related thiongs
This commit is contained in:
andre@woesten.com 2008-11-07 21:50:48 +00:00
parent 3dbfe2f82e
commit 2cf99985a4
16 changed files with 721 additions and 90 deletions

View File

@ -42,6 +42,7 @@
#include <cube/MainMenuController.hpp>
#include <cube/dialog/AddLibraryController.hpp>
#include <cube/dialog/HelpAboutController.hpp>
#include <cube/dialog/PreferencesController.hpp>
#include <win32cpp/Application.hpp>
#include <win32cpp/TopLevelWindow.hpp>
#include <boost/format.hpp>
@ -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<uistring> 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<uistring>::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();

View File

@ -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;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -514,6 +514,38 @@
>
</File>
</Filter>
<Filter
Name="Preferences"
>
<File
RelativePath=".\dialog\PreferencesCategoriesModel.cpp"
>
</File>
<File
RelativePath=".\dialog\PreferencesCategoriesModel.hpp"
>
</File>
<File
RelativePath=".\dialog\PreferencesCategory.hpp"
>
</File>
<File
RelativePath=".\dialog\PreferencesController.cpp"
>
</File>
<File
RelativePath=".\dialog\PreferencesController.hpp"
>
</File>
<File
RelativePath=".\dialog\PreferencesView.cpp"
>
</File>
<File
RelativePath=".\dialog\PreferencesView.hpp"
>
</File>
</Filter>
</Filter>
<File
RelativePath=".\main.cpp"

View File

@ -60,7 +60,7 @@ HelpAboutController::HelpAboutController(win32cpp::TopLevelWindow &mainWindow)
{
this->view = new HelpAboutView;
this->mainWindow.AddChild(this->view);
this->view->Created.connect(this, &HelpAboutController::OnViewCreated);
// Start drawing thread

View File

@ -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 <win32cpp/ApplicationThread.hpp>
#include <cube/dialog/PreferencesCategoriesModel.hpp>
//////////////////////////////////////////////////////////////////////////////
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;
}

View File

@ -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 <win32cpp/ComboBox.hpp>
#include <cube/dialog/PreferencesCategory.hpp>
#include <vector>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
namespace musik { namespace cube { namespace dialog {
//////////////////////////////////////////////////////////////////////////////
// PreferencesCategoriesModel
//////////////////////////////////////////////////////////////////////////////
class PreferencesCategoriesModel : public ComboBox::Model
{
private:
typedef std::vector<PreferencesCategory> 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

View File

@ -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

View File

@ -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 <core/LibraryFactory.h>
#include <core/Preferences.h>
#include <cube/dialog/PreferencesController.hpp>
#include <cube/dialog/PreferencesView.hpp>
#include <cube/dialog/PreferencesCategoriesModel.hpp>
#include <win32cpp/Window.hpp>
#include <win32cpp/Button.hpp>
//////////////////////////////////////////////////////////////////////////////
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();
}

View File

@ -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;
};
//////////////////////////////////////////////////////////////////////////////
} } }

View File

@ -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 <core/Common.h>
#include <cube/dialog/PreferencesView.hpp>
#include <cube/dialog/PreferencesCategoriesModel.hpp>
#include <win32cpp/Button.hpp>
#include <win32cpp/LinearLayout.hpp>
//////////////////////////////////////////////////////////////////////////////
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);
}

View File

@ -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 <win32cpp/Frame.hpp>
#include <win32cpp/Button.hpp>
#include <win32cpp/ComboBox.hpp>
#include <win32cpp/LinearLayout.hpp>
//////////////////////////////////////////////////////////////////////////////
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;
};
//////////////////////////////////////////////////////////////////////////////
} } }

View File

@ -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)
{

View File

@ -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<Model> ModelRef;
typedef sigslot::signal1<ComboBox*> 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;
};

View File

@ -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);
}

View File

@ -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;
};

View File

@ -795,7 +795,7 @@ bool Window::Resize(const Size& size)
}
return (result == TRUE);
}
}
return false;
}