dock.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: dock.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:08:19 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: dock.cpp,v 1000.1 2004/06/01 21:08:19 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 <gui/widgets/dock/dock.hpp>
- #include <math.h>
- #include "dock_frame.hpp"
- BEGIN_NCBI_SCOPE
- CDockWidget::CDockWidget(int x, int y, int w, int h, const char* label)
- : Fl_Tile(x, y, w, h, label)
- {
- }
- static inline void s_Scale(size_t old_min, size_t old_max,
- size_t new_min, size_t new_max,
- size_t& val)
- {
- _ASSERT(val >= old_min && val <= old_max);
- float fact = float (val - old_min) / float (old_max - old_min);
- val = size_t(new_min + (new_max - new_min) * fact);
- }
- void CDockWidget::Dock(Fl_Widget* widget, EDockPosition pos, bool owner)
- {
- if ( !widget ) {
- return;
- }
- size_t child_x = x();
- size_t child_y = y();
- size_t child_w = w();
- size_t child_h = h();
- widget->hide();
- Fl_Widget* frame = x_WidgetToDockFrame(widget, owner);
- _TRACE("docking widget: " << widget);
- if (children() != 0) {
- switch (pos) {
- case eDock_Top:
- {{
- child_h /= (children() + 1);
- // iterate our children and resize as needed
- for (size_t i = 0; i < children(); ++i) {
- Fl_Widget* ch = child(i);
- size_t this_y1 = ch->y();
- size_t this_y2 = ch->y() + ch->h();
- s_Scale(y(), y() + h(), y() + child_h, y() + h(),
- this_y1);
- s_Scale(y(), y() + h(), y() + child_h, y() + h(),
- this_y2);
- ch->resize(ch->x(), this_y1, ch->w(), this_y2 - this_y1);
- }
- }}
- break;
- case eDock_Bottom:
- {{
- child_h /= (children() + 1);
- child_y += h() - child_h;
- // iterate our children and resize as needed
- for (size_t i = 0; i < children(); ++i) {
- Fl_Widget* ch = child(i);
- size_t this_y1 = ch->y();
- size_t this_y2 = ch->y() + ch->h();
- s_Scale(y(), y() + h(), y(), child_y, this_y1);
- s_Scale(y(), y() + h(), y(), child_y, this_y2);
- ch->resize(ch->x(), this_y1, ch->w(), this_y2 - this_y1);
- }
- }}
- break;
- case eDock_Right:
- {{
- child_w /= (children() + 1);
- child_x += w() - child_w;
- // iterate our children and resize as needed
- for (size_t i = 0; i < children(); ++i) {
- Fl_Widget* ch = child(i);
- size_t this_x1 = ch->x();
- size_t this_x2 = ch->x() + ch->w();
- s_Scale(x(), x() + w(), x(), child_x, this_x1);
- s_Scale(x(), x() + w(), x(), child_x, this_x2);
- ch->resize(this_x1, ch->y(), this_x2 - this_x1, ch->h());
- }
- }}
- break;
- case eDock_Left:
- {{
- child_w /= (children() + 1);
- // iterate our children and resize as needed
- for (size_t i = 0; i < children(); ++i) {
- Fl_Widget* ch = child(i);
- size_t this_x1 = ch->x();
- size_t this_x2 = ch->x() + ch->w();
- s_Scale(x(), x() + w(), x() + child_w, x() + w(), this_x1);
- s_Scale(x(), x() + w(), x() + child_w, x() + w(), this_x2);
- ch->resize(this_x1, ch->y(), this_x2 - this_x1, ch->h());
- }
- }}
- break;
- default:
- _TRACE("unhandled dock position");
- break;
- }
- }
- // now, move the current widget and add
- frame->resize(child_x, child_y, child_w, child_h);
- add(frame);
- resizable(NULL);
- frame->show();
- widget->show();
- redraw();
- //...and add our dock info to our list
- SDockInfo info;
- info.widget = widget;
- info.frame = frame;
- info.pos = pos;
- m_DockInfo.push_back(info);
- }
- void CDockWidget::Undock(Fl_Widget* widget)
- {
- _TRACE("un-docking widget: " << widget);
- NON_CONST_ITERATE (TDockInfo, iter, m_DockInfo) {
- if (iter->widget == widget) {
- m_DockInfo.erase(iter);
- break;
- }
- }
- // remove all of our child widgets and re-add them
- while (children()) {
- remove(child(0));
- }
- TDockInfo temp;
- temp.swap(m_DockInfo);
- ITERATE (TDockInfo, iter, temp) {
- Dock(iter->widget, iter->pos);
- }
- }
- Fl_Widget* CDockWidget::x_WidgetToDockFrame(Fl_Widget* widget, bool owner)
- {
- auto_ptr<CDockFrame> frame
- (new CDockFrame(this,
- widget->x(), widget->y(), widget->w(), widget->h()));
- frame->Attach(widget, owner);
- return frame.release();
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: dock.cpp,v $
- * Revision 1000.1 2004/06/01 21:08:19 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2
- *
- * Revision 1.2 2004/05/21 22:27:53 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.1 2004/01/08 16:45:30 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */