swad-core/swad_theme.c

385 lines
13 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_theme.c: themes (colour layouts)
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************** Headers **********************************/
/*****************************************************************************/
#include <string.h>
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_config.h"
#include "swad_database.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2019-10-23 20:07:56 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_layout.h"
#include "swad_parameter.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2021-10-24 20:32:09 +02:00
#include "swad_setting_database.h"
2014-12-01 23:55:08 +01:00
#include "swad_theme.h"
/*****************************************************************************/
/*************** External global variables from others modules ***************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/******************************** Private constants **************************/
/*****************************************************************************/
2017-03-08 14:12:33 +01:00
#define The_MAX_BYTES_THEME_ID 16
2014-12-01 23:55:08 +01:00
const char *The_ThemeId[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "white",
[The_THEME_GREY ] = "grey",
[The_THEME_PURPLE] = "purple",
[The_THEME_BLUE ] = "blue",
[The_THEME_YELLOW] = "yellow",
[The_THEME_PINK ] = "pink",
[The_THEME_DARK ] = "dark",
2014-12-01 23:55:08 +01:00
};
const char *The_ThemeNames[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "White",
[The_THEME_GREY ] = "Grey",
[The_THEME_PURPLE] = "Purple",
[The_THEME_BLUE ] = "Blue",
[The_THEME_YELLOW] = "Yellow",
[The_THEME_PINK ] = "Pink",
[The_THEME_DARK ] = "Dark",
};
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkInBox[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_IN_WHITE",
[The_THEME_GREY ] = "BT_LINK FORM_IN_GREY",
[The_THEME_PURPLE] = "BT_LINK FORM_IN_PURPLE",
[The_THEME_BLUE ] = "BT_LINK FORM_IN_BLUE",
[The_THEME_YELLOW] = "BT_LINK FORM_IN_YELLOW",
[The_THEME_PINK ] = "BT_LINK FORM_IN_PINK",
[The_THEME_DARK ] = "BT_LINK FORM_IN_DARK",
2019-11-18 14:21:01 +01:00
};
2019-11-22 01:04:03 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBox[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_IN_WHITE",
[The_THEME_GREY ] = "FORM_IN_GREY",
[The_THEME_PURPLE] = "FORM_IN_PURPLE",
[The_THEME_BLUE ] = "FORM_IN_BLUE",
[The_THEME_YELLOW] = "FORM_IN_YELLOW",
[The_THEME_PINK ] = "FORM_IN_PINK",
[The_THEME_DARK ] = "FORM_IN_DARK",
2014-12-01 23:55:08 +01:00
};
2015-07-28 00:16:09 +02:00
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkInBoxBold[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_IN_WHITE BOLD",
[The_THEME_GREY ] = "BT_LINK FORM_IN_GREY BOLD",
[The_THEME_PURPLE] = "BT_LINK FORM_IN_PURPLE BOLD",
[The_THEME_BLUE ] = "BT_LINK FORM_IN_BLUE BOLD",
[The_THEME_YELLOW] = "BT_LINK FORM_IN_YELLOW BOLD",
[The_THEME_PINK ] = "BT_LINK FORM_IN_PINK BOLD",
[The_THEME_DARK ] = "BT_LINK FORM_IN_DARK BOLD",
2019-11-18 14:21:01 +01:00
};
2019-11-22 01:04:03 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBoxBold[The_NUM_THEMES] =
2015-12-25 22:05:28 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_IN_WHITE BOLD",
[The_THEME_GREY ] = "FORM_IN_GREY BOLD",
[The_THEME_PURPLE] = "FORM_IN_PURPLE BOLD",
[The_THEME_BLUE ] = "FORM_IN_BLUE BOLD",
[The_THEME_YELLOW] = "FORM_IN_YELLOW BOLD",
[The_THEME_PINK ] = "FORM_IN_PINK BOLD",
[The_THEME_DARK ] = "FORM_IN_DARK BOLD",
2015-12-25 22:05:28 +01:00
};
2019-11-18 17:59:02 +01:00
const char *The_ClassFormLinkInBoxNoWrap[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_IN_WHITE NOWRAP",
[The_THEME_GREY ] = "BT_LINK FORM_IN_GREY NOWRAP",
[The_THEME_PURPLE] = "BT_LINK FORM_IN_PURPLE NOWRAP",
[The_THEME_BLUE ] = "BT_LINK FORM_IN_BLUE NOWRAP",
[The_THEME_YELLOW] = "BT_LINK FORM_IN_YELLOW NOWRAP",
[The_THEME_PINK ] = "BT_LINK FORM_IN_PINK NOWRAP",
[The_THEME_DARK ] = "BT_LINK FORM_IN_DARK NOWRAP",
2019-11-18 17:59:02 +01:00
};
2019-11-22 01:04:03 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBoxNoWrap[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_IN_WHITE NOWRAP",
[The_THEME_GREY ] = "FORM_IN_GREY NOWRAP",
[The_THEME_PURPLE] = "FORM_IN_PURPLE NOWRAP",
[The_THEME_BLUE ] = "FORM_IN_BLUE NOWRAP",
[The_THEME_YELLOW] = "FORM_IN_YELLOW NOWRAP",
[The_THEME_PINK ] = "FORM_IN_PINK NOWRAP",
[The_THEME_DARK ] = "FORM_IN_DARK NOWRAP",
2014-12-01 23:55:08 +01:00
};
2015-07-28 00:16:09 +02:00
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkOutBox[The_NUM_THEMES] =
2019-11-18 08:38:34 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_OUT_WHITE",
[The_THEME_GREY ] = "BT_LINK FORM_OUT_GREY",
[The_THEME_PURPLE] = "BT_LINK FORM_OUT_PURPLE",
[The_THEME_BLUE ] = "BT_LINK FORM_OUT_BLUE",
[The_THEME_YELLOW] = "BT_LINK FORM_OUT_YELLOW",
[The_THEME_PINK ] = "BT_LINK FORM_OUT_PINK",
[The_THEME_DARK ] = "BT_LINK FORM_OUT_DARK",
2019-11-18 11:23:48 +01:00
};
2019-11-18 08:38:34 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormOutBox[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_OUT_WHITE",
[The_THEME_GREY ] = "FORM_OUT_GREY",
[The_THEME_PURPLE] = "FORM_OUT_PURPLE",
[The_THEME_BLUE ] = "FORM_OUT_BLUE",
[The_THEME_YELLOW] = "FORM_OUT_YELLOW",
[The_THEME_PINK ] = "FORM_OUT_PINK",
[The_THEME_DARK ] = "FORM_OUT_DARK",
2019-02-22 21:47:50 +01:00
};
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkOutBoxBold[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_OUT_WHITE BOLD",
[The_THEME_GREY ] = "BT_LINK FORM_OUT_GREY BOLD",
[The_THEME_PURPLE] = "BT_LINK FORM_OUT_PURPLE BOLD",
[The_THEME_BLUE ] = "BT_LINK FORM_OUT_BLUE BOLD",
[The_THEME_YELLOW] = "BT_LINK FORM_OUT_YELLOW BOLD",
[The_THEME_PINK ] = "BT_LINK FORM_OUT_PINK BOLD",
[The_THEME_DARK ] = "BT_LINK FORM_OUT_DARK BOLD",
2019-11-18 14:21:01 +01:00
};
2019-02-22 21:47:50 +01:00
const char *The_ClassFormOutBoxBold[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_OUT_WHITE BOLD",
[The_THEME_GREY ] = "FORM_OUT_GREY BOLD",
[The_THEME_PURPLE] = "FORM_OUT_PURPLE BOLD",
[The_THEME_BLUE ] = "FORM_OUT_BLUE BOLD",
[The_THEME_YELLOW] = "FORM_OUT_YELLOW BOLD",
[The_THEME_PINK ] = "FORM_OUT_PINK BOLD",
[The_THEME_DARK ] = "FORM_OUT_DARK BOLD",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassDat[The_NUM_THEMES] =
{
[The_THEME_WHITE ] = "DAT_WHITE",
[The_THEME_GREY ] = "DAT_GREY",
[The_THEME_PURPLE] = "DAT_PURPLE",
[The_THEME_BLUE ] = "DAT_BLUE",
[The_THEME_YELLOW] = "DAT_YELLOW",
[The_THEME_PINK ] = "DAT_PINK",
[The_THEME_DARK ] = "DAT_DARK",
};
const char *The_ClassDatStrong[The_NUM_THEMES] =
{
[The_THEME_WHITE ] = "DAT_STRONG_WHITE",
[The_THEME_GREY ] = "DAT_STRONG_GREY",
[The_THEME_PURPLE] = "DAT_STRONG_PURPLE",
[The_THEME_BLUE ] = "DAT_STRONG_BLUE",
[The_THEME_YELLOW] = "DAT_STRONG_YELLOW",
[The_THEME_PINK ] = "DAT_STRONG_PINK",
[The_THEME_DARK ] = "DAT_STRONG_DARK",
};
const char *The_ClassDatLight[The_NUM_THEMES] =
{
[The_THEME_WHITE ] = "DAT_LIGHT_WHITE",
[The_THEME_GREY ] = "DAT_LIGHT_GREY",
[The_THEME_PURPLE] = "DAT_LIGHT_PURPLE",
[The_THEME_BLUE ] = "DAT_LIGHT_BLUE",
[The_THEME_YELLOW] = "DAT_LIGHT_YELLOW",
[The_THEME_PINK ] = "DAT_LIGHT_PINK",
[The_THEME_DARK ] = "DAT_LIGHT_DARK",
};
const char *The_ClassInput[The_NUM_THEMES] =
{
[The_THEME_WHITE ] = "INPUT_WHITE",
[The_THEME_GREY ] = "INPUT_GREY",
[The_THEME_PURPLE] = "INPUT_PURPLE",
[The_THEME_BLUE ] = "INPUT_BLUE",
[The_THEME_YELLOW] = "INPUT_YELLOW",
[The_THEME_PINK ] = "INPUT_PINK",
[The_THEME_DARK ] = "INPUT_DARK",
};
const char *The_Colors[The_NUM_THEMES] =
{
[The_THEME_WHITE ] = "WHITE",
[The_THEME_GREY ] = "GREY",
[The_THEME_PURPLE] = "PURPLE",
[The_THEME_BLUE ] = "BLUE",
[The_THEME_YELLOW] = "YELLOW",
[The_THEME_PINK ] = "PINK",
[The_THEME_DARK ] = "DARK",
};
2016-11-07 13:04:47 +01:00
/*****************************************************************************/
/****************************** Private prototypes ***************************/
/*****************************************************************************/
2020-04-08 03:41:05 +02:00
static void The_PutIconsTheme (__attribute__((unused)) void *Args);
2016-11-07 13:04:47 +01:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Put icons to select a theme ***********************/
/*****************************************************************************/
void The_PutIconsToSelectTheme (void)
{
2019-03-26 11:53:21 +01:00
extern const char *Hlp_PROFILE_Settings_theme;
2015-01-01 15:50:45 +01:00
extern const char *Txt_Theme_SKIN;
2014-12-01 23:55:08 +01:00
The_Theme_t Theme;
2019-01-12 03:00:59 +01:00
char Icon[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Theme_SKIN,
2020-04-08 03:41:05 +02:00
The_PutIconsTheme,NULL,
2019-03-26 11:53:21 +01:00
Hlp_PROFILE_Settings_theme,Box_NOT_CLOSABLE);
2021-10-24 20:32:09 +02:00
Set_BeginSettingsHead ();
Set_BeginOneSettingSelector ();
for (Theme = (The_Theme_t) 0;
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
Theme++)
{
if (Theme == Gbl.Prefs.Theme)
HTM_DIV_Begin ("class=\"PREF_ON PREF_ON_%s\"",
The_Colors[Gbl.Prefs.Theme]);
else
HTM_DIV_Begin ("class=\"PREF_OFF\"");
Frm_BeginForm (ActChgThe);
Par_PutHiddenParamString (NULL,"Theme",The_ThemeId[Theme]);
snprintf (Icon,sizeof (Icon),"%s/%s/theme_32x20.gif",
Cfg_ICON_FOLDER_THEMES,The_ThemeId[Theme]);
Ico_PutSettingIconLink (Icon,Ico_UNCHANGED,The_ThemeNames[Theme]);
Frm_EndForm ();
2021-10-24 20:32:09 +02:00
HTM_DIV_End ();
}
Set_EndOneSettingSelector ();
Set_EndSettingsHead ();
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-11-07 13:04:47 +01:00
}
/*****************************************************************************/
2019-03-26 11:53:21 +01:00
/****************** Put contextual icons in theme setting ********************/
2016-11-07 13:04:47 +01:00
/*****************************************************************************/
2020-04-08 03:41:05 +02:00
static void The_PutIconsTheme (__attribute__((unused)) void *Args)
2016-11-07 13:04:47 +01:00
{
2020-04-08 03:41:05 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_THEMES);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************************* Change theme ******************************/
/*****************************************************************************/
void The_ChangeTheme (void)
{
2018-10-04 21:57:25 +02:00
char Path[PATH_MAX + 1 +
NAME_MAX + 1 +
NAME_MAX + 1];
2014-12-01 23:55:08 +01:00
/***** Get param theme *****/
Gbl.Prefs.Theme = The_GetParamTheme ();
The_SetColorRows ();
snprintf (Path,sizeof (Path),"%s/%s",
Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Gbl.Prefs.Theme]);
Str_Copy (Gbl.Prefs.URLTheme,Path,sizeof (Gbl.Prefs.URLTheme) - 1);
2014-12-01 23:55:08 +01:00
/***** Store theme in database *****/
if (Gbl.Usrs.Me.Logged)
2021-10-24 20:32:09 +02:00
Set_DB_UpdateMySettingsAboutTheme (The_ThemeId[Gbl.Prefs.Theme]);
2014-12-01 23:55:08 +01:00
2019-03-26 11:53:21 +01:00
/***** Set settings from current IP *****/
Set_SetSettingsFromIP ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** Get parameter theme ***************************/
/*****************************************************************************/
The_Theme_t The_GetParamTheme (void)
{
2017-03-08 14:12:33 +01:00
char ThemeId[The_MAX_BYTES_THEME_ID + 1];
2014-12-01 23:55:08 +01:00
The_Theme_t Theme;
2017-03-08 14:12:33 +01:00
Par_GetParToText ("Theme",ThemeId,The_MAX_BYTES_THEME_ID);
2019-12-15 20:02:34 +01:00
for (Theme = (The_Theme_t) 0;
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
2014-12-01 23:55:08 +01:00
Theme++)
if (!strcmp (ThemeId,The_ThemeId[Theme]))
return Theme;
return The_THEME_DEFAULT;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Get theme from string **************************/
/*****************************************************************************/
The_Theme_t The_GetThemeFromStr (const char *Str)
{
The_Theme_t Theme;
2019-12-15 20:02:34 +01:00
for (Theme = (The_Theme_t) 0;
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
2014-12-01 23:55:08 +01:00
Theme++)
if (!strcasecmp (Str,The_ThemeId[Theme]))
return Theme;
return The_THEME_DEFAULT;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******** Set background colors for rows depending on selected theme *********/
/*****************************************************************************/
void The_SetColorRows (void)
{
static const char *The_ClassColorRows[2][The_NUM_THEMES] =
{
[0][The_THEME_WHITE ] = "COLOR0_WHITE",
[0][The_THEME_GREY ] = "COLOR0_GREY",
[0][The_THEME_PURPLE] = "COLOR0_PURPLE",
[0][The_THEME_BLUE ] = "COLOR0_BLUE",
[0][The_THEME_YELLOW] = "COLOR0_YELLOW",
[0][The_THEME_PINK ] = "COLOR0_PINK",
[0][The_THEME_DARK ] = "COLOR0_DARK",
[1][The_THEME_WHITE ] = "COLOR1_WHITE",
[1][The_THEME_GREY ] = "COLOR1_GREY",
[1][The_THEME_PURPLE] = "COLOR1_PURPLE",
[1][The_THEME_BLUE ] = "COLOR1_BLUE",
[1][The_THEME_YELLOW] = "COLOR1_YELLOW",
[1][The_THEME_PINK ] = "COLOR1_PINK",
[1][The_THEME_DARK ] = "COLOR1_DARK",
};
Gbl.ColorRows[0] = The_ClassColorRows[0][Gbl.Prefs.Theme]; // Darker
Gbl.ColorRows[1] = The_ClassColorRows[1][Gbl.Prefs.Theme]; // Lighter
}