table.cpp

来自「ncbi源码」· C++ 代码 · 共 275 行

CPP
275
字号
/* * =========================================================================== * PRODUCTION $Log: table.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 20:46:38  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * PRODUCTION * =========================================================================== *//*  $Id: table.cpp,v 1000.2 2004/06/01 20:46:38 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:  Lou Friedman * * File Description: *    Implementation of an entry form table class that associate fields *      with some form of editable widget. */#include <ncbi_pch.hpp>#include <gui/dialogs/entry_form/table.hpp>#include <FL/Fl_Button.H>#include <FL/Fl_File_Input.H>#include <FL/Fl_Float_Input.H>#include <FL/Fl_Input.H>#include <FL/Fl_Int_Input.H>#include <FL/Fl_Multiline_Input.H>#include <FL/Fl_Secret_Input.H>#include <FL/Fl_Valuator.H>#include <memory>#include <gui/dialogs/file_browser.hpp>BEGIN_NCBI_SCOPECEntryFormTable::CEntryFormTable(int w, int space)    : Fl_Group(0, 0, w, 0){    box(FL_NO_BOX);    end();    m_Pack = new Fl_Pack(0, 0, w, 0);    m_Pack->end();    m_Pack->spacing(space);  }CEntryFormTable::~CEntryFormTable(){}// add a title row.  This creates a box with a piece of text centered in it and// a colored background.  The const char* here is not copied, so make sure that// it survives as long as this class doesvoid CEntryFormTable::AddTitleRow(const char* label){    auto_ptr<Fl_Box> box(new Fl_Box(0, 0, m_Pack->w(), 25));    box->box(FL_ENGRAVED_BOX);    box->label(label);    box->color(fl_rgb_color(192, 128, 128));    m_Pack->size(m_Pack->w(), m_Pack->h() + 25);    m_Pack->add(box.release());}// add a menu row.  A "Menu row" is a drop-down box with a label.Fl_Choice* CEntryFormTable::AddMenuRow(const char* label_value,                                       CEntryFormMenu& map_data,                                       int current_value,                                       void *user_data){    if (current_value == 0) {        _TRACE("CEntryFormTable::AddMenuRow(): current value = 0 ==> empty Fl_Choice");    }    const int row_ht = 25;    // If row already exists, must include spacing for height calculations    int h;    if (m_Pack->h()) {        h = m_Pack->h() + row_ht + m_Pack->spacing();    } else {        h = m_Pack->h() + row_ht;    }    // label and value width    int lw = int (m_Pack->w() / 3);    int vw = m_Pack->w() - lw;    // create a group for this row    auto_ptr<Fl_Group> group(new Fl_Group(0, 0, m_Pack->w(), row_ht));    Fl_Box* label = new Fl_Box(0, 0, lw, row_ht);    label->label(label_value);    label->labeltype(FL_NORMAL_LABEL);    label->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT);    label->box(FL_BORDER_FRAME);    Fl_Choice* choice = new Fl_Choice(lw, 0, vw, row_ht);    choice->copy(map_data.GetMenuItems());    choice->value(current_value);    choice->box(FL_EMBOSSED_BOX);    choice->color(FL_BACKGROUND2_COLOR);    choice->user_data(user_data);    group->resizable(choice);    group->end();    m_Pack->size(m_Pack->w(), h);    m_Pack->add(group.release());    return choice;}// add an input row.  This is a generic handler for built-in types, and// supports multiline, single-line, and validated input (password, integer,// double, file)Fl_Input* CEntryFormTable::AddInputRow(const char* label_value,                                       const char* current_value,                                       EInputType type){    int row_ht = 25;    // label and value width    int lw = int (m_Pack->w() / 3);    int vw = m_Pack->w() - lw;    // create our input item    Fl_Input* input = NULL;    Fl_Button* button = NULL;    switch (type) {    default:    case eMultiLine:        row_ht = 80;        input = new Fl_Multiline_Input(lw, 0, vw, row_ht);        input->wrap(1);        break;    case eSingleLine:        row_ht = 25;        input = new Fl_Input(lw, 0, vw, row_ht);        break;    case eFile:        row_ht = 35;        input = new Fl_File_Input(lw, 0, vw - 30, row_ht);        // we also need a button...        button = new Fl_Button(lw + vw - 22, 13, 19, 19);        button->label("...");        button->callback((Fl_Callback*)&CEntryFormTable::cb_FileOpen,                         (void*)input);        break;    case eInteger:        row_ht = 25;        input = new Fl_Int_Input(lw, 0, vw, row_ht);        break;    case eDouble:        row_ht = 25;        input = new Fl_Float_Input(lw, 0, vw, row_ht);        break;    case eSecret:        row_ht = 25;        input = new Fl_Secret_Input(lw, 0, vw, row_ht);        break;    }    _ASSERT(input);    input->value(current_value);    input->color(FL_BACKGROUND2_COLOR);    // create a label to go with this as well...    Fl_Box*   label = new Fl_Box(0, 0, lw, row_ht);    label->label(label_value);    label->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT |                 FL_ALIGN_CLIP | FL_ALIGN_WRAP);    // create a group for this row    Fl_Group*  group  = new Fl_Group(0, 0, m_Pack->w(), row_ht);    group->add(label);    group->add_resizable(*input);    if (button) {        group->add(button);    }    group->end();    int h = m_Pack->h() + row_ht;    m_Pack->size(m_Pack->w(), h);    m_Pack->add(group);    return input;}void CEntryFormTable::End() {    int ht = m_Pack->h();    ht += m_Pack->children() * m_Pack->spacing();    resize(0, 0, w(), ht);    add(m_Pack);}// internal callback for file open dialogsvoid CEntryFormTable::cb_FileOpen(Fl_Widget* w, void* data){    Fl_Input* input = reinterpret_cast<Fl_Input*> (data);    if ( !input ) {        return;    }    string str = NcbiFileBrowser("Open a file...", "", input->value());    input->value(str.c_str());}END_NCBI_SCOPE/* * =========================================================================== * $Log: table.cpp,v $ * Revision 1000.2  2004/06/01 20:46:38  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * * Revision 1.16  2004/05/21 22:27:41  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.15  2004/03/11 17:33:21  dicuccio * Use new file dialog * * Revision 1.14  2004/01/13 20:34:10  dicuccio * Pass the current file into the file selector as the selected file * * Revision 1.13  2004/01/06 20:13:41  dicuccio * Made the '...' button smaller for file inputs * * Revision 1.12  2003/12/31 20:28:17  dicuccio * Use '...' instead of '>>' for file selection * * Revision 1.11  2003/12/17 21:02:22  jcherry * Cosmetic change to file input * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?