Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
fltkpreview.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "../lout/msg.h"
21
22#include "fltkpreview.hh"
23#include "fltkmisc.hh"
24
25#include <FL/Fl.H>
26#include <FL/Fl_Bitmap.H>
27#include <FL/fl_draw.H>
28#include <stdio.h>
29
30#include "preview.xbm"
31
32namespace dw {
33namespace fltk {
34
35FltkPreview::FltkPreview (int x, int y, int w, int h,
36 dw::core::Layout *layout, const char *label):
37 FltkViewBase (x, y, w, h, label)
38{
39 layout->attachView (this);
40
41 scrollX = 0;
42 scrollY = 0;
43 scrollWidth = 1;
44 scrollHeight = 1;
45}
46
50
51int FltkPreview::handle (int event)
52{
53 return FltkViewBase::handle (event);
54}
55
57{
58 return x * canvasWidth / w ();
59}
60
62{
63 return y * canvasHeight / h ();
64}
65
67{
68 return x * w () / canvasWidth;
69}
70
72{
73 return y * h () / canvasHeight;
74}
75
76void FltkPreview::setCanvasSize (int width, int ascent, int descent)
77{
78 FltkViewBase::setCanvasSize (width, ascent, descent);
79 if (parent() && parent()->visible ())
80 ((FltkPreviewWindow*)parent())->reallocate ();
81}
82
84{
85 return true;
86}
87
89{
90 return 0;
91}
92
94{
95 return 0;
96}
97
99{
100 return 0;
101}
102
103void FltkPreview::scrollTo (int x, int y)
104{
105 scrollX = x;
106 scrollY = y;
107}
108
110{
111 MSG_ERR("FltkPreview::scroll not implemented\n");
112}
113
114void FltkPreview::setViewportSize (int width, int height,
115 int hScrollbarThickness,
116 int vScrollbarThickness)
117{
118 scrollWidth = width - vScrollbarThickness;
119 scrollHeight = height - hScrollbarThickness;
120}
121
123 core::style::Color *color,
125 int x, int y, const char *text, int len)
126{
127 /*
128 * We must call setfont() before calling getwidth() (or anything
129 * else that measures text).
130 */
131 FltkFont *ff = (FltkFont*)font;
132 Fl::set_font(ff->font, translateCanvasXToViewX (ff->size));
133#if 0
138 int width = (int)getwidth (text, len);
139 int height = font->ascent; // No descent, this would look to "bold".
140
141 int x1 = translateCanvasXToViewX (x);
142 int y1 = translateCanvasYToViewY (y);
143 int x2 = translateCanvasXToViewX (x + width);
144 int y2 = translateCanvasYToViewY (y + height);
145 Rectangle rect (x1, y1, x2 - x1, y2 - y1);
146
147 setcolor(((FltkColor*)color)->colors[shading]);
148 fillrect (rect);
149#endif
150 fl_color(((FltkColor*)color)->colors[shading]);
151 fl_draw(text, len, translateCanvasXToViewX (x), translateCanvasYToViewY(y));
152}
153
155 core::style::Color *color,
157 int x, int y, int w, int h,
158 const char *text)
159{
160}
161
162void FltkPreview::drawImage (core::Imgbuf *imgbuf, int xRoot, int yRoot,
163 int x, int y, int width, int height)
164{
165}
166
168{
169 return false;
170}
171
172void FltkPreview::drawFltkWidget (Fl_Widget *widget,
173 core::Rectangle *area)
174{
175}
176
177// ----------------------------------------------------------------------
178
180 Fl_Menu_Window (1, 1)
181{
182 box (FL_EMBOSSED_BOX);
183
184 begin ();
186 end ();
187
188 hide ();
189}
190
194
196{
197 reallocate ();
198 show ();
199}
200
202{
203 int maxWidth = misc::screenWidth () / 2;
204 int maxHeight = misc::screenHeight () * 4 / 5;
205 int mx, my, width, height;
206 bool warp = false;
207
208 if (preview->canvasHeight * maxWidth > maxHeight * preview->canvasWidth) {
209 // Expand to maximal height (most likely case).
210 width = preview->canvasWidth * maxHeight / preview->canvasHeight;
211 height = maxHeight;
212 } else {
213 // Expand to maximal width.
214 width = maxWidth;
215 height = preview->canvasHeight * maxWidth / preview->canvasWidth;
216 }
217
218 Fl::get_mouse(mx, my);
219
221 + preview->scrollWidth / 2);
223 + preview->scrollHeight / 2);
224
225 if (posX < 0) {
226 mx -= posX;
227 posX = 0;
228 warp = true;
229 } else if (posX + width > misc::screenWidth ()) {
230 mx -= (posX - (misc::screenWidth () - width));
231 posX = misc::screenWidth () - width;
232 warp = true;
233 }
234
235 if (posY < 0) {
236 my -= posY;
237 posY = 0;
238 warp = true;
239 } else if (posY + height > misc::screenHeight ()) {
240 my -= (posY - (misc::screenHeight () - height));
241 posY = misc::screenHeight () - height;
242 warp = true;
243 }
244
245 if (warp)
246 misc::warpPointer (mx, my);
247
248 resize (posX, posY, width, height);
249
250 preview->size(w () - 2 * BORDER_WIDTH, h () - 2 * BORDER_WIDTH);
251}
252
254{
255 Fl_Window::hide ();
256}
257
269
270// ----------------------------------------------------------------------
271
272FltkPreviewButton::FltkPreviewButton (int x, int y, int w, int h,
274 const char *label):
275 Fl_Button (x, y, w, h, label)
276{
277 image (new Fl_Bitmap (preview_bits, preview_width, preview_height));
279}
280
284
286{
289 switch (event) {
290 case FL_PUSH:
291 window->showWindow ();
292 return Fl_Button::handle (event);
293
294 case FL_DRAG:
295 if (window->visible ()) {
296 window->scrollTo (Fl::event_x_root (), Fl::event_y_root ());
297 return 1;
298 }
299 return Fl_Button::handle (event);
300
301 case FL_RELEASE:
302 window->hideWindow ();
303 return Fl_Button::handle (event);
304
305 default:
306 return Fl_Button::handle (event);
307 }
308}
309
310} // namespace fltk
311} // namespace dw
The platform independent interface for image buffers.
Definition imgbuf.hh:162
The central class for managing and drawing a widget tree.
Definition layout.hh:17
void scrollPosChanged(View *view, int x, int y)
Definition layout.cc:1306
dw::core::Shape implemtation for simple rectangles.
Definition types.hh:70
FltkPreviewWindow * window
FltkPreviewButton(int x, int y, int w, int h, dw::core::Layout *layout, const char *label=0)
void scrollTo(int mouseX, int mouseY)
FltkPreviewWindow(dw::core::Layout *layout)
void drawFltkWidget(Fl_Widget *widget, core::Rectangle *area)
void drawText(core::style::Font *font, core::style::Color *color, core::style::Color::Shading shading, int x, int y, const char *text, int len)
bool usesViewport()
Return, whether this view uses a viewport.
int getVScrollbarThickness()
Get the thickness of the vertical scrollbar, when it is visible.
int translateCanvasYToViewY(int y)
void scrollTo(int x, int y)
Scroll the vieport to the given position.
int handle(int event)
void scroll(dw::core::ScrollCommand cmd)
Scroll the viewport as commanded.
void drawImage(core::Imgbuf *imgbuf, int xRoot, int yRoot, int x, int y, int width, int height)
int translateViewXToCanvasX(int x)
void drawSimpleWrappedText(core::style::Font *font, core::style::Color *color, core::style::Color::Shading shading, int x, int y, int w, int h, const char *text)
int translateCanvasXToViewX(int x)
int getHScrollbarThickness()
Get the thickness of the horizontal scrollbar, when it is visible.
void setViewportSize(int width, int height, int hScrollbarThickness, int vScrollbarThickness)
Set the viewport size.
void setCanvasSize(int width, int ascent, int descent)
Set the canvas size.
int translateViewYToCanvasY(int y)
FltkPreview(int x, int y, int w, int h, dw::core::Layout *layout, const char *label=0)
void setCanvasSize(int width, int ascent, int descent)
Set the canvas size.
core::Layout * theLayout
#define MSG_ERR(...)
Definition dpid_common.h:23
static Layout * layout
static Image * image
static core::Imgbuf * imgbuf
ScrollCommand
Definition types.hh:35
void warpPointer(int x, int y)
Definition fltkmisc.cc:41
int screenHeight()
Definition fltkmisc.cc:36
int screenWidth()
Definition fltkmisc.cc:31
Dw is in this namespace, or sub namespaces of this one.