"Fossies" - the Fresh Open Source Software Archive

Member "xfe-1.43.2/src/DirHistBox.cpp" (6 Jun 2019, 3683 Bytes) of package /linux/privat/xfe-1.43.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "DirHistBox.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.43.1_vs_1.43.2.

    1 // Display a history list box and allows the user to select a string
    2 // This is based on FXChoiceBox
    3 
    4 #include "config.h"
    5 #include "i18n.h"
    6 
    7 #include <fx.h>
    8 #include <fxkeys.h>
    9 
   10 #include "xfedefs.h"
   11 #include "DirHistBox.h"
   12 
   13 
   14 #define VISIBLE_LINES    10
   15 
   16 
   17 // Map
   18 FXDEFMAP(DirHistBox) DirHistBoxMap[] =
   19 {
   20     FXMAPFUNC(SEL_KEYPRESS, 0, DirHistBox::onKeyPress),
   21     FXMAPFUNC(SEL_KEYRELEASE, 0, DirHistBox::onKeyRelease),
   22     FXMAPFUNC(SEL_FOCUSOUT, 0, DirHistBox::onCmdClose),
   23     FXMAPFUNC(SEL_COMMAND, DirHistBox::ID_CLOSE, DirHistBox::onCmdClose),
   24     FXMAPFUNC(SEL_CLICKED, DirHistBox::ID_CLICKED, DirHistBox::onCmdClicked),
   25 };
   26 
   27 
   28 // Object implementation
   29 FXIMPLEMENT(DirHistBox, DialogBox, DirHistBoxMap, ARRAYNUMBER(DirHistBoxMap))
   30 
   31 
   32 // Construct list box with given caption, icon, message text, and with choices from array of strings
   33 DirHistBox::DirHistBox(FXWindow* owner, const char** choices, FXuint opts, int x, int y, int w, int h) :
   34     DialogBox(owner, "", opts, x, y, w, h, 0, 0, 0, 0, 0, 0)
   35 {
   36     register int       n;
   37     FXHorizontalFrame* hor = new FXHorizontalFrame(this, FRAME_RAISED|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
   38 
   39     list = new FXList(hor, this, ID_CLICKED, LIST_BROWSESELECT|LAYOUT_FILL_Y|LAYOUT_FILL_X|HSCROLLING_OFF);
   40     list->setBackColor(this->getBackColor());
   41     n = list->fillItems(choices);
   42     list->setNumVisible(FXMIN(n, VISIBLE_LINES));
   43 }
   44 
   45 
   46 // Construct list box with given caption, icon, message text, and with choices from newline separated strings
   47 DirHistBox::DirHistBox(FXWindow* owner, const FXString& choices, FXuint opts, int x, int y, int w, int h) :
   48     DialogBox(owner, "", opts, x, y, w, h, 0, 0, 0, 0, 0, 0)
   49 {
   50     register int       n;
   51     FXHorizontalFrame* hor = new FXHorizontalFrame(this, FRAME_RAISED|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
   52 
   53     list = new FXList(hor, this, ID_CLICKED, LIST_BROWSESELECT|LAYOUT_FILL_Y|LAYOUT_FILL_X|HSCROLLING_OFF);
   54     list->setBackColor(this->getBackColor());
   55     n = list->fillItems(choices);
   56     list->setNumVisible(FXMIN(n, VISIBLE_LINES));
   57 }
   58 
   59 
   60 // Select item when click in list
   61 long DirHistBox::onCmdClicked(FXObject*, FXSelector, void*)
   62 {
   63     getApp()->stopModal(this, list->getCurrentItem());
   64     hide();
   65     return(1);
   66 }
   67 
   68 
   69 // Close dialog
   70 long DirHistBox::onCmdClose(FXObject*, FXSelector, void*)
   71 {
   72     getApp()->stopModal(this, -1);
   73     hide();
   74     return(1);
   75 }
   76 
   77 
   78 // Destroy list box
   79 DirHistBox::~DirHistBox()
   80 {
   81     list = (FXList*)-1L;
   82 }
   83 
   84 
   85 // Show a modal list dialog
   86 int DirHistBox::box(FXWindow* owner, FXuint opts, const char** choices, int x, int y, int w, int h)
   87 {
   88     DirHistBox box(owner, choices, opts, x, y, w, h);
   89 
   90     return(box.execute(PLACEMENT_DEFAULT));
   91 }
   92 
   93 
   94 // Show a modal list dialog
   95 int DirHistBox::box(FXWindow* owner, FXuint opts, const FXString& choices, int x, int y, int w, int h)
   96 {
   97     DirHistBox box(owner, choices, opts, x, y, w, h);
   98 
   99     return(box.execute(PLACEMENT_DEFAULT));
  100 }
  101 
  102 
  103 // Keyboard press; handle escape to close the dialog
  104 long DirHistBox::onKeyPress(FXObject* sender, FXSelector sel, void* ptr)
  105 {
  106     if (FXTopWindow::onKeyPress(sender, sel, ptr))
  107     {
  108         return(1);
  109     }
  110     if (((FXEvent*)ptr)->code == KEY_Escape)
  111     {
  112         handle(this, FXSEL(SEL_COMMAND, ID_CLOSE), NULL);
  113         return(1);
  114     }
  115     return(0);
  116 }
  117 
  118 
  119 // Keyboard release; handle escape to close the dialog
  120 long DirHistBox::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr)
  121 {
  122     if (FXTopWindow::onKeyRelease(sender, sel, ptr))
  123     {
  124         return(1);
  125     }
  126     if (((FXEvent*)ptr)->code == KEY_Escape)
  127     {
  128         return(1);
  129     }
  130     return(0);
  131 }