glow_growwindow.cpp 33.9 KB
Newer Older
claes's avatar
claes committed
1
/* 
Claes Sjofors's avatar
Claes Sjofors committed
2
 * Proview   Open Source Process Control.
Claes Sjofors's avatar
Claes Sjofors committed
3
 * Copyright (C) 2005-2016 SSAB EMEA AB.
Claes Sjofors's avatar
Claes Sjofors committed
4 5
 *
 * This file is part of Proview.
claes's avatar
claes committed
6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation, either version 2 of 
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
Claes Sjofors's avatar
Claes Sjofors committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 * along with Proview. If not, see <http://www.gnu.org/licenses/>
 *
 * Linking Proview statically or dynamically with other modules is
 * making a combined work based on Proview. Thus, the terms and 
 * conditions of the GNU General Public License cover the whole 
 * combination.
 *
 * In addition, as a special exception, the copyright holders of
 * Proview give you permission to, from the build function in the
 * Proview Configurator, combine Proview with modules generated by the
 * Proview PLC Editor to a PLC program, regardless of the license
 * terms of these modules. You may copy and distribute the resulting
 * combined work under the terms of your choice, provided that every 
 * copy of the combined work is accompanied by a complete copy of 
 * the source code of Proview (the version used to produce the 
 * combined work), being distributed under the terms of the GNU 
 * General Public License plus this exception.
claes's avatar
claes committed
35 36
 **/

37 38 39
#include "glow_std.h"


claes's avatar
claes committed
40
#include <iostream>
41 42 43 44 45 46 47 48 49 50
#include <float.h>
#include <math.h>
#include <stdlib.h>

#include "co_dcli.h"
#include "glow_growwindow.h"
#include "glow_grownode.h"
#include "glow_draw.h"
#include "glow_growctx.h"
#include "glow_growscrollbar.h"
claes's avatar
claes committed
51
#include "glow_msg.h"
52

claes's avatar
claes committed
53
GrowWindow::GrowWindow( GrowCtx *glow_ctx, const char *name, double x, double y, 
54 55 56 57 58 59 60 61
		double w, double h, glow_eDrawType border_d_type, int line_w, 
		glow_mDisplayLevel display_lev, int nodraw) : 
		GrowRect(glow_ctx,name,x,y,w,h,border_d_type,line_w,0,
		display_lev,0,1,0,glow_eDrawType_Line,nodraw), user_data(0),
		window_ctx(0), vertical_scrollbar(0), horizontal_scrollbar(0),
		scrollbar_width(0.5), v_scrollbar(0), h_scrollbar(0),
		v_value(0), h_value(0), wctx_x0(0), wctx_x1(0), wctx_y0(0), wctx_y1(0),
		scrollbar_color(glow_eDrawType_LightGray), scrollbar_bg_color(glow_eDrawType_MediumGray),
claes's avatar
claes committed
62
		window_scale(1), y_low_offs(0), input_focus(0)
63 64 65
{
  strcpy( file_name, "");
  strcpy( input_file_name, "");
66
  strcpy( owner, "");
67 68

  if ( !nodraw)
claes's avatar
claes committed
69
    draw( &ctx->mw, (GlowTransform *)NULL, highlight, hot, NULL, NULL);
70 71 72 73 74
}

GrowWindow::~GrowWindow()
{
  if ( !ctx->nodraw) {
claes's avatar
claes committed
75 76
    erase( &ctx->mw);
    erase( &ctx->navw);
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  }
  if ( window_ctx) {
    if ( window_ctx->trace_started)
      window_ctx->trace_close();
    delete window_ctx;
  }
  if ( v_scrollbar)
    delete v_scrollbar;
  if ( h_scrollbar)
    delete h_scrollbar;
}

void GrowWindow::save( ofstream& fp, glow_eSaveMode mode) 
{ 

  fp << int(glow_eSave_GrowWindow) << endl;
  fp << int(glow_eSave_GrowWindow_file_name) << FSPACE << file_name << endl;
  fp << int(glow_eSave_GrowWindow_scrollbar_width) << FSPACE << scrollbar_width << endl;
  fp << int(glow_eSave_GrowWindow_scrollbar_color) << FSPACE << scrollbar_color << endl;
  fp << int(glow_eSave_GrowWindow_scrollbar_bg_color) << FSPACE << scrollbar_bg_color << endl;
  fp << int(glow_eSave_GrowWindow_vertical_scrollbar) << FSPACE << vertical_scrollbar << endl;
  fp << int(glow_eSave_GrowWindow_horizontal_scrollbar) << FSPACE << horizontal_scrollbar << endl;
  fp << int(glow_eSave_GrowWindow_window_scale) << FSPACE << window_scale << endl;
100
  fp << int(glow_eSave_GrowWindow_owner) << FSPACE << owner << endl;
101 102 103 104
  fp << int(glow_eSave_GrowWindow_rect_part) << endl;
  GrowRect::save( fp, mode);
  if ( user_data && ctx->userdata_save_callback) {
    fp << int(glow_eSave_GrowWindow_userdata_cb) << endl;
105
    (ctx->userdata_save_callback)(&fp, this, glow_eUserdataCbType_Node);
106 107 108 109 110 111 112 113 114 115 116 117 118
  }
  fp << int(glow_eSave_End) << endl;
}

void GrowWindow::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int		tmp;

  for (;;)
  {
119 120 121 122 123 124
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GrowWindow: \"%d %s\"\n", type, dummy);      
    }

