~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/windowattributescontroller.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: thumbnailcontroller.cpp $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-12 MetaEmotion S.L. All rights reserved.
 
7
 *  http://ginkgo-cadx.com
 
8
 *
 
9
 *  This file is licensed under LGPL v3 license.
 
10
 *  See License.txt for details
 
11
 *
 
12
 *
 
13
 */
 
14
#include <wx/toplevel.h>
 
15
#include <wx/display.h>
 
16
#include "configurationcontroller.h"
 
17
#include "windowattributescontroller.h"
 
18
 
 
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"
 
26
 
 
27
namespace GNC {
 
28
        namespace GCS {
 
29
                WindowAttributesController::WindowAttributesController()
 
30
                {               
 
31
                }
 
32
                WindowAttributesController::~WindowAttributesController()
 
33
                {                       
 
34
                }
 
35
                
 
36
                void WindowAttributesController::LoadWindowAttributes(const std::string& windowId, wxWindow* pWindow, bool defaultMaximized)
 
37
                {
 
38
                        GNC::GCS::IConfigurationController::TListGroups groups;
 
39
                        GNC::GCS::ConfigurationController::Instance()->readGroupUser(ATTRIBUTES_SCOPE, groups);
 
40
 
 
41
                        int maxX = 0, maxY = 0;
 
42
                        int deviceCount = wxDisplay::GetCount();
 
43
                        for (int i = 0; i < deviceCount; ++i) {
 
44
                                wxDisplay dsply(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());
 
47
                        }
 
48
                        
 
49
                        std::string windowIdTmp;
 
50
                        for (GNC::GCS::IConfigurationController::TListGroups::iterator it = groups.begin(); it != groups.end(); ++it)
 
51
                        {
 
52
                                (*it).readStringValue(WINDOW_ID_KEY, windowIdTmp);
 
53
                                if (windowId.compare(windowIdTmp) == 0) {
 
54
                                        wxPoint position;
 
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);
 
60
                                        }
 
61
                                        wxSize size;
 
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);
 
67
                                                if (!isMaximized) {
 
68
                                                        (*it).readIntValue(WIDTH_KEY_POSITION, size.x, -1);
 
69
                                                        (*it).readIntValue(HEIGH_KEY_POSITION, size.y, -1);
 
70
                                                }
 
71
                                        } else {
 
72
                                                (*it).readIntValue(WIDTH_KEY_POSITION, size.x, -1);
 
73
                                                (*it).readIntValue(HEIGH_KEY_POSITION, size.y, -1);
 
74
                                        }
 
75
                                        pWindow->SetSize(size);
 
76
                                }
 
77
                        }
 
78
                }
 
79
 
 
80
                void WindowAttributesController::SaveWindowAttributes(const std::string& windowId, wxWindow* pWindow)
 
81
                {
 
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)
 
86
                        {
 
87
                                (*it).readStringValue(WINDOW_ID_KEY, windowIdTmp);
 
88
                                if (windowId.compare(windowIdTmp) == 0) {
 
89
                                        groups.erase(it);
 
90
                                        break;
 
91
                                }
 
92
                        }
 
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());
 
104
                        }
 
105
                        groups.push_back(newGroup);
 
106
                        GNC::GCS::ConfigurationController::Instance()->writeGroupUser(ATTRIBUTES_SCOPE, groups);
 
107
                }
 
108
                
 
109
        }
 
110
}