/[svn]/gigedit/trunk/src/gigedit/dimregionchooser.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/dimregionchooser.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1420 - (show annotations) (download)
Sun Oct 14 15:39:32 2007 UTC (13 years, 3 months ago) by persson
File size: 25673 byte(s)
* removed some compiler warnings and a verbose logging

1 /*
2 * Copyright (C) 2006, 2007 Andreas Persson
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with program; see the file COPYING. If not, write to the Free
16 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include "dimregionchooser.h"
21 #include <gdkmm/cursor.h>
22
23 DimRegionChooser::DimRegionChooser()
24 {
25 // get_window() would return 0 because the Gdk::Window has not yet been realized
26 // So we can only allocate the colors here - the rest will happen in on_realize().
27 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
28
29 black = Gdk::Color("black");
30 white = Gdk::Color("white");
31 red = Gdk::Color("#8070ff");
32 blue = Gdk::Color("blue");
33 green = Gdk::Color("green");
34
35 colormap->alloc_color(black);
36 colormap->alloc_color(white);
37 colormap->alloc_color(red);
38 colormap->alloc_color(blue);
39 colormap->alloc_color(green);
40 instrument = 0;
41 region = 0;
42 dimregno = -1;
43 focus_line = 0;
44 resize.active = false;
45 cursor_is_resize = false;
46 h = 20;
47 w = 800;
48 set_flags(Gtk::CAN_FOCUS);
49 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |
50 Gdk::POINTER_MOTION_HINT_MASK);
51
52 for (int i = 0 ; i < 256 ; i++) dimvalue[i] = 0;
53 }
54
55 DimRegionChooser::~DimRegionChooser()
56 {
57 }
58
59 void DimRegionChooser::on_realize()
60 {
61 // We need to call the base on_realize()
62 Gtk::DrawingArea::on_realize();
63
64 // Now we can allocate any additional resources we need
65 Glib::RefPtr<Gdk::Window> window = get_window();
66 gc = Gdk::GC::create(window);
67 }
68
69 bool DimRegionChooser::on_expose_event(GdkEventExpose* event)
70 {
71 if (!region) return true;
72
73 // This is where we draw on the window
74 Glib::RefPtr<Gdk::Window> window = get_window();
75 Glib::RefPtr<Pango::Context> context = get_pango_context();
76
77 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
78
79 window->clear();
80
81 // draw labels on the left (reflecting the dimension type)
82 int y = 0;
83 double maxwidth = 0;
84 for (int i = 0 ; i < region->Dimensions ; i++) {
85 int nbZones = region->pDimensionDefinitions[i].zones;
86 if (nbZones) {
87 const char* dstr;
88 char dstrbuf[10];
89 switch (region->pDimensionDefinitions[i].dimension) {
90 case gig::dimension_none: dstr="none"; break;
91 case gig::dimension_samplechannel: dstr="samplechannel"; break;
92 case gig::dimension_layer: dstr="layer"; break;
93 case gig::dimension_velocity: dstr="velocity"; break;
94 case gig::dimension_channelaftertouch: dstr="channelaftertouch"; break;
95 case gig::dimension_releasetrigger: dstr="releasetrigger"; break;
96 case gig::dimension_keyboard: dstr="keyboard"; break;
97 case gig::dimension_roundrobin: dstr="roundrobin"; break;
98 case gig::dimension_random: dstr="random"; break;
99 case gig::dimension_smartmidi: dstr="smartmidi"; break;
100 case gig::dimension_roundrobinkeyboard: dstr="roundrobinkeyboard"; break;
101 case gig::dimension_modwheel: dstr="modwheel"; break;
102 case gig::dimension_breath: dstr="breath"; break;
103 case gig::dimension_foot: dstr="foot"; break;
104 case gig::dimension_portamentotime: dstr="portamentotime"; break;
105 case gig::dimension_effect1: dstr="effect1"; break;
106 case gig::dimension_effect2: dstr="effect2"; break;
107 case gig::dimension_genpurpose1: dstr="genpurpose1"; break;
108 case gig::dimension_genpurpose2: dstr="genpurpose2"; break;
109 case gig::dimension_genpurpose3: dstr="genpurpose3"; break;
110 case gig::dimension_genpurpose4: dstr="genpurpose4"; break;
111 case gig::dimension_sustainpedal: dstr="sustainpedal"; break;
112 case gig::dimension_portamento: dstr="portamento"; break;
113 case gig::dimension_sostenutopedal: dstr="sostenutopedal"; break;
114 case gig::dimension_softpedal: dstr="softpedal"; break;
115 case gig::dimension_genpurpose5: dstr="genpurpose5"; break;
116 case gig::dimension_genpurpose6: dstr="genpurpose6"; break;
117 case gig::dimension_genpurpose7: dstr="genpurpose7"; break;
118 case gig::dimension_genpurpose8: dstr="genpurpose8"; break;
119 case gig::dimension_effect1depth: dstr="effect1depth"; break;
120 case gig::dimension_effect2depth: dstr="effect2depth"; break;
121 case gig::dimension_effect3depth: dstr="effect3depth"; break;
122 case gig::dimension_effect4depth: dstr="effect4depth"; break;
123 case gig::dimension_effect5depth: dstr="effect5depth"; break;
124 default:
125 sprintf(dstrbuf, "%d",
126 region->pDimensionDefinitions[i].dimension);
127 dstr = dstrbuf;
128 break;
129 }
130 layout->set_text(dstr);
131
132 Pango::Rectangle rectangle = layout->get_logical_extents();
133 double text_w = double(rectangle.get_width()) / Pango::SCALE;
134 if (text_w > maxwidth) maxwidth = text_w;
135 double text_h = double(rectangle.get_height()) / Pango::SCALE;
136 Glib::RefPtr<const Gdk::GC> fg = get_style()->get_fg_gc(get_state());
137 window->draw_layout(fg, 4, int(y + (h - text_h) / 2 + 0.5), layout);
138
139 }
140 y += h;
141 }
142
143 // draw dimensions' zones areas
144 y = 0;
145 int bitpos = 0;
146 label_width = int(maxwidth + 10);
147 for (int i = 0 ; i < region->Dimensions ; i++) {
148 int nbZones = region->pDimensionDefinitions[i].zones;
149 if (nbZones) {
150 // draw focus rectangle around dimension's label and zones
151 if (has_focus() && focus_line == i) {
152 Gdk::Rectangle farea(0, y, 150, 20);
153 get_style()->paint_focus(window, get_state(), farea, *this, "",
154 0, y, label_width, 20);
155 }
156
157 Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
158 // draw top and bottom lines of dimension's zones
159 window->draw_line(black, label_width, y, w - 1, y);
160 window->draw_line(black, w - 1, y + h - 1, label_width, y + h - 1);
161 // erase whole dimension's zones area
162 window->draw_rectangle(get_style()->get_white_gc(), true,
163 label_width + 1, y + 1, (w - label_width - 2), h - 2);
164
165 int c = 0;
166 if (dimregno >= 0) {
167 int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos);
168 c = dimregno & mask; // mask away this dimension
169 }
170 bool customsplits =
171 ((region->pDimensionDefinitions[i].split_type == gig::split_type_normal &&
172 region->pDimensionRegions[c]->DimensionUpperLimits[i]) ||
173 (region->pDimensionDefinitions[i].dimension == gig::dimension_velocity &&
174 region->pDimensionRegions[c]->VelocityUpperLimit));
175
176 // draw dimension's zone borders
177 if (customsplits) {
178 window->draw_line(black, label_width, y + 1, label_width, y + h - 2);
179 for (int j = 0 ; j < nbZones ; j++) {
180 gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
181 int upperLimit = d->DimensionUpperLimits[i];
182 if (!upperLimit) upperLimit = d->VelocityUpperLimit;
183 int v = upperLimit + 1;
184 int x = int((w - label_width - 1) * v / 128.0 + 0.5);
185 window->draw_line(black, label_width + x, y + 1, label_width + x, y + h - 2);
186 }
187 } else {
188 for (int j = 0 ; j <= nbZones ; j++) {
189 int x = int((w - label_width - 1) * j / double(nbZones) + 0.5);
190 window->draw_line(black, label_width + x, y + 1, label_width + x, y + h - 2);
191 }
192 }
193
194 // draw fill for currently selected zone
195 if (dimregno >= 0) {
196 gc->set_foreground(red);
197 int dr = (dimregno >> bitpos) & ((1 << region->pDimensionDefinitions[i].bits) - 1);
198 if (customsplits) {
199 int x1 = 0;
200 for (int j = 0 ; j < nbZones ; j++) {
201 gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
202 int upperLimit = d->DimensionUpperLimits[i];
203 if (!upperLimit) upperLimit = d->VelocityUpperLimit;
204 int v = upperLimit + 1;
205 int x2 = int((w - label_width - 1) * v / 128.0 + 0.5);
206 if (j == dr && x1 < x2) {
207 window->draw_rectangle(gc, true, label_width + x1 + 1, y + 1,
208 (x2 - x1) - 1, h - 2);
209 break;
210 }
211 x1 = x2;
212 }
213 } else {
214 if (dr < nbZones) {
215 int x1 = int((w - label_width - 1) * dr / double(nbZones) + 0.5);
216 int x2 = int((w - label_width - 1) * (dr + 1) / double(nbZones) + 0.5);
217 window->draw_rectangle(gc, true, label_width + x1 + 1, y + 1,
218 (x2 - x1) - 1, h - 2);
219 }
220 }
221 }
222
223 y += h;
224 }
225 bitpos += region->pDimensionDefinitions[i].bits;
226 }
227
228 return true;
229 }
230
231 void DimRegionChooser::on_size_request(GtkRequisition* requisition)
232 {
233 *requisition = GtkRequisition();
234 requisition->height = region ? nbDimensions * 20 : 0;
235 requisition->width = 800;
236 }
237
238 void DimRegionChooser::set_region(gig::Region* region)
239 {
240 this->region = region;
241 dimregno = 0;
242 nbDimensions = 0;
243 if (region) {
244 int bitcount = 0;
245 for (int dim = 0 ; dim < region->Dimensions ; dim++) {
246 if (region->pDimensionDefinitions[dim].bits == 0) continue;
247 nbDimensions++;
248
249 int z = std::min(dimvalue[region->pDimensionDefinitions[dim].dimension],
250 region->pDimensionDefinitions[dim].zones - 1);
251 int mask =
252 ~(((1 << region->pDimensionDefinitions[dim].bits) - 1) <<
253 bitcount);
254 dimregno &= mask;
255 dimregno |= (z << bitcount);
256 bitcount += region->pDimensionDefinitions[dim].bits;
257 }
258 dimreg = region->pDimensionRegions[dimregno];
259 } else {
260 dimreg = 0;
261 }
262 dimregion_selected();
263 queue_resize();
264 }
265
266 bool DimRegionChooser::on_button_release_event(GdkEventButton* event)
267 {
268 if (resize.active) {
269 get_window()->pointer_ungrab(event->time);
270 resize.active = false;
271
272 if (region->pDimensionDefinitions[resize.dimension].dimension == gig::dimension_velocity) {
273
274 int bitpos = 0;
275 for (int j = 0 ; j < resize.dimension ; j++) {
276 bitpos += region->pDimensionDefinitions[j].bits;
277 }
278 int mask =
279 ~(((1 << region->pDimensionDefinitions[resize.dimension].bits) - 1) << bitpos);
280 int c = dimregno & mask; // mask away this dimension
281
282 if (region->pDimensionRegions[c]->DimensionUpperLimits[resize.dimension] == 0) {
283 // the velocity dimension didn't previously have
284 // custom v3 splits, so we initialize all splits with
285 // default values
286 int nbZones = region->pDimensionDefinitions[resize.dimension].zones;
287 for (int j = 0 ; j < nbZones ; j++) {
288 gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
289 d->DimensionUpperLimits[resize.dimension] = int(128.0 * (j + 1) / nbZones - 1);
290 }
291 }
292 if (region->pDimensionRegions[c]->VelocityUpperLimit == 0) {
293 // the velocity dimension didn't previously have
294 // custom v2 splits, so we initialize all splits with
295 // default values
296 int nbZones = region->pDimensionDefinitions[resize.dimension].zones;
297 for (int j = 0 ; j < nbZones ; j++) {
298 gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
299 d->VelocityUpperLimit = int(128.0 * (j + 1) / nbZones - 1);
300 }
301 }
302
303 gig::DimensionRegion *d = region->pDimensionRegions[c + resize.offset];
304 // update both v2 and v3 values
305 d->DimensionUpperLimits[resize.dimension] = resize.pos - 1;
306 d->VelocityUpperLimit = resize.pos - 1;
307
308 } else {
309 for (int i = 0 ; i < region->DimensionRegions ; ) {
310
311 if (region->pDimensionRegions[i]->DimensionUpperLimits[resize.dimension] == 0) {
312 // the dimension didn't previously have custom
313 // limits, so we have to set default limits for
314 // all the dimension regions
315 int bitpos = 0;
316 for (int j = 0 ; j < resize.dimension ; j++) {
317 bitpos += region->pDimensionDefinitions[j].bits;
318 }
319 int nbZones = region->pDimensionDefinitions[resize.dimension].zones;
320
321 for (int j = 0 ; j < nbZones ; j++) {
322 gig::DimensionRegion *d = region->pDimensionRegions[i + (j << bitpos)];
323 d->DimensionUpperLimits[resize.dimension] = int(128.0 * (j + 1) / nbZones - 1);
324 }
325 }
326 gig::DimensionRegion *d = region->pDimensionRegions[i + resize.offset];
327 d->DimensionUpperLimits[resize.dimension] = resize.pos - 1;
328
329 int bitpos = 0;
330 int j;
331 for (j = 0 ; j < region->Dimensions ; j++) {
332 if (j != resize.dimension) {
333 int maxzones = 1 << region->pDimensionDefinitions[j].bits;
334 int dimj = (i >> bitpos) & (maxzones - 1);
335 if (dimj + 1 < region->pDimensionDefinitions[j].zones) break;
336 }
337 bitpos += region->pDimensionDefinitions[j].bits;
338 }
339 if (j == region->Dimensions) break;
340 i = (i & ~((1 << bitpos) - 1)) + (1 << bitpos);
341 }
342 }
343 region_changed();
344
345 if (!is_in_resize_zone(event->x, event->y) && cursor_is_resize) {
346 get_window()->set_cursor();
347 cursor_is_resize = false;
348 }
349 }
350 return true;
351 }
352
353 bool DimRegionChooser::on_button_press_event(GdkEventButton* event)
354 {
355 if (region && event->y < nbDimensions * h &&
356 event->x >= label_width && event->x < w) {
357
358 if (is_in_resize_zone(event->x, event->y)) {
359 Gdk::Cursor double_arrow(Gdk::SB_H_DOUBLE_ARROW);
360 get_window()->pointer_grab(false,
361 Gdk::BUTTON_RELEASE_MASK |
362 Gdk::POINTER_MOTION_MASK |
363 Gdk::POINTER_MOTION_HINT_MASK,
364 double_arrow, event->time);
365 resize.active = true;
366 } else {
367 int ydim = int(event->y / h);
368 int dim;
369 for (dim = 0 ; dim < region->Dimensions ; dim++) {
370 if (region->pDimensionDefinitions[dim].bits == 0) continue;
371 if (ydim == 0) break;
372 ydim--;
373 }
374 int nbZones = region->pDimensionDefinitions[dim].zones;
375
376 int z = -1;
377 int bitpos = 0;
378 for (int i = 0 ; i < dim ; i++) {
379 bitpos += region->pDimensionDefinitions[i].bits;
380 }
381
382 int i = dim;
383 if (dimregno < 0) dimregno = 0;
384 int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos);
385 int c = dimregno & mask; // mask away this dimension
386
387 bool customsplits =
388 ((region->pDimensionDefinitions[i].split_type == gig::split_type_normal &&
389 region->pDimensionRegions[c]->DimensionUpperLimits[i]) ||
390 (region->pDimensionDefinitions[i].dimension == gig::dimension_velocity &&
391 region->pDimensionRegions[c]->VelocityUpperLimit));
392 if (customsplits) {
393 int val = int((event->x - label_width) * 128 / (w - label_width - 1));
394
395 if (region->pDimensionRegions[c]->DimensionUpperLimits[i]) {
396 for (z = 0 ; z < nbZones ; z++) {
397 gig::DimensionRegion *d = region->pDimensionRegions[c + (z << bitpos)];
398 if (val <= d->DimensionUpperLimits[i]) break;
399 }
400 } else {
401 for (z = 0 ; z < nbZones ; z++) {
402 gig::DimensionRegion *d = region->pDimensionRegions[c + (z << bitpos)];
403 if (val <= d->VelocityUpperLimit) break;
404 }
405 }
406 } else {
407 z = int((event->x - label_width) * nbZones / (w - label_width - 1));
408 }
409
410 printf("dim=%d z=%d dimensionsource=%d split_type=%d zones=%d zone_size=%f\n", dim, z,
411 region->pDimensionDefinitions[dim].dimension,
412 region->pDimensionDefinitions[dim].split_type,
413 region->pDimensionDefinitions[dim].zones,
414 region->pDimensionDefinitions[dim].zone_size);
415 dimvalue[region->pDimensionDefinitions[dim].dimension] = z;
416
417 dimregno = c | (z << bitpos);
418
419 focus_line = dim;
420 if (has_focus()) queue_draw();
421 else grab_focus();
422 dimreg = region->pDimensionRegions[dimregno];
423 dimregion_selected();
424 }
425 }
426 return true;
427 }
428
429 bool DimRegionChooser::on_motion_notify_event(GdkEventMotion* event)
430 {
431 Glib::RefPtr<Gdk::Window> window = get_window();
432 int x, y;
433 Gdk::ModifierType state = Gdk::ModifierType(0);
434 window->get_pointer(x, y, state);
435
436 if (resize.active) {
437 int k = int((x - label_width) * 128.0 / (w - label_width - 1) + 0.5);
438
439 if (k < resize.min) k = resize.min;
440 else if (k > resize.max) k = resize.max;
441
442 if (k < 2) k = 2; // k is upper limit + 1, upper limit 0 is forbidden
443
444 if (k != resize.pos) {
445 Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
446 Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();
447
448 int prevx = int((w - label_width - 1) * resize.pos / 128.0 + 0.5) + label_width;
449 int x = int((w - label_width - 1) * k / 128.0 + 0.5) + label_width;
450 int y = resize.dimension * h;
451
452 if (resize.selected == resize.none) {
453 if (resize.pos != resize.min && resize.pos != resize.max) {
454 window->draw_line(white, prevx, y + 1, prevx, y + h - 2);
455 }
456 } else {
457 gc->set_foreground(red);
458
459 Glib::RefPtr<const Gdk::GC> left;
460 Glib::RefPtr<const Gdk::GC> right;
461 if (resize.selected == resize.left) {
462 left = gc;
463 right = white;
464 } else {
465 left = white;
466 right = gc;
467 }
468
469 if (k > resize.pos) {
470 int xx = resize.pos == resize.min ? 1 : 0;
471 window->draw_rectangle(left, true,
472 prevx + xx, y + 1, x - prevx - xx, h - 2);
473 } else {
474 int xx = resize.pos == resize.max ? 0 : 1;
475 window->draw_rectangle(right, true,
476 x, y + 1, prevx - x + xx, h - 2);
477 }
478 }
479 window->draw_line(black, x, y + 1, x, y + h - 2);
480 resize.pos = k;
481 }
482 } else {
483 if (is_in_resize_zone(x, y)) {
484 if (!cursor_is_resize) {
485 Gdk::Cursor double_arrow(Gdk::SB_H_DOUBLE_ARROW);
486 window->set_cursor(double_arrow);
487 cursor_is_resize = true;
488 }
489 } else if (cursor_is_resize) {
490 window->set_cursor();
491 cursor_is_resize = false;
492 }
493 }
494 return true;
495 }
496
497 bool DimRegionChooser::is_in_resize_zone(double x, double y)
498 {
499 if (region && y < nbDimensions * h && x >= label_width && x < w) {
500 int ydim = int(y / h);
501 int dim;
502 int bitpos = 0;
503 for (dim = 0 ; dim < region->Dimensions ; dim++) {
504 if (region->pDimensionDefinitions[dim].bits == 0) continue;
505 if (ydim == 0) break;
506 ydim--;
507 bitpos += region->pDimensionDefinitions[dim].bits;
508 }
509 int nbZones = region->pDimensionDefinitions[dim].zones;
510
511 int c = 0;
512 if (dimregno >= 0) {
513 int mask = ~(((1 << region->pDimensionDefinitions[dim].bits) - 1) << bitpos);
514 c = dimregno & mask; // mask away this dimension
515 }
516 const bool customsplits =
517 ((region->pDimensionDefinitions[dim].split_type == gig::split_type_normal &&
518 region->pDimensionRegions[c]->DimensionUpperLimits[dim]) ||
519 (region->pDimensionDefinitions[dim].dimension == gig::dimension_velocity &&
520 region->pDimensionRegions[c]->VelocityUpperLimit));
521
522 // dimensions of split_type_bit cannot be resized
523 if (region->pDimensionDefinitions[dim].split_type != gig::split_type_bit) {
524 int prev_limit = 0;
525 for (int iZone = 0 ; iZone < nbZones - 1 ; iZone++) {
526 gig::DimensionRegion *d = region->pDimensionRegions[c + (iZone << bitpos)];
527 const int upperLimit =
528 (customsplits) ?
529 (d->DimensionUpperLimits[dim]) ?
530 d->DimensionUpperLimits[dim] : d->VelocityUpperLimit
531 : (iZone+1) * (int)region->pDimensionDefinitions[dim].zone_size - 1;
532 int limit = upperLimit + 1;
533 int limitx = int((w - label_width - 1) * limit / 128.0 + 0.5) + label_width;
534 if (x <= limitx - 2) break;
535 if (x <= limitx + 2) {
536 resize.dimension = dim;
537 resize.offset = iZone << bitpos;
538 resize.pos = limit;
539 resize.min = prev_limit;
540
541 int dr = (dimregno >> bitpos) &
542 ((1 << region->pDimensionDefinitions[dim].bits) - 1);
543 resize.selected = dr == iZone ? resize.left :
544 dr == iZone + 1 ? resize.right : resize.none;
545
546 iZone++;
547 gig::DimensionRegion *d = region->pDimensionRegions[c + (iZone << bitpos)];
548
549 const int upperLimit =
550 (customsplits) ?
551 (d->DimensionUpperLimits[dim]) ?
552 d->DimensionUpperLimits[dim] : d->VelocityUpperLimit
553 : (iZone+1) * (int)region->pDimensionDefinitions[dim].zone_size - 1;
554
555 int limit = upperLimit + 1;
556 resize.max = limit;
557 return true;
558 }
559 prev_limit = limit;
560 }
561 }
562 }
563 return false;
564 }
565
566 sigc::signal<void>& DimRegionChooser::signal_dimregion_selected()
567 {
568 return dimregion_selected;
569 }
570
571 sigc::signal<void>& DimRegionChooser::signal_region_changed()
572 {
573 return region_changed;
574 }
575
576 bool DimRegionChooser::on_focus(Gtk::DirectionType direction)
577 {
578 // TODO: kolla att region finns osv, dvs att det g�r att s�tta
579 // fokus.
580 if (direction == Gtk::DIR_TAB_FORWARD ||
581 direction == Gtk::DIR_DOWN) {
582 if (!has_focus()) {
583 focus_line = 0;
584 grab_focus();
585 return true;
586 } else {
587 if (focus_line + 1 < region->Dimensions) {
588 focus_line++;
589 queue_draw();
590 return true;
591 } else {
592 return false;
593 }
594 }
595 } else if (direction == Gtk::DIR_TAB_BACKWARD ||
596 direction == Gtk::DIR_UP) {
597 if (!has_focus()) {
598 focus_line = region->Dimensions - 1;
599 grab_focus();
600 return true;
601 } else {
602 if (focus_line > 0) {
603 focus_line--;
604 queue_draw();
605 return true;
606 } else {
607 return false;
608 }
609 }
610 } else if (!has_focus()) {
611 // TODO: kolla att focus_line finns!
612 grab_focus();
613 return true;
614 } else {
615 // TODO: �ka eller minska v�rde!
616 }
617 }

  ViewVC Help
Powered by ViewVC