File: windowstack.cpp

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (178 lines) | stat: -rw-r--r-- 4,303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : windowstack.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
 #include "windowstack.h"

WindowStack::WindowStack(wxWindow *parent, wxWindowID id)
: wxPanel(parent, id)
, m_selection(NULL)
{
	m_mainSizer = new wxBoxSizer(wxVERTICAL);
	SetSizer(m_mainSizer);
	m_windows.clear();
}

WindowStack::~WindowStack()
{
	Clear();
}

void WindowStack::DoSelect(wxWindow *win, const wxString &key)
{
    Freeze();
    //remove the old selection
    if(m_selection){
        m_mainSizer->Detach(m_selection);
        m_selection->Hide();
    }
    if (win) {
        m_mainSizer->Add(win, 1, wxEXPAND);
        win->Show();
        m_selection = win;
        m_selectionKey = key;
    } else {
        m_selection = NULL;
        m_selectionKey.Clear();
    }
    m_mainSizer->Layout();
    Thaw();
}

void WindowStack::Add(wxWindow *win, const wxString &key)
{
	if(!win || key.IsEmpty()){
		return;
	}

	//add the new item to the map
	m_windows[key] = win;
	win->Hide();
}

void WindowStack::Select(const wxString &key)
{
    wxWindow *win = Find(key);
    if (win) {
        DoSelect(win, key);
    }
}

void WindowStack::Select(wxWindow* win)
{
    wxString key = Find(win);
    if (!key.IsEmpty()) {
        DoSelect(win, key);
    }
}

void WindowStack::SelectNone()
{
    DoSelect(NULL, wxEmptyString);
}

void WindowStack::Clear()
{
    SelectNone();
    m_selection = NULL;
    m_selectionKey.Clear();

	std::map<wxString,wxWindow*>::iterator iter = m_windows.begin();
	for (; iter != m_windows.end(); iter++) {
        iter->second->Destroy();
    }
    m_windows.clear();
}

wxWindow* WindowStack::Remove(const wxString &key)
{
    std::map<wxString, wxWindow*>::iterator iter = m_windows.find(key);
    if(iter == m_windows.end()){
	return NULL;
    }

    wxWindow *win = iter->second;
    if(!win){
        return NULL;
    }

    if (m_selection == win) {
        SelectNone();
    }

    m_windows.erase(iter);

    return win;
}

wxString WindowStack::Remove(wxWindow* win)
{
    wxString key = Find(win);
    if (!key.IsEmpty()) {
        Remove(key);
    }
    return key;
}

void WindowStack::Delete(const wxString &key)
{
    wxWindow *win = Remove(key);
    if (win) {
        win->Destroy();
    }
}

void WindowStack::Delete(wxWindow *win)
{
    wxString key = Remove(win);
    if (!key.IsEmpty()) {
        win->Destroy();
    }
}

wxWindow *WindowStack::Find(const wxString &key)
{
	std::map<wxString, wxWindow*>::iterator iter = m_windows.find(key);
	if(iter == m_windows.end()){
		return NULL;
	}
	return iter->second;
}

wxString WindowStack::Find(wxWindow *win)
{
    for (std::map<wxString,wxWindow*>::iterator iter = m_windows.begin();
            iter != m_windows.end(); iter++) {
        if (iter->second == win)
            return iter->first;
    }
    return wxEmptyString;
}

void WindowStack::GetKeys(std::vector<wxString> &keys) const
{
    for (std::map<wxString,wxWindow*>::const_iterator iter = m_windows.begin();
            iter != m_windows.end(); iter++) {
        keys.push_back(iter->first);
    }
}