125 126 127 128 129 130 131 132 133 134 135
    fp >> type;
    switch( type) {
      case glow_eSave_GrowWindow: break;
      case glow_eSave_GrowWindow_file_name: fp >> file_name; break;
      case glow_eSave_GrowWindow_scrollbar_width: fp >> scrollbar_width; break;
      case glow_eSave_GrowWindow_scrollbar_color: fp >> tmp; scrollbar_color = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowWindow_scrollbar_bg_color: fp >> tmp;
	scrollbar_bg_color = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowWindow_vertical_scrollbar: fp >> vertical_scrollbar; break;
      case glow_eSave_GrowWindow_horizontal_scrollbar: fp >> horizontal_scrollbar; break;
      case glow_eSave_GrowWindow_window_scale: fp >> window_scale; break;
claes's avatar
claes committed
136
      case glow_eSave_GrowWindow_owner:
137
        fp.get();
138
        fp.getline( owner, sizeof(owner)); break;
139 140 141 142 143
      case glow_eSave_GrowWindow_rect_part: 
        GrowRect::open( fp);
        break;
      case glow_eSave_GrowWindow_userdata_cb:
	if ( ctx->userdata_open_callback)
144
	  (ctx->userdata_open_callback)(&fp, this, glow_eUserdataCbType_Node);
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
	break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowWindow:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }

  if ( strcmp( file_name, "") != 0)
    new_ctx();
  configure_scrollbars();
}

claes's avatar
claes committed
160
void GrowWindow::draw( GlowWind *w, int ll_x, int ll_y, int ur_x, int ur_y) 
161 162 163
{ 
  int tmp;

claes's avatar
claes committed
164
  if ( ll_x > ur_x) {
165 166 167 168 169
    /* Shift */
    tmp = ll_x;
    ll_x = ur_x;
    ur_x = tmp;
  }
claes's avatar
claes committed
170
  if ( ll_y > ur_y) {
171 172 173 174 175 176
    /* Shift */
    tmp = ll_y;
    ll_y = ur_y;
    ur_y = tmp;
  }

claes's avatar
claes committed
177 178 179 180 181
  if ( x_right * w->zoom_factor_x - w->offset_x >= ll_x &&
      	x_left * w->zoom_factor_x - w->offset_x <= ur_x &&
       	y_high * w->zoom_factor_y - w->offset_y >= ll_y &&
       	y_low * w->zoom_factor_y- w->offset_y <= ur_y) {
    draw( w, (GlowTransform *)NULL, highlight, hot, NULL, NULL);
182 183 184
  }
}

claes's avatar
claes committed
185
void GrowWindow::draw( GlowWind *w, int *ll_x, int *ll_y, int *ur_x, int *ur_y) 
186 187
{ 
  int 	tmp;
claes's avatar
claes committed
188 189 190 191
  int 	obj_ur_x = int( x_right * w->zoom_factor_x) - w->offset_x;
  int	obj_ll_x = int( x_left * w->zoom_factor_x) - w->offset_x;
  int	obj_ur_y = int( y_high * w->zoom_factor_y) - w->offset_y;
  int   obj_ll_y = int( y_low * w->zoom_factor_y) - w->offset_y;
192 193


claes's avatar
claes committed
194
  if ( *ll_x > *ur_x) {
195 196 197 198 199
    /* Shift */
    tmp = *ll_x;
    *ll_x = *ur_x;
    *ur_x = tmp;
  }
claes's avatar
claes committed
200
  if ( *ll_y > *ur_y) {
201 202 203 204 205 206 207 208 209 210
    /* Shift */
    tmp = *ll_y;
    *ll_y = *ur_y;
    *ur_y = tmp;
  }

  if (  obj_ur_x >= *ll_x &&
      	obj_ll_x <= *ur_x &&
       	obj_ur_y >= *ll_y &&
       	obj_ll_y <= *ur_y) {
claes's avatar
claes committed
211
    draw( w, (GlowTransform *)NULL, highlight, hot, NULL, NULL);
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

    // Increase the redraw area
    if ( obj_ur_x > *ur_x)
      *ur_x = obj_ur_x;
    if ( obj_ur_y > *ur_y)
      *ur_y = obj_ur_y;
    if ( obj_ll_x < *ll_x)
      *ll_x = obj_ll_x;
    if ( obj_ll_y < *ll_y)
      *ll_y = obj_ll_y;
  }
}

void GrowWindow::set_highlight( int on)
{
  highlight = on;
  draw();
}

