tip_dlg.cpp
来自「ncbi源码」· C++ 代码 · 共 223 行
CPP
223 行
/* * =========================================================================== * PRODUCTION $Log: tip_dlg.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 20:56:35 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * PRODUCTION * =========================================================================== *//* $Id: tip_dlg.cpp,v 1000.2 2004/06/01 20:56:35 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include "tip_dlg.hpp"#include <corelib/ncbifile.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbireg.hpp>#include <gui/utils/system_path.hpp>#include <gui/utils/app_popup.hpp>#include <algorithm>BEGIN_NCBI_SCOPE#include "tip_dlg_.cpp"// callback function for linksstatic const char *s_DoLink(Fl_Widget *w, const char *uri){ CAppPopup::PopupURL(uri); return 0; // tells widget to do nothing}CTipDlg::CTipDlg() : m_Show(true){ m_Window.reset(x_CreateWindow()); m_Text->textsize(14); m_Text->link(s_DoLink); CNcbiApplication* app = CNcbiApplication::Instance(); _ASSERT(app); CNcbiRegistry& app_registry = app->GetConfig(); m_Show = NStr::StringToBool(app_registry.GetString("APP", "news", "true")); string fname = CSystemPath::ResolvePathExisting("<std>/etc/news.ini"); if (fname.empty()) { return; } CNcbiIfstream reg_stream(fname.c_str(), ios::in|ios::binary); CNcbiRegistry tips(reg_stream); int last_displayed = app_registry.GetInt("APP", "LastNewsDisplayed", -1); // figure out which messages to display list<string> sections; tips.EnumerateSections(§ions); ITERATE (list<string>, section, sections) { const string& sect = *section; STip tip; tip.idx = tips.GetInt(sect, "number", 0); tip.title = tips.Get(sect, "title"); tip.author = tips.Get(sect, "author"); tip.message = tips.Get(sect, "message"); m_Tips.push_back(tip); } sort(m_Tips.begin(), m_Tips.end()); // sort by idx m_Curr = m_Tips.begin(); while (m_Curr != m_Tips.end() && m_Curr->idx <= last_displayed) { ++m_Curr; } x_RefreshTip(); // center the view in the screen Center();}void CTipDlg::Show(){ if ( !m_Show ) { return; } CDialog::Show();}void CTipDlg::x_OnNextTip(){ vector<STip>::iterator iter = m_Curr; ++iter; if (iter != m_Tips.end()) { ++m_Curr; x_RefreshTip(); }}void CTipDlg::x_OnPrevTip(){ if (m_Curr != m_Tips.begin()) { --m_Curr; x_RefreshTip(); }}void CTipDlg::x_OnHideTips(){ CNcbiApplication* app = CNcbiApplication::Instance(); _ASSERT(app); CNcbiRegistry& app_registry = app->GetConfig(); app_registry.Set("APP", "news", NStr::BoolToString(m_HideTips->value() ? false : true), CNcbiRegistry::ePersistent);}void CTipDlg::x_RefreshTip(){ if (m_Curr != m_Tips.end()) { string msg = m_Curr->message; msg = "<table width=100%><tr><td width=95%>" + msg + "</td></tr></table>"; m_Text->value(msg.c_str()); m_TipStr = "Tip #" + NStr::IntToString(m_Curr->idx); if ( !m_Curr->title.empty() ) { m_TipStr += ": " + m_Curr->title; } if ( !m_Curr->author.empty() ) { m_TipStr += " (from " + m_Curr->author + ")"; } m_Tip->label(m_TipStr.c_str()); // record last displayed in registry CNcbiApplication* app = CNcbiApplication::Instance(); _ASSERT(app); CNcbiRegistry& app_registry = app->GetConfig(); app_registry.Set("APP", "LastNewsDisplayed", NStr::IntToString(m_Curr->idx), CNcbiRegistry::ePersistent); } else { m_Show = false; }}END_NCBI_SCOPE/* * =========================================================================== * $Log: tip_dlg.cpp,v $ * Revision 1000.2 2004/06/01 20:56:35 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * * Revision 1.7 2004/05/21 22:27:47 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.6 2004/02/17 20:35:27 rsmith * moved core/settings.[ch]pp and core/system_path.[ch]pp to config and utils, respectively. * * Revision 1.5 2003/12/22 19:27:26 dicuccio * Use CDialog::Center() instead of internal centering * * Revision 1.4 2003/12/03 15:28:29 jcherry * Sort items by index (otherwise they're alphabetical by section name). * Use vector rather than list to avoid non-portable list sort. * * Revision 1.3 2003/12/03 03:59:58 jcherry * Made s_DoLink() really static * * Revision 1.2 2003/12/02 22:41:16 jcherry * Added browser pop-up for links * * Revision 1.1 2003/11/24 15:43:13 dicuccio * Added new tip-of-the-day dialog. Changed CVersion to CPluginVersion * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?