Adding a ToolTip for an Annotation
I am using Acrobat c++ sdk to develop my plugin.
I need to create a ToolTip for an annotation. What I found is , Probably tooltip is not present as of now for an annotation. Although for ToolButton it is present.
To Implement , I ceated another annotation just beside my actual annotation and populated my data in that.
Binded two functions : MouseEnter and MouseExit to create and destroy the newly tool tip created annotation.
What I am trying is to run a thread, detach it, and in that thread , delele the annotation after two seconds.
void RemoveToolTipAnnot(PDAnnot annot)
{
AVDoc doc = AVAppGetActiveDoc(); // My program crashes here stating cannot access this .
PDDoc pdDoc = AVDocGetPDDoc(doc);
int pages = PDDocGetNumPages(pdDoc);
bool found = false;
for (int i = 0; i < pages; i++)
{
PDPage page = PDDocAcquirePage(pdDoc, i);
..........
..........
and this is main calling fn.
pdPageDel = AVPageViewGetPage(pageView);
ASFixedRect rect, newToolTipRect;
PDAnnotGetRect(annot, &rect);
newToolTipRect.left = rect.right + Int16ToFixed(10);
newToolTipRect.top = rect.top + Int16ToFixed(10);
newToolTipRect.right = newToolTipRect.left + Int16ToFixed(100);
newToolTipRect.bottom = newToolTipRect.top - Int16ToFixed(30);
tooltipAnnotDel =
PDPageCreateAnnot(pdPageDel, ASAtomFromString("FreeText"), &newToolTipRect);
CosDoc cosDoc = CosObjGetDoc(PDAnnotGetCosObj(tooltipAnnotDel));
CosObj annotDict = PDAnnotGetCosObj(tooltipAnnotDel);
// Set tooltip text
CosObj co = PDAnnotGetCosObj(annot);
ASTCount cb;
string val = "";
if (CosDictKnownKeyString(co, TTC::DK_TTC_State))
{
try
{
val = CosStringValue(CosDictGetKeyString(co, TTC::DK_TTC_State), &cb);
}
catch (...) {}
}
string data = "Annot Position:";
string d1 = data + val;
const char* str = d1.c_str();
CosObj contentsStr = CosNewString(cosDoc, false, (const char*)str, strlen(str));
CosDictPut(annotDict, ASAtomFromString("Contents"), contentsStr);
// Set default appearance (DA)
const char* da = "0 0 1 rg /Helv 10 Tf";
CosObj daStr = CosNewString(cosDoc, false, (const char*)da, strlen(da));
CosDictPut(annotDict, ASAtomFromString("DA"), daStr);
// Set color
PDColorValueRec color;
color.space = PDDeviceRGB;
color.value[0] = FloatToASFixed(1.0);
color.value[1] = FloatToASFixed(1.0);
color.value[2] = FloatToASFixed(0.8);
PDAnnotSetColor(tooltipAnnotDel, &color);
// Optional: make sure it's visible
PDAnnotSetFlags(tooltipAnnotDel, 0);
PDPageAddAnnot(pdPageDel, -2, tooltipAnnotDel);
PDPageNotifyContentsDidChange(pdPageDel);
PDPageRelease(pdPageDel);
thread t1(RemoveToolTipAnnot,tooltipAnnotDel);
t1.detach();
What is happening here?
