Example #1
0
void* wxProcessTerminationThread::Entry()
{
    while (true)
    {
        usleep(100);
        int status = 0;
        int rc = waitpid(abs(m_data->pid), & status, 0);
        if (rc != 0)
        {
            if ((rc != -1) && WIFEXITED(status))
                m_data->exitcode = WEXITSTATUS(status);
            else
                m_data->exitcode = -1;

            wxProcessEvent event;
            wxPostEvent(m_handler, event);

            break;
        }
    }

    return NULL;
}
Example #2
0
// if diff > 0 show next, else show previous
bool PicViewCtrl::ShowPageByDiffNumber(const int diff, bool bWantRet)
{
    int cnt     = m_pList->GetItemCount();
    int cursel  = m_pList->GetSelection();
    int nextsel = 0;
    if(cursel != wxNOT_FOUND)
    {
        nextsel = ((cursel+diff) > cnt-1 ? cnt-1 : (cursel+diff));
        nextsel = nextsel < 0 ? 0 : nextsel;
    }
    if(nextsel != cursel)
    {
        m_pList->SetSelection(nextsel);
        wxCommandEvent evt(wxEVT_COMMAND_LISTBOX_SELECTED, wxID_ANY);
        evt.SetInt(nextsel);
        if(!bWantRet)
            wxPostEvent(m_pFrame, evt);
        else
            ((MainFrame*)m_pFrame)->OnThumbnailLboxSelect(evt);
        return true;
    }
    return false;
}
Example #3
0
void Server::run()
{
	Poco::Net::ServerSocket socket(port);

	running = true;

	while (running)
	{
		if (socket.poll(Poco::Timespan(1, 0),
				Poco::Net::ServerSocket::SELECT_READ))

		{
			Poco::Net::StreamSocket ss = socket.acceptConnection();

			DebugThread *runnable = new DebugThread(ss);

			ClientThread *c = new ClientThread(new Poco::Thread(), runnable);
			clients.push_back(c);

			wxCommandEvent event(wxEVT_MY_EVENT_ADD_DEBUG_THREAD);
			event.SetClientData((void *) runnable);
			wxPostEvent(mainFrame, event);

			c->thread->start(*(c->runnable));
		}
	}

	BOOST_FOREACH(ClientThread *c, clients)
				{
					c->runnable->stop();
					c->thread->join();

					delete c->runnable;
					delete c->thread;

					delete c;
				}
    virtual wxDirTraverseResult OnFile(const wxString& filename)
    {
		if(m_pThread->TestDestroy())
		{
			m_files.Clear();
			return wxDIR_STOP;
		}
		wxFileName fn( filename );
		const tSongClass *psc = CMetaDataHandler::GetSongClass(fn.GetExt());
		if (psc) 
		{
			m_files.Add( filename );

			if ( m_files.GetCount() % 100 == 0 )
			{

				wxCommandEvent UpdateScanProg( wxEVT_COMMAND_MENU_SELECTED, MUSIK_LIBRARY_THREAD_SCAN_PROG );
				UpdateScanProg.SetExtraLong((long)m_files.GetCount());
				wxPostEvent( m_pThread->Parent(), UpdateScanProg );
			}
		}
        
        return wxDIR_CONTINUE;
    }
Example #5
0
bool ProjectManager::PushModificationToHistory(bool force)
{
	wxDateTime maintenant=wxDateTime::UNow();
	if(force || (maintenant-lastHistoryUpdate).GetMilliseconds()>UNDO_HISTORY_TIMESTEP)
	{
		lastHistoryUpdate=maintenant;
		if(this->rootUserConfig->GetElementByLibelle("mainpref")->GetElementByLibelle("history")->GetBoolConfig("keep_modification_history"))
		{
			if(!force)
				wxLogDebug(_("Add modifications in the change log"));
			else
				wxLogDebug(_("Forced adding changes in the change log."));
			this->UpdateXmlFile("",false);
			configHistory.Add(new wxXmlDocument(projetConfig));
			//Dû à la modification on perd soit la plus vieille modification soit tout les dernieres modifications ( en fonction de l'etat de navigation dans l'historique)
			if(currentHistoryNavigation==0)
			{
				if(configHistory.size()>UNDO_HISTORY_SIZE)
					configHistory.RemoveAt(0);
			}else{
				//L'utilisateur a fait annuler et il a ensuite modifié le projet, l'utilisateur ne peut donc plus utiliser refaire
				//Supprime de la version courante jusqu'à la dernière version
				configHistory.RemoveAt(configHistory.size()-currentHistoryNavigation,currentHistoryNavigation-1);
				currentHistoryNavigation=0;
			}
			wxCommandEvent eventUpdate( wxEVT_PSPS_MAIN_EVENT, mainFrame->GetId() );
			eventUpdate.SetInt(ApplicationConfiguration::MAIN_EVENT_UNDO_REDO_UPDATE);
			wxPostEvent(mainFrame,eventUpdate);
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
}
void CslIrcThread::LibIrcError(CslIrcContext *context,wxInt32 error)
{
    LOG_DEBUG("libirc error (%d): \n",error,irc_strerror(errno));

    wxEvtHandler *handler=context->EvtHandler;
    CslIrcEvent evt(context->Target,CslIrcEvent::ERR);
    evt.Strings.Add(A2U(irc_strerror(error)));
    evt.Ints.Add(error);

    switch (error)
    {
        case LIBIRC_ERR_INVAL:
            wxASSERT_MSG(error!=LIBIRC_ERR_INVAL,wxT("Invalid arguments."));
            break;
        case LIBIRC_ERR_RESOLV:
        case LIBIRC_ERR_SOCKET:
        case LIBIRC_ERR_CONNECT:
        case LIBIRC_ERR_CLOSED:
        case LIBIRC_ERR_NOMEM:
            RemoveContext(context);
            break;
        case LIBIRC_ERR_ACCEPT:
        case LIBIRC_ERR_NODCCSEND:
        case LIBIRC_ERR_READ:
        case LIBIRC_ERR_WRITE:
        case LIBIRC_ERR_STATE:
        case LIBIRC_ERR_TIMEOUT:
        case LIBIRC_ERR_OPENFILE:
            break;
        case LIBIRC_ERR_TERMINATED:
            RemoveContext(context);
            break;
    }

    wxPostEvent(handler,evt);
}
Example #7
0
PowerManDlg::PowerManDlg( wxWindow* parent ):powermandlggen( parent )
{
    m_Props = NULL;
    m_SortCol  = 0;
    m_bInvertSortOrder = false;
    initLabels();

    m_IndexPanel->GetSizer()->Layout();
    m_GeneralPanel->GetSizer()->Layout();
    m_ModulesPanel->GetSizer()->Layout();
    m_BlocksPanel->GetSizer()->Layout();
    m_DetailsPanel->GetSizer()->Layout();

    m_BoosterBook->Fit();

    GetSizer()->Fit(this);
    GetSizer()->SetSizeHints(this);

    m_GeneralPanel->Enable(false);
    m_ModulesPanel->Enable(false);
    m_BlocksPanel->Enable(false);
    m_DetailsPanel->Enable(false);

    initIndex();

    // not jet supported
    m_StopDistrictLocos->Enable(false);

    m_BoosterList->SetFocus();

    m_BoosterBook->Connect( wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PowerManDlg::onSetPage ), NULL, this );
    m_SetPage = 0;

    wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_BOOSTERBOOK );
    wxPostEvent( m_BoosterBook, event );
}
Example #8
0
// -------------------------------------------------------------------------------- //
guDownloadCoverThread::ExitCode guDownloadCoverThread::Entry()
{
    wxBitmapType ImageType;
    guCoverImage *  CoverImage = NULL;
    wxImage *   Image = guGetRemoteImage( m_UrlStr, ImageType );

    if( Image )
    {
        if( !TestDestroy() )
        {
            CoverImage = new guCoverImage( m_UrlStr, m_SizeStr, Image );
        }
        else
        {
          //guLogWarning( wxT( "Could not load image from the net index %u." ), LastDownload );
          delete Image;
        }
    }

    if( !TestDestroy() )
    {
        //guLogMessage( wxT( "Done: '%s'" ), m_UrlStr.c_str() );
        //m_CoverEditor->m_DownloadEventsMutex.Lock();
        wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_COVEREDITOR_ADDCOVERIMAGE );
        event.SetClientObject( ( wxClientData * ) this );
        event.SetClientData( CoverImage );
        wxPostEvent( m_CoverEditor, event );
        //m_CoverEditor->m_DownloadEventsMutex.Unlock();
    }
    else
    {
        if( CoverImage )
            delete CoverImage;
    }
    return 0;
}
Example #9
0
void browsers::LayerButton::OnLeftClick(wxMouseEvent &event)
{

   if (event.ShiftDown())
   //Lock layer
   {
      //_hidden = !_hidden;
      hideLayer(!_hidden);
      wxString cmd;
      cmd << wxT("hidelayer(") <<_layer->layno() << wxT(", ");
      if (_hidden) cmd << wxT("true") << wxT(");");
      else cmd << wxT("false") << wxT(");");
      Console->parseCommand(cmd);
   }
   else
   //Select layer
   {
      wxString cmd;
      cmd << wxT("usinglayer(") << _layer->layno()<< wxT(");");
      Console->parseCommand(cmd);

      if (!_selected)
      {
         select();
   
         //Next block uses for unselect previous button
         int bt = BT_LAYER_SELECT;
         wxCommandEvent eventLAYER_SELECT(wxEVT_CMD_BROWSER);
   
         eventLAYER_SELECT.SetExtraLong(_layer->layno());
   
         eventLAYER_SELECT.SetInt(bt);
			wxPostEvent(Browsers->TDTlayers()->getLayerPanel(), eventLAYER_SELECT);
      }
   }
}
Example #10
0
//==============================================================================
void* console::parse_thread::Entry() {
//   wxLogMessage(_T("Mouse is %s (%ld, %ld)"), where.c_str(), x, y);
//   wxLogMessage(_T("Mutex try to lock..."));
   while (wxMUTEX_NO_ERROR != _mutex.TryLock());
   
   telllloc.first_column = telllloc.first_line = 1;
   telllloc.last_column  = telllloc.last_line  = 1;
   telllloc.filename = NULL;
   void* b = tell_scan_string( command.mb_str() );
   StatusBusy(command);
   tellparse();
   my_delete_yy_buffer( b );
   
   _mutex.Unlock();
   if (Console->canvas_invalid())
   {
      wxPaintEvent upde(wxEVT_PAINT);
      wxPostEvent(_canvas_wnd, upde);
      Console->set_canvas_invalid(false);
   }
   StatusReady();
//   wxLogMessage(_T("Mutex unlocked"));
   return NULL;
};
    void castEvent(int type) {
        // 1 == done
        // 2 == failed to connect
        // 3 == failed to open output file
        // 4 == terminated by main loop
        // 5 == update progress bar
        // 6 == unexpected http response

        // 7 == connected, waiting for response
        // 8 == downloading

        // 9 == seeking in tar
        // 10 == unpacking tibia.pic
        // 11 == unpacking tibia.dat
        // 12 == unpacking tibia.spr

        // 13 == unpack failed
        wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, Data_File_FetcherDialog::ID_WORKEREVENT );
        event.SetInt( type );

        // send in a thread-safe way
        wxPostEvent( m_frame, event );

    }
