]> git.saurik.com Git - wxWidgets.git/commitdiff
image update
authorRobert Roebling <robert@roebling.de>
Tue, 12 Jan 1999 17:53:45 +0000 (17:53 +0000)
committerRobert Roebling <robert@roebling.de>
Tue, 12 Jan 1999 17:53:45 +0000 (17:53 +0000)
  listbox fix
  iODBC fixes

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

19 files changed:
docs/latex/wx/image.tex
include/wx/gtk/app.h
include/wx/gtk1/app.h
samples/db/dbtest.cpp
samples/db/dbtest.h
samples/image/image.cpp
src/common/dbtable.cpp
src/common/image.cpp
src/gtk/app.cpp
src/gtk/colour.cpp
src/gtk/listbox.cpp
src/gtk1/app.cpp
src/gtk1/colour.cpp
src/gtk1/listbox.cpp
src/iodbc/itrace.h
src/iodbc/misc.c
utils/glcanvas/samples/cube/cube.cpp
utils/glcanvas/samples/cube/cube.h
utils/glcanvas/samples/penguin/Makefile

index a3a15b60105e98bd9a1f73cf98fb40af9f0814ed..bbe5f315abba59603630040cdd25767161682fe4 100644 (file)
@@ -42,11 +42,11 @@ and forth without loss in that respect.
 
 Creates an image with the given width and height.
 
-\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxIMAGE\_TYPE\_PNG}}
+\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
 
 Loads an image from a file.
 
-\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxIMAGE\_TYPE\_PNG}}
+\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
 
 Loads an image from an input stream.
 
@@ -64,8 +64,8 @@ Loads an image from an input stream.
 
 \twocolwidtha{5cm}
 \begin{twocollist}
-\twocolitem{{\bf \indexit{wxIMAGE\_TYPE\_BMP}}}{Load a Windows bitmap file.}
-\twocolitem{{\bf \indexit{wxIMAGE\_TYPE\_PNG}}}{Load a PNG bitmap file.}
+\twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_BMP}}}{Load a Windows bitmap file.}
+\twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_PNG}}}{Load a PNG bitmap file.}
 \end{twocollist}
 
 The validity of these flags depends on the platform and wxWindows configuration.
@@ -111,10 +111,9 @@ This function is called by wxWindows on exit.
 Converts the image to a platform-specific bitmap object. This has to be done
 to actually display an image as you cannot draw an image directly on a window.
 The resulting bitmap will use the colour depth of the current system which entails
-that a (crude) colour reduction has to take place. Especially when converting
-to 8-bit (or even less) bitmaps, the routine is slow and will reduce the
-quality of the resulting bitmap. A proper set of colour reduction methods has
-not yet been written.
+that a (crude) colour reduction has to take place. When in 8-bit mode, this
+routine will use a color cube created on program start-up to look up colors.
+Still, the image quality won't be perfect for photo images.
 
 \membersection{wxImage::Create}\label{wximagecreate}
 
@@ -156,7 +155,7 @@ Finds the handler associated with the given image type.
 
 \docparam{extension}{The file extension, such as ``bmp".}
 
-\docparam{imageType}{The image type, such as wxIMAGE\_TYPE\_BMP.}
+\docparam{imageType}{The image type, such as wxBITMAP\_TYPE\_BMP.}
 
 \wxheading{Return value}
 
@@ -291,8 +290,8 @@ The meaning of {\it stream} data is determined by the {\it type} parameter.}
 
 \twocolwidtha{5cm}
 \begin{twocollist}
-\twocolitem{{\bf wxIMAGE\_TYPE\_BMP}}{Load a Windows image file.}
-\twocolitem{{\bf wxIMAGE\_TYPE\_PNG}}{Load a PNG image file.}
+\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Load a Windows image file.}
+\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Load a PNG image file.}
 \end{twocollist}
 
 The validity of these flags depends on the platform and wxWindows configuration.}
@@ -348,7 +347,7 @@ Saves a image in the given stream.
 
 \twocolwidtha{5cm}
 \begin{twocollist}
-\twocolitem{{\bf wxIMAGE\_TYPE\_PNG}}{Save a PNG image file.}
+\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Save a PNG image file.}
 \end{twocollist}
 
 The validity of these flags depends on the platform and wxWindows configuration
index 07d586dcb81f0d0665e8bab1f3478f9aa3533bc7..60ff70c26992f491c877958ea887f9cc46b0391e 100644 (file)
@@ -117,15 +117,16 @@ class wxApp: public wxEvtHandler
     bool ProcessIdle();
     void DeletePendingObjects();
 
