From 645889ad25eaa6e332463a6105a1dfd63d917d36 Mon Sep 17 00:00:00 2001 From: George Tasker Date: Thu, 1 Feb 2001 20:24:44 +0000 Subject: [PATCH] Huge cleanup of the code. Reformatting, spelling fixes, standardizing on wxWindows conventions, etc. Changed the couple lines of code required to work with checkins of the new ODBC classes that use wxStrings. Fixed a ton of memory leaks Demo still crashes on exit though - this problem has exited for nearly a year though. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9256 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- demos/dbbrowse/browsedb.cpp | 789 +++++++-------- demos/dbbrowse/browsedb.h | 111 +-- demos/dbbrowse/dbbrowse.cpp | 491 +++++----- demos/dbbrowse/dbbrowse.h | 43 +- demos/dbbrowse/dbgrid.cpp | 573 +++++------ demos/dbbrowse/dbgrid.h | 86 +- demos/dbbrowse/dbtree.cpp | 652 +++++++------ demos/dbbrowse/dbtree.h | 120 +-- demos/dbbrowse/dlguser.cpp | 183 ++-- demos/dbbrowse/dlguser.h | 27 +- demos/dbbrowse/doc.cpp | 507 +++++----- demos/dbbrowse/doc.h | 117 +-- demos/dbbrowse/pgmctrl.cpp | 406 ++++---- demos/dbbrowse/pgmctrl.h | 96 +- demos/dbbrowse/std.h | 2 +- demos/dbbrowse/tabpgwin.cpp | 1807 ++++++++++++++++++----------------- demos/dbbrowse/tabpgwin.h | 12 +- 17 files changed, 3100 insertions(+), 2922 deletions(-) diff --git a/demos/dbbrowse/browsedb.cpp b/demos/dbbrowse/browsedb.cpp index 0aced0e3ef..ef321bf2a6 100644 --- a/demos/dbbrowse/browsedb.cpp +++ b/demos/dbbrowse/browsedb.cpp @@ -1,12 +1,12 @@ //---------------------------------------------------------------------------------------- -// Name: BrowserDB.h,cpp -// Purpose: a wxDB class -// Author: Mark Johnson, mj10777@gmx.net +// Name: BrowserDB.h,cpp +// Purpose: a wxDB class +// Author: Mark Johnson, mj10777@gmx.net // Modified by: -// Created: 19991127.mj10777 -// Copyright: (c) Mark Johnson -// Licence: wxWindows license -// RCS-ID: $Id$ +// Created: 19991127.mj10777 +// Copyright: (c) Mark Johnson +// Licence: wxWindows license +// RCS-ID: $Id$ //---------------------------------------------------------------------------------------- //-- 1) //---------------------------------------------------------------------------------------- @@ -32,441 +32,458 @@ //---------------------------------------------------------------------------------------- // Global structure for holding ODBC connection information // - darf nur einmal im Projekte definiert werden ?? Extra Databasse Klasse ? -wxDbConnectInf ConnectInf; // Für DBase +wxDbConnectInf ConnectInf; // Für DBase + //---------------------------------------------------------------------------------------- -extern WXDLLEXPORT_DATA(wxDbList*) PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */ +extern WXDLLEXPORT_DATA(wxDbList*) PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */ + //---------------------------------------------------------------------------------------- char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) { - static wxString msg; - wxString tStr; - if (ErrFile || ErrLine) - { - msg += "File: "; - msg += ErrFile; - msg += " Line: "; - tStr.Printf("%d",ErrLine); - msg += tStr.GetData(); - // msg += "\n"; - } - msg.Append ("\nODBC errors:\n"); - // msg += "\n"; - /* Scan through each database connection displaying - * any ODBC errors that have occured. */ - wxDbList *pDbList; - for (pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext) - { - // Skip over any free connections - if (pDbList->Free) - continue; - // Display errors for this connection - for (int i = 0; i < DB_MAX_ERROR_HISTORY; i++) - { - if (pDbList->PtrDb->errorList[i]) - { - msg.Append(pDbList->PtrDb->errorList[i]); - if (strcmp(pDbList->PtrDb->errorList[i],"") != 0) - msg.Append("\n"); - } - } - } - msg += "\n"; - return (char*) (const char*) msg; + static wxString msg; + wxString tStr; + if (ErrFile || ErrLine) + { + msg += "File: "; + msg += ErrFile; + msg += " Line: "; + tStr.Printf("%d",ErrLine); + msg += tStr.GetData(); + // msg += "\n"; + } + msg.Append ("\nODBC errors:\n"); + // msg += "\n"; + /* Scan through each database connection displaying + * any ODBC errors that have occured. */ + wxDbList *pDbList; + for (pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext) + { + // Skip over any free connections + if (pDbList->Free) + continue; + // Display errors for this connection + for (int i = 0; i < DB_MAX_ERROR_HISTORY; i++) + { + if (pDbList->PtrDb->errorList[i]) + { + msg.Append(pDbList->PtrDb->errorList[i]); + if (strcmp(pDbList->PtrDb->errorList[i],"") != 0) + msg.Append("\n"); + } + } + } + msg += "\n"; + return (char*) (const char*) msg; } // GetExtendedDBErrorMsg //---------------------------------------------------------------------------------------- BrowserDB::BrowserDB() { - Zeiger_auf_NULL(0); - ODBCSource = ""; // ODBC data source name (created with ODBC Administrator under Win95/NT) - UserName = ""; // database username - must already exist in the data source - Password = ""; // password database username - OnFillSqlTyp(); - OnFilldbTyp(); + Zeiger_auf_NULL(0); + ODBCSource = ""; // ODBC data source name (created with ODBC Administrator under Win95/NT) + UserName = ""; // database username - must already exist in the data source + Password = ""; // password database username + OnFillSqlTyp(); + OnFilldbTyp(); } // BrowserDB Constructor + //---------------------------------------------------------------------------------------- BrowserDB::~BrowserDB() { - Zeiger_auf_NULL(1); // Clean up Tables and Databases (Commit, Close und delete) + Zeiger_auf_NULL(1); // Clean up Tables and Databases (Commit, Close und delete) } // BrowserDB destructor + //---------------------------------------------------------------------------------------- bool BrowserDB::Initialize(int Quiet) { - if (!OnStartDB(Quiet)) - { - wxLogMessage(_("\n\n-E-> BrowserDB::OnStartDB(%s) : Failed ! "),ODBCSource.c_str()); - return FALSE; - } - return TRUE; + if (!OnStartDB(Quiet)) + { + wxLogMessage(_("\n\n-E-> BrowserDB::OnStartDB(%s) : Failed ! "),ODBCSource.c_str()); + return FALSE; + } + return TRUE; } // BrowserDB:Initialize + //---------------------------------------------------------------------------------------- bool BrowserDB::OnStartDB(int Quiet) { - wxStopWatch sw; - if (!Quiet) - wxLogMessage(_("\n-I-> BrowserDB::OnStartDB(%s) : Begin "),ODBCSource.c_str()); - if (db_BrowserDB != NULL) - { - if (!Quiet) - wxLogMessage(_("\n-I-> BrowserDB::OnStartDB() : DB is allready open.")); - return TRUE; - } - // Initialize the ODBC Environment for Database Operations - if (SQLAllocEnv(&ConnectInf.Henv) != SQL_SUCCESS) - { - if (!Quiet) - wxLogMessage(_("\n-E-> BrowserDB::OnStartDB() : DB CONNECTION ERROR : A problem occured while trying to get a connection to the data source")); - return FALSE; - } - //--------------------------------------------------------------------------------------- - // Connect to datasource - //--------------------------------------------------------------------------------------- - DlgUser *p_Dlg; - p_Dlg = new DlgUser(pDoc->p_MainFrame,pDoc,""); - p_Dlg->s_DSN = ODBCSource; - p_Dlg->s_User = UserName; - p_Dlg->s_Password = Password; - p_Dlg->OnInit(); - p_Dlg->Fit(); - - bool OK = FALSE; - if (p_Dlg->ShowModal() == wxID_OK) - { - (pDoc->p_DSN+i_Which)->Usr = p_Dlg->s_User; - (pDoc->p_DSN+i_Which)->Pas = p_Dlg->s_Password; - UserName = p_Dlg->s_User; - Password = p_Dlg->s_Password; - OK = TRUE; - } - delete p_Dlg; - if (OK) - { - //-------------------------------------------------------------------------------------- - strcpy(ConnectInf.Dsn, ODBCSource); // ODBC data source name (created with ODBC Administrator under Win95/NT) - strcpy(ConnectInf.Uid, UserName); // database username - must already exist in the data source - strcpy(ConnectInf.AuthStr, Password); // password database username - db_BrowserDB = wxDbGetConnection(&ConnectInf); - // wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str()); - if (db_BrowserDB == NULL) - { - strcpy(ConnectInf.Dsn, ""); - strcpy(ConnectInf.Uid, ""); - strcpy(ConnectInf.AuthStr, ""); - if (!Quiet) - { - wxLogMessage(_("\n-E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the table prior to making a connection\n(using tools provided by the database manufacturer)")); - wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time()); - } - return FALSE; - } - //-------------------------------------------------------------------------------------- - if (!Quiet) - { - Temp1 = db_BrowserDB->GetDatabaseName(); - Temp2 = db_BrowserDB->GetDataSource(); - wxLogMessage(_("-I-> BrowserDB::OnGetDataSourceODBC() - DatabaseName(%s) ; DataSource(%s)"),Temp1.c_str(),Temp2.c_str()); - wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time()); - } - return TRUE; - } else return FALSE; + wxStopWatch sw; + if (!Quiet) + wxLogMessage(_("\n-I-> BrowserDB::OnStartDB(%s) : Begin "),ODBCSource.c_str()); + if (db_BrowserDB != NULL) + { + if (!Quiet) + wxLogMessage(_("\n-I-> BrowserDB::OnStartDB() : DB is allready open.")); + return TRUE; + } + // Initialize the ODBC Environment for Database Operations + if (SQLAllocEnv(&ConnectInf.Henv) != SQL_SUCCESS) + { + if (!Quiet) + wxLogMessage(_("\n-E-> BrowserDB::OnStartDB() : DB CONNECTION ERROR : A problem occured while trying to get a connection to the data source")); + return FALSE; + } + //--------------------------------------------------------------------------------------- + // Connect to datasource + //--------------------------------------------------------------------------------------- + DlgUser *p_Dlg; + p_Dlg = new DlgUser(pDoc->p_MainFrame,pDoc,""); + p_Dlg->s_DSN = ODBCSource; + p_Dlg->s_User = UserName; + p_Dlg->s_Password = Password; + p_Dlg->OnInit(); + p_Dlg->Fit(); + + bool OK = FALSE; + if (p_Dlg->ShowModal() == wxID_OK) + { + (pDoc->p_DSN+i_Which)->Usr = p_Dlg->s_User; + (pDoc->p_DSN+i_Which)->Pas = p_Dlg->s_Password; + UserName = p_Dlg->s_User; + Password = p_Dlg->s_Password; + OK = TRUE; + } + delete p_Dlg; + if (OK) + { + //-------------------------------------------------------------------------------------- + ConnectInf.Dsn = ODBCSource; // ODBC data source name (created with ODBC Administrator under Win95/NT) + ConnectInf.Uid = UserName; // database username - must already exist in the data source + ConnectInf.AuthStr= Password; // password database username + db_BrowserDB = wxDbGetConnection(&ConnectInf); + // wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str()); + if (db_BrowserDB == NULL) + { + ConnectInf.Dsn = ""; + ConnectInf.Uid = ""; + ConnectInf.AuthStr = ""; + if (!Quiet) + { + wxLogMessage(_("\n-E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the table prior to making a connection\n(using tools provided by the database manufacturer)")); + wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time()); + } + return FALSE; + } + //-------------------------------------------------------------------------------------- + if (!Quiet) + { + Temp1 = db_BrowserDB->GetDatabaseName(); + Temp2 = db_BrowserDB->GetDataSource(); + wxLogMessage(_("-I-> BrowserDB::OnGetDataSourceODBC() - DatabaseName(%s) ; DataSource(%s)"),Temp1.c_str(),Temp2.c_str()); + wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time()); + } + return TRUE; + } + else + return FALSE; } + //---------------------------------------------------------------------------------------- bool BrowserDB::OnCloseDB(int Quiet) { - if (!Quiet) - wxLogMessage(_("-I-> BrowserDB::OnCloseDB() : Begin ")); - if (db_BrowserDB) - { - db_BrowserDB->Close(); - wxDbFreeConnection(db_BrowserDB); - - // Free Environment Handle that ODBC uses - if (SQLFreeEnv(&ConnectInf.Henv) != SQL_SUCCESS) - { - // Error freeing environment handle - } - db_BrowserDB = NULL; - } - if (!Quiet) - wxLogMessage(_("\n-I-> BrowserDB::OnCloseDB() : End ")); - return TRUE; + if (!Quiet) + wxLogMessage(_("-I-> BrowserDB::OnCloseDB() : Begin ")); + if (db_BrowserDB) + { +// db_BrowserDB->Close(); + wxDbFreeConnection(db_BrowserDB); +/* + // Free Environment Handle that ODBC uses + if (SQLFreeEnv(&ConnectInf.Henv) != SQL_SUCCESS) + { + // Error freeing environment handle + } +*/ + db_BrowserDB = NULL; + } + if (!Quiet) + wxLogMessage(_("\n-I-> BrowserDB::OnCloseDB() : End ")); + return TRUE; } + //---------------------------------------------------------------------------------------- bool BrowserDB::OnGetNext(int Cols,int Quiet) { - SDWORD cb; - int i_dbDataType; - int i=0; - char s_temp[1024+1]; - long l_temp; - double f_temp; - int AnzError=0; - TIMESTAMP_STRUCT t_temp; - wxString Temp0; - //----------------------------- - if (!db_BrowserDB->GetNext()) - { - return FALSE; - Temp0.Printf(_("\n-E-> BrowserDB::OnGetNext - ODBC-Error with GetNext \n-E-> ")); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxLogMessage(Temp0); - wxMessageBox(Temp0); - } - else - { - for (i=0;itableName,"-E->"); - i_dbDataType = (cl_BrowserDB->pColFor+i)->i_dbDataType; - if (i_dbDataType == 0) // Filter unsupported dbDataTypes - { - if (((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_VARCHAR) || ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_LONGVARCHAR)) - i_dbDataType = DB_DATA_TYPE_VARCHAR; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_DATE) - i_dbDataType = DB_DATA_TYPE_DATE; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_BIT) - i_dbDataType = DB_DATA_TYPE_INTEGER; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_NUMERIC) - i_dbDataType = DB_DATA_TYPE_VARCHAR; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_REAL) - i_dbDataType = DB_DATA_TYPE_FLOAT; - } - if ((i_dbDataType == DB_DATA_TYPE_INTEGER) && ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_DOUBLE)) - { // DBASE Numeric - i_dbDataType = DB_DATA_TYPE_FLOAT; - } - switch(i_dbDataType) - { - case DB_DATA_TYPE_VARCHAR: - strcpy(s_temp,""); - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_dbDataType,&s_temp,sizeof(s_temp), &cb)) - { - Temp0.Printf(_("\n-E-> BrowserDB::OnGetNext - ODBC-Error with GetNext of >%s<.\n-E-> "),(cl_BrowserDB+i)->tableName); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxLogMessage(Temp0); - } - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,s_temp); - strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); - break; - case DB_DATA_TYPE_INTEGER: - l_temp = 0; - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&l_temp,sizeof(l_temp), &cb)) - { - Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - } - else - { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,l_temp); - strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); - } - break; - case DB_DATA_TYPE_FLOAT: - f_temp = 0; - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&f_temp,sizeof(f_temp), &cb)) - { - Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(Temp0); - } - else - { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,f_temp); - strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); - } - break; - case DB_DATA_TYPE_DATE: - t_temp.day = t_temp.month = t_temp.year = t_temp.hour = t_temp.minute = t_temp.second = t_temp.fraction = 0; - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&t_temp,sizeof(t_temp), &cb)) - { - Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - } - else - { - // i_Nation = 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US - if (((cl_BrowserDB->pColFor+i)->i_Nation == 0) || // TS YYYY-MM-DD - ((cl_BrowserDB->pColFor+i)->i_Nation == 3)) // IT YYYY-MM-DD - { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.year,t_temp.month,t_temp.day, - t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); - strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); - } - if (((cl_BrowserDB->pColFor+i)->i_Nation == 1) || // EU DD.MM.YYYY - ((cl_BrowserDB->pColFor+i)->i_Nation == 2)) // UK DD/MM/YYYY - { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.day,t_temp.month,t_temp.year, - t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); - strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); - } - if ((cl_BrowserDB->pColFor+i)->i_Nation == 3) // US MM/DD/YYYY - { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.month,t_temp.day,t_temp.year, - t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); - strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); - } - } - break; - default: - AnzError++; - if (AnzError <= 100) - { - Temp0 = (cl_BrowserDB+i)->colName; - wxLogMessage(_("-E-> BrowserDB::OnGetNext - DB_DATA_TYPE_?? (%d) in Col(%s)"),(cl_BrowserDB->pColFor+i)->i_dbDataType,Temp0.c_str()); - } - else - return TRUE; - Temp0.Printf(_("-E-> unknown Format(%d) - sql(%d)"),(cl_BrowserDB->pColFor+i)->i_dbDataType,(cl_BrowserDB->pColFor+i)->i_sqlDataType); - strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); - break; - }; - } - } - // wxLogMessage("-E-> BrowserDB::OnGetNext - End"); - return TRUE; + SDWORD cb; + int i_dbDataType; + int i=0; + char s_temp[1024+1]; + long l_temp; + double f_temp; + int AnzError=0; + TIMESTAMP_STRUCT t_temp; + wxString Temp0; + //----------------------------- + if (!db_BrowserDB->GetNext()) + { + return FALSE; + Temp0.Printf(_("\n-E-> BrowserDB::OnGetNext - ODBC-Error with GetNext \n-E-> ")); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + wxLogMessage(Temp0); + wxMessageBox(Temp0); + } + else + { + for (i=0;itableName,"-E->"); + i_dbDataType = (cl_BrowserDB->pColFor+i)->i_dbDataType; + if (i_dbDataType == 0) // Filter unsupported dbDataTypes + { + if (((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_VARCHAR) || ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_LONGVARCHAR)) + i_dbDataType = DB_DATA_TYPE_VARCHAR; + if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_DATE) + i_dbDataType = DB_DATA_TYPE_DATE; + if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_BIT) + i_dbDataType = DB_DATA_TYPE_INTEGER; + if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_NUMERIC) + i_dbDataType = DB_DATA_TYPE_VARCHAR; + if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_REAL) + i_dbDataType = DB_DATA_TYPE_FLOAT; + } + if ((i_dbDataType == DB_DATA_TYPE_INTEGER) && ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_DOUBLE)) + { // DBASE Numeric + i_dbDataType = DB_DATA_TYPE_FLOAT; + } + switch(i_dbDataType) + { + case DB_DATA_TYPE_VARCHAR: + strcpy(s_temp,""); + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_dbDataType,&s_temp,sizeof(s_temp), &cb)) + { + Temp0.Printf(_("\n-E-> BrowserDB::OnGetNext - ODBC-Error with GetNext of >%s<.\n-E-> "),(cl_BrowserDB+i)->tableName); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + wxLogMessage(Temp0); + } + Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,s_temp); + strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); + break; + case DB_DATA_TYPE_INTEGER: + l_temp = 0; + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&l_temp,sizeof(l_temp), &cb)) + { + Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + } + else + { + Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,l_temp); + strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); + } + break; + case DB_DATA_TYPE_FLOAT: + f_temp = 0; + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&f_temp,sizeof(f_temp), &cb)) + { + Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + wxMessageBox(Temp0); + } + else + { + Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,f_temp); + strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); + } + break; + case DB_DATA_TYPE_DATE: + t_temp.day = t_temp.month = t_temp.year = t_temp.hour = t_temp.minute = t_temp.second = t_temp.fraction = 0; + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&t_temp,sizeof(t_temp), &cb)) + { + Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + } + else + { + // i_Nation = 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US + if (((cl_BrowserDB->pColFor+i)->i_Nation == 0) || // TS YYYY-MM-DD + ((cl_BrowserDB->pColFor+i)->i_Nation == 3)) // IT YYYY-MM-DD + { + Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.year,t_temp.month,t_temp.day, + t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); + strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); + } + if (((cl_BrowserDB->pColFor+i)->i_Nation == 1) || // EU DD.MM.YYYY + ((cl_BrowserDB->pColFor+i)->i_Nation == 2)) // UK DD/MM/YYYY + { + Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.day,t_temp.month,t_temp.year, + t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); + strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); + } + if ((cl_BrowserDB->pColFor+i)->i_Nation == 3) // US MM/DD/YYYY + { + Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.month,t_temp.day,t_temp.year, + t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); + strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); + } + } + break; + default: + AnzError++; + if (AnzError <= 100) + { + Temp0 = (cl_BrowserDB+i)->colName; + wxLogMessage(_("-E-> BrowserDB::OnGetNext - DB_DATA_TYPE_?? (%d) in Col(%s)"),(cl_BrowserDB->pColFor+i)->i_dbDataType,Temp0.c_str()); + } + else + return TRUE; + Temp0.Printf(_("-E-> unknown Format(%d) - sql(%d)"),(cl_BrowserDB->pColFor+i)->i_dbDataType,(cl_BrowserDB->pColFor+i)->i_sqlDataType); + strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); + break; + }; // switch + } // for + } // else + + return TRUE; } + //---------------------------------------------------------------------------------------- bool BrowserDB::OnSelect(wxString tb_Name, int Quiet) { - wxStopWatch sw; - wxString SQLStmt; - i_Records = 0; - //--------------------------------------------------------------------------------------- - SQLStmt.sprintf("SELECT * FROM %s",tb_Name.c_str()); - if (!db_BrowserDB->ExecSql((char *)(SQLStmt.GetData()))) - { - Temp0.Printf(_("\n-E-> BrowserDB::OnSelect - ODBC-Error with ExecSql of >%s<.\n-E-> "),tb_Name.c_str()); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxLogMessage(Temp0); - wxMessageBox("-E-> BrowserDB::OnSelect - GetData()"); - return FALSE; - } - //--------------------------------------------------------------------------------------- - while (db_BrowserDB->GetNext()) - { - i_Records++; - } - //--------------------------------------------------------------------------------------- - if (!db_BrowserDB->ExecSql((char *)(SQLStmt.GetData()))) - { - Temp0.Printf(_("\n-E-> BrowserDB::OnSelect - ODBC-Error with ExecSql of >%s<.\n-E-> "),tb_Name.c_str()); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxLogMessage(Temp0); - return FALSE; - } - //--------------------------------------------------------------------------------------- - // SetColDefs ( 0,"NAME", DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), TRUE, TRUE); // Primary index - //--------------------------------------------------------------------------------------- - if (!Quiet) - { - wxLogMessage(_("\n-I-> BrowserDB::OnSelect(%s) Records(%d): End - Time needed : %ld ms"),tb_Name.c_str(),i_Records,sw.Time()); - } - return TRUE; + wxStopWatch sw; + wxString SQLStmt; + i_Records = 0; + //--------------------------------------------------------------------------------------- + SQLStmt.sprintf("SELECT * FROM %s",tb_Name.c_str()); + if (!db_BrowserDB->ExecSql((char *)(SQLStmt.GetData()))) + { + Temp0.Printf(_("\n-E-> BrowserDB::OnSelect - ODBC-Error with ExecSql of >%s<.\n-E-> "),tb_Name.c_str()); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + wxLogMessage(Temp0); + wxMessageBox("-E-> BrowserDB::OnSelect - GetData()"); + return FALSE; + } + //--------------------------------------------------------------------------------------- + while (db_BrowserDB->GetNext()) + { + i_Records++; + } + //--------------------------------------------------------------------------------------- + if (!db_BrowserDB->ExecSql((char *)(SQLStmt.GetData()))) + { + Temp0.Printf(_("\n-E-> BrowserDB::OnSelect - ODBC-Error with ExecSql of >%s<.\n-E-> "),tb_Name.c_str()); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + wxLogMessage(Temp0); + return FALSE; + } + //--------------------------------------------------------------------------------------- + // SetColDefs ( 0,"NAME", DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), TRUE, TRUE); // Primary index + //--------------------------------------------------------------------------------------- + if (!Quiet) + { + wxLogMessage(_("\n-I-> BrowserDB::OnSelect(%s) Records(%d): End - Time needed : %ld ms"),tb_Name.c_str(),i_Records,sw.Time()); + } + return TRUE; } + //---------------------------------------------------------------------------------------- bool BrowserDB::OnExecSql(wxString SQLStmt, int Quiet) { - //--------------------------------------------------------------------------------------- - if (!db_BrowserDB->ExecSql((char *)(SQLStmt.GetData()))) - { - Temp0.Printf(_("\n-E-> BrowserDB::OnExecSQL - ODBC-Error with ExecSql of >%s<.\n-E-> "),SQLStmt.c_str()); - Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); - if (!Quiet) - wxLogMessage(Temp0); - else - wxMessageBox("-E-> BrowserDB::OnExecSql - ExecSql()"); - return FALSE; - } - if (!Quiet) - { - // wxLogMessage(_("\n-I-> BrowserDB::OnExecSql(%s) - End - Time needed : %ld ms"),SQLStmt.c_str(),sw.Time()); - } - return TRUE; + //--------------------------------------------------------------------------------------- + if (!db_BrowserDB->ExecSql((char *)(SQLStmt.GetData()))) + { + Temp0.Printf(_("\n-E-> BrowserDB::OnExecSQL - ODBC-Error with ExecSql of >%s<.\n-E-> "),SQLStmt.c_str()); + Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); + if (!Quiet) + wxLogMessage(Temp0); + else + wxMessageBox("-E-> BrowserDB::OnExecSql - ExecSql()"); + return FALSE; + } + if (!Quiet) + { + // wxLogMessage(_("\n-I-> BrowserDB::OnExecSql(%s) - End - Time needed : %ld ms"),SQLStmt.c_str(),sw.Time()); + } + return TRUE; } + //---------------------------------------------------------------------------------------- wxDbInf* BrowserDB::OnGetCatalog(int Quiet) { - char UName[255]; - strcpy(UName,UserName); - ct_BrowserDB = db_BrowserDB->GetCatalog(UName); - return ct_BrowserDB; + char UName[255]; + strcpy(UName,UserName); + ct_BrowserDB = db_BrowserDB->GetCatalog(UName); + return ct_BrowserDB; } + //---------------------------------------------------------------------------------------- wxDbColInf* BrowserDB::OnGetColumns(char *tableName, int numCols, int Quiet) { - char UName[255]; - int i; - strcpy(UName,UserName); - cl_BrowserDB = db_BrowserDB->GetColumns(tableName,&numCols,UName); - cl_BrowserDB->pColFor = new wxDbColFor[numCols]; - for (i=0;ipColFor+i)->Format(1,(cl_BrowserDB+i)->dbDataType,(cl_BrowserDB+i)->sqlDataType, - (cl_BrowserDB+i)->columnSize, (cl_BrowserDB+i)->decimalDigits); - } - return cl_BrowserDB; + char UName[255]; + int i; + strcpy(UName,UserName); + cl_BrowserDB = db_BrowserDB->GetColumns(tableName,&numCols,UName); + cl_BrowserDB->pColFor = new wxDbColFor[numCols]; + for (i=0;ipColFor+i)->Format(1,(cl_BrowserDB+i)->dbDataType,(cl_BrowserDB+i)->sqlDataType, + (cl_BrowserDB+i)->columnSize, (cl_BrowserDB+i)->decimalDigits); + } + return cl_BrowserDB; } + //---------------------------------------------------------------------------------------- void BrowserDB::Zeiger_auf_NULL(int Art) { - if (Art == 1) // Löschen - { - if (cl_BrowserDB != NULL) - { // Destroy the memory - delete [] cl_BrowserDB; - } - if (ct_BrowserDB != NULL) - { // Destroy the memory - delete [] ct_BrowserDB; - } - if (db_BrowserDB != NULL) - { - db_BrowserDB->CommitTrans(); - db_BrowserDB->Close(); - wxDbCloseConnections(); - delete db_BrowserDB; - } - } - cl_BrowserDB = NULL; - ct_BrowserDB = NULL; - db_BrowserDB = NULL; - p_LogWindow = NULL; + if (Art == 1) // Löschen + { + if (cl_BrowserDB != NULL) + { // Destroy the memory + delete [] cl_BrowserDB; + } + if (ct_BrowserDB != NULL) + { // Destroy the memory + delete [] ct_BrowserDB; + } + if (db_BrowserDB != NULL) + { + db_BrowserDB->CommitTrans(); + db_BrowserDB->Close(); + wxDbCloseConnections(); + delete db_BrowserDB; + } + } + cl_BrowserDB = NULL; + ct_BrowserDB = NULL; + db_BrowserDB = NULL; + p_LogWindow = NULL; } + //---------------------------------------------------------------------------------------- void BrowserDB::OnFillSqlTyp() { - i_SqlTyp[1] = SQL_C_BINARY; s_SqlTyp[1] = "SQL_C_BINARY"; - i_SqlTyp[2] = SQL_C_BIT; s_SqlTyp[2] = "SQL_C_BIT"; - i_SqlTyp[3] = SQL_C_BOOKMARK; s_SqlTyp[3] = "SQL_C_BOOKMARK"; - i_SqlTyp[4] = SQL_C_CHAR; s_SqlTyp[4] = "SQL_C_CHAR"; - i_SqlTyp[5] = SQL_C_DATE; s_SqlTyp[5] = "SQL_C_DATE"; - i_SqlTyp[6] = SQL_C_DEFAULT; s_SqlTyp[6] = "SQL_C_DEFAULT"; - i_SqlTyp[7] = SQL_C_DOUBLE; s_SqlTyp[7] = "SQL_C_DOUBLE"; - i_SqlTyp[8] = SQL_C_FLOAT; s_SqlTyp[8] = "SQL_C_FLOAT"; - i_SqlTyp[9] = SQL_C_LONG; s_SqlTyp[9] = "SQL_C_LONG"; - i_SqlTyp[10] = SQL_C_SHORT; s_SqlTyp[10] = "SQL_C_SHORT"; - i_SqlTyp[11] = SQL_C_SLONG; s_SqlTyp[11] = "SQL_C_SLONG"; - i_SqlTyp[12] = SQL_C_SSHORT; s_SqlTyp[12] = "SQL_C_SSHORT"; - i_SqlTyp[13] = SQL_C_STINYINT; s_SqlTyp[13] = "SQL_C_STINYINT"; - i_SqlTyp[14] = SQL_C_TIME; s_SqlTyp[14] = "SQL_C_TIME"; - i_SqlTyp[15] = SQL_C_TIMESTAMP; s_SqlTyp[15] = "SQL_C_TIMESTAMP"; - i_SqlTyp[16] = SQL_C_TINYINT; s_SqlTyp[16] = "SQL_C_TINYINT"; - i_SqlTyp[17] = SQL_C_ULONG; s_SqlTyp[17] = "SQL_C_ULONG"; - i_SqlTyp[18] = SQL_C_USHORT; s_SqlTyp[18] = "SQL_C_USHORT"; - i_SqlTyp[19] = SQL_C_UTINYINT; s_SqlTyp[19] = "SQL_C_UTINYINT"; - i_SqlTyp[20] = SQL_VARCHAR; s_SqlTyp[20] = "SQL_VARCHAR"; - i_SqlTyp[21] = SQL_NUMERIC; s_SqlTyp[21] = "SQL_NUMERIC"; - i_SqlTyp[22] = SQL_LONGVARCHAR; s_SqlTyp[22] = "SQL_LONGVARCHAR"; - i_SqlTyp[23] = SQL_REAL; s_SqlTyp[23] = "SQL_REAL"; - i_SqlTyp[0] = 23; s_SqlTyp[0] = ""; + i_SqlTyp[1] = SQL_C_BINARY; s_SqlTyp[1] = "SQL_C_BINARY"; + i_SqlTyp[2] = SQL_C_BIT; s_SqlTyp[2] = "SQL_C_BIT"; + i_SqlTyp[3] = SQL_C_BOOKMARK; s_SqlTyp[3] = "SQL_C_BOOKMARK"; + i_SqlTyp[4] = SQL_C_CHAR; s_SqlTyp[4] = "SQL_C_CHAR"; + i_SqlTyp[5] = SQL_C_DATE; s_SqlTyp[5] = "SQL_C_DATE"; + i_SqlTyp[6] = SQL_C_DEFAULT; s_SqlTyp[6] = "SQL_C_DEFAULT"; + i_SqlTyp[7] = SQL_C_DOUBLE; s_SqlTyp[7] = "SQL_C_DOUBLE"; + i_SqlTyp[8] = SQL_C_FLOAT; s_SqlTyp[8] = "SQL_C_FLOAT"; + i_SqlTyp[9] = SQL_C_LONG; s_SqlTyp[9] = "SQL_C_LONG"; + i_SqlTyp[10] = SQL_C_SHORT; s_SqlTyp[10] = "SQL_C_SHORT"; + i_SqlTyp[11] = SQL_C_SLONG; s_SqlTyp[11] = "SQL_C_SLONG"; + i_SqlTyp[12] = SQL_C_SSHORT; s_SqlTyp[12] = "SQL_C_SSHORT"; + i_SqlTyp[13] = SQL_C_STINYINT; s_SqlTyp[13] = "SQL_C_STINYINT"; + i_SqlTyp[14] = SQL_C_TIME; s_SqlTyp[14] = "SQL_C_TIME"; + i_SqlTyp[15] = SQL_C_TIMESTAMP; s_SqlTyp[15] = "SQL_C_TIMESTAMP"; + i_SqlTyp[16] = SQL_C_TINYINT; s_SqlTyp[16] = "SQL_C_TINYINT"; + i_SqlTyp[17] = SQL_C_ULONG; s_SqlTyp[17] = "SQL_C_ULONG"; + i_SqlTyp[18] = SQL_C_USHORT; s_SqlTyp[18] = "SQL_C_USHORT"; + i_SqlTyp[19] = SQL_C_UTINYINT; s_SqlTyp[19] = "SQL_C_UTINYINT"; + i_SqlTyp[20] = SQL_VARCHAR; s_SqlTyp[20] = "SQL_VARCHAR"; + i_SqlTyp[21] = SQL_NUMERIC; s_SqlTyp[21] = "SQL_NUMERIC"; + i_SqlTyp[22] = SQL_LONGVARCHAR; s_SqlTyp[22] = "SQL_LONGVARCHAR"; + i_SqlTyp[23] = SQL_REAL; s_SqlTyp[23] = "SQL_REAL"; + i_SqlTyp[0] = 23; s_SqlTyp[0] = ""; } + //---------------------------------------------------------------------------------------- void BrowserDB::OnFilldbTyp() { - i_dbTyp[1] = DB_DATA_TYPE_VARCHAR; s_dbTyp[1] = "DB_DATA_TYPE_VARCHAR"; - i_dbTyp[2] = DB_DATA_TYPE_INTEGER; s_dbTyp[2] = "DB_DATA_TYPE_INTEGER"; - i_dbTyp[3] = DB_DATA_TYPE_FLOAT; s_dbTyp[3] = "DB_DATA_TYPE_FLOAT"; - i_dbTyp[4] = DB_DATA_TYPE_DATE; s_dbTyp[4] = "DB_DATA_TYPE_DATE"; - i_dbTyp[0] = 4; s_dbTyp[0] = ""; + i_dbTyp[1] = DB_DATA_TYPE_VARCHAR; s_dbTyp[1] = "DB_DATA_TYPE_VARCHAR"; + i_dbTyp[2] = DB_DATA_TYPE_INTEGER; s_dbTyp[2] = "DB_DATA_TYPE_INTEGER"; + i_dbTyp[3] = DB_DATA_TYPE_FLOAT; s_dbTyp[3] = "DB_DATA_TYPE_FLOAT"; + i_dbTyp[4] = DB_DATA_TYPE_DATE; s_dbTyp[4] = "DB_DATA_TYPE_DATE"; + i_dbTyp[0] = 4; s_dbTyp[0] = ""; } //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/browsedb.h b/demos/dbbrowse/browsedb.h index d55d9c9f47..155bfc157c 100644 --- a/demos/dbbrowse/browsedb.h +++ b/demos/dbbrowse/browsedb.h @@ -16,62 +16,63 @@ //---------------------------------------------------------------------------------------- extern wxDbConnectInf DbConnectInf; class MainDoc; + //---------------------------------------------------------------------------------------- class BrowserDB { - public: - //--------------------------------------------------------------------------------------- - // Pointer to the main database connection used in the program. This - // pointer would normally be used for doing things as database lookups - // for user login names and passwords, getting workstation settings, etc. - // ---> IMPORTANT <--- - // - // For each database object created which uses this wxDb pointer - // connection to the database, when a CommitTrans() or RollBackTrans() - // will commit or rollback EVERY object which uses this wxDb pointer. - // - // To allow each table object (those derived from wxDbTable) to be - // individually committed or rolled back, you MUST use a different - // instance of wxDb in the constructor of the table. Doing so creates - // more overhead, and will use more database connections (some DBs have - // connection limits...), so use connections sparringly. - // - // It is recommended that one "main" database connection be created for - // the entire program to use for READ-ONLY database accesses, but for each - // table object which will do a CommitTrans() or RollbackTrans() that a - // new wxDb object be created and used for it. - //--------------------------------------------------------------------------------------- - wxDb* db_BrowserDB; - wxDbInf* ct_BrowserDB; - wxDbColInf* cl_BrowserDB; - wxString ODBCSource, UserName, Password; - MainDoc *pDoc; - //--------------------------------------------------------------------------------------- - wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; - wxString ODBCText; - wxTextCtrl* p_LogWindow; - wxString s_SqlTyp[25]; - int i_SqlTyp[25]; - wxString s_dbTyp[5]; - int i_dbTyp[5]; - int i_Which; - int i_Records; - int i_Cols; - //--------------------------------------------------------------------------------------- - BrowserDB(); - ~BrowserDB(); - void Zeiger_auf_NULL(int Art); - bool Initialize(int Quiet); - //--------------------------------------------------------------------------------------- - bool OnStartDB(int Quiet); - bool OnCloseDB(int Quiet); - bool OnSelect(wxString tb_Name,int Quiet); - bool OnExecSql(wxString SQLStmt,int Quiet); - bool OnGetNext(int Cols,int Quiet); - wxDbInf* OnGetCatalog(int Quiet); - wxDbColInf* OnGetColumns(char *tableName, int numCols,int Quiet); - void OnFillSqlTyp(); - void OnFilldbTyp(); - //--------------------------------------------------------------------------------------- +public: + //--------------------------------------------------------------------------------------- + // Pointer to the main database connection used in the program. This + // pointer would normally be used for doing things as database lookups + // for user login names and passwords, getting workstation settings, etc. + // ---> IMPORTANT <--- + // + // For each database object created which uses this wxDb pointer + // connection to the database, when a CommitTrans() or RollBackTrans() + // will commit or rollback EVERY object which uses this wxDb pointer. + // + // To allow each table object (those derived from wxDbTable) to be + // individually committed or rolled back, you MUST use a different + // instance of wxDb in the constructor of the table. Doing so creates + // more overhead, and will use more database connections (some DBs have + // connection limits...), so use connections sparringly. + // + // It is recommended that one "main" database connection be created for + // the entire program to use for READ-ONLY database accesses, but for each + // table object which will do a CommitTrans() or RollbackTrans() that a + // new wxDb object be created and used for it. + //--------------------------------------------------------------------------------------- + wxDb* db_BrowserDB; + wxDbInf* ct_BrowserDB; + wxDbColInf* cl_BrowserDB; + wxString ODBCSource, UserName, Password; + MainDoc *pDoc; + //--------------------------------------------------------------------------------------- + wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; + wxString ODBCText; + wxTextCtrl* p_LogWindow; + wxString s_SqlTyp[25]; + int i_SqlTyp[25]; + wxString s_dbTyp[5]; + int i_dbTyp[5]; + int i_Which; + int i_Records; + int i_Cols; + //--------------------------------------------------------------------------------------- + BrowserDB(); + ~BrowserDB(); + void Zeiger_auf_NULL(int Art); + bool Initialize(int Quiet); + //--------------------------------------------------------------------------------------- + bool OnStartDB(int Quiet); + bool OnCloseDB(int Quiet); + bool OnSelect(wxString tb_Name,int Quiet); + bool OnExecSql(wxString SQLStmt,int Quiet); + bool OnGetNext(int Cols,int Quiet); + wxDbInf* OnGetCatalog(int Quiet); + wxDbColInf* OnGetColumns(char *tableName, int numCols,int Quiet); + void OnFillSqlTyp(); + void OnFilldbTyp(); + //--------------------------------------------------------------------------------------- }; // BrowserDB class definition -//---------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/dbbrowse.cpp b/demos/dbbrowse/dbbrowse.cpp index c75312caab..6a8a70df5e 100644 --- a/demos/dbbrowse/dbbrowse.cpp +++ b/demos/dbbrowse/dbbrowse.cpp @@ -12,23 +12,23 @@ //-- all #ifdefs that the whole Project needs. ------------------------------------------- //---------------------------------------------------------------------------------------- #ifdef __GNUG__ - #pragma implementation - #pragma interface +#pragma implementation +#pragma interface #endif //---------------------------------------------------------------------------------------- // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" //---------------------------------------------------------------------------------------- #ifdef __BORLANDC__ - #pragma hdrstop +#pragma hdrstop #endif //---------------------------------------------------------------------------------------- #ifndef WX_PRECOMP - #include "wx/wx.h" +#include "wx/wx.h" #endif //---------------------------------------------------------------------------------------- #ifndef __WXMSW__ - #include "bitmaps/logo.xpm" +#include "bitmaps/logo.xpm" #endif //---------------------------------------------------------------------------------------- //-- all #includes that every .cpp needs --- 19990807.mj10777 ---------------- @@ -39,278 +39,285 @@ //-- Some Global Vars for this file ------------------------------------------------------ //---------------------------------------------------------------------------------------- BEGIN_EVENT_TABLE(MainFrame, wxFrame) - EVT_MENU(QUIT, MainFrame::OnQuit) // Program End - EVT_MENU(ABOUT, MainFrame::OnAbout) // Program Discription - EVT_MENU(HELP, MainFrame::OnHelp) // Program Help + EVT_MENU(QUIT, MainFrame::OnQuit) // Program End + EVT_MENU(ABOUT, MainFrame::OnAbout) // Program Discription + EVT_MENU(HELP, MainFrame::OnHelp) // Program Help END_EVENT_TABLE() + //---------------------------------------------------------------------------------------- IMPLEMENT_APP(MainApp) // This declares wxApp::MainApp as "the" Application + //---------------------------------------------------------------------------------------- // 'Main program' equivalent, creating windows and returning main app frame //---------------------------------------------------------------------------------------- bool MainApp::OnInit(void) // Does everything needed for a program start { - wxString Temp0; // Use as needed - //--------------------------------------------------------------------------------------- - // set the language to use // Help.?? (.std = english, .de = german etc.) - const char *language = NULL; // czech, german, french, polish - const char *langid = NULL; // std = english , cz, de = german, fr = french, pl = polish - wxString s_LangHelp; // Directory/Filename.hhp of the Help-Project file - wxString s_LangId, s_Language; - s_Language.Empty(); s_LangId.Empty(); s_LangHelp.Empty(); - //--------------------------------------------------------------------------------------- - //-- Graphic File suport - use only when needed, otherwise big .exe's - //--------------------------------------------------------------------------------------- + wxString Temp0; // Use as needed + //--------------------------------------------------------------------------------------- + // set the language to use // Help.?? (.std = english, .de = german etc.) + const char *language = NULL; // czech, german, french, polish + const char *langid = NULL; // std = english , cz, de = german, fr = french, pl = polish + wxString s_LangHelp; // Directory/Filename.hhp of the Help-Project file + wxString s_LangId, s_Language; + s_Language.Empty(); s_LangId.Empty(); s_LangHelp.Empty(); + //--------------------------------------------------------------------------------------- + //-- Graphic File suport - use only when needed, otherwise big .exe's + //--------------------------------------------------------------------------------------- #if wxUSE_LIBPNG - wxImage::AddHandler( new wxPNGHandler ); // needed for help System + wxImage::AddHandler( new wxPNGHandler ); // needed for help System #endif /* -#if wxUSE_LIBJPEG - wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's -#endif - wxImage::AddHandler( new wxGIFHandler ); // use only when needed, otherwise big .exe's - wxImage::AddHandler( new wxPCXHandler ); // use only when needed, otherwise big .exe's - wxImage::AddHandler( new wxPNMHandler ); // use only when needed, otherwise big .exe's + #if wxUSE_LIBJPEG + wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's + #endif + wxImage::AddHandler( new wxGIFHandler ); // use only when needed, otherwise big .exe's + wxImage::AddHandler( new wxPCXHandler ); // use only when needed, otherwise big .exe's + wxImage::AddHandler( new wxPNMHandler ); // use only when needed, otherwise big .exe's */ #ifdef __WXMSW__ - // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico - // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed + // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico + // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed #endif - //--------------------------------------------------------------------------------------- - switch ( argc ) - { - default: - // ignore the other args, fall through - case 3: - language = argv[2]; // czech, english, french, german , polish - langid = argv[1]; // cz, std, fr, de , pl - break; - case 2: - langid = argv[1]; // cz, std, fr, de , pl - break; - case 1: - break; - }; - //--------------------------------------------------------------------------------------- - // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName() - //--------------------------------------------------------------------------------------- - SetVendorName("mj10777"); // Needed to get Configuration Information - SetAppName("DBBrowse"); // "" , also needed for s_LangHelp - //--------------------------------------------------------------------------------------- - // we're using wxConfig's "create-on-demand" feature: it will create the - // config object when it's used for the first time. It has a number of - // advantages compared with explicitly creating our wxConfig: - // 1) we don't pay for it if we don't use it - // 2) there is no danger to create it twice - - // application and vendor name are used by wxConfig to construct the name - // of the config file/registry key and must be set before the first call - // to Get() if you want to override the default values (the application - // name is the name of the executable and the vendor name is the same) - //--------------------------------------------------------------------------------------- - p_ProgramCfg = wxConfigBase::Get(); // Get Program Configuration from Registry - // p_ProgramCfg->DeleteAll(); // This is how the Config can be erased - p_ProgramCfg->SetPath("/"); // Start at root - //--------------------------------------------------------------------------------------- - //-- Set the Language and remember it for the next time. -------------------------------- - //--------------------------------------------------------------------------------------- - if (langid == NULL) // No Parameter was given - { - Temp0.Empty(); - p_ProgramCfg->Read("/Local/langid",&Temp0); // >const char *langid< can't be used here - if (Temp0 == "") - langid = "std"; // Standard language is "std" = english - else - langid = Temp0; - } - Temp0.Printf("%s",langid); - //--------------------------------------------------------------------------------------- - // Support the following languages (std = english) - if ((Temp0 == "a") || (Temp0 == "cz") || (Temp0 == "de") || - (Temp0 == "fr") || (Temp0 == "pl")) - { // The three-letter language-string codes are only valid in Windows NT and Windows 95. - if (Temp0 == "cz") - language = "czech"; // csy or czech - if ((Temp0 == "de") || (Temp0 == "a")) - { - language = "german"; // deu or german - if (Temp0 == "a") - { langid = Temp0 = "de"; } // Austrian = german - } // german / austrian - if (Temp0 == "fr") - language = "french"; // fra or french - if (Temp0 == "pl") - language = "polish"; // plk or polish - if (!m_locale.Init(language, langid, language)) // Don't do this for english (std) - { // You should recieve errors here for cz and pl since there is no cz/ and pl/ directory - wxLogMessage("-E-> %s : SetLocale error : langid(%s) ; language(%s)",GetAppName().c_str(),langid,language); - langid = "std"; - language = "C"; // english, english-aus , -can , -nz , -uk , -usa - } - else - { // Read in Foreign language's text for GetAppName() and Help - Temp0 = GetAppName(); - Temp0 = Temp0.Lower(); - m_locale.AddCatalog(Temp0.c_str()); - m_locale.AddCatalog("help"); - } - } // Support the following languages (std = english) - else - { - langid = "std"; - language = "C"; // english, english-aus , -can , -nz , -uk , -usa - } - s_Language.Printf("%s",language); // language is a pointer - s_LangId.Printf("%s",langid); // langid is a pointer - p_ProgramCfg->Write("/Local/language",s_Language); - p_ProgramCfg->Write("/Local/langid",s_LangId); - s_LangHelp.Printf("help.%s/%s.hhp",s_LangId.c_str(),GetAppName().c_str()); // "help.std/Garantie.hhp"; - s_LangHelp = s_LangHelp.Lower(); // A must for Linux - //--------------------------------------------------------------------------------------- - Temp0 = "NONE"; // I don't remember why I did this - p_ProgramCfg->Write("/NONE",Temp0); // I don't remember why I did this - p_ProgramCfg->Write("/Paths/NONE",Temp0); // I don't remember why I did this - p_ProgramCfg->Write("/MainFrame/NONE",Temp0); // I don't remember why I did this - //--------------------------------------------------------------------------------------- - p_ProgramCfg->Write("/Paths/Work",wxGetCwd()); // Get current Working Path - p_ProgramCfg->SetPath("/"); - //--------------------------------------------------------------------------------------- - // restore frame position and size, if empty start Values (1,1) and (750,600) - int x = p_ProgramCfg->Read("/MainFrame/x", 1), y = p_ProgramCfg->Read("/MainFrame/y", 1), - w = p_ProgramCfg->Read("/MainFrame/w", 750), h = p_ProgramCfg->Read("/MainFrame/h", 600); - //--------------------------------------------------------------------------------------- - // Create the main frame window - Temp0.Printf("%s - %s",GetAppName().c_str(),GetVendorName().c_str()); - frame = new MainFrame((wxFrame *) NULL,(char *) Temp0.c_str(),wxPoint(x,y),wxSize(w,h)); - //--------------------------------------------------------------------------------------- - // Set the Backgroundcolour (only need if your are NOT using wxSYS_COLOUR_BACKGROUND) - frame->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BACKGROUND)); - // frame->SetBackgroundColour(wxColour(255, 255, 255)); - // frame->SetBackgroundColour(* wxWHITE); - //--------------------------------------------------------------------------------------- - // Give it an icon - //--------------------------------------------------------------------------------------- - // 12.02.2000 - Guillermo Rodriguez Garcia : - //--------------------------------------------------------------------------------------- - // This is different for Win9x and WinNT; one of them takes the first ico - // in the .rc file, while the other takes the icon with the lowest name, - // so to be sure that it always work, put your icon the first *and* give - // it a name such a 'appicon' or something. - //--------------------------------------------------------------------------------------- - // mj10777 : any special rule in Linux ? - //--------------------------------------------------------------------------------------- - frame->SetIcon(wxICON(aLogo)); // lowest name and first entry in RC File - //--------------------------------------------------------------------------------------- - // Make a menubar - wxMenu *file_menu = new wxMenu; - wxMenu *help_menu = new wxMenu; - - help_menu->Append(HELP, _("&Help")); - help_menu->AppendSeparator(); - help_menu->Append(ABOUT, _("&About")); - file_menu->Append(QUIT, _("E&xit")); - - wxMenuBar *menu_bar = new wxMenuBar; - menu_bar->Append(file_menu, _("&File")); - menu_bar->Append(help_menu, _("&Help")); - frame->SetMenuBar(menu_bar); - frame->CreateStatusBar(1); - Temp0.Printf(_("%s has started !"),p_ProgramCfg->GetAppName().c_str()); - frame->SetStatusText(Temp0, 0); - //--------------------------------------------------------------------------------------- - int width, height; - frame->GetClientSize(&width, &height); - //--------------------------------------------------------------------------------------- - frame->p_Splitter = new DocSplitterWindow(frame,-1); - // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL)); - frame->pDoc = new MainDoc(); - frame->pDoc->p_MainFrame = frame; - frame->pDoc->p_Splitter = frame->p_Splitter; - frame->pDoc->p_Splitter->pDoc = frame->pDoc; // ControlBase: saving the Sash - //--------------------------------------------------------------------------------------- - //-- Problem : GetClientSize(Width,Hight) are not the same as the values given in the --- - //-- construction of the Frame. --- - //-- Solved : GetClientSize is called here and the difference is noted. When the --- - //-- Window is closed the diff. is added to the result of GetClientSize. --- - //--------------------------------------------------------------------------------------- - frame->GetClientSize(&frame->DiffW, &frame->DiffH); frame->DiffW-=w; frame->DiffH-=h; - //---------------------------------------------------------------------------- - //-- Help : Load the help.%langid/%GetAppName().hhp (help.std/dbbrowse.hhp) file --- - //---------------------------------------------------------------------------- - frame->p_Help = new wxHtmlHelpController(); // construct the Help System - frame->p_Help->UseConfig(p_ProgramCfg); // Don't rember what this was for - // You should recieve errors here for fr since there is no help.fr/ directory - if (!frame->p_Help->AddBook(s_LangHelp)) // Use the language set - { // You should recieve errors here for fr since there is no help.fr/ but a fr/ directory - wxLogMessage("-E-> %s : AddBook error : s_LangHelp(%s)",GetAppName().c_str(),s_LangHelp.c_str()); - } - frame->pDoc->p_Help = frame->p_Help; // Save the information to the document - //--------------------------------------------------------------------------------------- - frame->Show(TRUE); // Show the frame - SetTopWindow(frame); // At this point the frame can be seen - //--------------------------------------------------------------------------------------- - // If you need a "Splash Screen" because of a long OnNewDocument, do it here - if (!frame->pDoc->OnNewDocument()) - frame->Close(TRUE); - // Kill a "Splash Screen" because OnNewDocument, if you have one - //--------------------------------------------------------------------------------------- - p_ProgramCfg->Flush(TRUE); // save the configuration - return TRUE; + //--------------------------------------------------------------------------------------- + switch ( argc ) + { + default: + // ignore the other args, fall through + case 3: + language = argv[2]; // czech, english, french, german , polish + langid = argv[1]; // cz, std, fr, de , pl + break; + case 2: + langid = argv[1]; // cz, std, fr, de , pl + break; + case 1: + break; + }; + //--------------------------------------------------------------------------------------- + // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName() + //--------------------------------------------------------------------------------------- + SetVendorName("mj10777"); // Needed to get Configuration Information + SetAppName("DBBrowse"); // "" , also needed for s_LangHelp + //--------------------------------------------------------------------------------------- + // we're using wxConfig's "create-on-demand" feature: it will create the + // config object when it's used for the first time. It has a number of + // advantages compared with explicitly creating our wxConfig: + // 1) we don't pay for it if we don't use it + // 2) there is no danger to create it twice + + // application and vendor name are used by wxConfig to construct the name + // of the config file/registry key and must be set before the first call + // to Get() if you want to override the default values (the application + // name is the name of the executable and the vendor name is the same) + //--------------------------------------------------------------------------------------- + p_ProgramCfg = wxConfigBase::Get(); // Get Program Configuration from Registry + // p_ProgramCfg->DeleteAll(); // This is how the Config can be erased + p_ProgramCfg->SetPath("/"); // Start at root + //--------------------------------------------------------------------------------------- + //-- Set the Language and remember it for the next time. -------------------------------- + //--------------------------------------------------------------------------------------- + if (langid == NULL) // No Parameter was given + { + Temp0.Empty(); + p_ProgramCfg->Read("/Local/langid",&Temp0); // >const char *langid< can't be used here + if (Temp0 == "") + langid = "std"; // Standard language is "std" = english + else + langid = Temp0; + } + Temp0.Printf("%s",langid); + //--------------------------------------------------------------------------------------- + // Support the following languages (std = english) + if ((Temp0 == "a") || (Temp0 == "cz") || (Temp0 == "de") || + (Temp0 == "fr") || (Temp0 == "pl")) + { // The three-letter language-string codes are only valid in Windows NT and Windows 95. + if (Temp0 == "cz") + language = "czech"; // csy or czech + if ((Temp0 == "de") || (Temp0 == "a")) + { + language = "german"; // deu or german + if (Temp0 == "a") + { langid = Temp0 = "de"; } // Austrian = german + } // german / austrian + if (Temp0 == "fr") + language = "french"; // fra or french + if (Temp0 == "pl") + language = "polish"; // plk or polish + if (!m_locale.Init(language, langid, language)) // Don't do this for english (std) + { // You should recieve errors here for cz and pl since there is no cz/ and pl/ directory + wxLogMessage("-E-> %s : SetLocale error : langid(%s) ; language(%s)",GetAppName().c_str(),langid,language); + langid = "std"; + language = "C"; // english, english-aus , -can , -nz , -uk , -usa + } + else + { // Read in Foreign language's text for GetAppName() and Help + Temp0 = GetAppName(); + Temp0 = Temp0.Lower(); + m_locale.AddCatalog(Temp0.c_str()); + m_locale.AddCatalog("help"); + } + } // Support the following languages (std = english) + else + { + langid = "std"; + language = "C"; // english, english-aus , -can , -nz , -uk , -usa + } + s_Language.Printf("%s",language); // language is a pointer + s_LangId.Printf("%s",langid); // langid is a pointer + p_ProgramCfg->Write("/Local/language",s_Language); + p_ProgramCfg->Write("/Local/langid",s_LangId); + s_LangHelp.Printf("help.%s/%s.hhp",s_LangId.c_str(),GetAppName().c_str()); // "help.std/Garantie.hhp"; + s_LangHelp = s_LangHelp.Lower(); // A must for Linux + //--------------------------------------------------------------------------------------- + Temp0 = "NONE"; // I don't remember why I did this + p_ProgramCfg->Write("/NONE",Temp0); // I don't remember why I did this + p_ProgramCfg->Write("/Paths/NONE",Temp0); // I don't remember why I did this + p_ProgramCfg->Write("/MainFrame/NONE",Temp0); // I don't remember why I did this + //--------------------------------------------------------------------------------------- + p_ProgramCfg->Write("/Paths/Work",wxGetCwd()); // Get current Working Path + p_ProgramCfg->SetPath("/"); + //--------------------------------------------------------------------------------------- + // restore frame position and size, if empty start Values (1,1) and (750,600) + int x = p_ProgramCfg->Read("/MainFrame/x", 1), y = p_ProgramCfg->Read("/MainFrame/y", 1), + w = p_ProgramCfg->Read("/MainFrame/w", 750), h = p_ProgramCfg->Read("/MainFrame/h", 600); + //--------------------------------------------------------------------------------------- + // Create the main frame window + Temp0.Printf("%s - %s",GetAppName().c_str(),GetVendorName().c_str()); + frame = new MainFrame((wxFrame *) NULL,(char *) Temp0.c_str(),wxPoint(x,y),wxSize(w,h)); + //--------------------------------------------------------------------------------------- + // Set the Backgroundcolour (only need if your are NOT using wxSYS_COLOUR_BACKGROUND) + frame->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BACKGROUND)); + // frame->SetBackgroundColour(wxColour(255, 255, 255)); + // frame->SetBackgroundColour(* wxWHITE); + //--------------------------------------------------------------------------------------- + // Give it an icon + //--------------------------------------------------------------------------------------- + // 12.02.2000 - Guillermo Rodriguez Garcia : + //--------------------------------------------------------------------------------------- + // This is different for Win9x and WinNT; one of them takes the first ico + // in the .rc file, while the other takes the icon with the lowest name, + // so to be sure that it always work, put your icon the first *and* give + // it a name such a 'appicon' or something. + //--------------------------------------------------------------------------------------- + // mj10777 : any special rule in Linux ? + //--------------------------------------------------------------------------------------- + frame->SetIcon(wxICON(aLogo)); // lowest name and first entry in RC File + //--------------------------------------------------------------------------------------- + // Make a menubar + wxMenu *file_menu = new wxMenu; + wxMenu *help_menu = new wxMenu; + + help_menu->Append(HELP, _("&Help")); + help_menu->AppendSeparator(); + help_menu->Append(ABOUT, _("&About")); + file_menu->Append(QUIT, _("E&xit")); + + wxMenuBar *menu_bar = new wxMenuBar; + menu_bar->Append(file_menu, _("&File")); + menu_bar->Append(help_menu, _("&Help")); + frame->SetMenuBar(menu_bar); + frame->CreateStatusBar(1); + Temp0.Printf(_("%s has started !"),p_ProgramCfg->GetAppName().c_str()); + frame->SetStatusText(Temp0, 0); + //--------------------------------------------------------------------------------------- + int width, height; + frame->GetClientSize(&width, &height); + //--------------------------------------------------------------------------------------- + frame->p_Splitter = new DocSplitterWindow(frame,-1); + // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL)); + frame->pDoc = new MainDoc(); + frame->pDoc->p_MainFrame = frame; + frame->pDoc->p_Splitter = frame->p_Splitter; + frame->pDoc->p_Splitter->pDoc = frame->pDoc; // ControlBase: saving the Sash + //--------------------------------------------------------------------------------------- + //-- Problem : GetClientSize(Width,Hight) are not the same as the values given in the --- + //-- construction of the Frame. --- + //-- Solved : GetClientSize is called here and the difference is noted. When the --- + //-- Window is closed the diff. is added to the result of GetClientSize. --- + //--------------------------------------------------------------------------------------- + frame->GetClientSize(&frame->DiffW, &frame->DiffH); frame->DiffW-=w; frame->DiffH-=h; + //---------------------------------------------------------------------------- + //-- Help : Load the help.%langid/%GetAppName().hhp (help.std/dbbrowse.hhp) file --- + //---------------------------------------------------------------------------- + frame->p_Help = new wxHtmlHelpController(); // construct the Help System + frame->p_Help->UseConfig(p_ProgramCfg); // Don't rember what this was for + // You should recieve errors here for fr since there is no help.fr/ directory + if (!frame->p_Help->AddBook(s_LangHelp)) // Use the language set + { // You should recieve errors here for fr since there is no help.fr/ but a fr/ directory + wxLogMessage("-E-> %s : AddBook error : s_LangHelp(%s)",GetAppName().c_str(),s_LangHelp.c_str()); + } + frame->pDoc->p_Help = frame->p_Help; // Save the information to the document + //--------------------------------------------------------------------------------------- + frame->Show(TRUE); // Show the frame + SetTopWindow(frame); // At this point the frame can be seen + //--------------------------------------------------------------------------------------- + // If you need a "Splash Screen" because of a long OnNewDocument, do it here + if (!frame->pDoc->OnNewDocument()) + frame->Close(TRUE); + // Kill a "Splash Screen" because OnNewDocument, if you have one + //--------------------------------------------------------------------------------------- + p_ProgramCfg->Flush(TRUE); // save the configuration + return TRUE; } // bool MainApp::OnInit(void) + //---------------------------------------------------------------------------------------- // My frame constructor //---------------------------------------------------------------------------------------- MainFrame::MainFrame(wxFrame *frame, char *title, const wxPoint& pos, const wxSize& size): - wxFrame(frame, -1, title, pos, size) +wxFrame(frame, -1, title, pos, size) { - p_Splitter = NULL; pDoc = NULL; p_Help = NULL; // Keep the Pointers clean ! - //--- Everything else is done in MainApp::OnInit() -------------------------------------- + p_Splitter = NULL; pDoc = NULL; p_Help = NULL; // Keep the Pointers clean ! + //--- Everything else is done in MainApp::OnInit() -------------------------------------- } + //---------------------------------------------------------------------------------------- MainFrame::~MainFrame(void) { - // Close the help frame; this will cause the config data to get written. - if (p_Help->GetFrame()) // returns NULL if no help frame active - p_Help->GetFrame()->Close(TRUE); - delete p_Help; // Memory Leak - p_Help = NULL; - // save the control's values to the config - if (p_ProgramCfg == NULL) - return; - // save the frame position before it is destroyed - int x, y, w, h; - GetPosition(&x, &y); - GetClientSize(&w, &h); w -= DiffW; h -= DiffH; - p_ProgramCfg->Write("/MainFrame/x", (long) x); - p_ProgramCfg->Write("/MainFrame/y", (long) y); - p_ProgramCfg->Write("/MainFrame/w", (long) w); - p_ProgramCfg->Write("/MainFrame/h", (long) h); - p_ProgramCfg->Write("/MainFrame/Sash", (long) pDoc->Sash); - // clean up: Set() returns the active config object as Get() does, but unlike - // Get() it doesn't try to create one if there is none (definitely not what - // we want here!) - // delete wxConfigBase::Set((wxConfigBase *) NULL); - p_ProgramCfg->Flush(TRUE); // saves Objekt - if (pDoc) // If we have a Valid Document - delete pDoc; // Cleanup (MainDoc::~MainDoc) + // Close the help frame; this will cause the config data to get written. + if (p_Help->GetFrame()) // returns NULL if no help frame active + p_Help->GetFrame()->Close(TRUE); + delete p_Help; // Memory Leak + p_Help = NULL; + // save the control's values to the config + if (p_ProgramCfg == NULL) + return; + // save the frame position before it is destroyed + int x, y, w, h; + GetPosition(&x, &y); + GetClientSize(&w, &h); w -= DiffW; h -= DiffH; + p_ProgramCfg->Write("/MainFrame/x", (long) x); + p_ProgramCfg->Write("/MainFrame/y", (long) y); + p_ProgramCfg->Write("/MainFrame/w", (long) w); + p_ProgramCfg->Write("/MainFrame/h", (long) h); + p_ProgramCfg->Write("/MainFrame/Sash", (long) pDoc->Sash); + // clean up: Set() returns the active config object as Get() does, but unlike + // Get() it doesn't try to create one if there is none (definitely not what + // we want here!) + // delete wxConfigBase::Set((wxConfigBase *) NULL); + p_ProgramCfg->Flush(TRUE); // saves Objekt + if (pDoc) // If we have a Valid Document + delete pDoc; // Cleanup (MainDoc::~MainDoc) } // MainFrame::~MainFrame(void) + //---------------------------------------------------------------------------------------- void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { - Close(TRUE); + Close(TRUE); } + //---------------------------------------------------------------------------------------- void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { - wxString Temp0, Temp1; - Temp0.Printf(_("%s\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 2000"),p_ProgramCfg->GetAppName().c_str()); - Temp1.Printf(_("About %s"),p_ProgramCfg->GetAppName().c_str()); - wxMessageDialog dialog(this, Temp0,Temp1,wxOK|wxCANCEL); - dialog.ShowModal(); + wxString Temp0, Temp1; + Temp0.Printf(_("%s\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 2000"),p_ProgramCfg->GetAppName().c_str()); + Temp1.Printf(_("About %s"),p_ProgramCfg->GetAppName().c_str()); + wxMessageDialog dialog(this, Temp0,Temp1,wxOK|wxCANCEL); + dialog.ShowModal(); } + //---------------------------------------------------------------------------------------- void MainFrame::OnHelp(wxCommandEvent& WXUNUSED(event)) { - p_Help->Display("Main page"); + p_Help->Display("Main page"); } //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/dbbrowse.h b/demos/dbbrowse/dbbrowse.h index 12596fdf90..43a4ff4fd6 100644 --- a/demos/dbbrowse/dbbrowse.h +++ b/demos/dbbrowse/dbbrowse.h @@ -12,34 +12,37 @@ //---------------------------------------------------------------------------------------- class MainFrame: public wxFrame { - public: - MainFrame(wxFrame *frame, char *title, const wxPoint& pos, const wxSize& size); - ~MainFrame(void); +public: + MainFrame(wxFrame *frame, char *title, const wxPoint& pos, const wxSize& size); + ~MainFrame(void); + +public: + // menu callbacks + void OnAbout(wxCommandEvent& event); + void OnHelp(wxCommandEvent& event); + void OnQuit(wxCommandEvent& event); + //-------------------------------------------------------------------------------------- + int DiffW, DiffH; // Needed the saving of Frame size + //-------------------------------------------------------------------------------------- + DocSplitterWindow *p_Splitter; // for Document Views + MainDoc *pDoc; // Self made Document + wxHtmlHelpController *p_Help; // Help System - public: - // menu callbacks - void OnAbout(wxCommandEvent& event); - void OnHelp(wxCommandEvent& event); - void OnQuit(wxCommandEvent& event); - //-------------------------------------------------------------------------------------- - int DiffW, DiffH; // Needed the saving of Frame size - //-------------------------------------------------------------------------------------- - DocSplitterWindow *p_Splitter; // for Document Views - MainDoc *pDoc; // Self made Document - wxHtmlHelpController *p_Help; // Help System - //-------------------------------------------------------------------------------------- - DECLARE_EVENT_TABLE() + //-------------------------------------------------------------------------------------- + DECLARE_EVENT_TABLE() }; + //---------------------------------------------------------------------------------------- // Define a new application type //---------------------------------------------------------------------------------------- class MainApp: public wxApp { - public: - MainFrame *frame; // The one and only MainFrame - bool OnInit(void); // Programmstart - wxLocale m_locale; // locale we'll be using and language support - MUST be here ! +public: + MainFrame *frame; // The one and only MainFrame + bool OnInit(void); // Programmstart + wxLocale m_locale; // locale we'll be using and language support - MUST be here ! }; + //---------------------------------------------------------------------------------------- // ID for the menu quit command //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/dbgrid.cpp b/demos/dbbrowse/dbgrid.cpp index f84b628f96..3412640ac7 100644 --- a/demos/dbbrowse/dbgrid.cpp +++ b/demos/dbbrowse/dbgrid.cpp @@ -31,28 +31,29 @@ #include "std.h" // sorgsam Pflegen ! //---------------------------------------------------------------------------------------- BEGIN_EVENT_TABLE(DBGrid, wxGrid) - EVT_MOTION (DBGrid::OnMouseMove) - // DBGrid - // ------------ - EVT_GRID_CELL_CHANGE( DBGrid::OnCellChange ) - EVT_GRID_CELL_LEFT_CLICK( DBGrid::OnCellLeftClick ) - EVT_GRID_CELL_LEFT_DCLICK( DBGrid::OnCellLeftDClick ) - EVT_GRID_CELL_RIGHT_CLICK( DBGrid::OnCellRightClick ) - EVT_GRID_CELL_RIGHT_DCLICK( DBGrid::OnCellRightDClick ) - // EVT_GRID_COL_SIZE( DBGrid::OnColSize ) - // EVT_GRID_ROW_SIZE( DBGrid::OnRowSize ) - EVT_GRID_EDITOR_SHOWN( DBGrid::OnEditorShown ) - EVT_GRID_EDITOR_HIDDEN( DBGrid::OnEditorHidden ) - EVT_GRID_LABEL_LEFT_CLICK( DBGrid::OnLabelLeftClick ) - EVT_GRID_LABEL_LEFT_DCLICK( DBGrid::OnLabelLeftDClick ) - EVT_GRID_LABEL_RIGHT_CLICK( DBGrid::OnLabelRightClick ) - EVT_GRID_LABEL_RIGHT_DCLICK( DBGrid::OnLabelRightDClick ) - EVT_GRID_RANGE_SELECT( DBGrid::OnRangeSelected ) - EVT_GRID_ROW_SIZE( DBGrid::OnRowSize ) - EVT_GRID_SELECT_CELL( DBGrid::OnSelectCell ) - EVT_MENU(GRID_EDIT,DBGrid::OnModusEdit) - EVT_MENU(GRID_BROWSE,DBGrid::OnModusBrowse) + EVT_MOTION (DBGrid::OnMouseMove) + // DBGrid + // ------------ + EVT_GRID_CELL_CHANGE( DBGrid::OnCellChange ) + EVT_GRID_CELL_LEFT_CLICK( DBGrid::OnCellLeftClick ) + EVT_GRID_CELL_LEFT_DCLICK( DBGrid::OnCellLeftDClick ) + EVT_GRID_CELL_RIGHT_CLICK( DBGrid::OnCellRightClick ) + EVT_GRID_CELL_RIGHT_DCLICK( DBGrid::OnCellRightDClick ) + // EVT_GRID_COL_SIZE( DBGrid::OnColSize ) + // EVT_GRID_ROW_SIZE( DBGrid::OnRowSize ) + EVT_GRID_EDITOR_SHOWN( DBGrid::OnEditorShown ) + EVT_GRID_EDITOR_HIDDEN( DBGrid::OnEditorHidden ) + EVT_GRID_LABEL_LEFT_CLICK( DBGrid::OnLabelLeftClick ) + EVT_GRID_LABEL_LEFT_DCLICK( DBGrid::OnLabelLeftDClick ) + EVT_GRID_LABEL_RIGHT_CLICK( DBGrid::OnLabelRightClick ) + EVT_GRID_LABEL_RIGHT_DCLICK( DBGrid::OnLabelRightDClick ) + EVT_GRID_RANGE_SELECT( DBGrid::OnRangeSelected ) + EVT_GRID_ROW_SIZE( DBGrid::OnRowSize ) + EVT_GRID_SELECT_CELL( DBGrid::OnSelectCell ) + EVT_MENU(GRID_EDIT,DBGrid::OnModusEdit) + EVT_MENU(GRID_BROWSE,DBGrid::OnModusBrowse) END_EVENT_TABLE() + //---------------------------------------------------------------------------------------- // wxListCtrl(parent, id, pos, size, style) // wxGrid(parent,-1,wxPoint( 0, 0 ), wxSize( 400, 300 ) ); @@ -62,340 +63,364 @@ END_EVENT_TABLE() // DBGrid::DBGrid(wxWindow *parent, const wxWindowID id,const wxPoint& pos,const wxSize& size): // wxGrid(parent, id, pos, size) DBGrid::DBGrid(wxWindow *parent, const wxWindowID id,const wxPoint& pos,const wxSize& size, long style): - wxGrid(parent, id, pos, size, style) +wxGrid(parent, id, pos, size, style) { - b_EditModus = FALSE; - //--------------------------------------------------------------------------------------- - popupMenu1 = new wxMenu(""); - popupMenu1->Append(GRID_EDIT, _("Edit Modus")); - popupMenu2 = new wxMenu(""); - popupMenu2->Append(GRID_BROWSE, _("Browse Modus")); + b_EditModus = FALSE; + //--------------------------------------------------------------------------------------- + popupMenu1 = new wxMenu(""); + popupMenu1->Append(GRID_EDIT, _("Edit Modus")); + popupMenu2 = new wxMenu(""); + popupMenu2->Append(GRID_BROWSE, _("Browse Modus")); } + //---------------------------------------------------------------------------------------- DBGrid::~DBGrid() { - delete popupMenu1; - delete popupMenu2; + delete popupMenu1; + delete popupMenu2; } + //---------------------------------------------------------------------------------------- int DBGrid::OnTableView(wxString Table) { - wxStopWatch sw; - //--------------------------------------------------------------------------------------- - int i=0,x,y,z, ValidTable=0; - wxString Temp0; - wxBeginBusyCursor(); - SetDefaultCellFont(* pDoc->ft_Doc); - //--------------------------------------------------------------------------------------- - ct_BrowserDB = (db_Br+i_Which)->ct_BrowserDB; // Get the DSN Pointer - //--------------------------------------------------------------------------------------- - if (ct_BrowserDB) // Valid pointer (!= NULL) ? - { // Pointer is Valid, use the wxDatabase Information - for (x=0;xnumTables;x++) // go through the Tables - { - if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableName,Table)) // is this our Table ? - { // Yes, the Data of this Table shall be put into the Grid - ValidTable = x; // Save the Tablenumber - (db_Br+i_Which)->OnSelect(Table,FALSE); // Select * from "table" - // Set the local Pointer to the Column Information we are going to use - (db_Br+i_Which)->cl_BrowserDB = (ct_BrowserDB->pTableInf+x)->pColInf; - if ((ct_BrowserDB->pTableInf+x)->pColInf) // Valid pointer (!= NULL) ? - { // Pointer is Valid, Column Informationen sind Vorhanden - i = (db_Br+i_Which)->i_Records; // How many Records are there - (db_Br+i_Which)->i_Which = ValidTable; // Still used ???? mj10777 - if (i == 0) // If the Table is empty, then show one empty row - i++; - // wxLogMessage(_("\n-I-> DBGrid::OnTableView() : Vor CreateGrid")); - CreateGrid(i,(ct_BrowserDB->pTableInf+x)->numCols); // Records , Columns - for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) // Loop through the Fields - { // The Field / Column name is used here as Row Titel - SetColLabelValue(y,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); - SetColSize(y,95); - } // for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) - SetColSize(((ct_BrowserDB->pTableInf+x)->numCols-1),120); // Make the last Column Wider - // The Grid has been created, now fill it - for (z=0;z<(db_Br+i_Which)->i_Records;z++) // Loop through the Records - { - Temp0.Printf("%06d",z+1); SetRowLabelValue(z,Temp0); // Set Row Lable Value - (db_Br+i_Which)->OnGetNext((ct_BrowserDB->pTableInf+ValidTable)->numCols,FALSE); - for (y=0;y<(ct_BrowserDB->pTableInf+ValidTable)->numCols;y++) // Loop through the Fields - { // BrowserDB::OnGetNext Formats the field Value into tablename - SetCellValue(z, y,((db_Br+i_Which)->cl_BrowserDB+y)->tableName); - } - if (z % 50 == 0) - { - Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - Record %6d (from %d) has been read."),Table.c_str(),z,(db_Br+i_Which)->i_Records); - pDoc->p_MainFrame->SetStatusText(Temp0, 0); - } - } // for (z=0;z<(db_Br+i_Which)->i_Records;z++) - Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - %6d Records have been read. - Time needed : %ld ms"),Table.c_str(),z,sw.Time()); - wxLogMessage(Temp0); - pDoc->p_MainFrame->SetStatusText(Temp0, 0); - // The Grid has been filled, now leave - goto Weiter; - } // if ((ct_BrowserDB->pTableInf+x)->pColInf) + wxStopWatch sw; + //--------------------------------------------------------------------------------------- + int i=0,x,y,z, ValidTable=0; + wxString Temp0; + wxBeginBusyCursor(); + SetDefaultCellFont(* pDoc->ft_Doc); + //--------------------------------------------------------------------------------------- + ct_BrowserDB = (db_Br+i_Which)->ct_BrowserDB; // Get the DSN Pointer + //--------------------------------------------------------------------------------------- + if (ct_BrowserDB) // Valid pointer (!= NULL) ? + { // Pointer is Valid, use the wxDatabase Information + for (x=0;xnumTables;x++) // go through the Tables + { + if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableName,Table)) // is this our Table ? + { // Yes, the Data of this Table shall be put into the Grid + ValidTable = x; // Save the Tablenumber + (db_Br+i_Which)->OnSelect(Table,FALSE); // Select * from "table" + // Set the local Pointer to the Column Information we are going to use + (db_Br+i_Which)->cl_BrowserDB = (ct_BrowserDB->pTableInf+x)->pColInf; + if ((ct_BrowserDB->pTableInf+x)->pColInf) // Valid pointer (!= NULL) ? + { // Pointer is Valid, Column Informationen sind Vorhanden + i = (db_Br+i_Which)->i_Records; // How many Records are there + (db_Br+i_Which)->i_Which = ValidTable; // Still used ???? mj10777 + if (i == 0) // If the Table is empty, then show one empty row + i++; + // wxLogMessage(_("\n-I-> DBGrid::OnTableView() : Vor CreateGrid")); + CreateGrid(i,(ct_BrowserDB->pTableInf+x)->numCols); // Records , Columns + for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) // Loop through the Fields + { // The Field / Column name is used here as Row Titel + SetColLabelValue(y,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); + SetColSize(y,95); + } // for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) + SetColSize(((ct_BrowserDB->pTableInf+x)->numCols-1),120); // Make the last Column Wider + // The Grid has been created, now fill it + for (z=0;z<(db_Br+i_Which)->i_Records;z++) // Loop through the Records + { + Temp0.Printf("%06d",z+1); SetRowLabelValue(z,Temp0); // Set Row Lable Value + (db_Br+i_Which)->OnGetNext((ct_BrowserDB->pTableInf+ValidTable)->numCols,FALSE); + for (y=0;y<(ct_BrowserDB->pTableInf+ValidTable)->numCols;y++) // Loop through the Fields + { // BrowserDB::OnGetNext Formats the field Value into tablename + SetCellValue(z, y,((db_Br+i_Which)->cl_BrowserDB+y)->tableName); + } + if (z % 50 == 0) + { + Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - Record %6d (from %d) has been read."),Table.c_str(),z,(db_Br+i_Which)->i_Records); + pDoc->p_MainFrame->SetStatusText(Temp0, 0); + } + } // for (z=0;z<(db_Br+i_Which)->i_Records;z++) + Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - %6d Records have been read. - Time needed : %ld ms"),Table.c_str(),z,sw.Time()); + wxLogMessage(Temp0); + pDoc->p_MainFrame->SetStatusText(Temp0, 0); + // The Grid has been filled, now leave + goto Weiter; + } // if ((ct_BrowserDB->pTableInf+x)->pColInf) + else + wxLogMessage(_("\n-E-> DBGrid::OnTableView() : Invalid Column Pointer : Failed")); + } // if ((ct_BrowserDB->pTableInf+x)->tableType == "TABLE") + } // for (x=0;xnumTables;x++) + } // if (ct_BrowserDB) else - wxLogMessage(_("\n-E-> DBGrid::OnTableView() : Invalid Column Pointer : Failed")); - } // if ((ct_BrowserDB->pTableInf+x)->tableType == "TABLE") - } // for (x=0;xnumTables;x++) - } // if (ct_BrowserDB) - else - wxLogMessage(_("\n-E-> DBGrid::OnTableView() : Invalid DSN Pointer : Failed")); - //--------------------------------------------------------------------------------------- - Weiter: - EnableEditing(b_EditModus); // Deactivate in-place Editing - wxEndBusyCursor(); - //--------------------------------------------------------------------------------------- - wxLogMessage(_("-I-> DBGrid::OnTableView() - End")); - return 0; + wxLogMessage(_("\n-E-> DBGrid::OnTableView() : Invalid DSN Pointer : Failed")); + //--------------------------------------------------------------------------------------- +Weiter: + EnableEditing(b_EditModus); // Deactivate in-place Editing + wxEndBusyCursor(); + //--------------------------------------------------------------------------------------- + wxLogMessage(_("-I-> DBGrid::OnTableView() - End")); + return 0; } + //---------------------------------------------------------------------------------------- void DBGrid::OnModusEdit(wxCommandEvent& event) { - b_EditModus = TRUE; // Needed by PopupMenu - EnableEditing(b_EditModus); // Activate in-place Editing - UpdateDimensions(); // Redraw the Grid - // wxLogMessage(_("-I-> DBGrid::OnModusEdit() - End")); + b_EditModus = TRUE; // Needed by PopupMenu + EnableEditing(b_EditModus); // Activate in-place Editing + UpdateDimensions(); // Redraw the Grid + // wxLogMessage(_("-I-> DBGrid::OnModusEdit() - End")); } + //---------------------------------------------------------------------------------------- void DBGrid::OnModusBrowse(wxCommandEvent& event) { - b_EditModus = FALSE; // Needed by PopupMenu - EnableEditing(b_EditModus); // Deactivate in-place Editing - UpdateDimensions(); // Redraw the Grid - // wxLogMessage(_("-I-> DBGrid::OnModusBrowse() - End")); + b_EditModus = FALSE; // Needed by PopupMenu + EnableEditing(b_EditModus); // Deactivate in-place Editing + UpdateDimensions(); // Redraw the Grid + // wxLogMessage(_("-I-> DBGrid::OnModusBrowse() - End")); } + //---------------------------------------------------------------------------------------- void DBGrid::OnEditorShown( wxGridEvent& ev ) { - // wxLogMessage(_("-I-> DBGrid::OnEditorShown() - End")); - ev.Skip(); + // wxLogMessage(_("-I-> DBGrid::OnEditorShown() - End")); + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnEditorHidden( wxGridEvent& ev ) { - // wxLogMessage(_("-I-> DBGrid::OnEditorHidden() - End")); - ev.Skip(); + // wxLogMessage(_("-I-> DBGrid::OnEditorHidden() - End")); + ev.Skip(); } + +//---------------------------------------------------------------------------------------- void DBGrid::OnSelectCell( wxGridEvent& ev ) { - logBuf = ""; - logBuf << "Selected cell at row " << ev.GetRow() + logBuf = ""; + logBuf << "Selected cell at row " << ev.GetRow() << " col " << ev.GetCol(); - wxLogMessage( "%s", logBuf.c_str() ); - // you must call Skip() if you want the default processing - // to occur in wxGrid - ev.Skip(); + wxLogMessage( "%s", logBuf.c_str() ); + // you must call Skip() if you want the default processing + // to occur in wxGrid + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnMouseMove(wxMouseEvent &event) { - MousePos = event.GetPosition(); + MousePos = event.GetPosition(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnLabelLeftClick( wxGridEvent& ev ) { - logBuf = "DBGrid::OnLabelLeftClick : "; - if ( ev.GetRow() != -1 ) - { - logBuf << "row label " << ev.GetRow(); - } - else if ( ev.GetCol() != -1 ) - { - logBuf << "col label " << ev.GetCol(); - } - else - { - logBuf << "corner label"; - } - if ( ev.ShiftDown() ) - logBuf << " (shift down)"; - // wxLogMessage( "%s", logBuf.c_str() ); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - ev.Skip(); + logBuf = "DBGrid::OnLabelLeftClick : "; + if ( ev.GetRow() != -1 ) + { + logBuf << "row label " << ev.GetRow(); + } + else if ( ev.GetCol() != -1 ) + { + logBuf << "col label " << ev.GetCol(); + } + else + { + logBuf << "corner label"; + } + if ( ev.ShiftDown() ) + logBuf << " (shift down)"; + + // wxLogMessage( "%s", logBuf.c_str() ); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnLabelRightClick( wxGridEvent& ev ) { - //------------------------------------------------------- - if (b_EditModus) - PopupMenu(popupMenu2,MousePos.x,MousePos.y); - else - PopupMenu(popupMenu1,MousePos.x,MousePos.y); - //------------------- - logBuf = "DBGrid::OnLabelRightClick : "; - if ( ev.GetRow() != -1 ) - { - logBuf << "row label " << ev.GetRow(); - } - else if ( ev.GetCol() != -1 ) - { - logBuf << "col label " << ev.GetCol(); - } - else - { - logBuf << "corner label"; - } - if ( ev.ShiftDown() ) - logBuf << " (shift down)"; - // wxLogMessage( "%s", logBuf.c_str() ); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - ev.Skip(); + //------------------------------------------------------- + if (b_EditModus) + PopupMenu(popupMenu2,MousePos.x,MousePos.y); + else + PopupMenu(popupMenu1,MousePos.x,MousePos.y); + //------------------- + logBuf = "DBGrid::OnLabelRightClick : "; + if ( ev.GetRow() != -1 ) + { + logBuf << "row label " << ev.GetRow(); + } + else if ( ev.GetCol() != -1 ) + { + logBuf << "col label " << ev.GetCol(); + } + else + { + logBuf << "corner label"; + } + if ( ev.ShiftDown() ) + logBuf << " (shift down)"; + + // wxLogMessage( "%s", logBuf.c_str() ); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnLabelLeftDClick( wxGridEvent& ev ) { - logBuf = "DBGrid::OnLabelLeftDClick : "; - if ( ev.GetRow() != -1 ) - { - logBuf << "row label " << ev.GetRow(); - } - else if ( ev.GetCol() != -1 ) - { - logBuf << "col label " << ev.GetCol(); - } - else - { - logBuf << "corner label"; - } - if ( ev.ShiftDown() ) - logBuf << " (shift down)"; - // wxLogMessage( "%s", logBuf.c_str() ); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - ev.Skip(); + logBuf = "DBGrid::OnLabelLeftDClick : "; + if ( ev.GetRow() != -1 ) + { + logBuf << "row label " << ev.GetRow(); + } + else if ( ev.GetCol() != -1 ) + { + logBuf << "col label " << ev.GetCol(); + } + else + { + logBuf << "corner label"; + } + if ( ev.ShiftDown() ) + logBuf << " (shift down)"; + + // wxLogMessage( "%s", logBuf.c_str() ); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnLabelRightDClick( wxGridEvent& ev ) { - logBuf = "DBGrid::OnLabelRightDClick : "; - if ( ev.GetRow() != -1 ) - { - logBuf << "row label " << ev.GetRow(); - } - else if ( ev.GetCol() != -1 ) - { - logBuf << "col label " << ev.GetCol(); - } - else - { - logBuf << "corner label"; - } - if ( ev.ShiftDown() ) - logBuf << " (shift down)"; - // wxLogMessage( "%s", logBuf.c_str() ); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - ev.Skip(); + logBuf = "DBGrid::OnLabelRightDClick : "; + if ( ev.GetRow() != -1 ) + { + logBuf << "row label " << ev.GetRow(); + } + else if ( ev.GetCol() != -1 ) + { + logBuf << "col label " << ev.GetCol(); + } + else + { + logBuf << "corner label"; + } + if ( ev.ShiftDown() ) + logBuf << " (shift down)"; + // wxLogMessage( "%s", logBuf.c_str() ); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnCellLeftClick( wxGridEvent& ev ) { - logBuf = "DBGrid::OnCellLeftClick : "; - logBuf << "Cell at row " << ev.GetRow() - << " col " << ev.GetCol(); - // wxLogMessage( "%s", logBuf.c_str() ); - // wxMessageBox(logBuf); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - // you must call event skip if you want default grid processing - // (cell highlighting etc.) - // - ev.Skip(); + logBuf = "DBGrid::OnCellLeftClick : "; + logBuf << "Cell at row " << ev.GetRow() + << " col " << ev.GetCol(); + // wxLogMessage( "%s", logBuf.c_str() ); + // wxMessageBox(logBuf); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + // you must call event skip if you want default grid processing + // (cell highlighting etc.) + // + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnCellRightClick( wxGridEvent& ev ) { - logBuf = "DBGrid::OnCellRightClick : "; - logBuf << "Cell at row " << ev.GetRow() - << " col " << ev.GetCol(); - // wxLogMessage( "%s", logBuf.c_str() ); - // wxMessageBox(logBuf); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - // you must call event skip if you want default grid processing - // (cell highlighting etc.) - // - ev.Skip(); + logBuf = "DBGrid::OnCellRightClick : "; + logBuf << "Cell at row " << ev.GetRow() + << " col " << ev.GetCol(); + // wxLogMessage( "%s", logBuf.c_str() ); + // wxMessageBox(logBuf); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + // you must call event skip if you want default grid processing + // (cell highlighting etc.) + // + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnCellLeftDClick( wxGridEvent& ev ) { - logBuf = "DBGrid::OnCellLeftDClick : "; - logBuf << "Cell at row " << ev.GetRow() - << " col " << ev.GetCol(); - // wxLogMessage( "%s", logBuf.c_str() ); - // wxMessageBox(logBuf); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - // you must call event skip if you want default grid processing - // (cell highlighting etc.) - // - ev.Skip(); + logBuf = "DBGrid::OnCellLeftDClick : "; + logBuf << "Cell at row " << ev.GetRow() + << " col " << ev.GetCol(); + // wxLogMessage( "%s", logBuf.c_str() ); + // wxMessageBox(logBuf); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + // you must call event skip if you want default grid processing + // (cell highlighting etc.) + // + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnCellRightDClick( wxGridEvent& ev ) { - logBuf = "DBGrid::OnCellRightDClick : "; - logBuf << "Cell at row " << ev.GetRow() - << " col " << ev.GetCol(); - // wxLogMessage( "%s", logBuf.c_str() ); - // wxMessageBox(logBuf); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - // you must call event skip if you want default grid processing - // (cell highlighting etc.) - // - ev.Skip(); + logBuf = "DBGrid::OnCellRightDClick : "; + logBuf << "Cell at row " << ev.GetRow() + << " col " << ev.GetCol(); + // wxLogMessage( "%s", logBuf.c_str() ); + // wxMessageBox(logBuf); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + // you must call event skip if you want default grid processing + // (cell highlighting etc.) + // + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnCellChange( wxGridEvent& ev ) { - logBuf = "DBGrid::OnCellChange : "; - logBuf << "Cell at row " << ev.GetRow() - << " col " << ev.GetCol(); - // wxLogMessage( "%s", logBuf.c_str() ); - // wxMessageBox(logBuf); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - // you must call event skip if you want default grid processing - // (cell highlighting etc.) - // - ev.Skip(); + logBuf = "DBGrid::OnCellChange : "; + logBuf << "Cell at row " << ev.GetRow() + << " col " << ev.GetCol(); + // wxLogMessage( "%s", logBuf.c_str() ); + // wxMessageBox(logBuf); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + // you must call event skip if you want default grid processing + // (cell highlighting etc.) + // + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnRowSize( wxGridSizeEvent& ev ) { - logBuf = "DBGrid::OnRowSize : "; - logBuf << "Resized row " << ev.GetRowOrCol(); - // wxLogMessage( "%s", logBuf.c_str() ); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - ev.Skip(); + logBuf = "DBGrid::OnRowSize : "; + logBuf << "Resized row " << ev.GetRowOrCol(); + // wxLogMessage( "%s", logBuf.c_str() ); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnColSize( wxGridSizeEvent& ev ) { - logBuf = "DBGrid::OnColSize : "; - logBuf << "Resized col " << ev.GetRowOrCol(); - // wxLogMessage( "%s", logBuf.c_str() ); - logBuf += "\n"; - wxLogMessage(logBuf.c_str()); - ev.Skip(); + logBuf = "DBGrid::OnColSize : "; + logBuf << "Resized col " << ev.GetRowOrCol(); + // wxLogMessage( "%s", logBuf.c_str() ); + logBuf += "\n"; + wxLogMessage(logBuf.c_str()); + ev.Skip(); } + //---------------------------------------------------------------------------------------- void DBGrid::OnRangeSelected( wxGridRangeSelectEvent& ev ) { - logBuf = "DBGrid::OnRangeSelected : "; - logBuf << "Selected cells from row " << ev.GetTopRow() - << " col " << ev.GetLeftCol() - << " to row " << ev.GetBottomRow() - << " col " << ev.GetRightCol(); - logBuf += "\n"; - // wxLogMessage( "%s", logBuf.c_str() ); - wxLogMessage(logBuf.c_str()); - ev.Skip(); + logBuf = "DBGrid::OnRangeSelected : "; + logBuf << "Selected cells from row " << ev.GetTopRow() + << " col " << ev.GetLeftCol() + << " to row " << ev.GetBottomRow() + << " col " << ev.GetRightCol(); + logBuf += "\n"; + // wxLogMessage( "%s", logBuf.c_str() ); + wxLogMessage(logBuf.c_str()); + ev.Skip(); } //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/dbgrid.h b/demos/dbbrowse/dbgrid.h index 9335dddcd6..1037a81b55 100644 --- a/demos/dbbrowse/dbgrid.h +++ b/demos/dbbrowse/dbgrid.h @@ -9,57 +9,61 @@ // RCS-ID: $Id$ //---------------------------------------------------------------------------------------- #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) - #error "DBGrid requires the new wxGrid class" +#error "DBGrid requires the new wxGrid class" #endif + //---------------------------------------------------------------------------------------- class MainDoc; + //---------------------------------------------------------------------------------------- class DBGrid: public wxGrid { - public: - DBGrid(wxWindow *parent, const wxWindowID id,const wxPoint& pos,const wxSize& size, long style); - virtual ~DBGrid(); - //--------------------------------------------------------------------------------------- - int i_TabArt; // Tab = 0 ; Page = 1; - int i_ViewNr; // View Nummer in Tab / Page - int i_Which; // Which View, Database is this/using - //--------------------------------------------------------------------------------------- - MainDoc* pDoc; - wxDbInf* ct_BrowserDB; - BrowserDB* db_Br; - wxMenu *popupMenu1; // OnDBClass - wxMenu *popupMenu2; // OnDBGrid & OnTableclass - bool b_EditModus; - //--------------------------------------------------------------------------------------- - wxString logBuf,Temp0; - wxPoint MousePos; - //--------------------------------------------------------------------------------------- - void OnModusEdit(wxCommandEvent& event); - void OnModusBrowse(wxCommandEvent& event); - void OnMouseMove(wxMouseEvent& event); - int OnTableView(wxString Table); - //----- - void OnCellChange( wxGridEvent& ); - void OnCellLeftClick( wxGridEvent& ); - void OnCellLeftDClick( wxGridEvent& ); - void OnCellRightClick( wxGridEvent& ); - void OnCellRightDClick( wxGridEvent& ); - void OnColSize( wxGridSizeEvent& ); - void OnEditorShown( wxGridEvent& ); - void OnEditorHidden( wxGridEvent& ); - void OnLabelLeftClick( wxGridEvent& ); - void OnLabelLeftDClick( wxGridEvent& ); - void OnLabelRightClick( wxGridEvent& ); - void OnLabelRightDClick( wxGridEvent& ); - void OnRangeSelected( wxGridRangeSelectEvent& ); - void OnRowSize( wxGridSizeEvent& ); - void OnSelectCell( wxGridEvent& ); - //--------------------------------------------------------------------------------------- - DECLARE_EVENT_TABLE() +public: + DBGrid(wxWindow *parent, const wxWindowID id,const wxPoint& pos,const wxSize& size, long style); + virtual ~DBGrid(); + //--------------------------------------------------------------------------------------- + int i_TabArt; // Tab = 0 ; Page = 1; + int i_ViewNr; // View Nummer in Tab / Page + int i_Which; // Which View, Database is this/using + //--------------------------------------------------------------------------------------- + MainDoc* pDoc; + wxDbInf* ct_BrowserDB; + BrowserDB* db_Br; + wxMenu *popupMenu1; // OnDBClass + wxMenu *popupMenu2; // OnDBGrid & OnTableclass + bool b_EditModus; + //--------------------------------------------------------------------------------------- + wxString logBuf,Temp0; + wxPoint MousePos; + //--------------------------------------------------------------------------------------- + void OnModusEdit(wxCommandEvent& event); + void OnModusBrowse(wxCommandEvent& event); + void OnMouseMove(wxMouseEvent& event); + int OnTableView(wxString Table); + //----- + void OnCellChange( wxGridEvent& ); + void OnCellLeftClick( wxGridEvent& ); + void OnCellLeftDClick( wxGridEvent& ); + void OnCellRightClick( wxGridEvent& ); + void OnCellRightDClick( wxGridEvent& ); + void OnColSize( wxGridSizeEvent& ); + void OnEditorShown( wxGridEvent& ); + void OnEditorHidden( wxGridEvent& ); + void OnLabelLeftClick( wxGridEvent& ); + void OnLabelLeftDClick( wxGridEvent& ); + void OnLabelRightClick( wxGridEvent& ); + void OnLabelRightDClick( wxGridEvent& ); + void OnRangeSelected( wxGridRangeSelectEvent& ); + void OnRowSize( wxGridSizeEvent& ); + void OnSelectCell( wxGridEvent& ); + //--------------------------------------------------------------------------------------- + DECLARE_EVENT_TABLE() }; + //---------------------------------------------------------------------------------------- #define GRID_01_BEGIN 1200 #define GRID_BROWSE 1201 #define GRID_EDIT 1202 #define GRID_01_END 1203 //---------------------------------------------------------------------------------------- + diff --git a/demos/dbbrowse/dbtree.cpp b/demos/dbbrowse/dbtree.cpp index 1ee46028e4..d61d111850 100644 --- a/demos/dbbrowse/dbtree.cpp +++ b/demos/dbbrowse/dbtree.cpp @@ -32,385 +32,403 @@ //-- all #includes that every .cpp needs --- 19990807.mj10777 ---------------- //---------------------------------------------------------------------------------------- #include "std.h" // sorgsam Pflegen ! + //---------------------------------------------------------------------------------------- //-- Global functions -------------------------------------------------------------------- //---------------------------------------------------------------------------------------- static inline const char *bool2String(bool b) { - return b ? "" : "not "; + return b ? "" : "not "; } + //---------------------------------------------------------------------------------------- BEGIN_EVENT_TABLE(DBTree, wxTreeCtrl) - EVT_MOTION (DBTree::OnMouseMove) - EVT_TREE_SEL_CHANGED(TREE_CTRL_DB, DBTree::OnSelChanged) - EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_DB,DBTree::OnRightSelect) - EVT_MENU(DATA_SHOW,DBTree::OnDBGrid) - EVT_MENU(DATA_DB,DBTree::OnDBClass) - EVT_MENU(DATA_TABLE,DBTree::OnTableClass) - EVT_MENU(DATA_TABLE_ALL,DBTree::OnTableClassAll) + EVT_MOTION (DBTree::OnMouseMove) + EVT_TREE_SEL_CHANGED(TREE_CTRL_DB, DBTree::OnSelChanged) + EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_DB,DBTree::OnRightSelect) + EVT_MENU(DATA_SHOW,DBTree::OnDBGrid) + EVT_MENU(DATA_DB,DBTree::OnDBClass) + EVT_MENU(DATA_TABLE,DBTree::OnTableClass) + EVT_MENU(DATA_TABLE_ALL,DBTree::OnTableClassAll) END_EVENT_TABLE() //---------------------------------------------------------------------------------------- // DBTree implementation //---------------------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(DBTree, wxTreeCtrl) + //---------------------------------------------------------------------------------------- DBTree::DBTree(wxWindow *parent) : wxTreeCtrl(parent) { } + //---------------------------------------------------------------------------------------- DBTree::DBTree(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size, long style) - : wxTreeCtrl(parent, id, pos, size, style) +: wxTreeCtrl(parent, id, pos, size, style) { - // Make an image list containing small icons - p_imageListNormal = new wxImageList(16, 16, TRUE); - // should correspond to TreeIc_xxx enum + // Make an image list containing small icons + p_imageListNormal = new wxImageList(16, 16, TRUE); + // should correspond to TreeIc_xxx enum #if !defined(__WXMSW__) - #include "bitmaps/logo.xpm" - #include "bitmaps/dsnclose.xpm" - #include "bitmaps/dsnopen.xpm" - #include "bitmaps/tab.xpm" - #include "bitmaps/view.xpm" - #include "bitmaps/col.xpm" - #include "bitmaps/key.xpm" - #include "bitmaps/keyf.xpm" - #include "bitmaps/d_open.xpm" - #include "bitmaps/d_closed.xpm" +#include "bitmaps/logo.xpm" +#include "bitmaps/dsnclose.xpm" +#include "bitmaps/dsnopen.xpm" +#include "bitmaps/tab.xpm" +#include "bitmaps/view.xpm" +#include "bitmaps/col.xpm" +#include "bitmaps/key.xpm" +#include "bitmaps/keyf.xpm" +#include "bitmaps/d_open.xpm" +#include "bitmaps/d_closed.xpm" #endif - p_imageListNormal->Add(wxICON(aLogo)); - p_imageListNormal->Add(wxICON(DsnClosed)); - p_imageListNormal->Add(wxICON(DsnOpen)); - p_imageListNormal->Add(wxICON(TAB)); - p_imageListNormal->Add(wxICON(VIEW)); - p_imageListNormal->Add(wxICON(COL)); - p_imageListNormal->Add(wxICON(KEY)); - p_imageListNormal->Add(wxICON(KEYF)); - p_imageListNormal->Add(wxICON(DocOpen)); - p_imageListNormal->Add(wxICON(DocOpen)); - SetImageList(p_imageListNormal); - ct_BrowserDB = NULL; - popupMenu1 = NULL; - popupMenu2 = NULL; + p_imageListNormal->Add(wxICON(aLogo)); + p_imageListNormal->Add(wxICON(DsnClosed)); + p_imageListNormal->Add(wxICON(DsnOpen)); + p_imageListNormal->Add(wxICON(TAB)); + p_imageListNormal->Add(wxICON(VIEW)); + p_imageListNormal->Add(wxICON(COL)); + p_imageListNormal->Add(wxICON(KEY)); + p_imageListNormal->Add(wxICON(KEYF)); + p_imageListNormal->Add(wxICON(DocOpen)); + p_imageListNormal->Add(wxICON(DocOpen)); + SetImageList(p_imageListNormal); + ct_BrowserDB = NULL; + popupMenu1 = NULL; + popupMenu2 = NULL; } + //---------------------------------------------------------------------------------------- DBTree::~DBTree() { -// delete (pDoc->db_Br+i_Which); - // wxLogMessage("DBTree::~DBTree() - Vor OnCloseDB()"); - (pDoc->db_Br+i_Which)->OnCloseDB(FALSE); - // wxLogMessage("DBTree::~DBTree() - Nach OnCloseDB()"); - (pDoc->db_Br+i_Which)->db_BrowserDB = NULL; - (pDoc->db_Br+i_Which)->ct_BrowserDB = NULL; - (pDoc->db_Br+i_Which)->cl_BrowserDB = NULL; + delete ct_BrowserDB; + + // delete (pDoc->db_Br+i_Which); + // wxLogMessage("DBTree::~DBTree() - Vor OnCloseDB()"); + (pDoc->db_Br+i_Which)->OnCloseDB(FALSE); + // wxLogMessage("DBTree::~DBTree() - Nach OnCloseDB()"); + (pDoc->db_Br+i_Which)->db_BrowserDB = NULL; + (pDoc->db_Br+i_Which)->ct_BrowserDB = NULL; + (pDoc->db_Br+i_Which)->cl_BrowserDB = NULL; - delete ct_BrowserDB; - delete p_imageListNormal; - if (popupMenu1) // If the DSN has no Tables, then no delete should be done ! - delete popupMenu1; - if (popupMenu1) // If the DSN has no Tables, then no delete should be done ! - delete popupMenu2; + delete p_imageListNormal; + if (popupMenu1) // If the DSN has no Tables, then no delete should be done ! + delete popupMenu1; + if (popupMenu1) // If the DSN has no Tables, then no delete should be done ! + delete popupMenu2; } + //---------------------------------------------------------------------------------------- #undef TREE_EVENT_HANDLER + //---------------------------------------------------------------------------------------- -int DBTree::OnPopulate() +int DBTree::OnPopulate() { - wxTreeItemId Root, Folder, Docu, Funkt; - int i,x,y,z=0, TableType; - wxString SQL_TYPE, DB_TYPE; - SetFont(* pDoc->ft_Doc); - //--------------------------------------------------------------------------------------- - if ((pDoc->db_Br+i_Which)->Initialize(FALSE)) - { - wxStopWatch sw; - wxBeginBusyCursor(); - ct_BrowserDB = (pDoc->db_Br+i_Which)->OnGetCatalog(FALSE); - if (ct_BrowserDB) - { // Use the wxDatabase Information - Temp0.Printf("%s - (%s) (%s)", s_DSN.c_str(),ct_BrowserDB->catalog, ct_BrowserDB->schema); - Root = AddRoot(Temp0,TreeIc_DsnOpen,TreeIc_DsnOpen,new DBTreeData("Root")); - for (x=0;xnumTables;x++) - { - wxYield(); - TableType = 0; // TABLE = 1 ; VIEW = 2 ; 0 We are not interested in - if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableType,"TABLE")) // only TABLES - TableType = 1; - if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableType,"VIEW")) // and VIEWS - TableType = 2; - if (TableType) // only TABLES or Views + wxTreeItemId Root, Folder, Docu, Funkt; + int i,x,y,z=0, TableType; + wxString SQL_TYPE, DB_TYPE; + SetFont(* pDoc->ft_Doc); + //--------------------------------------------------------------------------------------- + if ((pDoc->db_Br+i_Which)->Initialize(FALSE)) { - Temp1.Printf("TN(%s",(ct_BrowserDB->pTableInf+x)->tableName); - //---- - (ct_BrowserDB->pTableInf+x)->pColInf = (pDoc->db_Br+i_Which)->OnGetColumns((ct_BrowserDB->pTableInf+x)->tableName,(ct_BrowserDB->pTableInf+x)->numCols,FALSE); - //---- - if ((ct_BrowserDB->pTableInf+x)->pColInf) - { - if (TableType == 1) // Table - { - Temp0.Printf(_("Table-Name(%s) with (%d)Columns ; Remarks(%s)"), (ct_BrowserDB->pTableInf+x)->tableName, - (ct_BrowserDB->pTableInf+x)->numCols,(ct_BrowserDB->pTableInf+x)->tableRemarks); - Folder = AppendItem(Root,Temp0,TreeIc_TAB,TreeIc_TAB, new DBTreeData(Temp1)); - } - if (TableType == 2) // View - { - Temp0.Printf(_("View-Name(%s) with (%d)Columns ; Remarks(%s)"), (ct_BrowserDB->pTableInf+x)->tableName, - (ct_BrowserDB->pTableInf+x)->numCols,(ct_BrowserDB->pTableInf+x)->tableRemarks); - Folder = AppendItem(Root,Temp0,TreeIc_VIEW,TreeIc_VIEW, new DBTreeData(Temp1)); - } - for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) - { - Temp1.Printf("FN(%s",((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); - // Here is where we find out if the Column is a Primary / Foreign Key - if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->PkCol != 0) // Primary Key - { - Temp2.Printf("(%d) - %s",((ct_BrowserDB->pTableInf+x)->pColInf+y)->PkCol,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); - Docu = AppendItem(Folder,Temp2,TreeIc_KEY,TreeIc_KEY,new DBTreeData(Temp1)); - Temp2 = ((ct_BrowserDB->pTableInf+x)->pColInf+y)->PkTableName; - if (Temp2 == "") - Temp2 = _("None"); - Temp2.Printf(_("This Primary Key is used in the following Tables : %s"),Temp2.c_str()); - Funkt = AppendItem(Docu,Temp2,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData("KEY")); - } - else - { - if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->FkCol != 0) // Foreign Key - { - Temp2.Printf("(%d) - %s",((ct_BrowserDB->pTableInf+x)->pColInf+y)->FkCol,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); - Docu = AppendItem(Folder,Temp2,TreeIc_KEYF,TreeIc_KEYF,new DBTreeData(Temp1)); - Temp2.Printf(_("This Foreign Key comes from the following Table : %s"),((ct_BrowserDB->pTableInf+x)->pColInf+y)->FkTableName); - Funkt = AppendItem(Docu,Temp2,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData("KEYF")); - } + wxStopWatch sw; + wxBeginBusyCursor(); + ct_BrowserDB = (pDoc->db_Br+i_Which)->OnGetCatalog(FALSE); + if (ct_BrowserDB) + { // Use the wxDatabase Information + Temp0.Printf("%s - (%s) (%s)", s_DSN.c_str(),ct_BrowserDB->catalog, ct_BrowserDB->schema); + Root = AddRoot(Temp0,TreeIc_DsnOpen,TreeIc_DsnOpen,new DBTreeData("Root")); + for (x=0;xnumTables;x++) + { + wxYield(); + TableType = 0; // TABLE = 1 ; VIEW = 2 ; 0 We are not interested in + if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableType,"TABLE")) // only TABLES + TableType = 1; + if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableType,"VIEW")) // and VIEWS + TableType = 2; + if (TableType) // only TABLES or Views + { + Temp1.Printf("TN(%s",(ct_BrowserDB->pTableInf+x)->tableName); + //---- + (ct_BrowserDB->pTableInf+x)->pColInf = (pDoc->db_Br+i_Which)->OnGetColumns((ct_BrowserDB->pTableInf+x)->tableName,(ct_BrowserDB->pTableInf+x)->numCols,FALSE); + //---- + if ((ct_BrowserDB->pTableInf+x)->pColInf) + { + if (TableType == 1) // Table + { + Temp0.Printf(_("Table-Name(%s) with (%d)Columns ; Remarks(%s)"), (ct_BrowserDB->pTableInf+x)->tableName, + (ct_BrowserDB->pTableInf+x)->numCols,(ct_BrowserDB->pTableInf+x)->tableRemarks); + Folder = AppendItem(Root,Temp0,TreeIc_TAB,TreeIc_TAB, new DBTreeData(Temp1)); + } + if (TableType == 2) // View + { + Temp0.Printf(_("View-Name(%s) with (%d)Columns ; Remarks(%s)"), (ct_BrowserDB->pTableInf+x)->tableName, + (ct_BrowserDB->pTableInf+x)->numCols,(ct_BrowserDB->pTableInf+x)->tableRemarks); + Folder = AppendItem(Root,Temp0,TreeIc_VIEW,TreeIc_VIEW, new DBTreeData(Temp1)); + } + for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) + { + Temp1.Printf("FN(%s",((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); + // Here is where we find out if the Column is a Primary / Foreign Key + if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->PkCol != 0) // Primary Key + { + Temp2.Printf("(%d) - %s",((ct_BrowserDB->pTableInf+x)->pColInf+y)->PkCol,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); + Docu = AppendItem(Folder,Temp2,TreeIc_KEY,TreeIc_KEY,new DBTreeData(Temp1)); + Temp2 = ((ct_BrowserDB->pTableInf+x)->pColInf+y)->PkTableName; + if (Temp2 == "") + Temp2 = _("None"); + Temp2.Printf(_("This Primary Key is used in the following Tables : %s"),Temp2.c_str()); + Funkt = AppendItem(Docu,Temp2,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData("KEY")); + } + else + { + if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->FkCol != 0) // Foreign Key + { + Temp2.Printf("(%d) - %s",((ct_BrowserDB->pTableInf+x)->pColInf+y)->FkCol,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); + Docu = AppendItem(Folder,Temp2,TreeIc_KEYF,TreeIc_KEYF,new DBTreeData(Temp1)); + Temp2.Printf(_("This Foreign Key comes from the following Table : %s"),((ct_BrowserDB->pTableInf+x)->pColInf+y)->FkTableName); + Funkt = AppendItem(Docu,Temp2,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData("KEYF")); + } + else + Docu = AppendItem(Folder,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName,TreeIc_COL,TreeIc_COL,new DBTreeData(Temp1)); + } + SQL_TYPE.Printf("SQL_C_???? (%d)",((ct_BrowserDB->pTableInf+x)->pColInf+y)->sqlDataType); + DB_TYPE.Printf("DB_DATA_TYPE_???? (%d)",((ct_BrowserDB->pTableInf+x)->pColInf+y)->dbDataType); + for (i=1;i<=(pDoc->db_Br+i_Which)->i_SqlTyp[0];i++) + { + if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->sqlDataType == (pDoc->db_Br+i_Which)->i_SqlTyp[i]) + { + SQL_TYPE.Printf("%s(%d) ; ",(pDoc->db_Br+i_Which)->s_SqlTyp[i].c_str(),(pDoc->db_Br+i_Which)->i_SqlTyp[i]); + } + } // for (i=1;i<=i_SqlTyp[0];i++) + wxYield(); + for (i=1;i<=(pDoc->db_Br+i_Which)->i_dbTyp[0];i++) + { + if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->dbDataType == (pDoc->db_Br+i_Which)->i_dbTyp[i]) + { + DB_TYPE.Printf("%s(%d)",(pDoc->db_Br+i_Which)->s_dbTyp[i].c_str(),(pDoc->db_Br+i_Which)->i_dbTyp[i]); + } + } // for (i=1;i<=i_dbTyp[0];i++) + wxYield(); + SQL_TYPE += DB_TYPE; + Funkt = AppendItem(Docu,SQL_TYPE,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData(SQL_TYPE)); + SQL_TYPE.Printf("%10s %d,%d",((ct_BrowserDB->pTableInf+x)->pColInf+y)->typeName, + ((ct_BrowserDB->pTableInf+x)->pColInf+y)->columnSize,((ct_BrowserDB->pTableInf+x)->pColInf+y)->decimalDigits); + Funkt = AppendItem(Docu,SQL_TYPE,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData(SQL_TYPE)); + } // for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) + } // if ((ct_BrowserDB->pTableInf+x)->pColInf) + else + Folder = AppendItem(Root,Temp0,TreeIc_FolderClosed,TreeIc_FolderOpen, new DBTreeData(Temp1)); + z++; +// if (z % 10 == 0) + { + Temp0.Printf(_("-I-> DBTree::OnPopulate(%s) - Table %6d (from %d) has been read."),(ct_BrowserDB->pTableInf+x)->tableName,z,ct_BrowserDB->numTables); + pDoc->p_MainFrame->SetStatusText(Temp0, 0); + } + wxYield(); + } // if ((ct_BrowserDB->pTableInf+x)->tableType == "TABLE" or VIEW) + // else + // wxLogMessage(_("\n-I-> if ! TABLE or VIEW >%s<"),(ct_BrowserDB->pTableInf+x)->tableType); + } // for (x=0;xnumTables;x++) + } // if (ct_BrowserDB) else - Docu = AppendItem(Folder,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName,TreeIc_COL,TreeIc_COL,new DBTreeData(Temp1)); - } - SQL_TYPE.Printf("SQL_C_???? (%d)",((ct_BrowserDB->pTableInf+x)->pColInf+y)->sqlDataType); - DB_TYPE.Printf("DB_DATA_TYPE_???? (%d)",((ct_BrowserDB->pTableInf+x)->pColInf+y)->dbDataType); - for (i=1;i<=(pDoc->db_Br+i_Which)->i_SqlTyp[0];i++) - { - if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->sqlDataType == (pDoc->db_Br+i_Which)->i_SqlTyp[i]) - { - SQL_TYPE.Printf("%s(%d) ; ",(pDoc->db_Br+i_Which)->s_SqlTyp[i].c_str(),(pDoc->db_Br+i_Which)->i_SqlTyp[i]); - } - } // for (i=1;i<=i_SqlTyp[0];i++) - for (i=1;i<=(pDoc->db_Br+i_Which)->i_dbTyp[0];i++) - { - if (((ct_BrowserDB->pTableInf+x)->pColInf+y)->dbDataType == (pDoc->db_Br+i_Which)->i_dbTyp[i]) - { - DB_TYPE.Printf("%s(%d)",(pDoc->db_Br+i_Which)->s_dbTyp[i].c_str(),(pDoc->db_Br+i_Which)->i_dbTyp[i]); - } - } // for (i=1;i<=i_dbTyp[0];i++) - SQL_TYPE += DB_TYPE; - Funkt = AppendItem(Docu,SQL_TYPE,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData(SQL_TYPE)); - SQL_TYPE.Printf("%10s %d,%d",((ct_BrowserDB->pTableInf+x)->pColInf+y)->typeName, - ((ct_BrowserDB->pTableInf+x)->pColInf+y)->columnSize,((ct_BrowserDB->pTableInf+x)->pColInf+y)->decimalDigits); - Funkt = AppendItem(Docu,SQL_TYPE,TreeIc_DocClosed,TreeIc_DocOpen,new DBTreeData(SQL_TYPE)); - } // for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) - } // if ((ct_BrowserDB->pTableInf+x)->pColInf) - else - Folder = AppendItem(Root,Temp0,TreeIc_FolderClosed,TreeIc_FolderOpen, new DBTreeData(Temp1)); - z++; - if (z % 10 == 0) - { - Temp0.Printf(_("-I-> DBTree::OnPopulate(%s) - Table %6d (from %d) has been read."),(ct_BrowserDB->pTableInf+x)->tableName,z,ct_BrowserDB->numTables); - pDoc->p_MainFrame->SetStatusText(Temp0, 0); - } - } // if ((ct_BrowserDB->pTableInf+x)->tableType == "TABLE" or VIEW) - // else - // wxLogMessage(_("\n-I-> if ! TABLE or VIEW >%s<"),(ct_BrowserDB->pTableInf+x)->tableType); - } // for (x=0;xnumTables;x++) - } // if (ct_BrowserDB) - else - wxLogMessage(_("\n-E-> DBTree::OnPopulate() : Invalid Catalog Pointer : Failed")); - wxEndBusyCursor(); - Temp0.Printf(_("-I-> DBTree::OnPopulate() - %6d Tables have been read. - Time needed : %ld ms"),z,sw.Time()); - wxLogMessage(Temp0); - pDoc->p_MainFrame->SetStatusText(Temp0, 0); - } // if((pDoc->db_Br+i_Which)->Initialize(FALSE)) - else - { - wxLogMessage(_("\n-E-> DBTree::OnPopulate() : A valid Pointer could not be created : Failed")); - return 0; - } - //--------------------------------------------------------------------------------------- - Expand(Root); - //--------------------------------------------------------------------------------------- - popupMenu1 = NULL; - popupMenu1 = new wxMenu(""); - popupMenu1->Append(DATA_DB, _("Make wxDB.cpp/h ")); - popupMenu1->AppendSeparator(); - popupMenu1->Append(DATA_TABLE_ALL, _("Make all wxTable.cpp/h classes")); - popupMenu2 = NULL; - popupMenu2 = new wxMenu(""); - popupMenu2->Append(DATA_SHOW, _("Show Data")); - popupMenu2->AppendSeparator(); - popupMenu2->Append(DATA_TABLE, _("Make wxTable.cpp/h ")); - //--------------------------------------------------------------------------------------- - return 0; -} + wxLogMessage(_("\n-E-> DBTree::OnPopulate() : Invalid Catalog Pointer : Failed")); + wxEndBusyCursor(); + Temp0.Printf(_("-I-> DBTree::OnPopulate() - %6d Tables have been read. - Time needed : %ld ms"),z,sw.Time()); + wxLogMessage(Temp0); + pDoc->p_MainFrame->SetStatusText(Temp0, 0); + } // if((pDoc->db_Br+i_Which)->Initialize(FALSE)) + else + { + wxLogMessage(_("\n-E-> DBTree::OnPopulate() : A valid Pointer could not be created : Failed")); + return 0; + } + //--------------------------------------------------------------------------------------- + Expand(Root); + //--------------------------------------------------------------------------------------- + popupMenu1 = NULL; + popupMenu1 = new wxMenu(""); + popupMenu1->Append(DATA_DB, _("Make wxDB.cpp/h ")); + popupMenu1->AppendSeparator(); + popupMenu1->Append(DATA_TABLE_ALL, _("Make all wxTable.cpp/h classes")); + popupMenu2 = NULL; + popupMenu2 = new wxMenu(""); + popupMenu2->Append(DATA_SHOW, _("Show Data")); + popupMenu2->AppendSeparator(); + popupMenu2->Append(DATA_TABLE, _("Make wxTable.cpp/h ")); + //--------------------------------------------------------------------------------------- + return 0; +} // DBTree::OnPopulate() + //---------------------------------------------------------------------------------------- void DBTree::OnSelChanged(wxTreeEvent& WXUNUSED(event)) { - int i; - Temp0.Empty(); - pDoc->p_MainFrame->SetStatusText(Temp0,0); - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - DBTreeData *item = (DBTreeData *)GetItemData(itemId); - if ( item != NULL ) - { - int Treffer = 0; - Temp1.Printf("%s",item->m_desc.c_str()); - //------------------------------------------------------------------------------------- - if (Temp1.Contains("ODBC-")) - { - Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); - for (i=0;ii_DSN;i++) - { - if (Temp1 == (pDoc->p_DSN+i)->Dsn) + int i; + Temp0.Empty(); + pDoc->p_MainFrame->SetStatusText(Temp0,0); + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + DBTreeData *item = (DBTreeData *)GetItemData(itemId); + if ( item != NULL ) { - // pDoc->OnChosenDSN(i); + int Treffer = 0; + Temp1.Printf("%s",item->m_desc.c_str()); + //------------------------------------------------------------------------------------- + if (Temp1.Contains("ODBC-")) + { + Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); + for (i=0;ii_DSN;i++) + { + if (Temp1 == (pDoc->p_DSN+i)->Dsn) + { + // pDoc->OnChosenDSN(i); + } + } + Treffer++; + } + //-------------------------------------------------------------------------------------- + if (Treffer == 0) + { + //------------------------------------------------------------------------------------- + /* + Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," + "%u children (%u immediately under this item)."), + item->m_desc.c_str(), + bool2String(IsSelected(itemId)), + bool2String(IsExpanded(itemId)), + bool2String(IsBold(itemId)), + GetChildrenCount(itemId), + GetChildrenCount(itemId)); + LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str()); + wxLogMessage( "%s", LogBuf.c_str() ); + */ + //------------------------------------------------------------------------------------- + } } - } - Treffer++; - } - //-------------------------------------------------------------------------------------- - if (Treffer == 0) - { - //------------------------------------------------------------------------------------- - /* - Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," - "%u children (%u immediately under this item)."), - item->m_desc.c_str(), - bool2String(IsSelected(itemId)), - bool2String(IsExpanded(itemId)), - bool2String(IsBold(itemId)), - GetChildrenCount(itemId), - GetChildrenCount(itemId)); - LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str()); - wxLogMessage( "%s", LogBuf.c_str() ); - */ - //------------------------------------------------------------------------------------- - } - } } + //---------------------------------------------------------------------------------------- void DBTree::OnRightSelect(wxTreeEvent& WXUNUSED(event)) { - int i; - Temp0.Empty(); - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - DBTreeData *item = (DBTreeData *)GetItemData(itemId); - if ( item != NULL ) - { - int Treffer = 0; - Temp1.Printf("%s",item->m_desc.c_str()); - //-------------------------------------------------------------------------------------- - if (!wxStrcmp("Root",Temp1)) - { - PopupMenu(popupMenu1,TreePos.x,TreePos.y); - Treffer++; - } - for (i=0;inumTables;i++) - { - Temp2.Printf("TN(%s",(ct_BrowserDB->pTableInf+i)->tableName); - if (!wxStrcmp(Temp2,Temp1)) - { - PopupMenu(popupMenu2,TreePos.x,TreePos.y); - Treffer++; - } - } - //-------------------------------------------------------------------------------------- - if (Treffer == 0) - { - //------------------------------------------------------------------------------------- - /* - Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," - "%u children (%u immediately under this item)."), - item->m_desc.c_str(), - bool2String(IsSelected(itemId)), - bool2String(IsExpanded(itemId)), - bool2String(IsBold(itemId)), - GetChildrenCount(itemId), - GetChildrenCount(itemId)); - LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str()); - wxLogMessage( "%s", LogBuf.c_str() ); - */ - //------------------------------------------------------------------------------------- - } - } + int i; + Temp0.Empty(); + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + DBTreeData *item = (DBTreeData *)GetItemData(itemId); + if ( item != NULL ) + { + int Treffer = 0; + Temp1.Printf("%s",item->m_desc.c_str()); + //-------------------------------------------------------------------------------------- + if (!wxStrcmp("Root",Temp1)) + { + PopupMenu(popupMenu1,TreePos.x,TreePos.y); + Treffer++; + } + for (i=0;inumTables;i++) + { + Temp2.Printf("TN(%s",(ct_BrowserDB->pTableInf+i)->tableName); + if (!wxStrcmp(Temp2,Temp1)) + { + PopupMenu(popupMenu2,TreePos.x,TreePos.y); + Treffer++; + } + } + //-------------------------------------------------------------------------------------- + if (Treffer == 0) + { + //------------------------------------------------------------------------------------- + /* + Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," + "%u children (%u immediately under this item)."), + item->m_desc.c_str(), + bool2String(IsSelected(itemId)), + bool2String(IsExpanded(itemId)), + bool2String(IsBold(itemId)), + GetChildrenCount(itemId), + GetChildrenCount(itemId)); + LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str()); + wxLogMessage( "%s", LogBuf.c_str() ); + */ + //------------------------------------------------------------------------------------- + } + } } + //---------------------------------------------------------------------------------------- void DBTree::OnDBGrid(wxCommandEvent& event) { - int i; - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - DBTreeData *item = (DBTreeData *)GetItemData(itemId); - if ( item != NULL ) - { - Temp1.Printf("%s",item->m_desc.c_str()); - for (i=0;inumTables;i++) - { - Temp2.Printf("TN(%s",(ct_BrowserDB->pTableInf+i)->tableName); - if (!wxStrcmp(Temp2,Temp1)) - { - // Temp0.Printf("(%d) Here is where a GridCtrl for >%s< will be called! ",i,(ct_BrowserDB->pTableInf+i)->tableName); - pDoc->OnChosenTbl(1,(ct_BrowserDB->pTableInf+i)->tableName); - // wxMessageBox(Temp0); - } - } - } + int i; + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + DBTreeData *item = (DBTreeData *)GetItemData(itemId); + if ( item != NULL ) + { + Temp1.Printf("%s",item->m_desc.c_str()); + for (i=0;inumTables;i++) + { + Temp2.Printf("TN(%s",(ct_BrowserDB->pTableInf+i)->tableName); + if (!wxStrcmp(Temp2,Temp1)) + { + // Temp0.Printf("(%d) Here is where a GridCtrl for >%s< will be called! ",i,(ct_BrowserDB->pTableInf+i)->tableName); + pDoc->OnChosenTbl(1,(ct_BrowserDB->pTableInf+i)->tableName); + // wxMessageBox(Temp0); + } + } + } } + //---------------------------------------------------------------------------------------- void DBTree::OnDBClass(wxCommandEvent& event) { - // int i; - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - DBTreeData *item = (DBTreeData *)GetItemData(itemId); - if ( item != NULL ) - { - Temp0.Printf(_("Here is where a wxDB Class for >%s< will be made! "),s_DSN.c_str()); - wxMessageBox(Temp0); - } + // int i; + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + DBTreeData *item = (DBTreeData *)GetItemData(itemId); + if ( item != NULL ) + { + Temp0.Printf(_("Here is where a wxDB Class for >%s< will be made! "),s_DSN.c_str()); + wxMessageBox(Temp0); + } } + //---------------------------------------------------------------------------------------- void DBTree::OnTableClass(wxCommandEvent& event) { - int i; - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - DBTreeData *item = (DBTreeData *)GetItemData(itemId); - if ( item != NULL ) - { - Temp1.Printf("%s",item->m_desc.c_str()); - for (i=0;inumTables;i++) - { - Temp2.Printf("TN(%s",(ct_BrowserDB->pTableInf+i)->tableName); - if (!wxStrcmp(Temp2,Temp1)) - { - Temp0.Printf(_("(%d) Here is where a wxTable Class for >%s< will be made! "),i,(ct_BrowserDB->pTableInf+i)->tableName); - wxMessageBox(Temp0); - } - } - } + int i; + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + DBTreeData *item = (DBTreeData *)GetItemData(itemId); + if ( item != NULL ) + { + Temp1.Printf("%s",item->m_desc.c_str()); + for (i=0;inumTables;i++) + { + Temp2.Printf("TN(%s",(ct_BrowserDB->pTableInf+i)->tableName); + if (!wxStrcmp(Temp2,Temp1)) + { + Temp0.Printf(_("(%d) Here is where a wxTable Class for >%s< will be made! "),i,(ct_BrowserDB->pTableInf+i)->tableName); + wxMessageBox(Temp0); + } + } + } } + //---------------------------------------------------------------------------------------- void DBTree::OnTableClassAll(wxCommandEvent& event) { - // int i; - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - DBTreeData *item = (DBTreeData *)GetItemData(itemId); - if ( item != NULL ) - { - Temp0.Printf(_("Here is where all wxTable Classes in >%s< will be made! "),s_DSN.c_str()); - wxMessageBox(Temp0); - } + // int i; + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + DBTreeData *item = (DBTreeData *)GetItemData(itemId); + if ( item != NULL ) + { + Temp0.Printf(_("Here is where all wxTable Classes in >%s< will be made! "),s_DSN.c_str()); + wxMessageBox(Temp0); + } } + //---------------------------------------------------------------------------------------- void DBTree::OnMouseMove(wxMouseEvent &event) { - TreePos = event.GetPosition(); + TreePos = event.GetPosition(); } //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/dbtree.h b/demos/dbbrowse/dbtree.h index 0ed916390d..7f318e34b5 100644 --- a/demos/dbbrowse/dbtree.h +++ b/demos/dbbrowse/dbtree.h @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------------------- -// Name: DBTree.cpp/.h +// Name: dbtree.cpp/.h // Purpose: Tree with Table and Views, branches show Field information // Author: Mark Johnson // Modified by: 19991129.mj10777 @@ -7,73 +7,77 @@ // Copyright: (c) Mark Johnson // Licence: wxWindows license // RCS-ID: $Id$ + //---------------------------------------------------------------------------------------- -class MainDoc; // Declared in Doc.h file +class MainDoc; // Declared in doc.h file + //---------------------------------------------------------------------------------------- class DBTreeData : public wxTreeItemData { public: - DBTreeData(const wxString& desc) : m_desc(desc) { } - void ShowInfo(wxTreeCtrl *tree); - wxString m_desc; + DBTreeData(const wxString& desc) : m_desc(desc) { } + void ShowInfo(wxTreeCtrl *tree); + wxString m_desc; }; + //---------------------------------------------------------------------------------------- class DBTree : public wxTreeCtrl { - public: - enum - { // The order here must be the same as in m_imageListNormal ! - TreeIc_Logo, // logo.ico - TreeIc_DsnClosed, // dsnclose.ico - TreeIc_DsnOpen, // dsnopen.ico - TreeIc_TAB, // tab.ico - TreeIc_VIEW, // view.ico - TreeIc_COL, // col.ico - TreeIc_KEY, // key.ico - TreeIc_KEYF, // keyf.ico - TreeIc_DocOpen, // d_open.ico - TreeIc_DocClosed, // d_closed.ico - TreeIc_FolderClosed, // f_closed.ico - TreeIc_FolderOpen // f_open.ico - }; - wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; -//---------------------------------------------------------------------------------------- - DBTree() { } - DBTree(wxWindow *parent); - DBTree(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size,long style); - virtual ~DBTree(); - MainDoc *pDoc; - wxDbInf *ct_BrowserDB; -//---------------------------------------------------------------------------------------- - int i_TabArt; // Tab = 0 ; Page = 1; - int i_ViewNr; // View Nummer in Tab / Page - int i_Which; // Which View, Database is this/using - wxString s_DSN; // Name of the Dataset - wxMenu *popupMenu1; // OnDBClass - wxMenu *popupMenu2; // OnDBGrid & OnTableclass - wxPoint TreePos; -//---------------------------------------------------------------------------------------- - wxImageList *p_imageListNormal; -//---------------------------------------------------------------------------------------- - public: - int OnPopulate(); - void OnSelChanged(wxTreeEvent& event); - void OnRightSelect(wxTreeEvent& event); - void OnDBGrid(wxCommandEvent& event); - void OnDBClass(wxCommandEvent& event); - void OnTableClass(wxCommandEvent& event); - void OnTableClassAll(wxCommandEvent& event); - void OnMouseEvent(wxMouseEvent& event); - void OnMouseMove(wxMouseEvent& event); - public: -//---------------------------------------------------------------------------------------- - // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() - // if you want your overloaded OnCompareItems() to be called. - // OTOH, if you don't want it you may omit the next line - this will - // make default (alphabetical) sorting much faster under wxMSW. - DECLARE_DYNAMIC_CLASS(DBTree) - DECLARE_EVENT_TABLE() +public: + enum + { // The order here must be the same as in m_imageListNormal ! + TreeIc_Logo, // logo.ico + TreeIc_DsnClosed, // dsnclose.ico + TreeIc_DsnOpen, // dsnopen.ico + TreeIc_TAB, // tab.ico + TreeIc_VIEW, // view.ico + TreeIc_COL, // col.ico + TreeIc_KEY, // key.ico + TreeIc_KEYF, // keyf.ico + TreeIc_DocOpen, // d_open.ico + TreeIc_DocClosed, // d_closed.ico + TreeIc_FolderClosed, // f_closed.ico + TreeIc_FolderOpen // f_open.ico + }; + wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; + //---------------------------------------------------------------------------------------- + DBTree() { } + DBTree(wxWindow *parent); + DBTree(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size,long style); + virtual ~DBTree(); + MainDoc *pDoc; + wxDbInf *ct_BrowserDB; + //---------------------------------------------------------------------------------------- + int i_TabArt; // Tab = 0 ; Page = 1; + int i_ViewNr; // View Nummer in Tab / Page + int i_Which; // Which View, Database is this/using + wxString s_DSN; // Name of the Dataset + wxMenu *popupMenu1; // OnDBClass + wxMenu *popupMenu2; // OnDBGrid & OnTableclass + wxPoint TreePos; + //---------------------------------------------------------------------------------------- + wxImageList *p_imageListNormal; + //---------------------------------------------------------------------------------------- +public: + int OnPopulate(); + void OnSelChanged(wxTreeEvent& event); + void OnRightSelect(wxTreeEvent& event); + void OnDBGrid(wxCommandEvent& event); + void OnDBClass(wxCommandEvent& event); + void OnTableClass(wxCommandEvent& event); + void OnTableClassAll(wxCommandEvent& event); + void OnMouseEvent(wxMouseEvent& event); + void OnMouseMove(wxMouseEvent& event); +public: + //---------------------------------------------------------------------------------------- + // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() + // if you want your overloaded OnCompareItems() to be called. + // OTOH, if you don't want it you may omit the next line - this will + // make default (alphabetical) sorting much faster under wxMSW. + DECLARE_DYNAMIC_CLASS(DBTree) + DECLARE_EVENT_TABLE() }; + //---------------------------------------------------------------------------------------- #define POPUP_01_BEGIN 1100 #define DATA_SHOW 1101 diff --git a/demos/dbbrowse/dlguser.cpp b/demos/dbbrowse/dlguser.cpp index 28dd64f7c6..59c43632d7 100644 --- a/demos/dbbrowse/dlguser.cpp +++ b/demos/dbbrowse/dlguser.cpp @@ -31,112 +31,117 @@ //-- all #includes that every .cpp needs ----19990807.mj10777 ---------------- //---------------------------------------------------------------------------------------- #include "std.h" + //---------------------------------------------------------------------------------------- DlgUser::DlgUser(wxWindow *parent, MainDoc *p_Doc, const wxString& title) : - wxDialog(parent, ID_DIALOG_DSN, title) + wxDialog(parent, ID_DIALOG_DSN, title) { - int chSize; // Height of Font * 1.4 = Height of wxTextCtrl - - float ratio = 1.4; + int chSize; // Height of Font * 1.4 = Height of wxTextCtrl + + float ratio = (float)1.4; #ifdef __WXMOTIF__ - ratio = 2.1; + ratio = (float)2.1; #endif - - SetBackgroundColour("wheat"); - pDoc = p_Doc; - wxLayoutConstraints* layout; - SetAutoLayout(TRUE); - - m_Label1 = new wxStaticText(this, -1, _("User ID:")); - m_Label1->SetFont(* pDoc->ft_Doc); - layout = new wxLayoutConstraints; - layout->left.SameAs(this, wxLeft, 10); - layout->top.SameAs(this, wxTop, 10); - layout->height.AsIs(); - layout->width.Absolute(75); - m_Label1->SetConstraints(layout); - - int w; - m_Label1->GetSize(&w, &chSize); - - m_UserName = new wxTextCtrl(this, -1, ""); - m_UserName->SetFont(* pDoc->ft_Doc); - chSize = (int) (m_UserName->GetCharHeight()*ratio); - - layout = new wxLayoutConstraints; - layout->left.SameAs(m_Label1, wxRight, 10); - layout->centreY.SameAs(m_Label1,wxCentreY); - layout->width.Absolute(200); - layout->height.Absolute(chSize); - // layout->height.AsIs(); - m_UserName->SetConstraints(layout); - - - m_Label2 = new wxStaticText(this, -1, _("Password:")); - m_Label2->SetFont(* pDoc->ft_Doc); - layout = new wxLayoutConstraints; - layout->left.SameAs(m_Label1, wxLeft); - layout->top.SameAs(m_Label1, wxBottom, 10); - layout->height.AsIs(); - layout->width.SameAs(m_Label1, wxWidth); - m_Label2->SetConstraints(layout); - - m_Password = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD); - m_Password->SetFont(* pDoc->ft_Doc); - layout = new wxLayoutConstraints; - layout->left.SameAs(m_UserName, wxLeft); - layout->width.SameAs(m_UserName, wxWidth); - layout->centreY.SameAs(m_Label2,wxCentreY); - layout->height.Absolute(chSize); - //layout->height.AsIs(); - m_Password->SetConstraints(layout); - - m_OK = new wxButton(this, wxID_OK, _("OK")); - m_OK->SetFont(* pDoc->ft_Doc); - layout = new wxLayoutConstraints; - layout->left.SameAs(this, wxLeft, 10); - layout->top.SameAs(m_Label2, wxBottom,10); - layout->height.AsIs(); - layout->width.Absolute(75); - m_OK->SetConstraints(layout); - - m_Cancel = new wxButton(this, wxID_CANCEL, _("Cancel")); - m_Cancel->SetFont(* pDoc->ft_Doc); - layout = new wxLayoutConstraints; - layout->left.SameAs(m_OK, wxRight, 10); - layout->top.SameAs(m_OK, wxTop); - layout->height.AsIs(); - layout->width.SameAs(m_OK, wxWidth); - m_Cancel->SetConstraints(layout); - - m_OK->SetDefault(); - m_UserName->SetFocus(); - - s_User = ""; - s_Password = ""; - Layout(); + + SetBackgroundColour("wheat"); + pDoc = p_Doc; + wxLayoutConstraints* layout; + SetAutoLayout(TRUE); + + m_Label1 = new wxStaticText(this, -1, _("User ID:")); + m_Label1->SetFont(* pDoc->ft_Doc); + layout = new wxLayoutConstraints; + layout->left.SameAs(this, wxLeft, 10); + layout->top.SameAs(this, wxTop, 10); + layout->height.AsIs(); + layout->width.Absolute(75); + m_Label1->SetConstraints(layout); + + int w; + m_Label1->GetSize(&w, &chSize); + + m_UserName = new wxTextCtrl(this, -1, ""); + m_UserName->SetFont(* pDoc->ft_Doc); + chSize = (int) (m_UserName->GetCharHeight()*ratio); + + layout = new wxLayoutConstraints; + layout->left.SameAs(m_Label1, wxRight, 10); + layout->centreY.SameAs(m_Label1,wxCentreY); + layout->width.Absolute(200); + layout->height.Absolute(chSize); + // layout->height.AsIs(); + m_UserName->SetConstraints(layout); + + + m_Label2 = new wxStaticText(this, -1, _("Password:")); + m_Label2->SetFont(* pDoc->ft_Doc); + layout = new wxLayoutConstraints; + layout->left.SameAs(m_Label1, wxLeft); + layout->top.SameAs(m_Label1, wxBottom, 10); + layout->height.AsIs(); + layout->width.SameAs(m_Label1, wxWidth); + m_Label2->SetConstraints(layout); + + m_Password = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD); + m_Password->SetFont(* pDoc->ft_Doc); + layout = new wxLayoutConstraints; + layout->left.SameAs(m_UserName, wxLeft); + layout->width.SameAs(m_UserName, wxWidth); + layout->centreY.SameAs(m_Label2,wxCentreY); + layout->height.Absolute(chSize); + //layout->height.AsIs(); + m_Password->SetConstraints(layout); + + m_OK = new wxButton(this, wxID_OK, _("OK")); + m_OK->SetFont(* pDoc->ft_Doc); + layout = new wxLayoutConstraints; + layout->left.SameAs(this, wxLeft, 10); + layout->top.SameAs(m_Label2, wxBottom,10); + layout->height.AsIs(); + layout->width.Absolute(75); + m_OK->SetConstraints(layout); + + m_Cancel = new wxButton(this, wxID_CANCEL, _("Cancel")); + m_Cancel->SetFont(* pDoc->ft_Doc); + layout = new wxLayoutConstraints; + layout->left.SameAs(m_OK, wxRight, 10); + layout->top.SameAs(m_OK, wxTop); + layout->height.AsIs(); + layout->width.SameAs(m_OK, wxWidth); + m_Cancel->SetConstraints(layout); + + m_OK->SetDefault(); + m_UserName->SetFocus(); + + s_User = ""; + s_Password = ""; + Layout(); } + //---------------------------------------------------------------------------------------- void DlgUser::OnInit() { - wxString Temp; Temp.Printf(">>> %s <<<",s_DSN.c_str()); - SetTitle(Temp); - m_UserName->SetLabel(s_User); - m_Password->SetLabel(s_Password); + wxString Temp; Temp.Printf(">>> %s <<<",s_DSN.c_str()); + SetTitle(Temp); + m_UserName->SetLabel(s_User); + m_Password->SetLabel(s_Password); } + //---------------------------------------------------------------------------------------- BEGIN_EVENT_TABLE(DlgUser, wxDialog) - EVT_BUTTON(wxID_OK, DlgUser::OnOk) - EVT_BUTTON(wxID_CANCEL, DlgUser::OnCancel) + EVT_BUTTON(wxID_OK, DlgUser::OnOk) + EVT_BUTTON(wxID_CANCEL, DlgUser::OnCancel) END_EVENT_TABLE() + //---------------------------------------------------------------------------------------- void DlgUser::OnOk(wxCommandEvent& WXUNUSED(event) ) { - //canceled = FALSE; - s_User = m_UserName->GetValue(); - s_Password = m_Password->GetValue(); - EndModal(wxID_OK); + //canceled = FALSE; + s_User = m_UserName->GetValue(); + s_Password = m_Password->GetValue(); + EndModal(wxID_OK); } + //---------------------------------------------------------------------------------------- //void DlgUser::OnCancel(wxCommandEvent& WXUNUSED(event) ) // { diff --git a/demos/dbbrowse/dlguser.h b/demos/dbbrowse/dlguser.h index 8e0f2eddff..b6280b66ef 100644 --- a/demos/dbbrowse/dlguser.h +++ b/demos/dbbrowse/dlguser.h @@ -15,22 +15,25 @@ #define ID_USER 102 #define ID_PASSWORD 103 #define ID_TEXT 104 + //---------------------------------------------------------------------------------------- class MainDoc; + //---------------------------------------------------------------------------------------- class DlgUser: public wxDialog { - public: - wxString s_DSN, s_User, s_Password; - wxStaticText *m_Label1, *m_Label2; - wxTextCtrl *m_UserName, *m_Password; - wxButton *m_OK, *m_Cancel; - MainDoc *pDoc; - //--------------------------------------------------------------------------------------- - DlgUser(wxWindow *parent,MainDoc *pDoc, const wxString& title); - void OnInit(); - void OnOk(wxCommandEvent& event); - //--------------------------------------------------------------------------------------- - DECLARE_EVENT_TABLE() +public: + wxString s_DSN, s_User, s_Password; + wxStaticText *m_Label1, *m_Label2; + wxTextCtrl *m_UserName, *m_Password; + wxButton *m_OK, *m_Cancel; + MainDoc *pDoc; + //--------------------------------------------------------------------------------------- + DlgUser(wxWindow *parent,MainDoc *pDoc, const wxString& title); + void OnInit(); + void OnOk(wxCommandEvent& event); + //--------------------------------------------------------------------------------------- + + DECLARE_EVENT_TABLE() }; //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/doc.cpp b/demos/dbbrowse/doc.cpp index 59acac8256..a78fc90847 100644 --- a/demos/dbbrowse/doc.cpp +++ b/demos/dbbrowse/doc.cpp @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------------------- -// Name: Doc.cpp +// Name: doc.cpp // Purpose: Holds information for DBBrowser - (a do-it-yourself document) // Author: Mark Johnson, mj10777@gmx.net // Modified by: 19990808.mj10777 @@ -34,293 +34,302 @@ //-- Some Global Vars for all Files (extern in ?.h needed) ------------------------------- // Global structure for holding ODBC connection information wxDbConnectInf DbConnectInf; + //---------------------------------------------------------------------------------------- wxConfigBase *p_ProgramCfg; // All Config and Path information wxLogTextCtrl *p_LogBook; // All Log messages wxString LogBuf; // String for all Logs + //---------------------------------------------------------------------------------------- MainDoc::MainDoc() { - db_Br = NULL; - p_DSN = NULL; - i_DSN = 0; - p_Splitter = NULL; - p_MainFrame = NULL; - p_PgmCtrl = NULL; // Is not active - p_DBTree = NULL; - p_DBGrid = NULL; - p_LogWin = NULL; - p_TabArea = NULL; - p_PageArea = NULL; - i_TabNr = 0; - i_PageNr = 0; - s_BColour = "WHEAT"; - ft_Doc = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT)); + db_Br = NULL; + p_DSN = NULL; + i_DSN = 0; + p_Splitter = NULL; + p_MainFrame = NULL; + p_PgmCtrl = NULL; // Is not active + p_DBTree = NULL; + p_DBGrid = NULL; + p_LogWin = NULL; + p_TabArea = NULL; + p_PageArea = NULL; + i_TabNr = 0; + i_PageNr = 0; + s_BColour = "WHEAT"; + ft_Doc = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT)); } + //---------------------------------------------------------------------------------------- MainDoc::~MainDoc() { - // ---------------------------------------------------------- - // -E-> The Tree Controls take to long to close : Why ?? - // ---------------------------------------------------------- - delete ft_Doc; - ft_Doc = NULL; - p_TabArea->Show(FALSE); // Deactivate the Window - p_PageArea->Show(FALSE); // Deactivate the Window - p_PgmCtrl = NULL; - delete p_PgmCtrl; - delete [] p_DSN; - delete p_DBTree; - p_TabArea = NULL; delete p_TabArea; - p_PageArea = NULL; delete p_PageArea; - p_Splitter = NULL; - delete p_Splitter; - delete [] db_Br; - // wxMessageBox("~MainDoc"); + p_TabArea->Show(FALSE); // Deactivate the Window + p_PageArea->Show(FALSE); // Deactivate the Window + + // ---------------------------------------------------------- + // -E-> The Tree Controls take to long to close : Why ?? + // ---------------------------------------------------------- + delete ft_Doc; ft_Doc = NULL; + delete p_PgmCtrl; p_PgmCtrl = NULL; + delete [] p_DSN; + delete p_DBTree; + delete p_TabArea; p_TabArea = NULL; + delete p_PageArea; p_PageArea = NULL; + delete p_Splitter; p_Splitter = NULL; + delete [] db_Br; db_Br = NULL; + // wxMessageBox("~MainDoc"); } + //---------------------------------------------------------------------------------------- bool MainDoc::OnNewDocument() { - wxStopWatch sw; - //--------------------------------------------------------------------------------------- - if (!OnInitView()) - return FALSE; - p_PgmCtrl->OnPopulate(); - //--------------------------------------------------------------------------------------- - wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time()); - return TRUE; + wxStopWatch sw; + //--------------------------------------------------------------------------------------- + if (!OnInitView()) + return FALSE; + p_PgmCtrl->OnPopulate(); + //--------------------------------------------------------------------------------------- + wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time()); + return TRUE; } + //---------------------------------------------------------------------------------------- bool MainDoc::OnInitView() { - Sash = p_ProgramCfg->Read("/MainFrame/Sash", 200); - // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView"); - //--------------------------------------------------------------------------------------- - // create "workplace" window - //--------------------------------------------------------------------------------------- - p_TabArea = new wxTabbedWindow(); // Init the Pointer - p_TabArea->Create(p_Splitter, -1); - //--------------------------------------------------------------------------------------- - p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize, - wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); - p_PgmCtrl->i_TabArt = 0; // 0 = Tab ; 1 = Page - p_PgmCtrl->i_ViewNr = p_TabArea->GetTabCount()-1; - //--------------------------------------------------------------------------------------- - wxBitmap *p_FolderClose = new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115 - //--------------------------------------------------------------------------------------- - p_TabArea->AddTab(p_PgmCtrl,"PgmCtrl",p_FolderClose); - delete p_FolderClose; // Memory leak - p_FolderClose = NULL; - //--------------------------------------------------------------------------------------- - // now create "output" window - //--------------------------------------------------------------------------------------- - p_PageArea = new wxPaggedWindow(); // Init the Pointer - p_PageArea->Create(p_Splitter, -1); - //--------------------------------------------------------------------------------------- - p_LogWin = new wxTextCtrl(p_PageArea,-1,wxEmptyString, - wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE ); - p_LogWin->SetFont(* ft_Doc); - // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1; - //--------------------------------------------------------------------------------------- - p_LogBook = new wxLogTextCtrl(p_LogWin); // make p_LogWin the LogBook - p_LogBook->SetActiveTarget(p_LogBook); - p_LogBook->SetTimestamp( NULL ); - //--------------------------------------------------------------------------------------- - p_PageArea->AddTab(p_LogWin,_("LogBook"), "what is this?" ); - i_TabNr = p_TabArea->GetTabCount()-1; // Add one when a new AddTab is done; - i_PageNr = p_PageArea->GetTabCount()-1; // Add one when a new AddTab is done; - //--------------------------------------------------------------------------------------- - p_PgmCtrl->pDoc = this; - p_TabArea->SetActiveTab(i_PageNr); - //--------------------------------------------------------------------------------------- - p_Splitter->Initialize(p_TabArea); - p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash); - //--------------------------------------------------------------------------------------- - // if (!OnInitODBC()) - // return FALSE; - OnInitODBC(); - //--------------------------------------------------------------------------------------- - Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN); - p_MainFrame->SetStatusText(Temp0, 0); - wxLogMessage(Temp0); - return TRUE; + Sash = p_ProgramCfg->Read("/MainFrame/Sash", 200); + // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView"); + //--------------------------------------------------------------------------------------- + // create "workplace" window + //--------------------------------------------------------------------------------------- + p_TabArea = new wxTabbedWindow(); // Init the Pointer + p_TabArea->Create(p_Splitter, -1); + //--------------------------------------------------------------------------------------- + p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize, + wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); + p_PgmCtrl->i_TabArt = 0; // 0 = Tab ; 1 = Page + p_PgmCtrl->i_ViewNr = p_TabArea->GetTabCount()-1; + //--------------------------------------------------------------------------------------- + wxBitmap *p_FolderClose = new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115 + //--------------------------------------------------------------------------------------- + p_TabArea->AddTab(p_PgmCtrl,"PgmCtrl",p_FolderClose); + delete p_FolderClose; // Memory leak + p_FolderClose = NULL; + //--------------------------------------------------------------------------------------- + // now create "output" window + //--------------------------------------------------------------------------------------- + p_PageArea = new wxPagedWindow(); // Init the Pointer + p_PageArea->Create(p_Splitter, -1); + //--------------------------------------------------------------------------------------- + p_LogWin = new wxTextCtrl(p_PageArea,-1,wxEmptyString, + wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE ); + p_LogWin->SetFont(* ft_Doc); + // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1; + //--------------------------------------------------------------------------------------- + p_LogBook = new wxLogTextCtrl(p_LogWin); // make p_LogWin the LogBook + p_LogBook->SetActiveTarget(p_LogBook); + p_LogBook->SetTimestamp( NULL ); + //--------------------------------------------------------------------------------------- + p_PageArea->AddTab(p_LogWin,_("LogBook"), "what is this?" ); + i_TabNr = p_TabArea->GetTabCount()-1; // Add one when a new AddTab is done; + i_PageNr = p_PageArea->GetTabCount()-1; // Add one when a new AddTab is done; + //--------------------------------------------------------------------------------------- + p_PgmCtrl->pDoc = this; + p_TabArea->SetActiveTab(i_PageNr); + //--------------------------------------------------------------------------------------- + p_Splitter->Initialize(p_TabArea); + p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash); + //--------------------------------------------------------------------------------------- + // if (!OnInitODBC()) + // return FALSE; + OnInitODBC(); + //--------------------------------------------------------------------------------------- + Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN); + p_MainFrame->SetStatusText(Temp0, 0); + wxLogMessage(Temp0); + return TRUE; } + //---------------------------------------------------------------------------------------- bool MainDoc::OnInitODBC() { - char Dsn[SQL_MAX_DSN_LENGTH + 1]; - char DsDesc[255]; // BJO20002501 instead of 512 - Temp0 = ""; - i_DSN = 0; // Counter - int i = 0; - //--------------------------------------------------------------------------------------- - // Initialize the ODBC Environment for Database Operations - - if (SQLAllocEnv(&DbConnectInf.Henv) != SQL_SUCCESS) - { - return FALSE; - } - //--------------------------------------------------------------------------------------- - const char sep = 3; // separator character used in string between DSN ans DsDesc - wxStringList 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.Henv, Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc))) - { - i_DSN++; // How many Dsn have we ? - KeyString.Printf("%s%c%s",Dsn, sep, DsDesc); - s_SortDSNList.Add(Dsn); - s_SortDsDescList.Add(KeyString); - } - s_SortDSNList.Sort(); //BJO - s_SortDsDescList.Sort(); //BJO - - char ** s_SortDSN = s_SortDSNList.ListToArray(); //BJO - char ** s_SortDsDesc = s_SortDsDescList.ListToArray(); //BJO - //--------------------------------------------------------------------------------------- - // Allocate n ODBC-DSN objects to hold the information - p_DSN = new DSN[i_DSN]; //BJO - for (i=0;iDsn = s_SortDSN[i]; - (p_DSN+i)->Drv = s_SortDsDesc[i]; - (p_DSN+i)->Usr = ""; - (p_DSN+i)->Pas = ""; - Temp0.Printf("%02d) Dsn(%s) DsDesc(%s)",i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str()); - wxLogMessage(Temp0); - } - i = 0; - //--------------------------------------------------------------------------------------- - // Allocate n wxDatabase objects to hold the column information - db_Br = new BrowserDB[i_DSN]; - for (i=0;ip_LogWindow = p_LogWin; - (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn; - (db_Br+i)->UserName = (p_DSN+i)->Usr; - (db_Br+i)->Password = (p_DSN+i)->Pas; - (db_Br+i)->pDoc = this; - (db_Br+i)->i_Which = i; - } - if (SQLFreeEnv(DbConnectInf.Henv) != SQL_SUCCESS) // BJO20000125 / MJ10777.20000309 : no & - { - // Error freeing environment handle - } - delete [] s_SortDSN; - delete [] s_SortDsDesc; - //--------------------------------------------------------------------------------------- - if (!i_DSN) - { - wxMessageBox(_("No Dataset names found in ODBC!\n" \ - " Program will exit!\n\n" \ - " Ciao"),"-E-> Fatal situation"); - return FALSE; - } - //--------------------------------------------------------------------------------------- - return TRUE; + char Dsn[SQL_MAX_DSN_LENGTH + 1]; + char DsDesc[255]; // BJO20002501 instead of 512 + Temp0 = ""; + i_DSN = 0; // Counter + int i = 0; + //--------------------------------------------------------------------------------------- + // Initialize the ODBC Environment for Database Operations + + if (SQLAllocEnv(&DbConnectInf.Henv) != SQL_SUCCESS) + { + return FALSE; + } + //--------------------------------------------------------------------------------------- + const char sep = 3; // separator character used in string between DSN ans DsDesc + wxStringList 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.Henv, Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc))) + { + i_DSN++; // How many Dsn have we ? + KeyString.Printf("%s%c%s",Dsn, sep, DsDesc); + s_SortDSNList.Add(Dsn); + s_SortDsDescList.Add(KeyString); + } + s_SortDSNList.Sort(); //BJO + s_SortDsDescList.Sort(); //BJO + + char ** s_SortDSN = s_SortDSNList.ListToArray(); //BJO + char ** s_SortDsDesc = s_SortDsDescList.ListToArray(); //BJO + //--------------------------------------------------------------------------------------- + // Allocate n ODBC-DSN objects to hold the information + p_DSN = new DSN[i_DSN]; //BJO + for (i=0;iDsn = s_SortDSN[i]; + (p_DSN+i)->Drv = s_SortDsDesc[i]; + (p_DSN+i)->Usr = ""; + (p_DSN+i)->Pas = ""; + Temp0.Printf("%02d) Dsn(%s) DsDesc(%s)",i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str()); + wxLogMessage(Temp0); + } + i = 0; + //--------------------------------------------------------------------------------------- + // Allocate n wxDatabase objects to hold the column information + db_Br = new BrowserDB[i_DSN]; + for (i=0;ip_LogWindow = p_LogWin; + (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn; + (db_Br+i)->UserName = (p_DSN+i)->Usr; + (db_Br+i)->Password = (p_DSN+i)->Pas; + (db_Br+i)->pDoc = this; + (db_Br+i)->i_Which = i; + } + if (SQLFreeEnv(DbConnectInf.Henv) != SQL_SUCCESS) // BJO20000125 / MJ10777.20000309 : no & + { + // Error freeing environment handle + } + delete [] s_SortDSN; + delete [] s_SortDsDesc; + //--------------------------------------------------------------------------------------- + if (!i_DSN) + { + wxMessageBox(_("No Dataset names found in ODBC!\n" \ + " Program will exit!\n\n" \ + " Ciao"),"-E-> Fatal situation"); + return FALSE; + } + //--------------------------------------------------------------------------------------- + return TRUE; } + //---------------------------------------------------------------------------------------- bool MainDoc::OnChosenDSN(int Which) { - // wxLogMessage("OnChosenDSN(%d) - Begin",Which); - //--------------------------------------------------------------------------------------- - if (p_DBTree != NULL) - { - p_TabArea->Show(FALSE); // Deactivate the Window - p_TabArea->RemoveTab(p_DBTree->i_ViewNr); - p_TabArea->Show(TRUE); // Activate the Window - OnChosenTbl(77,""); - } - //------------------------- - 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," ? "); - p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1; - 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; - p_DBTree->pDoc = this; - p_DBTree->OnPopulate(); - p_TabArea->SetActiveTab(p_DBTree->i_ViewNr); - //--------------------------------------------------------------------------------------- - // wxLogMessage("OnChosenDSN(%d) - End",Which); - return TRUE; + // wxLogMessage("OnChosenDSN(%d) - Begin",Which); + //--------------------------------------------------------------------------------------- + if (p_DBTree != NULL) + { + p_TabArea->Show(FALSE); // Deactivate the Window + p_TabArea->RemoveTab(p_DBTree->i_ViewNr); + p_TabArea->Show(TRUE); // Activate the Window + OnChosenTbl(77,""); + } + //------------------------- + 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," ? "); + p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1; + 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; + p_DBTree->pDoc = this; + p_DBTree->OnPopulate(); + p_TabArea->SetActiveTab(p_DBTree->i_ViewNr); + //--------------------------------------------------------------------------------------- + // wxLogMessage("OnChosenDSN(%d) - End",Which); + return TRUE; } + //---------------------------------------------------------------------------------------- bool MainDoc::OnChosenTbl(int Tab,wxString Table) { - // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str()); - //------------------------- - if (p_DBGrid != NULL) - { - if (p_DBGrid->i_TabArt == 0) - { - p_TabArea->Show(FALSE); // Deactivate the Window - p_TabArea->RemoveTab(p_DBGrid->i_ViewNr); - p_TabArea->Show(TRUE); // Activate the Window - } - if (p_DBGrid->i_TabArt == 1) - { - p_PageArea->Show(FALSE); // Deactivate the Window - p_PageArea->RemoveTab(p_DBGrid->i_ViewNr); - p_PageArea->Show(TRUE); // Activate the Window - } - p_DBGrid = NULL; - delete p_DBGrid; - } - if (Tab == 77) // Delete only - return TRUE; - //------------------------- - if (Tab == 0) // Tabview - { - 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, ""); - 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 - } - if (Tab == 1) // Pageview - { - 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, ""); - 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_DBGrid->OnTableView(Table); - p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr); - } - p_DBGrid->i_TabArt = Tab; - //-------------------------- - return TRUE;; + // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str()); + //------------------------- + if (p_DBGrid != NULL) + { + if (p_DBGrid->i_TabArt == 0) + { + p_TabArea->Show(FALSE); // Deactivate the Window + p_TabArea->RemoveTab(p_DBGrid->i_ViewNr); + p_TabArea->Show(TRUE); // Activate the Window + } + if (p_DBGrid->i_TabArt == 1) + { + p_PageArea->Show(FALSE); // Deactivate the Window + p_PageArea->RemoveTab(p_DBGrid->i_ViewNr); + p_PageArea->Show(TRUE); // Activate the Window + } + p_DBGrid = NULL; + delete p_DBGrid; + } + if (Tab == 77) // Delete only + return TRUE; + //------------------------- + if (Tab == 0) // Tabview + { + 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, ""); + 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 + } + if (Tab == 1) // Pageview + { + 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, ""); + 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_DBGrid->OnTableView(Table); + p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr); + } + p_DBGrid->i_TabArt = Tab; + //-------------------------- + return TRUE;; } + //---------------------------------------------------------------------------------------- void MainDoc::OnLeer(wxString Aufrufer) { - // Temp0.Printf(_("\nMainDoc::OnLeer(%s) : auch diese funktion steht eines Tages zur Verfügung !"),Aufrufer.c_str()); - Temp0.Printf(_("\nMainDoc::OnLeer(%s) : even this function will one day be available !"),Aufrufer.c_str()); - wxLogMessage(Temp0); Temp0.Empty(); - return; + // Temp0.Printf(_("\nMainDoc::OnLeer(%s) : auch diese funktion steht eines Tages zur Verfügung !"),Aufrufer.c_str()); + Temp0.Printf(_("\nMainDoc::OnLeer(%s) : even this function will one day be available !"),Aufrufer.c_str()); + wxLogMessage(Temp0); Temp0.Empty(); + return; } + //---------------------------------------------------------------------------------------- BEGIN_EVENT_TABLE(DocSplitterWindow, wxSplitterWindow) END_EVENT_TABLE() + //---------------------------------------------------------------------------------------- DocSplitterWindow::DocSplitterWindow(wxWindow *parent, wxWindowID id) : wxSplitterWindow(parent, id) { // Define a constructor for my p_Splitter diff --git a/demos/dbbrowse/doc.h b/demos/dbbrowse/doc.h index 473089075f..3fbb111033 100644 --- a/demos/dbbrowse/doc.h +++ b/demos/dbbrowse/doc.h @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// Name: Doc.h +// Name: doc.h // Purpose: a non-MFC Document (a do-it-yourself document) // Author: Mark Johnson, mj10777@gmx.net // Modified by: 19990808.mj10777 @@ -7,80 +7,87 @@ // Copyright: (c) Mark Johnson // Licence: wxWindows license // RCS-ID: $Id$ + //---------------------------------------------------------------------------------------- //-- Some Global Vars -------------------------------------------------------------------- //---------------------------------------------------------------------------------------- class DSN { - public: - wxString Dsn; - wxString Drv; - wxString Pas; - wxString Usr; +public: + wxString Dsn; + wxString Drv; + wxString Pas; + wxString Usr; }; + //---------------------------------------------------------------------------------------- - // Global structure for holding ODBC connection information +// Global structure for holding ODBC connection information extern wxDbConnectInf DbConnectInf; + //---------------------------------------------------------------------------------------- extern wxConfigBase *p_ProgramCfg; // All Config and Path information extern wxLogTextCtrl *p_LogBook; // All Log messages extern wxString LogBuf; // String for all Logs + //---------------------------------------------------------------------------------------- class PgmCtrl; // Declared in PgmCtrl.h file class DocSplitterWindow; // Declared at the end of the file + //---------------------------------------------------------------------------------------- class MainDoc { - public: - //--------------------------------------------------------------------------------------- - MainDoc(); - virtual ~MainDoc(); - int Sash; - //--------------------------------------------------------------------------------------- - //-- declare document Vars here --------------------------------------------------------- - //--------------------------------------------------------------------------------------- - wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; - BrowserDB *db_Br; // Pointer to wxDB - DSN *p_DSN; - int i_DSN; // Counter - wxString s_BColour; - wxFont *ft_Doc; - //--------------------------------------------------------------------------------------- - DocSplitterWindow *p_Splitter; - wxHtmlHelpController *p_Help; - wxFrame *p_MainFrame; // SDI Version - PgmCtrl *p_PgmCtrl; - DBTree *p_DBTree; - DBGrid *p_DBGrid; - wxTextCtrl *p_LogWin; - wxTabbedWindow *p_TabArea; - wxPaggedWindow *p_PageArea; - int i_TabNr; // Amount of active Views in Tab - int i_PageNr; // Amount of active Views in Page - //--------------------------------------------------------------------------------------- - //-- declare document Functions here ---------------------------------------------------- - //--------------------------------------------------------------------------------------- - bool OnNewDocument(); - bool OnInitView(); - bool OnInitODBC(); - bool OnChosenDSN(int Which); - bool OnChosenTbl(int Tab,wxString Table); - //--------------------------------------------------------------------------------------- - void OnLeer(wxString Aufrufer); // Dummy Funktion - //--------------------------------------------------------------------------------------- +public: + //--------------------------------------------------------------------------------------- + MainDoc(); + virtual ~MainDoc(); + int Sash; + //--------------------------------------------------------------------------------------- + //-- declare document Vars here --------------------------------------------------------- + //--------------------------------------------------------------------------------------- + wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; + BrowserDB *db_Br; // Pointer to wxDB + DSN *p_DSN; + int i_DSN; // Counter + wxString s_BColour; + wxFont *ft_Doc; + //--------------------------------------------------------------------------------------- + DocSplitterWindow *p_Splitter; + wxHtmlHelpController *p_Help; + wxFrame *p_MainFrame; // SDI Version + PgmCtrl *p_PgmCtrl; + DBTree *p_DBTree; + DBGrid *p_DBGrid; + wxTextCtrl *p_LogWin; + wxTabbedWindow *p_TabArea; + wxPagedWindow *p_PageArea; + int i_TabNr; // Amount of active Views in Tab + int i_PageNr; // Amount of active Views in Page + //--------------------------------------------------------------------------------------- + //-- declare document Functions here ---------------------------------------------------- + //--------------------------------------------------------------------------------------- + bool OnNewDocument(); + bool OnInitView(); + bool OnInitODBC(); + bool OnChosenDSN(int Which); + bool OnChosenTbl(int Tab,wxString Table); + //--------------------------------------------------------------------------------------- + void OnLeer(wxString Aufrufer); // Dummy Funktion + //--------------------------------------------------------------------------------------- }; + +//---------------------------------------------------------------------------------------- class DocSplitterWindow: public wxSplitterWindow { - public: - MainDoc *pDoc; - DocSplitterWindow(wxWindow *parent, wxWindowID id); - virtual bool OnSashPositionChange(int newSashPosition) - { - if ( !wxSplitterWindow::OnSashPositionChange(newSashPosition) ) - return FALSE; - pDoc->Sash = newSashPosition; - return TRUE; - } - DECLARE_EVENT_TABLE() +public: + MainDoc *pDoc; + DocSplitterWindow(wxWindow *parent, wxWindowID id); + virtual bool OnSashPositionChange(int newSashPosition) + { + if ( !wxSplitterWindow::OnSashPositionChange(newSashPosition) ) + return FALSE; + pDoc->Sash = newSashPosition; + return TRUE; + } + DECLARE_EVENT_TABLE() }; //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/pgmctrl.cpp b/demos/dbbrowse/pgmctrl.cpp index 6006503a5a..ea40bcc8ba 100644 --- a/demos/dbbrowse/pgmctrl.cpp +++ b/demos/dbbrowse/pgmctrl.cpp @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------------------- -// Name: pgmctrl.h +// Name: pgmctrl.cpp // Purpose: Programm Control with a Tree // Author: Mark Johnson // Modified by: 19990806.mj10777 @@ -39,253 +39,267 @@ //-- all #includes that every .cpp needs --- 19990807.mj10777 ---------------- //---------------------------------------------------------------------------------------- #include "std.h" // sorgsam Pflegen ! + //---------------------------------------------------------------------------------------- //-- Global functions -------------------------------------------------------------------- //---------------------------------------------------------------------------------------- static inline const char *bool2String(bool b) { - return b ? "" : "not "; + return b ? "" : "not "; } + //---------------------------------------------------------------------------------------- BEGIN_EVENT_TABLE(PgmCtrl, wxTreeCtrl) - EVT_MOTION (PgmCtrl::OnMouseMove) - EVT_LEFT_DCLICK(PgmCtrl::OnSelChanged) - EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_PGM,PgmCtrl::OnRightSelect) - EVT_MENU(PGMCTRL_ODBC_USER,PgmCtrl::OnUserPassword) + EVT_MOTION (PgmCtrl::OnMouseMove) + EVT_LEFT_DCLICK(PgmCtrl::OnSelChanged) + EVT_TREE_ITEM_RIGHT_CLICK(TREE_CTRL_PGM,PgmCtrl::OnRightSelect) + EVT_MENU(PGMCTRL_ODBC_USER,PgmCtrl::OnUserPassword) END_EVENT_TABLE() + //---------------------------------------------------------------------------------------- // PgmCtrl implementation //---------------------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(PgmCtrl, wxTreeCtrl) + //---------------------------------------------------------------------------------------- PgmCtrl::PgmCtrl(wxWindow *parent) : wxTreeCtrl(parent) { } + //---------------------------------------------------------------------------------------- PgmCtrl::PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size, long style) - : wxTreeCtrl(parent, id, pos, size, style) +: wxTreeCtrl(parent, id, pos, size, style) { - // Make an image list containing small icons - p_imageListNormal = new wxImageList(16, 16, TRUE); - // should correspond to TreeIc_xxx enum + // Make an image list containing small icons + p_imageListNormal = new wxImageList(16, 16, TRUE); + // should correspond to TreeIc_xxx enum #if defined(__WXMSW__) && defined(__WIN16__) - // This is required in 16-bit Windows mode only because we can't load a specific (16x16) - // icon image, so it comes out stretched - p_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE)); - p_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE)); + // This is required in 16-bit Windows mode only because we can't load a specific (16x16) + // icon image, so it comes out stretched + p_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE)); + p_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE)); #else - p_imageListNormal->Add(wxICON(aLogo)); - p_imageListNormal->Add(wxICON(DsnClosed)); - p_imageListNormal->Add(wxICON(DsnOpen)); - p_imageListNormal->Add(wxICON(DocClosed)); - p_imageListNormal->Add(wxICON(DocOpen)); - p_imageListNormal->Add(wxICON(FolderClosed)); - p_imageListNormal->Add(wxICON(FolderOpen)); + p_imageListNormal->Add(wxICON(aLogo)); + p_imageListNormal->Add(wxICON(DsnClosed)); + p_imageListNormal->Add(wxICON(DsnOpen)); + p_imageListNormal->Add(wxICON(DocClosed)); + p_imageListNormal->Add(wxICON(DocOpen)); + p_imageListNormal->Add(wxICON(FolderClosed)); + p_imageListNormal->Add(wxICON(FolderOpen)); #endif - SetImageList(p_imageListNormal); + SetImageList(p_imageListNormal); } + //---------------------------------------------------------------------------------------- PgmCtrl::~PgmCtrl() { - delete p_imageListNormal; - delete popupMenu1; + delete p_imageListNormal; + delete popupMenu1; } + //---------------------------------------------------------------------------------------- #undef TREE_EVENT_HANDLER + //---------------------------------------------------------------------------------------- int PgmCtrl::OnPopulate() { - SetFont(* pDoc->ft_Doc); - wxTreeItemId Root, Folder, Docu; - //--------------------------------------------------------------------------------------- - int i; - double dTmp = 1234567.89; - Temp0.Printf(_("%s Functions"),p_ProgramCfg->GetAppName().c_str()); - Root = AddRoot(Temp0,TreeIc_Logo,TreeIc_Logo, new TreeData("Root")); - //--------------------------------------------------------------------------------------- - Folder = AppendItem(Root, _("Program settings") ,TreeIc_FolderClosed, TreeIc_FolderOpen, new TreeData("Settings")); - p_ProgramCfg->Read("/Local/langid",&Temp0); p_ProgramCfg->Read("/Local/language",&Temp2); - Temp1.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0.c_str(), Temp2.c_str(), dTmp); Temp0.Empty(); Temp2.Empty(); - Docu = AppendItem(Folder, Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Setting Language")); - p_ProgramCfg->Read("/Paths/Work",&Temp0); Temp1.Printf(_("Work Path : %s"),Temp0.c_str()); Temp0.Empty(); - Docu = AppendItem(Folder,Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Path Work")); - Docu = AppendItem(Folder, _("Change the language to English") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language English")); - Docu = AppendItem(Folder, _("Change the language to German") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language German")); - Docu = AppendItem(Folder, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("wxConfigBase Delete")); - Folder = AppendItem(Root, "ODBC DSN",TreeIc_FolderClosed,TreeIc_FolderOpen,new TreeData("ODBC-DSN")); - for (i=0;ii_DSN;i++) - { - Temp0.Printf("ODBC-%s",(pDoc->p_DSN+i)->Dsn.c_str()); - Docu = AppendItem(Folder,(pDoc->p_DSN+i)->Dsn ,TreeIc_DsnClosed,TreeIc_DsnOpen, new TreeData(Temp0)); - } - //--------------------------------------------------------------------------------------- - popupMenu1 = NULL; - popupMenu1 = new wxMenu(""); - popupMenu1->Append(PGMCTRL_ODBC_USER, _("Set Username and Password")); - // popupMenu1->AppendSeparator(); - //--------------------------------------------------------------------------------------- - Expand(Root); - Expand(Folder); - //--------------------------------------------------------------------------------------- - return 0; + SetFont(* pDoc->ft_Doc); + wxTreeItemId Root, Folder, Docu; + //--------------------------------------------------------------------------------------- + int i; + double dTmp = 1234567.89; + Temp0.Printf(_("%s Functions"),p_ProgramCfg->GetAppName().c_str()); + Root = AddRoot(Temp0,TreeIc_Logo,TreeIc_Logo, new TreeData("Root")); + //--------------------------------------------------------------------------------------- + Folder = AppendItem(Root, _("Program settings") ,TreeIc_FolderClosed, TreeIc_FolderOpen, new TreeData("Settings")); + p_ProgramCfg->Read("/Local/langid",&Temp0); p_ProgramCfg->Read("/Local/language",&Temp2); + Temp1.Printf(_("locale (%s) ; Language (%s) ; Number(%2.2f)"),Temp0.c_str(), Temp2.c_str(), dTmp); Temp0.Empty(); Temp2.Empty(); + Docu = AppendItem(Folder, Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Setting Language")); + p_ProgramCfg->Read("/Paths/Work",&Temp0); Temp1.Printf(_("Work Path : %s"),Temp0.c_str()); Temp0.Empty(); + Docu = AppendItem(Folder,Temp1,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Path Work")); + Docu = AppendItem(Folder, _("Change the language to English") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language English")); + Docu = AppendItem(Folder, _("Change the language to German") ,TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("Language German")); + Docu = AppendItem(Folder, _("Delete all wxConfigBase Entry's"),TreeIc_DocClosed,TreeIc_DocOpen,new TreeData("wxConfigBase Delete")); + Folder = AppendItem(Root, "ODBC DSN",TreeIc_FolderClosed,TreeIc_FolderOpen,new TreeData("ODBC-DSN")); + for (i=0;ii_DSN;i++) + { + Temp0.Printf("ODBC-%s",(pDoc->p_DSN+i)->Dsn.c_str()); + Docu = AppendItem(Folder,(pDoc->p_DSN+i)->Dsn ,TreeIc_DsnClosed,TreeIc_DsnOpen, new TreeData(Temp0)); + } + //--------------------------------------------------------------------------------------- + popupMenu1 = NULL; + popupMenu1 = new wxMenu(""); + popupMenu1->Append(PGMCTRL_ODBC_USER, _("Set Username and Password")); + // popupMenu1->AppendSeparator(); + //--------------------------------------------------------------------------------------- + Expand(Root); + Expand(Folder); + //--------------------------------------------------------------------------------------- + return 0; } + //---------------------------------------------------------------------------------------- void PgmCtrl::OnSelChanged(wxMouseEvent& WXUNUSED(event)) { - int i; - Temp0.Empty(); Temp1.Empty(); - pDoc->p_MainFrame->SetStatusText(Temp0,0); - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - TreeData *item = (TreeData *)GetItemData(itemId); - if (item != NULL ) - { - int Treffer = 0; - Temp1.Printf("%s",item->m_desc.c_str()); - //-------------------------------------------------------------------------------------- - if (Temp1 == "Language English") - { - Temp0 = "std"; - p_ProgramCfg->Write("/Local/langid",Temp0); - Temp0 = _("-I-> After a programm restart, the language will be changed to English."); - wxMessageBox(Temp0); - } - if (Temp1 == "Language German") - { - Temp0 = "de"; - p_ProgramCfg->Write("/Local/langid",Temp0); - Temp0 = _("-I-> After a programm restart, the language will be changed to German."); - wxMessageBox(Temp0); - } - //-------------------------------------------------------------------------------------- - if (Temp1 == "wxConfigBase Delete") - { - if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector - Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull."); - else - Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !"); - wxBell(); // Ding_a_Ling - Treffer++; - } - //-------------------------------------------------------------------------------------- - if (Temp1.Contains("ODBC-")) - { - Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); - for (i=0;ii_DSN;i++) - { - if (Temp1 == (pDoc->p_DSN+i)->Dsn) + int i; + Temp0.Empty(); Temp1.Empty(); + pDoc->p_MainFrame->SetStatusText(Temp0,0); + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + TreeData *item = (TreeData *)GetItemData(itemId); + if (item != NULL ) { - pDoc->OnChosenDSN(i); + int Treffer = 0; + Temp1.Printf("%s",item->m_desc.c_str()); + //-------------------------------------------------------------------------------------- + if (Temp1 == "Language English") + { + Temp0 = "std"; + p_ProgramCfg->Write("/Local/langid",Temp0); + Temp0 = _("-I-> After a programm restart, the language will be changed to English."); + wxMessageBox(Temp0); + } + if (Temp1 == "Language German") + { + Temp0 = "de"; + p_ProgramCfg->Write("/Local/langid",Temp0); + Temp0 = _("-I-> After a programm restart, the language will be changed to German."); + wxMessageBox(Temp0); + } + //-------------------------------------------------------------------------------------- + if (Temp1 == "wxConfigBase Delete") + { + if (p_ProgramCfg->DeleteAll()) // Default Diretory for wxFileSelector + Temp0 = _("-I-> wxConfigBase.p_ProgramCfg->DeleteAll() was succesfull."); + else + Temp0 = _("-E-> wxConfigBase.p_ProgramCfg->DeleteAll() was not succesfull !"); + wxBell(); // Ding_a_Ling + Treffer++; + } + //-------------------------------------------------------------------------------------- + if (Temp1.Contains("ODBC-")) + { + Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); + for (i=0;ii_DSN;i++) + { + if (Temp1 == (pDoc->p_DSN+i)->Dsn) + { + pDoc->OnChosenDSN(i); + } + } + Treffer++; + } + //-------------------------------------------------------------------------------------- + if (Treffer == 0) + { + //------------------------------------------------------------------------------------- + Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," + "%u children (%u immediately under this item)."), + item->m_desc.c_str(), + bool2String(IsSelected(itemId)), + bool2String(IsExpanded(itemId)), + bool2String(IsBold(itemId)), + GetChildrenCount(itemId), + GetChildrenCount(itemId)); + LogBuf.Printf("-I-> PgmCtrl::OnSelChanged - %s",Temp0.c_str()); + wxLogMessage( "%s", LogBuf.c_str() ); + //------------------------------------------------------------------------------------- + } } - } - Treffer++; - } - //-------------------------------------------------------------------------------------- - if (Treffer == 0) - { - //------------------------------------------------------------------------------------- - Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," - "%u children (%u immediately under this item)."), - item->m_desc.c_str(), - bool2String(IsSelected(itemId)), - bool2String(IsExpanded(itemId)), - bool2String(IsBold(itemId)), - GetChildrenCount(itemId), - GetChildrenCount(itemId)); - LogBuf.Printf("-I-> PgmCtrl::OnSelChanged - %s",Temp0.c_str()); - wxLogMessage( "%s", LogBuf.c_str() ); - //------------------------------------------------------------------------------------- - } - } } + //---------------------------------------------------------------------------------------- void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event)) { - int i; - Temp0.Empty(); - // Get the Information that we need - wxTreeItemId itemId = GetSelection(); - DBTreeData *item = (DBTreeData *)GetItemData(itemId); - SaveDSN.Empty(); - if ( item != NULL ) - { - int Treffer = 0; - Temp1.Printf("%s",item->m_desc.c_str()); - //-------------------------------------------------------------------------------------- - if (Temp1.Contains("ODBC-")) - { - Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); - for (i=0;ii_DSN;i++) - { - if (Temp1 == (pDoc->p_DSN+i)->Dsn) + int i; + Temp0.Empty(); + // Get the Information that we need + wxTreeItemId itemId = GetSelection(); + DBTreeData *item = (DBTreeData *)GetItemData(itemId); + SaveDSN.Empty(); + if ( item != NULL ) { - SaveDSN = Temp1; - PopupMenu(popupMenu1,TreePos.x,TreePos.y); + int Treffer = 0; + Temp1.Printf("%s",item->m_desc.c_str()); + //-------------------------------------------------------------------------------------- + if (Temp1.Contains("ODBC-")) + { + Temp1 = Temp1.Mid(5,wxSTRING_MAXLEN); + for (i=0;ii_DSN;i++) + { + if (Temp1 == (pDoc->p_DSN+i)->Dsn) + { + SaveDSN = Temp1; + PopupMenu(popupMenu1,TreePos.x,TreePos.y); + } + } + Treffer++; + } + //-------------------------------------------------------------------------------------- + if (Treffer == 0) + { + /* + Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," + "%u children (%u immediately under this item)."), + item->m_desc.c_str(), + bool2String(IsSelected(itemId)), + bool2String(IsExpanded(itemId)), + bool2String(IsBold(itemId)), + GetChildrenCount(itemId), + GetChildrenCount(itemId)); + LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str()); + wxLogMessage( "%s", LogBuf.c_str() ); + */ + } + //-------------------------------------------------------------------------------------- } - } - Treffer++; - } - //-------------------------------------------------------------------------------------- - if (Treffer == 0) - { - /* - Temp0.Printf(_("Item '%s': %sselected, %sexpanded, %sbold," - "%u children (%u immediately under this item)."), - item->m_desc.c_str(), - bool2String(IsSelected(itemId)), - bool2String(IsExpanded(itemId)), - bool2String(IsBold(itemId)), - GetChildrenCount(itemId), - GetChildrenCount(itemId)); - LogBuf.Printf("-I-> DBTree::OnSelChanged - %s",Temp0.c_str()); - wxLogMessage( "%s", LogBuf.c_str() ); - */ - } - //-------------------------------------------------------------------------------------- - } } // void PgmCtrl::OnRightSelect(wxTreeEvent& WXUNUSED(event)) + //---------------------------------------------------------------------------------------- void PgmCtrl::OnMouseMove(wxMouseEvent &event) { - TreePos = event.GetPosition(); + TreePos = event.GetPosition(); } + //---------------------------------------------------------------------------------------- void PgmCtrl::OnUserPassword(wxCommandEvent& WXUNUSED(event)) { - // wxMessageBox(SaveDSN); - int i; - //-------------------------------------------- - DlgUser *p_Dlg = new DlgUser(this,pDoc,""); - //------------------------------------------- - for (i=0;ii_DSN;i++) - { - if (SaveDSN == (pDoc->p_DSN+i)->Dsn) - { - p_Dlg->pDoc = pDoc; - p_Dlg->s_DSN = (pDoc->p_DSN+i)->Dsn; - p_Dlg->s_User = (pDoc->p_DSN+i)->Usr; - p_Dlg->s_Password = (pDoc->p_DSN+i)->Pas; - p_Dlg->OnInit(); - p_Dlg->Fit(); - //-------------------- - // Temp0.Printf("i(%d) ; s_DSN(%s) ; s_User(%s) ; s_Password(%s)",i,p_Dlg.s_DSN,p_Dlg.s_User,p_Dlg.s_Password); - // wxMessageBox(Temp0); - bool OK = FALSE; - if (p_Dlg->ShowModal() == wxID_OK) - { - (pDoc->p_DSN+i)->Usr = p_Dlg->s_User; - (pDoc->p_DSN+i)->Pas = p_Dlg->s_Password; - (pDoc->db_Br+i)->UserName = (pDoc->p_DSN+i)->Usr; - (pDoc->db_Br+i)->Password = (pDoc->p_DSN+i)->Pas; - OK = TRUE; - } - delete p_Dlg; - if (!OK) return; - //-------------------- - break; // We have what we want, leave - } - } - //------------------------------------------- - SaveDSN.Empty(); + // wxMessageBox(SaveDSN); + int i; + //-------------------------------------------- + DlgUser *p_Dlg = new DlgUser(this,pDoc,""); + //------------------------------------------- + for (i=0;ii_DSN;i++) + { + wxYield(); + if (SaveDSN == (pDoc->p_DSN+i)->Dsn) + { + p_Dlg->pDoc = pDoc; + p_Dlg->s_DSN = (pDoc->p_DSN+i)->Dsn; + p_Dlg->s_User = (pDoc->p_DSN+i)->Usr; + p_Dlg->s_Password = (pDoc->p_DSN+i)->Pas; + p_Dlg->OnInit(); + p_Dlg->Fit(); + //-------------------- + // Temp0.Printf("i(%d) ; s_DSN(%s) ; s_User(%s) ; s_Password(%s)",i,p_Dlg.s_DSN,p_Dlg.s_User,p_Dlg.s_Password); + // wxMessageBox(Temp0); + bool OK = FALSE; + if (p_Dlg->ShowModal() == wxID_OK) + { + (pDoc->p_DSN+i)->Usr = p_Dlg->s_User; + (pDoc->p_DSN+i)->Pas = p_Dlg->s_Password; + (pDoc->db_Br+i)->UserName = (pDoc->p_DSN+i)->Usr; + (pDoc->db_Br+i)->Password = (pDoc->p_DSN+i)->Pas; + OK = TRUE; + } + delete p_Dlg; + if (!OK) + return; + //-------------------- + break; // We have what we want, leave + } + } + //------------------------------------------- + SaveDSN.Empty(); } //---------------------------------------------------------------------------------------- diff --git a/demos/dbbrowse/pgmctrl.h b/demos/dbbrowse/pgmctrl.h index 1910929d7f..80f7e26a7f 100644 --- a/demos/dbbrowse/pgmctrl.h +++ b/demos/dbbrowse/pgmctrl.h @@ -7,62 +7,66 @@ // RCS-ID: $Id$ // Copyright: (c) Mark Johnson, Berlin Germany, mj10777@gmx.net // Licence: wxWindows license + //---------------------------------------------------------------------------------------- class MainDoc; // Declared in doc.h file + //---------------------------------------------------------------------------------------- class TreeData : public wxTreeItemData { - public: - TreeData(const wxString& desc) : m_desc(desc) { } - void ShowInfo(wxTreeCtrl *tree); - wxString m_desc; +public: + TreeData(const wxString& desc) : m_desc(desc) { } + void ShowInfo(wxTreeCtrl *tree); + wxString m_desc; }; + //---------------------------------------------------------------------------------------- class PgmCtrl : public wxTreeCtrl { - public: - enum - { // The order here must be the same as in m_imageListNormal ! - TreeIc_Logo, // logo.ico - TreeIc_DsnClosed, // dsnclose.ico - TreeIc_DsnOpen, // dsnopen.ico - TreeIc_DocClosed, // d_closed.ico - TreeIc_DocOpen, // d_open.ico - TreeIc_FolderClosed, // f_closed.ico - TreeIc_FolderOpen // f_open.ico - }; - wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; -//---------------------------------------------------------------------------------------- - PgmCtrl() { } - PgmCtrl(wxWindow *parent); - PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size,long style); - virtual ~PgmCtrl(); - MainDoc *pDoc; -//---------------------------------------------------------------------------------------- - int i_TabArt; // Tab = 0 ; Page = 1; - int i_ViewNr; // View Nummer in Tab / Page -//---------------------------------------------------------------------------------------- - wxImageList *p_imageListNormal; - wxMenu *popupMenu1; // OnDBClass - wxPoint TreePos; - wxString SaveDSN; // Needed for User and Password -//---------------------------------------------------------------------------------------- - public: - int OnPopulate(); - void OnSelChanged(wxMouseEvent& event); - void OnRightSelect(wxTreeEvent& event); - void OnMouseMove(wxMouseEvent& event); - void OnUserPassword(wxCommandEvent& event); - - public: -//---------------------------------------------------------------------------------------- - // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() - // if you want your overloaded OnCompareItems() to be called. - // OTOH, if you don't want it you may omit the next line - this will - // make default (alphabetical) sorting much faster under wxMSW. - DECLARE_DYNAMIC_CLASS(PgmCtrl) - DECLARE_EVENT_TABLE() +public: + enum + { // The order here must be the same as in m_imageListNormal ! + TreeIc_Logo, // logo.ico + TreeIc_DsnClosed, // dsnclose.ico + TreeIc_DsnOpen, // dsnopen.ico + TreeIc_DocClosed, // d_closed.ico + TreeIc_DocOpen, // d_open.ico + TreeIc_FolderClosed, // f_closed.ico + TreeIc_FolderOpen // f_open.ico + }; + wxString Temp0, Temp1, Temp2, Temp3, Temp4, Temp5; + //---------------------------------------------------------------------------------------- + PgmCtrl() { } + PgmCtrl(wxWindow *parent); + PgmCtrl(wxWindow *parent, const wxWindowID id,const wxPoint& pos, const wxSize& size,long style); + virtual ~PgmCtrl(); + MainDoc *pDoc; + //---------------------------------------------------------------------------------------- + int i_TabArt; // Tab = 0 ; Page = 1; + int i_ViewNr; // View Nummer in Tab / Page + //---------------------------------------------------------------------------------------- + wxImageList *p_imageListNormal; + wxMenu *popupMenu1; // OnDBClass + wxPoint TreePos; + wxString SaveDSN; // Needed for User and Password + //---------------------------------------------------------------------------------------- +public: + int OnPopulate(); + void OnSelChanged(wxMouseEvent& event); + void OnRightSelect(wxTreeEvent& event); + void OnMouseMove(wxMouseEvent& event); + void OnUserPassword(wxCommandEvent& event); + +public: + //---------------------------------------------------------------------------------------- + // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() + // if you want your overloaded OnCompareItems() to be called. + // OTOH, if you don't want it you may omit the next line - this will + // make default (alphabetical) sorting much faster under wxMSW. + DECLARE_DYNAMIC_CLASS(PgmCtrl) + DECLARE_EVENT_TABLE() }; + //---------------------------------------------------------------------------------------- #define PGMCTRL_01_BEGIN 1000 #define PGMCTRL_ODBC_USER 1001 diff --git a/demos/dbbrowse/std.h b/demos/dbbrowse/std.h index c2655bca3a..ad57b7a60b 100644 --- a/demos/dbbrowse/std.h +++ b/demos/dbbrowse/std.h @@ -22,7 +22,7 @@ #include #include #ifdef __WXMSW__ - #include + #include #endif //--------------------------- #include "tabpgwin.h" // Original name : "controlarea.h" diff --git a/demos/dbbrowse/tabpgwin.cpp b/demos/dbbrowse/tabpgwin.cpp index f2728ed917..46b40bac50 100644 --- a/demos/dbbrowse/tabpgwin.cpp +++ b/demos/dbbrowse/tabpgwin.cpp @@ -5,10 +5,10 @@ // Modified by: 19990908 : mj10777@gmx.net // - rename to tabpgwin // - restruction of Variable declaration -// - to prevent Warnings under MingGW32 +// - to prevent Warnings under MingW32 // Modified by: 19990909 : mj10777@gmx.net // - mNoVertScroll TRUE = no / FALSE = Original Code -// the Original Code Paints a Vertical Scroll in wxPaggedWindow +// the Original Code Paints a Vertical Scroll in wxPagedWindow // which is not needed in this Version. Use TRUE for this. // Created: 07/09/98 // RCS-ID: $Id$ @@ -17,7 +17,7 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "controlarea.h" +#pragma implementation // #pragma interface #endif @@ -39,1106 +39,1163 @@ #include "wx/utils.h" // import wxMin/wxMax macros and wxFileExist(..) #include "tabpgwin.h" + //--------------------------------------------------------------------------- // Implementation for class twTabInfo //--------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS( twTabInfo, wxObject ) - //--------------------------------------------------------------------------- - twTabInfo::twTabInfo() - : mpContent( 0 ) + +//--------------------------------------------------------------------------- +twTabInfo::twTabInfo() +: mpContent( 0 ) {} + //--------------------------------------------------------------------------- twTabInfo::~twTabInfo() { - // FOR NOW:: nothing + // FOR NOW:: nothing } + //--------------------------------------------------------------------------- int twTabInfo::ImgWidth() { - if ( mBitMap.Ok() ) return mBitMap.GetWidth(); - else return 0; + if ( mBitMap.Ok() ) return mBitMap.GetWidth(); + else return 0; } + //--------------------------------------------------------------------------- int twTabInfo::ImgHeight() { - if ( mBitMap.Ok() ) return mBitMap.GetHeight(); - else return 0; + if ( mBitMap.Ok() ) + return mBitMap.GetHeight(); + else + return 0; } + //--------------------------------------------------------------------------- int twTabInfo::ImageToTxtGap( int prefGap ) { - if ( mBitMap.Ok() ) return prefGap; - else return 0; + if ( mBitMap.Ok() ) + return prefGap; + else + return 0; } + //--------------------------------------------------------------------------- bool twTabInfo::HasImg() { - return mBitMap.Ok(); + return mBitMap.Ok(); } + //--------------------------------------------------------------------------- // bool twTabInfo::HasText(); unsigned int twTabInfo::HasText() { - return mText.Length(); + return mText.Length(); } + //--------------------------------------------------------------------------- wxBitmap& twTabInfo::GetImg() { - return mBitMap; + return mBitMap; } + //--------------------------------------------------------------------------- wxString& twTabInfo::GetText() { - return mText; + return mText; } + //--------------------------------------------------------------------------- wxWindow& twTabInfo::GetContent() { - return *mpContent; + return *mpContent; } + //--------------------------------------------------------------------------- // Implementation for class wxTabbedWindow //--------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS( wxTabbedWindow, wxPanel ) - //--------------------------------------------------------------------------- - BEGIN_EVENT_TABLE( wxTabbedWindow, wxPanel ) - EVT_SIZE ( wxTabbedWindow::OnSize ) - EVT_PAINT( wxTabbedWindow::OnPaint ) - EVT_LEFT_DOWN( wxTabbedWindow::OnLButtonDown ) - // TDB:: filciker reduction - // EVT_ERASE_BACKGROUND( wxTabbedWindow::OnBkErase ) - END_EVENT_TABLE() - //--------------------------------------------------------------------------- - wxTabbedWindow::wxTabbedWindow() - - : mpTabScroll ( NULL ), - mpHorizScroll( NULL ), - mpVertScroll ( NULL ), - - mVertGap ( 0 ), - mHorizGap( 0 ), - - mTitleVertGap ( 3 ), - mTitleHorizGap( 4 ), - mImageTextGap ( 2 ), - mFirstTitleGap( 11 ), - - mBorderOnlyWidth( 8 ), - - mWhitePen( wxColour(255,255,255), 1, wxSOLID ), - mGrayPen ( wxColour(192,192,192), 1, wxSOLID ), - mDarkPen ( wxColour(128,128,128), 1, wxSOLID ), - mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID ), - - // state variables - - mActiveTab ( 0 ), - mTitleHeight( 0 ), - mLayoutType( wxTITLE_IMG_AND_TEXT ) + +//--------------------------------------------------------------------------- +BEGIN_EVENT_TABLE( wxTabbedWindow, wxPanel ) + EVT_SIZE ( wxTabbedWindow::OnSize ) + EVT_PAINT( wxTabbedWindow::OnPaint ) + EVT_LEFT_DOWN( wxTabbedWindow::OnLButtonDown ) + // TDB:: filciker reduction + // EVT_ERASE_BACKGROUND( wxTabbedWindow::OnBkErase ) +END_EVENT_TABLE() + +//--------------------------------------------------------------------------- +wxTabbedWindow::wxTabbedWindow() + +: mpTabScroll ( NULL ), + mpHorizScroll( NULL ), + mpVertScroll ( NULL ), + + mVertGap ( 0 ), + mHorizGap( 0 ), + + mTitleVertGap ( 3 ), + mTitleHorizGap( 4 ), + mImageTextGap ( 2 ), + mFirstTitleGap( 11 ), + + mBorderOnlyWidth( 8 ), + + mWhitePen( wxColour(255,255,255), 1, wxSOLID ), + mGrayPen ( wxColour(192,192,192), 1, wxSOLID ), + mDarkPen ( wxColour(128,128,128), 1, wxSOLID ), + mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID ), + + // state variables + mActiveTab ( 0 ), + mTitleHeight( 0 ), + mLayoutType( wxTITLE_IMG_AND_TEXT ) {} + //--------------------------------------------------------------------------- wxTabbedWindow::~wxTabbedWindow() { - wxNode* pTab = mTabs.First(); - - while( pTab ) + wxNode* pTab = mTabs.First(); + + while( pTab ) { - delete ((twTabInfo*)pTab->Data()); - pTab = pTab->Next(); + delete ((twTabInfo*)pTab->Data()); + pTab = pTab->Next(); } } + //--------------------------------------------------------------------------- void wxTabbedWindow::SizeTabs(int x,int y, int width, int height, bool repant) { - wxNode* pTabNode = mTabs.First(); - int n = 0; - - while( pTabNode ) - { - twTabInfo& info = *((twTabInfo*)pTabNode->Data()); - - if ( n == mActiveTab ) - { - //wxSizeEvent evt; - //info.mpContent->GetEventHandler()->ProcessEvent( evt ); - - info.mpContent->SetSize( x, y, width, height, 0 ); - info.mpContent->Show(TRUE); - info.mpContent->Refresh(); - - } - else - { - info.mpContent->Show(FALSE); - } - - pTabNode = pTabNode->Next(); - ++n; - } + wxNode* pTabNode = mTabs.First(); + int n = 0; + + while( pTabNode ) + { + twTabInfo& info = *((twTabInfo*)pTabNode->Data()); + + if ( n == mActiveTab ) + { + //wxSizeEvent evt; + //info.mpContent->GetEventHandler()->ProcessEvent( evt ); + + info.mpContent->SetSize( x, y, width, height, 0 ); + info.mpContent->Show(TRUE); + info.mpContent->Refresh(); + + } + else + { + info.mpContent->Show(FALSE); + } + + pTabNode = pTabNode->Next(); + ++n; + } } + //--------------------------------------------------------------------------- void wxTabbedWindow::AddTab( wxWindow* pContent, - wxString tabText, - wxString imageFileName, - long imageType ) + wxString tabText, + wxString imageFileName, + long imageType ) { - twTabInfo* pTab = new twTabInfo(); - - pTab->mpContent = pContent; - pTab->mText = tabText; - - if ( wxFileExists( imageFileName ) && - - pTab->mBitMap.LoadFile( imageFileName, imageType ) ) + twTabInfo* pTab = new twTabInfo(); + + pTab->mpContent = pContent; + pTab->mText = tabText; + + if ( wxFileExists( imageFileName ) && + + pTab->mBitMap.LoadFile( imageFileName, imageType ) ) { - pTab->mImageFile = imageFileName; - pTab->mImageType = imageType; + pTab->mImageFile = imageFileName; + pTab->mImageType = imageType; } - - - if ( pContent->GetParent() == NULL ) - pContent->Create( this, -1 ); - - mTabs.Append( (wxObject*)pTab ); - - RecalcLayout(TRUE); - - OnTabAdded( pTab ); + + + if ( pContent->GetParent() == NULL ) + pContent->Create( this, -1 ); + + mTabs.Append( (wxObject*)pTab ); + + RecalcLayout(TRUE); + + OnTabAdded( pTab ); } + //--------------------------------------------------------------------------- void wxTabbedWindow::AddTab( wxWindow* pContent, - wxString tabText, wxBitmap* pImage ) + wxString tabText, wxBitmap* pImage ) { - twTabInfo* pTab = new twTabInfo(); - - pTab->mpContent = pContent; - pTab->mText = tabText; - - if ( pImage ) - pTab->mBitMap = *pImage; - - if ( pContent->GetParent() == NULL ) - pContent->Create( this, -1 ); - - mTabs.Append( (wxObject*)pTab ); - RecalcLayout(TRUE); - OnTabAdded( pTab ); + twTabInfo* pTab = new twTabInfo(); + + pTab->mpContent = pContent; + pTab->mText = tabText; + + if ( pImage ) + pTab->mBitMap = *pImage; + + if ( pContent->GetParent() == NULL ) + pContent->Create( this, -1 ); + + mTabs.Append( (wxObject*)pTab ); + RecalcLayout(TRUE); + OnTabAdded( pTab ); } + //--------------------------------------------------------------------------- void wxTabbedWindow::RemoveTab( int tabNo ) { - twTabInfo* pTab = ((twTabInfo*)(mTabs.Nth( tabNo )->Data())); - pTab->mpContent->Destroy(); - delete pTab; - mTabs.DeleteNode( mTabs.Nth( tabNo ) ); - // if ( mActiveTab >= mTabs.Number() ); - if ( mActiveTab >= mTabs.Number() ) - mActiveTab = mTabs.Number() - 1; - SetActiveTab( mActiveTab ); + twTabInfo* pTab = ((twTabInfo*)(mTabs.Nth( tabNo )->Data())); + pTab->mpContent->Destroy(); + delete pTab; + mTabs.DeleteNode( mTabs.Nth( tabNo ) ); + // if ( mActiveTab >= mTabs.Number() ); + if ( mActiveTab >= mTabs.Number() ) + mActiveTab = mTabs.Number() - 1; + SetActiveTab( mActiveTab ); } + //--------------------------------------------------------------------------- int wxTabbedWindow::GetTabCount() { - return mTabs.Number(); + return mTabs.Number(); } + //--------------------------------------------------------------------------- wxWindow* wxTabbedWindow::GetTab( int tabNo ) { - return ((twTabInfo*)(mTabs.Nth( tabNo )->Data()))->mpContent; + return ((twTabInfo*)(mTabs.Nth( tabNo )->Data()))->mpContent; } + //--------------------------------------------------------------------------- wxWindow* wxTabbedWindow::GetActiveTab() { - // FIMXE:: this is lame - return GetTab( mActiveTab ); + // FIMXE:: this is lame + return GetTab( mActiveTab ); } + //--------------------------------------------------------------------------- void wxTabbedWindow::SetActiveTab( int tabNo ) { - mActiveTab = tabNo; - RecalcLayout(TRUE); - Refresh(); + mActiveTab = tabNo; + RecalcLayout(TRUE); + Refresh(); } + //--------------------------------------------------------------------------- // width of the decorations border (4 shade-lines), should not be changed //--------------------------------------------------------------------------- #define BORDER_SZ 4 + //--------------------------------------------------------------------------- void wxTabbedWindow::DrawShadedRect( int x, int y, int width, int height, - wxPen& upperPen, wxPen& lowerPen, wxDC& dc - ) + wxPen& upperPen, wxPen& lowerPen, wxDC& dc + ) { - // darw the lightened upper-left sides of the rectangle - - dc.SetPen( upperPen ); - dc.DrawLine( x,y, x, y + height - 1 ); // vert - dc.DrawLine( x,y, x + width - 1, y ); // horiz - - // draw the unenlightened lower-right sides of the rectangle - - dc.SetPen( lowerPen ); - dc.DrawLine( x + width - 1, y, x + width - 1, y + height - 1 ); // vert - dc.DrawLine( x, y + height - 1, x + width, y + height - 1 ); // horiz + // darw the lightened upper-left sides of the rectangle + + dc.SetPen( upperPen ); + dc.DrawLine( x,y, x, y + height - 1 ); // vert + dc.DrawLine( x,y, x + width - 1, y ); // horiz + + // draw the unenlightened lower-right sides of the rectangle + + dc.SetPen( lowerPen ); + dc.DrawLine( x + width - 1, y, x + width - 1, y + height - 1 ); // vert + dc.DrawLine( x, y + height - 1, x + width, y + height - 1 ); // horiz } + //--------------------------------------------------------------------------- void wxTabbedWindow::DrawDecorations( wxDC& dc ) { - // Protability NOTE::: DrawLine(..) draws a line from the first position, - // but not including the point specified by last position. - // This way Windows draws lines, not sure how Motif and Gtk - // prots behave... - - int width, height; - GetClientSize( &width, &height ); - - // check if there's at least a bit of space to draw things - - if ( width < mHorizGap*2 + BORDER_SZ*2+1 || - height < mVertGap*2 + BORDER_SZ*2+1 + mTitleHeight - ) - return; - - // step #1 - draw border around the tab content area - - // setup position for kind of "pencil" - int curX = mHorizGap; - int curY = mVertGap; - - int xSize = width - mHorizGap*2; - int ySize = height - mVertGap *2 - mTitleHeight; - - // layer 1 (upper white) - DrawShadedRect( curX+0, curY+0, xSize-0, ySize-0, - mWhitePen, mBlackPen, dc ); - - // layer 2 (upper gray) - DrawShadedRect( curX+1, curY+1, xSize-2-1, ySize-2-1, - mGrayPen, mGrayPen, dc ); - - // layer 3 (upper darkGray) - DrawShadedRect( curX+2, curY+2, xSize-3-2, ySize-3-2, - mDarkPen, mWhitePen, dc ); - - // layer 4 (upper black) - DrawShadedRect( curX+3, curY+3, xSize-4-3, ySize-4-3, - mBlackPen, mGrayPen, dc ); - - // add non-siemtric layer from the lower-right side (confroming to MFC-look) - - dc.SetPen( mDarkPen ); - dc.DrawLine( curX+1, curY + ySize - 2, curX + xSize - 1, curY + ySize - 2 ); // horiz - dc.DrawLine( curX + xSize - 2, curY + 1, curX + xSize - 2, curY + ySize - 2 ); // vert - - // step #2 - draw tab title bars - - curX = mFirstTitleGap; - curY = height - mVertGap - mTitleHeight; - - int tabNo = 0; - wxNode* pNode = mTabs.First(); - - while( pNode ) - { - // "hard-coded metafile" for decorations - - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - xSize = tab.mDims.x; - ySize = mTitleHeight; - - if ( tabNo == mActiveTab ) - { - dc.SetPen( mGrayPen ); - dc.DrawLine( curX+1, curY-2, curX+xSize-2, curY-2 ); - dc.DrawLine( curX+1, curY-1, curX+xSize-2, curY-1 ); - } - - dc.SetPen( mWhitePen ); - - if ( tabNo == mActiveTab ) - dc.DrawLine( curX, curY-2, curX, curY+ySize-2 ); - else - dc.DrawLine( curX, curY, curX, curY+ySize-2 ); - - dc.SetPen( mDarkPen ); - dc.DrawLine( curX+1, curY+ySize-3, curX+1, curY+ySize-1 ); // to pix down - dc.DrawLine( curX+2, curY+ySize-2, curX+xSize-2, curY+ySize-2 ); - dc.DrawLine( curX+xSize-3, curY+ySize-3, curX+xSize-2, curY+ySize-3 ); - if ( tabNo == mActiveTab ) - dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-3 ); - else - dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-1 ); - - dc.SetPen( mBlackPen ); - dc.DrawLine( curX+xSize-1, curY, curX+xSize-1, curY+ySize-2 ); - dc.DrawLine( curX+xSize-2, curY+ySize-2, curX+xSize-3, curY+ySize-2 ); - dc.DrawLine( curX+xSize-3, curY+ySize-1, curX+1, curY+ySize-1 ); - - pNode = pNode->Next(); - ++tabNo; - - // darw image and (or without) text centered within the - // title bar rectangle - - if ( mLayoutType != wxTITLE_BORDER_ONLY && tab.HasImg() ) - { - wxMemoryDC tmpDc; - tmpDc.SelectObject( tab.GetImg() ); - - dc.Blit( curX + mTitleHorizGap, - curY + ( ySize - tab.ImgHeight() ) / 2, - tab.ImgWidth(), - tab.ImgHeight(), - &tmpDc, 0, 0, wxCOPY - ); - } - - if ( mLayoutType == wxTITLE_IMG_AND_TEXT && tab.HasText() ) + // Protability NOTE::: DrawLine(..) draws a line from the first position, + // but not including the point specified by last position. + // This way Windows draws lines, not sure how Motif and Gtk + // prots behave... + + int width, height; + GetClientSize( &width, &height ); + + // check if there's at least a bit of space to draw things + + if ( width < mHorizGap*2 + BORDER_SZ*2+1 || + height < mVertGap*2 + BORDER_SZ*2+1 + mTitleHeight + ) + return; + + // step #1 - draw border around the tab content area + + // setup position for kind of "pencil" + int curX = mHorizGap; + int curY = mVertGap; + + int xSize = width - mHorizGap*2; + int ySize = height - mVertGap *2 - mTitleHeight; + + // layer 1 (upper white) + DrawShadedRect( curX+0, curY+0, xSize-0, ySize-0, + mWhitePen, mBlackPen, dc ); + + // layer 2 (upper gray) + DrawShadedRect( curX+1, curY+1, xSize-2-1, ySize-2-1, + mGrayPen, mGrayPen, dc ); + + // layer 3 (upper darkGray) + DrawShadedRect( curX+2, curY+2, xSize-3-2, ySize-3-2, + mDarkPen, mWhitePen, dc ); + + // layer 4 (upper black) + DrawShadedRect( curX+3, curY+3, xSize-4-3, ySize-4-3, + mBlackPen, mGrayPen, dc ); + + // add non-siemtric layer from the lower-right side (confroming to MFC-look) + + dc.SetPen( mDarkPen ); + dc.DrawLine( curX+1, curY + ySize - 2, curX + xSize - 1, curY + ySize - 2 ); // horiz + dc.DrawLine( curX + xSize - 2, curY + 1, curX + xSize - 2, curY + ySize - 2 ); // vert + + // step #2 - draw tab title bars + + curX = mFirstTitleGap; + curY = height - mVertGap - mTitleHeight; + + int tabNo = 0; + wxNode* pNode = mTabs.First(); + + while( pNode ) { - long x,w,h; - - // set select default font of the window into it's device context - //dc.SetFont( GetLabelingFont() ); - - dc.SetTextBackground( GetBackgroundColour() ); - - dc.GetTextExtent(tab.mText, &w, &h ); - - x = curX + mTitleHorizGap + - tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap); - - dc.DrawText( tab.GetText(), x, curY + ( ySize - h ) / 2 ); - } - curX += xSize; - + // "hard-coded metafile" for decorations + + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + xSize = tab.mDims.x; + ySize = mTitleHeight; + + if ( tabNo == mActiveTab ) + { + dc.SetPen( mGrayPen ); + dc.DrawLine( curX+1, curY-2, curX+xSize-2, curY-2 ); + dc.DrawLine( curX+1, curY-1, curX+xSize-2, curY-1 ); + } + + dc.SetPen( mWhitePen ); + + if ( tabNo == mActiveTab ) + dc.DrawLine( curX, curY-2, curX, curY+ySize-2 ); + else + dc.DrawLine( curX, curY, curX, curY+ySize-2 ); + + dc.SetPen( mDarkPen ); + dc.DrawLine( curX+1, curY+ySize-3, curX+1, curY+ySize-1 ); // to pix down + dc.DrawLine( curX+2, curY+ySize-2, curX+xSize-2, curY+ySize-2 ); + dc.DrawLine( curX+xSize-3, curY+ySize-3, curX+xSize-2, curY+ySize-3 ); + if ( tabNo == mActiveTab ) + dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-3 ); + else + dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-1 ); + + dc.SetPen( mBlackPen ); + dc.DrawLine( curX+xSize-1, curY, curX+xSize-1, curY+ySize-2 ); + dc.DrawLine( curX+xSize-2, curY+ySize-2, curX+xSize-3, curY+ySize-2 ); + dc.DrawLine( curX+xSize-3, curY+ySize-1, curX+1, curY+ySize-1 ); + + pNode = pNode->Next(); + ++tabNo; + + // darw image and (or without) text centered within the + // title bar rectangle + + if ( mLayoutType != wxTITLE_BORDER_ONLY && tab.HasImg() ) + { + wxMemoryDC tmpDc; + tmpDc.SelectObject( tab.GetImg() ); + + dc.Blit( curX + mTitleHorizGap, + curY + ( ySize - tab.ImgHeight() ) / 2, + tab.ImgWidth(), + tab.ImgHeight(), + &tmpDc, 0, 0, wxCOPY + ); + } + + if ( mLayoutType == wxTITLE_IMG_AND_TEXT && tab.HasText() ) + { + long x,w,h; + + // set select default font of the window into it's device context + //dc.SetFont( GetLabelingFont() ); + + dc.SetTextBackground( GetBackgroundColour() ); + + dc.GetTextExtent(tab.mText, &w, &h ); + + x = curX + mTitleHorizGap + + tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap); + + dc.DrawText( tab.GetText(), x, curY + ( ySize - h ) / 2 ); + } + curX += xSize; + } // end of `while (pNode)' -} +} // wxTabbedWindow::DrawDecorations() + //--------------------------------------------------------------------------- int wxTabbedWindow::HitTest( const wxPoint& pos ) { - int width, height; - GetClientSize( &width, &height ); - - int curX = mFirstTitleGap; - int curY = height - mVertGap - mTitleHeight; - - int tabNo = 0; - wxNode* pNode = mTabs.First(); - - while( pNode ) + int width, height; + GetClientSize( &width, &height ); + + int curX = mFirstTitleGap; + int curY = height - mVertGap - mTitleHeight; + + int tabNo = 0; + wxNode* pNode = mTabs.First(); + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - int w,h; - w = tab.mDims.x; - h = tab.mDims.y; - // hit test rectangle of the currnet tab title bar - if ( pos.x >= curX && pos.x < curX + tab.mDims.x && - pos.y >= curY && pos.y < curY + tab.mDims.y - ) - { - return tabNo; - } - - curX += tab.mDims.x; - - pNode = pNode->Next(); - ++tabNo; + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + int w,h; + w = tab.mDims.x; + h = tab.mDims.y; + // hit test rectangle of the currnet tab title bar + if ( pos.x >= curX && pos.x < curX + tab.mDims.x && + pos.y >= curY && pos.y < curY + tab.mDims.y + ) + { + return tabNo; + } + + curX += tab.mDims.x; + + pNode = pNode->Next(); + ++tabNo; } - - return -1; -} + + return -1; +} // wxTabbedWindow::HitTest() + //--------------------------------------------------------------------------- void wxTabbedWindow::HideInactiveTabs( bool andRepaint ) { - if ( !andRepaint ) - return; - - wxNode* pNode = mTabs.First(); - int tabNo = 0; - - while( pNode ) + if ( !andRepaint ) + return; + + wxNode* pNode = mTabs.First(); + int tabNo = 0; + + while( pNode ) { - if ( tabNo != mActiveTab ) - { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - tab.mpContent->Show(FALSE); - } - - pNode = pNode->Next(); - ++tabNo; + if ( tabNo != mActiveTab ) + { + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + tab.mpContent->Show(FALSE); + } + + pNode = pNode->Next(); + ++tabNo; } -} +} // wxTabbedWindow::HideInactiveTabs() + //--------------------------------------------------------------------------- wxFont wxTabbedWindow::GetLabelingFont() { - wxFont font; + wxFont font; #ifdef __WINDOWS__ - font.SetFaceName("MS Sans Serif"); + font.SetFaceName("MS Sans Serif"); #else - font.SetFamily( wxSWISS ); + font.SetFamily( wxSWISS ); #endif - - font.SetStyle(40); - font.SetWeight(40); - font.SetPointSize( 8 ); - + + font.SetStyle(40); + font.SetWeight(40); + font.SetPointSize( 8 ); + #ifdef __WINDOWS__ - font.RealizeResource(); + font.RealizeResource(); #endif - - return font; -} + + return font; +} // wxTabbedWindow::GetLabelingFont() + //--------------------------------------------------------------------------- void wxTabbedWindow::RecalcLayout(bool andRepaint) { - HideInactiveTabs(andRepaint); - - // resetup position of the active tab - - int width, height; - GetClientSize( &width, &height ); - - int curX = mHorizGap + BORDER_SZ; - int curY = mVertGap + BORDER_SZ; - - int xSize = width - mHorizGap*2 - BORDER_SZ*2-1; - int ySize = height - mVertGap*2 - BORDER_SZ*2-1 - mTitleHeight; - - SizeTabs( curX, curY, xSize, ySize, andRepaint ); - - // pass #1 - try to layout assuming it's wxTITLE_IMG_AND_TEXT - - mLayoutType = wxTITLE_IMG_AND_TEXT; - - wxNode* pNode = mTabs.First(); - - curX = mFirstTitleGap; // the left-side gap - mTitleHeight = 0; - - while( pNode ) + HideInactiveTabs(andRepaint); + + // resetup position of the active tab + + int width, height; + GetClientSize( &width, &height ); + + int curX = mHorizGap + BORDER_SZ; + int curY = mVertGap + BORDER_SZ; + + int xSize = width - mHorizGap*2 - BORDER_SZ*2-1; + int ySize = height - mVertGap*2 - BORDER_SZ*2-1 - mTitleHeight; + + SizeTabs( curX, curY, xSize, ySize, andRepaint ); + + // pass #1 - try to layout assuming it's wxTITLE_IMG_AND_TEXT + + mLayoutType = wxTITLE_IMG_AND_TEXT; + + wxNode* pNode = mTabs.First(); + + curX = mFirstTitleGap; // the left-side gap + mTitleHeight = 0; + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - wxWindowDC dc(this); - - long w,h; - - // set select default font of the window into it's device context - //dc.SetFont( GetLabelingFont() ); - - dc.GetTextExtent(tab.mText, &w, &h ); - - tab.mDims.x = w + tab.ImageToTxtGap(mImageTextGap) + - tab.ImgWidth() + mTitleHorizGap*2; - - tab.mDims.y = wxMax( h, tab.ImgHeight() ) + mTitleVertGap*2; - mTitleHeight = wxMax( mTitleHeight, tab.mDims.y ); - - curX += tab.mDims.x; - - pNode = pNode->Next(); + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + wxWindowDC dc(this); + + long w,h; + + // set select default font of the window into it's device context + //dc.SetFont( GetLabelingFont() ); + + dc.GetTextExtent(tab.mText, &w, &h ); + + tab.mDims.x = w + tab.ImageToTxtGap(mImageTextGap) + + tab.ImgWidth() + mTitleHorizGap*2; + + tab.mDims.y = wxMax( h, tab.ImgHeight() ) + mTitleVertGap*2; + mTitleHeight = wxMax( mTitleHeight, tab.mDims.y ); + + curX += tab.mDims.x; + + pNode = pNode->Next(); } - - curX += mHorizGap; // the right-side gap - - // make all title bars of equel height - - pNode = mTabs.First(); - - while( pNode ) + + curX += mHorizGap; // the right-side gap + + // make all title bars of equel height + + pNode = mTabs.First(); + + while( pNode ) { - ((twTabInfo*)(pNode->Data()))->mDims.y = mTitleHeight;; - pNode = pNode->Next(); + ((twTabInfo*)(pNode->Data()))->mDims.y = mTitleHeight;; + pNode = pNode->Next(); } - - // if curX has'nt ran out of bounds, leave TITLE_IMG layout and return - if ( curX < width - mHorizGap ) - return; - - // pass #2 - try to layout assuming wxTITLE_IMG_ONLY - - mLayoutType = wxTITLE_IMG_ONLY; - - pNode = mTabs.First(); - - curX = mFirstTitleGap; // the left-side gap - - int denomiator = mTabs.Number(); - if ( denomiator == 0 ) ++denomiator; - - mBorderOnlyWidth = (width - mFirstTitleGap - mHorizGap) / denomiator; - - while( pNode ) + + // if curX has'nt ran out of bounds, leave TITLE_IMG layout and return + if ( curX < width - mHorizGap ) + return; + + // pass #2 - try to layout assuming wxTITLE_IMG_ONLY + + mLayoutType = wxTITLE_IMG_ONLY; + + pNode = mTabs.First(); + + curX = mFirstTitleGap; // the left-side gap + + int denomiator = mTabs.Number(); + if ( denomiator == 0 ) + ++denomiator; + + mBorderOnlyWidth = (width - mFirstTitleGap - mHorizGap) / denomiator; + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - if ( tab.HasImg() ) - { - tab.mDims.x = tab.ImgWidth() + mTitleHorizGap*2; - tab.mDims.y = tab.ImgHeight() + mTitleVertGap*2; - } - else - { - tab.mDims.x = mBorderOnlyWidth; - tab.mDims.y = mTitleHeight; - } - - curX += tab.mDims.x; - - pNode = pNode->Next(); + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + if ( tab.HasImg() ) + { + tab.mDims.x = tab.ImgWidth() + mTitleHorizGap*2; + tab.mDims.y = tab.ImgHeight() + mTitleVertGap*2; + } + else + { + tab.mDims.x = mBorderOnlyWidth; + tab.mDims.y = mTitleHeight; + } + + curX += tab.mDims.x; + + pNode = pNode->Next(); } - - curX += mHorizGap; // the right-side gap - - // if curX has'nt ran out of bounds, leave IMG_ONLY layout and return - if ( curX < width - mHorizGap ) - return; - - // pass #3 - set the narrowest layout wxTITLE_BORDER_ONLY - - mLayoutType = wxTITLE_BORDER_ONLY; - - pNode = mTabs.First(); - - while( pNode ) + + curX += mHorizGap; // the right-side gap + + // if curX has'nt ran out of bounds, leave IMG_ONLY layout and return + if ( curX < width - mHorizGap ) + return; + + // pass #3 - set the narrowest layout wxTITLE_BORDER_ONLY + + mLayoutType = wxTITLE_BORDER_ONLY; + + pNode = mTabs.First(); + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - tab.mDims.x = mBorderOnlyWidth; - tab.mDims.y = mTitleHeight; - - pNode = pNode->Next(); + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + tab.mDims.x = mBorderOnlyWidth; + tab.mDims.y = mTitleHeight; + + pNode = pNode->Next(); } -} +} // wxTabbedWindow::RecalcLayout() + //--------------------------------------------------------------------------- // wx event handlers //--------------------------------------------------------------------------- void wxTabbedWindow::OnPaint( wxPaintEvent& event ) { - wxPaintDC dc(this); - DrawDecorations( dc ); + wxPaintDC dc(this); + DrawDecorations( dc ); } + //--------------------------------------------------------------------------- void wxTabbedWindow::OnSize ( wxSizeEvent& event ) { - SetBackgroundColour( wxColour( 192,192,192 ) ); - RecalcLayout(TRUE); + SetBackgroundColour( wxColour( 192,192,192 ) ); + RecalcLayout(TRUE); } + //--------------------------------------------------------------------------- void wxTabbedWindow::OnBkErase( wxEraseEvent& event ) { - // do nothing + // do nothing } + //--------------------------------------------------------------------------- void wxTabbedWindow::OnLButtonDown( wxMouseEvent& event ) { - // floats, why? - int x = (int)event.m_x; - int y = (int)event.m_y; - - int tabNo = HitTest( wxPoint(x,y) ); - - if ( tabNo != -1 ) + // floats, why? + int x = (int)event.m_x; + int y = (int)event.m_y; + + int tabNo = HitTest( wxPoint(x,y) ); + + if ( tabNo != -1 ) { - SetActiveTab( tabNo ); + SetActiveTab( tabNo ); } } + +//--------------------------------------------------------------------------- +// Implementation for class wxPagedWindow +//--------------------------------------------------------------------------- +IMPLEMENT_DYNAMIC_CLASS( wxPagedWindow, wxTabbedWindow ) + +//--------------------------------------------------------------------------- +BEGIN_EVENT_TABLE( wxPagedWindow, wxTabbedWindow ) + EVT_SIZE ( wxPagedWindow::OnSize ) + EVT_PAINT ( wxPagedWindow::OnPaint ) + EVT_LEFT_DOWN( wxPagedWindow::OnLButtonDown ) + EVT_LEFT_UP ( wxPagedWindow::OnLButtonUp ) + EVT_MOTION ( wxPagedWindow::OnMouseMove ) + EVT_SCROLL ( wxPagedWindow::OnScroll ) +END_EVENT_TABLE() + //--------------------------------------------------------------------------- -// Implementation for class wxPaggedWindow +// border for paged-window is 2 shaded-lines //--------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxPaggedWindow, wxTabbedWindow ) - //--------------------------------------------------------------------------- - BEGIN_EVENT_TABLE( wxPaggedWindow, wxTabbedWindow ) - EVT_SIZE ( wxPaggedWindow::OnSize ) - EVT_PAINT ( wxPaggedWindow::OnPaint ) - EVT_LEFT_DOWN( wxPaggedWindow::OnLButtonDown ) - EVT_LEFT_UP ( wxPaggedWindow::OnLButtonUp ) - EVT_MOTION ( wxPaggedWindow::OnMouseMove ) - EVT_SCROLL ( wxPaggedWindow::OnScroll ) - END_EVENT_TABLE() - //--------------------------------------------------------------------------- - // border for pagged-window is 2 shaded-lines - //--------------------------------------------------------------------------- #undef BORDER_SZ #define BORDER_SZ 2 - //--------------------------------------------------------------------------- - wxPaggedWindow::wxPaggedWindow() - - : mScrollEventInProgress( FALSE ), - - mTabTrianGap(4), - - mWhiteBrush( wxColour(255,255,255), wxSOLID ), - mGrayBrush ( wxColour(192,192,192), wxSOLID ), - - mCurentRowOfs( 0 ), - mAdjustableTitleRowLen( 300 ), - - mIsDragged ( FALSE ), - mDagOrigin ( 0 ), - mCursorChanged( FALSE ), - mResizeCursor ( wxCURSOR_SIZEWE ), - mNormalCursor ( wxCURSOR_ARROW ) + +//--------------------------------------------------------------------------- +wxPagedWindow::wxPagedWindow() + +: mScrollEventInProgress( FALSE ), + mTabTrianGap(4), + mWhiteBrush( wxColour(255,255,255), wxSOLID ), + mGrayBrush ( wxColour(192,192,192), wxSOLID ), + mCurentRowOfs( 0 ), + mAdjustableTitleRowLen( 300 ), + mIsDragged ( FALSE ), + mDagOrigin ( 0 ), + mCursorChanged( FALSE ), + mResizeCursor ( wxCURSOR_SIZEWE ), + mNormalCursor ( wxCURSOR_ARROW ) { - mTitleVertGap = 2; - mTitleHorizGap = 10; - mNoVertScroll = TRUE; // Horizontale Scroll abschalten + mTitleVertGap = 2; + mTitleHorizGap = 10; + mNoVertScroll = TRUE; // Horizontale Scroll abschalten } + //--------------------------------------------------------------------------- -wxPaggedWindow::~wxPaggedWindow() +wxPagedWindow::~wxPagedWindow() { - // nothing (base class handles destruction) + // nothing (base class handles destruction) } + //--------------------------------------------------------------------------- -wxFont wxPaggedWindow::GetLabelingFont() +wxFont wxPagedWindow::GetLabelingFont() { - wxFont font; - + wxFont font; + #ifdef __WINDOWS__ - font.SetFaceName("Comic Sans MS"); + font.SetFaceName("Comic Sans MS"); #else - font.SetFamily( wxSWISS ); + font.SetFamily( wxSWISS ); #endif - - font.SetStyle(40); - font.SetWeight(40); - font.SetPointSize( 8 ); - - return font; + + font.SetStyle(40); + font.SetWeight(40); + font.SetPointSize( 8 ); + + return font; } + //--------------------------------------------------------------------------- -void wxPaggedWindow::OnTabAdded( twTabInfo* pInfo ) +void wxPagedWindow::OnTabAdded( twTabInfo* pInfo ) { - int units = GetWholeTabRowLen() / 20; - - mpTabScroll->SetScrollbar( 0, 1, units, 1, FALSE ); + int units = GetWholeTabRowLen() / 20; + + mpTabScroll->SetScrollbar( 0, 1, units, 1, FALSE ); } + //--------------------------------------------------------------------------- -wxScrollBar& wxPaggedWindow::GetVerticalScrollBar() +wxScrollBar& wxPagedWindow::GetVerticalScrollBar() { - return *mpVertScroll; + return *mpVertScroll; } + //--------------------------------------------------------------------------- -wxScrollBar& wxPaggedWindow::GetHorizontalScrollBar() +wxScrollBar& wxPagedWindow::GetHorizontalScrollBar() { - return *mpHorizScroll; + return *mpHorizScroll; } + //--------------------------------------------------------------------------- -int wxPaggedWindow::GetWholeTabRowLen() +int wxPagedWindow::GetWholeTabRowLen() { - wxNode* pNode = mTabs.First(); - - int len = 0; - - while( pNode ) + wxNode* pNode = mTabs.First(); + + int len = 0; + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - len += tab.mDims.x; - pNode = pNode->Next(); + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + len += tab.mDims.x; + pNode = pNode->Next(); } - - return len; -} + + return len; +} // wxPagedWindow::GetWholeTabRowLen() + //--------------------------------------------------------------------------- -void wxPaggedWindow::DrawPaperBar( twTabInfo& tab, int x, int y, - wxBrush& brush, wxPen& pen, wxDC& dc ) +void wxPagedWindow::DrawPaperBar( twTabInfo& tab, int x, int y, + wxBrush& brush, wxPen& pen, wxDC& dc ) { - wxPoint poly[4]; - - // draw organizer-style paper outlet - - poly[0].x = x - mTabTrianGap; - poly[0].y = y; - - poly[1].x = x + mTabTrianGap; - poly[1].y = y + tab.mDims.y-1; - - poly[2].x = x + tab.mDims.x - mTabTrianGap; - poly[2].y = y + tab.mDims.y-1; - - poly[3].x = x + tab.mDims.x + mTabTrianGap; - poly[3].y = y; - - dc.SetPen( pen ); - dc.SetBrush( brush ); - - dc.DrawPolygon( 4, poly ); - - long w,h; - - // set select default font of the window into it's device context - //dc.SetFont( GetLabelingFont() ); - - dc.SetTextBackground( brush.GetColour() ); - - dc.GetTextExtent(tab.mText, &w, &h ); - - if ( tab.HasImg() ) + wxPoint poly[4]; + + // draw organizer-style paper outlet + + poly[0].x = x - mTabTrianGap; + poly[0].y = y; + + poly[1].x = x + mTabTrianGap; + poly[1].y = y + tab.mDims.y-1; + + poly[2].x = x + tab.mDims.x - mTabTrianGap; + poly[2].y = y + tab.mDims.y-1; + + poly[3].x = x + tab.mDims.x + mTabTrianGap; + poly[3].y = y; + + dc.SetPen( pen ); + dc.SetBrush( brush ); + + dc.DrawPolygon( 4, poly ); + + long w,h; + + // set select default font of the window into it's device context + //dc.SetFont( GetLabelingFont() ); + + dc.SetTextBackground( brush.GetColour() ); + + dc.GetTextExtent(tab.mText, &w, &h ); + + if ( tab.HasImg() ) { - wxMemoryDC tmpDc; - tmpDc.SelectObject( tab.GetImg() ); - - dc.Blit( x + mTitleHorizGap, - y + ( tab.mDims.y - tab.ImgHeight() ) / 2, - tab.ImgWidth(), - tab.ImgHeight(), - &tmpDc, 0, 0, wxCOPY - ); + wxMemoryDC tmpDc; + tmpDc.SelectObject( tab.GetImg() ); + + dc.Blit( x + mTitleHorizGap, + y + ( tab.mDims.y - tab.ImgHeight() ) / 2, + tab.ImgWidth(), + tab.ImgHeight(), + &tmpDc, 0, 0, wxCOPY + ); } - - if ( tab.HasText() ) + + if ( tab.HasText() ) { - int tx = x + mTitleHorizGap + - tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap); - - dc.DrawText( tab.GetText(), tx, y + ( tab.mDims.y - h ) / 2 ); + int tx = x + mTitleHorizGap + + tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap); + + dc.DrawText( tab.GetText(), tx, y + ( tab.mDims.y - h ) / 2 ); } -} +} // wxPagedWindow::DrawPaperBar() + //--------------------------------------------------------------------------- -void wxPaggedWindow::DrawDecorations( wxDC& dc ) +void wxPagedWindow::DrawDecorations( wxDC& dc ) { - // FIXME:: the is big body have to be split! - - int width, height; - GetClientSize( &width, &height ); - - int curX = mHorizGap; - int curY = mVertGap; - - int xSize = width - mHorizGap*2; - int ySize = height - mVertGap*2; - - DrawShadedRect( curX, curY, xSize, ySize, - mDarkPen, mWhitePen, dc ); - - DrawShadedRect( curX+1, curY+1, xSize-2, ySize-2, - mBlackPen, mGrayPen, dc ); - - // draw inactive tab title bars frist (left-to-right) - - wxNode* pNode = mTabs.First(); - int tabNo = 0; - - /* OLD STUFF:: - curX = mTitleRowStart; - curY = height - mVertGap - BORDER_SZ - mTitleHeight; - */ - - curX = mTabTrianGap; - curY = 0; - - // FOR NOW:: avoid creating bitmap with invalid dimensions - - if ( mTitleRowLen < 1 || mTitleHeight < 1 ) return; - - wxMemoryDC tmpDc; - wxBitmap tmpBmp( mTitleRowLen, mTitleHeight ); - - tmpDc.SelectObject( tmpBmp ); - tmpDc.SetPen( mGrayPen ); - tmpDc.SetBrush( mGrayBrush ); - tmpDc.DrawRectangle( 0,0, mTitleRowLen, mTitleHeight ); - - tmpDc.SetDeviceOrigin( mCurentRowOfs, 0 ); - - while( pNode ) + // FIXME:: the is big body have to be split! + + int width, height; + GetClientSize( &width, &height ); + + int curX = mHorizGap; + int curY = mVertGap; + + int xSize = width - mHorizGap*2; + int ySize = height - mVertGap*2; + + DrawShadedRect( curX, curY, xSize, ySize, + mDarkPen, mWhitePen, dc ); + + DrawShadedRect( curX+1, curY+1, xSize-2, ySize-2, + mBlackPen, mGrayPen, dc ); + + // draw inactive tab title bars frist (left-to-right) + + wxNode* pNode = mTabs.First(); + int tabNo = 0; + + /* OLD STUFF:: + curX = mTitleRowStart; + curY = height - mVertGap - BORDER_SZ - mTitleHeight; + */ + + curX = mTabTrianGap; + curY = 0; + + // FOR NOW:: avoid creating bitmap with invalid dimensions + + if ( mTitleRowLen < 1 || mTitleHeight < 1 ) + return; + + wxMemoryDC tmpDc; + wxBitmap tmpBmp( mTitleRowLen, mTitleHeight ); + + tmpDc.SelectObject( tmpBmp ); + tmpDc.SetPen( mGrayPen ); + tmpDc.SetBrush( mGrayBrush ); + tmpDc.DrawRectangle( 0,0, mTitleRowLen, mTitleHeight ); + + tmpDc.SetDeviceOrigin( mCurentRowOfs, 0 ); + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - if ( tabNo != mActiveTab ) - - DrawPaperBar( tab, curX, curY, mGrayBrush, mBlackPen, tmpDc ); - - curX += tab.mDims.x; - - pNode = pNode->Next(); - ++tabNo; + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + if ( tabNo != mActiveTab ) + DrawPaperBar( tab, curX, curY, mGrayBrush, mBlackPen, tmpDc ); + + curX += tab.mDims.x; + + pNode = pNode->Next(); + ++tabNo; } - - // finally, draw the active tab (white-filled) - - pNode = mTabs.First(); - tabNo = 0; - - curX = mTabTrianGap; - - while( pNode ) + + // finally, draw the active tab (white-filled) + + pNode = mTabs.First(); + tabNo = 0; + + curX = mTabTrianGap; + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - if ( tabNo == mActiveTab ) - { - DrawPaperBar( tab, curX, curY, mWhiteBrush, mBlackPen, tmpDc ); - - tmpDc.SetPen( mWhitePen ); - - tmpDc.DrawLine( curX - mTabTrianGap+1, curY, - curX + tab.mDims.x + mTabTrianGap, curY ); - break; - } - curX += tab.mDims.x; - - pNode = pNode->Next(); - ++tabNo; + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + if ( tabNo == mActiveTab ) + { + DrawPaperBar( tab, curX, curY, mWhiteBrush, mBlackPen, tmpDc ); + + tmpDc.SetPen( mWhitePen ); + + tmpDc.DrawLine( curX - mTabTrianGap+1, curY, + curX + tab.mDims.x + mTabTrianGap, curY ); + break; + } + curX += tab.mDims.x; + + pNode = pNode->Next(); + ++tabNo; } - - // back to initial device origin - - tmpDc.SetDeviceOrigin( 0, 0 ); - - // draw resize-hint-stick - - curX = mTitleRowLen - 6; - - DrawShadedRect( curX+0, 0+0, 6, mTitleHeight, mGrayPen, mBlackPen, tmpDc ); - DrawShadedRect( curX+1, 0+1, 6-2, mTitleHeight-2, mWhitePen, mDarkPen, tmpDc ); - DrawShadedRect( curX+2, 0+2, 6-4, mTitleHeight-4, mGrayPen, mGrayPen, tmpDc ); - - - - dc.Blit( mTitleRowStart, - height - mVertGap - BORDER_SZ - mTitleHeight, - mTitleRowLen, mTitleHeight, - &tmpDc, 0,0, wxCOPY ); -} + + // back to initial device origin + + tmpDc.SetDeviceOrigin( 0, 0 ); + + // draw resize-hint-stick + + curX = mTitleRowLen - 6; + + DrawShadedRect( curX+0, 0+0, 6, mTitleHeight, mGrayPen, mBlackPen, tmpDc ); + DrawShadedRect( curX+1, 0+1, 6-2, mTitleHeight-2, mWhitePen, mDarkPen, tmpDc ); + DrawShadedRect( curX+2, 0+2, 6-4, mTitleHeight-4, mGrayPen, mGrayPen, tmpDc ); + + + + dc.Blit( mTitleRowStart, + height - mVertGap - BORDER_SZ - mTitleHeight, + mTitleRowLen, mTitleHeight, + &tmpDc, 0,0, wxCOPY ); +} // wxPagedWindow::DrawDecorations() + //--------------------------------------------------------------------------- -int wxPaggedWindow::HitTest( const wxPoint& pos ) +int wxPagedWindow::HitTest( const wxPoint& pos ) { - return wxTabbedWindow::HitTest( pos ); + return wxTabbedWindow::HitTest( pos ); } + //--------------------------------------------------------------------------- -void wxPaggedWindow::RecalcLayout(bool andRepaint) +void wxPagedWindow::RecalcLayout(bool andRepaint) { - mTitleRowLen = mAdjustableTitleRowLen; - - if ( int(mpTabScroll) == -1 ) return; - - // scroll bars should be created after Create() for this window is called - if ( !mpTabScroll ) + mTitleRowLen = mAdjustableTitleRowLen; + + if ( int(mpTabScroll) == -1 ) return; + + // scroll bars should be created after Create() for this window is called + if ( !mpTabScroll ) { - mpTabScroll = - new wxScrollBar( this, -1, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL ); - - mpHorizScroll = - new wxScrollBar( this, -1, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL ); - if (!mNoVertScroll) // Vertical Scroll (Original) - mpVertScroll = new wxScrollBar( this, -1, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL ); + mpTabScroll = + new wxScrollBar( this, -1, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL ); + + mpHorizScroll = + new wxScrollBar( this, -1, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL ); + if (!mNoVertScroll) // Vertical Scroll (Original) + mpVertScroll = new wxScrollBar( this, -1, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL ); } - - { - int units = GetWholeTabRowLen() / 20; - mpTabScroll->SetScrollbar( 0, 1, units, 1, FALSE ); - } - - // resetup position of the active tab - - int thumbLen = 16; // FOR NOW:: hardcoded - - int width, height; - GetClientSize( &width, &height ); - - mTitleHeight = thumbLen; - - int curX = mHorizGap + BORDER_SZ; - int curY = mVertGap + BORDER_SZ; - - int xSize; - if (!mNoVertScroll) // Vertical Scroll (Original) - xSize = width - mHorizGap*2 - BORDER_SZ*2 - thumbLen; - else - xSize = width - mHorizGap*2 - BORDER_SZ*2; - - int ySize = height - mVertGap*2 - BORDER_SZ*2 - mTitleHeight; - - SizeTabs( curX, curY, xSize, ySize, andRepaint ); - - // setup title bar LINES's horizontal scroll bar - - curY = height - mVertGap - BORDER_SZ - thumbLen; - - mpTabScroll->SetSize( curX, curY, thumbLen*2, thumbLen ); - - // setup view's HORIZONTAL scroll bar - curX += thumbLen*2; - - mTitleRowStart = curX; - mFirstTitleGap = curX + mCurentRowOfs + mTabTrianGap; - - mTitleRowLen = wxMin( mAdjustableTitleRowLen, - width - mHorizGap - BORDER_SZ - thumbLen*4 - curX ); - - curX += mTitleRowLen; - - if (!mNoVertScroll) // Vertical Scroll (Original) - mpHorizScroll->SetSize( curX, curY,width - curX - mHorizGap - BORDER_SZ - thumbLen, thumbLen ); - else - mpHorizScroll->SetSize( curX, curY,width - curX - mHorizGap - BORDER_SZ-4, thumbLen ); - - // setup view's VERTICAL scroll bar - if (!mNoVertScroll) // Vertical Scroll (Original) { - curX = width - mHorizGap - BORDER_SZ - thumbLen; - curY = mVertGap + BORDER_SZ; - mpVertScroll->SetSize( curX, curY, thumbLen,height - curY - mVertGap - BORDER_SZ - thumbLen); + int units = GetWholeTabRowLen() / 20; + + mpTabScroll->SetScrollbar( 0, 1, units, 1, FALSE ); + } + + // resetup position of the active tab + + int thumbLen = 16; // FOR NOW:: hardcoded + + int width, height; + GetClientSize( &width, &height ); + + mTitleHeight = thumbLen; + + int curX = mHorizGap + BORDER_SZ; + int curY = mVertGap + BORDER_SZ; + + int xSize; + if (!mNoVertScroll) // Vertical Scroll (Original) + xSize = width - mHorizGap*2 - BORDER_SZ*2 - thumbLen; + else + xSize = width - mHorizGap*2 - BORDER_SZ*2; + + int ySize = height - mVertGap*2 - BORDER_SZ*2 - mTitleHeight; + + SizeTabs( curX, curY, xSize, ySize, andRepaint ); + + // setup title bar LINES's horizontal scroll bar + + curY = height - mVertGap - BORDER_SZ - thumbLen; + + mpTabScroll->SetSize( curX, curY, thumbLen*2, thumbLen ); + + // setup view's HORIZONTAL scroll bar + curX += thumbLen*2; + + mTitleRowStart = curX; + mFirstTitleGap = curX + mCurentRowOfs + mTabTrianGap; + + mTitleRowLen = wxMin( mAdjustableTitleRowLen, + width - mHorizGap - BORDER_SZ - thumbLen*4 - curX ); + + curX += mTitleRowLen; + + if (!mNoVertScroll) // Vertical Scroll (Original) + mpHorizScroll->SetSize( curX, curY,width - curX - mHorizGap - BORDER_SZ - thumbLen, thumbLen ); + else + mpHorizScroll->SetSize( curX, curY,width - curX - mHorizGap - BORDER_SZ-4, thumbLen ); + + // setup view's VERTICAL scroll bar + if (!mNoVertScroll) // Vertical Scroll (Original) + { + curX = width - mHorizGap - BORDER_SZ - thumbLen; + curY = mVertGap + BORDER_SZ; + mpVertScroll->SetSize( curX, curY, thumbLen,height - curY - mVertGap - BORDER_SZ - thumbLen); } - // layout tab title bars - - mLayoutType = wxTITLE_IMG_AND_TEXT; - - wxNode* pNode = mTabs.First(); - - while( pNode ) + // layout tab title bars + + mLayoutType = wxTITLE_IMG_AND_TEXT; + + wxNode* pNode = mTabs.First(); + + while( pNode ) { - twTabInfo& tab = *((twTabInfo*)(pNode->Data())); - - wxWindowDC dc(this); - - long w,h; - - // set select default font of the window into it's device context - //dc.SetFont( GetLabelingFont() ); - dc.GetTextExtent(tab.mText, &w, &h ); - - tab.mDims.x = w + tab.ImageToTxtGap(mImageTextGap) + - tab.ImgWidth() + mTitleHorizGap*2; - - tab.mDims.y = mTitleHeight; - - pNode = pNode->Next(); + twTabInfo& tab = *((twTabInfo*)(pNode->Data())); + + wxWindowDC dc(this); + + long w,h; + + // set select default font of the window into it's device context + //dc.SetFont( GetLabelingFont() ); + dc.GetTextExtent(tab.mText, &w, &h ); + + tab.mDims.x = w + tab.ImageToTxtGap(mImageTextGap) + + tab.ImgWidth() + mTitleHorizGap*2; + + tab.mDims.y = mTitleHeight; + + pNode = pNode->Next(); } - - // disable title-bar scroller if there's nowhere to scroll to - - mpTabScroll->Enable( mTitleRowLen < GetWholeTabRowLen() || mCurentRowOfs < 0 ); + + // disable title-bar scroller if there's nowhere to scroll to + + mpTabScroll->Enable( mTitleRowLen < GetWholeTabRowLen() || mCurentRowOfs < 0 ); } + //--------------------------------------------------------------------------- // event handlers //--------------------------------------------------------------------------- -void wxPaggedWindow::OnPaint( wxPaintEvent& event ) +void wxPagedWindow::OnPaint( wxPaintEvent& event ) { - wxPaintDC dc(this); - DrawDecorations( dc ); + wxPaintDC dc(this); + DrawDecorations( dc ); } + //--------------------------------------------------------------------------- -void wxPaggedWindow::OnSize ( wxSizeEvent& event ) +void wxPagedWindow::OnSize ( wxSizeEvent& event ) { - wxTabbedWindow::OnSize(event); + wxTabbedWindow::OnSize(event); } + //--------------------------------------------------------------------------- -void wxPaggedWindow::OnLButtonDown( wxMouseEvent& event ) +void wxPagedWindow::OnLButtonDown( wxMouseEvent& event ) { - if ( mCursorChanged ) + if ( mCursorChanged ) { - mIsDragged = TRUE; - mDagOrigin = event.m_x; - - mOriginalTitleRowLen = mAdjustableTitleRowLen; - - CaptureMouse(); + mIsDragged = TRUE; + mDagOrigin = event.m_x; + + mOriginalTitleRowLen = mAdjustableTitleRowLen; + + CaptureMouse(); } - else + else { - wxTabbedWindow::OnLButtonDown( event ); + wxTabbedWindow::OnLButtonDown( event ); } -} +} // wxPagedWindow::OnLButtonDown() + //--------------------------------------------------------------------------- -void wxPaggedWindow::OnLButtonUp( wxMouseEvent& event ) +void wxPagedWindow::OnLButtonUp( wxMouseEvent& event ) { - if ( mIsDragged ) + if ( mIsDragged ) { - mIsDragged = FALSE; - mCursorChanged = FALSE; - SetCursor( mNormalCursor ); - - ReleaseMouse(); + mIsDragged = FALSE; + mCursorChanged = FALSE; + SetCursor( mNormalCursor ); + + ReleaseMouse(); } -} +} // wxPagedWindow::OnLButtonUp() + //--------------------------------------------------------------------------- -void wxPaggedWindow::OnMouseMove( wxMouseEvent& event ) +void wxPagedWindow::OnMouseMove( wxMouseEvent& event ) { - int width, height; - GetClientSize( &width, &height ); - - if ( !mIsDragged ) + int width, height; + GetClientSize( &width, &height ); + + if ( !mIsDragged ) { - int y = height - mVertGap - BORDER_SZ - mTitleHeight; - int x = mTitleRowStart + mTitleRowLen - 6; - - if ( event.m_x >= x && event.m_y >= y && - event.m_x < x + 6 && - event.m_y < y + mTitleHeight - ) - { - if ( !mCursorChanged ) - { - SetCursor( mResizeCursor ); - - mCursorChanged = TRUE; - } - } - else - if ( mCursorChanged ) - { - SetCursor( mNormalCursor ); - - mCursorChanged = FALSE; - } + int y = height - mVertGap - BORDER_SZ - mTitleHeight; + int x = mTitleRowStart + mTitleRowLen - 6; + + if ( event.m_x >= x && event.m_y >= y && + event.m_x < x + 6 && + event.m_y < y + mTitleHeight + ) + { + if ( !mCursorChanged ) + { + SetCursor( mResizeCursor ); + + mCursorChanged = TRUE; + } + } + else + if ( mCursorChanged ) + { + SetCursor( mNormalCursor ); + + mCursorChanged = FALSE; + } } - else - if ( mIsDragged ) - { - mAdjustableTitleRowLen = mOriginalTitleRowLen + ( event.m_x - mDagOrigin ); - - // FOR NOW:: fixed - if ( mAdjustableTitleRowLen < 6 ) mAdjustableTitleRowLen = 6; - - wxWindowDC dc(this); - DrawDecorations( dc ); - - RecalcLayout(FALSE); - - //Refresh(); - } -} + else + { + if ( mIsDragged ) + { + mAdjustableTitleRowLen = mOriginalTitleRowLen + ( event.m_x - mDagOrigin ); + + // FOR NOW:: fixed + if ( mAdjustableTitleRowLen < 6 ) mAdjustableTitleRowLen = 6; + + wxWindowDC dc(this); + DrawDecorations( dc ); + + RecalcLayout(FALSE); + + //Refresh(); + } + } +} // wxPagedWindow::OnMouseMove() + //--------------------------------------------------------------------------- -void wxPaggedWindow::OnScroll( wxScrollEvent& event ) +void wxPagedWindow::OnScroll( wxScrollEvent& event ) { - - wxScrollBar* pSender = (wxScrollBar*)event.GetEventObject(); - // wxMessageBox("wxPaggedWindow::OnScroll","-I->"); - if ( pSender == mpTabScroll ) + wxScrollBar* pSender = (wxScrollBar*)event.GetEventObject(); + // wxMessageBox("wxPagedWindow::OnScroll","-I->"); + if ( pSender == mpTabScroll ) { - - int maxUnits = GetWholeTabRowLen() / 20; - - mCurentRowOfs = -event.GetPosition()*maxUnits; - - mFirstTitleGap = mTitleRowStart + mCurentRowOfs + mTabTrianGap; - - // let' it automatically disable itself if it's time - mpTabScroll->Enable( mTitleRowLen < GetWholeTabRowLen() || mCurentRowOfs < 0 ); - - // repaint title bars - wxWindowDC dc(this); - DrawDecorations( dc ); + + int maxUnits = GetWholeTabRowLen() / 20; + + mCurentRowOfs = -event.GetPosition()*maxUnits; + + mFirstTitleGap = mTitleRowStart + mCurentRowOfs + mTabTrianGap; + + // let' it automatically disable itself if it's time + mpTabScroll->Enable( mTitleRowLen < GetWholeTabRowLen() || mCurentRowOfs < 0 ); + + // repaint title bars + wxWindowDC dc(this); + DrawDecorations( dc ); } - else - if ( !mScrollEventInProgress ) - { - mScrollEventInProgress = TRUE; - - GetActiveTab()->GetEventHandler()->ProcessEvent( event ); - } else - { - // event bounced back to us, from here we - // know that it has traveled the loop - thus it's processed! - - mScrollEventInProgress = FALSE; - } -} + { + if ( !mScrollEventInProgress ) + { + mScrollEventInProgress = TRUE; + + GetActiveTab()->GetEventHandler()->ProcessEvent( event ); + } + else + { + // event bounced back to us, from here we + // know that it has traveled the loop - thus it's processed! + + mScrollEventInProgress = FALSE; + } + } +} // wxPagedWindow::OnScroll() //--------------------------------------------------------------------------- diff --git a/demos/dbbrowse/tabpgwin.h b/demos/dbbrowse/tabpgwin.h index e3f2ea61af..4c0724cfc4 100644 --- a/demos/dbbrowse/tabpgwin.h +++ b/demos/dbbrowse/tabpgwin.h @@ -9,7 +9,7 @@ // - to prevent Warnings under MingGW32 // Modified by: 19990909 : mj10777@gmx.net // - mNoVertScroll TRUE = no / FALSE = Original Code -// the Original Code Paints a Vertical Scroll in wxPaggedWindow +// the Original Code Paints a Vertical Scroll in wxPagedWindow // which is not needed in this Version. Use TRUE for this. // Created: 07/09/98 // RCS-ID: $Id$ @@ -60,7 +60,7 @@ public: virtual wxFont GetLabelingFont(); - // FOR NOW:: scrollbars are actually related to wxPaggedWindow + // FOR NOW:: scrollbars are actually related to wxPagedWindow wxScrollBar* mpTabScroll; wxScrollBar* mpHorizScroll; @@ -154,9 +154,9 @@ public: * of Microsoft Developer Studio 4.xx */ -class wxPaggedWindow : public wxTabbedWindow +class wxPagedWindow : public wxTabbedWindow { - DECLARE_DYNAMIC_CLASS( wxPaggedWindow ) + DECLARE_DYNAMIC_CLASS( wxPagedWindow ) // the protected: public: changes prevents Warnings in gcc protected: bool mScrollEventInProgress; @@ -199,8 +199,8 @@ public: public: - wxPaggedWindow(); - ~wxPaggedWindow(); + wxPagedWindow(); + ~wxPagedWindow(); // NOTE:: use public methods of the base class // to add "pages" to this window -- 2.45.2