vfs: check userland buffers before reading them.
[haiku.git] / src / libs / print / libprint / PagesView.cpp
blob7b3e94d697dddde9d78803d47f7c9bb4c35e5565
1 #include "PagesView.h"
3 static const float kWidth = 80;
4 static const float kHeight = 30;
6 static const float kPageWidth = 16;
7 static const float kPageHeight = 16;
9 static const float kPageHorizontalIndent = 7;
10 static const float kPageVerticalIndent = 5;
12 PagesView::PagesView(BRect frame, const char* name, uint32 resizeMask, uint32 flags)
13 : BView(frame, name, resizeMask, flags),
14 fCollate(false),
15 fReverse(false)
17 SetViewColor(B_TRANSPARENT_COLOR);
20 void PagesView::GetPreferredSize(float *width, float *height)
22 *width = kWidth;
23 *height = kHeight;
26 void PagesView::Draw(BRect rect)
28 rgb_color backgroundColor = {255, 255, 255};
29 // inherit view color from parent if available
30 if (Parent() != NULL) {
31 backgroundColor = Parent()->ViewColor();
33 SetHighColor(backgroundColor);
34 FillRect(rect);
36 BFont font(be_plain_font);
37 font.SetSize(8);
38 SetFont(&font);
40 BPoint position(3, 3);
41 if (fCollate) {
42 BPoint next(kPageWidth + kPageHorizontalIndent * 2 + 10, 0);
43 _DrawPages(position, 1, 3);
44 position += next;
45 _DrawPages(position, 1, 3);
46 } else {
47 BPoint next(kPageWidth + kPageHorizontalIndent * 1 + 10, 0);
48 for (int i = 1; i <= 3; i ++) {
49 int page = fReverse ? 4 - i : i;
50 _DrawPages(position, page, 2);
51 position += next;
56 void PagesView::_DrawPages(BPoint position, int number, int count)
58 position.x += kPageHorizontalIndent * (count - 1);
59 BPoint next(-kPageHorizontalIndent, kPageVerticalIndent);
60 if (fCollate) {
61 for (int i = 0; i < count; i ++) {
62 int page;
63 if (fReverse) {
64 page = 1 + i;
65 } else {
66 page = count - i;
68 _DrawPage(position, page);
69 position += next;
71 } else {
72 for (int i = 0; i < count; i ++) {
73 _DrawPage(position, number);
74 position += next;
79 void PagesView::_DrawPage(BPoint position, int number)
81 const rgb_color pageBackgroundColor = {255, 255, 255};
82 const rgb_color pageBorderColor = {0, 0, 0};
83 const rgb_color pageNumberColor = {0, 0, 0};
85 BPoint page[5];
86 page[0].x = position.x + 3;
87 page[0].y = position.y;
88 page[4].x = position.x;
89 page[4].y = position.y + 3;
90 page[1].x = position.x + kPageWidth - 1;
91 page[1].y = position.y;
92 page[2].x = position.x + kPageWidth - 1;
93 page[2].y = position.y + kPageHeight - 1;
94 page[3].x = position.x;
95 page[3].y = position.y + kPageHeight - 1;
97 SetHighColor(pageBackgroundColor);
98 FillPolygon(page, 5);
100 SetHighColor(pageBorderColor);
101 StrokePolygon(page, 5);
102 StrokeLine(position + BPoint(3, 1), position + BPoint(3, 3));
103 StrokeLine(position + BPoint(3, 3), position + BPoint(1, 3));
105 SetHighColor(pageNumberColor);
106 SetLowColor(pageBackgroundColor);
107 DrawChar('0' + number,
108 position +
109 BPoint(kPageWidth - kPageHorizontalIndent + 1, kPageHeight - 2));
112 void PagesView::SetCollate(bool collate)
114 fCollate = collate;
115 Invalidate();
118 void PagesView::SetReverse(bool reverse)
120 fReverse = reverse;
121 Invalidate();