Example #12
0
void console::parse_thread::StatusReady()
{
   wxCommandEvent eventSTATUSUPD(wxEVT_TPDSTATUS);
   eventSTATUSUPD.SetInt(TSTS_THREADOFF);
   wxPostEvent(_status_wnd, eventSTATUSUPD);
}
Example #13
0
void StaticLabel::OnMouseEvent(wxMouseEvent &event)
{
  wxCommandEvent _event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
  wxPostEvent(GetParent(), _event);  
}
Example #14
0
void *wxDownloadThread::Entry()
{
    // we'll use wxPostEvent to post this event since this is the
    // only thread-safe way to post events !
    wxCommandEvent updatevent(wxEVT_COMMAND_DOWNLOAD_COMPLETE);

    // begin our loop
    while (!TestDestroy()) {

        if (m_nStatus == wxDTS_WAITING) {
            //wxLogDebug(wxT("wxDownloadThread::Entry - sleeping 1sec"));
            m_bReady = TRUE;
            wxThread::Sleep(100);
            continue;
        }

        // reset our variables
        m_nFinalSize = 0;
        m_nCurrentSize = 0;

        // we are starting the download of a file; update our datetime field
        m_dtStart = wxDateTime::UNow();

        wxLogUsrMsg(wxT("wxDownloadThread::Entry - downloading ") + m_strURI);

        // ensure we can build a wxURL from the given URI
        wxInputStream *in = wxGetInputStreamFromURI(m_strURI);

        // check INPUT
        if (in == NULL) {
            // something is wrong with the input URL...
            wxDT_ABORT_DOWNLOAD(wxT("Cannot open the INPUT stream; ")
                wxT("url is [") + m_strURI + wxT("]"));
        }
        if (!in->IsOk()) {
            delete in;
            wxDT_ABORT_DOWNLOAD(wxT("Cannot init the INPUT stream"));
        }

        // now work on streams; wx docs says that using wxURL::GetInputStream
        // is deprecated but this is the only way to set advanced info like
        // proxy, user & password...
        wxFileOutputStream out(m_strOutput);
        if (!out.IsOk()) {
            delete in;
            wxDT_ABORT_DOWNLOAD(wxT("Cannot open/init the OUPUT stream [")
                                + m_strOutput + wxT("]"));
        }
        m_nFinalSize = in->GetSize();

        // see wxHTTP docs
        if (m_nFinalSize == 0xffffffff)
            m_nFinalSize = 0;

        // write the downloaded stuff in the output file
        // without using the
        //      out.Write(*in);
        // command; that would be easier but would not allow
        // the program to stop this thread while downloading
        // the file since the TestDestroy() function would not
        // be called in that way...
        char buf[wxDT_BUF_TEMP_SIZE];
        while (!TestDestroy() && m_nStatus == wxDTS_DOWNLOADING) {
            size_t bytes_read = in->Read(buf, WXSIZEOF(buf)).LastRead();
            if ( !bytes_read )
                break;

            if ( out.Write(buf, bytes_read).LastWrite() != bytes_read )
                break;

            // update our downloaded bytes var
            m_nCurrentSize = out.GetSize();

#ifdef __WXDEBUG__
            // do not send too many log messages; send a log message
            // each 20 cycles (i.e. each 20*wxDT_BUF_TEMP_SIZE byte downloaded)
            if ((m_nCurrentSize % (wxDT_BUF_TEMP_SIZE*20)) == 0)
                wxLogUsrMsg(wxT("wxDownloadThread::Entry - downloaded %lu bytes"),
                            m_nCurrentSize);
#endif
        }

        // we don't need the INPUT stream anymore...
        delete in;

        // if m_nFinalSize is set to zero, then we cannot trust it;
        // we must consider the size of the remote file as unavailable
        // since the wxHTTP protocol does not allow us to get it...
        if (!out.IsOk() || out.GetSize() == 0 ||
            (out.GetSize() != m_nFinalSize && m_nFinalSize != 0))
            wxDT_ABORT_DOWNLOAD(wxT("Output FILE stream size is wrong"));

        wxLogUsrMsg(wxT("wxDownloadThread::Entry - completed download of %lu bytes"),
                        m_nCurrentSize);

        // do we have to compute MD5 ?
#if wxUSE_MD5
        m_mStatus.Lock();
        m_nStatus = wxDTS_COMPUTINGMD5;
        m_mStatus.Unlock();

        // get the md5 checksum for the just downloaded file
        m_strComputedMD5 = wxMD5::GetFileMD5(m_strOutput);
#endif

        // we have successfully download the file
        m_bSuccess = TRUE;

        {
            // go in wait mode
            wxMutexLocker locker(m_mStatus);
            m_nStatus = wxDTS_WAITING;
        }

        wxPostEvent(m_pHandler, updatevent);
        m_nFileCount++;

        // we reset our variables here because there is a delay between the
        // wxDownloadThread::BeginNewDownload() calls and the execution of the
        // first statements of this thread...
        m_nCurrentSize = 0;
        m_nFinalSize = 0;
    }

    return (void*)FALSE;
}
Example #15
0
void *RXWorkerThread::Entry()
{
  int rv;
  VscpTcpIf tcpifReceive;
  wxCommandEvent eventReceive( wxVSCP_IN_EVENT, m_pCtrlObject->m_windowID );
    wxCommandEvent eventConnectionLost( wxVSCP_RCV_LOST_EVENT, m_pCtrlObject->m_windowID );
  
  // Must be a valid control object pointer
    if ( NULL == m_pCtrlObject ) return NULL;
  
  // Connect to the server with the control interface
  if ( !tcpifReceive.doCmdOpen( m_pCtrlObject->m_ifVSCP.m_strHost,
                            m_pCtrlObject->m_ifVSCP.m_port,
                            m_pCtrlObject->m_ifVSCP.m_strUser,
                            m_pCtrlObject->m_ifVSCP.m_strPassword ) ) {
    //::wxGetApp().logMsg ( _("VSCP Receive thread - Unable to connect to server."), DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_errorReceive = VSCP_SESSION_ERROR_UNABLE_TO_CONNECT;
        wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );
    return NULL;
  }
  
  // Find the channel id
  tcpifReceive.doCmdGetChannelID( &m_pCtrlObject->m_rxChannelID );

  // Start Receive Loop
    tcpifReceive.doCmdEnterReceiveLoop();

  vscpEvent event;
    while ( !TestDestroy() && !m_pCtrlObject->m_bQuit )
    {

    if ( CANAL_ERROR_SUCCESS == 
            ( rv = tcpifReceive.doCmdBlockReceive( &event, 1000 ) ) ) {

      if ( NULL != m_pCtrlObject->m_pWnd ) {

        vscpEvent *pEvent = new vscpEvent;
        if ( NULL != pEvent ) {

          copyVSCPEvent( pEvent, &event );

          eventReceive.SetClientData( pEvent );
          wxPostEvent( m_pCtrlObject->m_pWnd, eventReceive );
        
        }

      } // Session window exist

    }
    else {
      if ( CANAL_ERROR_COMMUNICATION == rv ) m_pCtrlObject->m_bQuit = true;
    }

    } // while

  // Close the interface
  tcpifReceive.doCmdClose();

    wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );

    return NULL;

}
Example #16
0
void browsers::clearGDStab() {
   wxCommandEvent eventADDTAB(wxEVT_CMD_BROWSER);
   eventADDTAB.SetInt(BT_CLEARGDS_TAB);
   wxPostEvent(Browsers, eventADDTAB);
}
Example #17
0
wxExSTCEntryDialog::wxExSTCEntryDialog(wxWindow* parent,
  const wxString& caption,
  const wxString& text,
  const wxString& prompt,
  long button_style,
  bool use_shell,
  wxWindowID id,
  const wxPoint& pos,
  const wxSize& size, 
  long style,
  const wxString& name)
  : wxExDialog(parent, caption, button_style, id, pos, size, style, name)
  , m_Process(NULL)
{
#if wxUSE_STATTEXT
  if (!prompt.empty())
  {
    // See wxWidgets: src\generic\textdlgg.cpp, use similar bottom border flags.
    AddUserSizer(CreateTextSizer(prompt), 
      wxSizerFlags().DoubleBorder(wxBOTTOM));
  }
#endif

  wxPersistentRegisterAndRestore(this);

  m_STC = (use_shell ?
    new wxExSTCShell(this, text, wxEmptyString, true, -1, wxEmptyString,
      wxExSTC::STC_MENU_DEFAULT | wxExSTC::STC_MENU_OPEN_LINK):
    new wxExSTC(this, text));
  
  m_STC->SetEdgeMode(wxSTC_EDGE_NONE);
  m_STC->ResetMargins();
  m_STC->SetViewEOL(false);
  m_STC->SetViewWhiteSpace(wxSTC_WS_INVISIBLE);

  AddUserSizer(m_STC);

  LayoutSizers();
  
  Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent& event){
    if (m_Process != NULL)
    {
      if (m_Process->IsRunning())
      {
        m_Process->Kill();
      }
    }});

  Bind(wxEVT_BUTTON, [=](wxCommandEvent& event) {
      if (m_Process != NULL)
      {
        if (m_Process->IsRunning())
        {
          m_Process->Kill();
        }
      }
      event.Skip();}, wxID_OK);
  
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
      wxPostEvent(wxTheApp->GetTopWindow(), event);}, wxID_FIND);
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
      wxPostEvent(wxTheApp->GetTopWindow(), event);}, wxID_REPLACE);
}
Example #18
0
bool CFileZillaEnginePrivate::SendEvent(enum EngineNotificationType eventType, int data /*=0*/)
{
	wxFzEngineEvent evt(wxID_ANY, eventType, data);
	wxPostEvent(this, evt);
	return true;
}
Example #19
0
	void HandleNotificationAlways(const CMuleNotiferBase& ntf)
	{
		CMuleGUIEvent evt(ntf.Clone());
		wxPostEvent(wxTheApp, evt);
	}
