fltk_utils.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: fltk_utils.cpp,v $
- * PRODUCTION Revision 1000.3 2004/06/01 21:04:57 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.24
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: fltk_utils.cpp,v 1000.3 2004/06/01 21:04:57 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:
- * Generic FLTK utilities.
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbiapp.hpp>
- #include <gui/utils/fltk_utils.hpp>
- #include <FL/Fl.H>
- #include <FL/fl_draw.H>
- #include <FL/Fl_Window.H>
- BEGIN_NCBI_SCOPE
- //
- // our event cache
- //
- CFltkEvent::TEventMap CFltkEvent::sm_EventMap;
- Fl_Cursor CFltkUtils::m_CurrentCursor = FL_CURSOR_DEFAULT;
- void CFltkUtils::Lock()
- {
- #ifdef NCBI_THREADS
- Fl::lock();
- #endif
- }
- void CFltkUtils::Unlock(void* ptr)
- {
- #ifdef NCBI_THREADS
- Fl::unlock();
- Fl::awake(ptr);
- #endif
- }
- void CFltkUtils::SetCursor(Fl_Cursor cursor)
- {
- CFltkGuard LOCK;
- m_CurrentCursor = cursor;
- fl_cursor(cursor);
- }
- //
- // Escape fltk special characters: , @, &
- //
- string CFltkUtils::EscapeSpecialChars(const string& src)
- {
- string dest = src;
- dest = NStr::Replace(dest, "/", "\/");
- dest = NStr::Replace(dest, "@", "\@");
- dest = NStr::Replace(dest, "&", "\&");
- return dest;
- }
- Fl_Cursor CFltkUtils::GetCursor()
- {
- CFltkGuard LOCK;
- return m_CurrentCursor;
- }
- CFltkCursorGuard::CFltkCursorGuard(Fl_Cursor cursor)
- : m_OrigCursor(FL_CURSOR_DEFAULT)
- , m_CursorWindow(NULL)
- {
- CFltkGuard LOCK;
- m_OrigCursor = CFltkUtils::GetCursor();
- Fl_Widget* focus = Fl::focus();
- if (focus) {
- m_CursorWindow = focus->window();
- }
- CFltkUtils::SetCursor(cursor);
- }
- CFltkCursorGuard::~CFltkCursorGuard()
- {
- CFltkGuard LOCK;
- Fl_Widget* focus = Fl::focus();
- Fl::focus(m_CursorWindow);
- CFltkUtils::SetCursor(m_OrigCursor);
- Fl::focus(focus);
- }
- //
- //
- // box types for FLTK
- //
- //
- static void s_NcbiBox_Right(int x, int y, int w, int h, Fl_Color c)
- {
- fl_color(FL_GRAY_RAMP + 15);
- fl_line_style(FL_SOLID, 2);
- fl_line(x + w, y, x + w, y + h);
- fl_line_style(FL_SOLID, 1);
- }
- void CFltkUtils::Init(int argc, char** argv)
- {
- CFltkUtils::Lock();
- //
- // basic FLTK setup stuff
- //
- // this gets us the fast path for OpenGL rendering
- CNcbiApplication* app = CNcbiApplication::Instance();
- if (app) {
- app->SetEnvironment("GL_SWAP_TYPE", "NODAMAGE");
- }
- // set our default visual
- Fl::visual(FL_DOUBLE | FL_RGB8);
- // set our default interaction modes
- // this is operating-system dependent
- // NB: this will go away
- CFltkEvent::SetOSDefaults();
- // all default box types
- Fl::set_boxtype(static_cast<Fl_Boxtype>(static_cast<int>(eBox_RightEdge)),
- s_NcbiBox_Right, 1, 1, 2, 2);
- // FLTK argument processing
- Fl::args(argc, argv);
- };
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: fltk_utils.cpp,v $
- * Revision 1000.3 2004/06/01 21:04:57 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.24
- *
- * Revision 1.24 2004/05/25 21:13:01 ucko
- * Explicitly cast through int when converting between enum types.
- *
- * Revision 1.23 2004/05/25 17:14:38 dicuccio
- * Added standard FLTK intialization routine. Fixed EscapeChars() - replace with
- * correct characters
- *
- * Revision 1.22 2004/05/21 22:27:51 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.21 2004/05/18 11:24:13 friedman
- * Added method to add escape char to FLTK special chars.
- *
- * Revision 1.20 2004/03/23 13:39:32 dicuccio
- * Added GetCursor(). Fixed hanging wait cursor
- *
- * Revision 1.19 2004/03/17 19:51:24 yazhuk
- * Moved Event classes to gui_event.cpp
- *
- * Revision 1.18 2004/03/02 22:28:08 yazhuk
- * CGUIEvent fix - reset m_GUIsignal on every event
- *
- * Revision 1.17 2004/02/05 16:57:44 lebedev
- * Mac OS specific StandartConfig fixed
- *
- * Revision 1.16 2004/01/30 17:14:40 dicuccio
- * Added standard handlers for cut/copy/paste/undo/redo
- *
- * Revision 1.15 2004/01/09 01:00:32 dicuccio
- * FIxed typo - CGUnIEvent
- *
- * Revision 1.14 2004/01/08 19:37:24 yazhuk
- * Added FL_UNFOCUS handling
- *
- * Revision 1.13 2004/01/06 20:16:34 dicuccio
- * Added CFltkCursorGuard
- *
- * Revision 1.12 2003/12/31 20:19:42 dicuccio
- * Added CFltkUtils::Lock(), CFltkUtils::Unlock()
- *
- * Revision 1.11 2003/12/01 16:31:37 yazhuk
- * Added CGUIEvent class
- *
- * Revision 1.10 2003/06/30 12:55:04 dicuccio
- * Fixed (hopefully) event mapping for MacOS
- *
- * Revision 1.9 2003/06/26 16:01:03 dicuccio
- * Remove double click from an explicitly set flag - it causes confusion on event
- * mapping
- *
- * Revision 1.8 2003/06/16 00:35:19 dicuccio
- * Added CAppPopup
- *
- * Revision 1.7 2003/06/13 12:39:09 dicuccio
- * Code clean-up. Made some local const arrays static
- *
- * Revision 1.6 2003/03/21 17:02:57 dicuccio
- * Moved fltk_utils --> gui/utils
- *
- * Revision 1.5 2003/03/10 23:06:13 kuznets
- * iterate -> ITERATE
- *
- * Revision 1.4 2003/01/13 13:10:07 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.3 2002/12/23 13:48:59 dicuccio
- * Changed all *EventState --> *Event (less verbose)
- *
- * Revision 1.2 2002/11/20 16:27:41 lebedev
- * Mac OS: key mapping changed
- *
- * Revision 1.1 2002/11/19 17:07:23 dicuccio
- * Initial revision.
- *
- * ===========================================================================
- */