Abdelrazak Younes wrote:
> Peter Kümmel wrote:
>> Abdelrazak Younes wrote:
>>> Peter Kümmel wrote:
>>>> +    {
>>>> +#ifdef Q_OS_WIN
>>>> +        int x, y;
>>>> +        int w, h;
>>>> +        QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[
>>>> ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
>>>> +        re.indexIn( toqstr(geometryArg.c_str()));
>>>> +        w = re.cap( 1 ).toInt();
>>>> +        h = re.cap( 2 ).toInt();
>>>> +        x = re.cap( 3 ).toInt();
>>>> +        y = re.cap( 4 ).toInt();
>>>> +        QWidget::setGeometry( x, y, w, h );
>>>> +#endif
>>>> +    }
>>> Couldn't you do that parsing in parse_geometry() instead and overwrite
>>> width and height?
>>
>> Then I don't have QRegExp, and must convert it to boost code, which I
>> don't
>> know, additionally the Qt version is already tested and when I add new
>> code
>> I could introduce regressions. So I prefer it as it is, but I could add a
>> FIXME.
> 
> Yes, put a FIXME please. You know how much I hate #ifdef ;-), one #ifdef
> in parse_geometry() should have been enough.

OK, here a ifdef free version. ;-)

Peter

-- 
Peter Kümmel
Index: src/frontends/Application.h
===================================================================
--- src/frontends/Application.h (Revision 16104)
+++ src/frontends/Application.h (Arbeitskopie)
@@ -172,7 +172,8 @@
 
        /// Create the main window with given geometry settings.
        LyXView & createView(unsigned int width, unsigned int height,
-               int posx, int posy, bool maximize, unsigned int iconSizeXY);
+               int posx, int posy, bool maximize, unsigned int iconSizeXY,
+               const std::string & geometryArg);
        
        /// 
        LyXView const & currentView() const;
Index: src/frontends/LyXView.h
===================================================================
--- src/frontends/LyXView.h     (Revision 16104)
+++ src/frontends/LyXView.h     (Arbeitskopie)
@@ -88,7 +88,8 @@
                unsigned int height,
                int posx, int posy,
                bool maximize,
-               unsigned int iconSizeXY) = 0;
+               unsigned int iconSizeXY,
+               const std::string & geometryArg) = 0;
 
        /// save the geometry state in the session manager.
        virtual void saveGeometry() = 0;
Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (Revision 16104)
+++ src/frontends/qt4/GuiView.h (Arbeitskopie)
@@ -61,7 +61,8 @@
                unsigned int height,
                int posx, int posy,
                bool maximize,
-               unsigned int iconSizeXY);
+               unsigned int iconSizeXY,
+               const std::string & geometryArg);
        virtual void saveGeometry();
        virtual void busy(bool);
        Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb);
Index: src/frontends/qt4/GuiView.C
===================================================================
--- src/frontends/qt4/GuiView.C (Revision 16104)
+++ src/frontends/qt4/GuiView.C (Arbeitskopie)
@@ -29,6 +29,7 @@
 #include "support/filetools.h"
 #include "support/convert.h"
 #include "support/lstrings.h"
+#include "support/os.h"
 
 #include "BufferView.h"
 #include "bufferlist.h"
@@ -220,12 +221,17 @@
        // Then also the moveEvent, resizeEvent, and the
        // code for floatingGeometry_ can be removed;
        // adjust GuiView::setGeometry()
-#ifdef Q_WS_WIN
-       QRect geometry = normalGeometry();
-#else
-       updateFloatingGeometry();
-       QRect geometry = floatingGeometry_;
-#endif
+       QRect geometry;
+       if (support::os::shell() != support::os::UNIX)
+       {
+               // Windows
+               geometry = normalGeometry();
+       }
+       else
+       {
+               updateFloatingGeometry();
+               geometry = floatingGeometry_;
+       }
 
        // save windows size and position
        Session & session = LyX::ref().session();
@@ -244,7 +250,8 @@
                                                                  unsigned int 
height,
                                                                  int posx, int 
posy,
                                                                  bool maximize,
