\hypertarget{edje-signals-messages_8c-example}{\section{edje-\/signals-\/messages.\+c}
}

\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}
\textcolor{preprocessor}{#include "config.h"}
\textcolor{preprocessor}{#else}
\textcolor{preprocessor}{#define PACKAGE\_EXAMPLES\_DIR "."}
\textcolor{preprocessor}{#define EINA\_UNUSED}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#ifndef PACKAGE\_DATA\_DIR}
\textcolor{preprocessor}{#define PACKAGE\_DATA\_DIR "."}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}>}
\textcolor{preprocessor}{#include <\hyperlink{Edje_8h}{Edje.h}>}
\textcolor{preprocessor}{#include <stdio.h>}

\textcolor{preprocessor}{#define WIDTH     (300)}
\textcolor{preprocessor}{#define HEIGHT    (300)}

\textcolor{preprocessor}{#define MSG\_COLOR 1}
\textcolor{preprocessor}{#define MSG\_TEXT  2}

\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} commands[] = \(\backslash\)
  \textcolor{stringliteral}{"commands are:\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tt - toggle right rectangle's visibility\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tEsc - exit\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)th - print help\(\backslash\)n"};

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} right\_rect\_show = \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_keydown(\textcolor{keywordtype}{void}        *data,
            \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}        *evas EINA\_UNUSED,
            \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *o EINA\_UNUSED,
            \textcolor{keywordtype}{void}        *einfo)
\{
   \hyperlink{struct__Evas__Event__Key__Down}{Evas\_Event\_Key\_Down} *ev;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}         *edje\_obj;

   ev = (\hyperlink{struct__Evas__Event__Key__Down}{Evas\_Event\_Key\_Down} *)einfo;
   edje\_obj = (\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *)data;

   \textcolor{keywordflow}{if} (!strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"h"})) \textcolor{comment}{/* print help */}
     \{
        fprintf(stdout, commands);
        \textcolor{keywordflow}{return};
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"t"})) \textcolor{comment}{/* toggle right rectangle's visibility */}
     \{
        \textcolor{keywordtype}{char} buf[1024];

        right\_rect\_show = !right\_rect\_show;
        snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"part\_right,%s"},
                 right\_rect\_show ? \textcolor{stringliteral}{"show"} : \textcolor{stringliteral}{"hide"});

        printf(\textcolor{stringliteral}{"emitting %s\(\backslash\)n"}, buf);

        edje\_object\_signal\_emit(edje\_obj, buf, \textcolor{stringliteral}{""});

        \textcolor{keywordflow}{return};
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"Escape"}))
     \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
   \textcolor{keywordflow}{else}
     \{
        printf(\textcolor{stringliteral}{"unhandled key: %s\(\backslash\)n"}, ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key});
        fprintf(stdout, commands);
     \}
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_delete(Ecore\_Evas *ee EINA\_UNUSED)
\{
   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
\}

