Example #1
0
wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
{
    // location has Unix path separators
    wxString right = GetRightLocation(location);
    wxFileName fn = wxFileSystem::URLToFileName(right);
    wxString fullpath = ms_root + fn.GetFullPath();

    if (!wxFileExists(fullpath))
        return NULL;

    // we need to check whether we can really read from this file, otherwise
    // wxFSFile is not going to work
#if wxUSE_FFILE
    wxFFileInputStream *is = new wxFFileInputStream(fullpath);
#elif wxUSE_FILE
    wxFileInputStream *is = new wxFileInputStream(fullpath);
#else
#error One of wxUSE_FILE or wxUSE_FFILE must be set to 1 for wxFSHandler to work
#endif
    if ( !is->IsOk() )
    {
        delete is;
        return NULL;
    }

    return new wxFSFile(is,
                        location,
                        wxEmptyString,
                        GetAnchor(location)
#if wxUSE_DATETIME
                        ,wxDateTime(wxFileModificationTime(fullpath))
#endif // wxUSE_DATETIME
                        );
}
Example #2
0
void
SelectionToClipboard(HWND hWnd,LPEDIT lp)
{
	HGLOBAL hText;
	LPSTR 	lpText;
	int	TextSize;
	int	BegSpot;
	int	EndSpot;

	GetAnchor(lp, &BegSpot, &EndSpot) ;
	TextSize = EndSpot - BegSpot ;

	if ((TextSize == 0) || !AnchorSet(lp))
		return;

	if ((hText = GlobalAlloc(GMEM_MOVEABLE, TextSize*sizeof(char))) == (HGLOBAL)0)
		return;

	if ((lpText = (LPSTR)GlobalLock(hText)) == NULL)
	{
		GlobalFree(hText);
		return;
	}

	lstrcpyn (lpText, lp->npdata+BegSpot, TextSize);
	*(lpText + TextSize) = '\0';

	if (OpenClipboard(hWnd))
	{
		EmptyClipboard();
		SetClipboardData(CF_TEXT, hText);
		CloseClipboard();
	}

}
Example #3
0
wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
{
    // location has Unix path separators
    wxString right = GetRightLocation(location);
    wxFileName fn = wxFileSystem::URLToFileName(right);
    wxString fullpath = ms_root + fn.GetFullPath();

    if (!wxFileExists(fullpath))
        return (wxFSFile*) NULL;

    // we need to check whether we can really read from this file, otherwise
    // wxFSFile is not going to work
    wxFFileInputStream *is = new wxFFileInputStream(fullpath);
    if ( !is->Ok() )
    {
        delete is;
        return (wxFSFile*) NULL;
    }

    return new wxFSFile(is,
                        right,
                        GetMimeTypeFromExt(location),
                        GetAnchor(location)
#if wxUSE_DATETIME
                        ,wxDateTime(wxFileModificationTime(fullpath))
#endif // wxUSE_DATETIME
                        );
}
Example #4
0
ProjectView::ProjectView(GUIWindow &w,ViewData *data):FieldView(w,data) {

	lastClock_=0 ;
	lastTick_=0 ;

	project_=data->project_ ;

	GUIPoint position=GetAnchor() ;
	
	Variable *v=project_->FindVariable(VAR_TEMPO) ;
	UITempoField *f=new UITempoField(ACTION_TEMPO_CHANGED,position,*v,"tempo: %d [%2.2x]  ",60,400,1,10) ;
	T_SimpleList<UIField>::Insert(f) ;
	f->AddObserver(*this) ;
	tempoField_=f ;

	v=project_->FindVariable(VAR_MASTERVOL) ;
	position._y+=1 ;
	UIIntVarField *f1=new UIIntVarField(position,*v,"master: %d",10,200,1,10) ;
	T_SimpleList<UIField>::Insert(f1) ;

	v=project_->FindVariable(VAR_TRANSPOSE) ;
	position._y+=1 ;
	UIIntVarField *f2=new UIIntVarField(position,*v,"transpose: %3.2d",-48,48,0x1,0xC) ;
	T_SimpleList<UIField>::Insert(f2) ;

	position._y+=2 ;
	UIActionField *a1=new UIActionField("Compact Sequencer",ACTION_PURGE,position) ;
	a1->AddObserver(*this) ;
	T_SimpleList<UIField>::Insert(a1) ;

	position._y+=1 ;
	a1=new UIActionField("Compact Instruments",ACTION_PURGE_INSTRUMENT,position) ;
	a1->AddObserver(*this) ;
	T_SimpleList<UIField>::Insert(a1) ;

	position._y+=2 ;
	a1=new UIActionField("Load Song",ACTION_LOAD,position) ;
	a1->AddObserver(*this) ;
	T_SimpleList<UIField>::Insert(a1) ;

	position._y+=1 ;
	a1=new UIActionField("Save Song",ACTION_SAVE,position) ;
	a1->AddObserver(*this) ;
	T_SimpleList<UIField>::Insert(a1) ;

	v=project_->FindVariable(VAR_MIDIDEVICE) ;
	NAssert(v) ;
	position._y+=2 ;
	UIIntVarField *f3=new UIIntVarField(position,*v,"midi: %s",0,MidiService::GetInstance()->Size(),1,1) ;
	T_SimpleList<UIField>::Insert(f3) ;

	position._y+=2 ;
	a1=new UIActionField("Exit",ACTION_QUIT,position) ;
	a1->AddObserver(*this) ;
	T_SimpleList<UIField>::Insert(a1) ;

}
Example #5
0
wxFSFile* wxChmFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
                                   const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);

    wxInputStream *s;

    int index;

    if ( GetProtocol(left) != _T("file") )
    {
        wxLogError(_("CHM handler currently supports only local files!"));
        return NULL;
    }

    // Work around javascript
    wxString tmp = wxString(right);
    if ( tmp.MakeLower().Contains(_T("javascipt")) && tmp.Contains(_T("\'")) )
    {
        right = right.AfterFirst(_T('\'')).BeforeLast(_T('\''));
    }

    // now work on the right location
    if (right.Contains(_T("..")))
    {
        wxFileName abs(right);
        abs.MakeAbsolute(_T("/"));
        right = abs.GetFullPath();
    }

    // a workaround for absolute links to root
    if ( (index=right.Index(_T("//"))) != wxNOT_FOUND )
    {
        right=wxString(right.Mid(index+1));
        wxLogWarning(_("Link contained '//', converted to absolute link."));
    }

    wxFileName leftFilename = wxFileSystem::URLToFileName(left);

    // Open a stream to read the content of the chm-file
    s = new wxChmInputStream(leftFilename.GetFullPath(), right, true);

    wxString mime = GetMimeTypeFromExt(location);

    if ( s )
    {
        return new wxFSFile(s,
                            left + _T("#chm:") + right,
                            mime,
                            GetAnchor(location),
                            wxDateTime(wxFileModificationTime(left)));
    }

    delete s;
    return NULL;
}
void viewInfo::SetGlViewTo() const
{
	// this->GetAnchor()
	// in OpenGL, up is +Y and look is -Z (left is +X)
	// in my conventions, up is +Z and look is +X (left is +Y)
	mdsVector<3, double> eyePos = GetPosition();
	mdsVector<3, double> upDir = GetUpDir();
	// glTranslated(-viewPos.x(), -viewPos.y(), -viewPos.z());
	
	gluLookAt(GetPosition()[0], GetPosition()[1], GetPosition()[2],
		GetAnchor()[0], GetAnchor()[1], GetAnchor()[2],
		GetUpDir()[0], GetUpDir()[1], GetUpDir()[2]);

	// glTranslated(-viewPos.y(), -viewPos.z(), viewPos.x());
	// mdsVector<3, double> 
	// glTranslated(viewPos.x(), viewPos.y(), viewPos.z());
	// glTranslated(0.0, 0.0, m_viewOffset[0]);

}
Example #7
0
result_t CYamlScalar::SaveToFile ( yaml_emitter_t* _pEmitter ) const
{
    result_t result_t = eResult_OK;

    yaml_event_t event;

    yaml_scalar_event_initialize ( &event, (yaml_char_t*)GetAnchor(), (yaml_char_t*)GetTag(), (yaml_char_t*)GetValue(), int(m_Value.Size()), 1, 0, CYamlScalar::ToYamlStyle(m_Style) );
    ex_check_return ( Flush( _pEmitter, &event ), "Flush failed" );

    return eResult;
}
Example #8
0
void OutputCtrl::OnCopy( wxCommandEvent& event )
{
   if ( GetCurrentPos() != GetAnchor() )
      Copy();

   else if ( wxTheClipboard->Open() ) 
   {
      wxASSERT( m_Selected != -1 );
      wxTheClipboard->SetData( new wxTextDataObject( GetLine( m_Selected ) ) );
      wxTheClipboard->Close();
   }
}
Example #9
0
void CControl::UpdateQuadP()
{
    const CVec2& realSize = GetRealSize();
    CVec2 anchorPos = GetAnchor() * realSize;

    //set vertex
    m_quadp.tl = CVec3(-anchorPos);
    m_quadp.br = CVec3(realSize - anchorPos);
    m_quadp.tr.x = m_quadp.br.x;
    m_quadp.tr.y = m_quadp.tl.y;
    m_quadp.bl.x = m_quadp.tl.x;
    m_quadp.bl.y = m_quadp.br.y;
}
Example #10
0
wxFSFile* wxZipFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);
    wxZipInputStream *s;

    if (right.Contains(wxT("./")))
    {
        if (right.GetChar(0) != wxT('/')) right = wxT('/') + right;
        wxFileName rightPart(right, wxPATH_UNIX);
        rightPart.Normalize(wxPATH_NORM_DOTS, wxT("/"), wxPATH_UNIX);
        right = rightPart.GetFullPath(wxPATH_UNIX);
    }

    if (right.GetChar(0) == wxT('/')) right = right.Mid(1);

    // a new wxFileSystem object is needed here to avoid infinite recursion
    wxFSFile *leftFile = wxFileSystem().OpenFile(left);
    if (!leftFile)
       return NULL;

    s = new wxZipFSInputStream(leftFile);
    if (s && s->IsOk())
    {
       bool found = false;
       while (!found)
       {
           wxZipEntry *ent = s->GetNextEntry();
           if (!ent)
               break;
           if (ent->GetInternalName() == right)
               found = true;
           delete ent;
       }
       if (found)
           return new wxFSFile(s,
                            left + wxT("#zip:") + right,
                            GetMimeTypeFromExt(location),
                            GetAnchor(location)
#if wxUSE_DATETIME
                            , wxDateTime(wxFileModificationTime(left))
#endif // wxUSE_DATETIME
                            );
    }

    delete s;
    return NULL;
}
Example #11
0
wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
                                        const wxString& location)
{
#if !wxUSE_URL
    return NULL;
#else
    wxString right =
        GetProtocol(location) + wxT(":") + StripProtocolAnchor(location);

    wxURL url(right);
    if (url.GetError() == wxURL_NOERR)
    {
        wxInputStream *s = url.GetInputStream();
        if (s)
        {
            wxString tmpfile =
                wxFileName::CreateTempFileName(wxT("wxhtml"));

            {   // now copy streams content to temporary file:
                wxFileOutputStream sout(tmpfile);
                s->Read(sout);
            }
            delete s;

            // Content-Type header, as defined by the RFC 2045, has the form of
            // "type/subtype" optionally followed by (multiple) "; parameter"
            // and we need just the MIME type here.
            const wxString& content = url.GetProtocol().GetContentType();
            wxString mimetype = content.BeforeFirst(';');
            mimetype.Trim();

            return new wxFSFile(new wxTemporaryFileInputStream(tmpfile),
                                right,
                                mimetype,
                                GetAnchor(location)
#if wxUSE_DATETIME
                                , wxDateTime::Now()
#endif // wxUSE_DATETIME
                        );
        }
    }

    return NULL; // incorrect URL
#endif
}
Example #12
0
wxFSFile* wxFilterFSHandler::OpenFile(
        wxFileSystem& fs,
        const wxString& location)
{
    wxString right = GetRightLocation(location);
    if (!right.empty())
        return NULL;

    wxString protocol = GetProtocol(location);
    const wxFilterClassFactory *factory = wxFilterClassFactory::Find(protocol);
    if (!factory)
        return NULL;

    wxString left = GetLeftLocation(location);
    wxFSFilePtr leftFile(fs.OpenFile(left));
    if (!leftFile.get())
        return NULL;

    wxInputStreamPtr leftStream(leftFile->DetachStream());
    if (!leftStream.get() || !leftStream->IsOk())
        return NULL;

    wxInputStreamPtr stream(factory->NewStream(leftStream.release()));

    // The way compressed streams are supposed to be served is e.g.:
    //  Content-type: application/postscript
    //  Content-encoding: gzip
    // So the mime type should be just the mime type of the lhs. However check
    // whether the mime type is that of this compression format (e.g.
    // application/gzip). If so pop any extension and try GetMimeTypeFromExt,
    // e.g. if it were '.ps.gz' pop the '.gz' and try looking up '.ps'
    wxString mime = leftFile->GetMimeType();
    if (factory->CanHandle(mime, wxSTREAM_MIMETYPE))
        mime = GetMimeTypeFromExt(factory->PopExtension(left));

    return new wxFSFile(stream.release(),
                        left + wxT("#") + protocol + wxT(":") + right,
                        mime,
                        GetAnchor(location)
#if wxUSE_DATETIME
                        , leftFile->GetModificationTime()
#endif // wxUSE_DATETIME
                       );
}
Example #13
0
wxFSFile * wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs),
                                           const wxString& location)
{
    wxMemoryFSHash::const_iterator i = m_Hash.find(GetRightLocation(location));
    if ( i == m_Hash.end() )
        return NULL;

    const wxMemoryFSFile * const obj = i->second;

    return new wxFSFile
               (
                    new wxMemoryInputStream(obj->m_Data, obj->m_Len),
                    location,
                    obj->m_MimeType,
                    GetAnchor(location)
#if wxUSE_DATETIME
                    , obj->m_Time
#endif // wxUSE_DATETIME
               );
}
Example #14
0
wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
                                        const wxString& location)
{
#if !wxUSE_URL
    return NULL;
#else
    wxString right =
        GetProtocol(location) + wxT(":") + StripProtocolAnchor(location);

    wxURL url(right);
    if (url.GetError() == wxURL_NOERR)
    {
        wxInputStream *s = url.GetInputStream();
        wxString content = url.GetProtocol().GetContentType();
        if (content == wxEmptyString) content = GetMimeTypeFromExt(location);
        if (s)
        {
            wxString tmpfile =
                wxFileName::CreateTempFileName(wxT("wxhtml"));

            {   // now copy streams content to temporary file:
                wxFileOutputStream sout(tmpfile);
                s->Read(sout);
            }
            delete s;

            return new wxFSFile(new wxTemporaryFileInputStream(tmpfile),
                                right,
                                content,
                                GetAnchor(location)
#if wxUSE_DATETIME
                                , wxDateTime::Now()
#endif // wxUSE_DATETIME
                        );
        }
    }

    return (wxFSFile*) NULL; // incorrect URL
#endif
}
Example #15
0
 wxString Anchor(const wxString& p) { return GetAnchor(p); }
