summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-12-19 18:16:01 (GMT)
committerfluxgen <fluxgen>2003-12-19 18:16:01 (GMT)
commita88e5e57c1ef990b2b7d60a71b31ab2fe3d590a5 (patch)
treec6a5662c902ad9fd549f84db69d41afe08859a2c /src
parent7287a0f11e4fe4fe95dbc063dc3a8524463bfa06 (diff)
downloadfluxbox_lack-a88e5e57c1ef990b2b7d60a71b31ab2fe3d590a5.zip
fluxbox_lack-a88e5e57c1ef990b2b7d60a71b31ab2fe3d590a5.tar.bz2
added post command and fixed correct font
Diffstat (limited to 'src')
-rw-r--r--src/CommandDialog.cc69
1 files changed, 47 insertions, 22 deletions
diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc
index 4396fde..47aeddd 100644
--- a/src/CommandDialog.cc
+++ b/src/CommandDialog.cc
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: CommandDialog.cc,v 1.1 2003/12/19 03:53:21 fluxgen Exp $ 23// $Id: CommandDialog.cc,v 1.2 2003/12/19 18:16:01 fluxgen Exp $
24 24
25#include "CommandDialog.hh" 25#include "CommandDialog.hh"
26 26
@@ -41,15 +41,12 @@
41#include <memory> 41#include <memory>
42using namespace std; 42using namespace std;
43 43
44//!!
45//!! TODO: Fix so it uses the same font as in the theme
46//!!
47CommandDialog::CommandDialog(BScreen &screen, const std::string &title): 44CommandDialog::CommandDialog(BScreen &screen, const std::string &title):
48 FbWindow(screen.rootWindow().screenNumber(), 45 FbWindow(screen.rootWindow().screenNumber(),
49 0, 0, 1, 1, 0), 46 0, 0, 200, 1, ExposureMask),
50 m_font("fixed"), 47 m_font("fixed"),
51 m_textbox(*this, m_font, ""), 48 m_textbox(*this, m_font, ""),
52 m_label(*this, m_font, title), 49 m_label(*this, screen.winFrameTheme().font(), title),
53 m_gc(m_textbox), 50 m_gc(m_textbox),
54 m_screen(screen), 51 m_screen(screen),
55 m_move_x(0), 52 m_move_x(0),
@@ -58,12 +55,13 @@ CommandDialog::CommandDialog(BScreen &screen, const std::string &title):
58 init(); 55 init();
59 56
60} 57}
58
61CommandDialog::CommandDialog(BScreen &screen, const std::string &title, const std::string &precommand): 59CommandDialog::CommandDialog(BScreen &screen, const std::string &title, const std::string &precommand):
62 FbWindow(screen.rootWindow().screenNumber(), 60 FbWindow(screen.rootWindow().screenNumber(),
63 0, 0, 1, 1, 0), 61 0, 0, 200, 1, ExposureMask),
64 m_font("fixed"), 62 m_font("fixed"),
65 m_textbox(*this, m_font, ""), 63 m_textbox(*this, m_font, ""),
66 m_label(*this, m_font, title), 64 m_label(*this, screen.winFrameTheme().font(), title),
67 m_gc(m_textbox), 65 m_gc(m_textbox),
68 m_screen(screen), 66 m_screen(screen),
69 m_move_x(0), 67 m_move_x(0),
@@ -88,8 +86,17 @@ void CommandDialog::setText(const std::string &text) {
88void CommandDialog::show() { 86void CommandDialog::show() {
89 FbTk::FbWindow::show(); 87 FbTk::FbWindow::show();
90 m_textbox.setInputFocus(); 88 m_textbox.setInputFocus();
91 m_textbox.clear();
92 m_label.clear(); 89 m_label.clear();
90 // resize to correct width, which should be the width of label text
91 // no need to truncate label text in this dialog
92 // but if label text size < 200 we set 200
93 if (m_label.textWidth() < 200)
94 return;
95 else {
96 resize(m_label.textWidth(), height());
97 updateSizes();
98 render();
99 }
93} 100}
94 101
95void CommandDialog::hide() { 102void CommandDialog::hide() {
@@ -102,6 +109,11 @@ void CommandDialog::hide() {
102 109
103} 110}
104 111
112void CommandDialog::exposeEvent(XExposeEvent &event) {
113 if (event.window == window())
114 clearArea(event.x, event.y, event.width, event.height);
115}
116
105void CommandDialog::buttonPressEvent(XButtonEvent &event) { 117void CommandDialog::buttonPressEvent(XButtonEvent &event) {
106 m_textbox.setInputFocus(); 118 m_textbox.setInputFocus();
107 m_move_x = event.x_root - x(); 119 m_move_x = event.x_root - x();
@@ -131,11 +143,16 @@ void CommandDialog::keyPressEvent(XKeyEvent &event) {
131 XLookupString(&event, keychar, 1, &ks, 0); 143 XLookupString(&event, keychar, 1, &ks, 0);
132 144
133 if (ks == XK_Return) { 145 if (ks == XK_Return) {
146 hide(); // hide and return focus to a FluxboxWindow
134 // create command from line 147 // create command from line
135 std::auto_ptr<FbTk::Command> cmd(CommandParser::instance(). 148 std::auto_ptr<FbTk::Command> cmd(CommandParser::instance().
136 parseLine(m_precommand + m_textbox.text())); 149 parseLine(m_precommand + m_textbox.text()));
137 if (cmd.get()) 150 if (cmd.get())
138 cmd->execute(); 151 cmd->execute();
152 // post execute
153 if (*m_postcommand != 0)
154 m_postcommand->execute();
155
139 delete this; // end this 156 delete this; // end this
140 } else if (ks == XK_Escape) 157 } else if (ks == XK_Escape)
141 delete this; // end this 158 delete this; // end this
@@ -159,32 +176,40 @@ void CommandDialog::render() {
159 176
160void CommandDialog::init() { 177void CommandDialog::init() {
161 178
162 m_label.moveResize(0, 0, 179
163 200, m_font.height() + 2); 180 // setup label
164 // we listen to motion notify too 181 // we listen to motion notify too
165 m_label.setEventMask(m_label.eventMask() | ButtonPressMask | ButtonMotionMask); 182 m_label.setEventMask(m_label.eventMask() | ButtonPressMask | ButtonMotionMask);
166
167 m_label.setGC(m_screen.winFrameTheme().labelTextFocusGC()); 183 m_label.setGC(m_screen.winFrameTheme().labelTextFocusGC());
168 render();
169 m_label.show(); 184 m_label.show();
170 185
171 m_textbox.setBackgroundColor(FbTk::Color("white", m_textbox.screenNumber())); 186 // setup text box
172 187 FbTk::Color white("white", m_textbox.screenNumber());
188 m_textbox.setBackgroundColor(white);
173 FbTk::Color black("black", m_textbox.screenNumber()); 189 FbTk::Color black("black", m_textbox.screenNumber());
174 m_gc.setForeground(black); 190 m_gc.setForeground(black);
175
176 m_textbox.setGC(m_gc.gc()); 191 m_textbox.setGC(m_gc.gc());
177
178 m_textbox.moveResize(0, m_label.height(),
179 200, m_font.height() + 2);
180 m_textbox.show(); 192 m_textbox.show();
181 193
182 resize(200, m_textbox.height() + m_label.height()); 194 // setup this window
183 195 setBorderWidth(1);
184 196 setBackgroundColor(white);
185 // move to center of the screen 197 // move to center of the screen
186 move((m_screen.width() - width())/2, (m_screen.height() - height())/2); 198 move((m_screen.width() - width())/2, (m_screen.height() - height())/2);
187 199
200 updateSizes();
201 resize(width(), m_textbox.height() + m_label.height());
202
203 render();
204
188 // we need ConfigureNotify from children 205 // we need ConfigureNotify from children
189 FbTk::EventManager::instance()->addParent(*this, *this); 206 FbTk::EventManager::instance()->addParent(*this, *this);
190} 207}
208
209void CommandDialog::updateSizes() {
210 m_label.moveResize(0, 0,
211 width(), m_font.height() + 2);
212
213 m_textbox.moveResize(2, m_label.height(),
214 width() - 4, m_font.height() + 2);
215}