swad-core/swad_box.c

240 lines
8.2 KiB
C
Raw Normal View History

2017-06-10 21:38:48 +02:00
// swad_box.c: layout of boxes
/*
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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2017-06-10 21:38:48 +02: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 <stdbool.h> // For boolean type
#include <stdio.h> // For fprintf
2019-07-04 12:58:15 +02:00
#include <stdlib.h> // For malloc and free
2017-06-10 21:38:48 +02:00
#include "swad_action.h"
#include "swad_box.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2017-06-10 21:38:48 +02:00
#include "swad_global.h"
#include "swad_help.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2017-06-10 21:38:48 +02:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
2019-05-14 09:03:48 +02:00
/*****************************************************************************/
2019-07-04 10:13:51 +02:00
/***************************** Private variables *****************************/
2019-05-14 09:03:48 +02:00
/*****************************************************************************/
2017-06-10 21:38:48 +02:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Box_StartBoxInternal (const char *Width,const char *Title,
2019-03-25 19:05:10 +01:00
void (*FunctionToDrawContextualIcons) (void),
const char *HelpLink,Box_Closable_t Closable,
const char *ClassFrame);
2017-06-10 21:38:48 +02:00
/*****************************************************************************/
2017-06-12 14:16:33 +02:00
/******************* Start and end a table with rounded box ******************/
2017-06-10 21:38:48 +02:00
/*****************************************************************************/
// CellPadding must be 0, 1, 2, 4 or 8
void Box_StartBoxTable (const char *Width,const char *Title,
void (*FunctionToDrawContextualIcons) (void),
2017-06-12 15:03:29 +02:00
const char *HelpLink,Box_Closable_t Closable,
2017-06-10 21:38:48 +02:00
unsigned CellPadding) // CellPadding must be 0, 1, 2, 5 or 10
{
2019-10-25 22:48:34 +02:00
Box_BoxBegin (Width,Title,FunctionToDrawContextualIcons,
2017-06-12 15:03:29 +02:00
HelpLink,Closable);
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (CellPadding);
2017-06-10 21:38:48 +02:00
}
void Box_StartBoxTableShadow (const char *Width,const char *Title,
void (*FunctionToDrawContextualIcons) (void),
const char *HelpLink,
unsigned CellPadding) // CellPadding must be 0, 1, 2, 5 or 10
{
Box_StartBoxShadow (Width,Title,
2017-06-11 22:26:40 +02:00
FunctionToDrawContextualIcons,
HelpLink);
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (CellPadding);
2017-06-10 21:38:48 +02:00
}
2019-10-25 22:48:34 +02:00
void Box_BoxBegin (const char *Width,const char *Title,
2017-06-10 21:38:48 +02:00
void (*FunctionToDrawContextualIcons) (void),
2017-06-12 15:03:29 +02:00
const char *HelpLink,Box_Closable_t Closable)
2017-06-10 21:38:48 +02:00
{
Box_StartBoxInternal (Width,Title,
FunctionToDrawContextualIcons,
2017-06-12 15:03:29 +02:00
HelpLink,Closable,
2017-06-10 21:38:48 +02:00
"FRAME");
}
void Box_StartBoxShadow (const char *Width,const char *Title,
void (*FunctionToDrawContextualIcons) (void),
const char *HelpLink)
{
Box_StartBoxInternal (Width,Title,
FunctionToDrawContextualIcons,
2017-06-12 15:03:29 +02:00
HelpLink,Box_NOT_CLOSABLE,
2017-06-10 21:38:48 +02:00
"FRAME_SHADOW");
}
2019-07-04 10:13:51 +02:00
// Return pointer to box id string
2017-06-10 21:38:48 +02:00
static void Box_StartBoxInternal (const char *Width,const char *Title,
2019-03-25 19:05:10 +01:00
void (*FunctionToDrawContextualIcons) (void),
const char *HelpLink,Box_Closable_t Closable,
const char *ClassFrame)
2017-06-10 21:38:48 +02:00
{
extern const char *Txt_Help;
extern const char *Txt_Close;
2019-07-04 10:13:51 +02:00
/***** Check level of nesting *****/
if (Gbl.Box.Nested >= Box_MAX_NESTED - 1) // Can not nest a new box
Lay_ShowErrorAndExit ("Box nesting limit reached.");
/***** Increase level of nesting *****/
Gbl.Box.Nested++;
/***** Create unique identifier for this box *****/
if (Closable == Box_CLOSABLE)
{
if ((Gbl.Box.Ids[Gbl.Box.Nested] = (char *) malloc (Frm_MAX_BYTES_ID + 1)) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for box id.");
}
else
Gbl.Box.Ids[Gbl.Box.Nested] = NULL;
2017-06-10 21:38:48 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box container *****/
2017-06-12 15:03:29 +02:00
if (Closable == Box_CLOSABLE)
2017-06-10 21:38:48 +02:00
{
/* Create unique id for alert */
2019-07-04 10:13:51 +02:00
Frm_SetUniqueId (Gbl.Box.Ids[Gbl.Box.Nested]);
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"FRAME_CONTAINER\" id=\"%s\"",Gbl.Box.Ids[Gbl.Box.Nested]);
2017-06-10 21:38:48 +02:00
}
2019-10-24 00:04:40 +02:00
else
HTM_DIV_Begin ("class=\"FRAME_CONTAINER\"");
2017-06-10 21:38:48 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2017-06-10 21:38:48 +02:00
if (Width)
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\" style=\"width:%s;\"",ClassFrame,Width);
else
HTM_DIV_Begin ("class=\"%s\"",ClassFrame);
2017-06-10 21:38:48 +02:00
/***** Row for left and right icons *****/
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"FRAME_ICO\"");
2017-06-10 21:38:48 +02:00
/* Contextual icons at left */
if (FunctionToDrawContextualIcons)
{
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"FRAME_ICO_LEFT\"");
2017-06-10 21:38:48 +02:00
FunctionToDrawContextualIcons ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2017-06-10 21:38:48 +02:00
}
/* Icons at right: help and close */
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"FRAME_ICO_RIGHT\"");
2017-06-10 21:38:48 +02:00
if (HelpLink) // Link to help
2019-01-12 03:00:59 +01:00
{
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"%s%s\" target=\"_blank\"",Hlp_WIKI,HelpLink);
2019-01-12 03:00:59 +01:00
Ico_PutDivIcon ("CONTEXT_OPT HLP_HIGHLIGHT",
"question.svg",Txt_Help);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-01-12 03:00:59 +01:00
}
2017-06-10 21:38:48 +02:00
2017-06-12 15:03:29 +02:00
if (Closable == Box_CLOSABLE) // Icon to close the box
2019-01-12 03:00:59 +01:00
{
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" onclick=\"toggleDisplay('%s');return false;\"",
Gbl.Box.Ids[Gbl.Box.Nested]);
2019-01-12 03:00:59 +01:00
Ico_PutDivIcon ("CONTEXT_OPT HLP_HIGHLIGHT",
"close.svg",Txt_Close);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-01-12 03:00:59 +01:00
}
2017-06-10 21:38:48 +02:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2017-06-10 21:38:48 +02:00
/***** End row for left and right icons *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2017-06-10 21:38:48 +02:00
/***** Frame title *****/
if (Title)
2019-10-23 20:07:56 +02:00
{
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"FRAME_TITLE %s\"",
Gbl.Box.Nested ? "FRAME_TITLE_SMALL" :
"FRAME_TITLE_BIG");
2019-11-10 12:36:37 +01:00
HTM_Txt (Title);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
}
2017-06-10 21:38:48 +02:00
}
void Box_EndBoxTable (void)
{
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-06-10 21:38:48 +02:00
}
2017-06-11 19:02:40 +02:00
void Box_EndBoxTableWithButton (Btn_Button_t Button,const char *TxtButton)
2017-06-10 21:38:48 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-06-10 21:38:48 +02:00
Box_EndBoxWithButton (Button,TxtButton);
}
2017-06-11 19:02:40 +02:00
void Box_EndBoxWithButton (Btn_Button_t Button,const char *TxtButton)
2017-06-10 21:38:48 +02:00
{
2017-06-11 19:02:40 +02:00
Btn_PutButton (Button,TxtButton);
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-06-10 21:38:48 +02:00
}
2019-10-25 22:48:34 +02:00
void Box_BoxEnd (void)
2017-06-10 21:38:48 +02:00
{
2019-07-04 10:13:51 +02:00
/***** Check level of nesting *****/
if (Gbl.Box.Nested < 0)
Lay_ShowErrorAndExit ("Trying to end a box not open.");
/***** Free memory allocated for box id string *****/
if (Gbl.Box.Ids[Gbl.Box.Nested])
free (Gbl.Box.Ids[Gbl.Box.Nested]);
2017-06-10 21:38:48 +02:00
2017-06-12 14:16:33 +02:00
/***** End box and box container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
HTM_DIV_End ();
2019-07-04 10:13:51 +02:00
/***** Decrease level of nesting *****/
Gbl.Box.Nested--;
2017-06-10 21:38:48 +02:00
}