summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CommandDialog.cc190
-rw-r--r--src/CommandDialog.hh68
2 files changed, 258 insertions, 0 deletions
diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc
new file mode 100644
index 0000000..4396fde
--- /dev/null
+++ b/src/CommandDialog.cc
@@ -0,0 +1,190 @@
1// CommandDialog.cc for Fluxbox
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: CommandDialog.cc,v 1.1 2003/12/19 03:53:21 fluxgen Exp $
24
25#include "CommandDialog.hh"
26
27#include "Screen.hh"
28#include "FbWinFrameTheme.hh"
29#include "WinClient.hh"
30#include "CommandParser.hh"
31#include "fluxbox.hh"
32
33#include "FbTk/ImageControl.hh"
34#include "FbTk/EventManager.hh"
35#include "FbTk/App.hh"
36
37#include <X11/keysym.h>
38#include <X11/Xutil.h>
39
40#include <iostream>
41#include <memory>
42using namespace std;
43
44//!!
45//!! TODO: Fix so it uses the same font as in the theme
46//!!
47CommandDialog::CommandDialog(BScreen &screen, const std::string &title):
48 FbWindow(screen.rootWindow().screenNumber(),
49 0, 0, 1, 1, 0),
50 m_font("fixed"),
51 m_textbox(*this, m_font, ""),
52 m_label(*this, m_font, title),
53 m_gc(m_textbox),
54 m_screen(screen),
55 m_move_x(0),
56 m_move_y(0),
57 m_pixmap(0) {
58 init();
59
60}
61CommandDialog::CommandDialog(BScreen &screen, const std::string &title, const std::string &precommand):
62 FbWindow(screen.rootWindow().screenNumber(),
63 0, 0, 1, 1, 0),
64 m_font("fixed"),
65 m_textbox(*this, m_font, ""),
66 m_label(*this, m_font, title),
67 m_gc(m_textbox),
68 m_screen(screen),
69 m_move_x(0),
70 m_move_y(0),
71 m_pixmap(0),
72 m_precommand(precommand) {
73 init();
74
75}
76
77CommandDialog::~CommandDialog() {
78 FbTk::EventManager::instance()->remove(*this);
79 hide();
80 if (m_pixmap != 0)
81 m_screen.imageControl().removeImage(m_pixmap);
82}
83
84void CommandDialog::setText(const std::string &text) {
85 m_textbox.setText(text);
86}
87
88void CommandDialog::show() {
89 FbTk::FbWindow::show();
90 m_textbox.setInputFocus();
91 m_textbox.clear();
92 m_label.clear();
93}
94
95void CommandDialog::hide() {
96 FbTk::FbWindow::hide();
97
98 // return focus to fluxbox window
99 if (Fluxbox::instance()->getFocusedWindow() &&
100 Fluxbox::instance()->getFocusedWindow()->fbwindow())
101 Fluxbox::instance()->getFocusedWindow()->fbwindow()->setInputFocus();
102
103}
104
105void CommandDialog::buttonPressEvent(XButtonEvent &event) {
106 m_textbox.setInputFocus();
107 m_move_x = event.x_root - x();
108 m_move_y = event.y_root - y();
109}
110
111void CommandDialog::handleEvent(XEvent &event) {
112 if (event.type == ConfigureNotify && event.xconfigure.window != window()) {
113 moveResize(event.xconfigure.x, event.xconfigure.y,
114 event.xconfigure.width, event.xconfigure.height);
115 } else if (event.type == DestroyNotify)
116 delete this;
117}
118
119void CommandDialog::motionNotifyEvent(XMotionEvent &event) {
120 int new_x = event.x_root - m_move_x;
121 int new_y = event.y_root - m_move_y;
122 move(new_x, new_y);
123}
124
125void CommandDialog::keyPressEvent(XKeyEvent &event) {
126 if (event.state)
127 return;
128
129 KeySym ks;
130 char keychar[1];
131 XLookupString(&event, keychar, 1, &ks, 0);
132
133 if (ks == XK_Return) {
134 // create command from line
135 std::auto_ptr<FbTk::Command> cmd(CommandParser::instance().
136 parseLine(m_precommand + m_textbox.text()));
137 if (cmd.get())
138 cmd->execute();
139 delete this; // end this
140 } else if (ks == XK_Escape)
141 delete this; // end this
142}
143
144void CommandDialog::render() {
145 Pixmap tmp = m_pixmap;
146 if (!m_screen.winFrameTheme().labelFocusTexture().usePixmap()) {
147 m_label.setBackgroundColor(m_screen.winFrameTheme().labelFocusTexture().color());
148 m_pixmap = 0;
149 } else {
150 m_pixmap = m_screen.imageControl().renderImage(m_label.width(), m_label.height(),
151 m_screen.winFrameTheme().labelFocusTexture());
152 m_label.setBackgroundPixmap(m_pixmap);
153 }
154
155 if (tmp)
156 m_screen.imageControl().removeImage(tmp);
157
158}
159
160void CommandDialog::init() {
161
162 m_label.moveResize(0, 0,
163 200, m_font.height() + 2);
164 // we listen to motion notify too
165 m_label.setEventMask(m_label.eventMask() | ButtonPressMask | ButtonMotionMask);
166
167 m_label.setGC(m_screen.winFrameTheme().labelTextFocusGC());
168 render();
169 m_label.show();
170
171 m_textbox.setBackgroundColor(FbTk::Color("white", m_textbox.screenNumber()));
172
173 FbTk::Color black("black", m_textbox.screenNumber());
174 m_gc.setForeground(black);
175
176 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();
181
182 resize(200, m_textbox.height() + m_label.height());
183
184
185 // move to center of the screen
186 move((m_screen.width() - width())/2, (m_screen.height() - height())/2);
187
188 // we need ConfigureNotify from children
189 FbTk::EventManager::instance()->addParent(*this, *this);
190}
diff --git a/src/CommandDialog.hh b/src/CommandDialog.hh
new file mode 100644
index 0000000..2bc0678
--- /dev/null
+++ b/src/CommandDialog.hh
@@ -0,0 +1,68 @@
1// CommandDialog.hh for Fluxbox
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: CommandDialog.hh,v 1.1 2003/12/19 03:53:21 fluxgen Exp $
24
25#ifndef RUNCOMMANDDIALOG_HH
26#define RUNCOMMANDDIALOG_HH
27
28#include "FbTk/TextBox.hh"
29#include "FbTk/TextButton.hh"
30#include "FbTk/Font.hh"
31#include "FbTk/GContext.hh"
32
33class BScreen;
34
35class CommandDialog: public FbTk::FbWindow, public FbTk::EventHandler {
36public:
37 CommandDialog(BScreen &screen, const std::string &title);
38 CommandDialog(BScreen &screen, const std::string &title,
39 const std::string &pre_command);
40 virtual ~CommandDialog();
41
42 void setText(const std::string &text);
43
44 void show();
45 void hide();
46
47 void motionNotifyEvent(XMotionEvent &event);
48 void buttonPressEvent(XButtonEvent &event);
49 void handleEvent(XEvent &event);
50 void keyPressEvent(XKeyEvent &event);
51
52private:
53 void init();
54
55 void render();
56
57 FbTk::Font m_font;
58 FbTk::TextBox m_textbox;
59 FbTk::TextButton m_label;
60 FbTk::GContext m_gc;
61 BScreen &m_screen;
62 int m_move_x, m_move_y;
63 Pixmap m_pixmap;
64 const std::string m_precommand; ///< command to be used before the text (usefull for setting workspace name)
65};
66
67
68#endif // SETWORKSPACENAME_HH