]> git.saurik.com Git - wxWidgets.git/commitdiff
Added background inheritance to wxUniv.
authorRobert Roebling <robert@roebling.de>
Fri, 26 Apr 2002 18:28:30 +0000 (18:28 +0000)
committerRobert Roebling <robert@roebling.de>
Fri, 26 Apr 2002 18:28:30 +0000 (18:28 +0000)
  Added sample to show this...

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15269 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/configure
samples/configure.in
samples/mobile/Makefile.in
samples/mobile/styles/Makefile.in [new file with mode: 0644]
samples/mobile/styles/marble.jpg [new file with mode: 0644]
samples/mobile/styles/styles.cpp [new file with mode: 0644]
samples/mobile/styles/styles.h [new file with mode: 0644]
src/univ/winuniv.cpp

index a28a31bb8b4c48f02b89050aff140d78f5558300..20c677220fd6baf06b5a65620eab3e10310fcdea 100755 (executable)
@@ -688,6 +688,7 @@ trap 'rm -fr `echo "
             minimal/Makefile
             mobile/Makefile
             mobile/wxedit/Makefile
+            mobile/styles/Makefile
             newgrid/Makefile
             notebook/Makefile
             png/Makefile
@@ -841,6 +842,7 @@ CONFIG_FILES=\${CONFIG_FILES-"Makefile
             minimal/Makefile
             mobile/Makefile
             mobile/wxedit/Makefile
+            mobile/styles/Makefile
             newgrid/Makefile
             notebook/Makefile
             png/Makefile
index a5af0b0fdf5db681746da0035e68f49cb1fe7b1e..773f64610708d9ad86a8fba49b53d1fd2a19d209 100644 (file)
@@ -56,6 +56,7 @@ AC_OUTPUT([
             minimal/Makefile
             mobile/Makefile
             mobile/wxedit/Makefile
+            mobile/styles/Makefile
             newgrid/Makefile
             notebook/Makefile
             png/Makefile
index 93cdb59e512d13256714911a00a24f9b04da9996..9f7a1991f42d0543f00cfbb90bcfc11e187820b0 100644 (file)
@@ -4,6 +4,8 @@
 
 all:
        cd wxedit && $(MAKE)
+       cd styles && $(MAKE)
 
 clean:
        cd wxedit && $(MAKE) clean
+       cd styles && $(MAKE) clean
diff --git a/samples/mobile/styles/Makefile.in b/samples/mobile/styles/Makefile.in
new file mode 100644 (file)
index 0000000..67ea3e5
--- /dev/null
@@ -0,0 +1,25 @@
+#
+# File:                makefile
+# Author:      Robert Roebling
+# Created:     2002
+# Updated:     
+# Copyright:   (c) 2002 Robert Roebling
+#
+# "%W% %G%"
+#
+# Makefile for wxedit
+
+top_srcdir = @top_srcdir@/..
+top_builddir = ../../..
+program_dir = samples/mobile/styles
+
+PROGRAM=styles
+
+DATAFILES=marble.jpg
+
+OBJECTS =$(PROGRAM).o
+DEPFILES=$(PROGRAM).d
+
+include ../../../src/makeprog.env
+
+@IF_GNU_MAKE@-include $(DEPFILES)
diff --git a/samples/mobile/styles/marble.jpg b/samples/mobile/styles/marble.jpg
new file mode 100644 (file)
index 0000000..e2904e1
Binary files /dev/null and b/samples/mobile/styles/marble.jpg differ
diff --git a/samples/mobile/styles/styles.cpp b/samples/mobile/styles/styles.cpp
new file mode 100644 (file)
index 0000000..f1023b2
--- /dev/null
@@ -0,0 +1,107 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        styles.cpp
+// Author:      Robert Roebling
+// Created:     04/07/02
+// Copyright:   
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+    #pragma implementation "styles.cpp"
+#endif
+
+// For compilers that support precompilation
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+// Include private headers
+#include "styles.h"
+
+//------------------------------------------------------------------------------
+// MyFrame
+//------------------------------------------------------------------------------
+
+BEGIN_EVENT_TABLE(MyFrame,wxFrame)
+    EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
+    EVT_MENU(ID_QUIT, MyFrame::OnQuit)
+    EVT_CLOSE(MyFrame::OnCloseWindow)
+END_EVENT_TABLE()
+
+MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
+    const wxPoint &position, const wxSize& size, long style ) :
+    wxFrame( parent, id, title, position, size, style )
+{
+    // Create menu and status bar.
+    CreateMyMenuBar();
+    CreateStatusBar(1);
+    SetStatusText( "Welcome to Styles!" );
+    
+    
+    wxImage image;
+    image.LoadFile( "marble.jpg", wxBITMAP_TYPE_JPEG );
+    
+    wxBitmap bitmap( image );
+    SetBackground( bitmap, 0, wxTILE );
+    
+    new wxStaticText( this, -1, "This is text", wxPoint( 20,50 ) );
+    
+    new wxCheckBox( this, -1, "This is a checkbox", wxPoint( 20,70 ) );
+}
+
+void MyFrame::CreateMyMenuBar()
+{
+    wxMenu *file_menu = new wxMenu;
+    file_menu->Append( ID_ABOUT, "About...", "Program info" );
+    file_menu->AppendSeparator();
+    file_menu->Append( ID_QUIT, "Quit...", "Quit program" );
+
+    wxMenuBar *menu_bar = new wxMenuBar();
+    menu_bar->Append( file_menu, "&File" );
+    
+    SetMenuBar( menu_bar );
+}
+
+void MyFrame::OnAbout( wxCommandEvent &event )
+{
+}
+
+void MyFrame::OnQuit( wxCommandEvent &event )
+{
+     Close( TRUE );
+}
+
+void MyFrame::OnCloseWindow( wxCloseEvent &event )
+{
+    Destroy();
+}
+
+//------------------------------------------------------------------------------
+// MyApp
+//------------------------------------------------------------------------------
+
+IMPLEMENT_APP(MyApp)
+
+MyApp::MyApp()
+{
+}
+
+bool MyApp::OnInit()
+{
+    wxInitAllImageHandlers();
+
+    SetVendorName("Free world");
+    SetAppName("Styles");
+    
+    MyFrame *frame = new MyFrame( NULL, -1, "Styles", wxPoint(20,20), wxSize(500,340) );
+    frame->Show( TRUE );
+    
+    return TRUE;
+}
+
+int MyApp::OnExit()
+{
+    return 0;
+}
+
diff --git a/samples/mobile/styles/styles.h b/samples/mobile/styles/styles.h
new file mode 100644 (file)
index 0000000..88b4944
--- /dev/null
@@ -0,0 +1,66 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        styles.h
+// Author:      Robert Roebling
+// Created:     04/07/02
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __styles_H__
+#define __styles_H__
+
+#ifdef __GNUG__
+    #pragma interface "styles.cpp"
+#endif
+
+// Include wxWindows' headers
+
+#ifndef WX_PRECOMP
+    #include <wx/wx.h>
+#endif
+
+//----------------------------------------------------------------------------
+//   constants
+//----------------------------------------------------------------------------
+
+#define ID_ABOUT    100
+#define ID_QUIT     204
+
+//----------------------------------------------------------------------------
+// MyFrame
+//----------------------------------------------------------------------------
+
+class MyFrame: public wxFrame
+{
+public:
+    // constructors and destructors
+    MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
+        const wxPoint& pos = wxDefaultPosition,
+        const wxSize& size = wxDefaultSize,
+        long style = wxDEFAULT_FRAME_STYLE );
+    
+private:
+    void CreateMyMenuBar();
+    
+private:
+    void OnAbout( wxCommandEvent &event );
+    void OnQuit( wxCommandEvent &event );
+    
+    void OnCloseWindow( wxCloseEvent &event );
+    
+private:
+    DECLARE_EVENT_TABLE()
+};
+
+//----------------------------------------------------------------------------
+// MyApp
+//----------------------------------------------------------------------------
+
+class MyApp: public wxApp
+{
+public:
+    MyApp();
+    
+    virtual bool OnInit();
+    virtual int OnExit();
+};
+
+#endif
index 966266581311918bea87bdb63b79e9e94639b561..f2b90368df6acb78ba879dde8507b7212fd8ddad 100644 (file)
@@ -180,39 +180,6 @@ const wxBitmap& wxWindow::GetBackgroundBitmap(int *alignment,
 // painting
 // ----------------------------------------------------------------------------
 
-// the event handler executed when the window background must be painted
-void wxWindow::OnErase(wxEraseEvent& event)
-{
-    if ( !m_renderer )
-    {
-        event.Skip();
-
-        return;
-    }
-    
-    DoDrawBackground(*event.GetDC());
-
-    // if we have both scrollbars, we also have a square in the corner between
-    // them which we must paint
-    if ( m_scrollbarVert && m_scrollbarHorz )
-    {
-        wxSize size = GetSize();
-        wxRect rectClient = GetClientRect(),
-               rectBorder = m_renderer->GetBorderDimensions(GetBorder());
-
-        wxRect rectCorner;
-        rectCorner.x = rectClient.GetRight() + 1;
-        rectCorner.y = rectClient.GetBottom() + 1;
-        rectCorner.SetRight(size.x - rectBorder.width);
-        rectCorner.SetBottom(size.y - rectBorder.height);
-
-        if ( GetUpdateRegion().Contains(rectCorner) )
-        {
-            m_renderer->DrawScrollCorner(*event.GetDC(), rectCorner);
-        }
-    }
-}
-
 // the event handlers executed when the window must be repainted
 void wxWindow::OnNcPaint(wxPaintEvent& event)
 {
@@ -263,47 +230,97 @@ void wxWindow::OnPaint(wxPaintEvent& event)
     }
 }
 
+// the event handler executed when the window background must be painted
+void wxWindow::OnErase(wxEraseEvent& event)
+{
+    if ( !m_renderer )
+    {
+        event.Skip();
+
+        return;
+    }
+    
+    DoDrawBackground(*event.GetDC());
+
+    // if we have both scrollbars, we also have a square in the corner between
+    // them which we must paint
+    if ( m_scrollbarVert && m_scrollbarHorz )
+    {
+        wxSize size = GetSize();
+        wxRect rectClient = GetClientRect(),
+               rectBorder = m_renderer->GetBorderDimensions(GetBorder());
+
+        wxRect rectCorner;
+        rectCorner.x = rectClient.GetRight() + 1;
+        rectCorner.y = rectClient.GetBottom() + 1;
+        rectCorner.SetRight(size.x - rectBorder.width);
+        rectCorner.SetBottom(size.y - rectBorder.height);
+
+        if ( GetUpdateRegion().Contains(rectCorner) )
+        {
+            m_renderer->DrawScrollCorner(*event.GetDC(), rectCorner);
+        }
+    }
+}
+
 bool wxWindow::DoDrawBackground(wxDC& dc)
 {
-    // FIXME: Leaving this code in leads to partial bg redraws
-    //        sometimes under MSW.
-    //        The same happens under X11 because it has a clear
-    //        region and an update region and these are sometimes
-    //        different. RR.
     wxRect rect;
-// #ifndef __WXMSW__
-#if 0
-    rect = GetUpdateRegion().GetBox();
-    if ( !rect.width && !rect.height )
-#endif
+    
+    wxSize size = GetSize();  // Why not GetClientSize() ?
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = size.x;
+    rect.height = size.y;
+    
+    if (HasTransparentBackground() && GetParent() && GetParent()->ProvidesBackground())
     {
-        wxSize size = GetSize();
-        rect.width = size.x;
-        rect.height = size.y;
+        wxASSERT( !IsTopLevel() );
+    
+        wxPoint pos = GetPosition();
+        
+        AdjustForParentClientOrigin( pos.x, pos.y, 0 );
+        
+        // Adjust DC logical origin
+        wxCoord x,y;
+        dc.GetLogicalOrigin( &x, &y );
+        x += pos.x;
+        y += pos.y;
+        dc.SetLogicalOrigin( x, y );
+        
+        // Adjust draw rect
+        rect.x = pos.x;
+        rect.y = pos.y;
+        
+        // Let parent draw the background
+        GetParent()->EraseBackground( dc, rect );
+    }
+    else
+    {
+        // Draw background ouselves
+         EraseBackground( dc, rect );
     }
+    
+    return TRUE;
+}
 
+void wxWindow::EraseBackground(wxDC& dc, const wxRect& rect)
+{
     if ( GetBackgroundBitmap().Ok() )
     {
-        // get the bitmap and the flags
+        // Get the bitmap and the flags
         int alignment;
         wxStretch stretch;
         wxBitmap bmp = GetBackgroundBitmap(&alignment, &stretch);
         wxControlRenderer::DrawBitmap(dc, bmp, rect, alignment, stretch);
     }
-    else // just fill it with bg colour if no bitmap
+    else 
     {
+        // Just fill it with bg colour if no bitmap
+    
         m_renderer->DrawBackground(dc, wxTHEME_BG_COLOUR(this),
                                    rect, GetStateFlags());
     }
-
-    return TRUE;
-}
-
-void wxWindow::EraseBackground(wxDC& dc, const wxRect& rect)
-{
-    // TODO: handle bg bitmaps here!
-    
-    m_renderer->DrawBackground(dc, wxTHEME_BG_COLOUR(this), rect, GetStateFlags());
 }
 
 void wxWindow::DoDrawBorder(wxDC& dc, const wxRect& rect)