Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/dox


Modified Files:
        dox.c dox.h format.c text.c 


Log Message:
Enable using arrow keys for navigation.
Enable reloading file ('r').
Cleanups.

===================================================================
RCS file: /cvs/e/e16/e/dox/dox.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -3 -r1.42 -r1.43
--- dox.c       28 May 2007 17:09:11 -0000      1.42
+++ dox.c       21 Oct 2007 13:14:10 -0000      1.43
@@ -55,6 +55,8 @@
 Imlib_Image         im_prev1, im_prev2;
 Imlib_Image         im_next1, im_next2;
 Imlib_Image         im_exit1, im_exit2;
+
+static const char   doxdir[] = ENLIGHTENMENT_ROOT "/E-docs";
 char               *docdir = NULL;
 
 static Atom         ATOM_WM_DELETE_WINDOW = None;
@@ -164,18 +166,29 @@
 }
 
 static              Imlib_Image
-LoadImage(const char *file)
+ImageLoad(const char *dir, const char *file)
 {
    Imlib_Image         im;
    char                tmp[4096];
 
-   sprintf(tmp, "%s/E-docs/%s", ENLIGHTENMENT_ROOT, file);
-   findLocalizedFile(tmp);
+   Esnprintf(tmp, sizeof(tmp), "%s/%s", dir, file);
    im = imlib_load_image(tmp);
 
    return im;
 }
 
+static              Imlib_Image
+ImageLoadDox(const char *file)
+{
+   return ImageLoad(doxdir, file);
+}
+
+Imlib_Image
+ImageLoadDoc(const char *file)
+{
+   return ImageLoad(docdir, file);
+}
+
 static void
 ApplyImage1(Window win, Imlib_Image im)
 {
@@ -196,6 +209,31 @@
    imlib_render_image_on_drawable(0, 0);
 }
 
+static void
+LoadFile(const char *file, const char *docfile)
+{
+   char                s[4096];
+   FILE               *f;
+
+   f = fopen(file, "r");
+   if (!f)
+     {
+       strcpy(s, docdir);
+       strcat(s, "/");
+       strcat(s, docfile);
+       f = fopen(s, "r");
+       if (!f)
+         {
+            printf("Edoc_dir %s does not contain a %s file\n", docdir,
+                   docfile);
+            exit(1);
+         }
+     }
+
+   GetObjects(f);
+   fclose(f);
+}
+
 #define ApplyImage3(win, im) \
        XClearWindow(disp, win)
 
