]> git.saurik.com Git - wxWidgets.git/blobdiff - demos/dbbrowse/doc.cpp
wxMediaCtrl patch from Ryan:
[wxWidgets.git] / demos / dbbrowse / doc.cpp
index a9ccf11ac87684c48db8687f559f0ed93256eeec..e0fd5ac3764778b6f07904d0da6b80c35891b186 100644 (file)
@@ -63,8 +63,8 @@ MainDoc::MainDoc()
 //----------------------------------------------------------------------------------------
 MainDoc::~MainDoc()
 {
-    p_TabArea->Show(FALSE);    // Deactivate the Window
-    p_PageArea->Show(FALSE);    // Deactivate the Window
+    p_TabArea->Show(false);    // Deactivate the Window
+    p_PageArea->Show(false);    // Deactivate the Window
 
     // ----------------------------------------------------------
     // -E-> The Tree Controls take to long to close : Why ??
@@ -86,11 +86,11 @@ bool MainDoc::OnNewDocument()
     wxStopWatch sw;
     //---------------------------------------------------------------------------------------
     if (!OnInitView())
-        return FALSE;
+        return false;
     p_PgmCtrl->OnPopulate();
     //---------------------------------------------------------------------------------------
     wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time());
-    return TRUE;
+    return true;
 }
 
 //----------------------------------------------------------------------------------------
@@ -102,7 +102,7 @@ bool MainDoc::OnInitView()
     // create "workplace" window
     //---------------------------------------------------------------------------------------
     p_TabArea = new wxTabbedWindow(); // Init the Pointer
-    p_TabArea->Create(p_Splitter, -1);
+    p_TabArea->Create(p_Splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE);
     //---------------------------------------------------------------------------------------
     p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize,
         wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
@@ -119,9 +119,9 @@ bool MainDoc::OnInitView()
     // now create "output" window
     //---------------------------------------------------------------------------------------
     p_PageArea = new wxPagedWindow();  // Init the Pointer
-    p_PageArea->Create(p_Splitter, -1);
+    p_PageArea->Create(p_Splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE);
     //---------------------------------------------------------------------------------------
-    p_LogWin = new wxTextCtrl(p_PageArea,-1,wxEmptyString,
+    p_LogWin = new wxTextCtrl(p_PageArea,wxID_ANY,wxEmptyString,
         wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE );
     p_LogWin->SetFont(* ft_Doc);
     // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
@@ -141,21 +141,23 @@ bool MainDoc::OnInitView()
     p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash);
     //---------------------------------------------------------------------------------------
     // if (!OnInitODBC())
-    //  return FALSE;
+    //  return false;
     OnInitODBC();
     //---------------------------------------------------------------------------------------
+#if wxUSE_STATUSBAR
     Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN);
     p_MainFrame->SetStatusText(Temp0, 0);
     wxLogMessage(Temp0);
-    return TRUE;
+#endif // wxUSE_STATUSBAR
+    return true;
 }
 
 //----------------------------------------------------------------------------------------
 bool MainDoc::OnInitODBC()
 {
-    wxChar Dsn[SQL_MAX_DSN_LENGTH + 1];
-    wxChar DsDesc[255]; // BJO20002501 instead of 512
-    Temp0 = _T("");
+    wxChar Dsn[SQL_MAX_DSN_LENGTH+1];
+    wxChar DsDesc[254+1]; // BJO20002501 instead of 512
+    Temp0 = wxEmptyString;
     i_DSN = 0;       // Counter
     int i;
     //---------------------------------------------------------------------------------------
@@ -163,49 +165,44 @@ bool MainDoc::OnInitODBC()
 
     if (!DbConnectInf.AllocHenv())
     {
-        return FALSE;
+        return false;
     }
 
     //---------------------------------------------------------------------------------------
-    const char sep = 3; // separator character used in string between DSN ans DsDesc
-    wxStringList s_SortDSNList, s_SortDsDescList;
+    const wxChar sep = 3; // separator character used in string between DSN and DsDesc
+    wxSortedArrayString s_SortDSNList, s_SortDsDescList;
     // BJO-20000127
     // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
     // The key will be removed after sorting
     wxString KeyString;
     //---------------------------------------------------------------------------------------
-    while(wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc)))
+    while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_MAX_DSN_LENGTH, DsDesc, 254))
     {
         i_DSN++;   // How many Dsn have we ?
         KeyString.Printf(_T("%s%c%s"),Dsn, sep, DsDesc);
         s_SortDSNList.Add(Dsn);
         s_SortDsDescList.Add(KeyString);
     }
-    s_SortDSNList.Sort();     //BJO
-    s_SortDsDescList.Sort();  //BJO
-    
-    wxChar ** s_SortDSN = s_SortDSNList.ListToArray();        //BJO
-    wxChar ** s_SortDsDesc = s_SortDsDescList.ListToArray();  //BJO
+
     //---------------------------------------------------------------------------------------
     // Allocate n ODBC-DSN objects to hold the information
+    // Allocate n wxDatabase objects to hold the column information
     p_DSN = new DSN[i_DSN];  //BJO
+    db_Br = new BrowserDB[i_DSN];
     for (i=0;i<i_DSN;i++)
     {
-        KeyString = s_SortDsDesc[i];
+        KeyString = s_SortDsDescList[i];
         KeyString = KeyString.AfterFirst(sep);
-        wxStrcpy(s_SortDsDesc[i],KeyString.c_str());
-        (p_DSN+i)->Dsn = s_SortDSN[i];
-        (p_DSN+i)->Drv = s_SortDsDesc[i];
-        (p_DSN+i)->Usr = _T("");
-        (p_DSN+i)->Pas = _T("");
+
+        // ODBC-DSN object
+        (p_DSN+i)->Dsn = s_SortDSNList[i];
+        (p_DSN+i)->Drv = KeyString;
+        (p_DSN+i)->Usr = wxEmptyString;
+        (p_DSN+i)->Pas = wxEmptyString;
         Temp0.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
         wxLogMessage(Temp0);
-    }
-    //---------------------------------------------------------------------------------------
-    // Allocate n wxDatabase objects to hold the column information
-    db_Br = new BrowserDB[i_DSN];
-    for (i=0;i<i_DSN;i++)
-    {
+
+        // wxDataBase object
         (db_Br+i)->p_LogWindow = p_LogWin;
         (db_Br+i)->ODBCSource  = (p_DSN+i)->Dsn;
         (db_Br+i)->UserName    = (p_DSN+i)->Usr;
@@ -216,8 +213,6 @@ bool MainDoc::OnInitODBC()
 
     DbConnectInf.FreeHenv();
 
-    delete [] s_SortDSN;
-    delete [] s_SortDsDesc;
     //---------------------------------------------------------------------------------------
     if (!i_DSN)
     {
@@ -225,10 +220,10 @@ bool MainDoc::OnInitODBC()
         message += _("           Program will exit!\n\n");
         message += _("                       Ciao");
         wxMessageBox( message,_("-E-> Fatal situation"));
-        return FALSE;
+        return false;
     }
     //---------------------------------------------------------------------------------------
-    return TRUE;
+    return true;
 }
 
 //----------------------------------------------------------------------------------------
@@ -238,18 +233,18 @@ bool MainDoc::OnChosenDSN(int Which)
     //---------------------------------------------------------------------------------------
     if (p_DBTree != NULL)
     {
-        p_TabArea->Show(FALSE);    // Deactivate the Window
+        p_TabArea->Show(false);    // Deactivate the Window
         p_TabArea->RemoveTab(p_DBTree->i_ViewNr);
-        p_TabArea->Show(TRUE);     // Activate the Window
-        OnChosenTbl(77,_T(""));
+        p_TabArea->Show(true);     // Activate the Window
+        OnChosenTbl(77,wxEmptyString);
     }
     //-------------------------
