Exemplo n.º 1
0
void rc2wxr::ParseMenu(wxString name)
{
    wxString tok;
    static int menuid=0;
    menuid++;
    wxFprintf(m_wxr,_T("static char *MenuBar%i = \"menu(name = '%s',\\\n"),menuid,name.c_str());
    wxFprintf(m_wxr,_T("menu = \\\n"));
    wxFprintf(m_wxr,_T("[\\\n"));

    while ((tok!=_T("BEGIN"))&(tok!=_T("{")))
        tok=GetToken();

    while ((tok!=_T("END"))&(tok!=_T("}")))
    {
        tok=GetToken();

        if (tok==_T("POPUP"))
        {
            ParsePopupMenu();
            wxFprintf(m_wxr,_T("  ],\\\n"));
        }
    }

    wxFprintf(m_wxr,_T("]).\";\n\n"));
}
Exemplo n.º 2
0
void rc2wxr::ParseStaticText()

{

wxString tok;

wxString phrase,varname;

phrase=GetQuoteField();

varname=GetToken();

m_controlid++;

int x,y,width,height;

ReadRect(x,y,width,height);

wxFprintf(m_wxr,_T("  control = [%i,wxStaticText,'%s','0','%s',"),m_controlid,phrase.c_str(),varname.c_str());

wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height);

wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));

}
Exemplo n.º 3
0
void rc2wxr::ParseTextCtrl()

{

wxString tok;

wxString varname;

varname=GetToken();

m_controlid++;

int x,y,width,height;

ReadRect(x,y,width,height);

wxFprintf(m_wxr,_T("  control = [%i,wxTextCtrl,'','0','%s',"),m_controlid,varname.c_str());

wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height);

wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));



}
Exemplo n.º 4
0
bool wxGISNTService::Install()
{
	if (IsInstalled()) 
	{
		wxFprintf(stderr, wxString::Format(_("%s is already installed\n"), m_sServiceName.c_str()));
		return false;
	}
	else
	{
		// Open the Service Control Manager
		SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (!hSCM) 
		{
			wxFprintf(stderr, wxString::Format(_("%s is not installed\n"), m_sServiceName.c_str()));
			return false;
		}
		// Get the executable file path
		wxStandardPaths stp;
		wxString sFilePath = stp.GetExecutablePath();

		// Create the service
		SC_HANDLE hService = ::CreateService(hSCM, m_sServiceName, wxT("wxGIS Server"), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START/*SERVICE_DEMAND_START*/, SERVICE_ERROR_NORMAL, sFilePath + wxT(" -s"), NULL, NULL, NULL, NULL, NULL);

		if (!hService)
		{
			::CloseServiceHandle(hSCM);
			wxFprintf(stderr, wxString::Format(_("%s is not installed\n"), m_sServiceName.c_str()));
			return false;
		}

		// make registry entries to support logging messages
		// Add the source name as a subkey under the Application
		// key in the EventLog service portion of the registry.
		wxString szKey = wxString::Format(wxT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s"), m_sServiceName.c_str());
		HKEY hKey = NULL;
		if (::RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) != ERROR_SUCCESS)
		{
			::CloseServiceHandle(hService);
			::CloseServiceHandle(hSCM);
			wxFprintf(stderr, wxString::Format(_("%s is not installed\n"), m_sServiceName.c_str()));
			return false;
		}

		// Add the Event ID message-file name to the 'EventMessageFile' subkey.
		::RegSetValueEx(hKey, wxT("EventMessageFile"), 0, REG_EXPAND_SZ, (CONST BYTE*)sFilePath.c_str(), sFilePath.Len() + 1);     

		// Set the supported types flags.
		DWORD dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
		::RegSetValueEx(hKey, wxT("TypesSupported"), 0, REG_DWORD, (CONST BYTE*)&dwData, sizeof(DWORD));
		::RegCloseKey(hKey);

		LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_INSTALLED, m_sServiceName);

		// tidy up
		::CloseServiceHandle(hService);
		::CloseServiceHandle(hSCM);
		wxFprintf(stdout, wxString::Format(_("%s installed\n"), m_sServiceName.c_str()));
		return true;
	}
}
Exemplo n.º 5
0
void wxError( const wxString &msg, const wxString &title )
{
  wxFprintf( stderr, _("Error ") );
  if (!title.IsNull()) wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title) );
  if (!msg.IsNull()) wxFprintf( stderr, wxT(": %s"), WXSTRINGCAST(msg) );
  wxFprintf( stderr, wxT(".\n") );
}
Exemplo n.º 6
0
void rc2wxr::ParseGroupBox()

{

//    GROUPBOX        "Rotate",IDC_STATIC,1,1,71,79

wxString tok;

wxString phrase,varname;

phrase=GetQuoteField();

varname=GetToken();

m_controlid++;

int x,y,width,height;

ReadRect(x,y,width,height);

wxFprintf(m_wxr,_T("  control = [%i,wxStaticBox,'%s','0','%s',"),m_controlid,phrase.c_str(),varname.c_str());

wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height);

wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));





}
Exemplo n.º 7
0
void wxFatalError( const wxString &msg, const wxString &title )
{
  wxFprintf( stderr, _("Error ") );
  if (!title.IsNull()) wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title) );
  if (!msg.IsNull()) wxFprintf( stderr, wxT(": %s"), WXSTRINGCAST(msg) );
  wxFprintf( stderr, wxT(".\n") );
  exit(3); // the same exit code as for abort()
}
Exemplo n.º 8
0
// Build up and save an index into the poetry data file, for
// rapid random access
bool Compile(void)
{
    FILE *file;
    int j;
    int ch;
    wxChar buf[100];

    if (data_filename)
        wxSprintf(buf, wxT("%s.dat"), data_filename);

    file = wxFopen(buf, wxT("rb"));
    if (! (data_filename && file))
    {
        wxSprintf(error_buf, wxT("Poetry data file %s not found\n"), buf);
        PoetryError(error_buf);
        return false;
    }

    nitems = 0;

    // Do first one (?)
    poem_index[nitems] = 0;
    nitems ++;

    // Do rest

    do {
        ch = getc(file);
        if (ch == '#')
        {
            ch = getc(file);
            long data;
            data = ftell(file);
            poem_index[nitems] = data;
            nitems ++;
        }
    } while (ch != EOF);
    fclose(file);

    if (index_filename)
      wxSprintf(buf, wxT("%s.idx"), index_filename);

    file = wxFopen(buf, wxT("w"));
    if (! (data_filename && file))
    {
        wxSprintf(error_buf, wxT("Poetry index file %s cannot be created\n"), buf);
        PoetryError(error_buf);
        return false;
    }

    wxFprintf(file, wxT("%ld\n\n"), nitems);
    for (j = 0; j < nitems; j++)
        wxFprintf(file, wxT("%ld\n"), poem_index[j]);

    fclose(file);
    PoetryNotify(wxT("Poetry index compiled."));
    return true;
}
Exemplo n.º 9
0
/*    CONTROL         "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
                    TBS_NOTICKS | WS_TABSTOP,52,73,100,15
*/
void rc2wxr::ParseSlider(wxString WXUNUSED(label), wxString varname)
{
    int x,y,width,height;
    wxString tok;

    while (ReadOrs(tok))
        ;
    wxFprintf(m_wxr,_T("  control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',"),m_controlid,varname.c_str());
    ReadRect(x,y,width,height);
    wxFprintf(m_wxr,_T("%i,%i,%i,%i,"),x,y,width,height);
    wxFprintf(m_wxr,_T(" 1, 1, 10,\\\n"));
    wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
}
Exemplo n.º 10
0
void rc2wxr::ParsePushButton()

{

wxString tok;

wxString phrase,varname;

phrase=GetQuoteField();

varname=GetToken();

int c;

m_controlid++;

c=m_controlid;

if (varname==_T("IDOK"))

c=wxID_OK;



if (varname==_T("IDCANCEL"))

c=wxID_CANCEL;



if (varname==_T("IDAPPLY"))

c=wxID_APPLY;



int x,y,width,height;

ReadRect(x,y,width,height);

wxFprintf(m_wxr,_T("  control = [%i,wxButton,'%s','0','%s',"),c,phrase.c_str(),varname.c_str());

wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height);

wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));



}
Exemplo n.º 11
0
bool SHGToMap(wxChar *filename, wxChar *defaultFile)
{
  // Test the SHG parser
  HotSpot *hotspots = NULL;
  int n = ParseSHG(filename, &hotspots);
  if (n == 0)
    return false;

  wxChar buf[100];
  wxSnprintf(buf, sizeof(buf), _T("Converting .SHG file to HTML map file: there are %d hotspots in %s."), n, filename);
  OnInform(buf);

  wxChar outBuf[256];
  wxStrcpy(outBuf, filename);
  StripExtension(outBuf);
  wxStrcat(outBuf, _T(".map"));

  FILE *fd = wxFopen(outBuf, _T("w"));
  if (!fd)
  {
    OnError(_T("Could not open .map file for writing."));
    delete[] hotspots;
    return false;
  }

  wxFprintf(fd, _T("default %s\n"), defaultFile);
  for (int i = 0; i < n; i++)
  {
    wxChar *refFilename = _T("??");
    
    TexRef *texRef = FindReference(hotspots[i].szHlpTopic_Macro);
    if (texRef)
      refFilename = texRef->refFile;
    else
    {
      wxChar buf[300];
      wxSnprintf(buf, sizeof(buf), _T("Warning: could not find hotspot reference %s"), hotspots[i].szHlpTopic_Macro);
      OnInform(buf);
    }
    wxFprintf(fd, _T("rect %s %d %d %d %d\n"), refFilename, (int)hotspots[i].left, (int)hotspots[i].top,
      (int)hotspots[i].right, (int)hotspots[i].bottom);
  }
  wxFprintf(fd, _T("\n"));

  fclose(fd);

  delete[] hotspots;
  return true;
}
Exemplo n.º 12
0
int Resample::Process(double  factor,
                      float  *inBuffer,
                      int     inBufferLen,
                      bool    lastFlag,
                      int    *inBufferUsed,
                      float  *outBuffer,
                      int     outBufferLen)
{
   if (mInitial) {
      src_set_ratio((SRC_STATE *)mHandle, factor);
      mInitial = false;
   }

   SRC_DATA data;

   data.data_in = inBuffer;
   data.data_out = outBuffer;
   data.input_frames = inBufferLen;
   data.output_frames = outBufferLen;
   data.input_frames_used = 0;
   data.output_frames_gen = 0;
   data.end_of_input = (int)lastFlag;
   data.src_ratio = factor;

   int err = src_process((SRC_STATE *)mHandle, &data);
   if (err) {
      wxFprintf(stderr, _("Libsamplerate error: %d\n"), err);
      return 0;
   }

   *inBufferUsed = (int)data.input_frames_used;
   return (int)data.output_frames_gen;
}
Exemplo n.º 13
0
bool wxAppTraitsBase::ShowAssertDialog(const wxString& msgOriginal)
{
#if wxDEBUG_LEVEL
    wxString msg = msgOriginal;

#if wxUSE_STACKWALKER
#if !defined(__WXMSW__)
    // on Unix stack frame generation may take some time, depending on the
    // size of the executable mainly... warn the user that we are working
    wxFprintf(stderr, wxT("[Debug] Generating a stack trace... please wait"));
    fflush(stderr);
#endif

    const wxString stackTrace = GetAssertStackTrace();
    if ( !stackTrace.empty() )
        msg << _T("\n\nCall stack:\n") << stackTrace;
#endif // wxUSE_STACKWALKER

    return DoShowAssertDialog(msg);
#else // !wxDEBUG_LEVEL
    wxUnusedVar(msgOriginal);

    return false;
#endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
}
Exemplo n.º 14
0
void wxSafeShowMessage(const wxString& title, const wxString& text)
{
#ifdef __WINDOWS__
    ::MessageBox(NULL, text, title, MB_OK | MB_ICONSTOP);
#else
    wxFprintf(stderr, _T("%s: %s\n"), title.c_str(), text.c_str());
    fflush(stderr);
#endif
}
Exemplo n.º 15
0
bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString& msg)
{
    // under MSW we prefer to use the base class version using ::MessageBox()
    // even if wxMessageBox() is available because it has less chances to
    // double fault our app than our wxMessageBox()
    //
    // under DFB the message dialog is not always functional right now
    //
    // and finally we can't use wxMessageBox() if it wasn't compiled in, of
    // course
#if defined(__WXMSW__) || defined(__WXDFB__) || !wxUSE_MSGDLG
    return wxAppTraitsBase::ShowAssertDialog(msg);
#else // wxUSE_MSGDLG
#if wxDEBUG_LEVEL
    wxString msgDlg = msg;

#if wxUSE_STACKWALKER
    // on Unix stack frame generation may take some time, depending on the
    // size of the executable mainly... warn the user that we are working
    wxFprintf(stderr, wxT("[Debug] Generating a stack trace... please wait"));
    fflush(stderr);

    const wxString stackTrace = GetAssertStackTrace();
    if ( !stackTrace.empty() )
        msgDlg << _T("\n\nCall stack:\n") << stackTrace;
#endif // wxUSE_STACKWALKER

    // this message is intentionally not translated -- it is for
    // developpers only
    msgDlg += wxT("\nDo you want to stop the program?\n")
              wxT("You can also choose [Cancel] to suppress ")
              wxT("further warnings.");

    switch ( wxMessageBox(msgDlg, wxT("wxWidgets Debug Alert"),
                          wxYES_NO | wxCANCEL | wxICON_STOP ) )
    {
        case wxYES:
            wxTrap();
            break;

        case wxCANCEL:
            // no more asserts
            return true;

        //case wxNO: nothing to do
    }
#else // !wxDEBUG_LEVEL
    // this function always exists (for ABI compatibility) but is never called
    // if debug level is 0 and so can simply do nothing then
    wxUnusedVar(msg);
#endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL

    return false;
#endif // !wxUSE_MSGDLG/wxUSE_MSGDLG
}
Exemplo n.º 16
0
//Is it a check button or a radio button
void rc2wxr::ParseCtrlButton(wxString label, wxString varname)
{
    int x,y,width,height;
    wxString tok = GetToken();

    m_controlid++;

    if (tok==_T("BS_AUTOCHECKBOX"))
    {
        wxFprintf(m_wxr,_T("  control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid,label.c_str(),varname.c_str());
        while (ReadOrs(tok))
            ;

        ReadRect(x,y,width,height);
        wxFprintf(m_wxr,_T("%i,%i,%i,%i,0,\\\n"),x,y,width,height);
        wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
    }

    if (tok==_T("BS_AUTORADIOBUTTON"))
    {
        wxFprintf(m_wxr,_T("  control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid,label.c_str(),varname.c_str());
        while(ReadOrs(tok))
            ;

        ReadRect(x,y,width,height);
        wxFprintf(m_wxr,_T("%i,%i,%i,%i,0,\\\n"),x,y,width,height);
        wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
    }
}
Exemplo n.º 17
0
void rc2wxr::ParsePopupMenu()
{
    static int menuitem=99;

    menuitem++;

    wxString tok = GetQuoteField();
    int spot;

    //Remove /t because it causes problems
    spot=tok.First(_T("\\t"));
    tok=tok.Left(spot);

    wxFprintf(m_wxr,_T("  ['%s',%i,'',\\\n"),tok.c_str(),menuitem);

    while ((tok!=_T("BEGIN"))&(tok!=_T("{")))
        tok=GetToken();

    while ((tok!=_T("END"))&(tok!=_T("}")))
    {
        tok=GetToken();

        if (tok==_T("MENUITEM"))
        {
            if (PeekToken()==_T("SEPARATOR"))
            {
                wxFprintf(m_wxr,_T("      [],\\\n"));
            }
            else
            {
                tok=GetQuoteField();
                //Remove /t because it causes problems
                spot=tok.First(_T("\\t"));
                tok=tok.Left(spot);
                menuitem++;
                wxFprintf(m_wxr,_T("      ['%s',%i,''],\\\n"),tok.c_str(),menuitem);
            }
        }
    }
}
Exemplo n.º 18
0
static size_t NumberOfBitsNeeded(size_t PowerOfTwo)
{
   if (PowerOfTwo < 2) {
      wxFprintf(stderr, "Error: FFT called with size %ld\n", PowerOfTwo);
      exit(1);
   }

   size_t i = 0;
   while (PowerOfTwo > 1)
      PowerOfTwo >>= 1, ++i;

   return i;
}
Exemplo n.º 19
0
void ReportProgress(int Progress)
{
	if (s_bDoProgress)
	{
		if (Progress > 100)
			Progress = 100;

		if (Progress > s_LastProgress)
		{
			wxFprintf(stderr, _T("PROGRESS:%d%%\n"), Progress);
			s_LastProgress = Progress;
		}
	}
}
Exemplo n.º 20
0
bool wxGISNTService::Uninstall()
{
	// Open the Service Control Manager
    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (!hSCM) 
	{
		wxFprintf(stderr, wxString::Format(_("Could not remove %s. Error %d\n"), m_sServiceName.c_str(), GetLastError()));
		return false;
	}

    bool bResult(false);
    SC_HANDLE hService = ::OpenService(hSCM, m_sServiceName, DELETE);
    if (hService)
	{
		if (::DeleteService(hService))
		{
            LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_REMOVED, m_sServiceName);
            bResult = true;
        }
		else
		{
            LogEvent(EVENTLOG_ERROR_TYPE, EVMSG_NOTREMOVED, m_sServiceName);
        }
        ::CloseServiceHandle(hService);
    }
    
    ::CloseServiceHandle(hSCM);
 
	if(bResult)
	{
		// Get the executable file path
		wxStandardPaths stp;
		wxString sFilePath = stp.GetExecutablePath();
		wxFprintf(stdout, wxString::Format(_("%s removed. (You must delete the file (%s) yourself.)\n"), m_sServiceName.c_str(), sFilePath.c_str()));	
	}
	return bResult;
}
Exemplo n.º 21
0
void LogMessage(wxString msg, int level)
{
	wxFFile file;
	if (logFile.IsEmpty())
	{
		file.Attach(stdout);
	}
	else
	{
		file.Open(logFile.c_str(), wxT("a"));
	}

	if (!file.IsOpened())
	{
		wxFprintf(stderr, _("Can not open the logfile!"));
		return;
	}

	wxDateTime logTime = wxDateTime::Now();
	wxString logTimeString = logTime.Format() + wxT(" : ");

	switch (level)
	{
		case LOG_DEBUG:
			if (minLogLevel >= LOG_DEBUG)
				file.Write(logTimeString + _("DEBUG: ") + msg + wxT("\n"));
			break;
		case LOG_WARNING:
			if (minLogLevel >= LOG_WARNING)
				file.Write(logTimeString + _("WARNING: ") + msg + wxT("\n"));
			break;
		case LOG_ERROR:
			file.Write(logTimeString + _("ERROR: ") + msg + wxT("\n"));
			exit(1);
			break;
		case LOG_STARTUP:
			file.Write(logTimeString + _("WARNING: ") + msg + wxT("\n"));
			break;
	}

	if (logFile.IsEmpty())
	{
		file.Detach();
	}
	else
	{
		file.Close();
	}
}
Exemplo n.º 22
0
int main(int argc, char* argv[])
{
	if (argc < 2)
	{
		wxFprintf(stderr, _T("Usage : ExpandXar <input file> <output file>\n"));
		return 1;
	}

#if wxUSE_UNICODE
	wxChar **wxArgv = new wxChar *[argc + 1];
	
	{
		int n;

		for (n = 0; n < argc; n++ )
		{
			wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
			wxArgv[n] = wxStrdup(warg);
		}

		wxArgv[n] = NULL;
	}
#else // !wxUSE_UNICODE
	#define wxArgv argv
#endif // wxUSE_UNICODE/!wxUSE_UNICODE

	int RetVal = 0;

	if (!ProcessFile(wxArgv[1], wxArgv[2]))
	{
		RetVal = 1;
	}

#if wxUSE_UNICODE
	{
		for ( int n = 0; n < argc; n++ )
			free(wxArgv[n]);

		delete [] wxArgv;
	}
#endif // wxUSE_UNICODE

	wxUnusedVar(argc);
	wxUnusedVar(argv);
	
	return RetVal;
}
Exemplo n.º 23
0
void writePid(pid_t pid)
{
	wxFFile file;
	wxString s;

	if (!pidFile.IsEmpty())
	{
		file.Open(pidFile.c_str(), wxT("w"));
		if (!file.IsOpened())
		{
			wxFprintf(stderr, _("Can not open the pidfile!"));
			return;
		}
		s.Printf(wxT("%d"), (int) pid);
		file.Write(s);
		file.Close();
	}
}
Exemplo n.º 24
0
   int VarRateResample::Process(double  factor,
                                  float  *inBuffer,
                                  int     inBufferLen,
                                  bool    lastFlag,
                                  int    *inBufferUsed,
                                  float  *outBuffer,
                                  int     outBufferLen)
   {
      src_set_ratio((SRC_STATE *)mHandle, factor);

      SRC_DATA data;
      
      if(mShouldReset) {
         if(inBufferLen > mSamplesLeft) {
            mShouldReset = false;
            src_reset((SRC_STATE *)mHandle);
         } else {
            mSamplesLeft -= inBufferLen;
         }
      }

      data.data_in = inBuffer;
      data.data_out = outBuffer;
      data.input_frames = inBufferLen;
      data.output_frames = outBufferLen;
      data.input_frames_used = 0;
      data.output_frames_gen = 0;
      data.end_of_input = (int)lastFlag;
      data.src_ratio = factor;

      int err = src_process((SRC_STATE *)mHandle, &data);
      if (err) {
         wxFprintf(stderr, _("Libsamplerate error: %d\n"), err);
         return 0;
      }
      
      if(lastFlag) {
         mShouldReset = true;
         mSamplesLeft = inBufferLen - (int)data.input_frames_used;
      }

      *inBufferUsed = (int)data.input_frames_used;
      return (int)data.output_frames_gen;
   }
Exemplo n.º 25
0
wxString wxAppTraitsBase::GetAssertStackTrace()
{
#if wxDEBUG_LEVEL

#if !defined(__WINDOWS__)
    // on Unix stack frame generation may take some time, depending on the
    // size of the executable mainly... warn the user that we are working
    wxFprintf(stderr, "Collecting stack trace information, please wait...");
    fflush(stderr);
#endif // !__WINDOWS__


    class StackDump : public wxStackWalker
    {
    public:
        StackDump() { m_numFrames = 0; }

        const wxString& GetStackTrace() const { return m_stackTrace; }

    protected:
Exemplo n.º 26
0
wxThread::ExitCode wxGISServerApp::Entry()
{
    // IMPORTANT:
    // this function gets executed in the secondary thread context!

    // here we do our long task, periodically calling TestDestroy():
    while (!GetThread()->TestDestroy())
    {
        wxFprintf(stdout, wxString(_("Press 'q' to quit.\n")));
        int nChar = getchar();
        if(nChar == 'q' || nChar == 'Q')
        {
            Exit(); //wxTheApp->
        //ProcessNetMessage();
            break;
        }
        wxThread::Sleep(QUIT_CHAR_DELAY);
    }

    // TestDestroy() returned true (which means the main thread asked us
    // to terminate as soon as possible) or we ended the long task...
    return (wxThread::ExitCode)0;
}
Exemplo n.º 27
0
bool DoShowAssertDialog(const wxString& msg)
{
    // under MSW we can show the dialog even in the console mode
#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
    wxString msgDlg(msg);

    // this message is intentionally not translated -- it is for
    // developpers only
    msgDlg += wxT("\nDo you want to stop the program?\n")
              wxT("You can also choose [Cancel] to suppress ")
              wxT("further warnings.");

    switch ( ::MessageBox(NULL, msgDlg, _T("wxWidgets Debug Alert"),
                          MB_YESNOCANCEL | MB_ICONSTOP ) )
    {
        case IDYES:
            wxTrap();
            break;

        case IDCANCEL:
            // stop the asserts
            return true;

        //case IDNO: nothing to do
    }
#else // !__WXMSW__
    wxFprintf(stderr, wxT("%s\n"), msg.c_str());
    fflush(stderr);

    // TODO: ask the user to enter "Y" or "N" on the console?
    wxTrap();
#endif // __WXMSW__/!__WXMSW__

    // continue with the asserts
    return false;
}
Exemplo n.º 28
0
BOOL ProcessFile(TCHAR* pInputFile, TCHAR* pOutputFile)
{
	// First we ask the library to create a Xar importer
	CXarImport* pImporter = XarLibrary::CreateImporter();
	if (!pImporter)
	{
		wxFprintf(stderr, _T("CreateImporter failed\n"));
		return(FALSE);
	}

	// Call PrepareImport passing the name of the output file
	BOOL ok = pImporter->PrepareImport(pInputFile);
	if (!ok)
	{
		wxFprintf(stderr, _T("PrepareImport failed\n"));
		return(FALSE);
	}

	MyData Data;
	Data.pExporter = NULL;
	Data.NextRecord = 2;
	Data.Depth = 0;

	// Ask the library to create a Xar Exporter object
	Data.pExporter = XarLibrary::CreateExporter();
	if (!Data.pExporter)
	{
		wxFprintf(stderr, _T("CreateExporter failed\n"));
		return(FALSE);
	}

	// Call StartExport passing the desired filename of the Xar file
	ok = Data.pExporter->StartExport(pOutputFile);
	if (!ok)
	{
		wxFprintf(stderr, _T("StartExport failed\n"));
		return(FALSE);
	}

	// Create a CXaraFileRecord object for the document header record
	CXaraFileRecord Rec(TAG_FILEHEADER);
	if (ok) ok = Rec.Init();
	if (ok) ok = Rec.WriteBuffer((BYTE*)"CXN",3);
	if (ok) ok = Rec.WriteUINT32(1);					// File size (doesn't actually care though zero may cause an error on loading)
	if (ok) ok = Rec.WriteUINT32(0);					// Native/Web link ID
	if (ok) ok = Rec.WriteUINT32(0);					// Precompression flags
	if (ok) ok = Rec.WriteASCII(_T("ExpandXar"));		// Producer
	if (ok) ok = Rec.WriteASCII(_T("0.01"));			// Producer version
	if (ok) ok = Rec.WriteASCII(_T(""));				// Producer build
	if (ok) ok = Data.pExporter->WriteRecord(&Rec);

	// Set up our record handler function
	ok = pImporter->SetHandler(&Data, ::HandleRecord);
	if (!ok)
	{
		wxFprintf(stderr, _T("SetHandler failed\n"));
		return(FALSE);
	}

	// Do the import
	ok = pImporter->DoImport();
	if (!ok)
	{
		wxFprintf(stderr, _T("DoImport failed\n"));
	}

	if (Data.Depth > 0)
	{
		wxFprintf(stderr, _T("Fixing tree depth (%d)\n"));
		while (Data.Depth > 0)
		{
			ok = Data.pExporter->WriteZeroSizedRecord(TAG_UP);
			(Data.Depth)--;
		}
	}

	// Clean up the importer
	delete pImporter;

	// Write the end of file record because it doesn't get passed to HandleRecord
	ok = Data.pExporter->WriteZeroSizedRecord(TAG_ENDOFFILE);

	delete Data.pExporter;

	return(TRUE);
}
Exemplo n.º 29
0
// The `main program' equivalent, creating the windows and returning the
// main frame
bool AudacityApp::OnInit()
{
   // Unused strings that we want to be translated, even though
   // we're not using them yet...
   wxString future1 = _("Master Gain Control");
   wxString future2 = _("Input Meter");
   wxString future3 = _("Output Meter");

   ::wxInitAllImageHandlers();

   wxFileSystem::AddHandler(new wxZipFSHandler);

   InitPreferences();

	#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__CYGWIN__)
		this->AssociateFileTypes(); 
	#endif

   //
   // Paths: set search path and temp dir path
   //

   wxString home = wxGetHomeDir();
   mAppHomeDir = home;

   // On Unix systems, the default temp dir is in /tmp.
   // Search path (in this order):
   // * The AUDACITY_PATH environment variable
   // * The current directory
   // * The user's .audacity-files directory in their home directory
   // * The "share" and "share/doc" directories in their install path
   #ifdef __WXGTK__
   defaultTempDir.Printf(wxT("/tmp/audacity1.2-%s"), wxGetUserId().c_str());
   wxString pathVar = wxGetenv(wxT("AUDACITY_PATH"));
   if (pathVar != wxT(""))
      AddMultiPathsToPathList(pathVar, audacityPathList);
   AddUniquePathToPathList(FROMFILENAME(::wxGetCwd()), audacityPathList);
   AddUniquePathToPathList(wxString::Format(wxT("%s/.audacity-files"),
                                            home.c_str()),
                           audacityPathList);
   #ifdef AUDACITY_NAME
      AddUniquePathToPathList(wxString::Format(wxT("%s/share/%s"),
                                               wxT(INSTALL_PREFIX), wxT(AUDACITY_NAME)),
                              audacityPathList);
      AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/%s"),
                                               wxT(INSTALL_PREFIX), wxT(AUDACITY_NAME)),
                              audacityPathList);
   #else
      AddUniquePathToPathList(wxString::Format(wxT("%s/share/audacity"),
                                               wxT(INSTALL_PREFIX)),
                              audacityPathList);
      AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/audacity"),
                                               wxT(INSTALL_PREFIX)),
                              audacityPathList);
   #endif

   AddUniquePathToPathList(wxString::Format(wxT("%s/share/locale"),
                                            wxT(INSTALL_PREFIX)),
                           audacityPathList);

   #endif

   wxFileName tmpFile;
   tmpFile.AssignTempFileName(wxT("nn"));
   wxString tmpDirLoc = tmpFile.GetPath(wxPATH_GET_VOLUME);
   ::wxRemoveFile(FILENAME(tmpFile.GetFullPath()));

   // On Mac and Windows systems, use the directory which contains Audacity.
   #ifdef __WXMSW__
   // On Windows, the path to the Audacity program is in argv[0]
   wxString progPath = wxPathOnly(argv[0]);
   AddUniquePathToPathList(progPath, audacityPathList);
   AddUniquePathToPathList(progPath+wxT("\\Languages"), audacityPathList);
   defaultTempDir.Printf(wxT("%s\\audacity_1_2_temp"), tmpDirLoc.c_str());
   #endif
   #ifdef __MACOSX__
   // On Mac OS X, the path to the Audacity program is in argv[0]
   wxString progPath = wxPathOnly(argv[0]);

   AddUniquePathToPathList(progPath, audacityPathList);
   // If Audacity is a "bundle" package, then the root directory is
   // the great-great-grandparent of the directory containing the executable.
   AddUniquePathToPathList(progPath+wxT("/../../../"), audacityPathList);

   AddUniquePathToPathList(progPath+wxT("/Languages"), audacityPathList);
   AddUniquePathToPathList(progPath+wxT("/../../../Languages"), audacityPathList);
   defaultTempDir.Printf(wxT("%s/audacity1.2-%s"),
                         tmpDirLoc.c_str(),
                         wxGetUserId().c_str());
   #endif
   #ifdef __MACOS9__
   // On Mac OS 9, the initial working directory is the one that
   // contains the program.
   wxString progPath = wxGetCwd();
   AddUniquePathToPathList(progPath, audacityPathList);
   AddUniquePathToPathList(progPath+wxT(":Languages"), audacityPathList);
   defaultTempDir.Printf(wxT("%s/audacity_1_2_temp"), tmpDirLoc.c_str());
   #endif

   // BG: Create a temporary window to set as the top window
   wxFrame *temporarywindow = new wxFrame(NULL, -1, wxT("temporarytopwindow"));
   SetTopWindow(temporarywindow);

   // Locale
   // wxWindows 2.3 has a much nicer wxLocale API.  We can make this code much
   // better once we move to wx 2.3/2.4.

   wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT(""));

   // Pop up a dialog the first time the program is run
   if (lang == wxT(""))
      lang = ChooseLanguage(NULL);

#ifdef NOT_RQD
//TIDY-ME: (CleanSpeech) Language prompt??
// The prompt for language only happens ONCE on a system.
// I don't think we should disable it JKC
   wxString lang = gPrefs->Read(wxT("/Locale/Language"), "en");  //lda

// Pop up a dialog the first time the program is run
//lda   if (lang == "")
//lda      lang = ChooseLanguage(NULL);
#endif
   gPrefs->Write(wxT("/Locale/Language"), lang);

   if (lang != wxT("en")) {
      wxLogNull nolog;
      mLocale = new wxLocale(wxT(""), lang, wxT(""), true, true);

      for(unsigned int i=0; i<audacityPathList.GetCount(); i++)
         mLocale->AddCatalogLookupPathPrefix(audacityPathList[i]);

#ifdef AUDACITY_NAME
      mLocale->AddCatalog(wxT(AUDACITY_NAME));
#else
      mLocale->AddCatalog(wxT("audacity"));
#endif
   } else
      mLocale = NULL;

   // Initialize internationalisation (number formats etc.)
   //
   // This must go _after_ creating the wxLocale instance because
   // creating the wxLocale instance sets the application-wide locale.
   Internat::Init();

   // Init DirManager, which initializes the temp directory
   // If this fails, we must exit the program.

   if (!InitTempDir()) {
      FinishPreferences();
      return false;
   }

   // More initialization
   InitCleanSpeech();

   InitDitherers();
   InitAudioIO();

   LoadEffects();

#ifdef __WXMAC__

   // On the Mac, users don't expect a program to quit when you close the last window.
   // Create an offscreen frame with a menu bar.  The frame should never
   // be visible, but when all other windows are closed, this menu bar should
   // become visible.

   gParentFrame = new wxFrame(NULL, -1, wxT("invisible"), wxPoint(5000, 5000), wxSize(100, 100));

   wxMenu *fileMenu = new wxMenu();
   fileMenu->Append(wxID_NEW, wxT("&New\tCtrl+N"));
   fileMenu->Append(wxID_OPEN, wxT("&Open...\tCtrl+O"));
   /* i18n-hint: Mac OS X shortcut should be Ctrl+, */
   fileMenu->Append(wxID_PREFERENCES, _("&Preferences...\tCtrl+,"));

   wxMenuBar *menuBar = new wxMenuBar();
   menuBar->Append(fileMenu, wxT("&File"));

   gParentFrame->SetMenuBar(menuBar);

   gParentFrame->Show();

   SetTopWindow(gParentFrame);

#endif

   SetExitOnFrameDelete(true);


   ///////////////////////////////////////////////////////////////////
   //////////////////////////////////////////////////////////////////
   //Initiate pointers to toolbars here, and create 
   //the toolbars that should be loaded at startup.

   gControlToolBarStub = 
      LoadToolBar( wxT(""),true,
      gParentWindow,ControlToolBarID);
   gMixerToolBarStub = 
      LoadToolBar( wxT("/GUI/EnableMixerToolBar"),true,
      gParentWindow,MixerToolBarID);
   gMeterToolBarStub = 
      LoadToolBar( wxT("/GUI/EnableMeterToolBar"),true,
      gParentWindow,MeterToolBarID);
   gEditToolBarStub = 
      LoadToolBar( wxT("/GUI/EnableEditToolBar"),true,
      gParentWindow,EditToolBarID);
   gTranscriptionToolBarStub = 
      LoadToolBar( wxT("/GUI/EnableTranscriptionToolBar"),false,
      gParentWindow,TranscriptionToolBarID);

   /// ToolBar Initiation Complete.
   ////////////////////////////////////////////////////////////////
   ////////////////////////////////////////////////////////////////

   AudacityProject *project = CreateNewAudacityProject(gParentWindow);
   SetTopWindow(project);

   delete temporarywindow;

   // Can't handle command-line args on Mac OS X yet...
   // Cygwin command-line parser below...
   #if !defined(__MACOSX__) && !defined(__CYGWIN__)
   // Parse command-line arguments
   if (argc > 1) {
      for (int option = 1; option < argc; option++) {
         if (!argv[option])
            continue;
         bool handled = false;

         if (!wxString(wxT("-help")).CmpNoCase(argv[option])) {
            wxPrintf(/* i18n-hint: '-help', '-test' and
                      '-blocksize' need to stay in English. */
                   _("Command-line options supported:\n  -help (this message)\n  -test (run self diagnostics)\n  -blocksize ### (set max disk block size in bytes)\n\nIn addition, specify the name of an audio file or Audacity project\nto open it.\n\n"));
            exit(0);
         }

         if (option < argc - 1 &&
             argv[option + 1] &&
             !wxString(wxT("-blocksize")).CmpNoCase(argv[option])) {
            long theBlockSize;
            if (wxString(argv[option + 1]).ToLong(&theBlockSize)) {
               if (theBlockSize >= 256 && theBlockSize < 100000000) {
                  wxFprintf(stderr, _("Using block size of %ld\n"),
                          theBlockSize);
                  Sequence::SetMaxDiskBlockSize(theBlockSize);
               }
            }
            option++;
            handled = true;
         }

         if (!handled && !wxString(wxT("-test")).CmpNoCase(argv[option])) {
            RunBenchmark(NULL);
            exit(0);
         }

         if (argv[option][0] == wxT('-') && !handled) {
            wxPrintf(_("Unknown command line option: %s\n"), argv[option]);
            exit(0);
         }

         if (!handled)
            project->OpenFile(argv[option]);

      }                         // for option...
   }                            // if (argc>1)
   #endif // not Mac OS X
	
   // Cygwin command line parser (by Dave Fancella)
   #if defined(__CYGWIN__)
   if (argc > 1) {
      int optionstart = 1;
      bool startAtOffset = false;
		
      // Scan command line arguments looking for trouble
      for (int option = 1; option < argc; option++) {
         if (!argv[option])
            continue;
         // Check to see if argv[0] is copied across other arguments.
         // This is the reason Cygwin gets its own command line parser.
         if (wxString(argv[option]).Lower().Contains(wxString(wxT("audacity.exe")))) {
            startAtOffset = true;
            optionstart = option + 1;
         }
      }
		
      for (int option = optionstart; option < argc; option++) {
         if (!argv[option])
            continue;
         bool handled = false;
         bool openThisFile = false;
         wxString fileToOpen;
			
         if (!wxString(wxT("-help")).CmpNoCase(argv[option])) {
            wxPrintf(/* i18n-hint: '-help', '-test' and
                      '-blocksize' need to stay in English. */
                   _("Command-line options supported:\n"
                     "  -help (this message)\n"
                     "  -test (run self diagnostics)\n"
                     "  -blocksize ### (set max disk block size in bytes)\n"
                     "\n"
                     "In addition, specify the name of an audio file or "
                     "Audacity project\n" "to open it.\n" "\n"));
            exit(0);
         }

         if (option < argc - 1 &&
             argv[option + 1] &&
             !wxString(wxT("-blocksize")).CmpNoCase(argv[option])) {
            long theBlockSize;
            if (wxString(argv[option + 1]).ToLong(&theBlockSize)) {
               if (theBlockSize >= 256 && theBlockSize < 100000000) {
                  wxFprintf(stderr, _("Using block size of %ld\n"),
                          theBlockSize);
                  Sequence::SetMaxDiskBlockSize(theBlockSize);
               }
            }
            option++;
            handled = true;
         }

         if (!handled && !wxString(wxT("-test")).CmpNoCase(argv[option])) {
            RunBenchmark(NULL);
            exit(0);
         }

         if (argv[option][0] == wxT('-') && !handled) {
            wxPrintf(_("Unknown command line option: %s\n"), argv[option]);
            exit(0);
         }
			
         if(handled)
            fileToOpen.Clear();
			
         if (!handled)
            fileToOpen = fileToOpen + wxT(" ") + argv[option];
         if(wxString(argv[option]).Lower().Contains(wxT(".aup")))
            openThisFile = true;
         if(openThisFile) {
            openThisFile = false;
            project->OpenFile(fileToOpen);
         }

      }                         // for option...
   }                            // if (argc>1)
   #endif // Cygwin command-line parser

   gInited = true;

   return TRUE;
}
Exemplo n.º 30
0
// show the assert modal dialog
static
void ShowAssertDialog(const wxChar *szFile,
                      int nLine,
                      const wxChar *szCond,
                      const wxChar *szMsg,
                      wxAppTraits *traits)
{
    // this variable can be set to true to suppress "assert failure" messages
    static bool s_bNoAsserts = false;

    wxString msg;
    msg.reserve(2048);

    // make life easier for people using VC++ IDE by using this format: like
    // this, clicking on the message will take us immediately to the place of
    // the failed assert
    msg.Printf(wxT("%s(%d): assert \"%s\" failed"), szFile, nLine, szCond);

    if ( szMsg )
    {
        msg << _T(": ") << szMsg;
    }
    else // no message given
    {
        msg << _T('.');
    }

#if wxUSE_STACKWALKER
    const wxString stackTrace = GetAssertStackTrace();
    if ( !stackTrace.empty() )
    {
        msg << _T("\n\nCall stack:\n") << stackTrace;
    }
#endif // wxUSE_STACKWALKER

#if wxUSE_THREADS
    // if we are not in the main thread, output the assert directly and trap
    // since dialogs cannot be displayed
    if ( !wxThread::IsMain() )
    {
        msg += wxT(" [in child thread]");

#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
        msg << wxT("\r\n");
        OutputDebugString(msg );
#else
        // send to stderr
        wxFprintf(stderr, wxT("%s\n"), msg.c_str());
        fflush(stderr);
#endif
        // He-e-e-e-elp!! we're asserting in a child thread
        wxTrap();
    }
    else
#endif // wxUSE_THREADS

    if ( !s_bNoAsserts )
    {
        // send it to the normal log destination
        wxLogDebug(_T("%s"), msg.c_str());

        if ( traits )
        {
            // delegate showing assert dialog (if possible) to that class
            s_bNoAsserts = traits->ShowAssertDialog(msg);
        }
        else // no traits object
        {
            // fall back to the function of last resort
            s_bNoAsserts = DoShowAssertDialog(msg);
        }
    }
}