comparison dw/image.hh @ 347:e5955ab8dafb

- Moved the dw2 tree into dillo2's tree.
author jcid
date Wed, 24 Sep 2008 18:44:40 +0200
parents
children b277eed3119c
comparison
equal deleted inserted replaced
346:05228bc9f399 347:e5955ab8dafb
1 #ifndef __DW_IMAGE_HH__
2 #define __DW_IMAGE_HH__
3
4 #include "core.hh"
5
6 namespace dw {
7
8 /**
9 * \brief Represents a list of client-side image maps.
10 *
11 * All image maps of a HTML page (in the future, also image maps from
12 * different HTML pages) are stored in a list, which is passed to the
13 * image, so that it is possible to deal with maps, which are defined
14 * after the image within the HTML page.
15 *
16 * Maps are referred by instances of object::Object. These keys are
17 * typically URLs, so the type representing URLS should be derived from
18 * object::Object.
19 *
20 * \todo Some methods within the key class have to be implemented, this
21 * is not clear at this time.
22 */
23 class ImageMapsList
24 {
25 private:
26 class ImageMap: public lout::object::Object {
27 private:
28 class ShapeAndLink: public lout::object::Object {
29 public:
30 core::Shape *shape;
31 int link;
32
33 ~ShapeAndLink () { if (shape) delete shape; };
34 };
35
36 lout::container::typed::List <ShapeAndLink> *shapesAndLinks;
37 int defaultLink;
38 public:
39 ImageMap ();
40 ~ImageMap ();
41
42 void add (core::Shape *shape, int link);
43 void setDefaultLink (int link) { defaultLink = link; };
44 int link (int x, int y);
45 };
46
47 lout::container::typed::HashTable <lout::object::Object, ImageMap>
48 *imageMaps;
49 ImageMap *currentMap;
50
51 public:
52 ImageMapsList ();
53 ~ImageMapsList ();
54
55 void startNewMap (lout::object::Object *key);
56 void addShapeToCurrentMap (core::Shape *shape, int link);
57 void setCurrentMapDefaultLink (int link);
58 int link (lout::object::Object *key, int x, int y);
59 };
60
61 /**
62 * \brief Displays an instance of dw::core::Imgbuf.
63 *
64 * The dw::core::Imgbuf is automatically scaled, when needed, but dw::Image
65 * does not keep a reference on the root buffer.
66 *
67 *
68 * <h3>Signals</h3>
69 *
70 * For image maps, dw::Image uses the signals defined in
71 * dw::core::Widget::LinkReceiver. For client side image maps, -1 is
72 * passed for the coordinates, for server side image maps, the respective
73 * coordinates are used. See section "Image Maps" below.
74 *
75 *
76 * <h3>%Image Maps</h3>
77 *
78 * <h4>Client Side %Image Maps</h4>
79 *
80 * You must first create a list of image maps (dw::ImageMapList), which can
81 * be used for multiple images. The caller is responsible for freeing the
82 * dw::ImageMapList.
83 *
84 * Adding a map is done by dw::ImageMapsList::startNewMap. The key is an
85 * instance of a sub class of object::Object. In the context of HTML, this is
86 * a URL, which defines this map globally, by combining the URL of the
87 * document, this map is defined in, with the value of the attribute "name" of
88 * the \<MAP\> element, as a fragment.
89 *
90 * dw::ImageMapsList::addShapeToCurrentMap adds a shape to the current
91 * map. The \em link argument is a number, which is later passed to
92 * the dw::core::Widget::LinkReceiver.
93 *
94 * This map list is then, together with the key for the image, passed to
95 * dw::Image::setUseMap. For HTML, a URL with the value of the "ismap"
96 * attribute of \<IMG\> should be used.
97 *
98 * dw::Image will search the correct map, when needed. If it is not found
99 * at this time, but later defined, it will be found and used later. This is
100 * the case, when an HTML \<MAP\> is defined below the \<IMG\> in the
101 * document.
102 *
103 * Currently, only maps defined in the same document as the image may be
104 * used, since the dw::ImageMapsList is stored in the HTML link block, and
105 * contains only the image maps defined in the document.
106 *
107 * <h4>Server Side %Image Maps</h4>
108 *
109 * To use images for server side image maps, you must call
110 * dw::Image::setIsMap, and the dw::Image::style must contain a valid link
111 * (dw::core::style::Style::x_link). After this, motions and clicks are
112 * delegated to dw::core::Widget::LinkReceiver.
113 *
114 * \sa\ref dw-images-and-backgrounds
115 */
116 class Image: public core::Widget
117 {
118 private:
119 char *altText;
120 core::Imgbuf *buffer;
121 int altTextWidth;
122 bool clicking;
123 int currLink;
124 ImageMapsList *mapList;
125 Object *mapKey;
126 bool isMap;
127
128 protected:
129 void sizeRequestImpl (core::Requisition *requisition);
130 void sizeAllocateImpl (core::Allocation *allocation);
131
132 void draw (core::View *view, core::Rectangle *area);
133
134 bool buttonPressImpl (core::EventButton *event);
135 bool buttonReleaseImpl (core::EventButton *event);
136 void enterNotifyImpl (core::EventCrossing *event);
137 void leaveNotifyImpl (core::EventCrossing *event);
138 bool motionNotifyImpl (core::EventMotion *event);
139
140 //core::Iterator *iterator (Content::Type mask, bool atEnd);
141
142 public:
143 static int CLASS_ID;
144
145 Image(const char *altText);
146 ~Image();
147
148 core::Iterator *iterator (core::Content::Type mask, bool atEnd);
149
150 inline core::Imgbuf *getBuffer () { return buffer; }
151 void setBuffer (core::Imgbuf *buffer, bool resize = false);
152
153 void drawRow (int row);
154
155 void setIsMap ();
156 void setUseMap (ImageMapsList *list, Object *key);
157 };
158
159 } // namespace dw
160
161 #endif // __DW_IMAGE_HH__