@@ -234,10 +272,9 @@
 int
 main(int argc, char **argv)
 {
-   int                 pagenum;
+   int                 pagenum, prev_pagenum;
    int                 i, w, h, t, x, y;
    int                 wx, wy;
-   FILE               *f;
    char               *s;
    const char         *docfile;
    Pixmap              draw = 0;
@@ -253,6 +290,14 @@
    y = 0;
    pagenum = 0;
 
+   if (argc < 1)
+     {
+       printf("usage:\n"
+              "%s [-page page_number] [-file Edoc_fname] [-size width height] 
[Edoc_dir]\n",
+              argv[0]);
+       exit(1);
+     }
+
    if ((disp = XOpenDisplay(NULL)) == NULL)
      {
        printf("%s: Cannot open X display.\n", argv[0]);
@@ -271,14 +316,6 @@
 
    VRootInit();
 
-   if (argc < 2)
-     {
-       printf("usage:\n"
-              "%s [-page page_number] [-file Edoc_fname] [-size width height] 
Edoc_dir\n",
-              argv[0]);
-       exit(1);
-     }
-
    docfile = "MAIN";
    for (i = 1; i < argc; i++)
      {
@@ -295,45 +332,26 @@
           docdir = strdup(argv[i]);
      }
    if (docdir == NULL)
-      docdir = strdup(".");
+      docdir = strdup(doxdir);
    s = EMALLOC(char, strlen(docdir) + strlen(docfile) + 2 + 20);
 
    sprintf(s, "%s/%s", docdir, docfile);
    findLocalizedFile(s);
 
-   im_title = LoadImage("title.png");
+   im_title = ImageLoadDox("title.png");
    imlib_context_set_image(im_title);
-
    ibd.left = 50;
    ibd.right = 2;
    ibd.top = 2;
    ibd.bottom = 2;
    imlib_image_set_border(&ibd);
 
-   im_prev1 = LoadImage("prev1.png");
-   im_prev2 = LoadImage("prev2.png");
-   im_next1 = LoadImage("next1.png");
-   im_next2 = LoadImage("next2.png");
-   im_exit1 = LoadImage("exit1.png");
-   im_exit2 = LoadImage("exit2.png");
-
-   f = fopen(s, "r");
-   if (!f)
-     {
-       strcpy(s, docdir);
-       strcat(s, "/");
-       strcat(s, docfile);
-       f = fopen(s, "r");
-       if (!f)
-         {
-            printf("Edoc_dir %s does not contain a %s file\n", docdir,
-                   docfile);
-            exit(1);
-         }
-     }
-
-   GetObjects(f);
-   fclose(f);
+   im_prev1 = ImageLoadDox("prev1.png");
+   im_prev2 = ImageLoadDox("prev2.png");
+   im_next1 = ImageLoadDox("next1.png");
+   im_next2 = ImageLoadDox("next2.png");
+   im_exit1 = ImageLoadDox("exit1.png");
+   im_exit2 = ImageLoadDox("exit2.png");
 
    t = 16;
    wx = (VRoot.w - w) / 2;
@@ -354,22 +372,13 @@
        screens = XineramaQueryScreens(disp, &num);
        for (i = 0; i < num; i++)
          {
-            if (pointer_x >= screens[i].x_org)
+            if (pointer_x >= screens[i].x_org &&
+                pointer_x <= (screens[i].width + screens[i].x_org) &&
+                pointer_y >= screens[i].y_org &&
+                pointer_y <= (screens[i].height + screens[i].y_org))
               {
-                 if (pointer_x <= (screens[i].width + screens[i].x_org))
-                   {
-                      if (pointer_y >= screens[i].y_org)
-                        {
-                           if (pointer_y <= (screens[i].height +
-                                             screens[i].y_org))
-                             {
-                                wx = ((screens[i].width - w) / 2)
-                                   + screens[i].x_org;
-                                wy = ((screens[i].height - (h + t)) / 2)
-                                   + screens[i].y_org;
-                             }
-                        }
-                   }
+                 wx = ((screens[i].width - w) / 2) + screens[i].x_org;
+                 wy = ((screens[i].height - (h + t)) / 2) + screens[i].y_org;
               }
          }
 
@@ -388,11 +397,13 @@
       XCreateSimpleWindow(disp, win_main, (w - 64 - 64 - t) + 64 + 64, 0, t, t,
                          0, 0, 0);
    win_text = XCreateSimpleWindow(disp, win_main, 0, t, w, h, 0, 0, 0);
+
+   XSelectInput(disp, win_main, KeyPressMask | KeyReleaseMask);
    XSelectInput(disp, win_prev, ButtonPressMask | ButtonReleaseMask);
    XSelectInput(disp, win_next, ButtonPressMask | ButtonReleaseMask);
    XSelectInput(disp, win_exit, ButtonPressMask | ButtonReleaseMask);
    XSelectInput(disp, win_text, ButtonPressMask | ButtonReleaseMask |
-               KeyPressMask | KeyReleaseMask | PointerMotionMask);
+               PointerMotionMask);
 
    draw = XCreatePixmap(disp, win_text, w, h, VRoot.depth);
 
@@ -401,6 +412,8 @@
    ApplyImage1(win_next, im_next1);
    ApplyImage1(win_exit, im_exit1);
 
+   LoadFile(s, docfile);
+
    l = RenderPage(draw, pagenum, w, h);
    UPDATE_NOW;
 
@@ -422,6 +435,8 @@
        KeySym              key;
        XEvent              ev;
 
+       prev_pagenum = pagenum;
+
        XNextEvent(disp, &ev);
        switch (ev.type)
          {
@@ -433,43 +448,73 @@
                  exit(0);
                  break;
               case XK_Down:
-              case XK_Right:
-                 break;
+                 goto do_next;
               case XK_Up:
-              case XK_Left:
-                 break;
-              case XK_Return:
-                 break;
+                 goto do_prev;
               case XK_Home:
-                 FREE_LINKS;
                  pagenum = 0;
-                 pagenum = FixPage(pagenum);
-                 l = RenderPage(draw, pagenum, w, h);
-                 UPDATE;
-                 break;
+                 page_hist_pos = 0;
+                 goto do_page;
               case XK_End:
-                 FREE_LINKS;
                  pagenum = 99999;
-                 pagenum = FixPage(pagenum);
-                 l = RenderPage(draw, pagenum, w, h);
-                 UPDATE;
-                 break;
+                 goto do_page;
+              case XK_Left:
               case XK_Prior:
-                 FREE_LINKS;
                  pagenum--;
-                 pagenum = FixPage(pagenum);
-                 l = RenderPage(draw, pagenum, w, h);
-                 UPDATE;
-                 break;
+                 page_hist_len = page_hist_pos + 1;
+                 goto do_page;
+              case XK_Right:
               case XK_Next:
-                 FREE_LINKS;
                  pagenum++;
-                 pagenum = FixPage(pagenum);
-                 l = RenderPage(draw, pagenum, w, h);
-                 UPDATE;
-                 break;
+                 page_hist_len = page_hist_pos + 1;
+                 goto do_page;
+              case XK_r:
+                 LoadFile(s, docfile);
+                 goto do_page1;
+              }
+            break;
+
+          do_next:
+            if (page_hist_pos >= page_hist_len - 1)
+               break;
+            page_hist_pos++;
+            pagenum = page_hist[page_hist_pos];
+            goto do_page;
+
+          do_prev:
+            if (pagenum == page_hist[page_hist_pos])
+              {
+                 page_hist_pos--;
+                 if (page_hist_pos < 0)
+                    page_hist_pos = 0;
+              }
+            pagenum = page_hist[page_hist_pos];
+            goto do_page;
+
+          do_page_save:
+            pagenum = FixPage(pagenum);
+            if (pagenum == prev_pagenum)
+               break;
+            page_hist_pos++;
+            if (page_hist_pos >= page_hist_len)
+              {
+                 page_hist_len++;
+                 page_hist = EREALLOC(int, page_hist, page_hist_len);
               }
+            page_hist_len = page_hist_pos + 1;
+            page_hist[page_hist_pos] = pagenum;
+            goto do_page;
+
+          do_page:
+            pagenum = FixPage(pagenum);
+            if (pagenum == prev_pagenum)
+               break;
+          do_page1:
+            FREE_LINKS;
+            l = RenderPage(draw, pagenum, w, h);
+            UPDATE;
             break;
+
          case ButtonPress:
             if (ev.xbutton.window == win_prev)
                ApplyImage2(win_prev, im_prev2);
@@ -553,19 +598,8 @@
                                 pg = GetPage(ll->name);
                                 if (pg >= 0)
                                   {
-                                     FREE_LINKS;
                                      pagenum = pg;
-                                     page_hist_pos++;
-                                     if (page_hist_pos >= page_hist_len)
-                                       {
-                                          page_hist_len++;
-                                          page_hist =
-                                             EREALLOC(int, page_hist,
-                                                      page_hist_len);
-                                       }
-                                     page_hist[page_hist_pos] = pagenum;
-                                     l = RenderPage(draw, pagenum, w, h);
-                                     UPDATE;
+                                     goto do_page_save;
                                   }
                              }
                            break;