-    bool          m_initialized;
-    bool          m_exitOnFrameDelete;
-    bool          m_wantDebugOutput;
-    wxWindow     *m_topWindow;
+    bool            m_initialized;
+    bool            m_exitOnFrameDelete;
+    bool            m_wantDebugOutput;
+    wxWindow       *m_topWindow;
     
-    gint          m_idleTag;
+    gint            m_idleTag;
+    unsigned char  *m_colorCube;
 
-    int         argc;
-    char      **argv;
+    int             argc;
+    char          **argv;
 
     static wxAppInitializerFunction m_appInitFn;
     
index 07d586dcb81f0d0665e8bab1f3478f9aa3533bc7..60ff70c26992f491c877958ea887f9cc46b0391e 100644 (file)
@@ -117,15 +117,16 @@ class wxApp: public wxEvtHandler
     bool ProcessIdle();
     void DeletePendingObjects();
 
-    bool          m_initialized;
-    bool          m_exitOnFrameDelete;
-    bool          m_wantDebugOutput;
-    wxWindow     *m_topWindow;
+    bool            m_initialized;
+    bool            m_exitOnFrameDelete;
+    bool            m_wantDebugOutput;
+    wxWindow       *m_topWindow;
     
-    gint          m_idleTag;
+    gint            m_idleTag;
+    unsigned char  *m_colorCube;
 
-    int         argc;
-    char      **argv;
+    int             argc;
+    char          **argv;
 
     static wxAppInitializerFunction m_appInitFn;
     
index 04fc85e12cb1a92ab20a91f56816b6b9200423c7..445fc8fb18821f0530b74fdb15c38c85eff331f5 100644 (file)
@@ -478,6 +478,11 @@ bool Ccontact::FetchByName(char *name)
  * An instance of Ccontact is created - "Contact" - which is used to hold the Ccontact
  * object that is currently being worked with.
  */
+BEGIN_EVENT_TABLE(CeditorDlg, wxPanel)
+    EVT_BUTTON(-1,  CeditorDlg::OnButton)
+END_EVENT_TABLE()
 CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455)
 {
        // Since the ::OnCommand() function is overridden, this prevents the widget
@@ -616,8 +621,12 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455)
        //
        // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s" 
        // to achieve a single row (in this case the first name in alphabetical order).
+       
+       Contact->whereStr.Printf("NAME = 'Robert'",Contact->tableName);
+/*
        Contact->whereStr.Printf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName);
-
+*/
+       
        // NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only
        Contact->where = (char*) (const char*) Contact->whereStr;
 
@@ -665,6 +674,12 @@ bool CeditorDlg::OnClose()
 }  // CeditorDlg::OnClose()
 
 
+void CeditorDlg::OnButton( wxCommandEvent &event )
+{
+  wxWindow *win = (wxWindow*) event.GetEventObject();
+  OnCommand( *win, event );
+}
+
 void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
 {
        wxString widgetName;
@@ -771,10 +786,12 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
                }
 
                // Previous record not available, retrieve first record in table
+               Contact->whereStr  = "NAME = 'Robert' ";
+/*
                Contact->whereStr  = "NAME = (SELECT MIN(NAME) FROM ";
                Contact->whereStr += Contact->tableName;
                Contact->whereStr += ")";
-
+*/
                Contact->where = (char*) (const char*) Contact->whereStr;
                if (!Contact->Query())
                {
@@ -825,8 +842,10 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
                if (strcmp(qryWhere, (const char*) Contact->qryWhereStr))
                {
                        Contact->orderBy                = "NAME";
+/*
                        Contact->whereStr               = "NAME = (SELECT MIN(NAME) FROM ";
                        Contact->whereStr               += CONTACT_TABLE_NAME;
+*/
                        // Append the query where string (if there is one)
                        Contact->qryWhereStr    = qryWhere;
                        if (strlen(qryWhere))
@@ -866,9 +885,12 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
 
                // Query the first record in the table
                Contact->orderBy                = "NAME";
+               Contact->whereStr               = "NAME = 'Robert' ";
+/*
                Contact->whereStr               = "NAME = (SELECT MIN(NAME) FROM ";
                Contact->whereStr               += CONTACT_TABLE_NAME;
                Contact->whereStr               += ")";
+*/
                Contact->where                  = (char*) (const char*) Contact->whereStr;
                if (!Contact->Query())
                {
@@ -1188,7 +1210,10 @@ bool CeditorDlg::GetNextRec()
 {
        wxString w;
 
+/*
        w  = "NAME = (SELECT MIN(NAME) FROM ";
+*/
+       w  = "NAME = (SELECT NAME FROM ";
        w += Contact->tableName;
        w += " WHERE NAME > '";
        w += Contact->Name;
@@ -1203,7 +1228,6 @@ bool CeditorDlg::GetNextRec()
        }
 
        w += ")";
-
        return(GetRec((char*) (const char*) w));
 
 }  // CeditorDlg::GetNextRec()
@@ -1458,6 +1482,10 @@ void CparameterDlg::FillDataSourceList()
 }  // CparameterDlg::CparameterDlg::FillDataSourceList()
 
 
+BEGIN_EVENT_TABLE(CqueryDlg, wxDialog)
+    EVT_BUTTON(-1,  CqueryDlg::OnButton)
+END_EVENT_TABLE()
 // CqueryDlg() constructor
 CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg) : wxDialog (parent, QUERY_DIALOG, "Query", wxPoint(-1, -1), wxSize(480, 360))
 {
@@ -1567,6 +1595,12 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA
 }  // CqueryDlg() constructor
 
 
