/*
* rofi
*
* MIT/X11 License
* Copyright © 2013-2020 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/widget.h>
#include <widgets/textbox.h>
#include <widgets/scrollbar.h>
#include <widgets/icon.h>
#include <widgets/box.h>
#include <widgets/listview.h>
#include "settings.h"
#include "theme.h"
#include "timings.h"
/** Default spacing between the elements in the listview. */
#define DEFAULT_SPACING 2
/**
* Orientation of the listview
*/
typedef enum
{
/** Vertical (classical) list */
LISTVIEW = ROFI_ORIENTATION_VERTICAL,
/** Horizontal list. (barview) */
BARVIEW = ROFI_ORIENTATION_HORIZONTAL,
} ViewType;
/**
* 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;
ViewType type;
// RChanged
// Text needs to be repainted.
unsigned int rchanged;
// 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 cycle;
gboolean multi_select;
ScrollType scroll_type;
_listview_row * boxes;
scrollbar *scrollbar;
listview_update_callback callback;
void *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", "selected.urgent", "alternate.urgent" },
/** Active row */
{ "normal.active", "selected.active", "alternate.active" },
};
static void listview_set_style ( widget *w, TextBoxFontType tbft )
{
TextBoxFontType t = tbft & STATE_MASK;
if ( w == NULL ) {
return;
}
// ACTIVE has priority over URGENT if both set.
if ( t == ( URGENT | ACTIVE ) ) {
t = ACTIVE;
}
switch ( ( tbft & FMOD_MASK ) )
{
case HIGHLIGHT:
widget_set_state ( w, listview_theme_prop_names[t][1] );
break;
case ALT:
widget_set_state ( w, listview_theme_prop_names[t][2] );
break;
default:
widget_set_state ( w, listview_theme_prop_names[t][0] );
break;
}
}
static void listview_create_row ( listview *lv, _listview_row *row )
{
TextboxFlags flags = (