void ShowHideManager::ShowDomainsWithHighlights(const StructureSet *set)
{
    // first, show all highlighted stuff
    MakeAllVisible();
    if (!GlobalMessenger()->IsAnythingHighlighted()) return;
    ShowSelectedResidues(set);

    // then, also show all domains that contain highlighted residues
    StructureSet::ObjectList::const_iterator o, oe = set->objects.end();
    for (o=set->objects.begin(); o!=oe; ++o) {
        ChemicalGraph::MoleculeMap::const_iterator m, me = (*o)->graph->molecules.end();
        for (m=(*o)->graph->molecules.begin(); m!=me; ++m) {
            Molecule::ResidueMap::const_iterator r, re = m->second->residues.end();

            // find domains in this molecule that have highlights
            map < int , bool > domains;
            int domain;
            for (r=m->second->residues.begin(); r!=re; ++r) {
                if (GlobalMessenger()->IsHighlighted(m->second, r->first)) {
                    domain = m->second->residueDomains[r->first - 1];
                    if (domain != Molecule::NO_DOMAIN_SET)
                        domains[domain] = true;
                }
            }

            // now show all residues in these domains
            for (r=m->second->residues.begin(); r!=re; ++r) {
                domain = m->second->residueDomains[r->first - 1];
                if (domain != Molecule::NO_DOMAIN_SET && domains.find(domain) != domains.end())
                    Show(r->second, true);
            }
        }
    }
}
void ViewerWindowBase::OnCacheHighlights(wxCommandEvent& event)
{
    if (event.GetId() == MID_CACHE_HIGHLIGHTS)
        GlobalMessenger()->CacheHighlights();
    else if (event.GetId() == MID_RESTORE_CACHED_HIGHLIGHTS)
        GlobalMessenger()->RestoreCachedHighlights();
}
Example #3
0
void SequenceViewer::CreateSequenceWindow(bool showNow)
{
    if (sequenceWindow) {
        sequenceWindow->Show(showNow);
        if (showNow)
            GlobalMessenger()->PostRedrawSequenceViewer(this);
    } else {
        SequenceDisplay *display = GetCurrentDisplay();
        if (display) {
            sequenceWindow = new SequenceViewerWindow(this);

#ifdef __WXMAC__
            //  Nudge down a bit to compensate for the menubar at the top of the screen
            wxPoint p = sequenceWindow->GetPosition();
            p.y += 20;
            sequenceWindow->Move(p);
#endif

            sequenceWindow->NewDisplay(display, true);
            sequenceWindow->ScrollToColumn(display->GetStartingColumn());
            sequenceWindow->Show(showNow);
            // ScrollTo causes immediate redraw, so don't need a second one
            GlobalMessenger()->UnPostRedrawSequenceViewer(this);
        }
    }
}
void ShowHideManager::ShowSelectedResidues(const StructureSet *set)
{
    MakeAllVisible();
    if (!GlobalMessenger()->IsAnythingHighlighted()) return;

    StructureSet::ObjectList::const_iterator o, oe = set->objects.end();
    for (o=set->objects.begin(); o!=oe; ++o) {
        bool anyResidueInObjectVisible = false;
        ChemicalGraph::MoleculeMap::const_iterator m, me = (*o)->graph->molecules.end();
        for (m=(*o)->graph->molecules.begin(); m!=me; ++m) {
            Molecule::ResidueMap::const_iterator r, re = m->second->residues.end();
            bool anyResidueInMoleculeVisible = false;
            for (r=m->second->residues.begin(); r!=re; ++r) {
                if (!GlobalMessenger()->IsHighlighted(m->second, r->first))
                    Show(r->second, false);
                else
                    anyResidueInMoleculeVisible = anyResidueInObjectVisible = true;
            }
            if (!anyResidueInMoleculeVisible) {
                for (r=m->second->residues.begin(); r!=re; ++r)
                    Show(r->second, true);  // un-flag individual residues
                Show(m->second, false);     // flag whole molecule as hidden
            }
        }
        if (!anyResidueInObjectVisible) {
            for (m=(*o)->graph->molecules.begin(); m!=me; ++m)
                Show(m->second, true);      // un-flag individual molecules
            Show(*o, false);                // flag whole object as hidden
        }
    }
}
void ViewerWindowBase::NewDisplay(SequenceDisplay *display, bool enableSelectByColumn)
{
    viewerWidget->AttachAlignment(display);
    GlobalMessenger()->PostRedrawAllSequenceViewers();
    menuBar->EnableTop(menuBar->FindMenu("Edit"), display->IsEditable());
    menuBar->EnableTop(menuBar->FindMenu("Unaligned Justification"), display->IsEditable());
    menuBar->Enable(MID_SELECT_COLS, enableSelectByColumn);
    viewer->SetUndoRedoMenuStates();
}
// same as hitting done button
void PreferencesDialog::OnCloseWindow(wxCloseEvent& event)
{
    bool okay = true, qualityChanged = false;

    // set values if changed
    try {
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_QUALITY_ATOM_SLICES, iAtomSlices, &qualityChanged);
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_QUALITY_ATOM_STACKS, iAtomStacks, &qualityChanged);
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_QUALITY_BOND_SIDES, iBondSides, &qualityChanged);
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_QUALITY_WORM_SIDES, iWormSides, &qualityChanged);
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_QUALITY_WORM_SEGMENTS, iWormSegments, &qualityChanged);
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_QUALITY_HELIX_SIDES, iHelixSides, &qualityChanged);
        SET_BOOL_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_HIGHLIGHTS_ON, ID_C_HIGHLIGHT, &qualityChanged);
        SET_RADIO_REGISTRY_VALUE_IF_DIFFERENT(REG_QUALITY_SECTION,
            REG_PROJECTION_TYPE, ID_RADIOBOX, &qualityChanged);

        SET_BOOL_REGISTRY_VALUE_IF_DIFFERENT(REG_CACHE_SECTION, REG_CACHE_ENABLED, ID_C_CACHE_ON, 0);
        DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tCache, ID_T_CACHE_FOLDER, wxTextCtrl)
        SET_STRING_REGISTRY_VALUE_IF_DIFFERENT(REG_CACHE_SECTION, REG_CACHE_FOLDER, tCache);
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_CACHE_SECTION, REG_CACHE_MAX_SIZE, iCacheSize, 0);

        SET_BOOL_REGISTRY_VALUE_IF_DIFFERENT(REG_ADVANCED_SECTION, REG_CDD_ANNOT_READONLY, ID_C_ANNOT_RO, 0);
