gwenhywfar  4.3.3
dlg_showbox.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  begin       : Wed Feb 17 2010
00003  copyright   : (C) 2010 by Martin Preuss
00004  email       : martin@libchipcard.de
00005 
00006  ***************************************************************************
00007  *          Please see toplevel file COPYING for license details           *
00008  ***************************************************************************/
00009 
00010 
00011 #ifdef HAVE_CONFIG_H
00012 # include <config.h>
00013 #endif
00014 
00015 #define DISABLE_DEBUGLOG
00016 
00017 
00018 #include "dlg_showbox_p.h"
00019 
00020 #include <gwenhywfar/gwenhywfar.h>
00021 #include <gwenhywfar/pathmanager.h>
00022 #include <gwenhywfar/gui.h>
00023 #include <gwenhywfar/debug.h>
00024 
00025 
00026 
00027 #define DIALOG_MINWIDTH  200
00028 #define DIALOG_MINHEIGHT 50
00029 
00030 
00031 
00032 GWEN_INHERIT(GWEN_DIALOG, GWEN_DLGSHOWBOX)
00033 
00034 
00035 
00036 
00037 
00038 GWEN_DIALOG *GWEN_DlgShowBox_new(uint32_t flags,
00039                                  const char *title,
00040                                  const char *text) {
00041   GWEN_DIALOG *dlg;
00042   GWEN_DLGSHOWBOX *xdlg;
00043   GWEN_BUFFER *fbuf;
00044   int rv;
00045 
00046   dlg=GWEN_Dialog_new("dlg_gwen_showbox");
00047   GWEN_NEW_OBJECT(GWEN_DLGSHOWBOX, xdlg);
00048 
00049   GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGSHOWBOX, dlg, xdlg,
00050                        GWEN_DlgShowBox_FreeData);
00051 
00052   GWEN_Dialog_SetSignalHandler(dlg, GWEN_DlgShowBox_SignalHandler);
00053 
00054   /* get path of dialog description file */
00055   fbuf=GWEN_Buffer_new(0, 256, 0, 1);
00056   rv=GWEN_PathManager_FindFile(GWEN_PM_LIBNAME, GWEN_PM_SYSDATADIR,
00057                                "gwenhywfar/dialogs/dlg_showbox.dlg",
00058                                fbuf);
00059   if (rv<0) {
00060     DBG_INFO(GWEN_LOGDOMAIN, "Dialog description file not found (%d).", rv);
00061     GWEN_Buffer_free(fbuf);
00062     GWEN_Dialog_free(dlg);
00063     return NULL;
00064   }
00065 
00066   /* read dialog from dialog description file */
00067   rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf));
00068   if (rv<0) {
00069     DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
00070     GWEN_Buffer_free(fbuf);
00071     GWEN_Dialog_free(dlg);
00072     return NULL;
00073   }
00074   GWEN_Buffer_free(fbuf);
00075 
00076   xdlg->flags=flags;
00077   if (title)
00078     xdlg->title=strdup(title);
00079   if (text)
00080     xdlg->text=strdup(text);
00081 
00082   return dlg;
00083 }
00084 
00085 
00086 
00087 void GWENHYWFAR_CB GWEN_DlgShowBox_FreeData(void *bp, void *p) {
00088   GWEN_DLGSHOWBOX *xdlg;
00089 
00090   xdlg=(GWEN_DLGSHOWBOX*) p;
00091 
00092   free(xdlg->title);
00093   free(xdlg->text);
00094 
00095   GWEN_FREE_OBJECT(xdlg);
00096 }
00097 
00098 
00099 
00100 void GWEN_DlgShowBox_Init(GWEN_DIALOG *dlg) {
00101   GWEN_DLGSHOWBOX *xdlg;
00102   int i;
00103   GWEN_DB_NODE *dbParams;
00104 
00105   assert(dlg);
00106   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGSHOWBOX, dlg);
00107   assert(xdlg);
00108 
00109   dbParams=GWEN_Dialog_GetPreferences(dlg);
00110   assert(dbParams);
00111 
00112   /* read width */
00113   i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
00114   if (i>=DIALOG_MINWIDTH)
00115     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0);
00116 
00117   /* read height */
00118   i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
00119   if (i>=DIALOG_MINHEIGHT)
00120     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0);
00121 
00122   /* special stuff */
00123   if (xdlg->title)
00124     GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
00125 
00126   if (xdlg->text)
00127     GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
00128 
00129 
00130   xdlg->wasInit=1;
00131 }
00132 
00133 
00134 
00135 void GWEN_DlgShowBox_Fini(GWEN_DIALOG *dlg) {
00136   GWEN_DLGSHOWBOX *xdlg;
00137   int i;
00138   GWEN_DB_NODE *dbParams;
00139 
00140   assert(dlg);
00141   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGSHOWBOX, dlg);
00142   assert(xdlg);
00143 
00144   dbParams=GWEN_Dialog_GetPreferences(dlg);
00145   assert(dbParams);
00146 
00147   /* store dialog width */
00148   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
00149   if (i<DIALOG_MINWIDTH)
00150     i=DIALOG_MINWIDTH;
00151   GWEN_DB_SetIntValue(dbParams,
00152                       GWEN_DB_FLAGS_OVERWRITE_VARS,
00153                       "dialog_width",
00154                       i);
00155 
00156   /* store dialog height */
00157   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
00158   if (i<DIALOG_MINHEIGHT)
00159     i=DIALOG_MINHEIGHT;
00160   GWEN_DB_SetIntValue(dbParams,
00161                       GWEN_DB_FLAGS_OVERWRITE_VARS,
00162                       "dialog_height",
00163                       i);
00164 }
00165 
00166 
00167 
00168 
00169 int GWENHYWFAR_CB GWEN_DlgShowBox_SignalHandler(GWEN_DIALOG *dlg,
00170                                                 GWEN_DIALOG_EVENTTYPE t,
00171                                                 const char *sender) {
00172   GWEN_DLGSHOWBOX *xdlg;
00173 
00174   assert(dlg);
00175   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGSHOWBOX, dlg);
00176   assert(xdlg);
00177 
00178   switch(t) {
00179   case GWEN_DialogEvent_TypeInit:
00180     GWEN_DlgShowBox_Init(dlg);
00181     return GWEN_DialogEvent_ResultHandled;;
00182 
00183   case GWEN_DialogEvent_TypeFini:
00184     GWEN_DlgShowBox_Fini(dlg);
00185     return GWEN_DialogEvent_ResultHandled;;
00186 
00187   case GWEN_DialogEvent_TypeActivated:
00188   case GWEN_DialogEvent_TypeValueChanged:
00189   case GWEN_DialogEvent_TypeEnabled:
00190   case GWEN_DialogEvent_TypeDisabled:
00191 
00192   case GWEN_DialogEvent_TypeClose:
00193     return GWEN_DialogEvent_ResultAccept;
00194 
00195   case GWEN_DialogEvent_TypeLast:
00196     return GWEN_DialogEvent_ResultNotHandled;
00197   }
00198 
00199   return GWEN_DialogEvent_ResultNotHandled;
00200 
00201 }
00202 
00203 
00204 
00205