From 984a123af39f99d3e5db645312054dd67a8eee8e Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 31 Jan 2005 15:26:40 +0000 Subject: [PATCH] Asger's obviously-correct Win32 changes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9556 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 4 ++++ src/frontends/qt2/ChangeLog | 9 +++++++++ src/frontends/qt2/QDialogView.h | 7 ++++++- src/frontends/qt2/QLPainter.C | 8 +++++--- src/frontends/qt2/lengthvalidator.h | 2 +- src/lyxlex_pimpl.h | 1 + src/support/ChangeLog | 9 +++++++++ src/support/chdir.C | 12 ++++++++--- src/support/getcwd.C | 13 +++++++++--- src/support/kill.C | 31 +++++++++++++++++++++++++++++ src/support/mkdir.C | 15 ++++++++------ src/support/os_win32.h | 10 ---------- 12 files changed, 94 insertions(+), 27 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d13d25f9f5..260b097364 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2005-01-31 Asger Ottar Alstrup + + * lyxlex_pimpl.h: #include . + 2005-01-31 Lars Gullik Bjonnes * vc-backend.C (find_file): rewrite to use boost.filesystem diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 70a1e10e9e..d454b6e5a0 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,12 @@ +2005-01-31 Asger Ottar Alstrup + + * QDialogView.h (form): add cast for MSVC. + + * QLPainter.C (smllCapsText, text): MSVC doesn't like the use + of operator[](i) here, so use at(i) instead. + + * lengthvalidator.h: remove incorrect Q_EXPORT spec. + 2005-01-31 Angus Leeming * QGraphics.[Ch] (slotEdit): unused cruft, so removed. diff --git a/src/frontends/qt2/QDialogView.h b/src/frontends/qt2/QDialogView.h index 8edd08c270..cc1e92a10a 100644 --- a/src/frontends/qt2/QDialogView.h +++ b/src/frontends/qt2/QDialogView.h @@ -13,6 +13,7 @@ #define QDIALOGVIEW_H #include "Dialog.h" + #include #include @@ -110,7 +111,11 @@ QView::QView(Dialog & p, std::string const & t) template QDialog * QView::form() const { - return dialog_.get(); + /* Brain dead MSVC compiler wants to know the class hierarchy at the + definition site of the template, rather than the instantation point + to downcast correctly. So, rather than including all dialogs to + provide that, we just cast it with the ugly hammer. */ + return (QDialog *) dialog_.get(); } diff --git a/src/frontends/qt2/QLPainter.C b/src/frontends/qt2/QLPainter.C index 9f5b8a1031..958bd459fe 100644 --- a/src/frontends/qt2/QLPainter.C +++ b/src/frontends/qt2/QLPainter.C @@ -202,8 +202,9 @@ void QLPainter::smallCapsText(int x, int y, int tmpx = x; size_t ls = s.length(); for (size_t i = 0; i < ls; ++i) { - QChar const c = s[i].upper(); - if (c != s[i]) { + // Brain-dead MSVC wants at(i) rather than operator[] + QChar const c = s.at(i).upper(); + if (c != s.at(i)) { qp_->setFont(qsmallfont); qp_->drawText(tmpx, y, c); tmpx += qsmallfontm.width(c); @@ -229,7 +230,8 @@ void QLPainter::text(int x, int y, char const * s, size_t ls, #if QT_VERSION >= 300 str.setLength(ls); for (size_t i = 0; i < ls; ++i) - str[i] = QChar(encoding->ucs(s[i])); + // Brain-dead MSVC wants at(i) rather than operator[] + str.at(i) = QChar(encoding->ucs(s[i])); // HACK: QT3 refuses to show single compose characters if (ls == 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2) str = ' ' + str; diff --git a/src/frontends/qt2/lengthvalidator.h b/src/frontends/qt2/lengthvalidator.h index ea45721154..9f60b9869c 100644 --- a/src/frontends/qt2/lengthvalidator.h +++ b/src/frontends/qt2/lengthvalidator.h @@ -19,7 +19,7 @@ class QWidget; -class Q_EXPORT LengthValidator : public QValidator +class LengthValidator : public QValidator { Q_OBJECT public: diff --git a/src/lyxlex_pimpl.h b/src/lyxlex_pimpl.h index 797605dc08..79f4393ace 100644 --- a/src/lyxlex_pimpl.h +++ b/src/lyxlex_pimpl.h @@ -20,6 +20,7 @@ #include +#include #include #include #include diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 29bfff2cc3..85a02b2a86 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,12 @@ +2005-01-31 Asger Ottar Alstrup + + * chdir.C (chdir): + * getcwd.C (l_getcwd): + * kill.C (kill): + * mkdir.C (mkdir): add Win32 specializations. + + * os_win32.h: remove cruft. + 2005-01-31 Lars Gullik Bjonnes * Makefile.am (libsupport_la_SOURCES): remove rmdir.C diff --git a/src/support/chdir.C b/src/support/chdir.C index d9776e9c6e..6425c860a2 100644 --- a/src/support/chdir.C +++ b/src/support/chdir.C @@ -16,11 +16,17 @@ # include #endif +#ifdef _WIN32 +# include +#endif + int lyx::support::chdir(std::string const & name) { -#ifndef __EMX__ - return ::chdir(name.c_str()); -#else +#ifdef __EMX__ return ::_chdir2(name.c_str()); +#elif defined(_WIN32) + return SetCurrentDirectory(name.c_str()) != 0 ? 0 : -1; +#else + return ::chdir(name.c_str()); #endif } diff --git a/src/support/getcwd.C b/src/support/getcwd.C index 47d67fa274..f660097406 100644 --- a/src/support/getcwd.C +++ b/src/support/getcwd.C @@ -19,6 +19,10 @@ # include #endif +#ifdef _WIN32 +# include +#endif + using boost::scoped_array; using std::string; @@ -29,10 +33,13 @@ namespace { inline char * l_getcwd(char * buffer, size_t size) { -#ifndef __EMX__ - return ::getcwd(buffer, size); -#else +#ifdef __EMX return ::_getcwd2(buffer, size); +#elif defined(_WIN32) + GetCurrentDirectory(size, buffer); + return buffer; +#else + return ::getcwd(buffer, size); #endif } diff --git a/src/support/kill.C b/src/support/kill.C index 019c97949d..3c23a96a9e 100644 --- a/src/support/kill.C +++ b/src/support/kill.C @@ -15,7 +15,38 @@ #include #include +#ifdef _WIN32 +#include "debug.h" +#include "os.h" + +#include +#include + +using std::endl; +#endif //_WIN32 + int lyx::support::kill(int pid, int sig) { +#ifdef _WIN32 + if (pid == (int)GetCurrentProcessId()) { + return -(raise(sig)); + } else { + HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); + if (!hProcess) { + lyxerr << "kill OpenProcess failed!" << endl; + return -1; + } else { + if (!TerminateProcess(hProcess, sig)){ + lyxerr << "kill process failed!" << endl; + CloseHandle(hProcess); + return -1; + } + CloseHandle(hProcess); + } + } + return 0; + +#else return ::kill(pid, sig); +#endif } diff --git a/src/support/mkdir.C b/src/support/mkdir.C index c590880c30..e0be4fd811 100644 --- a/src/support/mkdir.C +++ b/src/support/mkdir.C @@ -18,6 +18,9 @@ #ifdef HAVE_UNISTD_H # include #endif +#ifdef _WIN32 +# include +#endif int lyx::support::mkdir(std::string const & pathname, unsigned long int mode) { @@ -30,12 +33,12 @@ int lyx::support::mkdir(std::string const & pathname, unsigned long int mode) // POSIX return ::mkdir(pathname.c_str(), mode_t(mode)); # endif -#else -# if HAVE__MKDIR +#elif defined(_WIN32) // plain Windows 32 - return ::_mkdir(pathname.c_str()); -# else -# error "Don't know how to create a directory on this system." -# endif + return CreateDirectory(pathname.c_str(), 0) != 0 ? 0 : -1; +#elif HAVE__MKDIR + return ::_mkdir(pathname.c_str()); +#else +# error "Don't know how to create a directory on this system." #endif } diff --git a/src/support/os_win32.h b/src/support/os_win32.h index 7ee35d09ea..78ee2ee36b 100644 --- a/src/support/os_win32.h +++ b/src/support/os_win32.h @@ -65,16 +65,6 @@ extern "C" { #define O_NONBLOCK 0x4000 inline int fcntl (int, int, ...) {return -1;} -//signal.h -#define SIGHUP 1 -#define SIGKILL 9 - -//sys/time.h -//struct timeval { -// long tv_sec; -// long tv_usec; -//}; - //unistd.h inline int fork () {return -1;} #define pipe(a) _pipe(a,0,0) -- 2.39.2