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