+void CqueryDlg::OnButton( wxCommandEvent &event )
+{
+  wxWindow *win = (wxWindow*) event.GetEventObject();
+  OnCommand( *win, event );
+}
+
 void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
 {
        // Widget pointers won't be set when the dialog is constructed.
index d36cd14dec2cedf3b7eedbbecccf6845c2749589..0a58f99fe0d66179abe7a9563ccea2e7b1919e3b 100644 (file)
@@ -166,6 +166,7 @@ class CeditorDlg : public wxPanel
 
                CeditorDlg(wxWindow *parent);
                bool    OnClose(void);
+               void    OnButton( wxCommandEvent &event );
                void    OnCommand(wxWindow& win, wxCommandEvent& event);
                void    OnActivate(bool) {};  // necessary for hot keys
 
@@ -177,6 +178,8 @@ class CeditorDlg : public wxPanel
                bool    GetNextRec();
                bool    GetPrevRec();
                bool    GetRec(char *whereStr);
+               
+DECLARE_EVENT_TABLE()
 };  // CeditorDlg
 
 #define EDITOR_DIALOG                   199
@@ -336,6 +339,7 @@ class CqueryDlg : public wxDialog
 
                CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
 
+               void    OnButton( wxCommandEvent &event );
                void            OnCommand(wxWindow& win, wxCommandEvent& event);
                bool            OnClose();
                void            OnActivate(bool) {};  // necessary for hot keys
@@ -346,6 +350,7 @@ class CqueryDlg : public wxDialog
                void            ProcessCountBtn();
                bool            ValidateWhereClause();
 
+DECLARE_EVENT_TABLE()
 };  // CqueryDlg
 
 #define QUERY_DIALOG                    300
index 3546f1f1e67ddb855ab9915f583301be3295a495..12ca058f16ae5a77d90fb96ef821ddbf968a6191 100644 (file)
@@ -108,6 +108,9 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, c
   image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG );
   
   image.LoadFile( dir + wxString("horse.png"), wxBITMAP_TYPE_PNG );
+  image.SetRGB( 0, 0, 250, 0, 0 );
+  image.SetRGB( 1, 0, 100, 100, 100 );
+  image.SetRGB( 2, 0, 250, 250, 250 );
   my_horse = new wxBitmap( image.ConvertToBitmap() );
   
   image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG );
index 90f8e24054d16017a95b59786bb7ab51eb321afb..bf5c84377126726dc76db55e4a91d9546b8162c0 100644 (file)
@@ -353,7 +353,7 @@ bool wxTable::query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt
        // Make sure the cursor is closed first
        if (! CloseCursor(hstmt))
                return(FALSE);
-
+               
        // Execute the SQL SELECT statement
        if (SQLExecDirect(hstmt, (UCHAR FAR *) (queryType == DB_SELECT_STATEMENT ? pSqlStmt : sqlStmt),
                               SQL_NTS) != SQL_SUCCESS)