Example #20
0
void TopEffectsPanel::OnResize(wxSizeEvent& event)
{
    wxCommandEvent eventWindowResized(EVT_WINDOW_RESIZED);
    wxPostEvent(GetParent(), eventWindowResized);
    Refresh();
}
void *ThreadSearchThread::Entry()
{
    // Tests if we have a working searcher object.
    // Cancel search if it is not the case
    if ( m_pTextFileSearcher == NULL )
        return 0;

    size_t i = 0;

    // For now, we look for all paths for the different search scopes
    // and store them in a sorted array to avoid pasing several times
    // the same file.
    // This will be changed to avoid consuming a lot of memory (parsing
    // form C:\ and storing all paths...). Aim is to avoid the use of the
    // array for storing items.

    // Search in directory files ?
    if ( m_FindData.MustSearchInDirectory() == true )
    {
        int flags = wxDIR_FILES | wxDIR_DIRS | wxDIR_DOTDOT;
        flags    |= m_FindData.GetHiddenSearch() ? wxDIR_HIDDEN : 0;

        const wxString &path = m_FindData.GetSearchPath(true);
        if (!wxDir::Exists(path))
        {
            ThreadSearchEvent event(wxEVT_THREAD_SEARCH_ERROR, -1);
            event.SetString(_("Cannot open folder ") + path);

            // Using wxPostEvent, we avoid multi-threaded memory violation.
            wxPostEvent(m_pThreadSearchView,event);
            return 0;
        }
        else
        {
            wxDir Dir(path);
            Dir.Traverse(*(static_cast<wxDirTraverser*>(this)), wxEmptyString, flags);
        }

        // Tests thread stop (cancel search, app shutdown)
        if ( TestDestroy() == true ) return 0;
    }

    // Search in workspace files ?
    if ( m_FindData.MustSearchInWorkspace() == true )
    {
        ProjectsArray* pProjectsArray = Manager::Get()->GetProjectManager()->GetProjects();
        for ( size_t j=0; j < pProjectsArray->GetCount(); ++j )
        {
            AddProjectFiles(m_FilePaths, *pProjectsArray->Item(j));
            if ( TestDestroy() == true ) return 0;
        }
    }
    else if ( m_FindData.MustSearchInProject() == true )
    {
        // Search in project files ?
        // Necessary only if not already parsed in worspace part
        cbProject* pProject = Manager::Get()->GetProjectManager()->GetActiveProject();
        if ( pProject != NULL )
        {
            AddProjectFiles(m_FilePaths, *pProject);
            if ( TestDestroy() == true ) return 0;
        }
    }
    else if ( m_FindData.MustSearchInTarget() == true )
    {
        // Search in target files ?
        // Necessary only if not already parsed in project part
        cbProject* pProject = Manager::Get()->GetProjectManager()->GetActiveProject();
        if ( pProject != NULL )
        {
            ProjectBuildTarget *pTarget = pProject->GetBuildTarget(pProject->GetActiveBuildTarget());
            if ( pTarget != 0 )
            {
                AddTargetFiles(m_FilePaths, *pTarget);
                if ( TestDestroy() == true ) return 0;
            }
        }
    }

    // Tests thread stop (cancel search, app shutdown)
    if ( TestDestroy() == true ) return 0;

    // Open files
    if ( m_FindData.MustSearchInOpenFiles() == true )
    {
        EditorManager* pEdManager = Manager::Get()->GetEditorManager();
        for (i = 0; i < (size_t)pEdManager->GetNotebook()->GetPageCount(); ++i)
        {
            cbEditor* pEditor = pEdManager->GetBuiltinEditor(i);
            if ( pEditor != NULL )
            {
                AddNewItem(m_FilePaths, pEditor->GetFilename(), m_Masks);
            }
        }
    }

    // Tests thread stop (cancel search, app shutdown)
    if ( TestDestroy() == true ) return 0;

    // if the list is empty, leave
    if (m_FilePaths.GetCount() == 0)
    {
        //-cbMessageBox(wxT("No files to search in!"), wxT("Error"), wxICON_WARNING);
        ////(pecan 2008/4/26)
        // DO NOT issue graphics calls from this thread !!!!!!
        ThreadSearchEvent event(wxEVT_THREAD_SEARCH_ERROR, -1);
        event.SetString(_("No files to search.\nCheck options "));
        // Using wxPostEvent, we avoid multi-threaded memory violation.
        wxPostEvent(m_pThreadSearchView,event);
        return 0;
    }

    for ( i = 0; i < m_FilePaths.GetCount(); ++i )
    {
        FindInFile(m_FilePaths[i]);

        // Tests thread stop (cancel search, app shutdown)
        if ( TestDestroy() == true ) return 0;
    }

    return 0;
}
Example #22
0
void TopEffectsPanel::OnButtonUpdateEffectClick(wxCommandEvent& event)
{
    wxCommandEvent eventEffectUpdated(EVT_EFFECT_UPDATED);
    wxPostEvent(GetParent(), eventEffectUpdated);
    Refresh();
}
Example #23
0
bool PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition,
                               EDA_ITEM* aItem )
{
    if( aHotkeyCode == 0 )
        return false;

    bool itemCurrentlyEdited = GetCurItem() && GetCurItem()->GetFlags();
    MODULE* module = NULL;
    int evt_type = 0;       //Used to post a wxCommandEvent on demand
    PCB_SCREEN* screen = GetScreen();
    auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();

    /* Convert lower to upper case
     * (the usual toupper function has problem with non ascii codes like function keys
     */
    if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
        aHotkeyCode += 'A' - 'a';

    EDA_HOTKEY* HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, common_Hotkey_List );

    if( HK_Descr == NULL )
        HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, board_edit_Hotkey_List );

    if( HK_Descr == NULL )
        return false;

    int hk_id = HK_Descr->m_Idcommand;

    // Create a wxCommandEvent that will be posted in some hot keys functions
    wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
    cmd.SetEventObject( this );

    LAYER_NUM  ll;

    switch( hk_id )
    {
    default:
    case HK_NOT_FOUND:
        return false;

    case HK_LEFT_CLICK:
        OnLeftClick( aDC, aPosition );
        break;

    case HK_LEFT_DCLICK:    // Simulate a double left click: generate 2 events
        OnLeftClick( aDC, aPosition );
        OnLeftDClick( aDC, aPosition );
        break;

    case HK_SWITCH_TRACK_WIDTH_TO_NEXT:
        if( GetCanvas()->IsMouseCaptured() )
            GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false );

        if( GetDesignSettings().GetTrackWidthIndex() < GetDesignSettings().m_TrackWidthList.size() - 1 )
            GetDesignSettings().SetTrackWidthIndex( GetDesignSettings().GetTrackWidthIndex() + 1 );
        else
            GetDesignSettings().SetTrackWidthIndex( 0 );

        if( GetCanvas()->IsMouseCaptured() )
            GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false );

        break;

    case HK_SWITCH_TRACK_WIDTH_TO_PREVIOUS:
        if( GetCanvas()->IsMouseCaptured() )
            GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false );

        if( GetDesignSettings().GetTrackWidthIndex() <= 0 )
            GetDesignSettings().SetTrackWidthIndex( GetDesignSettings().m_TrackWidthList.size() -1 );
        else
            GetDesignSettings().SetTrackWidthIndex( GetDesignSettings().GetTrackWidthIndex() - 1 );

        if( GetCanvas()->IsMouseCaptured() )
            GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false );

        break;

    case HK_SWITCH_GRID_TO_FASTGRID1:
        SetFastGrid1();
        break;

    case HK_SWITCH_GRID_TO_FASTGRID2:
        SetFastGrid2();
        break;

    case HK_SWITCH_GRID_TO_NEXT:
        evt_type = ID_POPUP_GRID_NEXT;
        break;

    case HK_SWITCH_GRID_TO_PREVIOUS:
        evt_type = ID_POPUP_GRID_PREV;
        break;

    case HK_SWITCH_LAYER_TO_PREVIOUS:
        ll = GetActiveLayer();

        if( !IsCopperLayer( ll ) )
            break;

        if( ll == F_Cu )
            ll = B_Cu;
        else if( ll == B_Cu )
            ll = ToLAYER_ID( GetBoard()->GetCopperLayerCount() - 2 );
        else
            ll = ll - 1;

        SwitchLayer( aDC, ToLAYER_ID( ll ) );
        break;

    case HK_SWITCH_LAYER_TO_NEXT:
        ll = GetActiveLayer();

        if( !IsCopperLayer( ll ) )
            break;

        if( ll == B_Cu )
            ll = F_Cu;
        else if( ++ll >= GetBoard()->GetCopperLayerCount() - 1 )
            ll = B_Cu;

        SwitchLayer( aDC, ToLAYER_ID( ll ) );
        break;

    case HK_SWITCH_LAYER_TO_COMPONENT:
        SwitchLayer( aDC, F_Cu );
        break;

    case HK_SWITCH_LAYER_TO_COPPER:
        SwitchLayer( aDC, B_Cu );
        break;

    case HK_SWITCH_LAYER_TO_INNER1:
        SwitchLayer( aDC, In1_Cu );
        break;

    case HK_SWITCH_LAYER_TO_INNER2:
        SwitchLayer( aDC, In2_Cu );
        break;

    case HK_SWITCH_LAYER_TO_INNER3:
        SwitchLayer( aDC, In3_Cu );
        break;

    case HK_SWITCH_LAYER_TO_INNER4:
        SwitchLayer( aDC, In4_Cu );
        break;

    case HK_SWITCH_LAYER_TO_INNER5:
        SwitchLayer( aDC, In5_Cu );
        break;

    case HK_SWITCH_LAYER_TO_INNER6:
        SwitchLayer( aDC, In6_Cu );
        break;

    case HK_HELP: // Display Current hotkey list
        DisplayHotkeyList( this, g_Board_Editor_Hotkeys_Descr );
        break;

    case HK_PREFERENCES:
        evt_type = wxID_PREFERENCES;
        break;

    case HK_ZOOM_IN:
        evt_type = ID_KEY_ZOOM_IN;
        break;

    case HK_ZOOM_OUT:
        evt_type = ID_KEY_ZOOM_OUT;
        break;

    case HK_ZOOM_REDRAW:
        evt_type = ID_ZOOM_REDRAW;
        break;

    case HK_ZOOM_AUTO:
        evt_type = ID_ZOOM_PAGE;
        break;

    case HK_ZOOM_CENTER:
        evt_type = ID_POPUP_ZOOM_CENTER;
        break;

    case HK_ZOOM_SELECTION:
        evt_type = ID_ZOOM_SELECTION;
        break;

    case HK_ADD_MODULE:
        evt_type = ID_PCB_MODULE_BUTT;
        break;

    case HK_UNDO:
    case HK_REDO:
        if( !itemCurrentlyEdited )
        {
            wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent );
            wxPostEvent( this, event );
        }

        break;

    case HK_RESET_LOCAL_COORD:  // Set the relative coord
        GetScreen()->m_O_Curseur = GetCrossHairPosition();
        break;

    case HK_SET_GRID_ORIGIN:
        PCBNEW_CONTROL::SetGridOrigin( GetGalCanvas()->GetView(), this,
                                       new KIGFX::ORIGIN_VIEWITEM( GetGridOrigin(), UR_TRANSIENT ),
                                       GetCrossHairPosition() );
        m_canvas->Refresh();
        break;

    case HK_RESET_GRID_ORIGIN:
        PCBNEW_CONTROL::SetGridOrigin( GetGalCanvas()->GetView(), this,
                                       new KIGFX::ORIGIN_VIEWITEM( GetGridOrigin(), UR_TRANSIENT ),
                                       wxPoint( 0, 0 ) );
        m_canvas->Refresh();
        break;

    case HK_SWITCH_UNITS:
        evt_type = (GetUserUnits() == INCHES) ?
                    ID_TB_OPTIONS_SELECT_UNIT_MM : ID_TB_OPTIONS_SELECT_UNIT_INCH;
        break;

    case HK_SWITCH_TRACK_DISPLAY_MODE:
        displ_opts->m_DisplayPcbTrackFill = !displ_opts->m_DisplayPcbTrackFill;
        m_canvas->Refresh();
        break;

    case HK_DELETE:
        OnHotkeyDeleteItem( aDC );
        break;

    case HK_BACK_SPACE:
        if( IsCopperLayer( GetActiveLayer() ) )
        {
            if( !itemCurrentlyEdited )
            {
                // no track is currently being edited - select a segment and remove it.
                // @todo: possibly? pass the HK command code to PcbGeneralLocateAndDisplay()
                // so it can restrict its search to specific item types.
                BOARD_ITEM * item = PcbGeneralLocateAndDisplay();

                // don't let backspace delete modules!!
                if( item && item->IsTrack() )
                {
                    Delete_Segment( aDC, (TRACK*) item );
                    SetCurItem( NULL );
                }

                OnModify();
            }
            else if( GetCurItem()->IsTrack() )
            {
                // then an element is being edited - remove the last segment.
                // simple lines for debugger:
                TRACK* track = (TRACK*) GetCurItem();
                track = Delete_Segment( aDC, track );
                SetCurItem( track );
                OnModify();
            }
        }

        break;

    case HK_GET_AND_MOVE_FOOTPRINT:
        if( !itemCurrentlyEdited )
            evt_type = ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST;

        break;

    case HK_FIND_ITEM:
        if( !itemCurrentlyEdited )
            evt_type = ID_FIND_ITEMS;

        break;

    case HK_OPEN:
        if( !itemCurrentlyEdited )
            evt_type = ID_LOAD_FILE ;

        break;

    case HK_SAVE:
        if( !itemCurrentlyEdited )
            evt_type = ID_SAVE_BOARD;

        break;

    case HK_ADD_MICROVIA: // Place a micro via if a track is in progress
        if( GetToolId() != ID_TRACK_BUTT )
            return true;

        if( !itemCurrentlyEdited )                         // no track in progress: nothing to do
            break;

        if( GetCurItem()->Type() != PCB_TRACE_T )           // Should not occur
            return true;

        if( !GetCurItem()->IsNew() )
            return true;

        // place micro via and switch layer
        if( IsMicroViaAcceptable() )
            evt_type = ID_POPUP_PCB_PLACE_MICROVIA;

        break;

    case HK_ADD_BLIND_BURIED_VIA:
    case HK_ADD_THROUGH_VIA: // Switch to alternate layer and Place a via if a track is in progress
        if( GetBoard()->GetDesignSettings().m_BlindBuriedViaAllowed &&
            hk_id == HK_ADD_BLIND_BURIED_VIA  )
            GetBoard()->GetDesignSettings().m_CurrentViaType = VIA_BLIND_BURIED;
        else
            GetBoard()->GetDesignSettings().m_CurrentViaType = VIA_THROUGH;

        if( !itemCurrentlyEdited ) // no track in progress: switch layer only
        {
            Other_Layer_Route( NULL, aDC );
            if( displ_opts->m_ContrastModeDisplay )
                m_canvas->Refresh();
            break;
        }

        if( GetToolId() != ID_TRACK_BUTT )
            return true;

        if( GetCurItem()->Type() != PCB_TRACE_T )
            return true;

        if( !GetCurItem()->IsNew() )
            return true;

        evt_type = hk_id == HK_ADD_BLIND_BURIED_VIA ?
            ID_POPUP_PCB_PLACE_BLIND_BURIED_VIA : ID_POPUP_PCB_PLACE_THROUGH_VIA;
        break;

    case HK_SEL_LAYER_AND_ADD_THROUGH_VIA:
    case HK_SEL_LAYER_AND_ADD_BLIND_BURIED_VIA:
        if( GetCurItem() == NULL || !GetCurItem()->IsNew() ||
            GetCurItem()->Type() != PCB_TRACE_T )
            break;

        evt_type = hk_id == HK_SEL_LAYER_AND_ADD_BLIND_BURIED_VIA ?
            ID_POPUP_PCB_SELECT_CU_LAYER_AND_PLACE_BLIND_BURIED_VIA :
            ID_POPUP_PCB_SELECT_CU_LAYER_AND_PLACE_THROUGH_VIA;
        break;

    case HK_SWITCH_TRACK_POSTURE:
        /* change the position of initial segment when creating new tracks
         * switch from _/  to -\ .
         */
        evt_type = ID_POPUP_PCB_SWITCH_TRACK_POSTURE ;
        break;

    case HK_DRAG_TRACK_KEEP_SLOPE:
        OnHotkeyMoveItem( HK_DRAG_TRACK_KEEP_SLOPE );
        break;

    case HK_PLACE_ITEM:
        OnHotkeyPlaceItem( aDC );
        break;

    case HK_ADD_NEW_TRACK: // Start new track, if possible
        OnHotkeyBeginRoute( aDC );
        break;

    case HK_EDIT_ITEM:      // Edit board item
        OnHotkeyEditItem( HK_EDIT_ITEM );
        break;

    case HK_EDIT_MODULE_WITH_MODEDIT:      // Edit module with module editor
        OnHotkeyEditItem( HK_EDIT_MODULE_WITH_MODEDIT );
        break;

    case HK_LOCK_UNLOCK_FOOTPRINT: // toggle module "MODULE_is_LOCKED" status:
        // get any module, locked or not locked and toggle its locked status
        if( !itemCurrentlyEdited )
        {
            wxPoint pos = RefPos( true );
            module = GetBoard()->GetFootprint( pos, screen->m_Active_Layer, true );
        }
        else if( GetCurItem()->Type() == PCB_MODULE_T )
        {
            module = (MODULE*) GetCurItem();
        }

        if( module )
        {
            SetCurItem( module );
            module->SetLocked( !module->IsLocked() );
            OnModify();
            SetMsgPanel( module );
        }
        break;

    case HK_DRAG_ITEM:    // Start drag module or track segment
        OnHotkeyMoveItem( HK_DRAG_ITEM );
        break;

    case HK_MOVE_ITEM:                  // Start move item
        OnHotkeyMoveItem( HK_MOVE_ITEM );
        break;

    case HK_COPY_ITEM:
        evt_type = OnHotkeyCopyItem();
        break;

    case HK_ROTATE_ITEM:        // Rotation
        OnHotkeyRotateItem( HK_ROTATE_ITEM );
        break;

    case HK_FLIP_ITEM:
        OnHotkeyFlipItem( HK_FLIP_ITEM );
        break;

    case HK_MOVE_ITEM_EXACT:
    case HK_DUPLICATE_ITEM:
    case HK_DUPLICATE_ITEM_AND_INCREMENT:
    case HK_CREATE_ARRAY:
        OnHotkeyDuplicateOrArrayItem( HK_Descr->m_Idcommand );
        break;

    case HK_SWITCH_HIGHCONTRAST_MODE: // switch to high contrast mode and refresh the canvas
        displ_opts->m_ContrastModeDisplay = !displ_opts->m_ContrastModeDisplay;
        m_canvas->Refresh();
        break;

    case HK_CANVAS_CAIRO:
        evt_type = ID_MENU_CANVAS_CAIRO;
        break;

    case HK_CANVAS_OPENGL:
        evt_type = ID_MENU_CANVAS_OPENGL;
        break;

    case HK_CANVAS_LEGACY:
        evt_type = ID_MENU_CANVAS_LEGACY;
        break;

    case HK_ZONE_FILL_OR_REFILL:
        evt_type = ID_POPUP_PCB_FILL_ALL_ZONES;
        break;

    case HK_ZONE_REMOVE_FILLED:
        evt_type = ID_POPUP_PCB_REMOVE_FILLED_AREAS_IN_ALL_ZONES;
        break;
    }

    if( evt_type != 0 )
    {
        wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
        evt.SetEventObject( this );
        evt.SetId( evt_type );
        GetEventHandler()->ProcessEvent( evt );
    }

    return true;
}
void EDA_DRAW_PANEL_GAL::ForceRefresh()
{
    wxPaintEvent redrawEvent;
    wxPostEvent( this, redrawEvent );
}
Example #25
0
void browsers::celltree_highlight(const std::string cname) {
   wxCommandEvent eventCELLTREE(wxEVT_CMD_BROWSER);
   eventCELLTREE.SetInt(BT_CELL_HIGHLIGHT);
   eventCELLTREE.SetString(wxString(cname.c_str(), wxConvUTF8));
   wxPostEvent(Browsers->TDTstruct(), eventCELLTREE);
}
Example #26
0
// when the user double clicks on the server list
void dlgMain::OnServerListDoubleClick(wxListEvent& event)
{
    wxCommandEvent LaunchEvent(wxEVT_COMMAND_TOOL_CLICKED, Id_MnuItmLaunch);
    
    wxPostEvent(this, LaunchEvent);
}
Example #27
0
void *deviceThread::Entry()
{
  wxCommandEvent eventReceive( wxVSCP_IN_EVENT, m_pCtrlObject->m_windowID );
    wxCommandEvent eventConnectionLost( wxVSCP_RCV_LOST_EVENT, m_pCtrlObject->m_windowID );

    // Must have a valid pointer to the control object
    if ( NULL == m_pCtrlObject ) return NULL;

    // Load dynamic library
    if ( ! m_wxdll.Load ( m_pCtrlObject->m_ifCANAL.m_strPath, wxDL_LAZY ) )
    {
        //::wxGetApp().logMsg ( _T ( "vscpd: Unable to load dynamic library." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // Now find methods in library

    // * * * * CANAL OPEN * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalOpen =
                       ( LPFNDLL_CANALOPEN ) m_wxdll.GetSymbol ( _T ( "CanalOpen" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalOpen." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL CLOSE * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalClose =
                       ( LPFNDLL_CANALCLOSE ) m_wxdll.GetSymbol ( _T ( "CanalClose" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalClose." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL GETLEVEL * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalGetLevel =
                       ( LPFNDLL_CANALGETLEVEL ) m_wxdll.GetSymbol ( _T ( "CanalGetLevel" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalGetLevel." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL SEND * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalSend =
                       ( LPFNDLL_CANALSEND ) m_wxdll.GetSymbol ( _T ( "CanalSend" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalSend." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL DATA AVAILABLE * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalDataAvailable =
                       ( LPFNDLL_CANALDATAAVAILABLE ) m_wxdll.GetSymbol ( _T ( "CanalDataAvailable" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalDataAvailable." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }


    // * * * * CANAL RECEIVE * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalReceive =
                       ( LPFNDLL_CANALRECEIVE ) m_wxdll.GetSymbol ( _T ( "CanalReceive" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalReceive." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL GET STATUS * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalGetStatus =
                       ( LPFNDLL_CANALGETSTATUS ) m_wxdll.GetSymbol ( _T ( "CanalGetStatus" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalGetStatus." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL GET STATISTICS * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalGetStatistics =
                       ( LPFNDLL_CANALGETSTATISTICS ) m_wxdll.GetSymbol ( _T ( "CanalGetStatistics" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalGetStatistics." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL SET FILTER * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalSetFilter =
                       ( LPFNDLL_CANALSETFILTER ) m_wxdll.GetSymbol ( _T ( "CanalSetFilter" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalSetFilter." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL SET MASK * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalSetMask =
                       ( LPFNDLL_CANALSETMASK ) m_wxdll.GetSymbol ( _T ( "CanalSetMask" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalSetMask." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL GET VERSION * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalGetVersion =
                       ( LPFNDLL_CANALGETVERSION ) m_wxdll.GetSymbol ( _T ( "CanalGetVersion" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalGetVersion." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL GET DLL VERSION * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalGetDllVersion =
                       ( LPFNDLL_CANALGETDLLVERSION ) m_wxdll.GetSymbol ( _T ( "CanalGetDllVersion" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalGetDllVersion." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // * * * * CANAL GET VENDOR STRING * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalGetVendorString =
                       ( LPFNDLL_CANALGETVENDORSTRING ) m_wxdll.GetSymbol ( _T ( "CanalGetVendorString" ) ) ) )
    {
        // Free the library
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalGetVendorString." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }


    wxLogNull logNo;


    // ******************************
    //     Generation 2 Methods
    // ******************************


    // * * * * CANAL BLOCKING SEND * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalBlockingSend =
                       ( LPFNDLL_CANALBLOCKINGSEND ) m_wxdll.GetSymbol ( _T ( "CanalBlockingSend" ) ) ) )
    {
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalBlockingSend. Probably Generation 1 driver." ),
        //					              DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_proc_CanalBlockingSend = NULL;
    }

    // * * * * CANAL BLOCKING RECEIVE * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalBlockingReceive =
                       ( LPFNDLL_CANALBLOCKINGRECEIVE ) m_wxdll.GetSymbol ( _T ( "CanalBlockingReceive" ) ) ) )
    {
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalBlockingReceive. Probably Generation 1 driver." ),
        //					                DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_proc_CanalBlockingReceive = NULL;
    }

    // * * * * CANAL GET DRIVER INFO * * * *
    if ( NULL == ( m_pCtrlObject->m_proc_CanalGetdriverInfo =
                       ( LPFNDLL_CANALGETDRIVERINFO ) m_wxdll.GetSymbol ( _T ( "CanalGetDriverInfo" ) ) ) )
    {
        //::wxGetApp().logMsg ( _T ( "Unable to get dl entry for CanalGetDriverInfo. Probably Generation 1 driver." ),
        //					                DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_proc_CanalGetdriverInfo = NULL;
    }

    //
    // =====================================================================================
    //

    // Open the device
    m_pCtrlObject->m_openHandle =
        m_pCtrlObject->m_proc_CanalOpen ( ( const char * ) m_pCtrlObject->m_ifCANAL.m_strConfig.mb_str ( wxConvUTF8 ),
                                          m_pCtrlObject->m_ifCANAL.m_flags );



    // Check if the driver opened properly
    if ( 0 == m_pCtrlObject->m_openHandle )
    {
        //::wxGetApp().logMsg ( _T ( "Driver failed to open." ), DAEMON_LOGMSG_CRITICAL );
        return NULL;
    }

    // Get Driver Level
    m_pCtrlObject->m_driverLevel = m_pCtrlObject->m_proc_CanalGetLevel ( m_pCtrlObject->m_openHandle );


    // If this is a TCPIP level driver then nothing more then open and close should be done without
    // the driver. No messages should be put on any queues
    if ( CANAL_LEVEL_USES_TCPIP == m_pCtrlObject->m_driverLevel )
    {
        // Just sit and wait until the end
        while ( !TestDestroy() && !m_pCtrlObject->m_bQuit )
        {
            wxSleep ( 1 );
        }
    }
    else
    {
    if ( NULL != m_pCtrlObject->m_proc_CanalBlockingReceive )
        {

            // * * * * Blocking version * * * *

            /////////////////////////////////////////////////////////////////////////////
            // Device write worker thread
            /////////////////////////////////////////////////////////////////////////////
            m_pwriteThread = new deviceWriteThread;

            if ( m_pwriteThread )
            {
                m_pwriteThread->m_pMainThreadObj = this;
                wxThreadError err;
                if ( wxTHREAD_NO_ERROR == ( err = m_pwriteThread->Create() ) ) {
                    m_pwriteThread->SetPriority( WXTHREAD_MAX_PRIORITY );
                    if ( wxTHREAD_NO_ERROR != ( err = m_pwriteThread->Run() ) ) {
                        //::wxGetApp().logMsg ( _("Unable to run device write worker thread."), DAEMON_LOGMSG_CRITICAL );	
                    }
                }
                else {
                    //::wxGetApp().logMsg ( _("Unable to create device write worker thread."), DAEMON_LOGMSG_CRITICAL );	
                }
            }
            else
            {
                //::wxGetApp().logMsg ( _("Unable to allocate memory for device write worker thread."), DAEMON_LOGMSG_CRITICAL );
            }

            /////////////////////////////////////////////////////////////////////////////
            // Device read worker thread
            /////////////////////////////////////////////////////////////////////////////
            m_preceiveThread = new deviceReceiveThread;

            if ( m_preceiveThread )
            {
                m_preceiveThread->m_pMainThreadObj = this;
                wxThreadError err;
                if ( wxTHREAD_NO_ERROR == ( err = m_preceiveThread->Create() ) ) {
                    m_preceiveThread->SetPriority( WXTHREAD_MAX_PRIORITY );
                    if ( wxTHREAD_NO_ERROR != ( err = m_preceiveThread->Run() ) ) {
                        //::wxGetApp().logMsg ( _("Unable to run device receive worker thread."), DAEMON_LOGMSG_CRITICAL );	
                    }
                }
                else {
                    //::wxGetApp().logMsg ( _("Unable to create device receive worker thread."), DAEMON_LOGMSG_CRITICAL );	
                }
            }
            else
            {
                //::wxGetApp().logMsg ( _("Unable to allocate memory for device receive worker thread."), DAEMON_LOGMSG_CRITICAL );
            }

            // Just sit and wait until the end
            while ( !m_pCtrlObject->m_bQuit )
            {
                wxSleep ( 1 );
            }

      m_preceiveThread->m_bQuit = true;
      m_pwriteThread->m_bQuit = true;
      m_preceiveThread->Wait();
      m_pwriteThread->Wait();
        }
        else
        {

            // * * * * Non blocking version * * * *

      bool bActivity;
            while ( !TestDestroy() && !m_pCtrlObject->m_bQuit ) {

        bActivity = false;
                /////////////////////////////////////////////////////////////////////////////
                //                           Receive from device								   				 //
                /////////////////////////////////////////////////////////////////////////////
                canalMsg msg;
                if ( m_pCtrlObject->m_proc_CanalDataAvailable ( m_pCtrlObject->m_openHandle ) ) {

                        m_pCtrlObject->m_proc_CanalReceive ( m_pCtrlObject->m_openHandle, &msg );

            bActivity = true;
                            
                        vscpEvent *pEvent = new vscpEvent;
            if ( NULL != pEvent ) {

                          // Convert CANAL message to VSCP event
                          convertCanalToEvent ( pEvent,
                                                                        &msg,
                                                                    m_pCtrlObject->m_GUID );

              eventReceive.SetClientData( pEvent );
              wxPostEvent( m_pCtrlObject->m_pWnd, eventReceive );

            }

                }


                  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                  //             Send messages (if any) in the outqueue
                  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
          if ( m_pCtrlObject->m_outQueue.GetCount() ) {

            m_pCtrlObject->m_mutexOutQueue.Lock();

            eventOutQueue::compatibility_iterator node = 
                    m_pCtrlObject->m_outQueue.GetFirst();
            vscpEvent *pEvent = node->GetData();
    
            canalMsg canalMsg;
                convertEventToCanal ( &canalMsg, pEvent );
                if ( CANAL_ERROR_SUCCESS == 
                            m_pCtrlObject->m_proc_CanalBlockingSend ( m_pCtrlObject->m_openHandle, &canalMsg, 300 ) ) {

              eventReceive.SetClientData( pEvent );
              wxPostEvent( m_pCtrlObject->m_pWnd, eventReceive ); 

                  // Remove the node
                    m_pCtrlObject->m_outQueue.DeleteNode ( node );  
                }
                else {
                    // Give it another try
                    m_pCtrlObject->m_semOutQue.Post();
                }

            m_pCtrlObject->m_mutexOutQueue.Unlock();

          }

          if ( !bActivity ) {
            ::wxMilliSleep( 100 );
          }

          bActivity = false;

            } // while working - non blocking

        } // if blocking/non blocking

  } // not TCIP Driver

    // Close CANAL channel
    m_pCtrlObject->m_proc_CanalClose ( m_pCtrlObject->m_openHandle );

    // Library is unloaded in destructor

    if ( NULL != m_preceiveThread ) {
        m_preceiveThread->Wait();
        delete m_preceiveThread;
    }

    if ( NULL != m_pwriteThread ) {
        m_pwriteThread->Wait();
        delete m_pwriteThread;
    }

  wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );

    return NULL;
}
Example #28
0
// Main window creation
dlgMain::dlgMain(wxWindow* parent, wxWindowID id)
{
    wxFileConfig ConfigInfo;   
    wxInt32 WindowPosX, WindowPosY, WindowWidth, WindowHeight;
    wxString Version;

    // Loads the frame from the xml resource file
	wxXmlResource::Get()->LoadFrame(this, parent, wxT("dlgMain")); 
    
    // Sets the title of the application with a version string to boot
    Version = wxString::Format(
        wxT("The Odamex Launcher v%d.%d.%d"), 
        VERSIONMAJOR(VERSION), VERSIONMINOR(VERSION), VERSIONPATCH(VERSION));
    
    SetLabel(Version);
    
    // Sets the window size
    ConfigInfo.Read(wxT("MainWindowWidth"), 
                    &WindowWidth, 
                    GetClientSize().GetWidth());
                    
    ConfigInfo.Read(wxT("MainWindowHeight"), 
                    &WindowHeight, 
                    GetClientSize().GetHeight());
    
    SetClientSize(WindowWidth, WindowHeight);
    
    // Set Window position
    ConfigInfo.Read(wxT("MainWindowPosX"), 
                    &WindowPosX, 
                    0);
                    
    ConfigInfo.Read(wxT("MainWindowPosY"), 
                    &WindowPosY, 
                    0);
    
    Move(WindowPosX, WindowPosY);
    
    launchercfg_s.get_list_on_start = 1;
    launchercfg_s.show_blocked_servers = 1;
    launchercfg_s.wad_paths = wxGetCwd();
    launchercfg_s.odamex_directory = wxGetCwd();

    // Set up icons, this is a hack because wxwidgets does not have an xml
    // handler for wxIconBundle :(
    wxIconBundle IconBundle;
    
    IconBundle.AddIcon(wxXmlResource::Get()->LoadIcon(wxT("icon16x16x32")));
    IconBundle.AddIcon(wxXmlResource::Get()->LoadIcon(wxT("icon32x32x32")));
    IconBundle.AddIcon(wxXmlResource::Get()->LoadIcon(wxT("icon48x48x32")));
    IconBundle.AddIcon(wxXmlResource::Get()->LoadIcon(wxT("icon16x16x8")));
    IconBundle.AddIcon(wxXmlResource::Get()->LoadIcon(wxT("icon32x32x8")));
    
    SetIcons(IconBundle);
    
    m_LstCtrlServers = wxDynamicCast(FindWindow(Id_LstCtrlServers), LstOdaServerList);
    m_LstCtrlPlayers = wxDynamicCast(FindWindow(Id_LstCtrlPlayers), LstOdaPlayerList);
    m_LstOdaSrvDetails = wxDynamicCast(FindWindow(Id_LstCtrlServerDetails), LstOdaSrvDetails);

    m_LstCtrlServers->SetupServerListColumns();
    m_LstCtrlPlayers->SetupPlayerListColumns();

	// set up the master server information
    MServer.AddMaster(_T("master1.odamex.net"), 15000);
    MServer.AddMaster(_T("voxelsoft.com"), 15000);
    
    /* Init sub dialogs and load settings */
    config_dlg = new dlgConfig(&launchercfg_s, this);
    server_dlg = new dlgServers(&MServer, this);
    AboutDialog = new dlgAbout(this);
    
    /* Get the first directory for wad downloading */
    wxInt32 Pos = launchercfg_s.wad_paths.Find(wxT(PATH_DELIMITER), false);
    wxString FirstDirectory = launchercfg_s.wad_paths.Mid(0, Pos);
    
    OdaGet = new frmOdaGet(this, -1, FirstDirectory);
    
    QServer = NULL;

    // get master list on application start
    if (launchercfg_s.get_list_on_start)
    {
        wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, Id_MnuItmGetList);
    
        wxPostEvent(this, event);
    }
}
void wxTextCtrl::OnChar(wxKeyEvent& event)
{
    int key = event.GetKeyCode() ;
    bool eat_key = false ;
    long from, to;

    if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) &&
        !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
//        && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
        )
    {
        // eat it
        return ;
    }

    if ( !GetTextPeer()->CanClipMaxLength() )
    {
        // Check if we have reached the max # of chars (if it is set), but still
        // allow navigation and deletion
        GetSelection( &from, &to );
        if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength &&
            !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) &&
            !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) &&
            from == to )
        {
            // eat it, we don't want to add more than allowed # of characters

            // TODO: generate EVT_TEXT_MAXLEN()
            return;
        }
    }

    // assume that any key not processed yet is going to modify the control
    m_dirty = true;

    switch ( key )
    {
        case WXK_RETURN:
            if (m_windowStyle & wxTE_PROCESS_ENTER)
            {
                wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId);
                event.SetEventObject( this );
                event.SetString( GetValue() );
                if ( HandleWindowEvent(event) )
                    return;
            }

            if ( !(m_windowStyle & wxTE_MULTILINE) )
            {
                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
                if ( tlw && tlw->GetDefaultItem() )
                {
                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
                    if ( def && def->IsEnabled() )
                    {
                        wxCommandEvent event(wxEVT_BUTTON, def->GetId() );
                        event.SetEventObject(def);
                        def->Command(event);

                        return ;
                    }
                }

                // this will make wxWidgets eat the ENTER key so that
                // we actually prevent line wrapping in a single line text control
                eat_key = true;
            }
            break;

        case WXK_TAB:
            if ( !(m_windowStyle & wxTE_PROCESS_TAB))
            {
                int flags = 0;
                if (!event.ShiftDown())
                    flags |= wxNavigationKeyEvent::IsForward ;
                if (event.ControlDown())
                    flags |= wxNavigationKeyEvent::WinChange ;
                Navigate(flags);

                return;
            }
            else
            {
                // This is necessary (don't know why);
                // otherwise the tab will not be inserted.
                WriteText(wxT("\t"));
                eat_key = true;
            }
            break;

        default:
            break;
    }

    if (!eat_key)
    {
        // perform keystroke handling
        event.Skip(true) ;
    }

    // osx_cocoa sends its event upon insertText
#if wxOSX_USE_CARBON
    if ( ( key >= 0x20 && key < WXK_START ) ||
         ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) ||
         key == WXK_RETURN ||
         key == WXK_DELETE ||
         key == WXK_BACK)
    {
        wxCommandEvent event1(wxEVT_TEXT, m_windowId);
        event1.SetEventObject( this );
        wxPostEvent( GetEventHandler(), event1 );
    }
#endif
}
void *RPCThread::Entry() {
    int retval = 0;
    CRPCFinishedEvent RPC_done_event( wxEVT_RPC_FINISHED );
    ASYNC_RPC_REQUEST *current_request;
    double startTime = 0;
    wxMutexError mutexErr = wxMUTEX_NO_ERROR;
    wxCondError condErr = wxCOND_NO_ERROR;

#ifndef NO_PER_THREAD_LOCALE
#ifdef __WXMSW__
    // On Windows, set all locales for this thread on a per-thread basis
    _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
    setlocale(LC_ALL, "C");
#else
    // We initialize RPC_Thread_Locale to fix a compiler warning
    locale_t RPC_Thread_Locale = LC_GLOBAL_LOCALE;
#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4)
    if (uselocale)    // uselocale() is not available in Mac OS 10.3.9
#endif
    {
        // On Mac / Unix / Linux, set "C" locale for this thread only
        RPC_Thread_Locale = newlocale(LC_ALL_MASK, "C", NULL);
        uselocale(RPC_Thread_Locale);
    }
#endif      // ifndef __WXMSW__
#endif      // ifndef NO_PER_THREAD_LOCALE
   
    m_pRPC_Thread_Mutex->Lock();
    m_pDoc->m_bRPCThreadIsReady = true;
    while(true) {
        // Wait for main thread to wake us
        // This does the following:
        // (1) Unlocks the Mutex and puts the RPC thread to sleep as an atomic operation.
        // (2) On Signal from main thread: locks Mutex again and wakes the RPC thread.
        condErr = m_pRPC_Thread_Condition->Wait();
        wxASSERT(condErr == wxCOND_NO_ERROR);
        
        if (m_pDoc->m_bShutDownRPCThread) {
#if !defined(NO_PER_THREAD_LOCALE) && !defined(__WXMSW__)
#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4)
        if (uselocale)    // uselocale() is not available in Mac OS 10.3.9
#endif
        {
            uselocale(LC_GLOBAL_LOCALE);
            freelocale(RPC_Thread_Locale);
        }
#endif
            m_pRPC_Thread_Mutex->Unlock();  // Just for safety - not really needed
            // Tell CMainDocument that thread has gracefully ended 
            // We do this here because OnExit() is not called on Windows
            m_pDoc->m_RPCThread = NULL;
            return 0;
        }
        
        current_request = m_pDoc->GetCurrentRPCRequest();

        if (!current_request->isActive)  continue;       // Should never happen
        
        if (current_request->RPCExecutionTime) {
            startTime = dtime();
        }
        retval = ProcessRPCRequest();
        if (current_request->RPCExecutionTime) {
            *(current_request->RPCExecutionTime) = dtime() - startTime;
        }
        
        current_request->retval = retval;

        mutexErr = m_pRPC_Request_Mutex->Lock();
        wxASSERT(mutexErr == wxMUTEX_NO_ERROR);

        current_request->isActive = false;
        wxPostEvent( wxTheApp, RPC_done_event );

        // Signal() is ignored / discarded unless the main thread is 
        // currently blocked by m_pRPC_Request_Condition->Wait[Timeout]()
        m_pRPC_Request_Condition->Signal();
        
        mutexErr = m_pRPC_Request_Mutex->Unlock();
        wxASSERT(mutexErr == wxMUTEX_NO_ERROR);
    }

    return NULL;
}