/* fuer buttons:
is existiert noch kein modus

CLIPPED und RAW zusammen, dass heisst zur Zeit koennen
Buttons noch nicht auf hinteren Fenstern korrekt dagestellt werden!
*/

#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <mem.h>
#include <malloc.h>

#include "button.h"
#include "vesa.h"

#include "error.h"
#include "tool.h"
#include "tprint.h"

T_PCHAR mem_bild_buffer=NULL;
T_PCHAR text_ausgabe=NULL;
T_VOID _pc__(WINDOW_LISTEN_ELEMENT *window, T_INT flag ,T_INT x, T_INT y, T_INT max_pix, T_CHAR zeichen)
{_p__(window,flag,x,y,max_pix,&zeichen);}
MEM_BILD *virtual_rect_fill(T_INT len_x,T_INT len_y,T_BYTE color);
MEM_BILD *virtual_print_string_max(T_INT max_pix, T_PCHAR string);
T_INT last_printed_x=0;
T_INT last_printed_y=0;
T_INT is_upper=T_FALSE;

/***************************************************************/

T_VOID print_button(WINDOW_LISTEN_ELEMENT *window, BUTTON *button,T_INT flag, T_INT x, T_INT y, T_INT art,T_PINT status)
{
 T_INT old_print_modus=vesa_print_modus;
 T_INT old_text=vesa_text;
 T_INT old_back_color=vesa_back_color;
 T_INT old_text_color=vesa_text_color;
 T_DEBUG_ENTRY("print_button",55)
// if (button_raw)
 flag=PRINT_WIN_RAW;//_CLIPPED;
 if (window!=NULL)
 {
  if ((window_first->objekt)==window)
  is_upper=T_TRUE;
  flag=PRINT_WIN_RAW;
 }
 MOUSE_VERSTECKE
 if (button!=NULL)
 {
  if (*status != art)
  {
   vesa_print_modus=PIC_ON_BACK;
   vesa_text=SINGLE_COLOR;
   vesa_back_color=button->back_col;
   vesa_text_color=button->text_col;
   if (*status==INITIALISING)
   {
    switch (button->art)
    {
     case TEXT:
     case EDIT_TEXT:
     {
      print_rectfill_with_all_features(window,flag,x+button->line_width,y+button->line_width,
      button->breite-button->line_width,button->hoehe-button->line_width-1,button->back_col);
      print_with_all_features(window,flag,x+button->thickness_x+button->line_width,y+button->thickness_y+button->line_width,PMAX,button->name);
      break;
     }
     case CHECK:
     {
      print_rectfill_with_all_features(window,flag,x+button->line_width,y+button->line_width,button->breite-button->line_width,button->hoehe-button->line_width-1,button->back_col);
      print_srect(window,flag,x,y,button->breite,button->hoehe,button->light2_col,button->shade1_col, button->line_width/2);
      print_srect(window,flag,x+button->line_width/2, y+button->line_width/2, button->breite-button->line_width, button->hoehe-button->line_width, button->light1_col,button->shade2_col, button->line_width/2);
      print_rectfill_with_all_features(
      window,
      flag,
      x+button->line_width+2,
      y+button->line_width+2,
      button->breite-(2*button->line_width+4),
      button->hoehe-(2*button->line_width+4),
      button->text_col);
      if (*(button->value)==T_TRUE)
      {
       print_rectfill_with_all_features(
       window,
       flag,
       x+button->line_width+4,
       y+button->line_width+4,
       button->breite-2*button->line_width-2*4,
       button->hoehe-2*button->line_width-2*4,
       button->back_col);
      }
      else
      {
       print_rectfill_with_all_features(
       window,
       flag,
       x+button->line_width+4,
       y+button->line_width+4,
       button->breite-2*button->line_width-2*4,
       button->hoehe-2*button->line_width-2*4,
       button->text_col);
      }
      break;
     }
     case BIT_MAP:
     case MEMBILD:
     {
      vesa_back_color=button->hintergrund;
      print_membild_with_all_features(button->bitmap,window,flag,x+button->line_width,
      y+button->line_width,0,0, PMAX,PMAX);
      break;
     }
    }
   }
   switch (art)
   {
    case RELEASED:
    {
     print_srect(window,flag,x,y,button->breite,button->hoehe,button->light2_col,
     button->shade1_col, button->line_width/2);
     print_srect(window,flag,x+button->line_width/2, y+button->line_width/2,
     button->breite-button->line_width, button->hoehe-button->line_width,
     button->light1_col,button->shade2_col, button->line_width/2);
     *status=RELEASED;
     break;
    }
    case PRESSED:
    {
     print_srect(window,flag,x, y, button->breite, button->hoehe,button->shade2_col,button->light1_col,
     button->line_width/2);
     print_srect(window,flag,x+button->line_width/2, y+button->line_width/2, button->breite-button->line_width,
     button->hoehe-button->line_width,button->shade1_col,button->light2_col, button->line_width/2);
     *status=PRESSED;
     break;
    }
    case FORBIDDEN:
    {
     break;
    }
   }
  }
 }
 is_upper=T_FALSE;
 MOUSE_ZEIGE
 vesa_print_modus=old_print_modus;
 vesa_text=old_text;
 vesa_back_color=old_back_color;
 vesa_text_color=old_text_color;
 T_DEBUG_LEAVE
}

