Esempio n. 1
0
void wxMenuToHMenu(wxMenu* in, HMENU hMenu)
{
    if(!in) return;

    wxChar buf[256];

    wxMenuItemList::compatibility_iterator node = in->GetMenuItems().GetFirst();
    while ( node )
    {
        wxMenuItem *item = node->GetData();

        UINT uFlags = 0;
        UINT uIDNewItem;
        LPCTSTR lpNewItem;

        if( item->IsSeparator() )
        {
            uFlags |= MF_SEPARATOR;
            uIDNewItem = (unsigned)wxID_ANY;
            lpNewItem = NULL;
        }
        else
        {
            // label
            uFlags |= MF_STRING;
            wxStrcpy(buf, item->GetLabel().c_str());
            lpNewItem = buf;

            // state
            uFlags |= ( item->IsEnabled() ? MF_ENABLED : MF_GRAYED );

            // checked
            uFlags |= ( item->IsChecked() ? MF_CHECKED : MF_UNCHECKED );

            if( item->IsSubMenu() )
            {
                uFlags |= MF_POPUP;
                HMENU hSubMenu = CreatePopupMenu();
                wxMenuToHMenu(item->GetSubMenu(), hSubMenu);
                uIDNewItem = (UINT) hSubMenu;
            }
            else
            {
                uIDNewItem = item->GetId();
            }
        }

        AppendMenu(hMenu, uFlags, uIDNewItem, lpNewItem);

        node = node->GetNext();
    }
}
Esempio n. 2
0
// Get a temporary filename, opening and closing the file.
wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf)
{
    wxString filename;
    if ( !wxGetTempFileName(prefix, filename) )
        return NULL;

    if ( buf )
        wxStrcpy(buf, filename);
    else
        buf = MYcopystring(filename);

    return buf;
}
Esempio n. 3
0
// Return just the directory, or NULL if no directory
wxString wxPathOnly (const wxString& path)
{
    if (!path.empty())
    {
        wxChar buf[_MAXPATHLEN];

        int l = path.length();
        int i = l - 1;

        if ( i >= _MAXPATHLEN )
            return wxString();

        // Local copy
        wxStrcpy(buf, path);

        // Search backward for a backward or forward slash
        while (i > -1)
        {
            // Unix like or Windows
            if (path[i] == wxT('/') || path[i] == wxT('\\'))
            {
                // Don't return an empty string
                if (i == 0)
                    i ++;
                buf[i] = 0;
                return wxString(buf);
            }
#ifdef __VMS__
            if (path[i] == wxT(']'))
            {
                buf[i+1] = 0;
                return wxString(buf);
            }
#endif
            i --;
        }

#if defined(__WINDOWS__)
        // Try Drive specifier
        if (wxIsalpha (buf[0]) && buf[1] == wxT(':'))
        {
            // A:junk --> A:. (since A:.\junk Not A:\junk)
            buf[2] = wxT('.');
            buf[3] = wxT('\0');
            return wxString(buf);
        }
#endif
    }
    return wxEmptyString;
}
Esempio n. 4
0
bool CVolumeDescriptionEnumeratorThread::GetDrive(const wxChar* pDrive, const int len)
{
	wxChar* pVolume = new wxChar[len + 1];
	wxStrcpy(pVolume, pDrive);
	if (pVolume[len - 1] == '\\')
		pVolume[len - 1] = 0;
	if (!*pVolume)
	{
		delete [] pVolume;
		return false;
	}

	// Check if it is a network share
	wxChar *share_name = new wxChar[512];
	DWORD dwSize = 511;
	if (!WNetGetConnection(pVolume, share_name, &dwSize))
	{
		m_crit_section.Enter();
		t_VolumeInfoInternal volumeInfo;
		volumeInfo.pVolume = pVolume;
		volumeInfo.pVolumeName = share_name;
		m_volumeInfo.push_back(volumeInfo);
		m_crit_section.Leave();
		pDrive += len + 1;
		return true;
	}
	else
		delete [] share_name;

	// Get the label of the drive
	wxChar* pVolumeName = new wxChar[501];
	int oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
	BOOL res = GetVolumeInformation(pDrive, pVolumeName, 500, 0, 0, 0, 0, 0);
	SetErrorMode(oldErrorMode);
	if (res && pVolumeName[0])
	{
		m_crit_section.Enter();
		t_VolumeInfoInternal volumeInfo;
		volumeInfo.pVolume = pVolume;
		volumeInfo.pVolumeName = pVolumeName;
		m_volumeInfo.push_back(volumeInfo);
		m_crit_section.Leave();
		return true;
	}

	delete [] pVolumeName;
	delete [] pVolume;

	return false;
}
Esempio n. 5
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;
}
Esempio n. 6
0
int wxComboBox::DoInsert(const wxString& item, unsigned int pos)
{
    wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
    wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index"));

    if (pos == GetCount())
        return DoAppend(item);

    wxXmString str( item.c_str() );
    XmComboBoxAddItem((Widget) m_mainWidget, str(), pos+1);
    wxChar* copy = wxStrcpy(new wxChar[item.length() + 1], item.c_str());
    m_stringList.Insert(pos, copy);
    m_noStrings ++;

    return pos;
}
Esempio n. 7
0
// Return just the directory, or NULL if no directory
wxChar *
wxPathOnly (wxChar *path)
{
    if (path && *path)
    {
        static wxChar buf[_MAXPATHLEN];

        int l = wxStrlen(path);
        int i = l - 1;
        if ( i >= _MAXPATHLEN )
            return NULL;

        // Local copy
        wxStrcpy (buf, path);

        // Search backward for a backward or forward slash
        while (i > -1)
        {
            // Unix like or Windows
            if (path[i] == wxT('/') || path[i] == wxT('\\'))
            {
                buf[i] = 0;
                return buf;
            }
#ifdef __VMS__
            if (path[i] == wxT(']'))
            {
                buf[i+1] = 0;
                return buf;
            }
#endif
            i --;
        }

#if defined(__WINDOWS__)
        // Try Drive specifier
        if (wxIsalpha (buf[0]) && buf[1] == wxT(':'))
        {
            // A:junk --> A:. (since A:.\junk Not A:\junk)
            buf[2] = wxT('.');
            buf[3] = wxT('\0');
            return buf;
        }
#endif
    }
    return NULL;
}
Esempio n. 8
0
bool CIOThread::DoWrite(const char* pBuffer, int len)
{
	int fd = m_pFile->fd();
	if (wxWrite(fd, pBuffer, len) == len)
		return true;

	int code = wxSysErrorCode();

	const wxString error = wxSysErrorMsg(code);

	wxMutexLocker locker(m_mutex);
	delete [] m_error_description;
	m_error_description = new wxChar[error.Len() + 1];
	wxStrcpy(m_error_description, error);

	return false;
}
Esempio n. 9
0
//----------------------------------------------------------------------------------------
wxDbColInf* BrowserDB::OnGetColumns(wxChar *tableName, UWORD numCols, int WXUNUSED(Quiet))
{
    wxChar UName[255];
    int i;
    wxStrcpy(UName,UserName);
    cl_BrowserDB = db_BrowserDB->GetColumns(tableName,&numCols,UName);
//    cl_BrowserDB->pColFor = new wxDbColFor[numCols];
    for (i=0; i<numCols; i++)
    {
//        (cl_BrowserDB->pColFor+i)->Format(1,(cl_BrowserDB+i)->dbDataType,(cl_BrowserDB+i)->sqlDataType,
//            (cl_BrowserDB+i)->columnSize, (cl_BrowserDB+i)->decimalDigits);
        (cl_BrowserDB+i)->pColFor = new wxDbColFor;
        (cl_BrowserDB+i)->pColFor->Format(1,
                                          (cl_BrowserDB+i)->dbDataType,
                                          (cl_BrowserDB+i)->sqlDataType,
                                          (cl_BrowserDB+i)->columnLength,
                                          (cl_BrowserDB+i)->decimalDigits);
    }
    return cl_BrowserDB;
}
Esempio n. 10
0
// Insert an item
bool wxTabCtrl::InsertItem(int item, const wxString& text, int imageId, void* data)
{
    wxChar buf[256];
    TC_ITEM tcItem;
    tcItem.mask = TCIF_PARAM;
    tcItem.lParam = (long) data;
    if (!text.empty())
    {
        tcItem.mask |= TCIF_TEXT;
        wxStrcpy(buf, (const wxChar*) text);
        tcItem.pszText = buf;
        tcItem.cchTextMax = 256;
    }
    if (imageId != -1)
    {
        tcItem.mask |= TCIF_IMAGE;
        tcItem.iImage = imageId;
    }

    return (TabCtrl_InsertItem( (HWND) GetHWND(), item, & tcItem) != -1);
}
Esempio n. 11
0
void wxTopLevelWindowMSW::ReloadButton(ButtonMenu& button, UINT menuID)
{
    TBBUTTONINFO  button_info;
    wxChar        buf[256];

    // set button name
    memset (&button_info, 0, sizeof (TBBUTTONINFO));
    button_info.cbSize = sizeof(TBBUTTONINFO);
    button_info.dwMask = TBIF_TEXT | TBIF_STATE;
    button_info.fsState = TBSTATE_ENABLED;
    wxStrcpy(buf, button.GetLabel().c_str());
    button_info.pszText = buf;
    ::SendMessage(m_MenuBarHWND, TB_SETBUTTONINFO, menuID, (LPARAM) &button_info);

    if(button.IsMenu())
    {
        HMENU hPopupMenu = (HMENU) ::SendMessage(m_MenuBarHWND, SHCMBM_GETSUBMENU, 0, menuID);
        RemoveMenu(hPopupMenu, 0, MF_BYPOSITION);
        wxMenuToHMenu(button.GetMenu(), hPopupMenu);
    }
}
Esempio n. 12
0
void
PathFinder::AddPaths(const String & ipathlist, bool recursive, bool prepend)
{
    char *work = new char[ipathlist.length()+1];
    char   *found, *save_ptr;
    String   tmp;
    String   subdirList = wxEmptyString;

    MOcheck();
    wxStrcpy(work,ipathlist.c_str());
    found = wxStrtok(work, PATHFINDER_DELIMITER, &save_ptr);

    while(found)
    {
        if(prepend)
            pathList.push_front(found);
        else
            pathList.push_back(found);
        if(recursive && IsDir(found))   // look for subdirectories
        {
            tmp = String(found) + ANYFILE;
            wxString nextfile = wxFindFirstFile(tmp.c_str(), wxDIR);
            while ( !nextfile.empty() )
            {
                if(IsDir(nextfile))
                {
                    if(subdirList.length() > 0)
                        subdirList += _T(":");
                    subdirList = subdirList + String(nextfile);
                }
                nextfile = wxFindNextFile();
            }
        }
        found = wxStrtok(NULL, PATHFINDER_DELIMITER, &save_ptr);
    }
    delete[] work;
    if(subdirList.length() > 0)
        AddPaths(subdirList, recursive);
}
Esempio n. 13
0
wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out)
{
#if wxUSE_MENUS
    wxString s = wxMenuItem::GetLabelFromText(in);
#else
    wxString str(in);
    wxString s = wxStripMenuCodes(str);
#endif // wxUSE_MENUS
    if ( out )
    {
        // go smash their buffer if it's not big enough - I love char * params
        memcpy(out, s.c_str(), s.length() * sizeof(wxChar));
    }
    else
    {
        // MYcopystring - for easier search...
        out = new wxChar[s.length() + 1];
        wxStrcpy(out, s.c_str());
    }

    return out;
}
Esempio n. 14
0
bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file )
{
    wxString filename( file );
    if (filename.empty()) filename = wxT(".wxWindows");

    wxFileConfig conf( wxTheApp->GetAppName(), wxTheApp->GetVendorName(), filename );

    conf.SetPath( section );

    wxString result;
    if (conf.Read( entry, &result ))
    {
        if (!result.empty())
        {
            wxChar *s = new wxChar[result.Len()+1];
            wxStrcpy( s, result.c_str() );
            *value = s;
            return true;
        }
    }

    return false;
}
void CState::HandleDroppedFiles(const wxFileDataObject* pFileDataObject, const CLocalPath& path, bool copy)
{
	const wxArrayString &files = pFileDataObject->GetFilenames();
	if (!files.Count())
		return;

#ifdef __WXMSW__
	int len = 1;

	for (unsigned int i = 0; i < files.Count(); i++)
		len += files[i].Len() + 1;

	// SHFILEOPSTRUCT's pTo and pFrom accept null-terminated lists
	// of null-terminated filenames.
	wxChar* from = new wxChar[len];
	wxChar* p = from;
	for (unsigned int i = 0; i < files.Count(); i++)
	{
		wxStrcpy(p, files[i]);
		p += files[i].Len() + 1;
	}
	*p = 0; // End of list

	wxChar* to = new wxChar[path.GetPath().Len() + 2];
	wxStrcpy(to, path.GetPath());
	to[path.GetPath().Len() + 1] = 0; // End of list

	SHFILEOPSTRUCT op = {0};
	op.pFrom = from;
	op.pTo = to;
	op.wFunc = copy ? FO_COPY : FO_MOVE;
	op.hwnd = (HWND)m_pMainFrame->GetHandle();
	SHFileOperation(&op);

	delete [] to;
	delete [] from;
#else
	wxString error;
	for (unsigned int i = 0; i < files.Count(); i++)
	{
		const wxString& file(files[i]);

		int64_t size;
		bool is_link;
		CLocalFileSystem::local_fileType type = CLocalFileSystem::GetFileInfo(file, is_link, &size, 0, 0);
		if (type == CLocalFileSystem::file)
		{
			wxString name;
			CLocalPath sourcePath(file, &name);
			if (name.empty())
				continue;
			wxString target = path.GetPath() + name;
			if (file == target)
				continue;

			if (copy)
				wxCopyFile(file, target);
			else
				wxRenameFile(file, target);
		}
		else if (type == CLocalFileSystem::dir)
		{
			CLocalPath sourcePath(file);
			if (sourcePath == path || sourcePath.GetParent() == path)
				continue;
			if (sourcePath.IsParentOf(path))
			{
				error = _("A directory cannot be dragged into one of its subdirectories.");
				continue;
			}

			if (copy)
				RecursiveCopy(sourcePath, path);
			else
			{
				if (!sourcePath.HasParent())
					continue;
				wxRenameFile(file, path.GetPath() + sourcePath.GetLastSegment());
			}
		}
	}
	if (!error.empty())
		wxMessageBoxEx(error, _("Could not complete operation"));
#endif

	RefreshLocal();
}
Esempio n. 16
0
int wxFileDialog::ShowModal()
{
    wxString                        sTheFilter;
    wxString                        sFilterBuffer;
    wxChar*                         pzFilterBuffer;
    static wxChar                   zFileNameBuffer[wxMAXPATH];           // the file-name
    HWND                            hWnd = 0;
    wxChar                          zTitleBuffer[wxMAXFILE + 1 + wxMAXEXT];  // the file-name, without path
    wxString                        sDir;
    size_t                          i;
    size_t                          nLen = m_dir.length();
    int                             nCount = 0;
    FILEDLG                         vFileDlg;
    ULONG                           lFlags = 0L;

    memset(&vFileDlg, '\0', sizeof(FILEDLG));
    if (m_parent)
        hWnd = (HWND) m_parent->GetHWND();
    if (!hWnd && wxTheApp->GetTopWindow())
        hWnd = (HWND) wxTheApp->GetTopWindow()->GetHWND();


    *zFileNameBuffer = wxT('\0');
    *zTitleBuffer    = wxT('\0');

    if (m_dialogStyle & wxSAVE)
        lFlags = FDS_SAVEAS_DIALOG;
    else
        lFlags = FDS_OPEN_DIALOG;

#if WXWIN_COMPATIBILITY_2_4
    if (m_dialogStyle & wxHIDE_READONLY)
        lFlags |= FDS_SAVEAS_DIALOG;
#endif

    if (m_dialogStyle & wxSAVE)
        lFlags |= FDS_SAVEAS_DIALOG;
    if (m_dialogStyle & wxMULTIPLE )
        lFlags |= FDS_OPEN_DIALOG | FDS_MULTIPLESEL;

    vFileDlg.cbSize = sizeof(FILEDLG);
    vFileDlg.fl = lFlags;
    vFileDlg.pszTitle = (PSZ)zTitleBuffer;

    //
    // Convert forward slashes to backslashes (file selector doesn't like
    // forward slashes) and also squeeze multiple consecutive slashes into one
    // as it doesn't like two backslashes in a row neither
    //
    sDir.reserve(nLen);
    for ( i = 0; i < nLen; i++ )
    {
        wxChar                      ch = m_dir[i];

        switch (ch)
        {
            case _T('/'):
                //
                // Convert to backslash
                //
                ch = _T('\\');

                //
                // Fall through
                //
            case _T('\\'):
                while (i < nLen - 1)
                {
                    wxChar          chNext = m_dir[i + 1];

                    if (chNext != _T('\\') && chNext != _T('/'))
                        break;

                    //
                    // Ignore the next one, unless it is at the start of a UNC path
                    //
                    if (i > 0)
                        i++;
                    else
                        break;
                }

                //
                // Fall through
                //

            default:
                //
                // Normal char
                sDir += ch;
        }
    }
    if ( wxStrlen(m_wildCard) == 0 )
        sTheFilter = wxEmptyString;
    else
        sTheFilter = m_wildCard;

    wxStrtok((wxChar*)sTheFilter.c_str(), wxT("|"), &pzFilterBuffer);
    while(pzFilterBuffer != NULL)
    {
        if (nCount > 0 && !(nCount % 2))
            sDir += wxT(";");
        if (nCount % 2)
        {
            sDir += pzFilterBuffer;
        }
        wxStrtok(NULL, wxT("|"), &pzFilterBuffer);
        nCount++;
    }
    if (nCount == 0)
        sDir += m_fileName;
    if (sDir.empty())
        sDir = wxT("*.*");
    wxStrcpy((wxChar*)vFileDlg.szFullFile, sDir);
    sFilterBuffer = sDir;

    hWnd = ::WinFileDlg( HWND_DESKTOP
                        ,GetHwndOf(m_parent)
                        ,&vFileDlg
                       );
    if (hWnd && vFileDlg.lReturn == DID_OK)
    {
        m_fileNames.Empty();
        if ((m_dialogStyle & wxMULTIPLE ) && vFileDlg.ulFQFCount > 1)
        {
            for (int i = 0; i < (int)vFileDlg.ulFQFCount; i++)
            {
                if (i == 0)
                {
                    m_dir = wxPathOnly(wxString((const wxChar*)*vFileDlg.papszFQFilename[0]));
                    m_path = (const wxChar*)*vFileDlg.papszFQFilename[0];
                }
                m_fileName = wxFileNameFromPath(wxString((const wxChar*)*vFileDlg.papszFQFilename[i]));
                m_fileNames.Add(m_fileName);
            }
            ::WinFreeFileDlgList(vFileDlg.papszFQFilename);
        }
        else if (!(m_dialogStyle & wxSAVE))
        {
            m_path = (wxChar*)vFileDlg.szFullFile;
            m_fileName = wxFileNameFromPath(wxString((const wxChar*)vFileDlg.szFullFile));
            m_dir = wxPathOnly((const wxChar*)vFileDlg.szFullFile);
        }
        else // save file
        {
            const wxChar*           pzExtension = NULL;

            wxStrcpy(zFileNameBuffer, (const wxChar*)vFileDlg.szFullFile);

            int                     nIdx = wxStrlen(zFileNameBuffer) - 1;
            wxString                sExt;

            wxSplitPath( zFileNameBuffer
                        ,&m_path
                        ,&m_fileName
                        ,&sExt
                       );
            if (zFileNameBuffer[nIdx] == wxT('.') || sExt.empty())
            {
                zFileNameBuffer[nIdx] = wxT('\0');

                //
                // User has typed a filename without an extension:
                //
                // A filename can end in a "." here ("abc."), this means it
                // does not have an extension. Because later on a "." with
                // the default extension is appended we remove the "." if
                // filename ends with one (We don't want files called
                // "abc..ext")
                //
                pzExtension = sFilterBuffer.c_str();

                for( int i = 0; i < (int)sFilterBuffer.length(); i++ )
                {
                    //
                    // Get extension
                    //
                    pzExtension = wxStrrchr(pzExtension, wxT('.'));
                    if ( pzExtension                      &&
                        !wxStrrchr(pzExtension, wxT('*')) &&
                        !wxStrrchr(pzExtension, wxT('?')) &&
                        pzExtension[1]                    &&
                        pzExtension[1] != wxT(' ')
                       )              // != "blabla. "
                    {
                        //
                        // Now concat extension to the fileName:
                        //
                        m_path = wxString(zFileNameBuffer) + pzExtension;
                    }
                }
            }
            else
            {
                m_path = (wxChar*)vFileDlg.szFullFile;
            }
            m_fileName = wxFileNameFromPath((const wxChar*)vFileDlg.szFullFile);
            m_dir = wxPathOnly((const wxChar*)vFileDlg.szFullFile);

            //
            // === Simulating the wxOVERWRITE_PROMPT >>============================
            //
            if ((m_dialogStyle & wxOVERWRITE_PROMPT) &&
                (m_dialogStyle & wxSAVE) &&
                (wxFileExists(m_path.c_str())))
            {
                wxString            sMessageText;

                sMessageText.Printf( _("File '%s' already exists.\nDo you want to replace it?")
                                    ,m_path.c_str()
                                   );
                if (wxMessageBox( sMessageText
                                 ,wxT("Save File As")
                                 ,wxYES_NO | wxICON_EXCLAMATION
                                ) != wxYES)
                {
                    return wxID_CANCEL;
                }
            }
        }
        return wxID_OK;
    }
    return wxID_CANCEL;
} // end of wxFileDialog::ShowModal
Esempio n. 17
0
void CState::HandleDroppedFiles(const wxFileDataObject* pFileDataObject, const CLocalPath& path, bool copy)
{
	const wxArrayString &files = pFileDataObject->GetFilenames();
	if (!files.Count())
		return;

#ifdef __WXMSW__
	int len = 1;

	for (unsigned int i = 0; i < files.Count(); i++)
		len += files[i].Len() + 1;

	// SHFILEOPSTRUCT's pTo and pFrom accept null-terminated lists
	// of null-terminated filenames.
	wxChar* from = new wxChar[len];
	wxChar* p = from;
	for (unsigned int i = 0; i < files.Count(); i++)
	{
		wxStrcpy(p, files[i]);
		p += files[i].Len() + 1;
	}
	*p = 0; // End of list

	wxChar* to = new wxChar[path.GetPath().Len() + 2];
	wxStrcpy(to, path.GetPath());
	to[path.GetPath().Len() + 1] = 0; // End of list

	SHFILEOPSTRUCT op = {0};
	op.pFrom = from;
	op.pTo = to;
	op.wFunc = copy ? FO_COPY : FO_MOVE;
	op.hwnd = (HWND)m_pMainFrame->GetHandle();
	SHFileOperation(&op);

	delete [] to;
	delete [] from;
#else
	for (unsigned int i = 0; i < files.Count(); i++)
	{
		const wxString& file(files[i]);

		wxLongLong size;
		bool is_link;
		CLocalFileSystem::local_fileType type = CLocalFileSystem::GetFileInfo(file, is_link, &size, 0, 0);
		if (type == CLocalFileSystem::file)
		{
			wxString name;
			CLocalPath sourcePath(file, &name);
			if (name.empty())
				continue;
			if (copy)
				wxCopyFile(file, path.GetPath() + name);
			else
				wxRenameFile(file, path.GetPath() + name);
		}
		else if (type == CLocalFileSystem::dir)
		{
			if (copy)
				RecursiveCopy(CLocalPath(file), path);
			else
			{
				CLocalPath sourcePath(file);
				if (!sourcePath.HasParent())
					continue;
				wxRenameFile(file, path.GetPath() + sourcePath.GetLastSegment());
			}
		}
	}
#endif

	RefreshLocal();
}
Esempio n. 18
0
//----------------------------------------------------------------------------------------
bool BrowserDB::OnGetNext(int Cols,int WXUNUSED(Quiet))
{
    SDWORD cb;
    int i_dbDataType;
    wxChar s_temp[1024+1];
    long l_temp;
    double f_temp;
    int AnzError=0;
    TIMESTAMP_STRUCT t_temp;
    wxString Temp0;
    //-----------------------------
    if (!db_BrowserDB->GetNext())
    {
#ifdef __WXDEBUG__
        Temp0.Printf(_("\n-E-> BrowserDB::OnGetNext - ODBC-Error with GetNext \n-E-> "));
        Temp0 += GetExtendedDBErrorMsg(__TFILE__,__LINE__);
        wxLogMessage(Temp0);
        wxMessageBox(Temp0);
#endif
        return false;
    }
    else
    {
        int i;
        for (i=0; i<Cols; i++)
        {
            wxStrcpy((cl_BrowserDB+i)->tableName,_T("-E->"));
            i_dbDataType = (cl_BrowserDB+i)->pColFor->i_dbDataType;
            if (i_dbDataType == 0)         // Filter unsupported dbDataTypes
            {
                if (((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_VARCHAR) ||
                        ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_LONGVARCHAR))
                    i_dbDataType = DB_DATA_TYPE_VARCHAR;
                if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_C_DATE)
                    i_dbDataType = DB_DATA_TYPE_DATE;
                if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_C_BIT)
                    i_dbDataType = DB_DATA_TYPE_INTEGER;
                if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_NUMERIC)
                    i_dbDataType = DB_DATA_TYPE_VARCHAR;
                if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_REAL)
                    i_dbDataType = DB_DATA_TYPE_FLOAT;
            }
            if ((i_dbDataType == DB_DATA_TYPE_INTEGER) &&
                    ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_C_DOUBLE))
            {   // DBASE Numeric
                i_dbDataType = DB_DATA_TYPE_FLOAT;
            }
            switch(i_dbDataType)
            {
            case DB_DATA_TYPE_VARCHAR:
                wxStrcpy(s_temp,wxEmptyString);
                if (!db_BrowserDB->GetData((UWORD)(i+1),(SWORD)((cl_BrowserDB+i)->pColFor->i_dbDataType),&s_temp[0],sizeof(s_temp), &cb))
                {
                    Temp0.Printf(_("\n-E-> BrowserDB::OnGetNext - ODBC-Error with GetNext of >%s<.\n-E-> "),(cl_BrowserDB+i)->tableName);
                    Temp0 += GetExtendedDBErrorMsg(__TFILE__,__LINE__);
                    wxLogMessage(Temp0);
                }
                Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,s_temp);
                wxStrcpy((cl_BrowserDB+i)->tableName,Temp0.c_str());
                break;
            case DB_DATA_TYPE_INTEGER:
                l_temp = 0;
                if (!db_BrowserDB->GetData((UWORD)(i+1),(SWORD)((cl_BrowserDB+i)->pColFor->i_sqlDataType),&l_temp,sizeof(l_temp), &cb))
                {
                    Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> "));
                    Temp0 += GetExtendedDBErrorMsg(__TFILE__,__LINE__);
                }
                else
                {
                    Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,l_temp);
                    wxStrcpy((cl_BrowserDB+i)->tableName,Temp0.c_str());
                }
                break;
            case DB_DATA_TYPE_FLOAT:
                f_temp = 0;
                if (!db_BrowserDB->GetData((UWORD)(i+1),(SWORD)((cl_BrowserDB+i)->pColFor->i_sqlDataType),&f_temp,sizeof(f_temp), &cb))
                {
                    Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> "));
                    Temp0 += GetExtendedDBErrorMsg(__TFILE__,__LINE__);
                    wxMessageBox(Temp0);
                }
                else
                {
                    Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,f_temp);
                    wxStrcpy((cl_BrowserDB+i)->tableName,Temp0.c_str());
                }
                break;
            case DB_DATA_TYPE_DATE:
                t_temp.day = 0;
                t_temp.month = 0;
                t_temp.year = 0;
                t_temp.hour = 0;
                t_temp.minute = 0;
                t_temp.second = 0;
                t_temp.fraction = 0;
                if (!db_BrowserDB->GetData((UWORD)(i+1),(SWORD)((cl_BrowserDB+i)->pColFor->i_sqlDataType),&t_temp,sizeof(t_temp), &cb))
                {
                    Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> "));
                    Temp0 += GetExtendedDBErrorMsg(__TFILE__,__LINE__);
                }
                else
                {
                    // i_Nation =  0 = timestamp , 1=EU, 2=UK, 3=International, 4=US
                    if (((cl_BrowserDB+i)->pColFor->i_Nation == 0)    ||    // TS  YYYY-MM-DD
                            ((cl_BrowserDB+i)->pColFor->i_Nation == 3))     // IT  YYYY-MM-DD
                    {
                        Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,t_temp.year,t_temp.month,t_temp.day,
                                     t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction);
                        wxStrcpy((cl_BrowserDB+i)->tableName,Temp0.c_str());
                    }
                    if (((cl_BrowserDB+i)->pColFor->i_Nation == 1) ||  // EU  DD.MM.YYYY
                            ((cl_BrowserDB+i)->pColFor->i_Nation == 2))   // UK  DD/MM/YYYY
                    {
                        Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,t_temp.day,t_temp.month,t_temp.year,
                                     t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction);
                        wxStrcpy((cl_BrowserDB+i)->tableName,Temp0.c_str());
                    }
                    if ((cl_BrowserDB+i)->pColFor->i_Nation == 3)    // US  MM/DD/YYYY
                    {
                        Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,t_temp.month,t_temp.day,t_temp.year,
                                     t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction);
                        wxStrcpy((cl_BrowserDB+i)->tableName,Temp0.c_str());
                    }
                }
                break;
            default:
                AnzError++;
                if (AnzError <= 100)
                {
                    Temp0 = (cl_BrowserDB+i)->colName;
                    wxLogMessage(_("-E-> BrowserDB::OnGetNext - DB_DATA_TYPE_?? (%d) in Col(%s)"),(cl_BrowserDB+i)->pColFor->i_dbDataType,Temp0.c_str());
                }
                else
                    return true;
                Temp0.Printf(_("-E-> unknown Format(%d) - sql(%d)"),(cl_BrowserDB+i)->pColFor->i_dbDataType,(cl_BrowserDB+i)->pColFor->i_sqlDataType);
                wxStrcpy((cl_BrowserDB+i)->tableName,Temp0.c_str());
                break;
            };  // switch
        }  // for
    }  // else

    return true;
}
Esempio n. 19
0
CURLcode CUrlOpt::Run()
{
	CURL *curl;
	CURLcode res;
	char *pUrl, *pPorxy=NULL;

	m_content.Clear();
	if (m_url.IsEmpty())
		return (CURLcode)-1;

	curl = curl_easy_init();
	if(!curl){
		wxLogError("curl_easy_init fail\n");
		return CURLE_FAILED_INIT;
	}

	pUrl = (char*)calloc(m_url.Length()+1, 1);
	wxStrcpy(pUrl, m_url.c_str());

	if (!m_proxy.IsEmpty()) {
		pPorxy= (char*)calloc(m_proxy.Length()+1, 1);
		wxStrcpy(pPorxy, m_proxy.c_str());
	}
#ifdef _DEBUG
	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
	curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_curl_debug_callback);
