summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_internal_text_scroller.c
blob: 3387759e38e546b9273dad1516c6064fd27088e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define ELM_LAYOUT_PROTECTED
#define EFL_UI_SCROLL_MANAGER_PROTECTED
#define EFL_UI_SCROLLBAR_PROTECTED

#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Elementary.h>

#include "elm_priv.h"
#include "elm_widget_layout.h"
#include "efl_ui_widget_scroller.h"

#include "efl_ui_internal_text_scroller.h"

#define EFL_UI_SCROLLER_DATA_GET(o, sd) \
  Efl_Ui_Scroller_Data * sd = efl_data_scope_safe_get(o, EFL_UI_SCROLLER_CLASS)

#define EFL_UI_SCROLLER_DATA_GET_OR_RETURN(o, ptr, ...) \
  EFL_UI_SCROLLER_DATA_GET(o, ptr);                         \
  if (EINA_UNLIKELY(!ptr))                            \
    {                                                 \
       ERR("No widget data for object %p (%s)",       \
           o, evas_object_type_get(o));               \
       return __VA_ARGS__;                                    \
    }
#define MY_CLASS EFL_UI_INTERNAL_TEXT_SCROLLER_CLASS
#define MY_CLASS_PFX efl_ui_internal_text_scroller

#define MY_CLASS_NAME "Efl.Ui.Internal_Text_Scroller"

typedef struct _Efl_Ui_Internal_Text_Scroller_Data
{
   Efl_Canvas_Textblock *text_obj;
   Efl_Ui_Table *text_table;
   Eo *smanager;

   Efl_Ui_Text_Scroller_Mode mode;

   Eina_Bool  match_content_w: 1;
   Eina_Bool  match_content_h: 1;
} Efl_Ui_Internal_Text_Scroller_Data;

#define EFL_UI_INTERNAL_TEXT_SCROLLER_DATA_GET(o, sd) \
  Efl_Ui_Internal_Text_Scroller_Data * sd = efl_data_scope_safe_get(o, EFL_UI_INTERNAL_TEXT_SCROLLER_CLASS)

#define EFL_UI_INTERNAL_TEXT_SCROLLER_DATA_GET_OR_RETURN(o, ptr, ...) \
  EFL_UI_INTERNAL_TEXT_SCROLLER_DATA_GET(o, ptr);                         \
  if (EINA_UNLIKELY(!ptr))                            \
    {                                                 \
       ERR("No widget data for object %p (%s)",       \
           o, evas_object_type_get(o));               \
       return __VA_ARGS__;                                    \
    }

EOLIAN static Eo *
_efl_ui_internal_text_scroller_efl_object_constructor(Eo *obj,
                                        Efl_Ui_Internal_Text_Scroller_Data *sd EINA_UNUSED)
{
   obj = efl_constructor(efl_super(obj, MY_CLASS));
   //EFL_UI_SCROLLER_DATA_GET_OR_RETURN(obj, psd, NULL);
   efl_ui_scrollbar_bar_mode_set(obj,
         EFL_UI_SCROLLBAR_MODE_OFF, EFL_UI_SCROLLBAR_MODE_OFF);

   return obj;
}

