Dillo v3.1.1-46-g8a360e32
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
98void FltkPreview::scrollTo (int x, int y)
99{
100 scrollX = x;
101 scrollY = y;
102}
103
105{
106 MSG_ERR("FltkPreview::scroll not implemented\n");
107}
108
109void FltkPreview::setViewportSize (int width, int height,
110 int hScrollbarThickness,
111 int vScrollbarThickness)
112{
113 scrollWidth = width - vScrollbarThickness;
114 scrollHeight = height - hScrollbarThickness;
115}
116
118 core::style::Color *color,
120 int x, int y, const char *text, int len)
121{
122 /*
123 * We must call setfont() before calling getwidth() (or anything
124 * else that measures text).
125 */
126 FltkFont *ff = (FltkFont*)font;
127 Fl::set_font(ff->font, translateCanvasXToViewX (ff->size));
128#if 0
133 int width = (int)getwidth (text, len);
134 int height = font->ascent; // No descent, this would look to "bold".
135
136 int x1 = translateCanvasXToViewX (x);
137 int y1 = translateCanvasYToViewY (y);
138 int x2 = translateCanvasXToViewX (x + width);
139 int y2 = translateCanvasYToViewY (y + height);
140 Rectangle rect (x1, y1, x2 - x1, y2 - y1);
141
142 setcolor(((FltkColor*)color)->colors[shading]);
143 fillrect (rect);
144#endif
145 fl_color(((FltkColor*)color)->colors[shading]);
146 fl_draw(text, len, translateCanvasXToViewX (x), translateCanvasYToViewY(y));
147}
148
150 core::style::Color *color,
152 int x, int y, int w, int h,
153 const char *text)
154{
155}
156
157void FltkPreview::drawImage (core::Imgbuf *imgbuf, int xRoot, int yRoot,
158 int x, int y, int width, int height)
159{
160}
161
163{
164 return false;
165}
166
167void FltkPreview::drawFltkWidget (Fl_Widget *widget,
168 core::Rectangle *area)
169{
170}
171
172// ----------------------------------------------------------------------
173
175 Fl_Menu_Window (1, 1)
176{
177 box (FL_EMBOSSED_BOX);
178
179 begin ();
181 end ();
182
183 hide ();
184}
185
189
191{
192 reallocate ();
193 show ();
194}
195
197{
198 int maxWidth = misc::screenWidth () / 2;
199 int maxHeight = misc::screenHeight () * 4 / 5;
200 int mx, my, width, height;
201 bool warp = false;
202
203 if (preview->canvasHeight * maxWidth > maxHeight * preview->canvasWidth) {
204 // Expand to maximal height (most likely case).
205 width = preview->canvasWidth * maxHeight / preview->canvasHeight;
206 height = maxHeight;
207 } else {
208 // Expand to maximal width.
209 width = maxWidth;
210 height = preview->canvasHeight * maxWidth / preview->canvasWidth;
211 }
212
213 Fl::get_mouse(mx, my);
214
216 + preview->scrollWidth / 2);
218 + preview->scrollHeight / 2);
219
220 if (posX < 0) {
221 mx -= posX;
222 posX = 0;
223 warp = true;
224 } else if (posX + width > misc::screenWidth ()) {
225 mx -= (posX - (misc::screenWidth () - width));
226 posX = misc::screenWidth () - width;
227 warp = true;
228 }
229
230 if (posY < 0) {
231 my -= posY;
232 posY = 0;
233 warp = true;
234 } else if (posY + height > misc::screenHeight ()) {
235 my -= (posY - (misc::screenHeight () - height));
236 posY = misc::screenHeight () - height;
237 warp = true;
238 }
239
240 if (warp)
241 misc::warpPointer (mx, my);
242
243 resize (posX, posY, width, height);
244
245 preview->size(w () - 2 * BORDER_WIDTH, h () - 2 * BORDER_WIDTH);
246}
247
249{
250 Fl_Window::hide ();
251}
252
264
265// ----------------------------------------------------------------------
266
267FltkPreviewButton::FltkPreviewButton (int x, int y, int w, int h,
269 const char *label):
270 Fl_Button (x, y, w, h, label)
271{
272 image (new Fl_Bitmap (preview_bits, preview_width, preview_height));
274}
275
279
281{
284 switch (event) {
285 case FL_PUSH:
286 window->showWindow ();
287 return Fl_Button::handle (event);
288
289 case FL_DRAG:
290 if (window->visible ()) {
291 window->scrollTo (Fl::event_x_root (), Fl::event_y_root ());
292 return 1;
293 }
294 return Fl_Button::handle (event);
295
296 case FL_RELEASE:
297 window->hideWindow ();
298 return Fl_Button::handle (event);
299
300 default:
301 return Fl_Button::handle (event);
302 }
303}
304
305} // namespace fltk
306} // 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:1304
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.