/*
* rofi
*
* MIT/X11 License
* Copyright © 2013-2023 Qball Cow <qball@gmpclient.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "config.h"
#include <glib.h>
#include <widgets/box.h>
#include <widgets/icon.h>
#include <widgets/listview.h>
#include <widgets/scrollbar.h>
#include <widgets/textbox.h>
#include <widgets/widget.h>
#include "settings.h"
#include "theme.h"
#include "view.h"
#include "timings.h"
/** Default spacing between the elements in the listview. */
#define DEFAULT_SPACING 2
/**
* Orientation of the listview
*/
/** Vertical (classical) list */
#define LISTVIEW ROFI_ORIENTATION_VERTICAL
/** Horizontal list. (barview) */
#define BARVIEW ROFI_ORIENTATION_HORIZONTAL
/**
* The moving direction of the selection, this (in barview) affects the
* scrolling.
*/
typedef enum { LEFT_TO_RIGHT = 0, RIGHT_TO_LEFT = 1 } MoveDirection;
typedef struct {
box *box;
textbox *textbox;
textbox *index;
icon *icon;
} _listview_row;
struct _listview {
widget widget;
RofiOrientation type;
// RChanged
// Text needs to be repainted.
unsigned int rchanged;
// The direction we pack the widgets.
RofiOrientation pack_direction;
// Administration
unsigned int cur_page;
unsigned int last_offset;
unsigned int selected;
unsigned int element_height;
unsigned int max_rows;
unsigned int max_elements;
//
gboolean fixed_columns;
unsigned int cur_columns;
unsigned int req_elements;
unsigned int cur_elements;
RofiDistance spacing;
unsigned int menu_lines;
unsigned int max_displayed_lines;
unsigned int menu_columns;
unsigned int fixed_num_lines;
unsigned int dynamic;
unsigned int eh;
unsigned int reverse;
gboolean require_input;
gboolean filtered;
gboolean cycle;
ScrollType scroll_type;
_listview_row *boxes;
scrollbar *scrollbar;
listview_update_callback callback;
void *udata;
listview_selection_changed_callback sc_callback;
void *sc_udata;
gboolean scrollbar_scroll;
xcb_timestamp_t last_click;
listview_mouse_activated_cb mouse_activated;
void *mouse_activated_data;
char *listview_name;
PangoEllipsizeMode emode;
/** Barview */
struct {
MoveDirection direction;
unsigned int cur_visible;
} barview;
};
/**
* Names used for theming the elements in the listview.
* Each row can have 3 modes, normal, selected and alternate.
* Each row can have 3 states, normal, urgent and active.
*/
const char *const listview_theme_prop_names[][3] = {
/** Normal row */
{"normal.normal", "selected.normal", "alternate.normal"},
/** Urgent row */
{"normal.urgent",