Root/
| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by Mirko Lindner,,, * |
| 3 | * vegyraupe@mira * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | |
| 22 | // newer (non customized) versions of this file go to main_window.cc_new |
| 23 | |
| 24 | // This file is for your program, I won't touch it again! |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "main_window.hh" |
| 28 | #include "vido.hh" |
| 29 | #include <cxxtools/log.h> |
| 30 | |
| 31 | // extern "C" { |
| 32 | // #include <directfb/directfb.h> |
| 33 | // #include <gtk-2.0/gdk/gdkdisplay-directfb.h> |
| 34 | // #include <gtk-2.0/gdk/gdkdirectfb.h> |
| 35 | // } |
| 36 | |
| 37 | log_define("vido.main_window"); |
| 38 | |
| 39 | main_window::main_window() |
| 40 | { |
| 41 | sigc::connection press_id; |
| 42 | sigc::connection release_id; |
| 43 | |
| 44 | } |
| 45 | |
| 46 | void main_window::connect_all() |
| 47 | { |
| 48 | // (*this).add_events( Gdk::BUTTON_PRESS_MASK ) ; |
| 49 | log_debug("connecting all"); |
| 50 | // (*this).press_id = signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event)); |
| 51 | // (*this).release_id = signal_key_release_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_release_event)); |
| 52 | // (*this).press_id = |
| 53 | |
| 54 | (*this).add_events (Gdk::ALL_EVENTS_MASK); |
| 55 | |
| 56 | (*this).press_id = (*this).signal_key_press_event().connect_notify(sigc::mem_fun(*this,&main_window::on_notify_key_press_event)); |
| 57 | (*this).release_id = (*this).signal_key_release_event().connect_notify(sigc::mem_fun(*this,&main_window::on_notify_key_release_event)); |
| 58 | // (*this).motion_id = (*this).signal_event().connect_notify(sigc::mem_fun(*this,&main_window::on_notify_motion_notify_event)); |
| 59 | log_debug((*this).press_id << " " << (*this).release_id); |
| 60 | log_debug("event mask " << (*this).get_events()); |
| 61 | } |
| 62 | |
| 63 | void main_window::disconnect_all() |
| 64 | { |
| 65 | log_debug("disconnecting all"); |
| 66 | (*this).press_id.disconnect(); |
| 67 | (*this).release_id.disconnect(); |
| 68 | log_debug((*this).press_id << " " << (*this).release_id); |
| 69 | } |
| 70 | |
| 71 | void main_window::on_notify_motion_notify_event ( GdkEvent *event) |
| 72 | { |
| 73 | // gdouble x, y; |
| 74 | // gdouble pressure; |
| 75 | // GdkModifierType state; |
| 76 | // |
| 77 | // if (event->is_hint) |
| 78 | // gdk_input_window_get_pointer (event->window, event->deviceid, |
| 79 | // &x, &y, &pressure, NULL, NULL, &state); |
| 80 | // else |
| 81 | // { |
| 82 | // x = event->x; |
| 83 | // y = event->y; |
| 84 | // pressure = event->pressure; |
| 85 | // state = event->state; |
| 86 | // } |
| 87 | // |
| 88 | // if (state & GDK_BUTTON1_MASK && pixmap != NULL) |
| 89 | // draw_brush (widget, event->source, x, y, pressure); |
| 90 | // |
| 91 | log_debug("event here " << event->type); |
| 92 | // return TRUE; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | void main_window::move_cursor(int direction){ |
| 97 | |
| 98 | int x=0, y=0, xadd=0, yadd=0; |
| 99 | Glib::RefPtr<Gdk::Display> display; |
| 100 | display = display->get_default(); |
| 101 | Glib::RefPtr<Gdk::Screen> screen = display->get_default_screen(); |
| 102 | // screen = display->get_default_screen(); |
| 103 | log_debug("display: " << display); |
| 104 | log_debug("screen: " << screen); |
| 105 | /* check for up/down/left/right arrow key press */ |
| 106 | log_debug("moving " << direction); |
| 107 | switch (direction) |
| 108 | { |
| 109 | case 65361: |
| 110 | xadd -= 5; |
| 111 | break; |
| 112 | case 65363: |
| 113 | xadd += 5; |
| 114 | break; |
| 115 | case 65362: |
| 116 | yadd -= 5; |
| 117 | break; |
| 118 | case 65364: |
| 119 | yadd += 5; |
| 120 | break; |
| 121 | default: |
| 122 | log_debug("unknown direction"); |
| 123 | break; |
| 124 | // return FALSE; /* propogate event */ |
| 125 | } |
| 126 | |
| 127 | /* get default display and screen */ |
| 128 | // display = Gdk::Display::get_default(); |
| 129 | // screen =Gdk::Display::get_default_screen(); |
| 130 | // screen = gdk_display_get_default_screen (display); |
| 131 | |
| 132 | /* get cursor position */ |
| 133 | // GdkWindow* ; |
| 134 | // IDirectFBWindow *gdk_directfb_window_lookup(gtk_widget_get_root_window(scrolled_window2)); |
| 135 | // GdkDisplay gdk_display_open((const gchar) display->get_name()); |
| 136 | Gdk::ModifierType mask; |
| 137 | // display->get_pointer(x, y, mask); |
| 138 | // log_debug("unknown direction 2"); |
| 139 | |
| 140 | /* set new cusor position */ |
| 141 | // x += xadd; |
| 142 | // y += yadd; |
| 143 | // IDirectFB *directfb; |
| 144 | // log_debug("unknown direction 3"); |
| 145 | |
| 146 | |
| 147 | // GType _gdk_display = g_object_new (GDK_TYPE_DISPLAY_DFB, NULL); |
| 148 | // display->directfb = directfb; |
| 149 | |
| 150 | // IDirectFBDisplayLayer *layer; |
| 151 | // int ret = directfb->GetDisplayLayer (directfb, DLID_PRIMARY, &layer); |
| 152 | // log_debug("unknown direction 4"); |
| 153 | |
| 154 | // int ret = directfb->GetDisplayLayer (directfb, DLID_PRIMARY, &layer); |
| 155 | |
| 156 | |
| 157 | // DFBResult result; |
| 158 | // log_debug("unknown direction 5"); |
| 159 | // |
| 160 | // result = layer->WarpCursor(layer, x, y); |
| 161 | // log_debug("unknown direction 6"); |
| 162 | |
| 163 | // Gdk::ModifierType mask; |
| 164 | display->get_pointer(x, y, mask); |
| 165 | // log_debug("pointer x: " << x << "pointer y: " << display->pointer_hooks); |
| 166 | |
| 167 | // display->warp_pointer( screen, x, y); |
| 168 | |
| 169 | // Gdk::Event event(); |
| 170 | |
| 171 | // Gdk::Event event(gdk_event_new(GDK_MOTION_NOTIFY),true); |
| 172 | // |
| 173 | // // get_window_and_coordinates(event->button.window, event->button.x, event->button.y, event->button.x_root, event->button.y_root); |
| 174 | // event.send_event = TRUE; |
| 175 | // event.time = GDK_CURRENT_TIME; |
| 176 | // event.axes = 0; |
| 177 | // event.state = 0; |
| 178 | // event.motion.x = x; |
| 179 | // event.motion.y = y; |
| 180 | // /* set new cusor position */ |
| 181 | x += xadd; |
| 182 | y += yadd; |
| 183 | // event.motion.x_root = x; |
| 184 | // event.motion.y_root = y; |
| 185 | // // event->button.button = Button; |
| 186 | // // event->button.device = gdk_device_get_core_pointer(); |
| 187 | // |
| 188 | // // g_object_ref(event->screen.window); |
| 189 | // event.put(); |
| 190 | // handle_pending_events(); |
| 191 | // gdk_event_free(event); |
| 192 | Glib::RefPtr<Gdk::Device> pointer = display->get_core_pointer(); |
| 193 | log_debug("type cursor: " << pointer->get_source()); |
| 194 | log_debug("pointer xadd: " << xadd << "pointer yadd: " << yadd ); |
| 195 | if ((screen != 0) && (display!= 0)){ |
| 196 | display->warp_pointer( screen, x, y); |
| 197 | // this->signal_motion_notify_event(); |
| 198 | // g_signal_emit (G_OBJECT(display->gobj()), GDK_MOTION_NOTIFY, NULL, x= x, y = y); |
| 199 | |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | bool main_window::actions(int key) |
| 204 | { |
| 205 | // log_debug("in actions" << (*this).press_id << " " << (*this).release_id); |
| 206 | static int key_b = 98; |
| 207 | static int key_f = 102; |
| 208 | static int key_h = 104; |
| 209 | static int key_q = 113; |
| 210 | static int key_r = 114; |
| 211 | static int key_s = 115; |
| 212 | static int key_t = 116; |
| 213 | static int key_f1 = 65470; |
| 214 | static int key_left = 65361; |
| 215 | static int key_up = 65362; |
| 216 | static int key_right = 65363; |
| 217 | static int key_down = 65364; |
| 218 | |
| 219 | |
| 220 | // key commands only available if ctrl pressed |
| 221 | if ((ctrl_state == 1) && ((*this).press_id == 1)) |
| 222 | { |
| 223 | (*this).disconnect_all(); |
| 224 | if (key == key_q) |
| 225 | { |
| 226 | // log_debug("quit requested"); |
| 227 | (*this).quit(); |
| 228 | } |
| 229 | else if(key == key_r) |
| 230 | { |
| 231 | // log_debug("random"); |
| 232 | show_random(); |
| 233 | } |
| 234 | else if(key == key_s) |
| 235 | { |
| 236 | log_debug("search"); |
| 237 | search_window(this); |
| 238 | }else if(key == key_t){ |
| 239 | GoToTop(); |
| 240 | }else if(key == key_h){ |
| 241 | show_history(); |
| 242 | }else if(key == key_f){ |
| 243 | history_jump(1); |
| 244 | }else if(key == key_b){ |
| 245 | history_jump(-1); |
| 246 | } |
| 247 | else{ |
| 248 | (*this).connect_all(); |
| 249 | // log_debug("key pressed: " << key); |
| 250 | } |
| 251 | // other commands |
| 252 | }else{ |
| 253 | if(key == key_f1){ |
| 254 | (*this).disconnect_all(); |
| 255 | show_help(); |
| 256 | }else if(key == 65361){ |
| 257 | log_debug("key is left"); |
| 258 | (*this).move_cursor(key); |
| 259 | }else if(key == key_right){ |
| 260 | (*this).move_cursor(key); |
| 261 | }else if(key == key_up){ |
| 262 | (*this).move_cursor(key); |
| 263 | }else if(key == key_down){ |
| 264 | (*this).move_cursor(key); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return true; |
| 269 | |
| 270 | } |
| 271 | |
| 272 | void main_window::on_notify_key_press_event(GdkEventKey *Key) |
| 273 | { |
| 274 | |
| 275 | if (Key->keyval == gdk_keyval_from_name("Control_R")) |
| 276 | { |
| 277 | ctrl_state = 1; |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | actions(Key->keyval); |
| 282 | } |
| 283 | log_debug("Key Presssed is " << Key->keyval); |
| 284 | } |
| 285 | |
| 286 | void main_window::on_notify_key_release_event(GdkEventKey *Key) |
| 287 | { |
| 288 | if (Key->keyval == gdk_keyval_from_name("Control_R")) |
| 289 | { |
| 290 | ctrl_state = 0; |
| 291 | } |
| 292 | |
| 293 | } |
| 294 | |
| 295 | // bool main_window::on_my_key_press_event(GdkEventKey *Key) |
| 296 | // { |
| 297 | // if (Key->keyval == gdk_keyval_from_name("Control_R")) |
| 298 | // { |
| 299 | // ctrl_state = 1; |
| 300 | // } |
| 301 | // else |
| 302 | // { |
| 303 | // actions(Key->keyval); |
| 304 | // } |
| 305 | // log_debug("Key Presssed is " << Key->keyval); |
| 306 | // return true; |
| 307 | // } |
| 308 | |
| 309 | // bool main_window::on_my_key_release_event(GdkEventKey *Key) |
| 310 | // { |
| 311 | // if (Key->keyval == gdk_keyval_from_name("Control_R")) |
| 312 | // { |
| 313 | // ctrl_state = 0; |
| 314 | // } |
| 315 | // |
| 316 | // return true; |
| 317 | // } |
| 318 | |
| 319 | bool main_window::quit() |
| 320 | { |
| 321 | (*this).destroy_(); |
| 322 | return false; |
| 323 | } |
| 324 |
Branches:
development
master