@@ -574,42 +608,18 @@
                    }
               }
             break;
+
          case ButtonRelease:
             if (ev.xbutton.window == win_prev)
               {
                  ApplyImage3(win_prev, im_prev1);
-                 FREE_LINKS;
-                 page_hist_pos--;
-                 if (page_hist_pos < 0)
-                    page_hist_pos = 0;
-                 pagenum = page_hist[page_hist_pos];
-                 l = RenderPage(draw, pagenum, w, h);
-                 UPDATE;
+                 goto do_prev;
               }
             else if (ev.xbutton.window == win_next)
               {
-                 int                 prev_pagenum;
-
                  ApplyImage3(win_next, im_next1);
-                 prev_pagenum = pagenum;
                  pagenum++;
-                 pagenum = FixPage(pagenum);
-                 if (pagenum != prev_pagenum)
-                   {
-                      FREE_LINKS;
-                      page_hist_pos++;
-                      if (page_hist_pos >= page_hist_len)
-                        {
-                           page_hist_len++;
-                           page_hist = EREALLOC(int, page_hist, page_hist_len);
-
-                           page_hist[page_hist_pos] = pagenum;
-                        }
-                      else
-                         page_hist[page_hist_pos] = pagenum;
-                      l = RenderPage(draw, pagenum, w, h);
-                      UPDATE;
-                   }
+                 goto do_page_save;
               }
             else if (ev.xbutton.window == win_exit)
               {
@@ -617,10 +627,11 @@
                  exit(0);
               }
             break;
