diff options
Diffstat (limited to 'gtk/PlatGTK.cxx')
-rw-r--r-- | gtk/PlatGTK.cxx | 251 |
1 files changed, 125 insertions, 126 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 47e32118c..c028a52a1 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -8,6 +8,7 @@ #include <stdlib.h> #include <gtk/gtk.h> +#include <gdk/gdkkeysyms.h> #include "Platform.h" @@ -20,58 +21,50 @@ #define FAST_WAY #endif -Point Point::FromLong(long lpoint) { - return Point( - Platform::LowShortFromLong(lpoint), - Platform::HighShortFromLong(lpoint)); -} +#ifdef _MSC_VER +// Ignore unreferenced local functions in GTK+ headers +#pragma warning(disable: 4505) +#endif -static GdkColor ColourfromRGB(unsigned int red, unsigned int green, unsigned int blue) { - GdkColor co; - co.red = red * (65535 / 255); - co.green = green * (65535 / 255); - co.blue = blue * (65535 / 255); - // the pixel value indicates the index in the colourmap of the colour. - // it is simply a combination of the RGB values we set earlier - co.pixel = (gulong)(red * 65536 + green * 256 + blue); - return co; +static GdkFont *PFont(Font &f) { + return reinterpret_cast<GdkFont *>(f.GetID()); } -Colour::Colour(long lcol) { - unsigned int red = lcol & 0xff; - unsigned int green = (lcol >> 8) & 0xff; - unsigned int blue = lcol >> 16; - co = ColourfromRGB(red, green, blue); +static GdkDrawable *PDrawable(SurfaceID id) { + return reinterpret_cast<GdkDrawable *>(id); } -Colour::Colour(unsigned int red, unsigned int green, unsigned int blue) { - co = ColourfromRGB(red, green, blue); +static GdkGC *PGC(void *gc) { + return reinterpret_cast<GdkGC *>(gc); } -bool Colour::operator==(const Colour &other) const { - return - co.red == other.co.red && - co.green == other.co.green && - co.blue == other.co.blue; +static GtkWidget *PWidget(WindowID id) { + return reinterpret_cast<GtkWidget *>(id); } -unsigned int Colour::GetRed() { - return co.red; +static GtkWidget *PWidget(Window &w) { + return PWidget(w.GetID()); } -unsigned int Colour::GetGreen() { - return co.green; +static GtkItemFactory *PMenu(MenuID id) { + return reinterpret_cast<GtkItemFactory *>(id); } -unsigned int Colour::GetBlue() { - return co.blue; +Point Point::FromLong(long lpoint) { + return Point( + Platform::LowShortFromLong(lpoint), + Platform::HighShortFromLong(lpoint)); } -long Colour::AsLong() const { - unsigned int red = co.red * 255 / 65535; - unsigned int green = co.green * 255 / 65535; - unsigned int blue = co.blue * 255 / 65535; - return (red + green*256 + blue*65536); +static GdkColor ColourfromRGB(unsigned int red, unsigned int green, unsigned int blue) { + GdkColor co; + co.red = red * (65535 / 255); + co.green = green * (65535 / 255); + co.blue = blue * (65535 / 255); + // the pixel value indicates the index in the colourmap of the colour. + // it is simply a combination of the RGB values we set earlier + co.pixel = (gulong)(red * 65536 + green * 256 + blue); + return co; } Palette::Palette() { @@ -87,7 +80,7 @@ Palette::~Palette() { void Palette::Release() { used = 0; - delete []allocatedPalette; + delete [](reinterpret_cast<GdkColor *>(allocatedPalette)); allocatedPalette = 0; allocatedLen = 0; } @@ -104,7 +97,7 @@ void Palette::WantFind(ColourPair &cp, bool want) { if (used < numEntries) { entries[used].desired = cp.desired; - entries[used].allocated = cp.desired; + entries[used].allocated.Set(cp.desired.AsLong()); used++; } } else { @@ -114,31 +107,33 @@ void Palette::WantFind(ColourPair &cp, bool want) { return ; } } - cp.allocated = cp.desired; + cp.allocated.Set(cp.desired.AsLong()); } } void Palette::Allocate(Window &w) { if (allocatedPalette) { - gdk_colormap_free_colors(gtk_widget_get_colormap(w.GetID()), - allocatedPalette, allocatedLen); - delete []allocatedPalette; + gdk_colormap_free_colors(gtk_widget_get_colormap(PWidget(w)), + reinterpret_cast<GdkColor *>(allocatedPalette), + allocatedLen); + delete [](reinterpret_cast<GdkColor *>(allocatedPalette)); allocatedPalette = 0; allocatedLen = 0; } - allocatedPalette = new GdkColor[used]; + GdkColor *paletteNew = new GdkColor[used]; + allocatedPalette = paletteNew; gboolean *successPalette = new gboolean[used]; - if (allocatedPalette) { + if (paletteNew) { allocatedLen = used; int iPal = 0; for (iPal = 0; iPal < used; iPal++) { - allocatedPalette[iPal] = entries[iPal].desired.co; + paletteNew[iPal].pixel = entries[iPal].desired.AsLong(); } - gdk_colormap_alloc_colors(gtk_widget_get_colormap(w.GetID()), - allocatedPalette, allocatedLen, FALSE, TRUE, + gdk_colormap_alloc_colors(gtk_widget_get_colormap(PWidget(w)), + paletteNew, allocatedLen, FALSE, TRUE, successPalette); for (iPal = 0; iPal < used; iPal++) { - entries[iPal].allocated.co = allocatedPalette[iPal]; + entries[iPal].allocated.Set(paletteNew[iPal].pixel); } } delete []successPalette; @@ -231,7 +226,7 @@ void Font::Create(const char *faceName, int characterSet, void Font::Release() { if (id) - gdk_font_unref(id); + gdk_font_unref(PFont(*this)); id = 0; } @@ -246,11 +241,11 @@ void Surface::Release() { drawable = 0; if (createdGC) { createdGC = false; - gdk_gc_unref(gc); + gdk_gc_unref(PGC(gc)); } gc = 0; if (ppixmap) - gdk_pixmap_unref(ppixmap); + gdk_pixmap_unref(PDrawable(ppixmap)); ppixmap = 0; x = 0; y = 0; @@ -267,7 +262,8 @@ void Surface::Init() { inited = true; } -void Surface::Init(GdkDrawable *drawable_) { +void Surface::Init(SurfaceID sid) { + GdkDrawable *drawable_ = PDrawable(sid); Release(); drawable = drawable_; gc = gdk_gc_new(drawable_); @@ -280,18 +276,21 @@ void Surface::Init(GdkDrawable *drawable_) { void Surface::InitPixMap(int width, int height, Surface *surface_) { Release(); if (height > 0 && width > 0) - ppixmap = gdk_pixmap_new(surface_->drawable, width, height, -1); + ppixmap = gdk_pixmap_new(PDrawable(surface_->drawable), width, height, -1); drawable = ppixmap; - gc = gdk_gc_new(surface_->drawable); + gc = gdk_gc_new(PDrawable(surface_->drawable)); //gdk_gc_set_line_attributes(gc, 1, // GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL); createdGC = true; inited = true; } -void Surface::PenColour(Colour fore) { - if (gc) - gdk_gc_set_foreground(gc, &fore.co); +void Surface::PenColour(ColourAllocated fore) { + if (gc) { + GdkColor co; + co.pixel = fore.AsLong(); + gdk_gc_set_foreground(PGC(gc), &co); + } } int Surface::LogPixelsY() { @@ -309,15 +308,15 @@ void Surface::MoveTo(int x_, int y_) { } void Surface::LineTo(int x_, int y_) { - gdk_draw_line(drawable, gc, + gdk_draw_line(PDrawable(drawable), PGC(gc), x, y, x_, y_); x = x_; y = y_; } -void Surface::Polygon(Point *pts, int npts, Colour fore, - Colour back) { +void Surface::Polygon(Point *pts, int npts, ColourAllocated fore, + ColourAllocated back) { GdkPoint gpts[20]; if (npts < static_cast<int>((sizeof(gpts) / sizeof(gpts[0])))) { for (int i = 0;i < npts;i++) { @@ -325,32 +324,32 @@ void Surface::Polygon(Point *pts, int npts, Colour fore, gpts[i].y = pts[i].y; } PenColour(back); - gdk_draw_polygon(drawable, gc, 1, gpts, npts); + gdk_draw_polygon(PDrawable(drawable), PGC(gc), 1, gpts, npts); PenColour(fore); - gdk_draw_polygon(drawable, gc, 0, gpts, npts); + gdk_draw_polygon(PDrawable(drawable), PGC(gc), 0, gpts, npts); } } -void Surface::RectangleDraw(PRectangle rc, Colour fore, Colour back) { +void Surface::RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back) { if (gc && drawable) { PenColour(back); - gdk_draw_rectangle(drawable, gc, 1, + gdk_draw_rectangle(PDrawable(drawable), PGC(gc), 1, rc.left + 1, rc.top + 1, rc.right - rc.left - 2, rc.bottom - rc.top - 2); PenColour(fore); // The subtraction of 1 off the width and height here shouldn't be needed but // otherwise a different rectangle is drawn than would be done if the fill parameter == 1 - gdk_draw_rectangle(drawable, gc, 0, + gdk_draw_rectangle(PDrawable(drawable), PGC(gc), 0, rc.left, rc.top, rc.right - rc.left - 1, rc.bottom - rc.top - 1); } } -void Surface::FillRectangle(PRectangle rc, Colour back) { +void Surface::FillRectangle(PRectangle rc, ColourAllocated back) { PenColour(back); if (drawable) { - gdk_draw_rectangle(drawable, gc, 1, + gdk_draw_rectangle(PDrawable(drawable), PGC(gc), 1, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); } @@ -366,9 +365,9 @@ void Surface::FillRectangle(PRectangle rc, Surface &surfacePattern) { int widthx = (xTile + widthPat > rc.right) ? rc.right - xTile : widthPat; for (int yTile = rc.top; yTile < rc.bottom; yTile += heightPat) { int heighty = (yTile + heightPat > rc.bottom) ? rc.bottom - yTile : heightPat; - gdk_draw_pixmap(drawable, - gc, - surfacePattern.drawable, + gdk_draw_pixmap(PDrawable(drawable), + PGC(gc), + PDrawable(surfacePattern.drawable), 0, 0, xTile, yTile, widthx, heighty); @@ -377,11 +376,11 @@ void Surface::FillRectangle(PRectangle rc, Surface &surfacePattern) { } else { // Something is wrong so try to show anyway // Shows up black because colour not allocated - FillRectangle(rc, Colour(0xff, 0, 0)); + FillRectangle(rc, ColourAllocated(0)); } } -void Surface::RoundedRectangle(PRectangle rc, Colour fore, Colour back) { +void Surface::RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back) { if (((rc.right - rc.left) > 4) && ((rc.bottom - rc.top) > 4)) { // Approximate a round rect with some cut off corners Point pts[] = { @@ -400,16 +399,16 @@ void Surface::RoundedRectangle(PRectangle rc, Colour fore, Colour back) { } } -void Surface::Ellipse(PRectangle rc, Colour fore, Colour back) { +void Surface::Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back) { PenColour(back); - gdk_draw_arc(drawable, gc, 1, + gdk_draw_arc(PDrawable(drawable), PGC(gc), 1, rc.left + 1, rc.top + 1, rc.right - rc.left - 2, rc.bottom - rc.top - 2, 0, 32767); // The subtraction of 1 here is similar to the case for RectangleDraw PenColour(fore); - gdk_draw_arc(drawable, gc, 0, + gdk_draw_arc(PDrawable(drawable), PGC(gc), 0, rc.left, rc.top, rc.right - rc.left - 1, rc.bottom - rc.top - 1, 0, 32767); @@ -417,9 +416,9 @@ void Surface::Ellipse(PRectangle rc, Colour fore, Colour back) { void Surface::Copy(PRectangle rc, Point from, Surface &surfaceSource) { if (surfaceSource.drawable) { - gdk_draw_pixmap(drawable, - gc, - surfaceSource.drawable, + gdk_draw_pixmap(PDrawable(drawable), + PGC(gc), + PDrawable(surfaceSource.drawable), from.x, from.y, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); @@ -427,27 +426,27 @@ void Surface::Copy(PRectangle rc, Point from, Surface &surfaceSource) { } void Surface::DrawText(PRectangle rc, Font &font_, int ybase, const char *s, int len, - Colour fore, Colour back) { + ColourAllocated fore, ColourAllocated back) { FillRectangle(rc, back); PenColour(fore); if (gc && drawable) - gdk_draw_text(drawable, font_.id, gc, rc.left, ybase, s, len); + gdk_draw_text(PDrawable(drawable), PFont(font_), PGC(gc), rc.left, ybase, s, len); } // On GTK+, exactly same as DrawText void Surface::DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, - Colour fore, Colour back) { + ColourAllocated fore, ColourAllocated back) { FillRectangle(rc, back); PenColour(fore); if (gc && drawable) - gdk_draw_text(drawable, font_.id, gc, rc.left, ybase, s, len); + gdk_draw_text(PDrawable(drawable), PFont(font_), PGC(gc), rc.left, ybase, s, len); } void Surface::MeasureWidths(Font &font_, const char *s, int len, int *positions) { int totalWidth = 0; for (int i = 0;i < len;i++) { if (font_.id) { - int width = gdk_char_width(font_.id, s[i]); + int width = gdk_char_width(PFont(font_), s[i]); totalWidth += width; } else { totalWidth++; @@ -458,14 +457,14 @@ void Surface::MeasureWidths(Font &font_, const char *s, int len, int *positions) int Surface::WidthText(Font &font_, const char *s, int len) { if (font_.id) - return gdk_text_width(font_.id, s, len); + return gdk_text_width(PFont(font_), s, len); else return 1; } int Surface::WidthChar(Font &font_, char ch) { if (font_.id) - return gdk_char_width(font_.id, ch); + return gdk_char_width(PFont(font_), ch); else return 1; } @@ -489,7 +488,7 @@ int Surface::Ascent(Font &font_) { if (!font_.id) return 1; #ifdef FAST_WAY - return font_.id->ascent; + return PFont(font_)->ascent; #else gint lbearing; gint rbearing; @@ -507,7 +506,7 @@ int Surface::Descent(Font &font_) { if (!font_.id) return 1; #ifdef FAST_WAY - return font_.id->descent; + return PFont(font_)->descent; #else gint lbearing; gint rbearing; @@ -535,7 +534,7 @@ int Surface::Height(Font &font_) { int Surface::AverageCharWidth(Font &font_) { if (font_.id) - return gdk_char_width(font_.id, 'n'); + return gdk_char_width(PFont(font_), 'n'); else return 1; } @@ -548,7 +547,7 @@ int Surface::SetPalette(Palette *, bool) { void Surface::SetClip(PRectangle rc) { GdkRectangle area = {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top}; - gdk_gc_set_clip_rectangle(gc, &area); + gdk_gc_set_clip_rectangle(PGC(gc), &area); } void Surface::FlushCachedState() {} @@ -569,11 +568,11 @@ PRectangle Window::GetPosition() { // Before any size allocated pretend its 1000 wide so not scrolled PRectangle rc(0, 0, 1000, 1000); if (id) { - rc.left = id->allocation.x; - rc.top = id->allocation.y; - if (id->allocation.width > 20) { - rc.right = rc.left + id->allocation.width; - rc.bottom = rc.top + id->allocation.height; + rc.left = PWidget(id)->allocation.x; + rc.top = PWidget(id)->allocation.y; + if (PWidget(id)->allocation.width > 20) { + rc.right = rc.left + PWidget(id)->allocation.width; + rc.bottom = rc.top + PWidget(id)->allocation.height; } } return rc; @@ -587,7 +586,7 @@ void Window::SetPosition(PRectangle rc) { alloc.y = rc.top; alloc.width = rc.Width(); alloc.height = rc.Height(); - gtk_widget_size_allocate(id, &alloc); + gtk_widget_size_allocate(PWidget(id), &alloc); #else gtk_widget_set_uposition(id, rc.left, rc.top); gtk_widget_set_usize(id, rc.right - rc.left, rc.bottom - rc.top); @@ -597,9 +596,9 @@ void Window::SetPosition(PRectangle rc) { void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { int ox = 0; int oy = 0; - gdk_window_get_origin(relativeTo.id->window, &ox, &oy); + gdk_window_get_origin(PWidget(relativeTo.id)->window, &ox, &oy); - gtk_widget_set_uposition(id, rc.left + ox, rc.top + oy); + gtk_widget_set_uposition(PWidget(id), rc.left + ox, rc.top + oy); #if 0 GtkAllocation alloc; alloc.x = rc.left + ox; @@ -608,7 +607,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { alloc.height = rc.bottom - rc.top; gtk_widget_size_allocate(id, &alloc); #endif - gtk_widget_set_usize(id, rc.right - rc.left, rc.bottom - rc.top); + gtk_widget_set_usize(PWidget(id), rc.right - rc.left, rc.bottom - rc.top); } PRectangle Window::GetClientPosition() { @@ -618,18 +617,18 @@ PRectangle Window::GetClientPosition() { void Window::Show(bool show) { if (show) - gtk_widget_show(id); + gtk_widget_show(PWidget(id)); } void Window::InvalidateAll() { if (id) { - gtk_widget_queue_draw(id); + gtk_widget_queue_draw(PWidget(id)); } } void Window::InvalidateRectangle(PRectangle rc) { if (id) { - gtk_widget_queue_draw_area(id, + gtk_widget_queue_draw_area(PWidget(id), rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); } @@ -662,7 +661,7 @@ void Window::SetCursor(Cursor curs) { break; } - gdk_window_set_cursor(id->window, gdkCurs); + gdk_window_set_cursor(PWidget(id)->window, gdkCurs); gdk_cursor_destroy(gdkCurs); } @@ -694,7 +693,7 @@ static gboolean ButtonPress(GtkWidget *, GdkEventButton* ev, gpointer p) { void ListBox::Create(Window &, int) { id = gtk_window_new(GTK_WINDOW_POPUP); - GtkWidget* frame = gtk_frame_new(NULL); + GtkWidget *frame = gtk_frame_new(NULL); gtk_widget_show (frame); gtk_container_add(GTK_CONTAINER(GetID()), frame); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); @@ -704,33 +703,33 @@ void ListBox::Create(Window &, int) { gtk_container_set_border_width(GTK_CONTAINER(scroller), 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(frame), scroller); - gtk_widget_show(scroller); + gtk_container_add(GTK_CONTAINER(frame), PWidget(scroller)); + gtk_widget_show(PWidget(scroller)); list = gtk_clist_new(1); - gtk_widget_show(list); - gtk_container_add(GTK_CONTAINER(scroller), list); - gtk_clist_set_column_auto_resize(GTK_CLIST(list), 0, TRUE); - gtk_clist_set_selection_mode(GTK_CLIST(list), GTK_SELECTION_BROWSE); - gtk_signal_connect(GTK_OBJECT(list), "select_row", + gtk_widget_show(PWidget(list)); + gtk_container_add(GTK_CONTAINER(PWidget(scroller)), PWidget(list)); + gtk_clist_set_column_auto_resize(GTK_CLIST(PWidget(list)), 0, TRUE); + gtk_clist_set_selection_mode(GTK_CLIST(PWidget(list)), GTK_SELECTION_BROWSE); + gtk_signal_connect(GTK_OBJECT(PWidget(list)), "select_row", GTK_SIGNAL_FUNC(SelectionAC), ¤t); - gtk_signal_connect(GTK_OBJECT(list), "button_press_event", + gtk_signal_connect(GTK_OBJECT(PWidget(list)), "button_press_event", GTK_SIGNAL_FUNC(ButtonPress), this); - gtk_clist_set_shadow_type(GTK_CLIST(list), GTK_SHADOW_NONE); + gtk_clist_set_shadow_type(GTK_CLIST(PWidget(list)), GTK_SHADOW_NONE); - gtk_widget_realize(id); + gtk_widget_realize(PWidget(id)); } void ListBox::SetFont(Font &scint_font) { GtkStyle* style; - style = gtk_widget_get_style(GTK_WIDGET(list)); - if (!gdk_font_equal(style->font, scint_font.GetID())) { + style = gtk_widget_get_style(GTK_WIDGET(PWidget(list))); + if (!gdk_font_equal(style->font, PFont(scint_font))) { style = gtk_style_copy(style); gdk_font_unref(style->font); - style->font = scint_font.GetID(); + style->font = PFont(scint_font); gdk_font_ref(style->font); - gtk_widget_set_style(GTK_WIDGET(list), style); + gtk_widget_set_style(GTK_WIDGET(PWidget(list)), style); gtk_style_unref(style); } } @@ -757,9 +756,9 @@ PRectangle ListBox::GetDesiredRect() { // First calculate height of the clist for our desired visible row count otherwise it tries to expand to the total # of rows height = (rows * GTK_CLIST(list)->row_height + rows + 1 - + 2 * (list->style->klass->ythickness - + GTK_CONTAINER(list)->border_width)); - gtk_widget_set_usize(GTK_WIDGET(list), -1, height); + + 2 * (PWidget(list)->style->klass->ythickness + + GTK_CONTAINER(PWidget(list))->border_width)); + gtk_widget_set_usize(GTK_WIDGET(PWidget(list)), -1, height); // Get the size of the scroller because we set usize on the window gtk_widget_size_request(GTK_WIDGET(scroller), &req); @@ -845,15 +844,15 @@ void Menu::Destroy() { } void Menu::Show(Point pt, Window &) { - gtk_item_factory_popup(id, pt.x - 4, pt.y, 3, 0); + gtk_item_factory_popup(PMenu(id), pt.x - 4, pt.y, 3, 0); } -Colour Platform::Chrome() { - return Colour(0xe0, 0xe0, 0xe0); +ColourDesired Platform::Chrome() { + return ColourDesired(0xe0, 0xe0, 0xe0); } -Colour Platform::ChromeHighlight() { - return Colour(0xff, 0xff, 0xff); +ColourDesired Platform::ChromeHighlight() { + return ColourDesired(0xff, 0xff, 0xff); } const char *Platform::DefaultFont() { |