claes's avatar
claes committed
231
void GrowWindow::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, void *node, void *colornode)
232
{
claes's avatar
claes committed
233 234 235 236 237
  if ( w == &ctx->navw) {
    draw_brief( w, t, highlight, hot, node, colornode);
    return;
  }

238 239 240 241 242
  if ( !(display_level & ctx->display_level))
    return;
  int idx;
  glow_eDrawType drawtype;

claes's avatar
claes committed
243
  idx = int( w->zoom_factor_y / w->base_zoom_factor * line_width - 1);
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
  idx += hot;
  idx = max( 0, idx);
  idx = min( idx, DRAW_TYPE_SIZE-1);
  int ll_x, ll_y, ur_x, ur_y;
  double dx1, dy1, dx2, dy2;

  if (!t) {
    dx1 = trf.x( ll.x, ll.y);
    dy1 = trf.y( ll.x, ll.y);
    dx2 = trf.x( ur.x, ur.y);
    dy2 = trf.y( ur.x, ur.y);
  }
  else {
    dx1 = trf.x( t, ll.x, ll.y);
    dy1 = trf.y( t, ll.x, ll.y);
    dx2 = trf.x( t, ur.x, ur.y);
    dy2 = trf.y( t, ur.x, ur.y);
  }
  dx1 = min( dx1, dx2);
  dx2 = max( dx1, dx2);
  dy1 = min( dy1, dy2);
  dy2 = max( dy1, dy2);

  if ( v_scrollbar) {
    if ( !h_scrollbar)
      v_scrollbar->set_position( dx2 - scrollbar_width, dy1 + y_low_offs, scrollbar_width, 
				 dy2 - (dy1 + y_low_offs));
    else
      v_scrollbar->set_position( dx2 - scrollbar_width, dy1 + y_low_offs, scrollbar_width, 
				 dy2 - (dy1 + y_low_offs) - scrollbar_width);
claes's avatar
claes committed
274
    v_scrollbar->draw( w, 0, 0, 0, 0, 0);
275 276 277 278 279 280 281

  }
  if ( h_scrollbar) {
    if ( !v_scrollbar)
      h_scrollbar->set_position( dx1, dy2 - scrollbar_width, dx2 - dx1, scrollbar_width);
    else
      h_scrollbar->set_position( dx1, dy2 - scrollbar_width, dx2 - dx1 - scrollbar_width, scrollbar_width);
claes's avatar
claes committed
282
    h_scrollbar->draw( w, 0, 0, 0, 0, 0);
283
  }
claes's avatar
claes committed
284 285
  ll_x = int( dx1 * w->zoom_factor_x) - w->offset_x;
  ll_y = int( (dy1 + y_low_offs) * w->zoom_factor_y) - w->offset_y;
286 287

  if ( window_ctx) {
claes's avatar
claes committed
288 289 290 291 292 293 294 295 296 297 298 299
    ur_x = int( (dx2 - vertical_scrollbar * scrollbar_width) * w->zoom_factor_x) - w->offset_x;
    ur_y = int( (dy2 - horizontal_scrollbar * scrollbar_width) * w->zoom_factor_y) - w->offset_y;

    window_ctx->mw.window_width = int((x_right - x_left) * w->zoom_factor_x);
    window_ctx->mw.window_height = int((y_high - y_low) * w->zoom_factor_y);
    window_ctx->mw.subwindow_x = int(x_left * w->zoom_factor_x - w->offset_x);
    window_ctx->mw.subwindow_y = int(y_low * w->zoom_factor_y - w->offset_y);
    window_ctx->mw.offset_x = - ll_x + int( h_value * w->zoom_factor_x);
    window_ctx->mw.offset_y = - ll_y + int( v_value * w->zoom_factor_y);
    window_ctx->mw.zoom_factor_x = window_ctx->mw.subwindow_scale * w->zoom_factor_x;
    window_ctx->mw.zoom_factor_y = window_ctx->mw.subwindow_scale * w->zoom_factor_y;
    // window_ctx->draw_buffer_only = ctx->draw_buffer_only;
300

301
    ctx->gdraw->push_customcolors( window_ctx->customcolors);
302
    if ( fill)
claes's avatar
claes committed
303
      ctx->gdraw->fill_rect( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, fill_drawtype);
304

claes's avatar
claes committed
305
    window_ctx->draw( &window_ctx->mw, ll_x, ll_y, ur_x, ur_y);
Claes Sjofors's avatar
Claes Sjofors committed
306
    ctx->gdraw->pop_customcolors();
307 308
  }

claes's avatar
claes committed
309 310
  ur_x = int( dx2 * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
  ur_y = int( dy2 * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
311

claes's avatar
claes committed
312
  drawtype = ctx->get_drawtype( draw_type, glow_eDrawType_LineHighlight,
313
		 highlight, (GrowNode *)colornode, 0);
claes's avatar
claes committed
314
  ctx->gdraw->rect( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, drawtype, idx, 0);
315 316
}

claes's avatar
claes committed
317
void GrowWindow::erase( GlowWind *w, GlowTransform *t, int hot, void *node)
318 319 320 321
{
  if ( !(display_level & ctx->display_level))
    return;
  int idx;
claes's avatar
claes committed
322
  idx = int( w->zoom_factor_y / w->base_zoom_factor * line_width - 1);
323 324 325 326 327 328
  idx += hot;

  idx = max( 0, idx);
  idx = min( idx, DRAW_TYPE_SIZE-1);
  int x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y;

claes's avatar
claes committed
329 330 331 332 333
  if (!t) {
    x1 = int( trf.x( ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
    y1 = int( trf.y( ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
    x2 = int( trf.x( ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
    y2 = int( trf.y( ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
334
  }
claes's avatar
claes committed
335 336 337 338 339
  else {
    x1 = int( trf.x( t, ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
    y1 = int( trf.y( t, ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
    x2 = int( trf.x( t, ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
    y2 = int( trf.y( t, ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
340 341 342 343 344 345
  }
  ll_x = min( x1, x2);
  ur_x = max( x1, x2);
  ll_y = min( y1, y2);
  ur_y = max( y1, y2);

claes's avatar
claes committed
346 347 348 349
  w->set_draw_buffer_only();
  ctx->gdraw->rect_erase( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, idx);
  ctx->gdraw->fill_rect( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, glow_eDrawType_LineErase);
  w->reset_draw_buffer_only();
350 351
}

claes's avatar
claes committed
352
void GrowWindow::draw_brief( GlowWind *w, GlowTransform *t, int highlight, int hot, void *node, void *colornode)
353 354 355 356 357
{
  if ( !(display_level & ctx->display_level))
    return;
  glow_eDrawType drawtype;
  int idx;
claes's avatar
claes committed
358
  idx = int( w->zoom_factor_y / w->base_zoom_factor * line_width - 1);
359 360 361 362 363

  idx = max( 0, idx);
  idx = min( idx, DRAW_TYPE_SIZE-1);
  int x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y;

claes's avatar
claes committed
364 365 366 367 368
  if (!t) {
    x1 = int( trf.x( ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
    y1 = int( trf.y( ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
    x2 = int( trf.x( ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
    y2 = int( trf.y( ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
369
  }
claes's avatar
claes committed
370 371 372 373 374
  else {
    x1 = int( trf.x( t, ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
    y1 = int( trf.y( t, ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
    x2 = int( trf.x( t, ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
    y2 = int( trf.y( t, ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
375 376 377 378 379 380 381
  }
  ll_x = min( x1, x2);
  ur_x = max( x1, x2);
  ll_y = min( y1, y2);
  ur_y = max( y1, y2);

  if ( window_ctx && fill)
claes's avatar
claes committed
382
    ctx->gdraw->fill_rect( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, fill_drawtype);
383

claes's avatar
claes committed
384
  drawtype = ctx->get_drawtype( draw_type, glow_eDrawType_LineHighlight,
385
		 highlight, (GrowNode *)colornode, 0);
claes's avatar
claes committed
386
  ctx->gdraw->rect( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
387 388 389 390 391 392 393 394 395
	drawtype, idx, 0);
}

void GrowWindow::trace_scan()
{
  if ( trace.p && ctx->trace_scan_func)
    ctx->trace_scan_func( (void *) this, trace.p);

  if ( window_ctx) {
claes's avatar
claes committed
396 397 398 399
    int ur_x = int( (x_right - vertical_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ll_x = int( x_left * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ur_y = int( (y_high - horizontal_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
    int ll_y = int( (y_low + y_low_offs) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
400

claes's avatar
claes committed
401 402
    // window_ctx->draw_buffer_only = ctx->draw_buffer_only;
    ctx->gdraw->set_clip_rectangle( &ctx->mw, ll_x, ll_y, ur_x, ur_y);
403

404 405 406
    if ( ctx->trace_ctrl_func)
      (ctx->trace_ctrl_func) ( glow_eTraceCtrl_CtxPop, window_ctx);

407 408
    window_ctx->trace_scan();

409 410 411
    if ( ctx->trace_ctrl_func)
      (ctx->trace_ctrl_func) ( glow_eTraceCtrl_CtxPush, window_ctx);

claes's avatar
claes committed
412
    ctx->gdraw->reset_clip_rectangle( &ctx->mw);
413 414 415 416 417 418 419 420 421 422
  }
}

int GrowWindow::trace_init()
{
  int sts = 1;

  // sts = ctx->trace_connect_func( (void *) this, &trace);

  if ( window_ctx) {
claes's avatar
claes committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
    double dx1, dy1, dx2, dy2;

    ctx->set_nodraw();
    configure_scrollbars();
    ctx->reset_nodraw();

    dx1 = trf.x( ll.x, ll.y);
    dy1 = trf.y( ll.x, ll.y);
    dx2 = trf.x( ur.x, ur.y);
    dy2 = trf.y( ur.x, ur.y);
    dx1 = min( dx1, dx2);
    dx2 = max( dx1, dx2);
    dy1 = min( dy1, dy2);
    dy2 = max( dy1, dy2);

claes's avatar
claes committed
438 439
    int ll_x = int( dx1 * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int ll_y = int( (dy1 + y_low_offs) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
claes's avatar
claes committed
440

claes's avatar
claes committed
441 442
    window_ctx->mw.offset_x = - ll_x + int( h_value * ctx->mw.zoom_factor_x);
    window_ctx->mw.offset_y = - ll_y + int( v_value * ctx->mw.zoom_factor_y);
claes's avatar
claes committed
443

claes's avatar
claes committed
444 445
    memcpy( window_ctx->event_callback, ctx->event_callback, sizeof( ctx->event_callback));
    window_ctx->event_move_node = ctx->event_move_node;
446 447
    window_ctx->trace_init( ctx->trace_connect_func, 
			    ctx->trace_disconnect_func, 
448 449
			    ctx->trace_scan_func,
			    ctx->trace_ctrl_func);
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
  }
    
  return sts;
}

void GrowWindow::trace_close()
{
  if ( trace.p)
    ctx->trace_disconnect_func( (void *) this);

  if ( window_ctx)
    window_ctx->trace_close();
}

void GrowWindow::draw()
{
claes's avatar
claes committed
466 467 468 469 470 471 472 473
  ctx->draw( &ctx->mw, x_left * ctx->mw.zoom_factor_x - ctx->mw.offset_x - DRAW_MP,
	     y_low * ctx->mw.zoom_factor_y - ctx->mw.offset_y - DRAW_MP,
  	     x_right * ctx->mw.zoom_factor_x - ctx->mw.offset_x + DRAW_MP,
	     y_high * ctx->mw.zoom_factor_y - ctx->mw.offset_y + DRAW_MP);
  ctx->draw( &ctx->navw,  x_left * ctx->navw.zoom_factor_x - ctx->mw.offset_x - 1,
	     y_low * ctx->navw.zoom_factor_y - ctx->mw.offset_y - 1,
  	     x_right * ctx->navw.zoom_factor_x - ctx->mw.offset_x + 1,
	     y_high * ctx->navw.zoom_factor_y - ctx->mw.offset_y + 1);
474 475 476 477 478 479
}

void GrowWindow::align( double x, double y, glow_eAlignDirection direction)
{
    double dx, dy;

claes's avatar
claes committed
480 481 482 483
    erase( &ctx->mw);
    erase( &ctx->navw);
    ctx->set_defered_redraw();
    draw();
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
    switch ( direction)
    {
      case glow_eAlignDirection_CenterVert:
        dx = x - (x_right + x_left) / 2;
        dy = 0;
        break;        
      case glow_eAlignDirection_CenterHoriz:
        dx = 0;
        dy = y - (y_high + y_low) / 2;
        break;        
      case glow_eAlignDirection_CenterCenter:
        dx = x - (x_right + x_left) / 2;
        dy = y - (y_high + y_low) / 2;
        break;        
      case glow_eAlignDirection_Right:
        dx = x - x_right;
        dy = 0;
        break;        
      case glow_eAlignDirection_Left:
        dx = x - x_left;
        dy = 0;
        break;        
      case glow_eAlignDirection_Up:
        dx = 0;
        dy = y - y_high;
        break;        
      case glow_eAlignDirection_Down:
        dx = 0;
        dy = y - y_low;
        break;        
    }
    trf.move( dx, dy);
    x_right += dx;
    x_left += dx;
    y_high += dy;
    y_low += dy;

    draw();
claes's avatar
claes committed
522
    ctx->redraw_defered();
523 524 525 526 527 528 529 530 531
}

void GrowWindow::export_javabean( GlowTransform *t, void *node,
	glow_eExportPass pass, int *shape_cnt, int node_cnt, int in_nc, ofstream &fp)
{
  double x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y;

  if (!t)
  {
claes's avatar
claes committed
532 533 534 535
    x1 = trf.x( ll.x, ll.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x;
    y1 = trf.y( ll.x, ll.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y;
    x2 = trf.x( ur.x, ur.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x;
    y2 = trf.y( ur.x, ur.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y;
536 537 538
  }
  else
  {
claes's avatar
claes committed
539 540 541 542
    x1 = trf.x( t, ll.x, ll.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x;
    y1 = trf.y( t, ll.x, ll.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y;
    x2 = trf.x( t, ur.x, ur.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x;
    y2 = trf.y( t, ur.x, ur.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y;
543 544 545 546 547 548 549
  }

  ll_x = min( x1, x2);
  ur_x = max( x1, x2);
  ll_y = min( y1, y2);
  ur_y = max( y1, y2);

claes's avatar
claes committed
550
  ctx->export_jbean->window( ll_x, ll_y, ur_x, ur_y,
claes's avatar
claes committed
551
				       file_name, vertical_scrollbar, horizontal_scrollbar,
552
				       owner,
claes's avatar
claes committed
553
				       pass, shape_cnt, node_cnt, fp);
554 555 556 557 558 559 560 561 562 563 564
}

void GrowWindow::convert( glow_eConvert version) 
{
  switch ( version) {
  case glow_eConvert_V34: {
    // Conversion of colors
  }
  }  
}

claes's avatar
claes committed
565
int GrowWindow::event_handler( GlowWind *w, glow_eEvent event, int x, int y, double fx,
566 567 568 569
	double fy)
{
  int sts, v_sts, h_sts;

claes's avatar
claes committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
  switch ( event) {
  case glow_eEvent_Key_Right:
  case glow_eEvent_Key_Left:
  case glow_eEvent_Key_Up:
  case glow_eEvent_Key_Down:
  case glow_eEvent_Key_BackSpace:
  case glow_eEvent_Key_Return:
  case glow_eEvent_Key_Tab:
  case glow_eEvent_Key_ShiftTab:
  case glow_eEvent_Key_Escape:
  case glow_eEvent_Key_Ascii:
    if ( input_focus) {
      window_ctx->event_handler( event, 0, 0, x, 0);
      if ( !window_ctx->inputfocus_object) {
	ctx->register_inputfocus( this, 0);
	input_focus = 0;
      }
      return 1;
    }
    else
      return 0;
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
  case glow_eEvent_ScrollUp:
    if ( !ctx->trace_started)
      return 0;
    if ( v_scrollbar) {
      double rx, ry;

      // Convert koordinates to local koordinates
      trf.reverse( fx, fy, &rx, &ry);
      sts = local_event_handler( event, rx, ry);
      if ( sts) {
	v_value -= (wctx_y1 - wctx_y0) * window_scale/50;
	if ( v_value < wctx_y0 * window_scale)
	  v_value = wctx_y0 * window_scale;
	draw();
	v_scrollbar->set_value( v_value, y_high - 
				(y_low + y_low_offs) - scrollbar_width * horizontal_scrollbar);
	return 1;
      }
609 610
      else
	return 0;
611
    }
612
    break;
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
  case glow_eEvent_ScrollDown:
    if ( !ctx->trace_started)
      return 0;
    if ( v_scrollbar) {
      double rx, ry;

      // Convert koordinates to local koordinates
      trf.reverse( fx, fy, &rx, &ry);
      sts = local_event_handler( event, rx, ry);
      if ( sts) {
	v_value += (wctx_y1 - wctx_y0) * window_scale/50;
	if ( v_value > wctx_y1 * window_scale - ((y_high - (y_low + y_low_offs) - scrollbar_width * horizontal_scrollbar)))
	  v_value = wctx_y1 * window_scale - ((y_high - (y_low + y_low_offs) - scrollbar_width * horizontal_scrollbar));
	draw();
	v_scrollbar->set_value( v_value, y_high - 
				(y_low + y_low_offs) - scrollbar_width * horizontal_scrollbar);
	return 1;
      }
631 632
      else
	return 0;
633
    }
634
    break;
claes's avatar
claes committed
635 636 637 638
  default:
    ;
  }

639 640
  v_sts = h_sts = 0;
  if ( v_scrollbar)
claes's avatar
claes committed
641
    v_sts = v_scrollbar->event_handler( w, event, x, y, fx, fy);
642
  if (h_scrollbar)
claes's avatar
claes committed
643
    h_sts = h_scrollbar->event_handler( w, event, x, y, fx, fy);
644 645 646 647 648 649
  if ( v_sts || h_sts) {
    if ( event == ctx->event_move_node)
      return 0;
    return 1;
  }

claes's avatar
claes committed
650
  sts = GrowRect::event_handler( w, event, x, y, fx, fy);
651 652 653 654 655
  if ( ctx->trace_started && ctx->callback_object == this) {
    // Disable event callback for this object, let the window ctx handle it
    ctx->callback_object = 0;
    ctx->callback_object_type = glow_eObjectType_NoObject;
  }
claes's avatar
claes committed
656 657 658 659
  if ( !ctx->trace_started) {
    if ( event == glow_eEvent_ButtonMotion)
      return 0;
  }
660 661 662 663 664 665 666 667 668 669 670 671 672

  if ( ctx->hot_mode == glow_eHotMode_TraceAction) {
    double rx, ry;

    // Convert koordinates to local koordinates
    trf.reverse( fx, fy, &rx, &ry);
    sts = local_event_handler( event, rx, ry);
  }

  if ( window_ctx && sts) {
    if ( !ctx->trace_started)
      return sts;

claes's avatar
claes committed
673 674 675 676
    int ur_x = int( (x_right - vertical_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ll_x = int( x_left * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ur_y = int( (y_high - horizontal_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
    int ll_y = int( (y_low + y_low_offs) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
677

claes's avatar
claes committed
678
    // window_ctx->draw_buffer_only = ctx->draw_buffer_only;
Claes Sjofors's avatar
Claes Sjofors committed
679
    ctx->gdraw->push_customcolors( window_ctx->customcolors);
claes's avatar
claes committed
680
    ctx->gdraw->set_clip_rectangle( &ctx->mw, ll_x, ll_y, ur_x, ur_y);
681 682 683 684 685

    // Set callback to redraw the background
    window_ctx->redraw_callback = redraw_cb;
    window_ctx->redraw_data = (void *)this;

claes's avatar
claes committed
686 687 688
    sts = window_ctx->event_handler( event, x, y, 0, 0);
    if ( sts == GLOW__TERMINATED)
      return sts;
689 690 691

    window_ctx->redraw_callback = 0;
    window_ctx->redraw_data = 0;
claes's avatar
claes committed
692
    ctx->gdraw->reset_clip_rectangle( &ctx->mw);
Claes Sjofors's avatar
Claes Sjofors committed
693
    ctx->gdraw->pop_customcolors();
694

claes's avatar
claes committed
695 696 697 698 699 700 701 702 703
    if ( window_ctx->inputfocus_object && !input_focus) {
      ctx->register_inputfocus( this, 1);
      input_focus = 1;
    }
    else if ( !window_ctx->inputfocus_object && input_focus) {
      ctx->register_inputfocus( this, 0);
      input_focus = 0;
    }

704 705 706 707 708 709
    // if ( window_ctx->callback_object)
    //  ctx->register_callback_object( window_ctx->callback_object_type, window_ctx->callback_object);
  }
  return sts;
}

710
void GrowWindow::set_input_focus( int focus, glow_eEvent event)
claes's avatar
claes committed
711 712 713 714
{
  if ( focus && !input_focus) {
    input_focus = 1;
    ctx->register_inputfocus( this, 1);
715 716 717

    if ( event == glow_eEvent_InputFocusInit)
      window_ctx->inputfocus_init_event();
claes's avatar
claes committed
718 719 720
  }
  else if ( !focus && input_focus) {
    if ( window_ctx->inputfocus_object)
721
      window_ctx->inputfocus_object->set_input_focus(0, event);
claes's avatar
claes committed
722 723 724 725 726
    input_focus = 0;
    ctx->register_inputfocus( this, 0);
  }
}

727 728
void GrowWindow::update_attributes()
{
729
  if ( strcmp( input_file_name, file_name) != 0 ||
730
       (window_ctx && strcmp( window_ctx->owner, owner) != 0)) {
731 732
    // New graph, create new context
#if 0
claes's avatar
claes committed
733 734 735 736
    int ur_x = int( (x_right - vertical_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ll_x = int( x_left * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ur_y = int( (y_high - horizontal_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
    int ll_y = int( (y_low + y_low_offs) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
737

738 739
    if ( window_ctx)
      window_ctx->draw_buffer_only = ctx->draw_buffer_only;
740 741
    glow_draw_set_clip_rectangle( ctx, ll_x, ll_y, ur_x, ur_y);
#endif
claes's avatar
claes committed
742 743 744 745 746
    int ur_x = int( x_right * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ll_x = int( x_left * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    int	ur_y = int( y_high * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
    int ll_y = int( y_low * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
    ctx->gdraw->set_clip_rectangle( &ctx->mw, ll_x, ll_y, ur_x, ur_y);
747 748 749 750 751 752 753 754 755 756 757

    if ( window_ctx) {
      if ( window_ctx->trace_started)
	window_ctx->trace_close();
      delete window_ctx;
      fill_drawtype = original_fill_drawtype = glow_eDrawType_Inherit;
      fill = 0;
    }
    strcpy( file_name, input_file_name);
    new_ctx();

claes's avatar
claes committed
758
    //#if 0
claes's avatar
claes committed
759
    ctx->gdraw->reset_clip_rectangle( &ctx->mw);
claes's avatar
claes committed
760
    //#endif
761 762
  }
  if ( window_ctx) {
claes's avatar
claes committed
763 764 765
    window_ctx->mw.subwindow_scale = window_scale;
    window_ctx->mw.zoom_factor_x = window_ctx->mw.zoom_factor_y = 
      window_ctx->mw.subwindow_scale * ctx->mw.zoom_factor_x;
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
    window_ctx->a.zoom();
  }

  configure_scrollbars();

  if ( v_scrollbar)
    v_scrollbar->set_colors( scrollbar_bg_color, scrollbar_color);
  if ( h_scrollbar)
    h_scrollbar->set_colors( scrollbar_bg_color, scrollbar_color);
}

void GrowWindow::set_transform_from_stored( GlowTransform *t)
{
  GrowRect::set_transform_from_stored( t);
  configure_scrollbars();
}

void GrowWindow::configure_scrollbars()
{
  double x0, y0, width, height;

  if ( vertical_scrollbar && ! v_scrollbar) {
    x0 = x_right - scrollbar_width;
    y0 = y_low + y_low_offs;
    width = scrollbar_width;
    if ( horizontal_scrollbar)
      height = y_high - (y_low + y_low_offs) - scrollbar_width;
    else
      height = y_high - (y_low + y_low_offs);

    v_scrollbar = new GrowScrollBar( ctx, "vScrollbar", x0, y0, width, height,
				     glow_eDir_Vertical, glow_eDrawType_Line, 1, display_level, 
				     scrollbar_bg_color, scrollbar_color, 1);
    v_scrollbar->register_value_changed_cb( (void *)this, &v_value_changed_cb);
claes's avatar
claes committed
800
    if ( window_ctx) {
claes's avatar
claes committed
801
      v_scrollbar->set_value( wctx_y0 * window_ctx->mw.subwindow_scale, y_high - 
claes's avatar
claes committed
802
			      (y_low + y_low_offs) - scrollbar_width * horizontal_scrollbar);
claes's avatar
claes committed
803 804
      v_scrollbar->set_range( wctx_y0 * window_ctx->mw.subwindow_scale, wctx_y1 * window_scale);
      v_value = wctx_y0 * window_ctx->mw.subwindow_scale;
claes's avatar
claes committed
805
    }
806 807 808 809 810
    v_scrollbar->set_shadow( shadow);
  }
  else if ( !vertical_scrollbar && v_scrollbar) {
    delete v_scrollbar;
    v_scrollbar = 0;
claes's avatar
claes committed
811
    if ( window_ctx)
claes's avatar
claes committed
812
      v_value = wctx_y0 * window_ctx->mw.subwindow_scale;
813 814 815
  }
  else if ( v_scrollbar) {
    // Reconfigure range and length
claes's avatar
claes committed
816
    if ( window_ctx) {
claes's avatar
claes committed
817
      v_scrollbar->set_value( wctx_y0 * window_ctx->mw.subwindow_scale, y_high - 
claes's avatar
claes committed
818
			      (y_low + y_low_offs) - scrollbar_width * horizontal_scrollbar);
claes's avatar
claes committed
819 820
      v_value = wctx_y0 * window_ctx->mw.subwindow_scale;
      v_scrollbar->set_range( wctx_y0 * window_ctx->mw.subwindow_scale, wctx_y1 * window_ctx->mw.subwindow_scale);
claes's avatar
claes committed
821
    }
822 823
    v_scrollbar->set_shadow( shadow);
  }
claes's avatar
claes committed
824 825
  else {
    if ( window_ctx)
claes's avatar
claes committed
826
      v_value = wctx_y0 * window_ctx->mw.subwindow_scale;
claes's avatar
claes committed
827
  }
828 829 830 831 832 833 834 835 836 837 838 839 840 841

  if ( horizontal_scrollbar && ! h_scrollbar) {
    x0 = x_left;
    y0 = y_high - scrollbar_width;
    height = scrollbar_width;
    if ( vertical_scrollbar)
      width = x_right - x_left - scrollbar_width;
    else
      width = x_right - x_left;

    h_scrollbar = new GrowScrollBar( ctx, "vScrollbar", x0, y0, width, height,
				     glow_eDir_Horizontal, glow_eDrawType_Line, 1, display_level, 
				     scrollbar_bg_color, scrollbar_color, 1);
    h_scrollbar->register_value_changed_cb( (void *)this, &h_value_changed_cb);
claes's avatar
claes committed
842
    if ( window_ctx) {
claes's avatar
claes committed
843
      h_scrollbar->set_value( wctx_x0 * window_ctx->mw.subwindow_scale, 
claes's avatar
claes committed
844
			      x_right - x_left - scrollbar_width * vertical_scrollbar);
claes's avatar
claes committed
845 846
      h_scrollbar->set_range( wctx_x0 * window_ctx->mw.subwindow_scale, wctx_x1 * window_ctx->mw.subwindow_scale);
      h_value = wctx_x0 * window_ctx->mw.subwindow_scale;
claes's avatar
claes committed
847
    }
848 849 850 851 852
    h_scrollbar->set_shadow( shadow);
  }
  else if ( !horizontal_scrollbar && h_scrollbar) {
    delete h_scrollbar;
    h_scrollbar = 0;
claes's avatar
claes committed
853
    if ( window_ctx)
claes's avatar
claes committed
854
      h_value = wctx_x0 * window_ctx->mw.subwindow_scale;    
855 856 857
  }
  else if ( h_scrollbar) {
    // Reconfigure lenght and range
claes's avatar
claes committed
858
    if ( window_ctx) {
claes's avatar
claes committed
859
      h_scrollbar->set_value( wctx_x0 * window_ctx->mw.subwindow_scale, 
claes's avatar
claes committed
860
			      x_right - x_left - scrollbar_width * vertical_scrollbar);
claes's avatar
claes committed
861 862
      h_value = wctx_x0 * window_ctx->mw.subwindow_scale;
      h_scrollbar->set_range( wctx_x0 * window_ctx->mw.subwindow_scale, wctx_x1 * window_ctx->mw.subwindow_scale);
claes's avatar
claes committed
863
    }
864 865
    h_scrollbar->set_shadow( shadow);
  }
claes's avatar
claes committed
866 867
  else {
    if ( window_ctx)
claes's avatar
claes committed
868
      h_value = wctx_x0 * window_ctx->mw.subwindow_scale;    
claes's avatar
claes committed
869
  }
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
}

void GrowWindow::v_value_changed_cb( void *o, double value)
{
  GrowWindow *gw = (GrowWindow *) o;

  gw->v_value = value;
  gw->draw();
}

void GrowWindow::h_value_changed_cb( void *o, double value)
{
  GrowWindow *gw = (GrowWindow *) o;

  gw->h_value = value;
  gw->draw();
}

void GrowWindow::new_ctx() 
{
  char fname[200];
claes's avatar
claes committed
891
  int sts;
892
  int no_file = strcmp( file_name, "_no_") == 0 ? 1 : 0;   // No initial graph
893

claes's avatar
claes committed
894 895 896 897 898 899
  if ( strchr( file_name, '/') == 0) {
    strcpy( fname, "$pwrp_exe/");
    strcat( fname, file_name);
  }
  else 
    strcpy( fname, file_name);
900 901 902 903
  if ( !strchr( fname, '.'))
    strcat( fname, ".pwg");
  dcli_translate_filename( fname, fname);

claes's avatar
claes committed
904 905
  window_ctx = new GrowCtx( "WindowComponent", ctx->mw.zoom_factor_x * window_scale);
  window_ctx->gdraw = ctx->gdraw;
906
  window_ctx->is_subwindow = 1;
claes's avatar
claes committed
907 908
  window_ctx->mw.window = ctx->mw.window;
  window_ctx->navw.window = ctx->navw.window;
909 910 911
  window_ctx->userdata_save_callback = ctx->userdata_save_callback;
  window_ctx->userdata_open_callback = ctx->userdata_open_callback;
  window_ctx->userdata_copy_callback = ctx->userdata_copy_callback;
claes's avatar
claes committed
912
  // window_ctx->double_buffer_on = ctx->double_buffer_on;
913 914 915 916 917
  window_ctx->user_data = ctx->user_data;
  window_ctx->hot_mode = ctx->hot_mode;
  window_ctx->default_hot_mode = ctx->default_hot_mode;
  window_ctx->is_component = 1;
  memcpy( window_ctx->event_callback, ctx->event_callback, sizeof( ctx->event_callback));
claes's avatar
claes committed
918
  window_ctx->event_move_node = ctx->event_move_node;
919
  window_ctx->background_disabled = 1;
920
  if ( strcmp( owner, "$object") == 0 && ctx->is_subwindow)
921 922 923
    strcpy( window_ctx->owner, ctx->owner);
  else
    strcpy( window_ctx->owner, owner);
Claes Sjofors's avatar
Claes Sjofors committed
924
  window_ctx->customcolors = ctx->gdraw->create_customcolors();
925

926 927 928 929 930
  if ( !no_file) {
    sts = window_ctx->open( fname, glow_eSaveMode_Edit);
    if ( EVEN(sts))
      printf( "** Unable to open graph %s\n", fname);
  }
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948

  strcpy( input_file_name, file_name);
  if ( window_ctx->background_color != glow_eDrawType_Inherit) {
    fill_drawtype = original_fill_drawtype = window_ctx->background_color;
    fill = 1;
  }
  if ( window_ctx->x0 != window_ctx->x1 && window_ctx->y0 != window_ctx->y1) {
    wctx_x0 = window_ctx->x0;
    wctx_x1 = window_ctx->x1;
    wctx_y0 = window_ctx->y0;
    wctx_y1 = window_ctx->y1;
  }
  else {
    wctx_x0 = window_ctx->x_left;
    wctx_x1 = window_ctx->x_right;
    wctx_y0 = window_ctx->y_low;
    wctx_y1 = window_ctx->y_high;
  }      
claes's avatar
claes committed
949 950 951 952 953 954 955
  window_ctx->mw.window_width = int((x_right - x_left) * ctx->mw.zoom_factor_x);
  window_ctx->mw.window_height = int((y_high - y_low) * ctx->mw.zoom_factor_y);
  window_ctx->mw.subwindow_x = int(x_left * ctx->mw.zoom_factor_x - ctx->mw.offset_x);
  window_ctx->mw.subwindow_y = int(y_low * ctx->mw.zoom_factor_y - ctx->mw.offset_y);
  window_ctx->mw.subwindow_scale = ctx->mw.subwindow_scale * window_scale;
  window_ctx->mw.zoom_factor_x = window_ctx->mw.zoom_factor_y = 
    ctx->mw.zoom_factor_x * window_ctx->mw.subwindow_scale;
claes's avatar
claes committed
956
  window_ctx->move_restriction = glow_eMoveRestriction_Disable;
957 958 959
  window_ctx->a.zoom();

  if ( ctx->trace_started) {
claes's avatar
claes committed
960
    trace_init();
961 962
    trace_scan();
  }
963 964 965

  if ( input_focus)
    window_ctx->inputfocus_init_event();
966 967 968 969 970
}

void GrowWindow::redraw_cb( void *o)
{
  GrowWindow *gw = (GrowWindow *) o;
claes's avatar
claes committed
971
  int only = gw->ctx->mw.window->draw_buffer_only;
972

claes's avatar
claes committed
973
  // gw->ctx->draw_buffer_only = gw->window_ctx->draw_buffer_only;
974
  gw->draw_background();
claes's avatar
claes committed
975
  gw->ctx->mw.window->draw_buffer_only = only;
976 977 978 979 980 981 982 983 984
}

void GrowWindow::draw_background()
{
  if ( !(display_level & ctx->display_level))
    return;
  int idx;
  glow_eDrawType drawtype;

claes's avatar
claes committed
985
  idx = int( ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * line_width - 1);
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
  idx += hot;
  idx = max( 0, idx);
  idx = min( idx, DRAW_TYPE_SIZE-1);
  int ll_x, ll_y, ur_x, ur_y;
  double dx1, dy1, dx2, dy2;

  dx1 = trf.x( ll.x, ll.y);
  dy1 = trf.y( ll.x, ll.y);
  dx2 = trf.x( ur.x, ur.y);
  dy2 = trf.y( ur.x, ur.y);

  dx1 = min( dx1, dx2);
  dx2 = max( dx1, dx2);
  dy1 = min( dy1, dy2);
  dy2 = max( dy1, dy2);

  if ( v_scrollbar)
claes's avatar
claes committed
1003
    v_scrollbar->draw( &ctx->mw, 0, 0, 0, 0, 0);
1004
  if ( h_scrollbar)
claes's avatar
claes committed
1005
    h_scrollbar->draw( &ctx->mw, 0, 0, 0, 0, 0);
1006

claes's avatar
claes committed
1007 1008
  ll_x = int( dx1 * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
  ll_y = int( (dy1 + y_low_offs) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
1009 1010

  if ( window_ctx) {
claes's avatar
claes committed
1011 1012
    ur_x = int( (dx2 - vertical_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
    ur_y = int( (dy2 - horizontal_scrollbar * scrollbar_width) * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
1013 1014

    if ( fill)
claes's avatar
claes committed
1015
      ctx->gdraw->fill_rect( &ctx->mw, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, fill_drawtype);
1016 1017
  }

claes's avatar
claes committed
1018 1019
  ur_x = int( dx2 * ctx->mw.zoom_factor_x) - ctx->mw.offset_x;
  ur_y = int( dy2 * ctx->mw.zoom_factor_y) - ctx->mw.offset_y;
1020

claes's avatar
claes committed
1021
  drawtype = ctx->get_drawtype( draw_type, glow_eDrawType_LineHighlight,
1022
		 highlight, 0, 0);
claes's avatar
claes committed
1023
  ctx->gdraw->rect( &ctx->mw, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, drawtype, idx, 0);
1024 1025 1026 1027 1028 1029 1030 1031
}

void GrowWindow::zoom()
{
  GrowRect::zoom();
  if ( window_ctx)
    window_ctx->a.zoom();
}
claes's avatar
claes committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042

int GrowWindow::get_background_object_limits(GlowTransform *t,
		    glow_eTraceType type,
		    double x, double y, GlowArrayElem **background,
		    double *min, double *max, glow_eDirection *direction)
{
  if ( window_ctx)
    return window_ctx->get_background_object_limits( type, x, y,
					      background, min, max, direction);
  return 0;
}
claes's avatar
claes committed
1043

1044
int GrowWindow::set_source( char *source, char *new_owner)
claes's avatar
claes committed
1045 1046 1047
{
  int clip_removed = 0;

claes's avatar
claes committed
1048
  if ( ctx->gdraw->clip_level( &ctx->mw)) {
claes's avatar
claes committed
1049
    // Remove any clip
claes's avatar
claes committed
1050
    ctx->gdraw->reset_clip_rectangle( &ctx->mw);
claes's avatar
claes committed
1051 1052 1053 1054
    clip_removed = 1;
  }

  strcpy( input_file_name, source);
1055 1056
  if ( new_owner)
    strncpy( owner, new_owner, sizeof(owner));
claes's avatar
claes committed
1057 1058 1059 1060 1061
  update_attributes();
  draw();

  if ( clip_removed)
    // Set a clip to match the previous reset
claes's avatar
claes committed
1062 1063
    ctx->gdraw->set_clip_rectangle( &ctx->mw, 0, 0, ctx->mw.window_width, ctx->mw.window_height);    
   
claes's avatar
claes committed
1064 1065
  return 1;
}