173 lines
6.4 KiB
C++
173 lines
6.4 KiB
C++
// Copyright 2021, Paul Mosier
|
|
//
|
|
// This file is part of Scriptura, a ncurses-based Bible study
|
|
// software for the libsword backend.
|
|
//
|
|
// Scriptura is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, under version 2 of the License.
|
|
//
|
|
// Scriptura is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Scriptura. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// pane.h -- header file for pane class
|
|
|
|
#ifndef PANE
|
|
#define PANE
|
|
|
|
#include <menu.h>
|
|
#include <form.h>
|
|
#include <string>
|
|
|
|
#include <swconfig.h>
|
|
|
|
#include "free.h"
|
|
|
|
//! Defines a window complex to display data retrieved from sword.
|
|
class pane {
|
|
WINDOW *win; //!< the window drawing the bounding box
|
|
char titlebar[40]; //!< window titlebar
|
|
bool hasFocus; //!< holds window focus status
|
|
|
|
WINDOW *pad; /*!< typically a pad holding buffer text, but may
|
|
* instead be a window holding a menu or form */
|
|
int padx; //!< pad bounding box upper left X coord
|
|
int pady; //!< pad bounding box upper left Y coord
|
|
int padrows; //!< the pad's number of rows
|
|
int padcols; //!< the pad's number of columns
|
|
|
|
int buflocx; //!< if pad is a true pad, our current X location
|
|
int buflocy; //!< if pad is a true pad, our current Y location
|
|
int bufsizex; //!< if pad is a true pad, it's full number of rows
|
|
int bufsizey; //!< if pad is a true pad, it's full number of columns
|
|
|
|
modkey mod; //!< module key associated with this pane
|
|
char* rawtext; //!< copy of unprocessed text the pane is showing
|
|
|
|
//! Refresh the title of the window.
|
|
void retitle();
|
|
|
|
/*! Take a text to display and format it for display, also creating the pad
|
|
* to hold it. */
|
|
void renderText();
|
|
|
|
/*! For floating panes, print out instruction lines that fit in the window
|
|
* bounds
|
|
* \returns the next available row in the window to print on. */
|
|
int printInstructions(int y, //!< starting y coord to print at
|
|
const char* inst //!< the line of text to print
|
|
);
|
|
|
|
public:
|
|
int x; //!< starting X location on screen
|
|
int y; //!< starting Y location on screen
|
|
int height; //!< full height of the pane
|
|
int width; //!< full width of the pane
|
|
|
|
//! Pane constructor.
|
|
pane(int starty, //!< the pane's upper left Y coord
|
|
int startx, //!< the pane's upper left Y coord
|
|
int lines, //!< the pane's number of lines
|
|
int cols, //!< the pane's number of columns
|
|
const char* title, //!< starting titlebar text
|
|
modkey defmod //!< starting modkey, or NULL if not applicable
|
|
);
|
|
|
|
//! Resize the window & pad, in the case of terminal resizing.
|
|
void resize(int starty, //!< starting y coord of pane
|
|
int startx, //!< starting x coord of pane
|
|
int lines, //!< new number of lines
|
|
int cols //!< new number of columns
|
|
);
|
|
|
|
//! Sets the title of the window & truncates if too long.
|
|
void setTitle(const char* newtitle //!< the new title to set
|
|
);
|
|
|
|
//! Have a pane display a string of text.
|
|
void loadText(const char* stext //!< the text to load
|
|
);
|
|
|
|
//! When the window changes, put them on the screen.
|
|
void redraw(bool borders = false /*!< Optional. If true, will refresh the
|
|
* window outer border. */
|
|
);
|
|
|
|
//! Move down a page in the window.
|
|
void nextPage();
|
|
|
|
//! Move down a line in the window.
|
|
void scrollDown();
|
|
|
|
//! Move up a line in the window.
|
|
void scrollUp();
|
|
|
|
//! Move up a page in the window.
|
|
void prevPage();
|
|
|
|
//! Toggles whether the pane has focus. Will refresh the window titlebar.
|
|
void toggleFocus();
|
|
|
|
/*! Have a pane display a generated menu for user selection.
|
|
* \returns integer index of selected item,
|
|
* -1 if escaping out,
|
|
* -2 if terminal was resized */
|
|
int loadMenu(starray opts //!< the array of strings used as menu items
|
|
);
|
|
|
|
/*! Have the pane display a form for user input.
|
|
* \returns a list of strings of user input, with starray.length = the
|
|
* length of input fields if successful, 0 if the user escaped out,
|
|
* and -1 if the terminal was resized */
|
|
starray loadForm(starray inputs, //!< list of form item descriptions
|
|
const char* secondinst //!< instruction line for top of form
|
|
);
|
|
|
|
//! Unpost a menu and free up all allocated memory for it.
|
|
void menuClean(MENU* menu, //!< the menu that was loaded
|
|
ITEM** items, //!< the array of menu items
|
|
int numitems //!< the number of menu items
|
|
);
|
|
|
|
//! Clean up a loaded form, freeing up all allocated memory
|
|
void formClean(FORM* form, //!< the form that was loaded
|
|
FIELD** fields, //!< the array of form fields
|
|
int numfields //!< the number of form fields
|
|
);
|
|
|
|
/*! Change the module associated with this pane - stores the module index
|
|
* and switches the pane title to be something else. */
|
|
void setModule(const char* newtitle, //!< the new titlebar for this pane
|
|
const char* newmod, //!< the new module to load in modkey
|
|
int keytype /*!< indicates how the module is keyed,
|
|
* see modkey in scabbard.h */
|
|
);
|
|
|
|
//! Change the searchkey associated with this pane.
|
|
void setKey(const char* newkey //!< the new searchkey to assign into modkey
|
|
);
|
|
|
|
//! Set the search parameters stored in the modkey for this pane.
|
|
void setSearch(int type, /*!< the search type int used by Sword:
|
|
* 0 - word or part
|
|
* 1 - phrase
|
|
* 2 - multiple words
|
|
* 3 - attribute (eg. Strongs) */
|
|
const char* scope //!< scope to search within, in key format
|
|
);
|
|
|
|
/*! Loads an entirely new modkey into the pane. Will call associated
|
|
* redrawing functions. */
|
|
void setModkey(modkey newmod, //!< new modkey to load in
|
|
const char* newtitle //!< new pane title to use
|
|
);
|
|
};
|
|
|
|
|
|
#endif
|