gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
Window.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef WINDOW_H_
18 #define WINDOW_H_
19 #include "Container.H"
20 
26 class Window : public Container {
27 
28  bool fillBorderImplementation(GtkWidget *winIn, int borderFillVar=-1){
29  if (borderFillVar==-1) // if no border fill specified, use the class default
30  borderFillVar=borderFill;
31  GtkStyle *wStyle=gtk_widget_get_style(winIn); // get the widget's bg colour
32  cairo_t *cr=gdk_cairo_create(gtk_widget_get_window(widget));
33  gdk_cairo_set_source_color(cr, &wStyle->bg[GTK_STATE_NORMAL]);
34  int x, y, width, height;
35 #if GTK_MAJOR_VERSION==3
36  GtkAllocation winAlloc, widgetAlloc;
37  gtk_widget_get_allocation(widget, &winAlloc);
38  gtk_widget_get_allocation(winIn, &widgetAlloc);
39 #endif
40  if (borderFillVar&BORDER_LEFT){ // fill from the left side of the widget to the edge of the window
41 #if GTK_MAJOR_VERSION==2
42  x=widget->allocation.x; y=winIn->allocation.y; width=winIn->allocation.x-x; height=winIn->allocation.height;
43 #else
44  x=winAlloc.x; y=widgetAlloc.y; width=widgetAlloc.x-x; height=widgetAlloc.height;
45 #endif
46  cairo_rectangle(cr, x, y, width, height);
47  }
48  if (borderFillVar&BORDER_RIGHT){ // fill from the left side of the widget to the edge of the window
49 #if GTK_MAJOR_VERSION==2
50  x=winIn->allocation.x+winIn->allocation.width; y=winIn->allocation.y; width=(widget->allocation.x+widget->allocation.width)-x; height=winIn->allocation.height;
51 #else
52  x=widgetAlloc.x+widgetAlloc.width; y=widgetAlloc.y; width=(winAlloc.x+winAlloc.width)-x; height=widgetAlloc.height;
53 #endif
54  cairo_rectangle(cr, x, y, width, height);
55  }
56  if (((borderFillVar&BORDER_LEFT)!=0)&((borderFillVar&BORDER_TOP)!=0)){ // fill the top left corner if both left and top are filled
57 #if GTK_MAJOR_VERSION==2
58  x=widget->allocation.x; y=widget->allocation.y; width=winIn->allocation.x-x; height=winIn->allocation.y-widget->allocation.y;
59 #else
60  x=winAlloc.x; y=winAlloc.y; width=widgetAlloc.x-x; height=widgetAlloc.y-winAlloc.y;
61 #endif
62  cairo_rectangle(cr, x, y, width, height);
63  }
64  if (((borderFillVar&BORDER_RIGHT)!=0)&((borderFillVar&BORDER_TOP)!=0)){ // fill the top right corner if both right and top are filled
65 #if GTK_MAJOR_VERSION==2
66  x=winIn->allocation.x+winIn->allocation.width; y=widget->allocation.y; width=(widget->allocation.x+widget->allocation.width)-x; height=winIn->allocation.y-y;
67 #else
68  x=widgetAlloc.x+widgetAlloc.width; y=winAlloc.y; width=(winAlloc.x+winAlloc.width)-x; height=widgetAlloc.y-y;
69 #endif
70  cairo_rectangle(cr, x, y, width, height);
71  }
72  if (borderFillVar&BORDER_TOP){ // fill from the left side of the widget to the edge of the window
73 #if GTK_MAJOR_VERSION==2
74  x=winIn->allocation.x; y=widget->allocation.y; width=winIn->allocation.width; height=winIn->allocation.y-y;
75 #else
76  x=widgetAlloc.x; y=winAlloc.y; width=widgetAlloc.width; height=widgetAlloc.y-y;
77 #endif
78  cairo_rectangle(cr, x, y, width, height);
79  }
80  if (borderFillVar&BORDER_BOTTOM){ // fill from the left side of the widget to the edge of the window
81 #if GTK_MAJOR_VERSION==2
82  x=winIn->allocation.x; y=winIn->allocation.y+winIn->allocation.height; width=winIn->allocation.width; height=(widget->allocation.y+widget->allocation.height)-y;
83 #else
84  x=widgetAlloc.x; y=widgetAlloc.y+widgetAlloc.height; width=widgetAlloc.width; height=(winAlloc.y+winAlloc.height)-y;
85 #endif
86  cairo_rectangle(cr, x, y, width, height);
87  }
88  if (((borderFillVar&BORDER_LEFT)!=0)&((borderFillVar&BORDER_BOTTOM)!=0)){ // fill the bottom left corner if both left and bottom are filled
89 #if GTK_MAJOR_VERSION==2
90  x=widget->allocation.x; y=winIn->allocation.y+winIn->allocation.height; width=winIn->allocation.x-x; height=(widget->allocation.y+widget->allocation.height)-y;
91 #else
92  x=winAlloc.x; y=widgetAlloc.y+widgetAlloc.height; width=widgetAlloc.x-x; height=(winAlloc.y+winAlloc.height)-y;
93 #endif
94  cairo_rectangle(cr, x, y, width, height);
95  }
96  if (((borderFillVar&BORDER_RIGHT)!=0)&((borderFillVar&BORDER_BOTTOM)!=0)){ // fill the bottom right corner if both right and bottom are filled
97 #if GTK_MAJOR_VERSION==2
98  x=winIn->allocation.x+winIn->allocation.width; y=winIn->allocation.y+winIn->allocation.height; width=(widget->allocation.x+widget->allocation.width)-x; height=(widget->allocation.y+widget->allocation.height)-y;
99 #else
100  x=widgetAlloc.x+widgetAlloc.width; y=widgetAlloc.y+widgetAlloc.height; width=(winAlloc.x+winAlloc.width)-x; height=(winAlloc.y+winAlloc.height)-y;
101 #endif
102  cairo_rectangle(cr, x, y, width, height);
103  }
104  cairo_fill(cr);
105  cairo_destroy(cr);
106  return false;
107  }
108 public:
111 //
112 // GtkWidget *win; ///< The window widget
113 //
114 // /** Get the window widget
115 // \return the GtkWidget win
116 // */
117 // GtkWidget * getWidget(void){return win;}
118 
119 // /** \brief default constructor
120 // */
121 // Window(void){
122 //#ifdef DEBUG_Window
123 // cout<<"Window: init "<<this<<endl;
124 //#endif
125 // init();
126 // }
127 
133  Window(int width, int height, bool resiseable=true) : Container() {
134  init(width, height, resiseable);
135  }
136 
138  init();
139  }
140 
141 
147  void init(int width=0, int height=0, bool resiseable=true){
148  widget = gtk_window_new( GTK_WINDOW_TOPLEVEL );
149  if (width!=0 & height!=0) // only resize if both are non-zero
150  gtk_widget_set_size_request(widget, width, height);
151 // g_signal_connect(G_OBJECT (widget), "delete_event", reinterpret_cast<GCallback> (quit), NULL );
152  show();
153  }
154 
159  void setBackgroundColour(GdkColor *colour, GtkStateType state=GTK_STATE_NORMAL){
160  gtk_widget_modify_bg(widget, state, colour);
161  }
162 
167  void setBackgroundColour(const char* colourName, GtkStateType state=GTK_STATE_NORMAL){
168  GdkColor colour; gdk_color_parse (colourName, &colour);
169  setBackgroundColour(&colour, state);
170  }
171 
186  static bool fillBorder(GtkWidget *widget, GdkEventExpose *event, gpointer data){
187  Window *gtki=static_cast<Window*>(data);
188  return gtki->fillBorderImplementation(widget);
189  }
190 
197  static bool fillBannerTop(GtkWidget *widget, GdkEventExpose *event, gpointer data){
198  Window *gtki=static_cast<Window*>(data);
200  }
201 
208  static bool fillBannerMiddle(GtkWidget *widget, GdkEventExpose *event, gpointer data){
209  Window *gtki=static_cast<Window*>(data);
210  return gtki->fillBorderImplementation(widget, BORDER_LEFT|BORDER_RIGHT);
211  }
212 
219  static bool fillBannerBottom(GtkWidget *widget, GdkEventExpose *event, gpointer data){
220  Window *gtki=static_cast<Window*>(data);
222  }
223 };
224 
225 #endif // WINDOW_H_
226 
static bool fillBorder(GtkWidget *widget, GdkEventExpose *event, gpointer data)
Definition: Window.H:186
static bool fillBannerMiddle(GtkWidget *widget, GdkEventExpose *event, gpointer data)
Definition: Window.H:208
float * x
Definition: Window.H:26
static bool fillBannerTop(GtkWidget *widget, GdkEventExpose *event, gpointer data)
Definition: Window.H:197
GtkWidget * show(void)
Definition: Widget.H:65
Window()
Definition: Window.H:137
static bool fillBannerBottom(GtkWidget *widget, GdkEventExpose *event, gpointer data)
Definition: Window.H:219
BorderFillOptions
Definition: Window.H:109
GtkWidget * widget
The container based widget.
Definition: Widget.H:33
void setBackgroundColour(GdkColor *colour, GtkStateType state=GTK_STATE_NORMAL)
Definition: Window.H:159
float * y
bool fillBorderImplementation(GtkWidget *winIn, int borderFillVar=-1)
Definition: Window.H:28
int borderFill
Used if the fillBorder callback is in use.
Definition: Window.H:110
void setBackgroundColour(const char *colourName, GtkStateType state=GTK_STATE_NORMAL)
Definition: Window.H:167
void init(int width=0, int height=0, bool resiseable=true)
the initialisation of the window (common to both constructors)
Definition: Window.H:147
Window(int width, int height, bool resiseable=true)
default constructor
Definition: Window.H:133
gtkIOStream: /tmp/gtkiostream/include/Window.H Source File
GTK+ IOStream  Beta