@@ -667,10 +667,16 @@ bool wxTable::CreateTable(void)
                 * (sqlstate = 42000) rather than an S0002. */
                 
                /* PostgreSQL 6.4.0 returns "08S01" or in written form
-                  "ERROR: Relation ... Does Not Exist, Robert Roebling */
+                  "ERROR: Relation ... Does Not Exist", Robert Roebling */
+               
+               /* MySQL 3.23.33b returns "S1000" or in written form
+                  "ERROR: Unknown table ...", Robert Roebling */
+                  
+               /* This routine is bullshit, Robert Roebling */
                
                pDb->GetNextError(henv, hdbc, hstmt);
                if (strcmp(pDb->sqlState, "S0002") && 
+                   strcmp(pDb->sqlState, "S1000") &&
                    strcmp(pDb->sqlState, "42000") &&
                    strcmp(pDb->sqlState, "08S01"))
                {
@@ -753,6 +759,14 @@ bool wxTable::CreateTable(void)
                        sprintf(s, "(%d)", colDefs[i].SzDataObj);
                        strcat(sqlStmt, s);
                }
+               
+#ifdef __WXGTK__
+               if (colDefs[i].KeyField)
+               {
+                       strcat(sqlStmt, " NOT NULL");
+               }
+#endif
+               
                needComma = TRUE;
        }
        // If there is a primary key defined, include it in the create statement
@@ -766,9 +780,15 @@ bool wxTable::CreateTable(void)
        }
        if (j)  // Found a keyfield
        {
+#ifndef __WXGTK__
+  /* MySQL goes out on this one. We also declare the relevant key NON NULL above */
                strcat(sqlStmt, ",CONSTRAINT ");
                strcat(sqlStmt, tableName);
                strcat(sqlStmt, "_PIDX PRIMARY KEY (");
+#else
+               strcat(sqlStmt, ", PRIMARY KEY (");
+#endif
+
                // List column name(s) of column(s) comprising the primary key
                for (i = j = 0; i < noCols; i++)
                {
@@ -782,8 +802,8 @@ bool wxTable::CreateTable(void)
           strcat(sqlStmt, ")");
        }
        // Append the closing parentheses for the create table statement
-   strcat(sqlStmt, ")");
-
+        strcat(sqlStmt, ")");
+   
        pDb->WriteSqlLog(sqlStmt);
 
 #ifdef _CONSOLE
@@ -830,10 +850,15 @@ bool wxTable::CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *p
        for (int i = 0; i < noIdxCols; i++)
        {
                strcat(sqlStmt, pIdxDefs[i].ColName);
+
+      /* Postgres doesnt cope with ASC */
+#ifndef __WXGTK__
                if (pIdxDefs[i].Ascending)
                        strcat(sqlStmt, " ASC");
                else
                        strcat(sqlStmt, " DESC");
+#endif
+
                if ((i + 1) < noIdxCols)
                        strcat(sqlStmt, ", ");
        }
index 1b8d810a207ca70f92f6ac2a4a512b9f038ecd06..ee8a4a1ec8ac1cba54e9285fe69ee99417400c08 100644 (file)
@@ -22,6 +22,7 @@
 #include "wx/bitmap.h"
 #include "wx/debug.h"
 #include "wx/log.h"
+#include "wx/app.h"
 #ifdef wxUSE_LIBPNG
 #include "../png/png.h"
 #endif
@@ -1383,21 +1384,29 @@ wxBitmap wxImage::ConvertToBitmap() const
            {
                case 8:
                {
-                   GdkColormap *cmap = gtk_widget_get_default_colormap();
-                    GdkColor *colors = cmap->colors;
-                    int max = 3 * (65536);
-                    int index = -1;
-
-                    for (int i = 0; i < cmap->size; i++)
-                    {
-                        int rdiff = (r << 8) - colors[i].red;
-                        int gdiff = (g << 8) - colors[i].green;
-                        int bdiff = (b << 8) - colors[i].blue;
-                        int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
-                        if (sum < max) { index = i; max = sum; }
+                    int pixel = -1;
+                   if (wxTheApp->m_colorCube)
+                   {
+                       pixel = wxTheApp->m_colorCube
+                           [ ((r & 0xf8) << 7) + ((g & 0xf8) << 2) + ((b & 0xf8) >> 3) ];                    
+                    }              
+                    else
+                   {
+                       GdkColormap *cmap = gtk_widget_get_default_colormap();
+                        GdkColor *colors = cmap->colors;
+                        int max = 3 * (65536);
+
+                        for (int i = 0; i < cmap->size; i++)
+                        {
+                            int rdiff = (r << 8) - colors[i].red;
+                            int gdiff = (g << 8) - colors[i].green;
+                            int bdiff = (b << 8) - colors[i].blue;
+                            int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
+                            if (sum < max) { pixel = i; max = sum; }
+                       }
                     }
 
-                   gdk_image_put_pixel( data_image, x, y, index );
+                   gdk_image_put_pixel( data_image, x, y, pixel );
 
                    break;
                }
index 74560c6d6ee27c1a11d6eed840824a4677b27a4d..65db013776399ddf9d43cd98331f71c5ea70c545 100644 (file)
@@ -161,17 +161,23 @@ wxApp::wxApp()
     m_idleTag = 0;
     m_topWindow = (wxWindow *) NULL;
     m_exitOnFrameDelete = TRUE;
+    m_colorCube = (unsigned char*) NULL;
     wxTheApp = this;
 }
 
 wxApp::~wxApp(void)
 {
     gtk_idle_remove( m_idleTag );
+    
+    if (m_colorCube) free(m_colorCube);
 }
 
 bool wxApp::InitVisual()
 {
-    return TRUE;
+    /* Nothing to do for 15, 16, 24, 32 bit displays */
+
+    GdkVisual *visual = gdk_visual_get_system();
+    if (visual->depth > 8) return TRUE;
 
     /* this initiates the standard palette as defined by GdkImlib
        in the GNOME libraries. it ensures that all GNOME applications
@@ -179,6 +185,7 @@ bool wxApp::InitVisual()
        can use several rather graphics-heavy applications at the
        same time */
     
+    /*
     GdkColormap *cmap = gdk_colormap_new( gdk_visual_get_system(), TRUE );
 
     for (int i = 0; i < 64; i++)
@@ -193,6 +200,41 @@ bool wxApp::InitVisual()
     }
        
     gtk_widget_set_default_colormap( cmap );
+    */
+    
+    /* initialize color cube for 8-bit color reduction dithering */
+    
+    GdkColormap *cmap = gtk_widget_get_default_colormap();
+    
+    m_colorCube = (unsigned char*)malloc(32 * 32 * 32);
+
+     for (int r = 0; r < 32; r++)
+     {
+       for (int g = 0; g < 32; g++)
+       {
+           for (int b = 0; b < 32; b++)
+           {
+               int rr = (r << 3) | (r >> 2);
+               int gg = (g << 3) | (g >> 2);
+               int bb = (b << 3) | (b >> 2);
+               
+                GdkColor *colors = cmap->colors;
+                int max = 3 * (65536);
+                int index = -1;
+
+                for (int i = 0; i < cmap->size; i++)
+                {
+                    int rdiff = ((rr << 8) - colors[i].red);
+                    int gdiff = ((gg << 8)- colors[i].green);
+                    int bdiff = ((bb << 8)- colors[i].blue);
+                    int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
+                    if (sum < max) { index = i; max = sum; }
+                }
+               
+               m_colorCube[ (r*1024) + (g*32) + b ] = index;
+           }
+       }
+    }
     
     return TRUE;
 }
index c9a925530156af4cb0b983bed9609ba1c904bb0c..a3292d450daafb1ba65df6aeddad52eacd5a3c63 100644 (file)
@@ -169,26 +169,26 @@ void wxColour::CalcPixel( GdkColormap *cmap )
     if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap)) return;
     M_COLDATA->FreeColour();
 
