The source code moved from the SPIN with license changed to Flora 1.1
[apps/native/home/homescreen-efl.git] / src / mouse.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <stdbool.h>
20 #include <Elementary.h>
21
22 #include "livebox/livebox_panel.h"
23 #include "util.h"
24 #include "livebox_all_pages.h"
25 #include "folder_panel.h"
26
27
28 static struct {
29         Ecore_Event_Handler *mouse_down;
30         Ecore_Event_Handler *mouse_up;
31         Ecore_Event_Handler *mouse_move;
32         bool pressed;
33         Evas_Coord pre_x;
34         Evas_Coord pre_y;
35         bool is_initialized;
36         Evas_Coord down_x;
37         Evas_Coord down_y;
38         Evas_Coord move_x;
39         Evas_Coord move_y;
40         Evas_Coord up_x;
41         Evas_Coord up_y;
42 } mouse_info = {
43         .mouse_down = NULL,
44         .mouse_up = NULL,
45         .mouse_move = NULL,
46         .pressed = false,
47         .pre_x = 0,
48         .pre_y = 0,
49         .is_initialized = false,
50         .down_x = 0,
51         .down_y = 0,
52         .move_x = 0,
53         .move_y = 0,
54         .up_x = 0,
55         .up_y = 0,
56 };
57
58
59 static Eina_Bool __mouse_down_cb(void *data, int type, void *event);
60 static Eina_Bool __mouse_up_cb(void *data, int type, void *event);
61 static Eina_Bool __mouse_move_cb(void *data, int type, void *event);
62
63
64 HAPI void mouse_register(void)
65 {
66         mouse_info.mouse_down = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, __mouse_down_cb, NULL);
67         if (!mouse_info.mouse_down)
68                 LOGD("Failed to register the mouse down event callback");
69
70         mouse_info.mouse_move = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, __mouse_move_cb, NULL);
71         if (!mouse_info.mouse_move) {
72                 LOGD("Failed to register the mouse move event callback");
73                 ecore_event_handler_del(mouse_info.mouse_down);
74                 mouse_info.mouse_down = NULL;
75         }
76
77         mouse_info.mouse_up = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, __mouse_up_cb, NULL);
78         if (!mouse_info.mouse_up) {
79                 LOGD("Failed to register the mouse up event callback");
80                 ecore_event_handler_del(mouse_info.mouse_down);
81                 ecore_event_handler_del(mouse_info.mouse_move);
82
83                 mouse_info.mouse_down = NULL;
84                 mouse_info.mouse_move = NULL;
85         }
86 }
87
88
89 HAPI void mouse_unregister(void)
90 {
91         if (mouse_info.mouse_down) {
92                 ecore_event_handler_del(mouse_info.mouse_down);
93                 mouse_info.mouse_down = NULL;
94         }
95
96         if (mouse_info.mouse_up) {
97                 ecore_event_handler_del(mouse_info.mouse_up);
98                 mouse_info.mouse_up = NULL;
99         }
100
101         if (mouse_info.mouse_move) {
102                 ecore_event_handler_del(mouse_info.mouse_move);
103                 mouse_info.mouse_move = NULL;
104         }
105 }
106
107
108 static Eina_Bool __mouse_down_cb(void *data, int type, void *event)
109 {
110         Ecore_Event_Mouse_Button *move = event;
111
112         if (mouse_info.pressed)
113                 return ECORE_CALLBACK_RENEW;
114
115         mouse_info.pressed = true;
116         mouse_info.is_initialized = false;
117
118         mouse_info.down_x = move->root.x;
119         mouse_info.down_y = move->root.y;
120
121         return ECORE_CALLBACK_RENEW;
122 }
123
124
125 static Eina_Bool __mouse_up_cb(void *data, int type, void *event)
126 {
127         Ecore_Event_Mouse_Button *move = event;
128
129         if (!mouse_info.pressed)
130                 return ECORE_CALLBACK_RENEW;
131
132         mouse_info.pressed = false;
133         mouse_info.pre_x = 0;
134         mouse_info.pre_y = 0;
135
136         mouse_info.up_x = move->root.x;
137         mouse_info.up_y = move->root.y;
138
139         livebox_all_pages_up_item();
140
141         return ECORE_CALLBACK_RENEW;
142 }
143
144 static Eina_Bool __mouse_move_cb(void *data, int type, void *event)
145 {
146         Ecore_Event_Mouse_Move *move = event;
147
148         mouse_info.move_x = move->root.x;
149         mouse_info.move_y = move->root.y;
150
151         if (mouse_info.pressed == false)
152                 return ECORE_CALLBACK_RENEW;
153
154         livebox_all_pages_move_item(move->root.x, move->root.y);
155         livebox_panel_move_mouse_cb(move->root.x, move->root.y);
156
157         return ECORE_CALLBACK_RENEW;
158 }
159
160
161
162