+
          case EnterNotify:
-            break;
          case LeaveNotify:
             break;
+
          case MotionNotify:
             while (XCheckTypedEvent(disp, ev.type, &ev));
             {
@@ -669,11 +680,13 @@
                  }
             }
             break;
+
          case ClientMessage:
             if (ev.xclient.message_type == ATOM_WM_PROTOCOLS &&
                 (Atom) ev.xclient.data.l[0] == ATOM_WM_DELETE_WINDOW)
                goto done;
             break;
+
          default:
             break;
          }
===================================================================
RCS file: /cvs/e/e16/e/dox/dox.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -3 -r1.42 -r1.43
--- dox.h       18 Mar 2007 21:59:46 -0000      1.42
+++ dox.h       21 Oct 2007 13:14:10 -0000      1.43
@@ -23,7 +23,6 @@
   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   */
-
 #include "config.h"
 
 #include <X11/Xlib.h>
@@ -59,20 +58,10 @@
 
 #define FILEPATH_LEN_MAX 4096
 
-#define DEFAULT_LINKCOLOR_R 30
-#define DEFAULT_LINKCOLOR_G 50
-#define DEFAULT_LINKCOLOR_B 160
-
 #ifndef MAX
 #define MAX(a,b)  ((a)>(b)?(a):(b))
 #endif
 
-/* ISO encodings */
-#define ENCOING_ISO_8859_1 0
-#define ENCOING_ISO_8859_2 1
-#define ENCOING_ISO_8859_3 2
-#define ENCOING_ISO_8859_4 3
-
 #if defined(HAVE_WCTYPE_H) && defined(HAVE_WCHAR_T) && !defined(__FreeBSD__)
 #define USE_WORD_MB
 #endif
@@ -87,8 +76,7 @@
    Colormap            cmap;
    int                 scr;
    unsigned int        w, h;
-}
-Root;
+} Root;
 
 typedef struct _textstate
 {
@@ -101,74 +89,21 @@
    XFontSet            xfontset;
    int                 xfontset_ascent;
    int                 height;
-}
-TextState;
-
-typedef enum _type
-{
-   IMG,
-   BR,
-   FONT,
-   P,
-   TEXT,
-   PAGE
-}
-Type;
-
-typedef struct _img
-{
-   char               *src;
-   char               *src2;
-   char               *src3;
-   int                 x, y;
-   char               *link;
-   int                 w, h;
-}
-Img_;
-
-typedef struct _font
-{
-   char               *face;
-   int                 r, g, b;
-}
-Font_;
-
-typedef struct _p
-{
-   float               align;
-}
-P_;
-
-typedef struct _object
-{
-   Type                type;
-   void               *object;
-}
-Object;
-
-typedef struct _page
-{
-   char               *name;
-   int                 count;
-   Object             *obj;
-   int                 columns;
-   int                 padding;
-   int                 linkr, linkg, linkb;
-   char               *background;
-}
-Page;
+} TextState;
 
 typedef struct _link
 {
    char               *name;
    int                 x, y, w, h;
    struct _link       *next;
-}
-Link;
+} Link;
 
+/* dox.c */
+Imlib_Image         ImageLoadDoc(const char *file);
 void                ESetColor(XColor * pxc, int r, int g, int b);
 void                EGetColor(XColor * pxc, int *pr, int *pg, int *pb);
 
+/* ttfont.c */
 void                Efont_extents(Efont * f, const char *text,
                                  int *font_ascent_return,
                                  int *font_descent_return, int *width_return,
@@ -181,6 +116,7 @@
                                      int x, int y, const char *text,
                                      Efont * font, Visual * vis, Colormap cm);
 
+/* text.c */
 void                TextStateLoadFont(TextState * ts);
 void                TextSize(TextState * ts, const char *text,
                             int *width, int *height, int fsize);
@@ -188,6 +124,7 @@
                             int x, int y, int w, int h, int fsize,
                             int justification);
 
+/* file.c */
 void                freestrlist(char **l, int num);
 void                word(char *s, int num, char *wd);
 