/***************************************************************/

T_INT back_show(T_VOID)
{
 T_DEBUG_ENTRY("back_show",55)
 if (back_pic!= NULL)
 {
  print_mem_bild(back_pic,0,0);
  T_DEBUG_FUNCTION_POSITION(1)
  T_DEBUG_LEAVE
  return T_OK;
 }
 T_DEBUG_SET_THIS_FUNCTION_ERROR(GENERIC_NO_BACKGROUND)
 T_DEBUG_LEAVE
 return GENERIC_NO_BACKGROUND;
}

/***************************************************************/

T_INT back_save(T_INT flag)
{
 T_DEBUG_ENTRY("back_save",55)
 if ((back_pic==NULL)||(flag==FORCED_SAVE))
 {
  if (back_pic!=NULL)
  {
   free_mem_bild(back_pic);
  }
#ifndef VECTREX
  back_pic=lade_vga_nach_mem(0,0,vesa_x,vesa_y,ALL_MEM_OK);
#else
  back_pic=lade_vga_nach_mem(0,0,vesa_bytes_per_scanline,vesa_y,NO_HD);
#endif
  if (back_pic==NULL)
  {
   T_DEBUG_SET_THIS_FUNCTION_ERROR(GENERIC_MEMORY_NOT_AVAILABLE)
   T_DEBUG_FUNCTION_POSITION(2)
   T_DEBUG_LEAVE
   tool_exit(GENERIC_MEMORY_NOT_AVAILABLE);
   return T_NOT_OK;
  }
 }
 T_DEBUG_LEAVE
 return T_OK;
}

/***************************************************************/

// MEM_BILD *lade_vga_nach_low(int x, int y, int len_x, int len_y);
/* funktion geht mal noch davon aus, dass alle zeichen die gleiche hoehe haben */

