]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/gtk/GWorkArea.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / gtk / GWorkArea.C
index 2044cd4258f893d876f5c72191b80c71942ab5df..4442e4b0c8ec6ec35246d89faa34996026291604 100644 (file)
@@ -9,8 +9,11 @@
  */
 
 #include <config.h>
-#include <gtkmm.h>
-#include <X11/Xft/Xft.h>
+
+// Too hard to make concept checks work with this file
+#ifdef _GLIBCPP_CONCEPT_CHECKS
+#undef _GLIBCPP_CONCEPT_CHECKS
+#endif
 
 #include "GWorkArea.h"
 #include "GView.h"
 #include "funcrequest.h"
 #include "LColor.h"
 
+using boost::shared_ptr;
+
 using std::string;
 
 namespace lyx {
 namespace frontend {
 
-ColorCache colorCache;
-
+namespace {
+
+mouse_button::state gButtonToLyx(guint gdkbutton)
+{
+       // GDK uses int 1,2,3 but lyx uses enums (1,2,4)
+       switch (gdkbutton) {
+       case 1:
+               return mouse_button::button1;
+       case 2:
+               return mouse_button::button2;
+       case 3:
+               return mouse_button::button3;
+       case 4:
+               return mouse_button::button4;
+       case 5:
+               return mouse_button::button5;
+       }
 
-ColorCache::~ColorCache()
-{
-       clear();
+       // This shouldn't happen, according to gdk docs
+       lyxerr << "gButtonToLyx: unhandled button index\n";
+       return mouse_button::button1;
 }
 
+} // namespace anon
+
+ColorCache colorCache;
 
 Gdk::Color * ColorCache::getColor(LColor_color clr)
 {
        MapIt it = cache_.find(clr);
-       return it == cache_.end() ? 0 : it->second;
+       return it == cache_.end() ? 0 : it->second.get();
 }
 
 
 XftColor * ColorCache::getXftColor(LColor_color clr)
 {
        MapIt2 it = cache2_.find(clr);
-       return it == cache2_.end() ? 0 : it->second;
+       return it == cache2_.end() ? 0 : it->second.get();
 }
 
 
 void ColorCache::cacheColor(LColor_color clr, Gdk::Color * gclr)
 {
-       cache_[clr] = gclr;
+       cache_[clr] = shared_ptr<Gdk::Color>(gclr);
 }
 
 
 void ColorCache::cacheXftColor(LColor_color clr, XftColor * xclr)
 {
-       cache2_[clr] = xclr;
+       cache2_[clr] = shared_ptr<XftColor>(xclr);
 }
 
 
 void ColorCache::clear()
 {
-       MapIt it = cache_.begin();
-       for (; it != cache_.end(); ++it)
-               delete it->second;
        cache_.clear();
-       MapIt2 it2 = cache2_.begin();
-       for (; it2 != cache2_.end(); ++it2)
-               delete it2->second;
        cache2_.clear();
 }
 
@@ -160,22 +177,22 @@ GWorkArea::GWorkArea(LyXView & owner, int width, int height)
                             Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK |
                             Gdk::KEY_PRESS_MASK | Gdk::BUTTON1_MOTION_MASK);
        workArea_.signal_expose_event().connect(
-               SigC::slot(*this, &GWorkArea::onExpose));
+               sigc::mem_fun(*this, &GWorkArea::onExpose));
        workArea_.signal_configure_event().connect(
-               SigC::slot(*this, &GWorkArea::onConfigure));
+               sigc::mem_fun(*this, &GWorkArea::onConfigure));
        workArea_.signal_button_press_event().connect(
-               SigC::slot(*this, &GWorkArea::onButtonPress));
+               sigc::mem_fun(*this, &GWorkArea::onButtonPress));
        workArea_.signal_button_release_event().connect(
-               SigC::slot(*this, &GWorkArea::onButtonRelease));
+               sigc::mem_fun(*this, &GWorkArea::onButtonRelease));
        workArea_.signal_key_press_event().connect(
-               SigC::slot(*this, &GWorkArea::onKeyPress));
+               sigc::mem_fun(*this, &GWorkArea::onKeyPress));
        workArea_.signal_motion_notify_event().connect(
-               SigC::slot(*this, &GWorkArea::onMotionNotify));
+               sigc::mem_fun(*this, &GWorkArea::onMotionNotify));
        workArea_.show();
        vscrollbar_.get_adjustment()->signal_value_changed().connect(
-               SigC::slot(*this, &GWorkArea::onScroll));
+               sigc::mem_fun(*this, &GWorkArea::onScroll));
        workArea_.signal_scroll_event().connect(
-               SigC::slot(*this, &GWorkArea::onScrollWheel));
+               sigc::mem_fun(*this, &GWorkArea::onScrollWheel));
        vscrollbar_.show();
        hbox_.children().push_back(Gtk::Box_Helpers::Element(workArea_));
        hbox_.children().push_back(
@@ -327,9 +344,11 @@ void GWorkArea::setScrollbarParams(int height, int pos, int line_height)
                adjustment->changed();
                return;
        }
-       adjustment->set_step_increment(line_height);
+       adjustment->set_step_increment(line_height * 3);
        adjustment->set_page_increment(workAreaHeight - line_height);
-       adjustment->set_upper(height);
+       // Allow the user half a screen of blank at the end
+       // to make scrollbar consistant with centering the cursor
+       adjustment->set_upper(height + workAreaHeight / 2);
        adjustment->set_page_size(workAreaHeight);
        adjustment->set_value(pos);
        adjustment->changed();
@@ -356,8 +375,14 @@ bool GWorkArea::onScrollWheel(GdkEventScroll * event)
        if (event->direction == GDK_SCROLL_UP)
                step *= -1.0f;
 
-       adjustment->set_value(adjustment->get_value() + step);
+       double target = adjustment->get_value() + step;
+       // Prevent the user getting a whole screen of blank when they
+       // try to scroll past the end of the doc
+       double max = adjustment->get_upper() - workHeight();
+       if (target > max)
+               target = max;
 
+       adjustment->set_value(target);
        return true;
 }
 
@@ -381,7 +406,7 @@ bool GWorkArea::onButtonPress(GdkEventButton * event)
        dispatch(FuncRequest(ka,
                             static_cast<int>(event->x),
                             static_cast<int>(event->y),
-                            static_cast<mouse_button::state>(event->button)));
+                            gButtonToLyx(event->button)));
        workArea_.grab_focus();
        return true;
 }
@@ -392,7 +417,7 @@ bool GWorkArea::onButtonRelease(GdkEventButton * event)
        dispatch(FuncRequest(LFUN_MOUSE_RELEASE,
                             static_cast<int>(event->x),
                             static_cast<int>(event->y),
-                            static_cast<mouse_button::state>(event->button)));
+                            gButtonToLyx(event->button)));
        return true;
 }
 
@@ -469,9 +494,9 @@ void GWorkArea::haveSelection(bool toHave) const
                std::vector<Gtk::TargetEntry> listTargets;
                listTargets.push_back(Gtk::TargetEntry("UTF8_STRING"));
                clipboard->set(listTargets,
-                              SigC::slot(const_cast<GWorkArea&>(*this),
+                              sigc::mem_fun(const_cast<GWorkArea&>(*this),
                                          &GWorkArea::onClipboardGet),
-                              SigC::slot(const_cast<GWorkArea&>(*this),
+                              sigc::mem_fun(const_cast<GWorkArea&>(*this),
                                          &GWorkArea::onClipboardClear));
        }
 }