#endif
	curl_easy_setopt(curl, CURLOPT_URL, pUrl);
#if 1
	curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
	curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
	curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, m_timeout);
	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, my_header_callback);
	curl_easy_setopt(curl, CURLOPT_HEADERDATA, this);

	if (m_bGzip) 
		curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");


	curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0");
#endif
	if (!m_proxy.IsEmpty()){
		curl_easy_setopt(curl, CURLOPT_PROXY, pPorxy);
		curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
	}

	m_length = 0x0;
	m_pBuf = NULL;
	res = curl_easy_perform(curl);

	curl_easy_cleanup(curl);

	m_ret = res;
	if (pUrl)   free(pUrl);
	if (pPorxy) free(pPorxy);

	if (res==0) 
	{
		if (m_bGzip)
		{
			wxMemoryInputStream istream((char*)m_pBuf, m_length);
			wxZlibInputStream zstream(istream, wxZLIB_GZIP);
			wxStringOutputStream ostream(&m_content);
			zstream.Read(ostream);
		}
		else {
			wxConvAuto *pConv;
			if (m_bGBK)
				pConv = new wxConvAuto(wxFONTENCODING_CP936);
			else
				pConv = new wxConvAuto(wxFONTENCODING_UTF8);
			m_content = wxString(m_pBuf, *pConv, m_length);
			delete pConv;
		}
	}
	return res;
}
Esempio n. 20
0
bool Go(void)
{
#ifndef NO_GUI
  ChooseInputFile();
  ChooseOutputFile();
#endif

  if (InputFile.empty() || OutputFile.empty() || stopRunning)
    return false;

#ifndef NO_GUI
  if (isInteractive)
  {
    wxChar buf[300];
    wxString str = wxFileNameFromPath(InputFile);

    wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str);
    frame->SetTitle(buf);
  }

  wxStartTimer();