MEM_BILD *virtual_print_string_max(T_INT max_pix, T_PCHAR string)
{
 MEM_BILD *rueckgabe;
 T_PBYTE video;
 T_PBYTE zeiger;
 T_BYTE zeichen;
 T_INT breite_counter=0;
 T_INT buchstabe=0;
 T_INT breite;
 T_INT len_y;
 T_INT len_x;
 T_INT yy,xx;
 T_DEBUG_ENTRY("virtual_print_string_max",55)
 vesa_get_text_len(string,&len_x,&len_y);
 if (len_x>max_pix)
  len_x=max_pix;
 if ((rueckgabe=(MEM_BILD *)malloc(sizeof(MEM_BILD)))==NULL)
 {
  T_DEBUG_FUNCTION_POSITION(1)
  T_DEBUG_LEAVE
  return NULL;
 }
 rueckgabe->mem_zeiger=mem_bild_buffer;
 rueckgabe->x_size=len_x;
 rueckgabe->y_size=len_y;
 rueckgabe->speicher_art=SPEICHER;
 video=(T_PBYTE )mem_bild_buffer;
// original setmem(mem_bild_buffer,len_x*len_y,vesa_back_color);
 memset(mem_bild_buffer,vesa_back_color,len_x*len_y);
 #pragma warn -pia
 while ((zeichen=string[buchstabe])&&(breite_counter<len_x))
 #pragma warn .pia
 {
  T_INT copy_breite;
  if ((zeiger=font_now->zeichen[zeichen].zeiger)!=NULL)
  {
   copy_breite=breite=font_now->zeichen[zeichen].breite;
   breite_counter+=breite;
   if (breite_counter>len_x)
    copy_breite=len_x+breite-breite_counter;
   if (vesa_text==MULTI_COLOR)
   {
    for (yy=0;yy<font_now->zeichen[zeichen].hoehe;yy++)
    {
     for (xx=0;xx<copy_breite;xx++)
     {
      if (font_now->hintergrundfarbe != *(zeiger+xx))
      {
       *(video+xx) = *(zeiger+xx);
      }
     }
     video  += len_x;
     zeiger += breite;
    }
   }
   else // vesa_text_modus (SINGLE_COLOR)
   {
    for (yy=0;yy<font_now->zeichen[zeichen].hoehe;yy++)
    {
     for (xx=0;xx<copy_breite;xx++)
     {
      if (font_now->hintergrundfarbe != *(zeiger+xx))
      {
       *(video+xx) = vesa_text_color;
      }
     }
     video  += len_x;
     zeiger += breite;
    }
   }// vesa_text_modus (SINGLE_COLOR) ->else
   video=((T_PBYTE) (mem_bild_buffer))+breite_counter;
  }
  buchstabe++;
 }
 T_DEBUG_LEAVE
 return rueckgabe;
}

/***************************************************************/

// MAX_LOW_MEMBILD_BUFFER als rekursion
T_VOID print_with_all_features(WINDOW_LISTEN_ELEMENT *window, T_INT flag ,T_INT x, T_INT y,
T_INT max_pix, T_PCHAR string,...)
{
 MEM_BILD *destination;
 MEM_BILD *source=NULL;
 T_LONG size_in_bytes;
 T_INT abs_x,abs_y,pic_x,pic_y;
 T_INT len_x,len_y;
 T_PCHAR string1=NULL;
 T_PCHAR string2=NULL;
 va_list parameter;
 T_DEBUG_ENTRY("print_with_all_features",55)
 if (x<0)
  pic_x=last_printed_x;
 else
  pic_x=x;
 if (y<0)
  pic_y=last_printed_y;
 else
  pic_y=y;
 if ((string==NULL)||(string[0]==0))
 {
  T_DEBUG_FUNCTION_POSITION(1)
  T_DEBUG_LEAVE
  return;
 }
 if ((string==NULL)||(string[0]==(T_CHAR)0))
 {
  T_DEBUG_FUNCTION_POSITION(2)
  T_DEBUG_LEAVE
  return;
 }
 va_start( parameter, string );
 vsprintf( text_ausgabe, string, parameter );
 vesa_get_text_len(text_ausgabe, &len_x, &len_y);
 if (len_x > max_pix)
  len_x=max_pix;
 if (window==NULL)
 {
  destination=back_pic;
  abs_x=x;
  abs_y=y;
 }
 else
 {
  destination=window->window_pic;
  if ((flag==PRINT_WIN_RAW)||(flag==PRINT_RAW_OC))
  {
   abs_x=pic_x+window->x;
   abs_y=pic_y+window->y;
  }
  else
  {
   abs_x=pic_x+window->x+window->x_0;
   abs_y=pic_y+window->y+window->y_0;
  }
 }
 if (flag==PRINT_RAW_OC)
 {
  vesa_print_string_max_oc(0,0,x,y,len_x,len_y,text_ausgabe);
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
  T_DEBUG_FUNCTION_POSITION(3)
  T_DEBUG_LEAVE
  return;
 }
 else if ((flag==PRINT_RAW)||(destination==NULL))
 {
  t_hide_win_mouse(window);
  vesa_print_string_max(0,0,x,y,len_x,len_y,text_ausgabe);
  t_show_win_mouse(window);
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
  T_DEBUG_FUNCTION_POSITION(3)
  T_DEBUG_LEAVE
  return;
 }
 if (window!=NULL)
 {
  if (is_upper==T_TRUE)
  {
   if (flag==PRINT_WIN_RAW)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(4)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    t_hide_win_mouse(window);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
   }
   else if (flag==PRINT_RAW_OC)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(4)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
   }
   else if (flag==PRINT_CLIPPED_OC)
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(105)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
   }
   else
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(5)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    t_hide_win_mouse(window);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
   }
   T_DEBUG_FUNCTION_POSITION(6)
   T_DEBUG_LEAVE
   return;
  }
  if ( touching_upper_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
  {
   /* Also auf aktive window */
   /* hier abfrage auf fenster clipping */
   /* wenn sizeable fenster, dann rest in membild speichern */
   if (flag==PRINT_WIN_RAW)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(7)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    t_hide_win_mouse(window);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
    T_DEBUG_FUNCTION_POSITION(8)
    T_DEBUG_LEAVE
    return;
   }
   else if (flag==PRINT_RAW_OC)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(7)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
    T_DEBUG_FUNCTION_POSITION(8)
    T_DEBUG_LEAVE
    return;
   }
   else if (flag==PRINT_CLIPPED_OC)
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(109)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
    T_DEBUG_FUNCTION_POSITION(1010)
    T_DEBUG_LEAVE
    return;
   }
   else
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(9)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    t_hide_win_mouse(window);
    vesa_print_string_max_oc(0,0,abs_x,abs_y,len_x,len_y,text_ausgabe);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
    T_DEBUG_FUNCTION_POSITION(10)
    T_DEBUG_LEAVE
    return;
   }
  // sonst zeigt destination richtig und wird weiter unten bearbeitet
  }
 }
 size_in_bytes=((T_LONG)len_x)*((T_LONG)len_y);
 if (size_in_bytes>MAX_LOW_MEMBILD_BUFFER)
 {
  T_INT len1_x,len1_y,anzahl;
  string1=strdup(text_ausgabe);
  string2=strdup(text_ausgabe);
  string1[(T_INT)(strlen(text_ausgabe)/2)]=0;
  anzahl=vesa_get_text_len(string1,&len1_x,&len1_y);
  print_with_all_features(window,flag,x,y,len1_x,string1);
  print_with_all_features(window,flag,x+len1_x,y,len_x-len1_x,(string2+anzahl));
  if (string1!=NULL) free(string1);
  if (string2!=NULL) free(string2);
 }
 else
 {
  source=virtual_print_string_max(len_x, text_ausgabe);
  if (source!=NULL)
  {
   print_membild_with_all_features(source,window,flag,x,y,0,0,len_x,len_y);
   free(source); // new, correct?
   source=NULL;
  }
  else
  {
   show_message("no memory");
  }
 }
 if ((flag==PRINT_WIN_RAW)||(flag==PRINT_RAW_OC))
 {
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
 }
 else
 {
  last_printed_x=pic_x+len_x+window->x_0;
  last_printed_y=pic_y+len_y+window->y_0;
 }
 T_DEBUG_LEAVE
}

