2006-05-30 13:47:28 +00:00
|
|
|
#ifndef HEADER_Panel
|
|
|
|
#define HEADER_Panel
|
|
|
|
/*
|
2006-06-06 20:28:42 +00:00
|
|
|
htop - Panel.h
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2006-05-30 13:47:28 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
2021-08-24 15:27:43 +00:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
|
|
|
#include <assert.h>
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2020-12-16 20:46:11 +00:00
|
|
|
#include "CRT.h"
|
2020-09-18 17:23:04 +00:00
|
|
|
#include "FunctionBar.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "Object.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "RichString.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "Vector.h"
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
|
|
|
|
struct Panel_;
|
2006-05-30 13:47:28 +00:00
|
|
|
typedef struct Panel_ Panel;
|
|
|
|
|
|
|
|
typedef enum HandlerResult_ {
|
2015-01-23 05:08:21 +00:00
|
|
|
HANDLED = 0x01,
|
|
|
|
IGNORED = 0x02,
|
|
|
|
BREAK_LOOP = 0x04,
|
2020-12-16 20:46:11 +00:00
|
|
|
REFRESH = 0x08,
|
|
|
|
REDRAW = 0x10,
|
|
|
|
RESCAN = 0x20,
|
2021-08-21 18:48:45 +00:00
|
|
|
RESIZE = 0x40,
|
|
|
|
SYNTH_KEY = 0x80,
|
2006-05-30 13:47:28 +00:00
|
|
|
} HandlerResult;
|
|
|
|
|
2020-10-27 20:26:33 +00:00
|
|
|
#define EVENT_SET_SELECTED (-1)
|
2015-03-25 02:12:43 +00:00
|
|
|
|
2020-10-27 20:26:33 +00:00
|
|
|
#define EVENT_HEADER_CLICK(x_) (-10000 + (x_))
|
|
|
|
#define EVENT_IS_HEADER_CLICK(ev_) ((ev_) >= -10000 && (ev_) <= -9000)
|
|
|
|
#define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000)
|
2008-03-05 06:54:30 +00:00
|
|
|
|
2020-12-16 20:46:11 +00:00
|
|
|
typedef HandlerResult (*Panel_EventHandler)(Panel*, int);
|
2020-12-28 22:26:14 +00:00
|
|
|
typedef void (*Panel_DrawFunctionBar)(Panel*, bool);
|
2020-12-22 16:12:38 +00:00
|
|
|
typedef void (*Panel_PrintHeader)(Panel*);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
typedef struct PanelClass_ {
|
|
|
|
const ObjectClass super;
|
|
|
|
const Panel_EventHandler eventHandler;
|
2020-12-16 20:46:11 +00:00
|
|
|
const Panel_DrawFunctionBar drawFunctionBar;
|
2020-12-22 16:12:38 +00:00
|
|
|
const Panel_PrintHeader printHeader;
|
2012-12-05 15:12:20 +00:00
|
|
|
} PanelClass;
|
|
|
|
|
2020-12-28 22:26:14 +00:00
|
|
|
#define As_Panel(this_) ((const PanelClass*)((this_)->super.klass))
|
|
|
|
#define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler
|
|
|
|
#define Panel_eventHandler(this_, ev_) (assert(As_Panel(this_)->eventHandler), As_Panel(this_)->eventHandler((Panel*)(this_), ev_))
|
|
|
|
#define Panel_drawFunctionBarFn(this_) As_Panel(this_)->drawFunctionBar
|
|
|
|
#define Panel_drawFunctionBar(this_, hideFB_) (assert(As_Panel(this_)->drawFunctionBar), As_Panel(this_)->drawFunctionBar((Panel*)(this_), hideFB_))
|
|
|
|
#define Panel_printHeaderFn(this_) As_Panel(this_)->printHeader
|
|
|
|
#define Panel_printHeader(this_) (assert(As_Panel(this_)->printHeader), As_Panel(this_)->printHeader((Panel*)(this_)))
|
2012-12-05 15:12:20 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
struct Panel_ {
|
|
|
|
Object super;
|
|
|
|
int x, y, w, h;
|
|
|
|
Vector* items;
|
|
|
|
int selected;
|
|
|
|
int oldSelected;
|
2016-06-15 15:45:23 +00:00
|
|
|
int selectedLen;
|
2015-01-22 01:27:31 +00:00
|
|
|
void* eventHandlerState;
|
2014-02-27 19:35:22 +00:00
|
|
|
int scrollV;
|
|
|
|
short scrollH;
|
2006-05-30 13:47:28 +00:00
|
|
|
bool needsRedraw;
|
2020-12-16 20:46:11 +00:00
|
|
|
bool wasFocus;
|
2015-03-23 18:26:56 +00:00
|
|
|
FunctionBar* currentBar;
|
|
|
|
FunctionBar* defaultBar;
|
2006-05-30 13:47:28 +00:00
|
|
|
RichString header;
|
2020-12-16 20:46:11 +00:00
|
|
|
ColorElements selectionColorId;
|
2006-05-30 13:47:28 +00:00
|
|
|
};
|
|
|
|
|
2020-10-31 19:39:01 +00:00
|
|
|
#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while (0)
|
2015-03-23 20:04:53 +00:00
|
|
|
|
2016-06-15 15:45:23 +00:00
|
|
|
#define KEY_CTRL(l) ((l)-'A'+1)
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
extern const PanelClass Panel_class;
|
2012-12-05 15:12:20 +00:00
|
|
|
|
2021-01-02 22:51:53 +00:00
|
|
|
Panel* Panel_new(int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_delete(Object* cast);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-10-04 15:55:08 +00:00
|
|
|
void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_done(Panel* this);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-12-16 20:46:11 +00:00
|
|
|
void Panel_setSelectionColor(Panel* this, ColorElements colorId);
|
2015-04-09 18:17:20 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_setHeader(Panel* this, const char* header);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_move(Panel* this, int x, int y);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_resize(Panel* this, int w, int h);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_prune(Panel* this);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_add(Panel* this, Object* o);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_insert(Panel* this, int i, Object* o);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_set(Panel* this, int i, Object* o);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
Object* Panel_get(Panel* this, int i);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
Object* Panel_remove(Panel* this, int i);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
Object* Panel_getSelected(Panel* this);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_moveSelectedUp(Panel* this);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_moveSelectedDown(Panel* this);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2021-01-05 22:42:55 +00:00
|
|
|
int Panel_getSelectedIndex(const Panel* this);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2021-01-05 22:42:55 +00:00
|
|
|
int Panel_size(const Panel* this);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Panel_setSelected(Panel* this, int selected);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-12-28 22:26:14 +00:00
|
|
|
void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected, bool hideFunctionBar);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-10-31 22:28:02 +00:00
|
|
|
void Panel_splice(Panel* this, Vector* from);
|
2020-08-26 00:15:00 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
bool Panel_onKey(Panel* this, int key);
|
2006-05-30 13:47:28 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
2011-11-18 06:08:56 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
#endif
|