OpenASIP
2.0
src
applibs
wxToolkit
WidgetTools.cc
Go to the documentation of this file.
1
/*
2
Copyright (c) 2002-2009 Tampere University.
3
4
This file is part of TTA-Based Codesign Environment (TCE).
5
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
23
*/
24
/**
25
* @file WidgetTools.cc
26
*
27
* Implementation of the WidgetTools class.
28
*
29
* @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30
*/
31
32
#include <wx/wx.h>
33
#include <wx/listctrl.h>
34
#include <boost/format.hpp>
35
#include <string>
36
37
#include "
WidgetTools.hh
"
38
#include "
WxConversion.hh
"
39
#include "
TextGenerator.hh
"
40
41
using
std::string;
42
using
boost::format;
43
44
/**
45
* Sets a wxControl label text.
46
*
47
* @param widget Widget to set the label to.
48
* @param textId Enumerated ID which identifies the text label.
49
* @exception WrongSubclass If the widget was not a wxControl.
50
*/
51
void
52
WidgetTools::setWidgetLabel
(wxWindow* widget,
string
text) {
53
// wxControls
54
if
(widget->IsKindOf(CLASSINFO(wxControl))) {
55
wxControl* control =
dynamic_cast<
wxControl*
>
(widget);
56
assert
(widget != NULL);
57
wxString label =
WxConversion::toWxString
(text);
58
control->SetLabel(label);
59
return
;
60
}
61
62
63
string
method =
"GUITextGenerator::setWidgetLabel()"
;
64
string
message =
"Widget is not a wxControl, "
;
65
message +=
"unable to set the widget label."
;
66
throw
WrongSubclass
(__FILE__, __LINE__, method, message);
67
}
68
69
/**
70
* Sets a boxsizer label text.
71
*
72
* @param sizer wxStaticBoxSizer to set the label to.
73
* @param textId Enumerated ID which identifies the text label.
74
*/
75
void
76
WidgetTools::setWidgetLabel
(
77
wxStaticBoxSizer* sizer,
string
text) {
78
wxControl* box = sizer->GetStaticBox();
79
wxString label =
WxConversion::toWxString
(text);
80
box->SetLabel(label);
81
}
82
83
84
/**
85
* Sets a widget label text.
86
*
87
* @param generator TextGenerator which provides the label text.
88
* @param widget Widget to set the label to.
89
* @param textID Text generator string ID for the label text.
90
*/
91
void
92
WidgetTools::setLabel
(
Texts::TextGenerator
* generator, wxWindow* widget,
93
int
textID) {
94
95
format fmt = generator->
text
(textID);
96
setWidgetLabel
(widget, fmt.str());
97
}
98
99
100
/**
101
* Returns wxListCtrl's first selected item as a string.
102
*
103
* @param list List to search for selected item.
104
* @param column Column of the string to return.
105
* @return Selected list item string, or empty string if no item is selected.
106
*/
107
std::string
108
WidgetTools::lcStringSelection
(wxListCtrl* list,
int
column) {
109
110
long
item = -1;
111
item = list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
112
113
if
(item == -1) {
114
return
""
;
115
}
116
117
wxListItem info;
118
info.SetId(item);
119
info.SetColumn(column);
120
list->GetItem(info);
121
122
return
WxConversion::toString
(info.GetText());
123
}
WxConversion::toWxString
static wxString toWxString(const std::string &source)
WidgetTools::setLabel
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
Definition:
WidgetTools.cc:92
WidgetTools.hh
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition:
TextGenerator.cc:94
assert
#define assert(condition)
Definition:
Application.hh:86
WrongSubclass
Definition:
Exception.hh:336
WidgetTools::lcStringSelection
static std::string lcStringSelection(wxListCtrl *list, int column)
Definition:
WidgetTools.cc:108
Texts::TextGenerator
Definition:
TextGenerator.hh:79
TextGenerator.hh
WxConversion.hh
WidgetTools::setWidgetLabel
static void setWidgetLabel(wxWindow *widget, std::string text)
Definition:
WidgetTools.cc:52
WxConversion::toString
static std::string toString(const wxString &source)
Generated by
1.8.17