#ifdef __WXGTK__
        DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tLaunch, ID_T_LAUNCH, wxTextCtrl)
        SET_STRING_REGISTRY_VALUE_IF_DIFFERENT(REG_ADVANCED_SECTION, REG_BROWSER_LAUNCH, tLaunch);
#endif
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_ADVANCED_SECTION, REG_MAX_N_STRUCTS, iMaxStructs, 0);
        SET_INTEGER_REGISTRY_VALUE_IF_DIFFERENT(REG_ADVANCED_SECTION, REG_FOOTPRINT_RES, iFootRes, 0);

        SET_DOUBLE_REGISTRY_VALUE_IF_DIFFERENT(REG_ADVANCED_SECTION, REG_STEREO_SEPARATION, fSeparation, 0);
        SET_BOOL_REGISTRY_VALUE_IF_DIFFERENT(REG_ADVANCED_SECTION, REG_PROXIMAL_STEREO, ID_C_PROXIMAL, 0);

        // Limit cache size to current value now
        int size;
        if (iCacheSize->GetInteger(&size)) TruncateCache(size);

    } catch (const char *err) {
        ERRORMSG("Error setting registry values - " << err);
        okay = false;
    }

    // close dialog only if all user values are legit
    if (okay) {
        if (qualityChanged) GlobalMessenger()->PostRedrawAllStructures();
        EndModal(wxOK);
    } else {
        if (event.CanVeto())
            event.Veto();
    }
}
void ViewerWindowBase::UpdateDisplay(SequenceDisplay *display)
{
    int vsX, vsY;   // to preserve scroll position
    viewerWidget->GetScroll(&vsX, &vsY);
    viewerWidget->AttachAlignment(display, vsX, vsY);
    menuBar->EnableTop(menuBar->FindMenu("Edit"), display->IsEditable());
    menuBar->EnableTop(menuBar->FindMenu("Unaligned Justification"), display->IsEditable());
    GlobalMessenger()->PostRedrawAllSequenceViewers();
    viewer->SetUndoRedoMenuStates();
    UpdateGeometryViolations();
}
void ViewerWindowBase::OnFindPattern(wxCommandEvent& event)
{
    // remember previous pattern
    static wxString previousPattern;
    static wxString previousMode("Replace");

    // get pattern from user
    PatternDialog dialog(this);
    dialog.m_Pattern->SetValue(previousPattern);
    dialog.m_Pattern->SetSelection(-1, -1);
    dialog.m_Mode->SetStringSelection(previousMode);
    int status = dialog.ShowModal();
    wxString pattern = dialog.m_Pattern->GetValue();
    if (status != wxID_OK || pattern.size() == 0)
        return;

    // add trailing period if not present (convenience for the user)
    if (pattern[pattern.size() - 1] != '.') pattern += '.';
    previousPattern = pattern;
    previousMode = dialog.m_Mode->GetStringSelection();

    // set up highlighting
    Messenger::MoleculeHighlightMap restrictTo;
    if (dialog.m_Mode->GetStringSelection() == "Within")
        GlobalMessenger()->GetHighlights(&restrictTo);
    if (dialog.m_Mode->GetStringSelection() == "Replace" || dialog.m_Mode->GetStringSelection() == "Within")
        GlobalMessenger()->RemoveAllHighlights(true);

    // highlight pattern from each (unique) sequence in the display
    map < const Sequence * , bool > usedSequences;
    const SequenceDisplay *display = viewer->GetCurrentDisplay();

    for (unsigned int i=0; i<display->NRows(); ++i) {

        const Sequence *sequence = display->GetSequenceForRow(i);
        if (!sequence || usedSequences.find(sequence) != usedSequences.end()) continue;
        usedSequences[sequence] = true;

        if (!sequence->HighlightPattern(pattern.c_str(), restrictTo)) break;
    }
}
static void PostRedrawEntity(const StructureObject *object, const Molecule *molecule, const Residue *residue)
{
    if (residue) {
        const Molecule *m;
        if (residue->GetParentOfType(&m))
            GlobalMessenger()->PostRedrawMolecule(m);
    }

    else if (molecule) {
        GlobalMessenger()->PostRedrawMolecule(molecule);
    }

    else if (object) {
        // redraw all prot/nuc molecules
        ChemicalGraph::MoleculeMap::const_iterator m, me = object->graph->molecules.end();
        for (m=object->graph->molecules.begin(); m!=me; ++m) {
            if (m->second->IsProtein() || m->second->IsNucleotide())
                GlobalMessenger()->PostRedrawMolecule(m->second);
        }
    }

    GlobalMessenger()->PostRedrawAllSequenceViewers();
}
void ViewerWindowBase::OnJustification(wxCommandEvent& event)
{
    for (int i=MID_LEFT; i<=MID_SPLIT; ++i)
        menuBar->Check(i, (i == event.GetId()) ? true : false);

    switch (event.GetId()) {
        case MID_LEFT:
            currentJustification = BlockMultipleAlignment::eLeft; break;
        case MID_RIGHT:
            currentJustification = BlockMultipleAlignment::eRight; break;
        case MID_CENTER:
            currentJustification = BlockMultipleAlignment::eCenter; break;
        case MID_SPLIT:
            currentJustification = BlockMultipleAlignment::eSplit; break;
    }
    GlobalMessenger()->PostRedrawSequenceViewer(viewer);
}
Example #11
0
AnnotateDialog::AnnotateDialog(wxWindow *parent, StyleManager *manager, const StructureSet *set) :
    wxDialog(parent, -1, "User Annotations", wxPoint(400, 100), wxDefaultSize, wxDEFAULT_DIALOG_STYLE),
    styleManager(manager), structureSet(set)
{
    // get the structure highlights present when this dialog is created
    GlobalMessenger()->GetHighlightedResiduesWithStructure(&highlightedResidues);

    // construct the panel
    wxSizer *topSizer = SetupAnnotationControlDialog(this, false);

    // fill in list boxes with available and displayed styles
    ResetListBoxes();

    // set initial button states
    SetButtonStates();

    // call sizer stuff
    topSizer->Fit(this);
    topSizer->SetSizeHints(this);
}
void ViewerWindowBase::OnShowGeomVltns(wxCommandEvent& event)
{
    UpdateGeometryViolations();
    GlobalMessenger()->PostRedrawSequenceViewer(viewer);
}
Example #13
0
bool Sequence::HighlightPattern(const string& prositePattern, const MoleculeHighlightMap& restrictTo) const
{
    bool retval = true;
    try {

        // update CRegexp if not the same pattern as before
        static auto_ptr < CRegexp > regexp;
        static string previousPrositePattern;
        static int nGroups;
        if (!regexp.get() || prositePattern != previousPrositePattern) {

            // convert from ProSite syntax
            string regexPattern;
            if (!Prosite2Regex(prositePattern, &regexPattern, &nGroups))
                throw "error converting ProSite to regex syntax";

            // create pattern buffer
            TRACEMSG("creating CRegexp with pattern '" << regexPattern << "'");
            regexp.reset(new CRegexp(regexPattern, CRegexp::fCompile_ungreedy));

            previousPrositePattern = prositePattern;
        }

        // do the search, finding all non-overlapping matches
        int i, start = 0;
        while (start < (int)Length()) {

            // do the search
            string ignore = regexp->GetMatch(sequenceString, start, 0, CRegexp::fMatch_default, true);
            if (regexp->NumFound() <= 0)
                break;

//            TRACEMSG("got match, num (sub)patterns: " << regexp->NumFound());
//            for (i=0; i<regexp->NumFound(); ++i)
//                TRACEMSG("    " << i << ": " << (regexp->GetResults(i)[0] + 1) << '-' << regexp->GetResults(i)[1]);

            // check to see if this entire match is within the restricted set
            bool addMatch = true;
            if (restrictTo.size() > 0) {
                MoleculeHighlightMap::const_iterator r = restrictTo.find(identifier);
                if (r != restrictTo.end()) {
                    for (i=1; i<regexp->NumFound(); ++i) {
                        for (int j=regexp->GetResults(i)[0]; j<=regexp->GetResults(i)[1]-1; ++j) {
                            if (!r->second[j]) {
                                addMatch = false;
                                break;
                            }
                        }
                        if (!addMatch)
                            break;
                    }
                } else
                    addMatch = false;
            }

            // parse the match subpatterns, highlight each subpattern range
            if (addMatch)
                for (i=1; i<regexp->NumFound(); ++i)
                    GlobalMessenger()->AddHighlights(this, regexp->GetResults(i)[0], regexp->GetResults(i)[1] - 1);

            // start next search after the end of this one
            start = regexp->GetResults(regexp->NumFound() - 1)[1];
        }

    } catch (const char *err) {
        ERRORMSG("Sequence::HighlightPattern() - " << err);
        retval = false;
    } catch (exception& e) {
        ERRORMSG("Sequence::HighlightPattern() - caught exception: " << e.what());
        retval = false;
    }

    return retval;
}
Example #14
0
// draw atom spheres and residue labels here
bool Residue::Draw(const AtomSet *atomSet) const
{
    if (!atomSet) {
        ERRORMSG("Residue::Draw(data) - NULL AtomSet*");
        return false;
    }

    // verify presense of OpenGLRenderer
    if (!parentSet->renderer) {
        WARNINGMSG("Residue::Draw() - no renderer");
        return false;
    }

    // get Molecule parent
    const Molecule *molecule;
    if (!GetParentOfType(&molecule)) return false;

    // get object parent
    const StructureObject *object;
    if (!GetParentOfType(&object)) return false;

    // is this residue labeled?
    const StyleSettings& settings = parentSet->styleManager->GetStyleForResidue(object, molecule->id, id);
    bool proteinLabel = (IsAminoAcid() && settings.proteinLabels.spacing > 0 &&
        (id-1)%settings.proteinLabels.spacing == 0);
    bool nucleotideLabel = (IsNucleotide() && settings.nucleotideLabels.spacing > 0 &&
        (id-1)%settings.nucleotideLabels.spacing == 0);

    bool overlayEnsembles = parentSet->showHideManager->OverlayConfEnsembles();
    AtomStyle atomStyle;
    const AtomCoord *atom, *l1 = NULL, *l2 = NULL, *l3 = NULL;
    Vector labelColor;
    bool alphaVisible = false, alphaOnly = false;

    // iterate atoms; key is atomID
    AtomInfoMap::const_iterator a, ae = atomInfos.end();
    for (a=atomInfos.begin(); a!=ae; ++a) {

        // get AtomCoord* for appropriate altConf
        AtomPntr ap(molecule->id, id, a->first);
        atom = atomSet->GetAtom(ap, overlayEnsembles, true);
        if (!atom) continue;

        // get Style
        if (!parentSet->styleManager->GetAtomStyle(this, ap, atom, &atomStyle))
            return false;

        // highlight atom if necessary
        if (atomStyle.isHighlighted)
            atomStyle.color = GlobalColors()->Get(Colors::eHighlight);

        // draw the atom
        if (atomStyle.style != StyleManager::eNotDisplayed && atomStyle.radius > 0.0)
            parentSet->renderer->DrawAtom(atom->site, atomStyle);

        // store coords for positioning label, based on backbone coordinates
        if ((proteinLabel || nucleotideLabel) && a->second->classification != eSideChainAtom) {
            if (IsAminoAcid()) {
                if (a->second->name == " CA ") {
                    l1 = atom;
                    labelColor = atomStyle.color;
                    alphaVisible = (atomStyle.style != StyleManager::eNotDisplayed);
                }
                else if (a->second->name == " C  ") l2 = atom;
                else if (a->second->name == " N  ") l3 = atom;
            } else if (IsNucleotide()) {
                if (a->second->name == " P  ") {
                    l1 = atom;
                    labelColor = atomStyle.color;
                    alphaVisible = (atomStyle.style != StyleManager::eNotDisplayed);
                }
                // labeling by alphas seems to work better for nucleotides
//                else if (a->second->name == " C4*") l2 = atom;
//                else if (a->second->name == " C5*") l3 = atom;
            }
        }
    }

    // if not all backbone atoms present (e.g. alpha only), use alpha coords of neighboring residues
    if (l1 && (!l2 || !l3)) {
        Molecule::ResidueMap::const_iterator prevRes, nextRes;
        const AtomCoord *prevAlpha, *nextAlpha;
        if ((prevRes=molecule->residues.find(id - 1)) != molecule->residues.end() &&
            prevRes->second->alphaID != NO_ALPHA_ID &&
            (prevAlpha=atomSet->GetAtom(AtomPntr(molecule->id, id - 1, prevRes->second->alphaID))) != NULL &&
            (nextRes=molecule->residues.find(id + 1)) != molecule->residues.end() &&
            nextRes->second->alphaID != NO_ALPHA_ID &&
            (nextAlpha=atomSet->GetAtom(AtomPntr(molecule->id, id + 1, nextRes->second->alphaID))) != NULL)
        {
            l2 = prevAlpha;
            l3 = nextAlpha;
            alphaOnly = true;
        }
    }

    // draw residue (but not terminus) labels, assuming we have the necessary coordinates and
    // that alpha atoms are visible
    if (alphaVisible && (proteinLabel|| nucleotideLabel)) {
        Vector labelPosition;
        CNcbiOstrstream oss;

        double contrast = Colors::IsLightColor(settings.backgroundColor) ? 0 : 1;

        // protein label
        if (IsAminoAcid() && l1 && l2 && l3) {
            // position
            if (alphaOnly) {
                Vector forward = - ((l2->site - l1->site) + (l3->site - l1->site));
                forward.normalize();
                labelPosition = l1->site + 1.5 * forward;
            } else {
                Vector up = vector_cross(l2->site - l1->site, l3->site - l1->site);
                up.normalize();
                Vector forward = (-((l2->site - l1->site) + (l3->site - l1->site)) / 2);
                forward.normalize();
                labelPosition = l1->site + 1.5 * forward + 1.5 * up;
            }
            // text
            if (settings.proteinLabels.type == StyleSettings::eOneLetter) {
                oss << code;
            } else if (settings.proteinLabels.type == StyleSettings::eThreeLetter) {
                for (unsigned int i=0; i<nameGraph.size() && i<3; ++i)
                    oss << ((i == 0) ? (char) toupper((unsigned char) nameGraph[0]) : (char) tolower((unsigned char) nameGraph[i]));
            }
            // add number if necessary
            if (settings.proteinLabels.numbering == StyleSettings::eSequentialNumbering)
                oss << ' ' << id;
            else if (settings.proteinLabels.numbering == StyleSettings::ePDBNumbering)
                oss << namePDB;
            // contrasting color? (default to CA's color)
            if (settings.proteinLabels.white) labelColor.Set(contrast, contrast, contrast);
        }

        // nucleotide label
        else if (IsNucleotide() && l2 && l3) {
            if (alphaOnly) {
                Vector forward = - ((l2->site - l1->site) + (l3->site - l1->site));
                forward.normalize();
                labelPosition = l1->site + 3 * forward;
            } else {
                labelPosition = l3->site + 3 * (l3->site - l2->site);
            }
            // text
            if (settings.nucleotideLabels.type == StyleSettings::eOneLetter) {
                oss << code;
            } else if (settings.nucleotideLabels.type == StyleSettings::eThreeLetter) {
                for (unsigned int i=0; i<3; ++i)
                    if (nameGraph.size() > i && nameGraph[i] != ' ')
                        oss << nameGraph[i];
            }
            // add number if necessary
            if (settings.nucleotideLabels.numbering == StyleSettings::eSequentialNumbering)
                oss << ' ' << id;
            else if (settings.nucleotideLabels.numbering == StyleSettings::ePDBNumbering)
                oss << namePDB;
            // contrasting color? (default to C4*'s color)
            if (settings.nucleotideLabels.white) labelColor.Set(contrast, contrast, contrast);
        }

        // draw label
        if (oss.pcount() > 0) {
            string labelText = (string) CNcbiOstrstreamToString(oss);

            // apply highlight color if necessary
            if (GlobalMessenger()->IsHighlighted(molecule, id))
                labelColor = GlobalColors()->Get(Colors::eHighlight);

            parentSet->renderer->DrawLabel(labelText, labelPosition, labelColor);
        }
    }

    return true;
}
Example #15
0
void AnnotateDialog::OnButton(wxCommandEvent& event)
{
    switch (event.GetId()) {
        case ID_B_NEW:
            NewAnnotation();
            break;
        case ID_B_EDIT:
            EditAnnotation();
            break;
        case ID_B_MOVE:
            MoveAnnotation();
            break;
        case ID_B_DELETE:
            DeleteAnnotation();
            break;
        case ID_B_SHOW: {
            DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(available, ID_L_AVAILABLE, wxListBox)
            if (available->GetSelection() >= 0) {
                StyleManager::UserAnnotation *annotation = ANNOT_FROM_CLIENT_DATA(available);
                if (annotation) {
                    GlobalMessenger()->SetHighlights(annotation->residues);
                    structureSet->showHideManager->ShowDomainsWithHighlights(structureSet);
                    highlightedResidues = annotation->residues;
                } else
                    ERRORMSG("AnnotateDialog::OnButton() - error highlighting annotation #"
                        << available->GetSelection());
            }
            break;
        }
        case ID_B_MOVE_UP: case ID_B_MOVE_DOWN: {
            DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(available, ID_L_AVAILABLE, wxListBox)
            if (available->GetSelection() >= 0) {
                StyleManager::UserAnnotation *annotation = ANNOT_FROM_CLIENT_DATA(available);
                if (annotation && styleManager->
                        MoveUserAnnotation(annotation, (event.GetId() == ID_B_MOVE_UP)))
                    ResetListBoxes();
                else
                    ERRORMSG("AnnotateDialog::OnButton() - error reprioritizing annotation #"
                        << available->GetSelection());
            }
            break;
        }
        case ID_B_TURN_OFF: case ID_B_TURN_ON: {
			int listID = (event.GetId() == ID_B_TURN_OFF) ? ID_L_DISPLAYED : ID_L_AVAILABLE;
            DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(listBox, listID, wxListBox)
            if (listBox->GetSelection() >= 0) {
                StyleManager::UserAnnotation *annotation = ANNOT_FROM_CLIENT_DATA(listBox);
                if (annotation && styleManager->
                        DisplayUserAnnotation(annotation, (event.GetId() == ID_B_TURN_ON)))
                    ResetListBoxes();
                else
                    ERRORMSG("AnnotateDialog::OnButton() - error toggling annotation #"
                        << listBox->GetSelection());
            }
            break;
        }
        case ID_B_DONE:
            EndModal(wxOK);
            break;
        default:
            event.Skip();
    }

    SetButtonStates();
}