EOLIAN static void
_efl_ui_internal_text_scroller_efl_canvas_group_group_calculate(Eo *obj,
      Efl_Ui_Internal_Text_Scroller_Data *sd)
{
   Eina_Size2D size = {-1, -1};
   Eina_Rect view = EINA_RECT(0, 0, 0, 0);
   Evas_Coord vmw = 0, vmh = 0;

   efl_canvas_group_need_recalculate_set(obj, EINA_FALSE);
   EFL_UI_SCROLLER_DATA_GET_OR_RETURN(obj, psd);

   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);


   if (psd->smanager)
     {
        view = efl_ui_scrollable_viewport_geometry_get(psd->smanager);
     }

   edje_object_size_min_calc(wd->resize_obj, &vmw, &vmh);

   if (sd->text_obj)
     {
        Eina_Size2D fsz = EINA_SIZE2D(0, 0);
        Eina_Size2D sz = EINA_SIZE2D(0, 0);

        sz = efl_gfx_entity_size_get(sd->text_table);
        efl_event_freeze(sd->text_table);
        efl_event_freeze(sd->text_obj);
        efl_gfx_entity_size_set(sd->text_table, view.size);
        efl_gfx_entity_size_set(sd->text_obj, view.size);
        fsz = efl_canvas_textblock_size_formatted_get(sd->text_obj);
        efl_gfx_entity_size_set(sd->text_table, sz);
        efl_gfx_entity_size_set(sd->text_obj, sz);
        efl_event_thaw(sd->text_obj);
        efl_event_thaw(sd->text_table);


        if (sd->mode == EFL_UI_TEXT_SCROLLER_MODE_SINGLELINE)
          {
             size.h = vmh + fsz.h;
             if (fsz.w < view.w)
               {
                  fsz.w = view.w;
               }
          }
        else
          {
             if (fsz.h < view.h)
                fsz.h = view.h;

             if (fsz.w < view.w)
                fsz.w = view.w;
          }

        efl_gfx_entity_size_set(sd->text_table, fsz);
        efl_gfx_hint_size_restricted_min_set(obj, size);
     }
}

EOLIAN static Eo *
_efl_ui_internal_text_scroller_efl_object_finalize(Eo *obj,
                                     Efl_Ui_Internal_Text_Scroller_Data *sd EINA_UNUSED)
{
   obj = efl_finalize(efl_super(obj, MY_CLASS));
   efl_ui_scrollbar_bar_mode_set(obj,
         EFL_UI_SCROLLBAR_MODE_OFF, EFL_UI_SCROLLBAR_MODE_OFF);
   efl_content_set(obj, sd->text_table);

   return obj;
}

EOLIAN static void
_efl_ui_internal_text_scroller_efl_object_destructor(Eo *obj,
                                       Efl_Ui_Internal_Text_Scroller_Data *sd EINA_UNUSED)
{
   efl_destructor(efl_super(obj, MY_CLASS));
}

EOLIAN static void
_efl_ui_internal_text_scroller_initialize(Eo *obj,
                                       Efl_Ui_Internal_Text_Scroller_Data *sd,
                                       Efl_Canvas_Textblock *text_obj,
                                       Efl_Ui_Table *text_table)
{
   if (efl_finalized_get(obj))
     {
        ERR("Can only be called on construction");
        return;
     }

   sd->text_obj = text_obj;
   sd->text_table = text_table;
}

EOLIAN static void
_efl_ui_internal_text_scroller_scroller_mode_set(Eo *obj,
                                       Efl_Ui_Internal_Text_Scroller_Data *sd,
                                       Efl_Ui_Text_Scroller_Mode mode)
{
   EFL_UI_SCROLLER_DATA_GET_OR_RETURN(obj, psd);
   sd->mode = mode;
   if (mode == EFL_UI_TEXT_SCROLLER_MODE_MULTILINE)
     {
        efl_ui_scrollbar_bar_mode_set(psd->smanager,
              EFL_UI_SCROLLBAR_MODE_AUTO, EFL_UI_SCROLLBAR_MODE_AUTO);
     }
   else // default (single-line)
     {
        efl_ui_scrollbar_bar_mode_set(psd->smanager,
              EFL_UI_SCROLLBAR_MODE_OFF, EFL_UI_SCROLLBAR_MODE_OFF);
     }
}

EOLIAN static Eo *
_efl_ui_internal_text_scroller_viewport_clip_get(const Eo *obj,
      Efl_Ui_Internal_Text_Scroller_Data *sd EINA_UNUSED)
{
   EFL_UI_SCROLLER_DATA_GET_OR_RETURN(obj, psd, NULL);
   return evas_object_clip_get(psd->pan_obj);
}

/* Internal EO APIs and hidden overrides */

#include "efl_ui_internal_text_scroller.eo.c"