-                                                                 unsigned int 
iconSizeXY)
+                                                                 unsigned int 
iconSizeXY,
+                                                                 const 
std::string & geometryArg)
 {
        // use last value (not at startup)
        if (d.lastIconSize != 0)
@@ -256,7 +263,8 @@
 
        // only true when the -geometry option was NOT used
        if (width != 0 && height != 0) {
-               if (posx != -1 && posy != -1) {
+               if (posx != -1 && posy != -1) 
+               {
                        // if there are ever startup positioning problems 
                        // on a virtual desktop then check the 6 lines below
                        // http://doc.trolltech.com/4.2/qdesktopwidget.html 
@@ -264,20 +272,38 @@
                        QRect desk = dw.availableGeometry(dw.primaryScreen());
                        (posx >= desk.width() ? posx = 50 : true);
                        (posy >= desk.height()? posy = 50 : true);
-#ifdef Q_WS_WIN
-                       // FIXME: use setGeometry only when Trolltech has fixed 
the qt4/X11 bug
-                       QWidget::setGeometry(posx, posy, width, height);
-#else
+                       if (support::os::shell() != support::os::UNIX)
+                       {
+                               // Windows
+                               // FIXME: use setGeometry only when Trolltech 
has fixed the qt4/X11 bug
+                               QWidget::setGeometry(posx, posy, width, height);
+                       }
+                       else
+                       {       resize(width, height);
+                               move(posx, posy);
+                       }
+               } 
+               else 
+               {
                        resize(width, height);
-                       move(posx, posy);
-#endif
-               } else {
-                       resize(width, height);
                }
 
                if (maximize)
                        setWindowState(Qt::WindowMaximized);
        }
+       else if (support::os::shell() != support::os::UNIX)
+       {
+               // Windows
+               int x, y;
+               int w, h;
+               QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ 
]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
+               re.indexIn( toqstr(geometryArg.c_str()));
+               w = re.cap( 1 ).toInt();
+               h = re.cap( 2 ).toInt();
+               x = re.cap( 3 ).toInt();
+               y = re.cap( 4 ).toInt();
+               QWidget::setGeometry( x, y, w, h );
+       }
 
        show();
 
@@ -289,17 +315,20 @@
        // we compensate the drift when storing the position
        d.posx_offset = 0;
        d.posy_offset = 0;
-       if (width != 0 && height != 0) 
-               if (posx != -1 && posy != -1) {
-#ifdef Q_WS_WIN
+       if (width != 0 && height != 0 && posx != -1 && posy != -1) 
+               if (support::os::shell() != support::os::UNIX)
+               {                       
+                       // Windows
                        d.posx_offset = posx - normalGeometry().x();
                        d.posy_offset = posy - normalGeometry().y();
-#else
-                       if (!maximize) {
+               }
+               else
+               {
+                       if (!maximize) 
+                       {
                                d.posx_offset = posx - geometry().x();
                                d.posy_offset = posy - geometry().y();
                        }
-#endif
                }
 }
 
Index: src/frontends/Application.C
===================================================================
--- src/frontends/Application.C (Revision 16104)
+++ src/frontends/Application.C (Arbeitskopie)
@@ -52,7 +52,8 @@
                                                                  unsigned int 
height,
                                                                  int posx, int 
posy,
                                                                  bool maximize,
-                                                                 unsigned int 
iconSizeXY)
+                                                                 unsigned int 
iconSizeXY,
+                                                                 const 
std::string & geometryArg)
 {
        int view_id = gui().newView();
        LyXView & view = gui().view(view_id);
@@ -62,7 +63,7 @@
        /*int workArea_id_ =*/ gui().newWorkArea(width, height, view_id);
 
        view.init();
-       view.setGeometry(width, height, posx, posy, maximize, iconSizeXY);
+       view.setGeometry(width, height, posx, posy, maximize, iconSizeXY, 
geometryArg);
 
        setCurrentView(view);
 
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C      (Revision 16104)
+++ src/lyx_main.C      (Arbeitskopie)
@@ -116,6 +116,8 @@
 string cl_system_support;
 string cl_user_support;
 
+std::string geometryArg;
+
 LyX * singleton_ = 0;
 
 void showFileError(string const & error)
@@ -193,10 +195,11 @@
 
 
 LyX::LyX()
-       : first_start(false), geometryOption_(false)
+       : first_start(false)
 {
        singleton_ = this;
        pimpl_.reset(new Singletons);
+       geometryArg.clear();
 }
 
 
@@ -603,12 +606,14 @@
                        posy = convert<int>(val);
        }
 
-       if (geometryOption_) {
+       if (!geometryArg.empty()) 
+       {
                width = 0;
                height = 0;
        }
+
        // create the main window
-       LyXView * view = &pimpl_->application_->createView(width, height, posx, 
posy, maximize, iconSizeXY);
+       LyXView * view = &pimpl_->application_->createView(width, height, posx, 
posy, maximize, iconSizeXY, geometryArg);
 
        return view;
 }
@@ -1273,6 +1278,18 @@
        return 2;
 }
 
+int parse_geometry(string const & arg1, string const &)
+{
+       geometryArg = arg1;
+       if (os::shell() == os::UNIX)
+               // don't remove "-geometry"
+               return -1;
+       else  
+               // remove on Windows also the arg
+               return 1;
+}
+
+
 } // namespace anon
 
 
@@ -1293,15 +1310,12 @@
        cmdmap["--export"] = parse_export;
        cmdmap["-i"] = parse_import;
        cmdmap["--import"] = parse_import;
+       cmdmap["-geometry"] = parse_geometry;
 
        for (int i = 1; i < argc; ++i) {
                std::map<string, cmd_helper>::const_iterator it
                        = cmdmap.find(argv[i]);
 
-               // check for X11 -geometry option
-               if (support::compare(argv[i], "-geometry") == 0)
-                       geometryOption_ = true;
-
                // don't complain if not found - may be parsed later
                if (it == cmdmap.end())
                        continue;
Index: src/lyx_main.h
===================================================================
--- src/lyx_main.h      (Revision 16104)
+++ src/lyx_main.h      (Arbeitskopie)
@@ -163,9 +163,6 @@
        /// Use the Pimpl idiom to hide the internals.
        struct Singletons;
        boost::scoped_ptr<Singletons> pimpl_;
-
-       ///
-       bool geometryOption_;
 };
 
 } // namespace lyx

Reply via email to