@@ -196,11 +133,7 @@
 #endif
 int                 findLocalizedFile(char *fname);
 
-void                AddPage(Object * obj);
-void                AddObject(Object * obj);
-void                BuildObj(Object * obj, char *var, char *param);
-int                 GetNextTag(Object * obj);
-char               *GetTextUntilTag(void);
+/* format.c */
 int                 GetObjects(FILE * f);
 int                 FixPage(int p);
 int                 GetPage(char *name);
===================================================================
RCS file: /cvs/e/e16/e/dox/format.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- format.c    17 Jan 2007 01:10:40 -0000      1.22
+++ format.c    21 Oct 2007 13:14:10 -0000      1.23
@@ -20,18 +20,66 @@
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-
 #include "dox.h"
 
+#define DEFAULT_LINKCOLOR_R 30
+#define DEFAULT_LINKCOLOR_G 50
+#define DEFAULT_LINKCOLOR_B 160
+
+typedef enum _type
+{
+   IMG,
+   BR,
+   FONT,
+   P,
+   TEXT,
+   PAGE
+} Type;
+
+typedef struct _img
+{
+   char               *src;
+   char               *src2;
+   char               *src3;
+   int                 x, y;
+   char               *link;
+   int                 w, h;
+} Img_;
+
+typedef struct _font
+{
+   char               *face;
+   int                 r, g, b;
+} Font_;
+
+typedef struct _p
+{
+   float               align;
+} P_;
+
+typedef struct _object
+{
+   Type                type;
+   void               *object;
+} Object;
+
+typedef struct _page
+{
+   char               *name;
+   int                 count;
+   Object             *obj;
+   int                 columns;
+   int                 padding;
+   int                 linkr, linkg, linkb;
+   char               *background;
+} Page;
+
 static int          num_pages = 0;
 static Page        *page = NULL;
 static char        *fdat_ptr = NULL;
 static int          fdat_size = 0;
 static char        *fdat = NULL;
 
-static int          fdgetc(void);
-static void         fdjump(int count);
-
 static int
 fdgetc(void)
 {
@@ -54,7 +102,7 @@
       fdat_ptr = (fdat + fdat_size) - 1;
 }
 
-void
+static void
 AddPage(Object * obj)
 {
    num_pages++;
@@ -86,7 +134,7 @@
      }
 }
 
-void
+static void
 AddObject(Object * obj)
 {
    page[num_pages - 1].count++;
@@ -96,7 +144,7 @@
    page[num_pages - 1].obj[page[num_pages - 1].count - 1].object = obj->object;
 }
 
-void
+static void
 BuildObj(Object * obj, char *var, char *param)
 {
    static Page        *pg = NULL;
@@ -225,7 +273,7 @@
      }
 }
 
-int
+static int
 GetNextTag(Object * obj)
 {
    char                s[65536];
@@ -304,7 +352,7 @@
    return 1;
 }
 
-char               *
+static char        *
 GetTextUntilTag(void)
 {
    char                s[65536];
@@ -537,11 +585,7 @@
    col_h = h - (pg->padding * 2);
    if (pg->background)
      {
-       char                tmp[4096];
-
-       sprintf(tmp, "%s/%s", docdir, pg->background);
-       findLocalizedFile(tmp);
-       im = imlib_load_image(tmp);
+       im = ImageLoadDoc(pg->background);
        if (im)
          {
             imlib_context_set_image(im);
@@ -565,10 +609,7 @@
             img = (Img_ *) pg->obj[i].object;
             if (img->src)
               {
-                 char                tmp[4096];
-
-                 sprintf(tmp, "%s/%s", docdir, img->src);
-                 im = imlib_load_image(tmp);
+                 im = ImageLoadDoc(img->src);
                  if (im)
                    {
                       imlib_context_set_image(im);
===================================================================
RCS file: /cvs/e/e16/e/dox/text.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- text.c      17 Jan 2007 01:10:40 -0000      1.22
+++ text.c      21 Oct 2007 13:14:10 -0000      1.23
@@ -75,7 +75,6 @@
             *ss = ' ';
             word(s2, 1, w);
             sprintf(s, "%s/%s.ttf", docdir, w);
-            findLocalizedFile(s);
             word(s2, 2, w);
             ts->efont = Efont_load(s, atoi(w));
             if (ts->efont)



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to