aboutsummaryrefslogtreecommitdiff
path: root/src/TextDialog.cc
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-08-17 11:10:17 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-08-17 11:10:17 (GMT)
commita23778a44d2469fdc414884f5fe72fde09c100cc (patch)
treedcff8778bef2f70fb1112f60f6de290a0aebe777 /src/TextDialog.cc
parent72fd5e03a48396e6feec86534d266c68a9edd915 (diff)
downloadfluxbox_pavel-a23778a44d2469fdc414884f5fe72fde09c100cc.zip
fluxbox_pavel-a23778a44d2469fdc414884f5fe72fde09c100cc.tar.bz2
add SetTitle and SetTitleDialog key commands
Diffstat (limited to 'src/TextDialog.cc')
-rw-r--r--src/TextDialog.cc191
1 files changed, 191 insertions, 0 deletions
diff --git a/src/TextDialog.cc b/src/TextDialog.cc
new file mode 100644
index 0000000..7f95c13
--- /dev/null
+++ b/src/TextDialog.cc
@@ -0,0 +1,191 @@
1// TextDialog.cc
2// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#include "TextDialog.hh"
23
24#include "Screen.hh"
25#include "FbWinFrameTheme.hh"
26#include "fluxbox.hh"
27
28#include "FbTk/ImageControl.hh"
29#include "FbTk/EventManager.hh"
30#include "FbTk/KeyUtil.hh"
31
32#include <X11/keysym.h>
33#include <X11/Xutil.h>
34
35#include <memory>
36#include <stdexcept>
37
38using std::string;
39
40/**
41 * This is an abstract class providing a text box dialog
42 */
43
44TextDialog::TextDialog(BScreen &screen,
45 const string &title) :
46 FbTk::FbWindow(screen.rootWindow().screenNumber(), 0, 0, 200, 1, ExposureMask),
47 m_textbox(*this, screen.focusedWinFrameTheme()->font(), ""),
48 m_label(*this, screen.focusedWinFrameTheme()->font(), title),
49 m_gc(m_textbox),
50 m_screen(screen),
51 m_move_x(0),
52 m_move_y(0),
53 m_pixmap(0){
54 init();
55}
56
57
58TextDialog::~TextDialog() {
59 FbTk::EventManager::instance()->remove(*this);
60 hide();
61 if (m_pixmap != 0)
62 m_screen.imageControl().removeImage(m_pixmap);
63}
64
65
66void TextDialog::setText(const string &text) {
67 m_textbox.setText(text);
68}
69
70void TextDialog::show() {
71 FbTk::FbWindow::show();
72 m_textbox.setInputFocus();
73 m_label.clear();
74 Fluxbox::instance()->setShowingDialog(true);
75 // resize to correct width, which should be the width of label text
76 // no need to truncate label text in this dialog
77 // but if label text size < 200 we set 200
78 if (m_label.textWidth() < 200)
79 return;
80 else {
81 resize(m_label.textWidth(), height());
82 updateSizes();
83 render();
84 }
85}
86
87void TextDialog::hide() {
88 FbTk::FbWindow::hide();
89 Fluxbox::instance()->setShowingDialog(false);
90}
91
92void TextDialog::exposeEvent(XExposeEvent &event) {
93 if (event.window == window())
94 clearArea(event.x, event.y, event.width, event.height);
95}
96
97void TextDialog::buttonPressEvent(XButtonEvent &event) {
98 m_textbox.setInputFocus();
99 m_move_x = event.x_root - x();
100 m_move_y = event.y_root - y();
101}
102
103void TextDialog::handleEvent(XEvent &event) {
104 if (event.type == ConfigureNotify && event.xconfigure.window != window()) {
105 moveResize(event.xconfigure.x, event.xconfigure.y,
106 event.xconfigure.width, event.xconfigure.height);
107 } else if (event.type == DestroyNotify)
108 delete this;
109}
110
111void TextDialog::motionNotifyEvent(XMotionEvent &event) {
112 int new_x = event.x_root - m_move_x;
113 int new_y = event.y_root - m_move_y;
114 move(new_x, new_y);
115}
116
117void TextDialog::keyPressEvent(XKeyEvent &event) {
118 unsigned int state = FbTk::KeyUtil::instance().isolateModifierMask(event.state);
119 if (state)
120 return;
121
122 KeySym ks;
123 char keychar;
124 XLookupString(&event, &keychar, 1, &ks, 0);
125
126 if (ks == XK_Return) {
127 exec(m_textbox.text());
128 delete this;
129 } else if (ks == XK_Escape)
130 delete this; // end this
131 else if (ks == XK_Tab) {
132 // try to expand a command
133 tabComplete();
134 }
135
136}
137
138void TextDialog::render() {
139 Pixmap tmp = m_pixmap;
140 if (!m_screen.focusedWinFrameTheme()->iconbarTheme().texture().usePixmap()) {
141 m_label.setBackgroundColor(m_screen.focusedWinFrameTheme()->iconbarTheme().texture().color());
142 m_pixmap = 0;
143 } else {
144 m_pixmap = m_screen.imageControl().renderImage(m_label.width(), m_label.height(),
145 m_screen.focusedWinFrameTheme()->iconbarTheme().texture());
146 m_label.setBackgroundPixmap(m_pixmap);
147 }
148
149 if (tmp)
150 m_screen.imageControl().removeImage(tmp);
151
152}
153
154void TextDialog::init() {
155
156 // setup label
157 // we listen to motion notify too
158 m_label.setEventMask(m_label.eventMask() | ButtonPressMask | ButtonMotionMask);
159 m_label.setGC(m_screen.focusedWinFrameTheme()->iconbarTheme().text().textGC());
160 m_label.show();
161
162 // setup text box
163 FbTk::Color white("white", m_textbox.screenNumber());
164 m_textbox.setBackgroundColor(white);
165 FbTk::Color black("black", m_textbox.screenNumber());
166 m_gc.setForeground(black);
167 m_textbox.setGC(m_gc.gc());
168 m_textbox.show();
169
170 // setup this window
171 setBorderWidth(1);
172 setBackgroundColor(white);
173 // move to center of the screen
174 move((m_screen.width() - width())/2, (m_screen.height() - height())/2);
175
176 updateSizes();
177 resize(width(), m_textbox.height() + m_label.height());
178
179 render();
180
181 // we need ConfigureNotify from children
182 FbTk::EventManager::instance()->addParent(*this, *this);
183}
184
185void TextDialog::updateSizes() {
186 m_label.moveResize(0, 0,
187 width(), m_textbox.font().height() + 2);
188
189 m_textbox.moveResize(2, m_label.height(),
190 width() - 4, m_textbox.font().height() + 2);
191}