-  GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
-  if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
-      (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
-  {
-    GdkColor *colors = cmap->colors;
-    int max = 3 * (65536);
-    int index = -1;
-
-    for (int i = 0; i < cmap->size; i++)
+    GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
+    if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
+        (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
     {
-      int rdiff = (M_COLDATA->m_color.red - colors[i].red);
-      int gdiff = (M_COLDATA->m_color.green - colors[i].green);
-      int bdiff = (M_COLDATA->m_color.blue - colors[i].blue);
-      int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
-      if (sum < max) { index = i; max = sum; }
-    }
+        GdkColor *colors = cmap->colors;
+        int max = 3 * (65536);
+        int index = -1;
 
-    M_COLDATA->m_hasPixel = TRUE;
-    M_COLDATA->m_color.pixel = index;
-  }
+        for (int i = 0; i < cmap->size; i++)
+        {
+            int rdiff = (M_COLDATA->m_color.red - colors[i].red);
+            int gdiff = (M_COLDATA->m_color.green - colors[i].green);
+            int bdiff = (M_COLDATA->m_color.blue - colors[i].blue);
+            int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
+            if (sum < max) { index = i; max = sum; }
+        }
+
+        M_COLDATA->m_hasPixel = TRUE;
+        M_COLDATA->m_color.pixel = index;
+    }
     else
     { 
         M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
index fb6ef44edc696e5527b828096af9cc12610e1a4d..58c4bf34d62520f43f832f8f40de787d115ca92d 100644 (file)
@@ -239,13 +239,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
             gtk_signal_connect( GTK_OBJECT(list_item), "deselect",
               GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
 
-       if (m_hasCheckBoxes)
-       {
-            gtk_signal_connect( GTK_OBJECT(list_item), 
-                               "button_press_event",
-                                (GtkSignalFunc)gtk_listbox_button_press_callback, 
-                               (gpointer) this );
-       }
+        gtk_signal_connect( GTK_OBJECT(list_item), 
+                           "button_press_event",
+                            (GtkSignalFunc)gtk_listbox_button_press_callback, 
+                           (gpointer) this );
        
         gtk_signal_connect( GTK_OBJECT(list_item), 
                            "key_press_event",
@@ -306,13 +303,10 @@ void wxListBox::AppendCommon( const wxString &item )
 
     if (m_widgetStyle) ApplyWidgetStyle();
   
-    if (m_hasCheckBoxes)
-    {
-            gtk_signal_connect( GTK_OBJECT(list_item), 
-                               "button_press_event",
-                                (GtkSignalFunc)gtk_listbox_button_press_callback, 
-                               (gpointer) this );
-    }
+    gtk_signal_connect( GTK_OBJECT(list_item), 
+                       "button_press_event",
+                        (GtkSignalFunc)gtk_listbox_button_press_callback, 
+                       (gpointer) this );
     
     gtk_signal_connect( GTK_OBJECT(list_item), 
                        "key_press_event",
index 74560c6d6ee27c1a11d6eed840824a4677b27a4d..65db013776399ddf9d43cd98331f71c5ea70c545 100644 (file)
@@ -161,17 +161,23 @@ wxApp::wxApp()
     m_idleTag = 0;
     m_topWindow = (wxWindow *) NULL;
     m_exitOnFrameDelete = TRUE;
+    m_colorCube = (unsigned char*) NULL;
     wxTheApp = this;
 }
 
 wxApp::~wxApp(void)
 {
     gtk_idle_remove( m_idleTag );
+    
+    if (m_colorCube) free(m_colorCube);
 }
 
 bool wxApp::InitVisual()
 {
-    return TRUE;
+    /* Nothing to do for 15, 16, 24, 32 bit displays */
+
+    GdkVisual *visual = gdk_visual_get_system();
+    if (visual->depth > 8) return TRUE;
 
     /* this initiates the standard palette as defined by GdkImlib
        in the GNOME libraries. it ensures that all GNOME applications
@@ -179,6 +185,7 @@ bool wxApp::InitVisual()
        can use several rather graphics-heavy applications at the
        same time */
     
+    /*
     GdkColormap *cmap = gdk_colormap_new( gdk_visual_get_system(), TRUE );
 
     for (int i = 0; i < 64; i++)
@@ -193,6 +200,41 @@ bool wxApp::InitVisual()
     }
        
     gtk_widget_set_default_colormap( cmap );
+    */
+    
+    /* initialize color cube for 8-bit color reduction dithering */
+    
+    GdkColormap *cmap = gtk_widget_get_default_colormap();
+    
+    m_colorCube = (unsigned char*)malloc(32 * 32 * 32);
+
+     for (int r = 0; r < 32; r++)
+     {
+       for (int g = 0; g < 32; g++)
+       {
+           for (int b = 0; b < 32; b++)
+           {
+               int rr = (r << 3) | (r >> 2);
+               int gg = (g << 3) | (g >> 2);
+               int bb = (b << 3) | (b >> 2);
+               
+                GdkColor *colors = cmap->colors;
+                int max = 3 * (65536);
+                int index = -1;
+
+                for (int i = 0; i < cmap->size; i++)
+                {
+                    int rdiff = ((rr << 8) - colors[i].red);
+                    int gdiff = ((gg << 8)- colors[i].green);
+                    int bdiff = ((bb << 8)- colors[i].blue);
+                    int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
+                    if (sum < max) { index = i; max = sum; }
+                }
+               
+               m_colorCube[ (r*1024) + (g*32) + b ] = index;
+           }
+       }
+    }
     
     return TRUE;
 }
index c9a925530156af4cb0b983bed9609ba1c904bb0c..a3292d450daafb1ba65df6aeddad52eacd5a3c63 100644 (file)
@@ -169,26 +169,26 @@ void wxColour::CalcPixel( GdkColormap *cmap )
     if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap)) return;
     M_COLDATA->FreeColour();
 
-  GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
-  if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
-      (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
-  {
-    GdkColor *colors = cmap->colors;
-    int max = 3 * (65536);
-    int index = -1;
-
-    for (int i = 0; i < cmap->size; i++)
+    GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
+    if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
+        (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
     {
-      int rdiff = (M_COLDATA->m_color.red - colors[i].red);
-      int gdiff = (M_COLDATA->m_color.green - colors[i].green);
-      int bdiff = (M_COLDATA->m_color.blue - colors[i].blue);
-      int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
-      if (sum < max) { index = i; max = sum; }
-    }
+        GdkColor *colors = cmap->colors;
+        int max = 3 * (65536);
+        int index = -1;
 
-    M_COLDATA->m_hasPixel = TRUE;
-    M_COLDATA->m_color.pixel = index;
-  }
+        for (int i = 0; i < cmap->size; i++)
+        {
+            int rdiff = (M_COLDATA->m_color.red - colors[i].red);
+            int gdiff = (M_COLDATA->m_color.green - colors[i].green);
+            int bdiff = (M_COLDATA->m_color.blue - colors[i].blue);
+            int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
+            if (sum < max) { index = i; max = sum; }
+        }
+
+        M_COLDATA->m_hasPixel = TRUE;
+        M_COLDATA->m_color.pixel = index;
+    }
     else
     { 
         M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
index fb6ef44edc696e5527b828096af9cc12610e1a4d..58c4bf34d62520f43f832f8f40de787d115ca92d 100644 (file)
@@ -239,13 +239,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
             gtk_signal_connect( GTK_OBJECT(list_item), "deselect",
               GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
 
-       if (m_hasCheckBoxes)
-       {
-            gtk_signal_connect( GTK_OBJECT(list_item), 
-                               "button_press_event",
-                                (GtkSignalFunc)gtk_listbox_button_press_callback, 
-                               (gpointer) this );
-       }
+        gtk_signal_connect( GTK_OBJECT(list_item), 
+                           "button_press_event",
+                            (GtkSignalFunc)gtk_listbox_button_press_callback, 
+                           (gpointer) this );
        
         gtk_signal_connect( GTK_OBJECT(list_item), 
                            "key_press_event",
@@ -306,13 +303,10 @@ void wxListBox::AppendCommon( const wxString &item )
 
     if (m_widgetStyle) ApplyWidgetStyle();
   
-    if (m_hasCheckBoxes)
-    {
-            gtk_signal_connect( GTK_OBJECT(list_item), 
-                               "button_press_event",
-                                (GtkSignalFunc)gtk_listbox_button_press_callback, 
-                               (gpointer) this );
-    }
+    gtk_signal_connect( GTK_OBJECT(list_item), 
+                       "button_press_event",
+                        (GtkSignalFunc)gtk_listbox_button_press_callback, 
+                       (gpointer) this );
     
     gtk_signal_connect( GTK_OBJECT(list_item), 
                        "key_press_event",
index f932dcc746e2fe5f1c64f647cca524ca918cf728..1fa2f27075d7b0d7b62723ae0efca9298cb4e3b5 100644 (file)
@@ -7,6 +7,8 @@
 #  endif
 # endif
 
+#define NO_TRACE
+
 # define TRACE_TYPE_APP2DM      1
 # define TRACE_TYPE_DM2DRV      2
 # define TRACE_TYPE_DRV2DM      3
index 4535ecd892537d6cfc5f67df35e43597c86a2cbb..42b26a62b92a1b7fea43cafaa9eccaba190f8df7 100644 (file)
@@ -122,7 +122,7 @@ getinitfile(char* buf, int size)
         int     i, j;
         char*   ptr;
 
-        j = STRLEN("/odbc.ini") + 1;
+        j = STRLEN("/iodbc.ini") + 1;
 
         if( size < j )
         {
@@ -130,13 +130,13 @@ getinitfile(char* buf, int size)
         }
 
 #ifdef FIX_INI_FILE
-        sprintf( buf, "%s/odbc.ini", DIR_INI_FILE );
+        sprintf( buf, "%s/iodbc.ini", DIR_INI_FILE );
 #else
 #  ifdef OS2
         *buf = '\0';
-        if( NULL != getenv("ODBC_INI") )
+        if( NULL != getenv("IODBC_INI") )
         {
-                strcpy( buf, getenv("ODBC_INI") );
+                strcpy( buf, getenv("IODBC_INI") );
         }
         else
         {
@@ -151,7 +151,7 @@ getinitfile(char* buf, int size)
                 }
                 else
                 {
-                        strcpy( buf, "odbc.ini" );
+                        strcpy( buf, "iodbc.ini" );
                 }
 
         }
@@ -166,7 +166,7 @@ getinitfile(char* buf, int size)
                 return NULL;
         }
 
-        sprintf( buf + i, "/odbc.ini");
+        sprintf( buf + i, "/iodbc.ini");
 
         return buf;
 #    else
@@ -189,8 +189,8 @@ getinitfile(char* buf, int size)
                 return NULL;
         }
 
-        sprintf( buf, "%s%s", ptr, "/.odbc.ini");
-        /* i.e. searching ~/.odbc.ini */
+        sprintf( buf, "%s%s", ptr, "/.iodbc.ini");
+        /* i.e. searching ~/.iodbc.ini */
 #    endif
 #  endif
 #endif
index 675cdaba73d8b2c00da617baf5af5e9adc6bc496..73542bd7dbe710016eee5dc606cfb84672c9f138 100644 (file)
@@ -52,33 +52,12 @@ bool MyApp::OnInit(void)
 
   frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200));
 
-//  InitGL();
-
   // Show the frame
   frame->Show(TRUE);
   
   return TRUE;
 }
 
-void MyApp::InitGL(void)
-{
-    /* set viewing projection */
-    glMatrixMode(GL_PROJECTION);
-    glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
-
-    /* position viewer */
-    glMatrixMode(GL_MODELVIEW);
-    glTranslatef(0.0F, 0.0F, -2.0F);
-
-    /* position object */
-    glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
-    glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
-
-    glEnable(GL_DEPTH_TEST);
-    glEnable(GL_LIGHTING);
-    glEnable(GL_LIGHT0);
-}
-
 IMPLEMENT_APP(MyApp)
 
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
@@ -114,6 +93,7 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
     const wxPoint& pos, const wxSize& size, long style, const wxString& name):
   wxGLCanvas(parent, id, pos, size, style, name)
 {
+  m_init = FALSE;
 }
 
 TestGLCanvas::~TestGLCanvas(void)