-    p_TabArea->Show(FALSE);    // Deactivate the Window
+    p_TabArea->Show(false);    // Deactivate the Window
     p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize,
         wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
     p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn,_T(" ? "));
     p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1;
-    p_TabArea->Show(TRUE);    // Deactivate the Window
+    p_TabArea->Show(true);    // Deactivate the Window
     p_DBTree->i_Which  = Which;
     p_DBTree->s_DSN    = (p_DSN+Which)->Dsn;
     p_DBTree->i_TabArt = 0;
@@ -258,7 +253,7 @@ bool MainDoc::OnChosenDSN(int Which)
     p_TabArea->SetActiveTab(p_DBTree->i_ViewNr);
     //---------------------------------------------------------------------------------------
     // wxLogMessage("OnChosenDSN(%d) - End",Which);
-    return TRUE;
+    return true;
 }
 
 //----------------------------------------------------------------------------------------
@@ -270,52 +265,52 @@ bool MainDoc::OnChosenTbl(int Tab,wxString Table)
     {
         if (p_DBGrid->i_TabArt == 0)
         {
-            p_TabArea->Show(FALSE);    // Deactivate the Window
+            p_TabArea->Show(false);    // Deactivate the Window
             p_TabArea->RemoveTab(p_DBGrid->i_ViewNr);
-            p_TabArea->Show(TRUE);     // Activate the Window
+            p_TabArea->Show(true);     // Activate the Window
         }
         if (p_DBGrid->i_TabArt == 1)
         {
-            p_PageArea->Show(FALSE);   // Deactivate the Window
+            p_PageArea->Show(false);   // Deactivate the Window
             p_PageArea->RemoveTab(p_DBGrid->i_ViewNr);
-            p_PageArea->Show(TRUE);    // Activate the Window
+            p_PageArea->Show(true);    // Activate the Window
         }
         p_DBGrid = NULL;
         delete p_DBGrid;
     }
     if (Tab == 77)               // Delete only
-        return TRUE;
+        return true;
     //-------------------------
     if (Tab == 0)  // Tabview
     {
-        p_TabArea->Show(FALSE);    // Deactivate the Window
+        p_TabArea->Show(false);    // Deactivate the Window
         p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
             wxSUNKEN_BORDER);
-        p_TabArea->AddTab(p_DBGrid, Table, _T(""));
+        p_TabArea->AddTab(p_DBGrid, Table, wxEmptyString);
         p_DBGrid->i_ViewNr = p_TabArea->GetTabCount()-1;
         p_DBGrid->pDoc       = this;
         p_DBGrid->db_Br      = db_Br;
         p_DBGrid->OnTableView(Table);
         p_TabArea->SetActiveTab(p_DBGrid->i_ViewNr);
-        p_TabArea->Show(TRUE);     // Activate the Window
+        p_TabArea->Show(true);     // Activate the Window
     }
     if (Tab == 1)  // Pageview
     {
-        p_PageArea->Show(FALSE);   // Deactivate the Window
+        p_PageArea->Show(false);   // Deactivate the Window
         p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
             wxSUNKEN_BORDER);
-        p_PageArea->AddTab(p_DBGrid, Table, _T(""));
+        p_PageArea->AddTab(p_DBGrid, Table, wxEmptyString);
         p_DBGrid->i_ViewNr = p_PageArea->GetTabCount()-1;
         p_DBGrid->pDoc       = this;
         p_DBGrid->db_Br      = db_Br;
         p_DBGrid->i_Which    = p_DBTree->i_Which;
-        p_PageArea->Show(TRUE);    // Activate the Window
+        p_PageArea->Show(true);    // Activate the Window
         p_DBGrid->OnTableView(Table);
         p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr);
     }
     p_DBGrid->i_TabArt = Tab;
     //--------------------------
-    return TRUE;;
+    return true;
 }
 
 //----------------------------------------------------------------------------------------