#endif

  // Find extension-less filename
  wxStrcpy(FileRoot, OutputFile.c_str());
  StripExtension(FileRoot);

  if (truncateFilenames && convertMode == TEX_HTML)
  {
    // Truncate to five characters. This ensures that
    // we can generate DOS filenames such as thing999. But 1000 files
    // may not be enough, of course...
    wxChar* sName = wxFileNameFromPath( FileRoot);  // this Julian's method is non-destructive reference

    if(sName)
      if(wxStrlen( sName) > 5)
        sName[5] = '\0';  // that should do!
  }

  wxSnprintf(ContentsName, 300, _T("%s.con"), FileRoot);
  wxSnprintf(TmpContentsName, 300, _T("%s.cn1"), FileRoot);
  wxSnprintf(TmpFrameContentsName, 300, _T("%s.frc"), FileRoot);
  wxSnprintf(WinHelpContentsFileName, 300, _T("%s.cnt"), FileRoot);
  wxSnprintf(RefFileName, 300, _T("%s.ref"), FileRoot);

  TexPathList.EnsureFileAccessible(InputFile);
  if (!bulletFile)
  {
    wxString s = TexPathList.FindValidPath(_T("bullet.bmp"));
    if (!s.empty())
    {
      wxString str = wxFileNameFromPath(s);
      bulletFile = copystring(str);
    }
  }

  if (wxFileExists(RefFileName))
    ReadTexReferences(RefFileName);

  bool success = false;

  if (!InputFile.empty() && !OutputFile.empty())
  {
    if (!wxFileExists(InputFile))
    {
      OnError(_T("Cannot open input file!"));
      TexCleanUp();
      return false;
    }
#if !defined(NO_GUI) && wxUSE_STATUSBAR
    if (isInteractive)
    {
      wxString buf;
      buf.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber);
      frame->SetStatusText((wxChar *)buf.c_str());
    }