@@ -126,11 +106,17 @@ void TestGLCanvas::OnPaint( wxPaintEvent& event )
     // OnPaint handlers must always create a wxPaintDC.
     wxPaintDC dc(this);
 
-    if ( !GetContext() )
-        return;
+    if (!GetContext()) return;
 
     SetCurrent();
 
+    /* init OpenGL once, but after SetCurrent */
+    if (!m_init)
+    {
+       InitGL();
+       m_init = TRUE;
+    }
+
     /* clear color and depth buffers */
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
@@ -181,3 +167,22 @@ void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)
     // Do nothing, to avoid flashing.
 }
 
+void TestGLCanvas::InitGL(void)
+{
+    /* set viewing projection */
+    glMatrixMode(GL_PROJECTION);
+    glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
+
+    /* position viewer */
+    glMatrixMode(GL_MODELVIEW);
+    glTranslatef(0.0F, 0.0F, -2.0F);
+
+    /* position object */
+    glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
+    glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
+
+    glEnable(GL_DEPTH_TEST);
+    glEnable(GL_LIGHTING);
+    glEnable(GL_LIGHT0);
+}
+
index f3dc44ac49f3ff24082217558878e9c17705a5d2..5ae1fd9f7f19d4c50da4ce429fd63a4ea7e81c9f 100644 (file)
@@ -19,7 +19,6 @@ class MyApp: public wxApp
 {
 public:
     bool OnInit(void);
-    void InitGL(void);
 };
 
 // Define a new frame type
@@ -48,6 +47,11 @@ class TestGLCanvas: public wxGLCanvas
    void OnPaint(wxPaintEvent& event);
    void OnSize(wxSizeEvent& event);
    void OnEraseBackground(wxEraseEvent& event);
+   void InitGL(void);
+   
+ private:
+   bool m_init;
 
 DECLARE_EVENT_TABLE()
 };
index fd005b951d8412b23f2597d337e88543ec0984c2..013c6f088466d5e7b0a1bdfa0052c4bd318d6f67 100644 (file)
@@ -20,4 +20,4 @@ glcanvas.o: ../../src/glcanvas.cpp
        $(CPP) `wx-config --cflags` `gtk-config --cflags` -I../../src -c ../../src/glcanvas.cpp
 
 clean: 
-       rm -f *.o penguin
+       rm -f *.o Penguin