Example #16
0
wxFSFile* wxArchiveFSHandler::OpenFile(
        wxFileSystem& WXUNUSED(fs),
        const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);
    wxString protocol = GetProtocol(location);
    wxString key = left + wxT("#") + protocol + wxT(":");

    if (right.Contains(wxT("./")))
    {
        if (right.GetChar(0) != wxT('/')) right = wxT('/') + right;
        wxFileName rightPart(right, wxPATH_UNIX);
        rightPart.Normalize(wxPATH_NORM_DOTS, wxT("/"), wxPATH_UNIX);
        right = rightPart.GetFullPath(wxPATH_UNIX);
    }

    if (right.GetChar(0) == wxT('/')) right = right.Mid(1);

    if (!m_cache)
        m_cache = new wxArchiveFSCache;

    const wxArchiveClassFactory *factory;
    factory = wxArchiveClassFactory::Find(protocol);
    if (!factory)
        return NULL;

    wxArchiveFSCacheData *cached = m_cache->Get(key);
    if (!cached)
    {
        wxFSFile *leftFile = m_fs.OpenFile(left);
        if (!leftFile)
            return NULL;
        cached = m_cache->Add(key, *factory, leftFile->DetachStream());
        delete leftFile;
    }

    wxArchiveEntry *entry = cached->Get(right);
    if (!entry)
        return NULL;

    wxInputStream *leftStream = cached->NewStream();
    if (!leftStream)
    {
        wxFSFile *leftFile = m_fs.OpenFile(left);
        if (!leftFile)
            return NULL;
        leftStream = leftFile->DetachStream();
        delete leftFile;
    }

    wxArchiveInputStream *s = factory->NewStream(leftStream);
    if ( !s )
        return NULL;

    s->OpenEntry(*entry);

    if (!s->IsOk())
    {
        delete s;
        return NULL;
    }