#endif
    OkToClose = false;
    OnInform(_T("Reading LaTeX file..."));
    TexLoadFile(InputFile);

    if (stopRunning)
    {
        OkToClose = true;
        return false;
    }

    switch (convertMode)
    {
      case TEX_RTF:
      {
        success = RTFGo();
        break;
      }
      case TEX_XLP:
      {
        success = XLPGo();
        break;
      }
      case TEX_HTML:
      {
        success = HTMLGo();
        break;
      }
    }
  }
  if (stopRunning)
  {
    OnInform(_T("*** Aborted by user."));
    success = false;
    stopRunning = false;
    OkToClose = true;
  }

  if (success)
  {
    WriteTexReferences(RefFileName);
    TexCleanUp();
    startedSections = false;

    wxString buf;
#ifndef NO_GUI
    long tim = wxGetElapsedTime();
    buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(tim/1000.0));
    OnInform((wxChar *)buf.c_str());

    if (errorCount)
    {
        buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount);
        OnInform((wxChar *)buf.c_str());
    }

#if wxUSE_STATUSBAR
    if (isInteractive)
    {
      buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass"));
      frame->SetStatusText((wxChar *)buf.c_str());
    }
#endif // wxUSE_STATUSBAR
#else
    buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass"));
    OnInform((wxChar *)buf.c_str());
    if (errorCount)
    {
        buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount);
        OnInform((wxChar *)buf.c_str());
    }
