1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include <math.h>
#include "magnifier.h"
#include "util.h"
// Parser Stuff
#undef yyFlexLexer
#define yyFlexLexer mgFlexLexer
#include <FlexLexer.h>
void* mglval;
extern int mgparse(Magnifier*, mgFlexLexer*);
int mglex(void* vval, mgFlexLexer* ll)
{
mglval = vval;
return ll ? ll->yylex() : 0;
}
void mgerror(Magnifier* mg, mgFlexLexer* ll, const char* m)
{
mg->error(m);
const char* cmd = ll ? ll->YYText() : (const char*)NULL;
if (cmd && cmd[0] != '\n') {
mg->error(": ");
mg->error(cmd);
}
}
// Public Member Functions
Magnifier::Magnifier(Tcl_Interp* i, Tk_Canvas c, Tk_Item* item)
: Widget(i, c, item)
{
thumbnail = 0;
needsUpdate = 0;
}
int Magnifier::parse(istringstream& istr)
{
result = TCL_OK;
mgFlexLexer* ll = new mgFlexLexer(&istr);
mgparse(this, ll);
delete ll;
return result;
}
void Magnifier::update()
{
needsUpdate = 1;
redrawNow();
}
// Required Virtual Functions
// UpdatePixmap. This function is responsable for creating a valid
// pixmap the size of the current Magnifier
int Magnifier::updatePixmap(const BBox& bb)
{
if (!widgetGC)
widgetGC = XCreateGC(display, Tk_WindowId(tkwin), 0, NULL);
// create a valid pixmap if needed
// bb is in canvas coords
if (!pixmap)
if (!(pixmap = Tk_GetPixmap(display, Tk_WindowId(tkwin),
options->width, options->height, depth))) {
internalError("Magnifier: Unable to Create Pixmap");
return TCL_OK;
}
if (needsUpdate) {
if (thumbnail) {
XSetClipOrigin(display, widgetGC, 0, 0);
XCopyArea(display, thumbnail, pixmap, widgetGC, 0, 0,
options->width, options->height, 0, 0);
}
else
clearPixmap();
// MacOS will generate an Expose event (dark mode)
// so need to update
#ifndef MAC_OSX_TK
needsUpdate = 0;
#endif
}
return TCL_OK;
}
void Magnifier::invalidPixmap()
{
Widget::invalidPixmap();
update();
}
// Command Functions
void Magnifier::getBBoxCmd()
{
ostringstream str;
str << options->width << " " << options->height << ends;
Tcl_AppendResult(interp, str.str().c_str(), NULL);
}
void Magnifier::updateCmd(void* pp)
{
thumbnail = (Pixmap)pp;
update();
}
|