comparison anagram/vaclgui/multiline.cpp @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * multiline.cpp
7 */
8
9 #include <icoordsy.hpp>
10 #include <ifont.hpp>
11 //#include <istring.hpp>
12 #include <windows.h>
13
14 #include "multiline.hpp"
15
16 //#define INCLUDE_LOGGING
17 #include "log.h"
18
19
20 MultiLineText &MultiLineText::setText(const char *s) {
21 LOGSECTION("MultiLineText::setText");
22 textString = s;
23 char *p = textString.pointer();
24 nLines = 0;
25 while (p && *p) {
26 LOGV((int) p);
27 p = strchr(p, '\n');
28 nLines++;
29 if (p == 0) {
30 break;
31 }
32 p++;
33 }
34 LOGV(nLines);
35 return *this;
36 }
37
38 Boolean MultiLineText::paintWindow(IPaintEvent &event) {
39 LOGSECTION("MultiLineText::paintWindow");
40 LOGV(event.rect().asString());
41 LOGV(event.rect().movedBy(position()).asString());
42 IPresSpaceHandle presSpaceHandle = event.presSpaceHandle();
43
44 font().beginUsingFont(presSpaceHandle);
45
46 int lineWidth = size().width();
47
48 SetBkMode(presSpaceHandle, TRANSPARENT);
49 event.clearBackground(event.rect(),IGUIColor::dialogBgnd);
50 IPoint where(0, margin.height());
51 int i;
52 int leading = font().maxSize().height() + font().externalLeading();
53 //LOGV(leading);
54 char *p = textString.pointer();
55 for (i = 0; i < nLines; i++) {
56 char *q = strchr(p, '\n');
57 if (q) {
58 *q = 0;
59 }
60 char *t = p;
61 if (*t =='\v') {
62 t++;
63 }
64 int margin = (lineWidth - font().textWidth(t))/2;
65 where.setX(margin);
66 IPoint actualWhere = where;
67 if (ICoordinateSystem::isConversionNeeded()) {
68 actualWhere = ICoordinateSystem::convertToNative(where, size());
69 actualWhere.setY(actualWhere.y() - leading);
70 }
71 event.drawText(p, actualWhere);
72 LOGV(p);
73 if (q) {
74 *q = '\n';
75 }
76 p = q+1;
77 if (q) {
78 LOGV(p);
79 }
80 if (q && *p == '\v') {
81 LOGV(vTab);
82 where.setY(where.y() + vTab);
83 p++;
84 }
85 where.setY(where.y() + leading);
86 }
87 return true;
88 }
89
90 ISize MultiLineText::calcMinimumSize() const {
91 LOGSECTION("MultiLineText::calcMinimumSize");
92 char *p = textString.pointer();
93 int maxWidth = 0;
94 IPoint where(0, 0);
95 int leading = font().maxSize().height() + font().externalLeading();
96 for (int i = 0; i < nLines; i++) {
97 char *q = strchr(p, '\n');
98 if (q) {
99 *q = 0;
100 }
101 int width = font().textWidth(p);
102 if (width > maxWidth) {
103 maxWidth = width;
104 }
105 LOGV(width);
106 LOGV(p);
107 if (q) {
108 *q = '\n';
109 }
110 p = q+1;
111 if (q && *p == '\v') {
112 where.setY(where.y() + vTab);
113 p++;
114 }
115 where.setY(where.y() + leading);
116 }
117 //int enWidth = font().avgCharWidth();
118 maxWidth += 2*margin.width();
119
120 ISize minSize(maxWidth, where.y() + 2*margin.height());
121 LOGV(minSize.asString());
122 return minSize;
123 }
124