From 30760ce7e58df02af3308cd7de8bd7694e791b8d Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 17 Oct 1999 10:22:45 +0000 Subject: [PATCH] Applied Diana's font patch II Made wxGLCanvas work again git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/scrolwin.tex | 15 +++++ include/wx/gtk/window.h | 13 +++-- include/wx/gtk1/window.h | 13 +++-- src/gtk/font.cpp | 9 ++- src/gtk/window.cpp | 65 +++++++++++++++++++-- src/gtk1/font.cpp | 9 ++- src/gtk1/window.cpp | 65 +++++++++++++++++++-- src/unix/utilsunx.cpp | 100 +++++++++++++++++++++++++++++++- utils/glcanvas/gtk/glcanvas.cpp | 22 +++++++ 9 files changed, 286 insertions(+), 25 deletions(-) diff --git a/docs/latex/wx/scrolwin.tex b/docs/latex/wx/scrolwin.tex index aae43b2b28..e8a364b900 100644 --- a/docs/latex/wx/scrolwin.tex +++ b/docs/latex/wx/scrolwin.tex @@ -14,12 +14,20 @@ If you don't wish to calculate your own scrolling, you must call PrepareDC when within OnDraw, to set the device origin for the device context according to the current scroll position. +A wxScrolledWindow will normally scroll itself and therefore its child windows as well. It +might however be desired to scroll a different window than itself: e.g. when designing a +spreadsheet, you'll normally only have to scroll the (usually white) cell area, whereas the +(usually grey) label area will scroll very differently. For this special purpose, you can +call \helpref{SetTargetWindow}{wxscrolledwindowsettargetwindow} which means that pressing +the scrollbars will scroll a different window. + Note that the underlying system knows nothing about scrolling coordinates, so that all system functions (mouse events, expose events, refresh calls etc) as well as the position of subwindows are relative to the "physical" origin of the scrolled window. If the user insert a child window at position (10,10) and scrolls the window down 100 pixels (moving the child window out of the visible area), the child window will report a position of (10,-90). + \wxheading{Derived from} \helpref{wxPanel}{wxpanel}\\ @@ -323,6 +331,13 @@ scroll steps may be variable according to the position in the document, it will necessary to derive a new class from wxWindow, overriding {\bf OnSize} and adjusting the scrollbars appropriately. +\membersection{wxScrolledWindow::SetTargetWindow}\label{wxscrolledwindowsettargetwindow} + +\func{void}{SetTargetWindow}{\param{wxWindow* }{window}} + +Call this function to tell wxScrolledWindow to perform the actually scrolling on +a different window (not on itself). + \membersection{wxScrolledWindow::ViewStart}\label{wxscrolledwindowviewstart} \constfunc{void}{ViewStart}{\param{int* }{x}, \param{int* }{ y}} diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 9f255ab617..9ec7f12639 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -173,17 +173,18 @@ public: float m_oldVerticalPos; // extra (wxGTK-specific) flags - bool m_needParent:1; /* ! wxFrame, wxDialog, wxNotebookPage ? */ - bool m_noExpose:1; /* wxGLCanvas has its own redrawing */ + bool m_needParent:1; /* ! wxFrame, wxDialog, wxNotebookPage ? */ + bool m_noExpose:1; /* wxGLCanvas has its own redrawing */ + bool m_nativeSizeEvent:1; /* wxGLCanvas sends wxSizeEvent upon "alloc_size" */ bool m_hasScrolling:1; bool m_isScrolling:1; bool m_hasVMT:1; bool m_sizeSet:1; bool m_resizing:1; - bool m_isStaticBox:1; /* faster than IS_KIND_OF */ - bool m_isRadioButton:1; /* faster than IS_KIND_OF */ - bool m_isFrame:1; /* faster than IS_KIND_OF */ - bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */ + bool m_isStaticBox:1; /* faster than IS_KIND_OF */ + bool m_isRadioButton:1; /* faster than IS_KIND_OF */ + bool m_isFrame:1; /* faster than IS_KIND_OF */ + bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */ // these are true if the style were set before the widget was realized // (typcally in the constructor) but the actual GTK style must not be set diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index 9f255ab617..9ec7f12639 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -173,17 +173,18 @@ public: float m_oldVerticalPos; // extra (wxGTK-specific) flags - bool m_needParent:1; /* ! wxFrame, wxDialog, wxNotebookPage ? */ - bool m_noExpose:1; /* wxGLCanvas has its own redrawing */ + bool m_needParent:1; /* ! wxFrame, wxDialog, wxNotebookPage ? */ + bool m_noExpose:1; /* wxGLCanvas has its own redrawing */ + bool m_nativeSizeEvent:1; /* wxGLCanvas sends wxSizeEvent upon "alloc_size" */ bool m_hasScrolling:1; bool m_isScrolling:1; bool m_hasVMT:1; bool m_sizeSet:1; bool m_resizing:1; - bool m_isStaticBox:1; /* faster than IS_KIND_OF */ - bool m_isRadioButton:1; /* faster than IS_KIND_OF */ - bool m_isFrame:1; /* faster than IS_KIND_OF */ - bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */ + bool m_isStaticBox:1; /* faster than IS_KIND_OF */ + bool m_isRadioButton:1; /* faster than IS_KIND_OF */ + bool m_isFrame:1; /* faster than IS_KIND_OF */ + bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */ // these are true if the style were set before the widget was realized // (typcally in the constructor) but the actual GTK style must not be set diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 72348fda2c..0457bda88e 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -170,7 +170,14 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) tmp = tn.GetNextToken().MakeUpper(); if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxBOLD; - + if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD; + if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxBOLD; + if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxBOLD; + if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxBOLD; + + if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT; + if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT; + tmp = tn.GetNextToken().MakeUpper(); if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC; if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 3dfbae632d..e1172d0fdc 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -57,6 +57,8 @@ some more information about what the wxWindow, which is the base class for all other window classes, does seems required as well. + I) + What does wxWindow do? It contains the common interface for the following jobs of its descendants: @@ -82,6 +84,8 @@ 5) A multitude of helper or extra methods for special purposes, such as Drag'n'Drop, managing validators etc. + 6) Display a border (sunken, raised, simple or none). + Normally one might expect, that one wxWindows window would always correspond to one GTK widget. Under GTK, there is no such allround widget that has all the functionality. Moreover, the GTK defines a client area as a different @@ -120,6 +124,55 @@ If the m_wxwindow field is set, then all input to this widget is inter- cepted and sent to the wxWindows class. If not, all input to the widget that gets pointed to by m_widget gets intercepted and sent to the class. + + II) + + The design of scrolling in wxWindows is markedly different from that offered + by the GTK itself and therefore we cannot simply take it as it is. In GTK, + clicking on a scrollbar belonging to scrolled window will inevitably move + the window. In wxWindows, the scrollbar will only emit an event, send this + to (normally) a wxScrolledWindow and that class will call ScrollWindow() + which actually move the window and its subchildren. Note that GtkMyFixed + memorizes how much it has been scrolled but that wxWindows forgets this + so that the two coordinates systems have to be kept in synch. This is done + in various places using the myfixed->xoffset and myfixed->yoffset values. + + III) + + Singularily the most broken code in GTK is the code that is supposes to + inform subwindows (child windows) about new positions. Very often, duplicate + events are sent without changes in size or position, equally often no + events are sent at all (All this is due to a bug in the GtkContainer code + which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores + GTK's own system and it simply waits for size events for toplevel windows + and then iterates down the respective size events to all window. This has + the disadvantage, that windows might get size events before the GTK widget + actually has the reported size. This doesn't normally pose any problem, but + the OpenGl drawing routines rely in correct behaviour. Therefore, I have + added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas, + i.e. the wxGLCanvas will emit a size event, when (and not before) the X11 + window that is used for OpenGl output really has that size (as reported by + GTK). + + IV) + + If someone at some point of time feels the immense desire to have a look at, + change or attempt to optimse the Refresh() logic, this person will need an + intimate understanding of what a "draw" and what an "expose" events are and + what there are used for, in particular when used in connection with GTK's + own windowless widgets. Beware. + + V) + + Cursors, too, have been a constant source of pleasure. The main difficulty + is that a GdkWindow inherits a cursor if the programmer sets a new cursor + for the parent. To prevent this from doing too much harm, I use idle time + to set the cursor over and over again, starting from the toplevel windows + and ending with the youngest generation (speaking of parent and child windows). + Also don't forget that cursors (like much else) are connected to GdkWindows, + not GtkWidgets and that the "window" field of a GtkWidget might very well + point to the GdkWindow of the parent widget (-> "window less widget") and + that the two obviously have very different meanings. */ @@ -1776,7 +1829,8 @@ void wxWindow::Init() m_isBeingDeleted = FALSE; m_noExpose = FALSE; - + m_nativeSizeEvent = FALSE; + m_hasScrolling = FALSE; m_isScrolling = FALSE; @@ -2184,9 +2238,12 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height ); */ - wxSizeEvent event( wxSize(m_width,m_height), GetId() ); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); + if (!m_nativeSizeEvent) + { + wxSizeEvent event( wxSize(m_width,m_height), GetId() ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + } m_resizing = FALSE; } diff --git a/src/gtk1/font.cpp b/src/gtk1/font.cpp index 72348fda2c..0457bda88e 100644 --- a/src/gtk1/font.cpp +++ b/src/gtk1/font.cpp @@ -170,7 +170,14 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) tmp = tn.GetNextToken().MakeUpper(); if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxBOLD; - + if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD; + if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxBOLD; + if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxBOLD; + if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxBOLD; + + if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT; + if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT; + tmp = tn.GetNextToken().MakeUpper(); if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC; if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC; diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 3dfbae632d..e1172d0fdc 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -57,6 +57,8 @@ some more information about what the wxWindow, which is the base class for all other window classes, does seems required as well. + I) + What does wxWindow do? It contains the common interface for the following jobs of its descendants: @@ -82,6 +84,8 @@ 5) A multitude of helper or extra methods for special purposes, such as Drag'n'Drop, managing validators etc. + 6) Display a border (sunken, raised, simple or none). + Normally one might expect, that one wxWindows window would always correspond to one GTK widget. Under GTK, there is no such allround widget that has all the functionality. Moreover, the GTK defines a client area as a different @@ -120,6 +124,55 @@ If the m_wxwindow field is set, then all input to this widget is inter- cepted and sent to the wxWindows class. If not, all input to the widget that gets pointed to by m_widget gets intercepted and sent to the class. + + II) + + The design of scrolling in wxWindows is markedly different from that offered + by the GTK itself and therefore we cannot simply take it as it is. In GTK, + clicking on a scrollbar belonging to scrolled window will inevitably move + the window. In wxWindows, the scrollbar will only emit an event, send this + to (normally) a wxScrolledWindow and that class will call ScrollWindow() + which actually move the window and its subchildren. Note that GtkMyFixed + memorizes how much it has been scrolled but that wxWindows forgets this + so that the two coordinates systems have to be kept in synch. This is done + in various places using the myfixed->xoffset and myfixed->yoffset values. + + III) + + Singularily the most broken code in GTK is the code that is supposes to + inform subwindows (child windows) about new positions. Very often, duplicate + events are sent without changes in size or position, equally often no + events are sent at all (All this is due to a bug in the GtkContainer code + which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores + GTK's own system and it simply waits for size events for toplevel windows + and then iterates down the respective size events to all window. This has + the disadvantage, that windows might get size events before the GTK widget + actually has the reported size. This doesn't normally pose any problem, but + the OpenGl drawing routines rely in correct behaviour. Therefore, I have + added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas, + i.e. the wxGLCanvas will emit a size event, when (and not before) the X11 + window that is used for OpenGl output really has that size (as reported by + GTK). + + IV) + + If someone at some point of time feels the immense desire to have a look at, + change or attempt to optimse the Refresh() logic, this person will need an + intimate understanding of what a "draw" and what an "expose" events are and + what there are used for, in particular when used in connection with GTK's + own windowless widgets. Beware. + + V) + + Cursors, too, have been a constant source of pleasure. The main difficulty + is that a GdkWindow inherits a cursor if the programmer sets a new cursor + for the parent. To prevent this from doing too much harm, I use idle time + to set the cursor over and over again, starting from the toplevel windows + and ending with the youngest generation (speaking of parent and child windows). + Also don't forget that cursors (like much else) are connected to GdkWindows, + not GtkWidgets and that the "window" field of a GtkWidget might very well + point to the GdkWindow of the parent widget (-> "window less widget") and + that the two obviously have very different meanings. */ @@ -1776,7 +1829,8 @@ void wxWindow::Init() m_isBeingDeleted = FALSE; m_noExpose = FALSE; - + m_nativeSizeEvent = FALSE; + m_hasScrolling = FALSE; m_isScrolling = FALSE; @@ -2184,9 +2238,12 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height ); */ - wxSizeEvent event( wxSize(m_width,m_height), GetId() ); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); + if (!m_nativeSizeEvent) + { + wxSizeEvent event( wxSize(m_width,m_height), GetId() ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + } m_resizing = FALSE; } diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index e031c31654..b87a2a4bb0 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -686,9 +686,96 @@ static wxNativeFont wxLoadQueryFont(int pointSize, wxString xweight; switch (weight) { - case wxBOLD: xweight = wxT("bold"); break; + case wxBOLD: + { + fontSpec.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("bold"); + break; + } + fontSpec.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("heavy"); + break; + } + fontSpec.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("extrabold"); + break; + } + fontSpec.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("demibold"); + break; + } + fontSpec.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("black"); + break; + } + fontSpec.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("ultrablack"); + break; + } + } + break; case wxLIGHT: - case wxNORMAL: xweight = wxT("medium"); break; + { + fontSpec.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("light"); + break; + } + fontSpec.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("thin"); + break; + } + } + break; + case wxNORMAL: + { + fontSpec.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("medium"); + break; + } + fontSpec.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("normal"); + break; + } + fontSpec.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"), + xfamily.c_str()); + if ( wxTestFontSpec(fontSpec) ) + { + xweight = wxT("regular"); + break; + } + xweight = wxT("*"); + } + break; default: xweight = wxT("*"); break; } @@ -829,12 +916,19 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize, underlined, facename, encoding ); } - // Bogus font + // Bogus font I if ( !font ) { font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL, underlined, facename, encoding ); } + + // Bogus font II + if ( !font ) + { + font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL, + underlined, wxEmptyString, encoding ); + } } return font; diff --git a/utils/glcanvas/gtk/glcanvas.cpp b/utils/glcanvas/gtk/glcanvas.cpp index a59ceaed95..b774feb1c4 100644 --- a/utils/glcanvas/gtk/glcanvas.cpp +++ b/utils/glcanvas/gtk/glcanvas.cpp @@ -186,6 +186,24 @@ gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxG rect->width, rect->height ); } +//----------------------------------------------------------------------------- +// "size_allocate" of m_wxwindow +//----------------------------------------------------------------------------- + +static void +gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxGLCanvas *win ) +{ + if (g_isIdle) + wxapp_install_idle_handler(); + + if (!win->m_hasVMT) + return; + + wxSizeEvent event( wxSize(win->m_width,win->m_height), win->GetId() ); + event.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( event ); +} + //--------------------------------------------------------------------------- // wxGlCanvas //--------------------------------------------------------------------------- @@ -228,6 +246,7 @@ bool wxGLCanvas::Create( wxWindow *parent, m_exposed = FALSE; m_noExpose = TRUE; + m_nativeSizeEvent = TRUE; if (!attribList) { @@ -296,6 +315,9 @@ bool wxGLCanvas::Create( wxWindow *parent, gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw", GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this ); + gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this ); + gtk_widget_pop_visual(); gtk_widget_pop_colormap(); -- 2.45.2