\textcolor{comment}{/* print signals coming from theme */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_sig\_print(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *emission,
           \textcolor{keyword}{const} \textcolor{keywordtype}{char} *source)
\{
   fprintf(stdout, \textcolor{stringliteral}{"Signal %s coming from part %s!\(\backslash\)n"}, emission, source);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_mouse\_wheel(\textcolor{keywordtype}{void}        *data EINA\_UNUSED,
                  \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj EINA\_UNUSED,
                  \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *emission,
                  \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *source)
\{
   \_sig\_print(emission, source);
\}

\textcolor{comment}{/* mouse over signals */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_mouse\_over(\textcolor{keywordtype}{void}        *data EINA\_UNUSED,
               \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *edje\_obj,
               \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *emission,
               \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *source)
\{
   \textcolor{keywordtype}{int} i;

   \_sig\_print(emission, source);

   \hyperlink{struct__Edje__Message__Int__Set}{Edje\_Message\_Int\_Set} *msg = malloc(\textcolor{keyword}{sizeof}(*msg) + 3 * \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{int}));
   msg->\hyperlink{struct__Edje__Message__Int__Set_a975ee039878b90538f2fb4471428c56e}{count} = 4;
   \textcolor{keywordflow}{for} (i = 0; i < 4; i++)
     msg->\hyperlink{struct__Edje__Message__Int__Set_a835187daa81c0007a58cbcf4eaa896ed}{val}[i] = rand() % 256;

   edje\_object\_message\_send(edje\_obj, \hyperlink{group__Edje__Object__Communication__Interface__Message_gga0d3b39bbf2f2f0c070d45edd5d0b0cfaaa392f6e98640e16c6b71f3dd19e18d39}{EDJE\_MESSAGE\_INT\_SET}, MSG\_COLOR, msg);

   free(msg);
\}

\textcolor{comment}{/* print out received message string */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_message\_handle(\textcolor{keywordtype}{void}             *data EINA\_UNUSED,
                \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}      *obj EINA\_UNUSED,
                \hyperlink{group__Edje__Object__Communication__Interface__Message_ga986c03fa5abf90ef03b6dbbd93cf8dcc}{Edje\_Message\_Type} type,
                \textcolor{keywordtype}{int}               \textcolor{keywordtype}{id},
                \textcolor{keywordtype}{void}             *msg)
\{
   \hyperlink{struct__Edje__Message__String}{Edje\_Message\_String} *m;

   \textcolor{keywordflow}{if} (type != \hyperlink{group__Edje__Object__Communication__Interface__Message_gga0d3b39bbf2f2f0c070d45edd5d0b0cfaad24747cc7c7ef0d5a61d29cf9d78dd77}{EDJE\_MESSAGE\_STRING}) \textcolor{keywordflow}{return};
   \textcolor{keywordflow}{if} (\textcolor{keywordtype}{id} != MSG\_TEXT) \textcolor{keywordflow}{return};

   m = msg;

   fprintf(stdout, \textcolor{stringliteral}{"String message received: %s\(\backslash\)n"}, m->\hyperlink{struct__Edje__Message__String_a26d7286d36a05fa3f148b426ed8267e9}{str});
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc EINA\_UNUSED, \textcolor{keywordtype}{char} *argv[] EINA\_UNUSED)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *img\_file = PACKAGE\_DATA\_DIR\textcolor{stringliteral}{"/red.png"};
   \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *edje\_file = PACKAGE\_DATA\_DIR\textcolor{stringliteral}{"/signals-messages.edj"};
   Ecore\_Evas  *ee;
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}        *evas;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *bg;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *edje\_obj;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *border;

   \textcolor{keywordflow}{if} (!\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}())
     \textcolor{keywordflow}{return} EXIT\_FAILURE;

   \textcolor{keywordflow}{if} (!\hyperlink{group__Edje__General__Group_ga1c9c6594f38023c29fbfb2d0c8c675db}{edje\_init}())
     \textcolor{keywordflow}{goto} shutdown\_ecore\_evas;

   \textcolor{comment}{/* this will give you a window with an Evas canvas under the first}
\textcolor{comment}{    * engine available */}
   ee = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, WIDTH, HEIGHT, NULL);
   \textcolor{keywordflow}{if} (!ee) \textcolor{keywordflow}{goto} shutdown\_edje;

   \hyperlink{group__Ecore__Evas__Group_ga3d478e975e2101b9b821ef24baf3dd9e}{ecore\_evas\_callback\_delete\_request\_set}(ee, \_on\_delete);
   \hyperlink{group__Ecore__Evas__Group_ga3b2832e0373bbafae2bb7143618535c1}{ecore\_evas\_title\_set}(ee, \textcolor{stringliteral}{"Edje Basics Example"});

   evas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(ee);

   bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(evas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(bg, 255, 255, 255, 255); \textcolor{comment}{/* white bg */}
   evas\_object\_move(bg, 0, 0); \textcolor{comment}{/* at canvas' origin */}
   evas\_object\_resize(bg, WIDTH, HEIGHT); \textcolor{comment}{/* covers full canvas */}
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);
   evas\_object\_focus\_set(bg, \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__Ecore__Evas__Group_gac35627a5c3a766ee42762dbcc9eb733d}{ecore\_evas\_object\_associate}(ee, bg, ECORE\_EVAS\_OBJECT\_ASSOCIATE\_BASE);

   edje\_obj = edje\_object\_add(evas);

   \textcolor{keywordflow}{if} (!edje\_object\_file\_set(edje\_obj, edje\_file, \textcolor{stringliteral}{"example\_group"}))
     \{
        \textcolor{keywordtype}{int} err = edje\_object\_load\_error\_get(edje\_obj);
        \textcolor{keyword}{const} \textcolor{keywordtype}{char} *errmsg = \hyperlink{group__Edje__Object__File_ga034465c2de4ab495802da20f332c386e}{edje\_load\_error\_str}(err);
        fprintf(stderr, \textcolor{stringliteral}{"Could not load 'example\_group' from "}
                        \textcolor{stringliteral}{"signals-messages.edj: %s\(\backslash\)n"}, errmsg);

        \hyperlink{group__Evas__Object__Group__Basic_ga7e7a625dab7a3890532aa13b43117076}{evas\_object\_del}(edje\_obj);
        \textcolor{keywordflow}{goto} shutdown\_edje;
     \}

   edje\_object\_signal\_callback\_add(edje\_obj, \textcolor{stringliteral}{"mouse,wheel,*"}, \textcolor{stringliteral}{"part\_left"},
                                   \_on\_mouse\_wheel, NULL);

   edje\_object\_signal\_callback\_add(edje\_obj, \textcolor{stringliteral}{"mouse,over"}, \textcolor{stringliteral}{"part\_right"},
                                   \_on\_mouse\_over, NULL);

   edje\_object\_message\_handler\_set(edje\_obj, \_message\_handle, NULL);

   evas\_object\_move(edje\_obj, 20, 20);
   evas\_object\_resize(edje\_obj, WIDTH - 40, HEIGHT - 40);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(edje\_obj);

   \hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}(bg, 
      \hyperlink{Evas__Common_8h_a99e208e463a20499aabe6faac8a8cb8aa336b86bad4f145f84c155e4922335584}{EVAS\_CALLBACK\_KEY\_DOWN}, \_on\_keydown, edje\_obj);

   \textcolor{comment}{/* this is a border around the Edje object above, here just to}
\textcolor{comment}{    * emphasize its geometry */}
   border = \hyperlink{group__Evas__Object__Image_ga0e8cb83d31d02bf583c75925b7cd14d7}{evas\_object\_image\_filled\_add}(evas);
   \hyperlink{group__Evas__Object__Image_gac27fd0ceabe5f56607b7a86d71577df1}{evas\_object\_image\_file\_set}(border, img\_file, NULL);
   evas\_object\_image\_border\_set(border, 2, 2, 2, 2);
   evas\_object\_image\_border\_center\_fill\_set(border, \hyperlink{Evas__Common_8h_a4a05f0fd82f51c6b330e349457cdc7e2a2ad856ac6aab5e2659c3a584a37aec70}{EVAS\_BORDER\_FILL\_NONE});

   evas\_object\_resize(border, WIDTH - 40 + 4, HEIGHT - 40 + 4);
   evas\_object\_move(border, 20 - 2, 20 - 2);
   evas\_object\_repeat\_events\_set(border, \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(border);

   fprintf(stdout, commands);

   \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(ee);

   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}(ee);
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();
   \hyperlink{group__Edje__General__Group_ga01041f6702f2d81bf10c3e41899805cb}{edje\_shutdown}();

   \textcolor{keywordflow}{return} EXIT\_SUCCESS;

 shutdown\_edje:
   \hyperlink{group__Edje__General__Group_ga01041f6702f2d81bf10c3e41899805cb}{edje\_shutdown}();
 shutdown\_ecore\_evas:
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

   \textcolor{keywordflow}{return} EXIT\_FAILURE;
\}
\end{DoxyCodeInclude}
 