3
* $Id: thumbnailcontroller.cpp $
6
* Copyright 2008-12 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
14
#include <wx/toplevel.h>
15
#include <wx/display.h>
16
#include "configurationcontroller.h"
17
#include "windowattributescontroller.h"
19
#define ATTRIBUTES_SCOPE "/GinkgoCore/WindowAttributes"
20
#define WINDOW_ID_KEY "windowId"
21
#define X_KEY_POSITION "xPos"
22
#define Y_KEY_POSITION "yPos"
23
#define WIDTH_KEY_POSITION "width"
24
#define HEIGH_KEY_POSITION "heigh"
25
#define IS_MAXIMIZED_KEY "isMaximized"
29
WindowAttributesController::WindowAttributesController()
32
WindowAttributesController::~WindowAttributesController()
36
void WindowAttributesController::LoadWindowAttributes(const std::string& windowId, wxWindow* pWindow, bool defaultMaximized)
38
GNC::GCS::IConfigurationController::TListGroups groups;
39
GNC::GCS::ConfigurationController::Instance()->readGroupUser(ATTRIBUTES_SCOPE, groups);
41
int maxX = 0, maxY = 0;
42
int deviceCount = wxDisplay::GetCount();
43
for (int i = 0; i < deviceCount; ++i) {
45
maxX = std::max<int>(maxX, dsply.GetClientArea().x + dsply.GetCurrentMode().GetWidth());
46
maxY = std::max<int>(maxY, dsply.GetClientArea().y + dsply.GetCurrentMode().GetHeight());
49
std::string windowIdTmp;
50
for (GNC::GCS::IConfigurationController::TListGroups::iterator it = groups.begin(); it != groups.end(); ++it)
52
(*it).readStringValue(WINDOW_ID_KEY, windowIdTmp);
53
if (windowId.compare(windowIdTmp) == 0) {
55
(*it).readIntValue(X_KEY_POSITION, position.x, -1);
56
(*it).readIntValue(Y_KEY_POSITION, position.y, -1);
57
if (position.x > -50 && position.x < maxX
58
&& position.y > -50 && position.y < maxY) {
59
pWindow->SetPosition(position);
62
wxTopLevelWindow* pTopLevel = dynamic_cast<wxTopLevelWindow*>(pWindow);
63
if (pTopLevel != NULL) {
64
bool isMaximized = defaultMaximized;
65
(*it).readBoolValue(IS_MAXIMIZED_KEY, isMaximized);
66
pTopLevel->Maximize(isMaximized);
68
(*it).readIntValue(WIDTH_KEY_POSITION, size.x, -1);
69
(*it).readIntValue(HEIGH_KEY_POSITION, size.y, -1);
72
(*it).readIntValue(WIDTH_KEY_POSITION, size.x, -1);
73
(*it).readIntValue(HEIGH_KEY_POSITION, size.y, -1);
75
pWindow->SetSize(size);
80
void WindowAttributesController::SaveWindowAttributes(const std::string& windowId, wxWindow* pWindow)
82
GNC::GCS::IConfigurationController::TListGroups groups;
83
GNC::GCS::ConfigurationController::Instance()->readGroupUser(ATTRIBUTES_SCOPE, groups);
84
std::string windowIdTmp;
85
for (GNC::GCS::IConfigurationController::TListGroups::iterator it = groups.begin(); it != groups.end(); ++it)
87
(*it).readStringValue(WINDOW_ID_KEY, windowIdTmp);
88
if (windowId.compare(windowIdTmp) == 0) {
93
GNC::GCS::ConfigurationController::TMapValues newGroup;
94
newGroup[WINDOW_ID_KEY] = windowId;
95
wxPoint position = pWindow->GetPosition();
96
newGroup.insertInt(X_KEY_POSITION,position.x);
97
newGroup.insertInt(Y_KEY_POSITION,position.y);
98
wxSize size = pWindow->GetSize();
99
newGroup.insertInt(WIDTH_KEY_POSITION,size.x);
100
newGroup.insertInt(HEIGH_KEY_POSITION,size.y);
101
wxTopLevelWindow* pTopLevel = dynamic_cast<wxTopLevelWindow*>(pWindow);
102
if (pTopLevel != NULL) {
103
newGroup.insertBool(IS_MAXIMIZED_KEY, pTopLevel->IsMaximized());
105
groups.push_back(newGroup);
106
GNC::GCS::ConfigurationController::Instance()->writeGroupUser(ATTRIBUTES_SCOPE, groups);