/* Monolith calendar widget. * - by Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: ml_calendar_visible.c,v 1.4 2003/02/22 15:34:27 rich Exp $ */ #include #include #include #ifdef HAVE_TIME_H #include #endif #ifdef HAVE_STRING_H #include #endif #include #include #include #include #include #include #include #include "ml_calendar_lib.h" #include "ml_calendar_visible.h" static void repaint (void *, ml_session, const char *, io_handle); struct ml_widget_operations calendar_visible_ops = { repaint: repaint }; struct ml_calendar_visible { struct ml_widget_operations *ops; pool pool; /* Pool for allocations. */ ml_session session; /* Current session. */ const char *conninfo; /* Database connection. */ ml_calendar calendar; /* Parent calendar. */ ml_flow_layout flow; /* List of calendars. */ }; static pool cal_vis_pool; static ml_text_label bullet; static void calendar_visible_init (void) __attribute__ ((constructor)); static void calendar_visible_stop (void) __attribute__ ((destructor)); static void calendar_visible_init () { cal_vis_pool = new_subpool (global_pool); bullet = new_ml_text_label (cal_vis_pool, "*"); } static void calendar_visible_stop () { delete_pool (cal_vis_pool); } ml_calendar_visible new_ml_calendar_visible (pool pool, ml_session session, const char *conninfo, ml_calendar calendar) { ml_calendar_visible w = pmalloc (pool, sizeof *w); w->ops = &calendar_visible_ops; w->pool = pool; w->session = session; w->conninfo = conninfo; w->calendar = calendar; return w; } extern void ml_calendar_visible_update (ml_calendar_visible w) { vector resids = _ml_calendar_get_calendars (w->calendar); db_handle dbh; st_handle sth; int resid; const char *resname; ml_text_label lbl; w->flow = new_ml_flow_layout (w->pool); /* Get the list of calendars from the database. */ dbh = get_db_handle (w->conninfo, DBI_THROW_ERRORS); sth = st_prepare_cached (dbh, "select c.resid, r.name " " from ml_calendar c, ml_resources r " " where c.resid in (@) and c.resid = r.resid " " order by 1", DBI_VECTOR_INT); st_execute (sth, resids); st_bind (sth, 0, resid, DBI_INT); st_bind (sth, 1, resname, DBI_STRING); while (st_fetch (sth)) { ml_flow_layout_pack (w->flow, bullet); lbl = new_ml_text_label (w->pool, resname); ml_widget_set_property (lbl, "color", _ml_calendar_colour (resid)); ml_flow_layout_pack (w->flow, lbl); } put_db_handle (dbh); } static void repaint (void *vw, ml_session session, const char *windowid, io_handle io) { ml_calendar_visible w = (ml_calendar_visible) vw; ml_widget_repaint (w->flow, session, windowid, io); }