diff options
Diffstat (limited to 'gtk/PlatGTK.cxx')
| -rw-r--r-- | gtk/PlatGTK.cxx | 163 | 
1 files changed, 80 insertions, 83 deletions
| diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 8fe55145a..ffb04d005 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -92,7 +92,7 @@ enum encodingType { singleByte, UTF8, dbcs};  struct LOGFONT {  	int size; -	bool bold; +	int weight;  	bool italic;  	int characterSet;  	char faceName[300]; @@ -443,10 +443,10 @@ static void GenerateFontSpecStrings(const char *fontName, int characterSet,  #endif -static void SetLogFont(LOGFONT &lf, const char *faceName, int characterSet, int size, bool bold, bool italic) { +static void SetLogFont(LOGFONT &lf, const char *faceName, int characterSet, float size, int weight, bool italic) {  	memset(&lf, 0, sizeof(lf));  	lf.size = size; -	lf.bold = bold; +	lf.weight = weight;  	lf.italic = italic;  	lf.characterSet = characterSet;  	strncpy(lf.faceName, faceName, sizeof(lf.faceName) - 1); @@ -457,13 +457,13 @@ static void SetLogFont(LOGFONT &lf, const char *faceName, int characterSet, int   * If one font is the same as another, its hash will be the same, but if the hash is the   * same then they may still be different.   */ -static int HashFont(const char *faceName, int characterSet, int size, bool bold, bool italic) { +static int HashFont(const FontParameters &fp) {  	return -	    size ^ -	    (characterSet << 10) ^ -	    (bold ? 0x10000000 : 0) ^ -	    (italic ? 0x20000000 : 0) ^ -	    faceName[0]; +	    static_cast<int>(fp.size+0.5) ^ +	    (fp.characterSet << 10) ^ +	    ((fp.weight / 100) << 12) ^ +	    (fp.italic ? 0x20000000 : 0) ^ +	    fp.faceName[0];  }  class FontCached : Font { @@ -471,35 +471,34 @@ class FontCached : Font {  	int usage;  	LOGFONT lf;  	int hash; -	FontCached(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_); +	FontCached(const FontParameters &fp);  	~FontCached() {} -	bool SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_); +	bool SameAs(const FontParameters &fp);  	virtual void Release(); -	static FontID CreateNewFont(const char *fontName, int characterSet, -	                            int size, bool bold, bool italic); +	static FontID CreateNewFont(const FontParameters &fp);  	static FontCached *first;  public: -	static FontID FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_); +	static FontID FindOrCreate(const FontParameters &fp);  	static void ReleaseId(FontID fid_);  };  FontCached *FontCached::first = 0; -FontCached::FontCached(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) : +FontCached::FontCached(const FontParameters &fp) :  next(0), usage(0), hash(0) { -	::SetLogFont(lf, faceName_, characterSet_, size_, bold_, italic_); -	hash = HashFont(faceName_, characterSet_, size_, bold_, italic_); -	fid = CreateNewFont(faceName_, characterSet_, size_, bold_, italic_); +	::SetLogFont(lf, fp.faceName, fp.characterSet, fp.size, fp.weight, fp.italic); +	hash = HashFont(fp); +	fid = CreateNewFont(fp);  	usage = 1;  } -bool FontCached::SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) { +bool FontCached::SameAs(const FontParameters &fp) {  	return -	    lf.size == size_ && -	    lf.bold == bold_ && -	    lf.italic == italic_ && -	    lf.characterSet == characterSet_ && -	    0 == strcmp(lf.faceName, faceName_); +	    lf.size == fp.size && +	    lf.weight == fp.weight && +	    lf.italic == fp.italic && +	    lf.characterSet == fp.characterSet && +	    0 == strcmp(lf.faceName, fp.faceName);  }  void FontCached::Release() { @@ -508,19 +507,19 @@ void FontCached::Release() {  	fid = 0;  } -FontID FontCached::FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) { +FontID FontCached::FindOrCreate(const FontParameters &fp) {  	FontID ret = 0;  	FontMutexLock(); -	int hashFind = HashFont(faceName_, characterSet_, size_, bold_, italic_); +	int hashFind = HashFont(fp);  	for (FontCached *cur = first; cur; cur = cur->next) {  		if ((cur->hash == hashFind) && -		        cur->SameAs(faceName_, characterSet_, size_, bold_, italic_)) { +		        cur->SameAs(fp)) {  			cur->usage++;  			ret = cur->fid;  		}  	}  	if (ret == 0) { -		FontCached *fc = new FontCached(faceName_, characterSet_, size_, bold_, italic_); +		FontCached *fc = new FontCached(fp);  		if (fc) {  			fc->next = first;  			first = fc; @@ -560,16 +559,15 @@ static GdkFont *LoadFontOrSet(const char *fontspec, int characterSet) {  }  #endif -FontID FontCached::CreateNewFont(const char *fontName, int characterSet, -                                 int size, bool bold, bool italic) { -	if (fontName[0] == '!') { +FontID FontCached::CreateNewFont(const FontParameters &fp) { +	if (fp.faceName[0] == '!') {  		PangoFontDescription *pfd = pango_font_description_new();  		if (pfd) { -			pango_font_description_set_family(pfd, fontName+1); -			pango_font_description_set_size(pfd, size * PANGO_SCALE); -			pango_font_description_set_weight(pfd, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); -			pango_font_description_set_style(pfd, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); -			return new FontHandle(pfd, characterSet); +			pango_font_description_set_family(pfd, fp.faceName+1); +			pango_font_description_set_size(pfd, pango_units_from_double(fp.size)); +			pango_font_description_set_weight(pfd, static_cast<PangoWeight>(fp.weight)); +			pango_font_description_set_style(pfd, fp.italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); +			return new FontHandle(pfd, fp.characterSet);  		}  	} @@ -636,7 +634,7 @@ FontID FontCached::CreateNewFont(const char *fontName, int characterSet,  			         sizeof(fontspec) - 1,  			         spec,  			         foundary, faceName, -			         bold ? "-bold" : "-medium", +			         (weight > 400) ? "-bold" : "-medium",  			         italic ? "-i" : "-r",  			         size * 10,  			         charset); @@ -652,7 +650,7 @@ FontID FontCached::CreateNewFont(const char *fontName, int characterSet,  				         sizeof(fontspec) - 1,  				         ",%s%s%s-o-*-*-*-%0d-*-*-*-*-%s",  				         foundary, faceName, -				         bold ? "-bold" : "-medium", +				         (weight > 400) ? "-bold" : "-medium",  				         size * 10,  				         charset);  			} @@ -686,7 +684,7 @@ FontID FontCached::CreateNewFont(const char *fontName, int characterSet,  	         sizeof(fontspec) - 1,  	         "%s%s%s%s-*-*-*-%0d-*-*-*-*-%s",  	         foundary, faceName, -	         bold ? "-bold" : "-medium", +	         (weight > 400) ? "-bold" : "-medium",  	         italic ? "-i" : "-r",  	         size * 10,  	         charset); @@ -697,7 +695,7 @@ FontID FontCached::CreateNewFont(const char *fontName, int characterSet,  		         sizeof(fontspec) - 1,  		         "%s%s%s%s-*-*-*-%0d-*-*-*-*-%s",  		         foundary, faceName, -		         bold ? "-bold" : "-medium", +		         (weight > 400) ? "-bold" : "-medium",  		         italic ? "-o" : "-r",  		         size * 10,  		         charset); @@ -727,10 +725,9 @@ Font::Font() : fid(0) {}  Font::~Font() {} -void Font::Create(const char *faceName, int characterSet, int size, -	bool bold, bool italic, int) { +void Font::Create(const FontParameters &fp) {  	Release(); -	fid = FontCached::FindOrCreate(faceName, characterSet, size, bold, italic); +	fid = FontCached::FindOrCreate(fp);  }  void Font::Release() { @@ -790,19 +787,19 @@ public:  	void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back);  	void Copy(PRectangle rc, Point from, Surface &surfaceSource); -	void DrawTextBase(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore); -	void DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); -	void DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); -	void DrawTextTransparent(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore); -	void MeasureWidths(Font &font_, const char *s, int len, int *positions); -	int WidthText(Font &font_, const char *s, int len); -	int WidthChar(Font &font_, char ch); -	int Ascent(Font &font_); -	int Descent(Font &font_); -	int InternalLeading(Font &font_); -	int ExternalLeading(Font &font_); -	int Height(Font &font_); -	int AverageCharWidth(Font &font_); +	void DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourAllocated fore); +	void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); +	void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); +	void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourAllocated fore); +	void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions); +	XYPOSITION WidthText(Font &font_, const char *s, int len); +	XYPOSITION WidthChar(Font &font_, char ch); +	XYPOSITION Ascent(Font &font_); +	XYPOSITION Descent(Font &font_); +	XYPOSITION InternalLeading(Font &font_); +	XYPOSITION ExternalLeading(Font &font_); +	XYPOSITION Height(Font &font_); +	XYPOSITION AverageCharWidth(Font &font_);  	int SetPalette(Palette *pal, bool inBackGround);  	void SetClip(PRectangle rc); @@ -1579,7 +1576,7 @@ static size_t UTF8CharLength(const char *s) {  const int maxLengthTextRun = 10000; -void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, int ybase, const char *s, int len, +void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len,                                   ColourAllocated fore) {  	PenColour(fore);  #ifdef USE_CAIRO @@ -1587,7 +1584,7 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, int ybase, const char  #else  	if (gc && drawable) {  #endif -		int xText = rc.left; +		XYPOSITION xText = rc.left;  		if (PFont(font_)->pfd) {  			char *utfForm = 0;  			if (et == UTF8) { @@ -1678,20 +1675,20 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, int ybase, const char  	}  } -void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, +void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len,                                   ColourAllocated fore, ColourAllocated back) {  	FillRectangle(rc, back);  	DrawTextBase(rc, font_, ybase, s, len, fore);  }  // On GTK+, exactly same as DrawTextNoClip -void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, +void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len,                                    ColourAllocated fore, ColourAllocated back) {  	FillRectangle(rc, back);  	DrawTextBase(rc, font_, ybase, s, len, fore);  } -void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, int ybase, const char *s, int len, +void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len,                                    ColourAllocated fore) {  	// Avoid drawing spaces in transparent mode  	for (int i=0;i<len;i++) { @@ -1708,9 +1705,9 @@ class ClusterIterator {  	int lenPositions;  public:  	bool finished; -	int positionStart; -	int position; -	int distance; +	XYPOSITION positionStart; +	XYPOSITION position; +	XYPOSITION distance;  	int curIndex;  	ClusterIterator(PangoLayout *layout, int len) : lenPositions(len), finished(false),  		positionStart(0), position(0), distance(0), curIndex(0) { @@ -1725,18 +1722,18 @@ public:  		positionStart = position;  		if (pango_layout_iter_next_cluster(iter)) {  			pango_layout_iter_get_cluster_extents(iter, NULL, &pos); -			position = PANGO_PIXELS(pos.x); +			position = pango_units_to_double(pos.x);  			curIndex = pango_layout_iter_get_index(iter);  		} else {  			finished = true; -			position = PANGO_PIXELS(pos.x + pos.width); +			position = pango_units_to_double(pos.x + pos.width);  			curIndex = lenPositions;  		}  		distance = position - positionStart;  	}  }; -void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, int *positions) { +void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) {  	if (font_.GetID()) {  		const int lenPositions = len;  		if (PFont(font_)->pfd) { @@ -1892,7 +1889,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, int *positi  	}  } -int SurfaceImpl::WidthText(Font &font_, const char *s, int len) { +XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) {  	if (font_.GetID()) {  		if (PFont(font_)->pfd) {  			char *utfForm = 0; @@ -1921,7 +1918,7 @@ int SurfaceImpl::WidthText(Font &font_, const char *s, int len) {  #endif  			pango_layout_line_get_extents(pangoLine, NULL, &pos);  			delete []utfForm; -			return PANGO_PIXELS(pos.width); +			return pango_units_to_double(pos.width);  		}  #ifndef DISABLE_GDK_FONT  		if (et == UTF8) { @@ -1941,7 +1938,7 @@ int SurfaceImpl::WidthText(Font &font_, const char *s, int len) {  	}  } -int SurfaceImpl::WidthChar(Font &font_, char ch) { +XYPOSITION SurfaceImpl::WidthChar(Font &font_, char ch) {  	if (font_.GetID()) {  		if (PFont(font_)->pfd) {  			return WidthText(font_, &ch, 1); @@ -1973,7 +1970,7 @@ const char sizeString[] = "`~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890"                            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";  #endif -int SurfaceImpl::Ascent(Font &font_) { +XYPOSITION SurfaceImpl::Ascent(Font &font_) {  	if (!(font_.GetID()))  		return 1;  #ifdef FAST_WAY @@ -1983,7 +1980,7 @@ int SurfaceImpl::Ascent(Font &font_) {  		PangoFontMetrics *metrics = pango_context_get_metrics(pcontext,  			PFont(font_)->pfd, pango_context_get_language(pcontext));  		PFont(font_)->ascent = -			PANGO_PIXELS(pango_font_metrics_get_ascent(metrics)); +			pango_units_to_double(pango_font_metrics_get_ascent(metrics));  		pango_font_metrics_unref(metrics);  		ascent = PFont(font_)->ascent;  	} @@ -2011,7 +2008,7 @@ int SurfaceImpl::Ascent(Font &font_) {  #endif  } -int SurfaceImpl::Descent(Font &font_) { +XYPOSITION SurfaceImpl::Descent(Font &font_) {  	if (!(font_.GetID()))  		return 1;  #ifdef FAST_WAY @@ -2019,7 +2016,7 @@ int SurfaceImpl::Descent(Font &font_) {  	if (PFont(font_)->pfd) {  		PangoFontMetrics *metrics = pango_context_get_metrics(pcontext,  			PFont(font_)->pfd, pango_context_get_language(pcontext)); -		int descent = PANGO_PIXELS(pango_font_metrics_get_descent(metrics)); +		int descent = pango_units_to_double(pango_font_metrics_get_descent(metrics));  		pango_font_metrics_unref(metrics);  		return descent;  	} @@ -2042,19 +2039,19 @@ int SurfaceImpl::Descent(Font &font_) {  #endif  } -int SurfaceImpl::InternalLeading(Font &) { +XYPOSITION SurfaceImpl::InternalLeading(Font &) {  	return 0;  } -int SurfaceImpl::ExternalLeading(Font &) { +XYPOSITION SurfaceImpl::ExternalLeading(Font &) {  	return 0;  } -int SurfaceImpl::Height(Font &font_) { +XYPOSITION SurfaceImpl::Height(Font &font_) {  	return Ascent(font_) + Descent(font_);  } -int SurfaceImpl::AverageCharWidth(Font &font_) { +XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) {  	return WidthChar(font_, 'n');  } @@ -2086,8 +2083,8 @@ void SurfaceImpl::SetDBCSMode(int codePage) {  		et = dbcs;  } -Surface *Surface::Allocate() { -	return new SurfaceImpl; +Surface *Surface::Allocate(int) { +	return new SurfaceImpl();  }  Window::~Window() {} @@ -2307,7 +2304,7 @@ public:  		}  	}  	virtual void SetFont(Font &font); -	virtual void Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_); +	virtual void Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_, int technology_);  	virtual void SetAverageCharWidth(int width);  	virtual void SetVisibleRows(int rows);  	virtual int GetVisibleRows() const; @@ -2396,7 +2393,7 @@ static void StyleSet(GtkWidget *w, GtkStyle*, void*) {  #endif  } -void ListBoxX::Create(Window &, int, Point, int, bool) { +void ListBoxX::Create(Window &, int, Point, int, bool, int) {  	wid = gtk_window_new(GTK_WINDOW_POPUP);  	GtkWidget *frame = gtk_frame_new(NULL); @@ -2838,7 +2835,7 @@ void Menu::Show(Point pt, Window &) {  		pt.y = screenHeight - requisition.height;  	}  	gtk_menu_popup(widget, NULL, NULL, MenuPositionFunc, -		reinterpret_cast<void *>((pt.y << 16) | pt.x), 0, +		reinterpret_cast<void *>((static_cast<int>(pt.y) << 16) | static_cast<int>(pt.x)), 0,  		gtk_get_current_event_time());  } | 
