rename image files in a coherent way; remove old unused images
[wxWidgets.git] / interface / wx / html / htmlcell.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: html/htmlcell.h
3 // Purpose: interface of wxHtml*Cell
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9
10
11 /**
12 @class wxHtmlRenderingStyle
13
14 Allows HTML rendering customizations.
15 This class is used when rendering wxHtmlCells as a callback.
16
17 @library{wxhtml}
18 @category{html}
19
20 @see wxHtmlRenderingInfo
21 */
22 class wxHtmlRenderingStyle
23 {
24 public:
25 /**
26 Returns the colour to use for the selected text.
27 */
28 virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0;
29
30 /**
31 Returns the colour to use for the selected text's background.
32 */
33 virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0;
34 };
35
36
37 /**
38 @class wxHtmlRenderingInfo
39
40 This class contains information given to cells when drawing them.
41 Contains rendering state, selection information and rendering style object
42 that can be used to customize the output.
43
44 @library{wxhtml}
45 @category{html}
46
47 @see @ref overview_html_cells, wxHtmlCell
48 */
49 class wxHtmlRenderingInfo
50 {
51 public:
52 /**
53 Default ctor.
54 */
55 wxHtmlRenderingInfo();
56
57 //@{
58 /**
59 Accessors.
60 */
61 void SetSelection(wxHtmlSelection *s);
62 wxHtmlSelection *GetSelection() const;
63
64 void SetStyle(wxHtmlRenderingStyle *style);
65 wxHtmlRenderingStyle& GetStyle();
66
67 wxHtmlRenderingState& GetState();
68 //@}
69 };
70
71
72 /**
73 @class wxHtmlCell
74
75 Internal data structure. It represents fragments of parsed HTML page, the
76 so-called @b cell - a word, picture, table, horizontal line and so on.
77 It is used by wxHtmlWindow and wxHtmlWinParser to represent HTML page in memory.
78
79 You can divide cells into two groups : @e visible cells with non-zero width and
80 height and @e helper cells (usually with zero width and height) that perform
81 special actions such as color or font change.
82
83 @library{wxhtml}
84 @category{html}
85
86 @see @ref overview_html_cells, wxHtmlContainerCell
87 */
88 class wxHtmlCell : public wxObject
89 {
90 public:
91 /**
92 Constructor.
93 */
94 wxHtmlCell();
95
96 /**
97 This method is used to adjust pagebreak position.
98 The parameter is variable that contains y-coordinate of page break
99 (= horizontal line that should not be crossed by words, images etc.).
100 If this cell cannot be divided into two pieces (each one on another page)
101 then it moves the pagebreak few pixels up.
102 Returns @true if pagebreak was modified, @false otherwise.
103
104 Usage:
105 @code
106 while (container->AdjustPagebreak(&p)) {}
107 @endcode
108 */
109 virtual bool AdjustPagebreak(int* pagebreak,
110 wxArrayInt& known_pagebreaks) const;
111
112 /**
113 Renders the cell.
114
115 @param dc
116 Device context to which the cell is to be drawn.
117 @param x,y
118 Coordinates of parent's upper left corner (origin). You must
119 add this to m_PosX,m_PosY when passing coordinates to dc's methods
120 Example:
121 @code
122 dc->DrawText("hello", x + m_PosX, y + m_PosY)
123 @endcode
124 @param view_y1
125 y-coord of the first line visible in window.
126 This is used to optimize rendering speed.
127 @param view_y2
128 y-coord of the last line visible in window.
129 This is used to optimize rendering speed.
130 @param info
131 Additional information for the rendering of the cell.
132 */
133 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, wxHtmlRenderingInfo& info);
134
135 /**
136 This method is called instead of Draw() when the cell is certainly out of
137 the screen (and thus invisible). This is not nonsense - some tags (like
138 wxHtmlColourCell or font setter) must be drawn even if they are invisible!
139
140 @param dc
141 Device context to which the cell is to be drawn.
142 @param x,y
143 Coordinates of parent's upper left corner. You must
144 add this to m_PosX,m_PosY when passing coordinates to dc's methods
145 Example:
146 @code
147 dc->DrawText("hello", x + m_PosX, y + m_PosY)
148 @endcode
149 @param info
150 Additional information for the rendering of the cell.
151 */
152 virtual void DrawInvisible(wxDC& dc, int x , int y, wxHtmlRenderingInfo& info);
153
154 /**
155 Returns pointer to itself if this cell matches condition (or if any of the
156 cells following in the list matches), @NULL otherwise.
157 (In other words if you call top-level container's Find() it will
158 return pointer to the first cell that matches the condition)
159
160 It is recommended way how to obtain pointer to particular cell or
161 to cell of some type (e.g. wxHtmlAnchorCell reacts on wxHTML_COND_ISANCHOR
162 condition).
163
164 @param condition
165 Unique integer identifier of condition
166 @param param
167 Optional parameters
168 */
169 virtual const wxHtmlCell* Find(int condition, const void* param) const;
170
171 /**
172 Returns descent value of the cell (m_Descent member).
173 See explanation:
174 @image html htmlcell_descent.png
175 */
176 int GetDescent() const;
177
178 /**
179 Returns pointer to the first cell in the list.
180 You can then use child's GetNext() method to obtain pointer to the next
181 cell in list.
182
183 @note This shouldn't be used by the end user. If you need some way of
184 finding particular cell in the list, try Find() method instead.
185 */
186 virtual wxHtmlCell* GetFirstChild() const;
187
188 /**
189 Returns height of the cell (m_Height member).
190 */
191 int GetHeight() const;
192
193 /**
194 Returns unique cell identifier if there is any, the empty string otherwise.
195 */
196 const wxString& GetId() const;
197
198 /**
199 Returns hypertext link if associated with this cell or @NULL otherwise.
200 See wxHtmlLinkInfo. (Note: this makes sense only for visible tags).
201
202 @param x,y
203 Coordinates of position where the user pressed mouse button.
204 These coordinates are used e.g. by COLORMAP. Values are relative to the
205 upper left corner of THIS cell (i.e. from 0 to m_Width or m_Height)
206 */
207 virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
208
209 /**
210 Returns cursor to show when mouse pointer is over the cell.
211
212 @param window
213 interface to the parent HTML window
214 */
215 virtual wxCursor GetMouseCursor(wxHtmlWindowInterface* window) const;
216
217 /**
218 Returns pointer to the next cell in list (see htmlcell.h if you're
219 interested in details).
220 */
221 wxHtmlCell* GetNext() const;
222
223 /**
224 Returns pointer to parent container.
225 */
226 wxHtmlContainerCell* GetParent() const;
227
228 /**
229 Returns X position within parent (the value is relative to parent's
230 upper left corner). The returned value is meaningful only if
231 parent's Layout() was called before!
232 */
233 int GetPosX() const;
234
235 /**
236 Returns Y position within parent (the value is relative to parent's
237 upper left corner). The returned value is meaningful only if
238 parent's Layout() was called before!
239 */
240 int GetPosY() const;
241
242 /**
243 Returns width of the cell (m_Width member).
244 */
245 int GetWidth() const;
246
247 /**
248 This method performs two actions:
249 -# adjusts the cell's width according to the fact that maximal possible
250 width is @e w. (this has sense when working with horizontal lines, tables etc.)
251 -# prepares layout (=fill-in m_PosX, m_PosY (and sometimes m_Height) members)
252 based on actual width @e w
253
254 It must be called before displaying cells structure because m_PosX and
255 m_PosY are undefined (or invalid) before calling Layout().
256 */
257 virtual void Layout(int w);
258
259 /**
260 This function is simple event handler.
261 Each time the user clicks mouse button over a cell within wxHtmlWindow
262 this method of that cell is called.
263 Default behavior is to call wxHtmlWindow::LoadPage.
264
265 @param window
266 interface to the parent HTML window
267 @param pos
268 coordinates of mouse click (this is relative to cell's origin
269 @param event
270 mouse event that triggered the call
271
272 @return @true if a link was clicked, @false otherwise.
273
274 @since 2.7.0 (before OnMouseClick() method served a similar purpose).
275
276 @note
277 If you need more "advanced" event handling you should use wxHtmlBinderCell instead.
278 */
279 virtual bool ProcessMouseClick(wxHtmlWindowInterface* window,
280 const wxPoint& pos,
281 const wxMouseEvent& event);
282
283 /**
284 Sets unique cell identifier. Default value is no identifier, i.e. empty string.
285 */
286 void SetId(const wxString& id);
287
288 /**
289 Sets the hypertext link associated with this cell.
290 (Default value is wxHtmlLinkInfo("", "") (no link))
291 */
292 void SetLink(const wxHtmlLinkInfo& link);
293
294 /**
295 Sets the next cell in the list. This shouldn't be called by user - it is
296 to be used only by wxHtmlContainerCell::InsertCell.
297 */
298 void SetNext(wxHtmlCell* cell);
299
300 /**
301 Sets parent container of this cell.
302 This is called from wxHtmlContainerCell::InsertCell.
303 */
304 void SetParent(wxHtmlContainerCell* p);
305
306 /**
307 Sets the cell's position within parent container.
308 */
309 virtual void SetPos(int x, int y);
310 };
311
312
313
314 /**
315 @class wxHtmlContainerCell
316
317 The wxHtmlContainerCell class is an implementation of a cell that may
318 contain more cells in it. It is heavily used in the wxHTML layout algorithm.
319
320 @library{wxhtml}
321 @category{html}
322
323 @see @ref overview_html_cells
324 */
325 class wxHtmlContainerCell : public wxHtmlCell
326 {
327 public:
328 /**
329 Constructor. @a parent is pointer to parent container or @NULL.
330 */
331 wxHtmlContainerCell(wxHtmlContainerCell* parent);
332
333 /**
334 Returns container's horizontal alignment.
335 */
336 int GetAlignHor() const;
337
338 /**
339 Returns container's vertical alignment.
340 */
341 int GetAlignVer() const;
342
343 /**
344 Returns the background colour of the container or @c wxNullColour if no
345 background colour is set.
346 */
347 wxColour GetBackgroundColour();
348
349 /**
350 Returns the indentation. @a ind is one of the @b wxHTML_INDENT_* constants.
351
352 @note You must call GetIndentUnits() with same @a ind parameter in order
353 to correctly interpret the returned integer value.
354 It is NOT always in pixels!
355 */
356 int GetIndent(int ind) const;
357
358 /**
359 Returns the units of indentation for @a ind where @a ind is one
360 of the @b wxHTML_INDENT_* constants.
361 */
362 int GetIndentUnits(int ind) const;
363
364 /**
365 Inserts a new cell into the container.
366 */
367 void InsertCell(wxHtmlCell* cell);
368
369 /**
370 Sets the container's alignment (both horizontal and vertical) according to
371 the values stored in @e tag. (Tags @c ALIGN parameter is extracted.)
372 In fact it is only a front-end to SetAlignHor() and SetAlignVer().
373 */
374 void SetAlign(const wxHtmlTag& tag);
375
376 /**
377 Sets the container's @e horizontal alignment.
378 During wxHtmlCell::Layout each line is aligned according to @a al value.
379
380 @param al
381 new horizontal alignment. May be one of these values:
382 - wxHTML_ALIGN_LEFT: lines are left-aligned (default)
383 - wxHTML_ALIGN_JUSTIFY: lines are justified
384 - wxHTML_ALIGN_CENTER: lines are centered
385 - wxHTML_ALIGN_RIGHT: lines are right-aligned
386 */
387 void SetAlignHor(int al);
388
389 /**
390 Sets the container's @e vertical alignment. This is per-line alignment!
391
392 @param al
393 new vertical alignment. May be one of these values:
394 - wxHTML_ALIGN_BOTTOM: cells are over the line (default)
395 - wxHTML_ALIGN_CENTER: cells are centered on line
396 - wxHTML_ALIGN_TOP: cells are under the line
397
398 @image html htmlcontcell_alignv.png
399 */
400 void SetAlignVer(int al);
401
402 /**
403 Sets the background colour for this container.
404 */
405 void SetBackgroundColour(const wxColour& clr);
406
407 /**
408 Sets the border (frame) colours. A border is a rectangle around the container.
409
410 @param clr1
411 Colour of top and left lines
412 @param clr2
413 Colour of bottom and right lines
414 */
415 void SetBorder(const wxColour& clr1, const wxColour& clr2);
416
417 /**
418 Sets the indentation (free space between borders of container and subcells).
419
420 @image html htmlcontcell_indent.png
421
422 @param i
423 Indentation value.
424 @param what
425 Determines which of the four borders we're setting. It is OR
426 combination of following constants:
427 - wxHTML_INDENT_TOP: top border
428 - wxHTML_INDENT_BOTTOM: bottom
429 - wxHTML_INDENT_LEFT: left
430 - wxHTML_INDENT_RIGHT: right
431 - wxHTML_INDENT_HORIZONTAL: left and right
432 - wxHTML_INDENT_VERTICAL: top and bottom
433 - wxHTML_INDENT_ALL: all 4 borders
434 @param units
435 Units of i. This parameter affects interpretation of value.
436 - wxHTML_UNITS_PIXELS: @a i is number of pixels
437 - wxHTML_UNITS_PERCENT: @a i is interpreted as percents of width
438 of parent container
439 */
440 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
441
442 /**
443 Sets minimal height of the container.
444 When container's wxHtmlCell::Layout is called, m_Height is set depending
445 on layout of subcells to the height of area covered by layed-out subcells.
446 Calling this method guarantees you that the height of container is never
447 smaller than @a h - even if the subcells cover much smaller area.
448
449 @param h
450 The minimal height.
451 @param align
452 If height of the container is lower than the minimum height, empty space
453 must be inserted somewhere in order to ensure minimal height.
454 This parameter is one of @c wxHTML_ALIGN_TOP, @c wxHTML_ALIGN_BOTTOM,
455 @c wxHTML_ALIGN_CENTER. It refers to the contents, not to the
456 empty place.
457 */
458 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
459
460 /**
461 Sets floating width adjustment.
462
463 The normal behaviour of container is that its width is the same as the width of
464 parent container (and thus you can have only one sub-container per line).
465 You can change this by setting the floating width adjustment.
466
467 @param w
468 Width of the container. If the value is negative it means
469 complement to full width of parent container.
470 E.g. @code SetWidthFloat(-50, wxHTML_UNITS_PIXELS) @endcode sets the
471 width of container to parent's width minus 50 pixels. This is useful when
472 creating tables - you can call SetWidthFloat(50) and SetWidthFloat(-50).
473 @param units
474 Units of w This parameter affects the interpretation of value.
475 - wxHTML_UNITS_PIXELS: @a w is number of pixels
476 - wxHTML_UNITS_PERCENT: @a w is interpreted as percents of width
477 of parent container
478 */
479 void SetWidthFloat(int w, int units);
480
481 /**
482 Sets floating width adjustment.
483
484 The normal behaviour of container is that its width is the same as the width of
485 parent container (and thus you can have only one sub-container per line).
486 You can change this by setting the floating width adjustment.
487
488 @param tag
489 In the second version of method, @a w and @a units info is extracted
490 from tag's WIDTH parameter.
491 @param pixel_scale
492 This is number of real pixels that equals to 1 HTML pixel.
493 */
494 void SetWidthFloat(const wxHtmlTag& tag,
495 double pixel_scale = 1.0);
496 };
497
498
499
500 /**
501 @class wxHtmlLinkInfo
502
503 This class stores all necessary information about hypertext links
504 (as represented by \<A\> tag in HTML documents).
505 In current implementation it stores URL and target frame name.
506
507 @note Frames are not currently supported by wxHTML!
508
509 @library{wxhtml}
510 @category{html}
511 */
512 class wxHtmlLinkInfo : public wxObject
513 {
514 public:
515 /**
516 Default ctor.
517 */
518 wxHtmlLinkInfo();
519
520 /**
521 Construct hypertext link from HREF (aka URL) and TARGET (name of target frame).
522 */
523 wxHtmlLinkInfo(const wxString& href,
524 const wxString& target = wxEmptyString);
525
526 /**
527 Return pointer to event that generated OnLinkClicked() event.
528 Valid only within wxHtmlWindow::OnLinkClicked, @NULL otherwise.
529 */
530 const wxMouseEvent* GetEvent() const;
531
532 /**
533 Return @e HREF value of the \<A\> tag.
534 */
535 wxString GetHref() const;
536
537 /**
538 Return pointer to the cell that was clicked.
539 Valid only within wxHtmlWindow::OnLinkClicked, @NULL otherwise.
540 */
541 const wxHtmlCell* GetHtmlCell() const;
542
543 /**
544 Return @e TARGET value of the \<A\> tag (this value is used to specify
545 in which frame should be the page pointed by @ref GetHref() Href opened).
546 */
547 wxString GetTarget() const;
548 };
549
550 /**
551 @class wxHtmlColourCell
552
553 This cell changes the colour of either the background or the foreground.
554
555 @library{wxhtml}
556 @category{html}
557 */
558 class wxHtmlColourCell : public wxHtmlCell
559 {
560 public:
561 /**
562 Constructor.
563
564 @param clr
565 The color
566 @param flags
567 Can be one of following:
568 - wxHTML_CLR_FOREGROUND: change color of text
569 - wxHTML_CLR_BACKGROUND: change background color
570 */
571 wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND);
572 };
573
574
575
576 /**
577 @class wxHtmlWidgetCell
578
579 wxHtmlWidgetCell is a class that provides a connection between HTML cells and
580 widgets (an object derived from wxWindow).
581 You can use it to display things like forms, input boxes etc. in an HTML window.
582
583 wxHtmlWidgetCell takes care of resizing and moving window.
584
585 @library{wxhtml}
586 @category{html}
587 */
588 class wxHtmlWidgetCell : public wxHtmlCell
589 {
590 public:
591 /**
592 Constructor.
593
594 @param wnd
595 Connected window. It is parent window @b must be the wxHtmlWindow object
596 within which it is displayed!
597 @param w
598 Floating width. If non-zero width of wnd window is adjusted so that it is
599 always w percents of parent container's width. (For example w = 100 means
600 that the window will always have same width as parent container).
601 */
602 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
603 };