/***************************************************************/

T_VOID print_membild_with_all_features(MEM_BILD *source, WINDOW_LISTEN_ELEMENT *window,
T_INT flag ,T_INT x, T_INT y,T_INT x_offset, T_INT y_offset, T_INT len_x,T_INT len_y)
{
 MEM_BILD *destination;
 T_INT abs_x,abs_y,pic_x,pic_y;
 T_DEBUG_ENTRY("print_membild_with_all_features",55)
 if (x<0)
  pic_x=last_printed_x;
 else
  pic_x=x;
 if (y<0)
  pic_y=last_printed_y;
 else
  pic_y=y;
 if (source==NULL)
 {
  T_DEBUG_FUNCTION_POSITION(1)
  T_DEBUG_LEAVE
  return;
 }
 if (len_x+x_offset>source->x_size)
  len_x=source->x_size-x_offset;
 if (len_y+y_offset>source->y_size)
  len_y=source->y_size-y_offset;
 if (window==NULL)
 {
  destination=back_pic;
  abs_x=x;
  abs_y=y;
 }
 else
 {
  destination=window->window_pic;
  if ((flag==PRINT_WIN_RAW)||(flag==PRINT_RAW_OC))
  {
   abs_x=pic_x+window->x;
   abs_y=pic_y+window->y;
  }
  else
  {
   abs_x=pic_x+window->x+window->x_0;
   abs_y=pic_y+window->y+window->y_0;
  }
 }
 if ((flag==PRINT_RAW)||(destination==NULL))
 {
  print_mem_teilbild(source,pic_x,pic_y,x_offset,y_offset,len_x,len_y);
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
  T_DEBUG_FUNCTION_POSITION(2)
  T_DEBUG_LEAVE
  return;
 }
 else if (flag==PRINT_RAW_OC)
 {
  print_mem_teilbild_oc(source,pic_x,pic_y,x_offset,y_offset,len_x,len_y);
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
  T_DEBUG_FUNCTION_POSITION(2)
  T_DEBUG_LEAVE
  return;
 }
 if (window!=NULL)
 {
  if (is_upper==T_TRUE)
  {
   if (flag==PRINT_RAW_OC)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(3)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
   }
   else if (flag==PRINT_WIN_RAW)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(103)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    t_hide_win_mouse(window);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
   }
   else if (flag==PRINT_CLIPPED_OC)
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(104)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
   }
   else
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(4)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    t_hide_win_mouse(window);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
   }
   T_DEBUG_FUNCTION_POSITION(5)
   T_DEBUG_LEAVE
   return;
  }
  if (touching_upper_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
  {
   /* hier abfrage auf fenster clipping */
   /* wenn sizeable fenster, dann rest in membild speichern */
   if (flag==PRINT_RAW_OC)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(6)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
    T_DEBUG_FUNCTION_POSITION(7)
    T_DEBUG_LEAVE
    return;
   }
   else if (flag==PRINT_WIN_RAW)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(106)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    t_hide_win_mouse(window);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
    T_DEBUG_FUNCTION_POSITION(107)
    T_DEBUG_LEAVE
    return;
   }
   else if (flag==PRINT_CLIPPED_OC)
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(108)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
    T_DEBUG_FUNCTION_POSITION(109)
    T_DEBUG_LEAVE
    return;
   }
   else
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     T_DEBUG_FUNCTION_POSITION(8)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    t_hide_win_mouse(window);
    print_mem_teilbild_oc(source,abs_x,abs_y,x_offset,y_offset,len_x,len_y);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
    T_DEBUG_FUNCTION_POSITION(9)
    T_DEBUG_LEAVE
    return;
   }
   // sonst zeigt destination richtig und wird weiter unten bearbeitet
  }
 }
 if ((flag==PRINT_WIN_RAW)||(flag==PRINT_RAW_OC))
 {
  lade_mem_nach_mem_teil(source,x_offset,y_offset,destination,pic_x,pic_y,len_x, len_y,COPY_MEM_WITH_VESA_OPTIONS);
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
 }
 else
 {
  lade_mem_nach_mem_teil(source,x_offset,y_offset,destination,pic_x+window->x_0,pic_y+window->y_0,len_x, len_y,COPY_MEM_WITH_VESA_OPTIONS);
  last_printed_x=pic_x+len_x+window->x_0;
  last_printed_y=pic_y+len_y+window->y_0;
 }
 /* ab hier nur noch Bildschirm update */
 if (touching_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
 {
  if (flag==PRINT_RAW_OC)
   print_mem_teilbild_oc(destination,abs_x,abs_y,pic_x,pic_y,len_x,len_y);
  else if (flag==PRINT_WIN_RAW)
   print_mem_teilbild(destination,abs_x,abs_y,pic_x,pic_y,len_x,len_y);
  else if (flag==PRINT_CLIPPED_OC)
   print_mem_teilbild_oc(destination,abs_x,abs_y,pic_x+window->x_0,pic_y+window->y_0,len_x,len_y);
  else
   print_mem_teilbild(destination,abs_x,abs_y,pic_x+window->x_0,pic_y+window->y_0,len_x,len_y);
 }
 else
 {
  if (destination==back_pic)
   repair_screen(NULL,UPDATE_VISIBLE_BACK_RECT,abs_x,abs_y,len_x,len_y);
  else
   if ((window->hide==0)&&(window->dhide==0))
    repair_screen(window,UPDATE_VISIBLE_WINDOW_RECT,abs_x,abs_y,len_x,len_y);
 }
 T_DEBUG_LEAVE
}

/***************************************************************/

T_VOID print_rectfill_with_all_features(WINDOW_LISTEN_ELEMENT *window, T_INT flag ,T_INT x,
T_INT y, T_INT len_x,T_INT len_y,T_BYTE color)
{
 MEM_BILD *destination;
 MEM_BILD *source;
 T_INT abs_x,abs_y,pic_x,pic_y;
 T_INT old_print_modus=vesa_print_modus;
 T_INT old_back_color=vesa_back_color;
 T_LONG size_in_bytes;
 T_DEBUG_ENTRY("print_rectfill_with_all_features",55)
 if (x<0)
  pic_x=last_printed_x;
 else
  pic_x=x;
 if (y<0)
  pic_y=last_printed_y;
 else
  pic_y=y;
 vesa_print_modus=PIC_FILLED;
 vesa_back_color=color+1;
 if (window==NULL)
 {
  destination=back_pic;
  abs_x=x;
  abs_y=y;
 }
 else
 {
  destination=window->window_pic;
  if ((flag==PRINT_WIN_RAW)||(flag==PRINT_RAW_OC))
  {
   abs_x=pic_x+window->x;
   abs_y=pic_y+window->y;
  }
  else
  {
   abs_x=pic_x+window->x+window->x_0;
   abs_y=pic_y+window->y+window->y_0;
  }
 }
 if ((flag==PRINT_RAW)||(destination==NULL))
 {
  vesa_rect_fill(pic_x,pic_y,len_x,len_y,color);
  vesa_print_modus=old_print_modus;
  vesa_back_color=old_back_color;
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
  T_DEBUG_FUNCTION_POSITION(1)
  T_DEBUG_LEAVE
  return;
 }
 else if (flag==PRINT_RAW_OC)
 {
  vesa_rect_fill_oc(pic_x,pic_y,len_x,len_y,color);
  vesa_print_modus=old_print_modus;
  vesa_back_color=old_back_color;
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
  T_DEBUG_FUNCTION_POSITION(101)
  T_DEBUG_LEAVE
  return;
 }
 if (window!=NULL)
 {
  if (is_upper==T_TRUE)
  {
   if (flag==PRINT_RAW_OC)
   {
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(2)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(3)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
   }
   else if (flag==PRINT_WIN_RAW)
   {
    t_hide_win_mouse(window);
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     t_show_win_mouse(window);
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(102)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     t_show_win_mouse(window);
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(103)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
   }
   else if (flag==PRINT_CLIPPED_OC)
   {
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(104)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(105)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
   }
   else
   {
    t_hide_win_mouse(window);
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     t_show_win_mouse(window);
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(4)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     t_show_win_mouse(window);
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(5)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    t_show_win_mouse(window);
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
   }
   vesa_print_modus=old_print_modus;
   vesa_back_color=old_back_color;
   T_DEBUG_FUNCTION_POSITION(6)
   T_DEBUG_LEAVE
   return;
  }
  if (touching_upper_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
  {
   /* hier abfrage auf fenster clipping */
   /* wenn sizeable fenster, dann rest in membild speichern */
   if (flag==PRINT_RAW_OC)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(7)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(8)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    vesa_print_modus=old_print_modus;
    vesa_back_color=old_back_color;
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
    T_DEBUG_FUNCTION_POSITION(9)
    T_DEBUG_LEAVE
    return;
   }
   else if (flag==PRINT_WIN_RAW)
   {
    if ((pic_x>window->b)||(pic_y>window->h))  ////// meistens ueberfluessig
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(107)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b)
     len_x=window->b-(pic_x);
    if (pic_y+len_y>window->h)
     len_y=window->h-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(108)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    t_hide_win_mouse(window);
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x,pic_y,window->window_pic);
    t_show_win_mouse(window);
    vesa_print_modus=old_print_modus;
    vesa_back_color=old_back_color;
    last_printed_x=pic_x+len_x;
    last_printed_y=pic_y+len_y;
    T_DEBUG_FUNCTION_POSITION(109)
    T_DEBUG_LEAVE
    return;
   }
   else if (flag==PRINT_CLIPPED_OC)
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(1010)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(1011)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    vesa_print_modus=old_print_modus;
    vesa_back_color=old_back_color;
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
    T_DEBUG_FUNCTION_POSITION(1012)
    T_DEBUG_LEAVE
    return;
   }
   else
   {
    if ((pic_x>window->b_open)||(pic_y>window->h_open))  ////// meistens ueberfluessig
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(10)
     T_DEBUG_LEAVE
     return;
    }
    if (pic_x+len_x>window->b_open)
     len_x=window->b_open-(pic_x);
    if (pic_y+len_y>window->h_open)
     len_y=window->h_open-(pic_y);
    if ((len_x<0)||(len_y<0))
    {
     vesa_print_modus=old_print_modus;
     vesa_back_color=old_back_color;
     T_DEBUG_FUNCTION_POSITION(11)
     T_DEBUG_LEAVE
     return; // eigentlich ueberall, aber zu verschwenderisch...
    }
    t_hide_win_mouse(window);
    vesa_rect_fill_oc(abs_x,abs_y,len_x,len_y,color);
    lade_vga_nach_mem_teil_oc(abs_x,abs_y,len_x,len_y,pic_x+window->x_0,pic_y+window->y_0,window->window_pic);
    t_show_win_mouse(window);
    vesa_print_modus=old_print_modus;
    vesa_back_color=old_back_color;
    last_printed_x=pic_x+len_x+window->x_0;
    last_printed_y=pic_y+len_y+window->y_0;
    T_DEBUG_FUNCTION_POSITION(12)
    T_DEBUG_LEAVE
    return;
   }
   // sonst zeigt destination richtig und wird weiter unten bearbeitet
  }
 }