#if WXWIN_COMPATIBILITY_2_6 && wxUSE_ZIPSTREAM
    if (factory->IsKindOf(CLASSINFO(wxZipClassFactory)))
        ((wxZipInputStream*)s)->m_allowSeeking = true;
#endif // WXWIN_COMPATIBILITY_2_6

    return new wxFSFile(s,
                        key + right,
                        wxEmptyString,
                        GetAnchor(location)
#if wxUSE_DATETIME
                        , entry->GetDateTime()
#endif // wxUSE_DATETIME
                        );
}
Example #17
0
void OutputCtrl::OnUpdateCopy( wxUpdateUIEvent& event )
{
   event.Enable( GetCurrentPos() != GetAnchor() || m_Selected != -1 );
}
Example #18
0
void OutputCtrl::AppendText( const wxString& text )
{
   SetReadOnly( false );

   bool scrollEnd = false;
   int pos = GetLength();
   if (  GetCurrentPos() == pos && 
         GetAnchor() == pos )
      scrollEnd = true;

   // For each line...
   const wxChar* ptr = text.c_str();
   const wxChar* const end = ptr + text.Length();
   const wxChar* next;

   wxString line;
   bool isError = false;
   bool isWarn = false;

   //wxTextAttr errorStyle( *wxRED, *wxWHITE ); 
   //wxTextAttr warnStyle( *wxRED, *wxWHITE ); //wxColour( 255, 128, 0 ), *wxWHITE ); 
   long lnumb;

   while( ptr != end )
   {
      wxASSERT( ptr < end );
      next = std::find( ptr, end, '\n' );
      if ( next != end ) ++next;
      line.assign( ptr, next );
      ptr = next;

      // Look for error lines and highlight them...
      //
      // TODO: I need to optimize the regex here... maybe i 
      // shouldn't use a regex, but use my own logic to spot
      // errors... could be much faster.
      //
      if ( m_ErrorExpr.Matches( line ) && m_ErrorExpr.GetMatchCount() > 3 )
         isError = true;
      else if ( m_WarnExpr.Matches( line ) && m_ErrorExpr.GetMatchCount() > 3 )
         isWarn = true;

      pos = GetLength();
      SetTargetStart( pos );
      SetTargetEnd( pos );
      ReplaceTarget( line );

      if ( isError ) 
      {
         StartStyling( pos, 0xFF );
         SetStyling( line.Len(), 2 );

         // TODO: SetStyle will screw with the current scroll position.  The
         // trick is to disable ECO_AUTOVSCROLL and ECO_AUTOHSCROLL before
         // changing the selection to change the style.  We need to submit this
         // fix back to wxWindows.
         //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL );
         //SetStyle( start, last, errorStyle );
         //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL );

         // Add the error to the debugger state.
         m_ErrorExpr.GetMatch( line, 2 ).ToLong( &lnumb );

         ScriptError* error = new ScriptError;
         error->file = m_ErrorExpr.GetMatch( line, 1 );
         error->line = lnumb;
         error->start = pos;
         error->end = pos + line.Len();
         error->row = LineFromPosition( pos );
         error->error = m_ErrorExpr.GetMatch( line, 3 );
         error->error.Trim();
         error->warning = false;
         AddError( error );

         isError = false;
      } 
      else if ( isWarn ) 
      {
         StartStyling( pos, 0xFF );
         SetStyling( line.Len(), 2 );

         // TODO: SetStyle will screw with the current scroll position.  The
         // trick is to disable ECO_AUTOVSCROLL and ECO_AUTOHSCROLL before
         // changing the selection to change the style.  We need to submit this
         // fix back to wxWindows.
         //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL );
         //SetStyle( start, last, warnStyle );
         //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL );

         // Add the error to the debugger state.
         m_WarnExpr.GetMatch( line, 2 ).ToLong( &lnumb );

         ScriptError* error = new ScriptError;
         error->file = m_WarnExpr.GetMatch( line, 1 );
         error->line = lnumb;
         error->start = pos;
         error->end = pos + line.Len();
         error->row = LineFromPosition( pos );
         error->error = m_WarnExpr.GetMatch( line, 3 );
         error->error.Trim();
         error->warning = true;
         AddError( error );

         isWarn = false;
      }
   }

   if ( scrollEnd )
   {
      const int endPos = GetLength();
      SetAnchor( endPos );
      SetCurrentPos( endPos );
      ShowLine( LineFromPosition( endPos ) );
   }

   EmptyUndoBuffer();

   SetReadOnly( true );
}
Example #19
0
void CControl::GetAnchorPosition( float& x, float& y )
{
    x = GetAnchor().x * GetRealSize().x;
    y = GetAnchor().y * GetRealSize().y;
}