Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

App.c

Go to the documentation of this file.
00001 /*
00002  *    gui - [gega user interface] the flexible solution for user interface problems
00003  *    Copyright (C) 2002  Gergely Gati
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; version 2 of the License.
00008  *
00009  *    This program is distributed in the hope that it will be useful,
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *    GNU General Public License for more details.
00013  *
00014  *    You should have received a copy of the GNU General Public License
00015  *    along with this program; if not, write to the Free Software
00016  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  *    Gergely Gati
00019  *      email:           g.gati@freemail.hu
00020  *      AIM screenname:  GatiGergely
00021  *      ICQ number:      93131690
00022  *
00023  */
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 
00028 #include <App.h>
00029 #include <Window.h>
00030 #include <gadgets/gadget_Group.h>
00031 #include <gadgets/gadget_Test.h>
00032 #include <gadgets/gadget_Icon.h>
00033 #include <gadgets/gadget_Space.h>
00034 #include <gadgets/gadget_Button.h>
00035 #include <gadgets/gadget_Compound.h>
00036 #include <gadgets/gadget_Scroller.h>
00037 #include <classes.h>
00038 
00039 #include <Client.h>
00040 
00041 
00042 static char *ggpix[]={ "pix_desc.png", "pix_desc2.png" };
00043 static int actpix=0;
00044 static char myapp[]="TestApp";
00045 static Window_t *mainwin;
00046 static gadget_Check_t checklist[]=
00047 {
00048  { 9, "Button", GADGET_REQUIRED },
00049  { 11, "Button", GADGET_REQUIRED },
00050  { 10, "Icon", 0L },
00051  GADGET_CHECK_DONE
00052 };
00053 static gadget_Check_t sub_checklist[]=
00054 {
00055  { 5, "Button", GADGET_REQUIRED },
00056  { 4, "Scroller", 0L },
00057  GADGET_CHECK_DONE
00058 };
00059 /*
00060 static char *guifile=\
00061   "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" \
00062   "<Gui app=\"TestApp\">" \
00063   "  <Layout id=\"SubWindow\" type=\"window\">" \
00064   "    <Group id=\"1\" weight=\"1\" orientation=\"horizontal\" gapsize=\"2\" bordersize=\"2\" backgroundcolor=\"#efefef\" font-name=\"Helvetica\" font-size=\"16\">" \
00065   "      <Group id=\"2\" weight=\"5\" orientation=\"vertical\" gapsize=\"2\" bordersize=\"0\">" \
00066   "        <Group weight=\"1\" orientation=\"horizontal\" gapsize=\"1\" bordersize=\"1\" backgroundcolor=\"#661111\">" \
00067   "          <Icon id=\"6\" weight=\"10\" image=\"pix_gega.jpg\" />" \
00068   "          <Test weight=\"1\" color=\"#ff0000\" />" \
00069   "        </Group>" \
00070   "        <Test id=\"3\" weight=\"2\" />" \
00071   "        <Scroller id=\"4\" weight=\"5\" orientation=\"horizontal\" total=\"100\" visible=\"25\" position=\"50\" />" \
00072   "        <Space weight=\"1\" />" \
00073   "        <Button id=\"5\" weight=\"1\" label=\"#msg_close\" />" \
00074   "      </Group>" \
00075   "    </Group>" \
00076   "  </Layout>" \
00077   "  <Layout id=\"MainWindow\" type=\"window\">" \
00078   "    <Group id=\"1\" weight=\"1\" orientation=\"horizontal\" gapsize=\"2\" bordersize=\"2\" backgroundcolor=\"#efefef\" font-name=\"Arial\" font-size=\"16\">" \
00079   "      <Group weight=\"3\" orientation=\"vertical\" gapsize=\"2\" bordersize=\"0\">" \
00080   "        <Test weight=\"1\" color=\"#445577\" />" \
00081   "        <Space weight=\"1\" />" \
00082   "        <Icon id=\"10\" weight=\"8\" image=\"pix_desc.png\" />" \
00083   "        <Button id=\"9\" weight=\"10\" label=\"#msg_hellotelo\" />" \
00084   "      </Group>" \
00085   "      <Group id=\"8\" weight=\"5\" orientation=\"vertical\" gapsize=\"2\" bordersize=\"0\">" \
00086   "        <Test weight=\"1\" color=\"#ff0000\" />" \
00087   "        <Compound id=\"3\" weight=\"2\" />" \
00088   "        <Icon id=\"4\" weight=\"3\" skin=\"btn\" image=\"pix_arrow_up.pvc\" />" \
00089   "        <Button id=\"11\" weight=\"1\" skin=\"piros\" label=\"#msg_senkialfonz\" />" \
00090   "      </Group>" \
00091   "    </Group>" \
00092   "  </Layout>" \
00093   "</Gui>";
00094 */
00095 
00096 static int my_timer(Window_t *win, u32 userdata)
00097 {
00098 static int i=0;
00099   printf("timer_timeout %lu (%d)\n",userdata,i++);
00100   return((i<2?0:1));
00101 }
00102 
00103 
00104 static int sub_event_handler(gui_App_t *app, Window_t *win, u32 gadget_id, int event, u32 event_data)
00105 {
00106   int ret=CLIENT_DISCARD_EVENT;
00107   printf("SUB: sender=%ld -- EVENT: %d (DATA=%d)\n",gadget_id,event,(int)event_data);
00108   if(event==CBK_WINDOW_ACTIVATED) { ret=0; printf("SUBwindow activated\n"); }
00109   if(event==CBK_WINDOW_INACTIVATED) { ret=0; printf("SUBwindow inactivated\n"); }
00110   if(event==CBK_WINDOW_CLOSED) { ret=0; printf("window closed %ld\n",event_data); }
00111   if(event==CBK_WINDOW_OPENED) { ret=0; printf("window opened %ld\n",event_data); }
00112   if(event==CBK_GADGET_CLICKED&&gadget_id==5)
00113   {
00114     printf("sub window close!!\n");
00115     client_CloseWindow(app,win);
00116     ret=0;
00117   }
00118   if(event==CBK_GADGET_CLICKED&&gadget_id==7)
00119   {
00120     actpix=1-actpix;
00121     client_CallAGadget(app,mainwin,10,MET_ICON_SET_IMAGE,TAG_ICO_IMAGENAME,(u32)ggpix[actpix],TAG_DONE);
00122     ret=0;
00123   }
00124   if(event==CBK_WINDOW_CLOSE)
00125   {
00126     printf("sub window close!!(2)\n");
00127     client_CloseWindow(app,win);
00128     ret=0;
00129   }
00130   return(ret);
00131 }
00132 
00133 
00134 static int test_event_handler(gui_App_t *app, Window_t *win, u32 gadget_id, int event, u32 event_data)
00135 {
00136   static char *skins[3]={"tst3Skin","tst4Skin","tst2Skin"};
00137   static int currskin=0;
00138   int ret=CLIENT_DISCARD_EVENT;
00139   u32 rv=0L;
00140   Rect_t rct;
00141   Window_t *subwin;
00142 
00143   printf("sender=%ld -- EVENT: %d (DATA=%d)\n",gadget_id,event,(int)event_data);
00144   if(event==CBK_WINDOW_ACTIVATED) { ret=0; printf("MAINwindow activated\n"); }
00145   if(event==CBK_WINDOW_INACTIVATED) { ret=0; printf("MAINwindow inactivated\n"); }
00146   if(event==CBK_WINDOW_CLOSED) { ret=0; printf("window closed %ld\n",event_data); }
00147   if(event==CBK_WINDOW_OPENED) { ret=0; printf("window opened %ld\n",event_data); }
00148   if(event==CBK_CHILD_WINDOW_OPENED)
00149   {
00150     printf("CBK_CHILD_WINDOW_OPENED - subwindow\n");
00151     ret=0;
00152   }
00153   if(event==CBK_CHILD_WINDOW_CLOSED)
00154   {
00155     printf("CBK_CHILD_WINDOW_CLOSED - subwindow\n");
00156     ret=0;
00157   }
00158   if(event==CBK_GADGET_CLICKED&&gadget_id==9)
00159   {
00160     actpix=1-actpix;
00161     rv=client_CallSGadget(app,win,10,MET_ICON_SET_IMAGE,TAG_ICO_IMAGENAME,(u32)ggpix[actpix],TAG_DONE);
00162     ret=0;
00163   }
00164   if(event==CBK_GADGET_CLICKED&&gadget_id==20)
00165   {
00166     if(++currskin>2) currskin=0;
00167     printf("NEW SKIN: '%s'\n",skins[currskin]);
00168     client_ChangeSkin(app,win,skins[currskin]);
00169     ret=0;
00170   }
00171   if(event==CBK_GADGET_CLICKED&&gadget_id==11)
00172   {
00173     rct.left=150;
00174     rct.top=150;
00175     rct.width=300;
00176     rct.height=200;
00177     ret=0;
00178     if(NULL!=(subwin=client_OpenWindow(app,&rct,"SubWindow",
00179         sub_event_handler,GLWF_SMART_REFRESH,
00180         TAG_WIN_TITLE,(u32)"Test subwindow",
00181         TAG_WIN_PXTOP,40,
00182         TAG_WIN_PXLEFT,10,
00183         TAG_WIN_PXWIDTH,350,
00184         TAG_WIN_PXHEIGHT,250,
00185         TAG_WIN_FONTNAME, "Times",
00186         TAG_WIN_FONTSIZE, 20,
00187         TAG_WIN_CHECKLIST, (u32)sub_checklist,
00188         TAG_WIN_PARENT,win,
00189         TAG_WIN_PARENTDATA,3072,
00190         TAG_WIN_WINFLAGS,WIN_FLAGS_SLEEPPARENT|WIN_FLAGS_NOBORDER,
00191         TAG_WIN_USERDATA,1052L,
00192         TAG_DONE)
00193       )) {
00194         printf("window2 opened\n");
00195         }
00196   }
00197   if(event==CBK_WINDOW_CLOSE)
00198   {
00199     printf("hulye!!\n");
00200     client_CloseWindow(app,win);
00201     client_SendCloseApp(app->conn,app);
00202     ret=0;
00203   }
00204   return(ret);
00205 }
00206 
00207 
00208 char *app_name(void)
00209 {
00210   return(myapp);
00211 }
00212 
00213 
00214 int app_Init(gui_App_t *app)
00215 {
00216   Rect_t rct;
00217   Window_t *win;
00218 
00219   rct.left=100;
00220   rct.top=100;
00221   rct.width=600;
00222   rct.height=400;
00223   if(NULL!=(mainwin=win=client_OpenWindow(app,&rct,"MainWindow",
00224       test_event_handler,GLWF_SMART_REFRESH,
00225       TAG_WIN_TITLE,(u32)"Test application",
00226       TAG_WIN_TOP,10,
00227       TAG_WIN_BOTTOM,55,
00228       TAG_WIN_LEFT,10,
00229       TAG_WIN_RIGHT,60,
00230       TAG_WIN_FONTNAME, "Arial",
00231       TAG_WIN_FONTSIZE, 18,
00232       TAG_WIN_CHECKLIST, (u32)checklist,
00233       TAG_WIN_USERDATA,338L,
00234 //      TAG_WIN_GUI_FILE,(u32)guifile,
00235       TAG_DONE)
00236     )) client_TimerStart(app,win,10000,GUI_TIMER_REPEAT,(u32)112,my_timer);
00237 
00238   return(0);
00239 }
00240 
00241 
00242 void app_CleanUp(gui_App_t *app)
00243 {
00244   return;
00245 }

Generated on Tue Jan 7 12:11:18 2003 for THEGUI by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002