Enlightenment CVS committal Author : doursse Project : e17 Module : proto
Dir : e17/proto/epdf/src/lib Modified Files: ewl_pdf.c ewl_pdf.h Log Message: The widget does not inherit from Ewl_Image, but from Ewl_Widget directly =================================================================== RCS file: /cvs/e/e17/proto/epdf/src/lib/ewl_pdf.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- ewl_pdf.c 3 Jun 2006 10:11:38 -0000 1.7 +++ ewl_pdf.c 30 Sep 2006 23:01:43 -0000 1.8 @@ -45,37 +45,39 @@ * @return Returns no value. * @brief Initialize an pdf widget to default values and callbacks * - * Sets the fields and callbacks of @a i to their default values. + * Sets the fields and callbacks of @a pdf to their default values. */ int ewl_pdf_init(Ewl_Pdf *pdf) { Ewl_Widget *w; - Ewl_Image *i; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("pdf", pdf, FALSE); w = EWL_WIDGET(pdf); - i = EWL_IMAGE(pdf); - if (!ewl_image_init(i)) + if (!ewl_widget_init(w)) DRETURN_INT(FALSE, DLEVEL_STABLE); - ewl_widget_appearance_set(w, "pdf"); - ewl_widget_inherit(w, "pdf"); + ewl_widget_appearance_set(w, EWL_PDF_TYPE); + ewl_widget_inherit(w, EWL_PDF_TYPE); + + ewl_object_fill_policy_set(EWL_OBJECT(w), EWL_FLAG_FILL_NONE); /* * Append necessary callbacks. */ + ewl_callback_append(w, EWL_CALLBACK_CONFIGURE, ewl_pdf_configure_cb, + NULL); ewl_callback_append(w, EWL_CALLBACK_REVEAL, ewl_pdf_reveal_cb, NULL); + ewl_callback_append(w, EWL_CALLBACK_OBSCURE, ewl_pdf_obscure_cb, + NULL); ewl_callback_prepend(w, EWL_CALLBACK_DESTROY, ewl_pdf_destroy_cb, NULL); - i->type = EWL_IMAGE_TYPE_NORMAL; - - i->path = NULL; + pdf->filename = NULL; pdf->page = 0; pdf->page_length = 10; @@ -107,18 +109,18 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("pdf", pdf, 0); - DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + DCHECK_TYPE_RET("pdf", pdf, EWL_PDF_TYPE, 0); DRETURN_INT(pdf->page, DLEVEL_STABLE); } /** * @param pdf: the pdf widget to change the displayed pdf - * @param filename: the path to the new pdf to be displayed by @a pdf + * @param filename: the filename to the new pdf to be displayed by @a pdf * @return Returns no value. * @brief Change the pdf file displayed by an pdf widget * - * Set the pdf displayed by @a pdf to the one found at the path @a im. If an + * Set the pdf displayed by @a pdf to the one found at the filename @a filename. If an * edje is used, a minimum size should be specified in the edje or the code. */ void @@ -129,12 +131,17 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); w = EWL_WIDGET(pdf); emb = ewl_embed_widget_find(w); - ewl_image_file_set(EWL_IMAGE(pdf), filename, NULL); + if (pdf->filename != filename) { + IF_FREE(pdf->filename); + } + if (filename) { + pdf->filename = strdup(filename); + } if (pdf->pdf_document) { if (pdf->pdf_page) @@ -178,7 +185,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf->pdf_document || (page >= epdf_document_page_count_get (pdf->pdf_document)) || @@ -199,8 +206,8 @@ Epdf_Document *ewl_pdf_pdf_document_get (Ewl_Pdf *pdf) { DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("pdf", pdf, 0); - DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + DCHECK_PARAM_PTR_RET("pdf", pdf, NULL); + DCHECK_TYPE_RET("pdf", pdf, EWL_PDF_TYPE, NULL); DRETURN_PTR(pdf->pdf_document, DLEVEL_STABLE); } @@ -213,8 +220,8 @@ Epdf_Page *ewl_pdf_pdf_page_get (Ewl_Pdf *pdf) { DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("pdf", pdf, 0); - DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + DCHECK_PARAM_PTR_RET("pdf", pdf, NULL); + DCHECK_TYPE_RET("pdf", pdf, EWL_PDF_TYPE, NULL); DRETURN_PTR(pdf->pdf_page, DLEVEL_STABLE); } @@ -227,8 +234,8 @@ Ecore_List *ewl_pdf_pdf_index_get (Ewl_Pdf *pdf) { DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("pdf", pdf, 0); - DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + DCHECK_PARAM_PTR_RET("pdf", pdf, NULL); + DCHECK_TYPE_RET("pdf", pdf, EWL_PDF_TYPE, NULL); DRETURN_PTR(pdf->pdf_index, DLEVEL_STABLE); } @@ -244,7 +251,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf) { if (width) *width = 0; @@ -263,7 +270,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if ((!text) || (pdf->search.text && @@ -282,7 +289,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (page != pdf->search.page) pdf->search.page = page; @@ -295,7 +302,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (is_case_sensitive != pdf->search.is_case_sensitive) pdf->search.is_case_sensitive = is_case_sensitive; @@ -308,7 +315,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("pdf", pdf, FALSE); - DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + DCHECK_TYPE_RET("pdf", pdf, EWL_PDF_TYPE, FALSE); if (!pdf->search.text) DRETURN_INT(FALSE, DLEVEL_STABLE); @@ -384,7 +391,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf || !pdf->pdf_page || (pdf->orientation == o)) DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -399,8 +406,8 @@ ewl_pdf_orientation_get (Ewl_Pdf *pdf) { DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("pdf", pdf, FALSE); - DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + DCHECK_PARAM_PTR_RET("pdf", pdf, EPDF_PAGE_ORIENTATION_PORTRAIT); + DCHECK_TYPE_RET("pdf", pdf, EWL_PDF_TYPE, EPDF_PAGE_ORIENTATION_PORTRAIT); if (!pdf || !pdf->pdf_page) DRETURN_INT(EPDF_PAGE_ORIENTATION_PORTRAIT, DLEVEL_STABLE); @@ -413,7 +420,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf) DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -430,7 +437,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf) { if (hscale) *hscale = 1.0; @@ -451,7 +458,7 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf) DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -471,7 +478,7 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf) DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -489,7 +496,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf || (page_length <= 0) || (pdf->page_length == page_length)) DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -504,7 +511,7 @@ { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("pdf", pdf, 0); - DCHECK_TYPE_RET("pdf", pdf, "pdf", 0); + DCHECK_TYPE_RET("pdf", pdf, EWL_PDF_TYPE, 0); if (!pdf) DRETURN_INT(0, DLEVEL_STABLE); @@ -519,7 +526,7 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf) DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -539,7 +546,7 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("pdf", pdf); - DCHECK_TYPE("pdf", pdf, "pdf"); + DCHECK_TYPE("pdf", pdf, EWL_PDF_TYPE); if (!pdf) DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -557,76 +564,118 @@ void *user_data __UNUSED__) { Ewl_Pdf *pdf; - Ewl_Image *i; Ewl_Embed *emb; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("w", w); - DCHECK_TYPE("w", w, "widget"); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); pdf = EWL_PDF(w); - i = EWL_IMAGE(w); emb = ewl_embed_widget_find(w); /* * Load the pdf */ - if (!i->image) - i->image = ewl_embed_object_request(emb, "pdf"); - if (!i->image) - i->image = evas_object_image_add(emb->evas); - if (!i->image) + if (!pdf->image) + pdf->image = ewl_embed_object_request(emb, "pdf"); + if (!pdf->image) + pdf->image = evas_object_image_add(emb->evas); + if (!pdf->image) DRETURN(DLEVEL_STABLE); if (pdf->pdf_document) { if (pdf->pdf_page) epdf_page_delete (pdf->pdf_page); pdf->pdf_page = epdf_document_page_get (pdf->pdf_document, pdf->page); - epdf_page_render (pdf->pdf_page, i->image, + epdf_page_render (pdf->pdf_page, pdf->image, pdf->orientation, 0, 0, -1, -1, pdf->hscale, pdf->vscale); } - evas_object_image_size_get(i->image, &i->ow, &i->oh); + evas_object_image_size_get(pdf->image, &pdf->ow, &pdf->oh); + + evas_object_smart_member_add(pdf->image, w->smart_object); + if (w->fx_clip_box) + evas_object_stack_below(pdf->image, w->fx_clip_box); - evas_object_smart_member_add(i->image, w->smart_object); if (w->fx_clip_box) - evas_object_clip_set(i->image, w->fx_clip_box); + evas_object_clip_set(pdf->image, w->fx_clip_box); - evas_object_pass_events_set(i->image, TRUE); - evas_object_show(i->image); + evas_object_pass_events_set(pdf->image, TRUE); + evas_object_show(pdf->image); - if (!i->ow) - i->ow = 1; - if (!i->oh) - i->oh = 1; + if (!pdf->ow) + pdf->ow = 1; + if (!pdf->oh) + pdf->oh = 1; - if (i->aw || i->ah) { - ewl_image_size_set(i, i->aw, i->ah); - } - else { - ewl_object_preferred_inner_w_set(EWL_OBJECT(i), i->ow); - ewl_object_preferred_inner_h_set(EWL_OBJECT(i), i->oh); - ewl_image_scale_set(i, i->sw, i->sh); - } + ewl_object_preferred_inner_w_set(EWL_OBJECT(w), pdf->ow); + ewl_object_preferred_inner_h_set(EWL_OBJECT(w), pdf->oh); - /*Constrain settings*/ - if (i->cs && (i->ow > i->cs || i->oh > i->cs)) { - double cp = 0; - if (i->ow > i->oh) - cp = i->cs / (double)i->ow; - else - cp = i->cs / (double)i->oh; + DLEAVE_FUNCTION(DLEVEL_STABLE); +} - ewl_image_scale_set(i, cp, cp); - ewl_image_tile_set(i, 0, 0, cp*i->ow, cp*i->oh); +void +ewl_pdf_obscure_cb(Ewl_Widget *w, void *ev_data __UNUSED__, + void *user_data __UNUSED__) +{ + Ewl_Pdf *pdf; + Ewl_Embed *emb; + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); + + emb = ewl_embed_widget_find(w); + + pdf = EWL_PDF(w); + if (emb && pdf->image) { + ewl_embed_object_cache(emb, pdf->image); + pdf->image = NULL; } DLEAVE_FUNCTION(DLEVEL_STABLE); } void +ewl_pdf_configure_cb(Ewl_Widget *w, void *ev_data __UNUSED__, + void *user_data __UNUSED__) +{ + Ewl_Pdf *pdf; + Ewl_Embed *emb; + int ww, hh; + int dx = 0, dy = 0; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); + + pdf = EWL_PDF(w); + if (!pdf->image) + DRETURN(DLEVEL_STABLE); + + emb = ewl_embed_widget_find(w); + + ww = CURRENT_W(w); + hh = CURRENT_H(w); + if (ww > pdf->ow) + ww = pdf->ow; + if (hh > pdf->oh) + hh = pdf->oh; + + dx = (CURRENT_W(w) - ww) / 2; + dy = (CURRENT_H(w) - hh) / 2; + + evas_object_image_fill_set(pdf->image, 0, 0, + ww, hh); + + evas_object_move(pdf->image, CURRENT_X(w) + dx, CURRENT_Y(w) + dy); + evas_object_resize(pdf->image, ww, hh); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void ewl_pdf_destroy_cb(Ewl_Widget *w, void *ev_data __UNUSED__, void *user_data __UNUSED__) { @@ -638,6 +687,7 @@ pdf = EWL_PDF(w); + IF_FREE(pdf->filename); if (pdf->pdf_document) epdf_document_delete (pdf->pdf_document); if (pdf->pdf_page) =================================================================== RCS file: /cvs/e/e17/proto/epdf/src/lib/ewl_pdf.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- ewl_pdf.h 3 Jun 2006 10:11:38 -0000 1.6 +++ ewl_pdf.h 30 Sep 2006 23:01:43 -0000 1.7 @@ -16,17 +16,33 @@ * @themekey /pdf/group */ +/** + * @def EWL_PDF_TYPE + * The type name for the Ewl_Pdf widget + */ +#define EWL_PDF_TYPE "pdf" + +/** + * The Ewl_Pdf widget + */ typedef struct Ewl_Pdf Ewl_Pdf; +/** + * @def EWL_PDF(pdf) + * Typecase a pointer to an Ewl_Pdf widget + */ #define EWL_PDF(pdf) ((Ewl_Pdf *) pdf) /** - * @struct Ewl_Pdf - * + * Inherits from Ewl_Widget and extends to provide a pdf widget */ struct Ewl_Pdf { - Ewl_Image image; + Ewl_Widget widget; + Evas_Object *image; + char *filename; + int ow; + int oh; int page; int page_length; @@ -76,7 +92,9 @@ /* * Internally used callbacks, override at your own risk. */ +void ewl_pdf_configure_cb(Ewl_Widget *w, void *ev_data, void *user_data); void ewl_pdf_reveal_cb(Ewl_Widget *w, void *ev_data, void *user_data); +void ewl_pdf_obscure_cb(Ewl_Widget *w, void *ev_data, void *user_data); void ewl_pdf_destroy_cb(Ewl_Widget *w, void *ev_data, void *user_data ); /** ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs