EditorGadget Background color

Linux specific forum
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

EditorGadget Background color

Post by Inner »

Does anyone know how to alter the editorgadget background color please?
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Here it is:

Code: Select all

Procedure SetBackgroundColor(EditorGadget, Color)

  ; First we need to create a GdkColor structure for our color:
  ;
  NewColor.GdkColor
  NewColor\red   = Red(Color) << 8
  NewColor\green = Green(Color) << 8
  NewColor\blue  = Blue(Color) << 8
  
  ; now apply the color:
  ;
  *text._GtkText = GadgetID(EditorGadget)
  gdk_window_set_background_(*text\text_area, @NewColor)
  gtk_widget_queue_draw_(*text)

EndProcedure

Note: You need these 2 gtk structures, because PB defines them wrong.
(that's because these 1 byte types are used there which PB doesn't support)

Code: Select all

Structure _GtkEditable
  widget.GtkWidget

  current_pos.l
  selection_start_pos.l
  selection_end_pos.l

  _packed_flags.l  ; below listed flags:
    ; guint      has_selection : 1;
    ; guint      editable : 1;
    ; guint      visible : 1;

  *ic.GdkIC
  *ic_attr.GdkICAttr
  
  *clipboard_text.b
EndStructure

Structure _GtkText
  editable._GtkEditable

  *text_area.GdkWindow

  *hadj.GtkAdjustment
  *vadj.GtkAdjustment

  *gc.GdkGC

  *line_wrap_bitmap.GdkPixmap
  *line_arrow_bitmap.GdkPixmap

  ;/* GAPPED TEXT SEGMENT */

     ;/* The text, a single segment of text a'la emacs, with a gap
     ; * where insertion occurs. */
  *text.b

     ;/* The allocated length of the text segment. */
  text_len.l

     ;/* The gap position, index into address where a char
     ; * should be inserted. */
  gap_position.l

     ;/* The gap size, s.t. *(text + gap_position + gap_size) is
     ; * the first valid character following the gap. */
  gap_size.l

     ;/* The last character position, index into address where a
     ; * character should be appeneded.  Thus, text_end - gap_size
     ; * is the length of the actual data. */
  text_end.l

  ;/* LINE START CACHE */

     ;/* A cache of line-start information.  Data is a LineParam*. */
  line_start_cache.l  ; pointer to a GList

     ;/* Index to the start of the first visible line. */
  first_line_start_index.l

     ;/* The number of pixels cut off of the top line. */
  first_cut_pixels.l

     ;/* First visible horizontal pixel. */
  first_onscreen_hor_pixel.l

     ;/* First visible vertical pixel. */
  first_onscreen_ver_pixel.l

  ;/* FLAGS */

  _packed_flags.l

     ;/* True iff this buffer is wrapping lines, otherwise it is using a
     ; * horizontal scrollbar. */
  ;guint line_wrap : 1;
  ;guint word_wrap : 1;

     ;/* If a fontset is supplied for the widget, use_wchar become true,
     ; * and we use GdkWchar as the encoding of text. */
  ;guint use_wchar : 1;

     ;/* Frozen, don't do updates. @@@ fixme */
  ;guint freeze_count;

  ;/* TEXT PROPERTIES */

     ;/* A doubly-linked-list containing TextProperty objects. */
  *text_properties.GList

     ;/* The end of this list. */
  *text_properties_end.GList

     ;/* The first node before or on the point along with its offset to
     ; * the point and the buffer's current point.  This is the only
     ; * PropertyMark whose index is guaranteed to remain correct
     ; * following a buffer insertion or deletion. */
  point.GtkPropertyMark

  ;/* SCRATCH AREA */

  *scratch_buffer.b
  scratch_buffer_len.l

  ;/* SCROLLING */

  last_ver_value.l

  ;/* CURSOR */

  cursor_pos_x.l;       /* Position of cursor. */
  cursor_pos_y.l;       /* Baseline of line cursor is drawn on. */
  cursor_mark.GtkPropertyMark;        /* Where it is in the buffer. */
  cursor_char.w;        /* Character to redraw. */
  cursor_char_offset.b; /* Distance from baseline of the font. */
  cursor_virtual_x.l;   /* Where it would be if it could be. */
  cursor_drawn_level.l; /* How many people have undrawn. */

  ;/* Current Line */

  *current_line.GList

  ;/* Tab Stops */

  *tab_stops.GList
  default_tab_width.l

  *current_font.GtkTextFont;	/* Text font for current style */

     ;/* Timer used for auto-scrolling off ends */
  timer.l
  
  button.l;			/* currently pressed mouse button */
  *bg_gc.GdkGC;			/* gc for drawing background pixmap */
EndStructure
quidquid Latine dictum sit altum videtur
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

Thanks freak ;)

btw: anyone using this code, the code above is only compatable with GTK v1.2
Post Reply