#endif
    passNumber ++;
    errorCount = 0;
    OkToClose = true;
    return true;
  }

  TexCleanUp();
  startedSections = false;

#if !defined(NO_GUI) && wxUSE_STATUSBAR
  frame->SetStatusText(_T("Aborted by user."));
#endif // GUI

  OnInform(_T("Sorry, unsuccessful."));
  OkToClose = true;
  return false;
}
Esempio n. 21
0
static inline wxChar* MYcopystring(const wxString& s)
{
    wxChar* copy = new wxChar[s.length() + 1];
    return wxStrcpy(copy, s.c_str());
}
Esempio n. 22
0
static inline wxChar* copystring(const wxChar* s)
    { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
Esempio n. 23
0
wxHashTableBase_Node::wxHashTableBase_Node( const wxChar* key, void* value,
                                            wxHashTableBase* table )
    : m_value( value ), m_hashPtr( table )
{
    m_key.string = wxStrcpy( new wxChar[wxStrlen( key ) + 1], key );
}
Esempio n. 24
0
bool Tex2RTFConnection::OnExecute(const wxString& WXUNUSED(topic), wxChar *data, int WXUNUSED(size), wxIPCFormat WXUNUSED(format))
{
  wxStrcpy(Tex2RTFLastStatus, _T("OK"));

  wxChar firstArg[50];
  wxChar secondArg[300];
  if (SplitCommand(data, firstArg, secondArg))
  {
    bool hasArg = (wxStrlen(secondArg) > 0);
    if (wxStrcmp(firstArg, _T("INPUT")) == 0 && hasArg)
    {
        InputFile = secondArg;
        if (frame)
        {
            wxChar buf[100];
            wxString str = wxFileNameFromPath(InputFile);
            wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str);
            frame->SetTitle(buf);
        }
    }
    else if (wxStrcmp(firstArg, _T("OUTPUT")) == 0 && hasArg)
    {
        OutputFile = secondArg;
    }
    else if (wxStrcmp(firstArg, _T("GO")) == 0)
    {
      wxStrcpy(Tex2RTFLastStatus, _T("WORKING"));
      if (!Go())
        wxStrcpy(Tex2RTFLastStatus, _T("CONVERSION ERROR"));
      else
        wxStrcpy(Tex2RTFLastStatus, _T("OK"));
    }
    else if (wxStrcmp(firstArg, _T("EXIT")) == 0)
    {
      if (frame) frame->Close();
    }
    else if (wxStrcmp(firstArg, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg, _T("ICONIZE")) == 0)
    {
      if (frame)
        frame->Iconize(true);
    }
    else if (wxStrcmp(firstArg, _T("SHOW")) == 0 || wxStrcmp(firstArg, _T("RESTORE")) == 0)
    {
      if (frame)
      {
        frame->Iconize(false);
        frame->Show(true);
      }
    }
    else
    {
      // Try for a setting
      wxStrcpy(Tex2RTFLastStatus, RegisterSetting(firstArg, secondArg, false));
#if !defined(NO_GUI) && wxUSE_STATUSBAR
      if (frame && wxStrcmp(firstArg, _T("conversionMode")) == 0)
      {
        wxChar buf[100];
        wxStrcpy(buf, _T("In "));

        if (winHelp && (convertMode == TEX_RTF))
          wxStrcat(buf, _T("WinHelp RTF"));
        else if (!winHelp && (convertMode == TEX_RTF))
          wxStrcat(buf, _T("linear RTF"));
        else if (convertMode == TEX_HTML) wxStrcat(buf, _T("HTML"));
        else if (convertMode == TEX_XLP) wxStrcat(buf, _T("XLP"));
          wxStrcat(buf, _T(" mode."));
        frame->SetStatusText(buf, 1);
      }
#endif
    }
  }
  return true;
}
Esempio n. 25
0
int copyStrToBuf(void* dst, wxString& src) {
  if (dst) wxStrcpy ((wxChar*) dst, src.c_str());
  return src.Length();
}
Esempio n. 26
0
static inline wxChar* MYcopystring(const wxChar* s)
{
    wxChar* copy = new wxChar[wxStrlen(s) + 1];
    return wxStrcpy(copy, s);
}
Esempio n. 27
0
void wxOS2SelectMatchingFontByName(
  PFATTRS                           pFattrs
, PFACENAMEDESC                     pFaceName
, PFONTMETRICS                      pFM
, int                               nNumFonts
, const wxFont*                     pFont
)
{
    int                             i;
    int                             nPointSize;
    int                             nIs;
    int                             nMinDiff0;
    int                             anDiff[16];
    int                             anMinDiff[16];
    int                             nIndex = 0;
    wxChar                          zFontFaceName[FACESIZE];
    wxString                        sFaceName;
    USHORT                          usWeightClass;
    int                             fsSelection = 0;

    nMinDiff0 = 0xf000;
    for(i = 0;i < 16; i++)
        anMinDiff[i] = nMinDiff0;

    switch (pFont->GetFamily())
    {
        case wxSCRIPT:
            sFaceName = wxT("Tms Rmn");
            break;

        case wxDECORATIVE:
            sFaceName = wxT("WarpSans");
            break;

        case wxROMAN:
            sFaceName = wxT("Tms Rmn");
            break;

        case wxTELETYPE:
            sFaceName = wxT("Courier") ;
            break;

        case wxMODERN:
            sFaceName = wxT("System VIO") ;
            break;

        case wxSWISS:
            sFaceName = wxT("Helv") ;
            break;

        case wxDEFAULT:
        default:
            sFaceName = wxT("System VIO") ;
    }

    switch (pFont->GetWeight())
    {
        default:
            wxFAIL_MSG(wxT("unknown font weight"));
            // fall through
            usWeightClass = FWEIGHT_DONT_CARE;
            break;

        case wxNORMAL:
            usWeightClass = FWEIGHT_NORMAL;
            break;

        case wxLIGHT:
            usWeightClass = FWEIGHT_LIGHT;
            break;

        case wxBOLD:
            usWeightClass = FWEIGHT_BOLD;
            break;

         case wxFONTWEIGHT_MAX:
            usWeightClass = FWEIGHT_ULTRA_BOLD;
            break;
    }
    pFaceName->usWeightClass = usWeightClass;

    switch (pFont->GetStyle())
    {
        case wxITALIC:
        case wxSLANT:
            fsSelection = FM_SEL_ITALIC;
            pFaceName->flOptions = FTYPE_ITALIC;
            break;

        default:
            wxFAIL_MSG(wxT("unknown font slant"));
            // fall through

        case wxNORMAL:
            fsSelection  = 0;
            break;
    }

    wxStrlcpy(zFontFaceName, sFaceName.c_str(), WXSIZEOF(zFontFaceName));
    nPointSize = pFont->GetPointSize();

    //
    // Matching logic to find the right FM struct
    //
    nIndex = 0;
    for(i = 0, nIs = 0; i < nNumFonts; i++)
    {
        anDiff[0] = wxGpiStrcmp((wxChar*)pFM[i].szFacename, zFontFaceName);
        anDiff[1] = abs(pFM[i].lEmHeight - nPointSize);
        anDiff[2] = abs(pFM[i].usWeightClass -  usWeightClass);
        anDiff[3] = abs((pFM[i].fsSelection & 0x2f) -  fsSelection);
        if(anDiff[0] == 0)
        {
            if( (nIs & 0x01) == 0)
            {
                nIs = 1;
                nIndex = i;
                anMinDiff[1] = anDiff[1];
                anMinDiff[2] = anDiff[2];
                anMinDiff[3] = anDiff[3];
            }
            else if(anDiff[3] < anMinDiff[3])
            {
                nIndex = i;
                anMinDiff[3] = anDiff[3];
            }
            else if(anDiff[2] < anMinDiff[2])
            {
                nIndex = i;
                anMinDiff[2] = anDiff[2];
            }
            else if(anDiff[1] < anMinDiff[1])
            {
                nIndex = i;
                anMinDiff[1] = anDiff[1];
            }
            anMinDiff[0] = 0;
        }
        else if(anDiff[0] < anMinDiff[0])
        {
              nIs = 2;
              nIndex = i;
              anMinDiff[3] = anDiff[3];
              anMinDiff[2] = anDiff[2];
              anMinDiff[1] = anDiff[1];
              anMinDiff[0] = anDiff[0];
        }
        else if(anDiff[0] == anMinDiff[0])
        {
            if(anDiff[3] < anMinDiff[3])
            {
                nIndex = i;
                anMinDiff[3] = anDiff[3];
                nIs = 2;
            }
            else if(anDiff[2] < anMinDiff[2])
            {
                nIndex = i;
                anMinDiff[2] = anDiff[2];
                nIs = 2;
            }
            else if(anDiff[1] < anMinDiff[1])
            {
                nIndex = i;
                anMinDiff[1] = anDiff[1];
                nIs = 2;
            }
        }
    }

    //
    // Fill in the FATTRS with the best match from FONTMETRICS
    //
    pFattrs->usRecordLength  = sizeof(FATTRS);              // Sets size of structure
    pFattrs->lMatch          = pFM[nIndex].lMatch;          // Force match
    pFattrs->idRegistry      = 0;
    pFattrs->usCodePage      = 0;
    pFattrs->fsFontUse       = 0;
    pFattrs->fsType          = 0;
    pFattrs->lMaxBaselineExt = 0;
    pFattrs->lAveCharWidth   = 0;
    wxStrcpy((wxChar*)pFattrs->szFacename, (wxChar*)pFM[nIndex].szFacename);
    if (pFont->GetWeight() == wxNORMAL)
        pFattrs->fsSelection = 0;
    else
        pFattrs->fsSelection = FATTR_SEL_BOLD;

    if (pFont->GetStyle() == wxITALIC || pFont->GetStyle() == wxSLANT)
        pFattrs->fsSelection |= FATTR_SEL_ITALIC;

    if (pFont->GetUnderlined())
        pFattrs->fsSelection |= FATTR_SEL_UNDERSCORE;
} // end of wxOS2SelectMatchingFontByName
Esempio n. 28
0
static inline CharType* MYcopystring(const CharType* s)
{
    CharType* copy = new CharType[wxStrlen(s) + 1];
    return wxStrcpy(copy, s);
}
Esempio n. 29
0
File: db.cpp Progetto: snmsts/wxc
EWXWEXPORT(wxDbColInf*,wxDb_GetResultColumns)(wxDb* db,int* pnumCols)
{
#ifndef wxUSE_ODBC
  if (pnumCols) *pnumCols = 0;
  return NULL;
#else
  RETCODE retcode = 0;
  HSTMT   hstmt   = SQL_NULL_HSTMT;
  SWORD   numCols = 0;
  
  UWORD       column = 0;
  wxDbColInf* colInf = NULL;

  if (pnumCols) *pnumCols = 0;
  if (db==NULL) return NULL;

  /* allocate column info's */
  hstmt   = db->GetHSTMT();
  retcode = SQLNumResultCols(hstmt,&numCols);
  if (retcode != SQL_SUCCESS) {
    db->DispAllErrors(db->GetHENV(), db->GetHDBC(), hstmt);
    return NULL;
  }
  if (numCols==0) return NULL; 
  
  colInf = new wxDbColInf[numCols+1];
  if (!colInf) return NULL;

  /* mark the end of the array */
  wxStrcpy(colInf[numCols].tableName, wxEmptyString);
  wxStrcpy(colInf[numCols].colName, wxEmptyString);
  colInf[numCols].sqlDataType = 0;

  /* initialize all column infos */
  for( column = 0; column < numCols; column++)
  {
    SWORD  colNameLen  = 0;
    SWORD  typeNameLen = 0;
    UDWORD colSize     = 0;

    /* get the column information */
    retcode = SQLDescribeCol(hstmt, column+1,
#ifndef wxUSE_UNICODE
                            (SQLCHAR*)colInf[column].colName,
#else
                            (SQLWCHAR*)colInf[column].colName,
#endif
                            DB_MAX_COLUMN_NAME_LEN+1, &colNameLen,
                            &colInf[column].sqlDataType,
                            &colSize,
                            &colInf[column].decimalDigits, 
                            &colInf[column].nullable );
#if (wxVERSION_NUMBER <= 2500)
    colInf[column].columnSize   = colSize;
#else /* (wxVERSION_NUMBER <= 2500) */
    colInf[column].columnLength = colSize;
#endif /* (wxVERSION_NUMBER <= 2500) */
    
    /* check for errors */
    if (retcode != SQL_SUCCESS) {
      db->DispAllErrors(db->GetHENV(), db->GetHDBC(), hstmt);
      delete [] colInf;
      return NULL;
    }

#ifdef SQL_DESC_TYPE_NAME    
    /* try to get type name too (errors are no problem) */
    SQLColAttribute( hstmt, column+1, SQL_DESC_TYPE_NAME,
                     colInf[column].typeName, 128+1,
                     &typeNameLen, NULL );
#endif

    /* for compatibilty with the wxWindows GetColumns, we set the dbDataType too */
    colInf[column].dbDataType = 0;
    switch (colInf[column].sqlDataType)
    {
#ifndef wxUSE_UNICODE
    #if defined(SQL_WVARCHAR)
        case SQL_WVARCHAR:
    #endif
    #if defined(SQL_WCHAR)
        case SQL_WCHAR:
    #endif
#endif
        case SQL_VARCHAR:
        case SQL_CHAR:
            colInf[column].dbDataType = DB_DATA_TYPE_VARCHAR;
        break;

        case SQL_TINYINT:
        case SQL_SMALLINT:
        case SQL_INTEGER:
#ifdef SQL_BIGINT
        case SQL_BIGINT:
#endif
#ifdef SQL_BIT
        case SQL_BIT:
#endif
            colInf[column].dbDataType = DB_DATA_TYPE_INTEGER;
            break;
        case SQL_DOUBLE:
        case SQL_DECIMAL:
        case SQL_NUMERIC:
        case SQL_FLOAT:
        case SQL_REAL:
            colInf[column].dbDataType = DB_DATA_TYPE_FLOAT;
            break;
#ifdef SQL_DATE
        case SQL_DATE:
            colInf[column].dbDataType = DB_DATA_TYPE_DATE;
            break;
#endif
#ifdef SQL_BINARY
        case SQL_BINARY:
            colInf[column].dbDataType = DB_DATA_TYPE_BLOB;
            break;
#endif
#ifdef __WXDEBUG__
        default:
            wxString errMsg;
            errMsg.Printf(wxT("SQL Data type %d currently not supported by wxWindows"), colInf[column].sqlDataType);
            wxLogDebug(errMsg,wxT("ODBC DEBUG MESSAGE"));
#endif
    }
  } /* for columns */

  if (pnumCols) *pnumCols = numCols;
  return colInf;
#endif
}
Esempio n. 30
0
long wxExecute( const wxString& command, int flags, wxProcess *process )
{
    wxCHECK_MSG( !command.empty(), 0, wxT("can't exec empty command") );
    wxLogDebug(wxString(wxT("Launching: ")) + command);

#if wxUSE_THREADS
    // fork() doesn't mix well with POSIX threads: on many systems the program
    // deadlocks or crashes for some reason. Probably our code is buggy and
    // doesn't do something which must be done to allow this to work, but I
    // don't know what yet, so for now just warn the user (this is the least we
    // can do) about it
    wxASSERT_MSG( wxThread::IsMain(),
                    _T("wxExecute() can be called only from the main thread") );
#endif // wxUSE_THREADS

    int argc = 0;
    wxChar *argv[WXEXECUTE_NARGS];
    wxString argument;
    const wxChar *cptr = command.c_str();
    wxChar quotechar = wxT('\0'); // is arg quoted?
    bool escaped = false;

    // split the command line in arguments
    do
    {
        argument=wxT("");
        quotechar = wxT('\0');

        // eat leading whitespace:
        while ( wxIsspace(*cptr) )
            cptr++;

        if ( *cptr == wxT('\'') || *cptr == wxT('"') )
            quotechar = *cptr++;

        do
        {
            if ( *cptr == wxT('\\') && ! escaped )
            {
                escaped = true;
                cptr++;
                continue;
            }

            // all other characters:
            argument += *cptr++;
            escaped = false;

            // have we reached the end of the argument?
            if ( (*cptr == quotechar && ! escaped)
                 || (quotechar == wxT('\0') && wxIsspace(*cptr))
                 || *cptr == wxT('\0') )
            {
                wxASSERT_MSG( argc < WXEXECUTE_NARGS,
                              wxT("too many arguments in wxExecute") );

                argv[argc] = new wxChar[argument.length() + 1];
                wxStrcpy(argv[argc], argument.c_str());
                argc++;

                // if not at end of buffer, swallow last character:
                if(*cptr)
                    cptr++;

                break; // done with this one, start over
            }
        } while(*cptr);
    } while(*cptr);
    argv[argc] = NULL;

    long lRc;
#if defined(__DARWIN__)
    // wxMacExecute only executes app bundles.
    // It returns an error code if the target is not an app bundle, thus falling
    // through to the regular wxExecute for non app bundles.
    lRc = wxMacExecute(argv, flags, process);
    if( lRc != ((flags & wxEXEC_SYNC) ? -1 : 0))
        return lRc;
#endif

    // do execute the command
    lRc = wxExecute(argv, flags, process);

    // clean up
    argc = 0;
    while( argv[argc] )
        delete [] argv[argc++];

    return lRc;
}