// hier, wenn es mindestens ein Fenster gibt, dass ueber dem zu beschreibenden
// liegt!
 size_in_bytes=((T_LONG)len_x)*((T_LONG)len_y);
 if (size_in_bytes>MAX_LOW_MEMBILD_BUFFER)
 {
  if (len_x<len_y) /* dann eine rekursion durchfuehren */
  {
   T_INT len_x1=len_x;
   T_INT len_x2=len_x;
   T_INT len_y1=len_y/2;
   T_INT len_y2=len_y-len_y1;
   print_rectfill_with_all_features(window,flag,x,y,len_x1,len_y1,color);
   print_rectfill_with_all_features(window,flag,x,y+len_y1,len_x2,len_y2,color);
  }
  else
  {
   T_INT len_x1=len_x/2;
   T_INT len_x2=len_x-len_x1;
   T_INT len_y1=len_y;
   T_INT len_y2=len_y;
   print_rectfill_with_all_features(window,flag,x,y,len_x1,len_y1,color);
   print_rectfill_with_all_features(window,flag,x+len_x1,y,len_x2,len_y2,color);
  }
 }
 else
 {
  // keine rekursion durchfuehren...
  source=virtual_rect_fill(len_x,len_y,color);
  if (source!=NULL)
  {
   if (flag==PRINT_WIN_RAW)
   {
    lade_mem_nach_mem_teil(source,0,0,destination,pic_x,pic_y,len_x,len_y,COPY_MEM_WITH_VESA_OPTIONS);
    free(source); // nur das membild freigeben, der speicher dafuer ist in tools_init belegt worden, als fester buffer
     /* ab hier nur noch Bildschirm update */
    if (touching_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
     print_mem_teilbild(destination,abs_x,abs_y,pic_x,pic_y,len_x,len_y);
    else
    {
     if (destination==back_pic)
      repair_screen(NULL,UPDATE_VISIBLE_BACK_RECT,abs_x,abs_y,len_x,len_y);
     else
      if ((window->hide==0)&&(window->dhide==0))
       repair_screen(window,UPDATE_VISIBLE_WINDOW_RECT,abs_x,abs_y,len_x,len_y);
    }
   }
   else if (flag==PRINT_RAW_OC)
   {
    lade_mem_nach_mem_teil(source,0,0,destination,pic_x,pic_y,len_x,len_y,COPY_MEM_WITH_VESA_OPTIONS);
    free(source); // nur das membild freigeben, der speicher dafuer ist in tools_init belegt worden, als fester buffer
     /* ab hier nur noch Bildschirm update */
    if (touching_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
     print_mem_teilbild_oc(destination,abs_x,abs_y,pic_x,pic_y,len_x,len_y);
    else
    {
     if (destination==back_pic)
      repair_screen(NULL,UPDATE_VISIBLE_BACK_RECT,abs_x,abs_y,len_x,len_y);
     else
      if ((window->hide==0)&&(window->dhide==0))
       repair_screen(window,UPDATE_VISIBLE_WINDOW_RECT,abs_x,abs_y,len_x,len_y);
    }
   }
   else if (flag==PRINT_CLIPPED_OC)
   {
    lade_mem_nach_mem_teil(source,0,0,destination,pic_x+window->x_0,pic_y+window->y_0,len_x,len_y,COPY_MEM_WITH_VESA_OPTIONS);
    free(source); // nur das membild freigeben, der speicher dafuer ist in tools_init belegt worden, als fester buffer
     /* ab hier nur noch Bildschirm update */
    if (touching_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
     print_mem_teilbild_oc(destination,abs_x,abs_y,pic_x+window->x_0,pic_y+window->y_0,len_x,len_y);
    else
    {
     if (destination==back_pic)
      repair_screen(NULL,UPDATE_VISIBLE_BACK_RECT,abs_x,abs_y,len_x,len_y);
     else
      if ((window->hide==0)&&(window->dhide==0))
       repair_screen(window,UPDATE_VISIBLE_WINDOW_RECT,abs_x,abs_y,len_x,len_y);
    }
   }
   else
   {
    lade_mem_nach_mem_teil(source,0,0,destination,pic_x+window->x_0,pic_y+window->y_0,len_x,len_y,COPY_MEM_WITH_VESA_OPTIONS);
    free(source); // nur das membild freigeben, der speicher dafuer ist in tools_init belegt worden, als fester buffer
     /* ab hier nur noch Bildschirm update */
    if (touching_windows(abs_x,abs_y,len_x,len_y,window)==T_FALSE)
     print_mem_teilbild(destination,abs_x,abs_y,pic_x+window->x_0,pic_y+window->y_0,len_x,len_y);
    else
    {
     if (destination==back_pic)
      repair_screen(NULL,UPDATE_VISIBLE_BACK_RECT,abs_x,abs_y,len_x,len_y);
     else
      if ((window->hide==0)&&(window->dhide==0))
       repair_screen(window,UPDATE_VISIBLE_WINDOW_RECT,abs_x,abs_y,len_x,len_y);
    }
   }
  }
 }
 vesa_print_modus=old_print_modus;
 vesa_back_color=old_back_color;
 if ((flag==PRINT_WIN_RAW)||(flag==PRINT_RAW_OC))
 {
  last_printed_x=pic_x+len_x;
  last_printed_y=pic_y+len_y;
 }
 else
 {
  last_printed_x=pic_x+len_x+window->x_0;
  last_printed_y=pic_y+len_y+window->y_0;
 }
 T_DEBUG_LEAVE
}

/***************************************************************/

MEM_BILD *virtual_rect_fill(T_INT len_x,T_INT len_y,T_BYTE color)
{
// len_x*len_y < MAX_LOW_MEMBILD_BUFFER sonst segmentation fault...
 MEM_BILD *rueckgabe;
 T_DEBUG_ENTRY("virtual_rect_fill",55)
 if ((rueckgabe=(MEM_BILD *)malloc(sizeof(MEM_BILD)))==NULL)
 {
  T_DEBUG_FUNCTION_POSITION(1)
  T_DEBUG_LEAVE
  return NULL;
 }
 rueckgabe->mem_zeiger=mem_bild_buffer;
 rueckgabe->x_size=len_x;
 rueckgabe->y_size=len_y;
 rueckgabe->speicher_art=SPEICHER;
 memset(mem_bild_buffer,color,len_x*len_y);
 T_DEBUG_LEAVE
 return rueckgabe;
}

/***************************************************************/

T_VOID print_srect(WINDOW_LISTEN_ELEMENT *this_window,T_INT flag,T_INT x, T_INT y, T_INT b,
T_INT h,T_BYTE col1, T_BYTE col2, T_INT thick)
{
 T_INT i;
 T_DEBUG_ENTRY("print_srect",55)
 MOUSE_VERSTECKE
 for (i=0;i<thick;i++)
 {
  print_lineh(this_window,flag,x,y+i,b-1-i,col1);
  print_lineh(this_window,flag,x+i,y+h-1-i,b-1-i,col2);
  print_linev(this_window,flag,x+i,y,h-1-i,col1);
  print_linev(this_window,flag,x+b-1-i,y+i,h/*-1*/-i,col2);
 }
 MOUSE_ZEIGE
 T_DEBUG_LEAVE
}

