remove unused includes
[blender-staging.git] / source / blender / editors / interface / view2d_ops.c
index bd1c734b870ae6ecc311dfd9e210d9232b8d4d46..8611f6dd4ea0acda766dbdaf4c7bd45a0eb7884c 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2008 Blender Foundation.
  * All rights reserved.
 
 #include "MEM_guardedalloc.h"
 
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
-#include "DNA_vec_types.h"
-#include "DNA_view2d_types.h"
 
 #include "BLI_blenlib.h"
 
 #include "BKE_context.h"
-#include "BKE_utildefines.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -51,7 +45,6 @@
 
 #include "ED_screen.h"
 
-#include "UI_resources.h"
 #include "UI_view2d.h"
 
 static int view2d_poll(bContext *C)
@@ -78,6 +71,7 @@ static int view2d_poll(bContext *C)
 typedef struct v2dViewPanData {
        bScreen *sc;                    /* screen where view pan was initiated */
        ScrArea *sa;                    /* area where view pan was initiated */
+       ARegion *ar;                    /* region where view pan was initiated */
        View2D *v2d;                    /* view2d we're operating in */
        
        float facx, facy;               /* amount to move view relative to zoom */
@@ -114,6 +108,7 @@ static int view_pan_init(bContext *C, wmOperator *op)
        vpd->sc= CTX_wm_screen(C);
        vpd->sa= CTX_wm_area(C);
        vpd->v2d= v2d;
+       vpd->ar = ar;
        
        /* calculate translation factor - based on size of view */
        winx= (float)(ar->winrct.xmax - ar->winrct.xmin + 1);
@@ -149,8 +144,17 @@ static void view_pan_apply(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(vpd->sa);
+       ED_region_tag_redraw(vpd->ar);
+       
        UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
+       
+       /* exceptions */
+       if (vpd->sa->spacetype==SPACE_OUTLINER) {
+               /* don't rebuild full tree, since we're just changing our view */
+               SpaceOops *soops= vpd->sa->spacedata.first;
+               soops->storeflag |= SO_TREESTORE_REDRAW;
+       }
 }
 
 /* cleanup temp customdata  */
@@ -192,6 +196,16 @@ static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
        /* set initial settings */
        vpd->startx= vpd->lastx= event->x;
        vpd->starty= vpd->lasty= event->y;
+
+       if (event->type == MOUSEPAN) {
+               RNA_int_set(op->ptr, "deltax", event->prevx - event->x);
+               RNA_int_set(op->ptr, "deltay", event->prevy - event->y);
+               
+               view_pan_apply(C, op);
+               view_pan_exit(C, op);
+               return OPERATOR_FINISHED;
+       }
+       
        RNA_int_set(op->ptr, "deltax", 0);
        RNA_int_set(op->ptr, "deltay", 0);
        
@@ -203,7 +217,7 @@ static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
                WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
        
        /* add temp handler */
-       WM_event_add_modal_handler(C, &window->handlers, op);
+       WM_event_add_modal_handler(C, op);
 
        return OPERATOR_RUNNING_MODAL;
 }
@@ -228,8 +242,22 @@ static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
                }
                        break;
                        
+               case LEFTMOUSE:
+                       /* switch to zoom */
+                       if (event->val==KM_PRESS) {
+                               /* calculate overall delta mouse-movement for redo */
+                               RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
+                               RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
+                               
+                               view_pan_exit(C, op);
+                               WM_cursor_restore(CTX_wm_window(C));
+                               
+                               WM_operator_name_call(C, "VIEW2D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL);
+                               return OPERATOR_FINISHED;
+                       }
                case MIDDLEMOUSE:
-                       if (event->val==0) {
+               case ESCKEY:
+                       if (event->val==KM_RELEASE) {
                                /* calculate overall delta mouse-movement for redo */
                                RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
                                RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
@@ -245,19 +273,27 @@ static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
        return OPERATOR_RUNNING_MODAL;
 }
 
+static int view_pan_cancel(bContext *C, wmOperator *op)
+{
+       view_pan_exit(C, op);
+       return OPERATOR_CANCELLED;
+}
+
 void VIEW2D_OT_pan(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Pan View";
+       ot->description= "Pan the view";
        ot->idname= "VIEW2D_OT_pan";
        
        /* api callbacks */
        ot->exec= view_pan_exec;
        ot->invoke= view_pan_invoke;
        ot->modal= view_pan_modal;
+       ot->cancel= view_pan_cancel;
        
-       /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       /* operator is modal */
+       ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
@@ -297,14 +333,12 @@ void VIEW2D_OT_scroll_right(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Scroll Right";
+       ot->description= "Scroll the view right";
        ot->idname= "VIEW2D_OT_scroll_right";
        
        /* api callbacks */
        ot->exec= view_scrollright_exec;
        
-       /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
-       
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
@@ -343,14 +377,12 @@ void VIEW2D_OT_scroll_left(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Scroll Left";
+       ot->description= "Scroll the view left";
        ot->idname= "VIEW2D_OT_scroll_left";
        
        /* api callbacks */
        ot->exec= view_scrollleft_exec;
        
-       /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
-       
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
@@ -375,7 +407,7 @@ static int view_scrolldown_exec(bContext *C, wmOperator *op)
        
        /* set RNA-Props */
        RNA_int_set(op->ptr, "deltax", 0);
-       RNA_int_set(op->ptr, "deltay", -20);
+       RNA_int_set(op->ptr, "deltay", -40);
        
        /* apply movement, then we're done */
        view_pan_apply(C, op);
@@ -388,14 +420,12 @@ void VIEW2D_OT_scroll_down(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Scroll Down";
+       ot->description= "Scroll the view down";
        ot->idname= "VIEW2D_OT_scroll_down";
        
        /* api callbacks */
        ot->exec= view_scrolldown_exec;
        
-       /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
-       
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
@@ -421,7 +451,7 @@ static int view_scrollup_exec(bContext *C, wmOperator *op)
        
        /* set RNA-Props */
        RNA_int_set(op->ptr, "deltax", 0);
-       RNA_int_set(op->ptr, "deltay", 20);
+       RNA_int_set(op->ptr, "deltay", 40);
        
        /* apply movement, then we're done */
        view_pan_apply(C, op);
@@ -434,14 +464,12 @@ void VIEW2D_OT_scroll_up(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Scroll Up";
+       ot->description= "Scroll the view up";
        ot->idname= "VIEW2D_OT_scroll_up";
        
        /* api callbacks */
        ot->exec= view_scrollup_exec;
        
-       /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
-       
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX);
@@ -462,9 +490,47 @@ void VIEW2D_OT_scroll_up(wmOperatorType *ot)
  */
 
 /* ------------------ 'Shared' stuff ------------------------ */
+
+/* temp customdata for operator */
+typedef struct v2dViewZoomData {
+       View2D *v2d;                    /* view2d we're operating in */
+       ARegion *ar;
+       
+       int lastx, lasty;               /* previous x/y values of mouse in window */
+       float dx, dy;                   /* running tally of previous delta values (for obtaining final zoom) */
+       float mx_2d, my_2d;             /* initial mouse location in v2d coords */
+} v2dViewZoomData;
+
+
+/* initialise panning customdata */
+static int view_zoomdrag_init(bContext *C, wmOperator *op)
+{
+       ARegion *ar= CTX_wm_region(C);
+       v2dViewZoomData *vzd;
+       View2D *v2d;
+       
+       /* regions now have v2d-data by default, so check for region */
+       if (ar == NULL)
+               return 0;
+       v2d= &ar->v2d;
+       
+       /* check that 2d-view is zoomable */
+       if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
+               return 0;
+       
+       /* set custom-data for operator */
+       vzd= MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
+       op->customdata= vzd;
+       
+       /* set pointers to owners */
+       vzd->v2d= v2d;
+       vzd->ar = ar;
+       
+       return 1;
+}
+
 /* check if step-zoom can be applied */
-static short view_zoomstep_ok(bContext *C)
+static int view_zoom_poll(bContext *C)
 {
        ARegion *ar= CTX_wm_region(C);
        View2D *v2d;
@@ -485,49 +551,103 @@ static short view_zoomstep_ok(bContext *C)
 /* apply transform to view (i.e. adjust 'cur' rect) */
 static void view_zoomstep_apply(bContext *C, wmOperator *op)
 {
+       v2dViewZoomData *vzd= op->customdata;
        ARegion *ar= CTX_wm_region(C);
        View2D *v2d= &ar->v2d;
-       float dx, dy;
-       
-       /* calculate amount to move view by */
-       dx= (v2d->cur.xmax - v2d->cur.xmin) * (float)RNA_float_get(op->ptr, "zoomfacx");
-       dy= (v2d->cur.ymax - v2d->cur.ymin) * (float)RNA_float_get(op->ptr, "zoomfacy");
+       float dx, dy, facx, facy;
        
+       /* calculate amount to move view by, ensuring symmetry so the
+        * old zoom level is restored after zooming back the same amount 
+        */
+       facx= RNA_float_get(op->ptr, "zoomfacx");
+       facy= RNA_float_get(op->ptr, "zoomfacy");
+
+       if (facx >= 0.0f) {
+               dx= (v2d->cur.xmax - v2d->cur.xmin) * facx;
+               dy= (v2d->cur.ymax - v2d->cur.ymin) * facy;
+       }
+       else {
+               dx= ((v2d->cur.xmax - v2d->cur.xmin)/(1.0f + 2.0f*facx)) * facx;
+               dy= ((v2d->cur.ymax - v2d->cur.ymin)/(1.0f + 2.0f*facy)) * facy;
+       }
+
        /* only resize view on an axis if change is allowed */
        if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
                if (v2d->keepofs & V2D_LOCKOFS_X) {
                        v2d->cur.xmax -= 2*dx;
                }
+               else if (v2d->keepofs & V2D_KEEPOFS_X) {
+                       if (v2d->align & V2D_ALIGN_NO_POS_X)
+                               v2d->cur.xmin += 2*dx;
+                       else
+                               v2d->cur.xmax -= 2*dx;
+               }
                else {
-                       v2d->cur.xmin += dx;
-                       v2d->cur.xmax -= dx;
+                       if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+                               float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / (v2d->cur.xmax-v2d->cur.xmin);
+                               float mval_faci = 1.0 - mval_fac;
+                               float ofs= (mval_fac * dx) - (mval_faci * dx);
+                               
+                               v2d->cur.xmin += ofs + dx;
+                               v2d->cur.xmax += ofs - dx;
+                       }
+                       else {
+                               v2d->cur.xmin += dx;
+                               v2d->cur.xmax -= dx;
+                       }
                }
        }
        if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
                if (v2d->keepofs & V2D_LOCKOFS_Y) {
                        v2d->cur.ymax -= 2*dy;
                }
+               else if (v2d->keepofs & V2D_KEEPOFS_Y) {
+                       if (v2d->align & V2D_ALIGN_NO_POS_Y)
+                               v2d->cur.ymin += 2*dy;
+                       else
+                               v2d->cur.ymax -= 2*dy;
+               }
                else {
-                       v2d->cur.ymin += dy;
-                       v2d->cur.ymax -= dy;
+                       if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+                               float mval_fac = (vzd->my_2d - v2d->cur.ymin) / (v2d->cur.ymax-v2d->cur.ymin);
+                               float mval_faci = 1.0 - mval_fac;
+                               float ofs= (mval_fac * dy) - (mval_faci * dy);
+                               
+                               v2d->cur.ymin += ofs + dy;
+                               v2d->cur.ymax += ofs - dy;
+                       } 
+                       else {
+                               v2d->cur.ymin += dy;
+                               v2d->cur.ymax -= dy;
+                       }
                }
        }
-       
+
        /* validate that view is in valid configuration after this operation */
        UI_view2d_curRect_validate(v2d);
-       
+
        /* request updates to be done... */
-       ED_area_tag_redraw(CTX_wm_area(C));
+       ED_region_tag_redraw(vzd->ar);
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
 }
 
 /* --------------- Individual Operators ------------------- */
 
+/* cleanup temp customdata  */
+static void view_zoomstep_exit(bContext *C, wmOperator *op)
+{
+       if (op->customdata) {
+               MEM_freeN(op->customdata);
+               op->customdata= NULL;                           
+       }
+}
+
 /* this operator only needs this single callback, where it calls the view_zoom_*() methods */
 static int view_zoomin_exec(bContext *C, wmOperator *op)
 {
        /* check that there's an active region, as View2D data resides there */
-       if (!view_zoomstep_ok(C))
+       if (!view_zoom_poll(C))
                return OPERATOR_PASS_THROUGH;
        
        /* set RNA-Props - zooming in by uniform factor */
@@ -537,33 +657,54 @@ static int view_zoomin_exec(bContext *C, wmOperator *op)
        /* apply movement, then we're done */
        view_zoomstep_apply(C, op);
        
+       view_zoomstep_exit(C, op);
+       
        return OPERATOR_FINISHED;
 }
 
+static int view_zoomin_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       v2dViewZoomData *vzd;
+       
+       if (!view_zoomdrag_init(C, op))
+               return OPERATOR_PASS_THROUGH;
+       
+       vzd= op->customdata;
+       
+       if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+               ARegion *ar= CTX_wm_region(C);
+               
+               /* store initial mouse position (in view space) */
+               UI_view2d_region_to_view(&ar->v2d, 
+                               event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, 
+                               &vzd->mx_2d, &vzd->my_2d);
+       }
+       
+       return view_zoomin_exec(C, op);
+}
+
 void VIEW2D_OT_zoom_in(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Zoom In";
+       ot->description= "Zoom in the view";
        ot->idname= "VIEW2D_OT_zoom_in";
        
        /* api callbacks */
+       ot->invoke= view_zoomin_invoke;
        ot->exec= view_zoomin_exec;
-       
-       /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       ot->poll= view_zoom_poll;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
        RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX);
 }
-
-
-
+       
 /* this operator only needs this single callback, where it callsthe view_zoom_*() methods */
 static int view_zoomout_exec(bContext *C, wmOperator *op)
 {
        /* check that there's an active region, as View2D data resides there */
-       if (!view_zoomstep_ok(C))
+       if (!view_zoom_poll(C))
                return OPERATOR_PASS_THROUGH;
        
        /* set RNA-Props - zooming in by uniform factor */
@@ -572,21 +713,44 @@ static int view_zoomout_exec(bContext *C, wmOperator *op)
        
        /* apply movement, then we're done */
        view_zoomstep_apply(C, op);
+
+       view_zoomstep_exit(C, op);
        
        return OPERATOR_FINISHED;
 }
 
+static int view_zoomout_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       v2dViewZoomData *vzd;
+       
+       if (!view_zoomdrag_init(C, op))
+               return OPERATOR_PASS_THROUGH;
+
+       vzd= op->customdata;
+       
+       if(U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+               ARegion *ar= CTX_wm_region(C);
+               
+               /* store initial mouse position (in view space) */
+               UI_view2d_region_to_view(&ar->v2d, 
+                               event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, 
+                               &vzd->mx_2d, &vzd->my_2d);
+       }
+       
+       return view_zoomout_exec(C, op);
+}
+
 void VIEW2D_OT_zoom_out(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Zoom Out";
+       ot->description= "Zoom out the view";
        ot->idname= "VIEW2D_OT_zoom_out";
        
        /* api callbacks */
+       ot->invoke= view_zoomout_invoke;
        ot->exec= view_zoomout_exec;
-       
-       /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       ot->poll= view_zoom_poll;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
@@ -601,42 +765,6 @@ void VIEW2D_OT_zoom_out(wmOperatorType *ot)
  *     In order to make sure this works, each operator must define the following RNA-Operator Props:
  *             deltax, deltay  - amounts to add to each side of the 'cur' rect
  */
-/* ------------------ Shared 'core' stuff ---------------------- */
-/* temp customdata for operator */
-typedef struct v2dViewZoomData {
-       View2D *v2d;                    /* view2d we're operating in */
-       
-       int lastx, lasty;               /* previous x/y values of mouse in window */
-       float dx, dy;                   /* running tally of previous delta values (for obtaining final zoom) */
-} v2dViewZoomData;
-/* initialise panning customdata */
-static int view_zoomdrag_init(bContext *C, wmOperator *op)
-{
-       ARegion *ar= CTX_wm_region(C);
-       v2dViewZoomData *vzd;
-       View2D *v2d;
-       
-       /* regions now have v2d-data by default, so check for region */
-       if (ar == NULL)
-               return 0;
-       v2d= &ar->v2d;
-       
-       /* check that 2d-view is zoomable */
-       if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
-               return 0;
-       
-       /* set custom-data for operator */
-       vzd= MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
-       op->customdata= vzd;
-       
-       /* set pointers to owners */
-       vzd->v2d= v2d;
-       
-       return 1;
-}
 
 /* apply transform to view (i.e. adjust 'cur' rect) */
 static void view_zoomdrag_apply(bContext *C, wmOperator *op)
@@ -655,8 +783,18 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
                        v2d->cur.xmax -= 2*dx;
                }
                else {
-                       v2d->cur.xmin += dx;
-                       v2d->cur.xmax -= dx;
+                       if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+                               float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / (v2d->cur.xmax-v2d->cur.xmin);
+                               float mval_faci = 1.0 - mval_fac;
+                               float ofs= (mval_fac * dx) - (mval_faci * dx);
+                               
+                               v2d->cur.xmin += ofs + dx;
+                               v2d->cur.xmax += ofs - dx;
+                       }
+                       else {
+                               v2d->cur.xmin += dx;
+                               v2d->cur.xmax -= dx;
+                       }
                }
        }
        if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
@@ -664,8 +802,18 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
                        v2d->cur.ymax -= 2*dy;
                }
                else {
-                       v2d->cur.ymin += dy;
-                       v2d->cur.ymax -= dy;
+                       if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+                               float mval_fac = (vzd->my_2d - v2d->cur.ymin) / (v2d->cur.ymax-v2d->cur.ymin);
+                               float mval_faci = 1.0 - mval_fac;
+                               float ofs= (mval_fac * dy) - (mval_faci * dy);
+                               
+                               v2d->cur.ymin += ofs + dy;
+                               v2d->cur.ymax += ofs - dy;
+                       }
+                       else {
+                               v2d->cur.ymin += dy;
+                               v2d->cur.ymax -= dy;
+                       }
                }
        }
        
@@ -673,8 +821,9 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(CTX_wm_area(C));
+       ED_region_tag_redraw(vzd->ar);
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
 }
 
 /* cleanup temp customdata  */
@@ -711,12 +860,42 @@ static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
        vzd= op->customdata;
        v2d= vzd->v2d;
        
+       if (event->type == MOUSEZOOM) {
+               float dx, dy, fac;
+               
+               vzd->lastx= event->prevx;
+               vzd->lasty= event->prevy;
+               
+               /* As we have only 1D information (magnify value), feed both axes
+                * with magnify information that is stored in x axis 
+                */
+               fac= 0.01f * (event->x - event->prevx);
+               dx= fac * (v2d->cur.xmax - v2d->cur.xmin) / 10.0f;
+               dy= fac * (v2d->cur.ymax - v2d->cur.ymin) / 10.0f;
+
+               RNA_float_set(op->ptr, "deltax", dx);
+               RNA_float_set(op->ptr, "deltay", dy);
+               
+               view_zoomdrag_apply(C, op);
+               view_zoomdrag_exit(C, op);
+               return OPERATOR_FINISHED;
+       }       
+       
        /* set initial settings */
        vzd->lastx= event->x;
        vzd->lasty= event->y;
        RNA_float_set(op->ptr, "deltax", 0);
        RNA_float_set(op->ptr, "deltay", 0);
        
+       if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+               ARegion *ar= CTX_wm_region(C);
+               
+               /* store initial mouse position (in view space) */
+               UI_view2d_region_to_view(&ar->v2d, 
+                               event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, 
+                               &vzd->mx_2d, &vzd->my_2d);
+       }
+
        if (v2d->keepofs & V2D_LOCKOFS_X)
                WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
        else if (v2d->keepofs & V2D_LOCKOFS_Y)
@@ -725,7 +904,7 @@ static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
                WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
        
        /* add temp handler */
-       WM_event_add_modal_handler(C, &window->handlers, op);
+       WM_event_add_modal_handler(C, op);
 
        return OPERATOR_RUNNING_MODAL;
 }
@@ -795,8 +974,9 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
                }
                        break;
                        
+               case LEFTMOUSE:
                case MIDDLEMOUSE:
-                       if (event->val==0) {
+                       if (event->val==KM_RELEASE) {
                                /* for redo, store the overall deltas - need to respect zoom-locks here... */
                                if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0)
                                        RNA_float_set(op->ptr, "deltax", vzd->dx);
@@ -824,6 +1004,7 @@ void VIEW2D_OT_zoom(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Zoom View";
+       ot->description= "Zoom in/out the view";
        ot->idname= "VIEW2D_OT_zoom";
        
        /* api callbacks */
@@ -831,8 +1012,10 @@ void VIEW2D_OT_zoom(wmOperatorType *ot)
        ot->invoke= view_zoomdrag_invoke;
        ot->modal= view_zoomdrag_modal;
        
+       ot->poll= view_zoom_poll;
+       
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       // ot->flag= OPTYPE_BLOCKING;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX);
@@ -856,17 +1039,16 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
        ARegion *ar= CTX_wm_region(C);
        View2D *v2d= &ar->v2d;
        rctf rect;
-       int event_type;
+       int gesture_mode;
        
        /* convert coordinates of rect to 'tot' rect coordinates */
        UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
        UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
        
        /* check if zooming in/out view */
-       // XXX hardcoded for now!
-       event_type= RNA_int_get(op->ptr, "event_type");
+       gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
        
-       if (event_type == LEFTMOUSE) {
+       if (gesture_mode == GESTURE_MODAL_IN) {
                /* zoom in: 
                 *      - 'cur' rect will be defined by the coordinates of the border region 
                 *      - just set the 'cur' rect to have the same coordinates as the border region
@@ -881,7 +1063,7 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
                        v2d->cur.ymax= rect.ymax;
                }
        }
-       else {
+       else /* if (gesture_mode == GESTURE_MODAL_OUT) */ {
                /* zoom out:
                 *      - the current 'cur' rect coordinates are going to end upwhere the 'rect' ones are, 
                 *        but the 'cur' rect coordinates will need to be adjusted to take in more of the view
@@ -912,8 +1094,9 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(CTX_wm_area(C));
+       ED_region_tag_redraw(ar);
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
        
        return OPERATOR_FINISHED;
 } 
@@ -922,6 +1105,7 @@ void VIEW2D_OT_zoom_border(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Zoom to Border";
+       ot->description= "Zoom in the view to the nearest item contained in the border";
        ot->idname= "VIEW2D_OT_zoom_border";
        
        /* api callbacks */
@@ -929,10 +1113,10 @@ void VIEW2D_OT_zoom_border(wmOperatorType *ot)
        ot->exec= view_borderzoom_exec;
        ot->modal= WM_border_select_modal;
        
-       ot->poll= ED_operator_areaactive;
+       ot->poll= view_zoom_poll;
        
        /* rna */
-       RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
@@ -954,6 +1138,7 @@ void VIEW2D_OT_zoom_border(wmOperatorType *ot)
 /* customdata for scroller-invoke data */
 typedef struct v2dScrollerMove {
        View2D *v2d;                    /* View2D data that this operation affects */
+       ARegion *ar;                    /* region that the scroller is in */
        
        short scroller;                 /* scroller that mouse is in ('h' or 'v') */
        short zone;                             /* -1 is min zoomer, 0 is bar, 1 is max zoomer */ // XXX find some way to provide visual feedback of this (active colour?)
@@ -961,6 +1146,8 @@ typedef struct v2dScrollerMove {
        float fac;                              /* view adjustment factor, based on size of region */
        float delta;                    /* amount moved by mouse on axis of interest */
        
+       float scrollbarwidth;   /* width of the scrollbar itself, used for page up/down clicks */
+       
        int lastx, lasty;               /* previous mouse coordinates (in screen coordinates) for determining movement */
 } v2dScrollerMove;
 
@@ -980,19 +1167,21 @@ struct View2DScrollers {
 enum {
        SCROLLHANDLE_MIN= -1,
        SCROLLHANDLE_BAR,
-       SCROLLHANDLE_MAX
+       SCROLLHANDLE_MAX,
+       SCROLLHANDLE_MIN_OUTSIDE,
+       SCROLLHANDLE_MAX_OUTSIDE
 } eV2DScrollerHandle_Zone;
 
 /* ------------------------ */
 
 /* check if mouse is within scroller handle 
  *     - mouse                 =       relevant mouse coordinate in region space
- *     - sc_min, sc_max        =       extents of scroller
- *     - sh_min, sh_max        =       positions of scroller handles
+ *     - sc_min, sc_max        =       extents of scroller 'groove' (potential available space for scroller)
+ *     - sh_min, sh_max        =       positions of scrollbar handles
  */
 static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_min, int sh_max)
 {
-       short in_min, in_max, in_view=1;
+       short in_min, in_max, in_bar, out_min, out_max, in_view=1;
        
        /* firstly, check if 
         *      - 'bubble' fills entire scroller 
@@ -1010,29 +1199,28 @@ static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_
        
        
        if (in_view == 0) {
-               /* handles are only activated if the mouse is within the relative quater lengths of the scroller */
-               int qLen = (sc_max + sc_min) / 4;
-               
-               if (mouse >= (sc_max - qLen))
-                       return SCROLLHANDLE_MAX;
-               else if (mouse <= qLen)
-                       return SCROLLHANDLE_MIN;
-               else
-                       return SCROLLHANDLE_BAR;
+               return SCROLLHANDLE_BAR;
        }
        
        /* check if mouse is in or past either handle */
+       // TODO: check if these extents are still valid or not
        in_max= ( (mouse >= (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse <= (sh_max + V2D_SCROLLER_HANDLE_SIZE)) );
        in_min= ( (mouse <= (sh_min + V2D_SCROLLER_HANDLE_SIZE)) && (mouse >= (sh_min - V2D_SCROLLER_HANDLE_SIZE)) );
+       in_bar= ( (mouse < (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse > (sh_min + V2D_SCROLLER_HANDLE_SIZE)) );
+       out_min= mouse < (sh_min - V2D_SCROLLER_HANDLE_SIZE);
+       out_max= mouse > (sh_max + V2D_SCROLLER_HANDLE_SIZE);
        
-       /* check if overlap --> which means user clicked on bar, as bar is within handles region */
-       if (in_max && in_min)
+       if (in_bar)
                return SCROLLHANDLE_BAR;
        else if (in_max)
                return SCROLLHANDLE_MAX;
        else if (in_min)
                return SCROLLHANDLE_MIN;
-               
+       else if (out_min)
+               return SCROLLHANDLE_MIN_OUTSIDE;                          
+       else if (out_max)
+               return SCROLLHANDLE_MAX_OUTSIDE;
+       
        /* unlikely to happen, though we just cover it in case */
        return SCROLLHANDLE_BAR;
 } 
@@ -1053,6 +1241,7 @@ static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event,
        
        /* set general data */
        vsm->v2d= v2d;
+       vsm->ar= ar;
        vsm->scroller= in_scroller;
        
        /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */
@@ -1071,14 +1260,14 @@ static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event,
                vsm->fac= (v2d->tot.xmax - v2d->tot.xmin) / mask_size;
                
                /* get 'zone' (i.e. which part of scroller is activated) */
-               if (v2d->keepzoom & V2D_LOCKZOOM_X) {
+               vsm->zone= mouse_in_scroller_handle(x, v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max); 
+               
+               if ((v2d->keepzoom & V2D_LOCKZOOM_X) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) {
                        /* default to scroll, as handles not usable */
                        vsm->zone= SCROLLHANDLE_BAR;
                }
-               else {
-                       /* check which handle we're in */
-                       vsm->zone= mouse_in_scroller_handle(x, v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max); 
-               }
+
+               vsm->scrollbarwidth = scrollers->hor_max - scrollers->hor_min;
        }
        else {
                /* vertical scroller - calculate adjustment factor first */
@@ -1086,24 +1275,32 @@ static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event,
                vsm->fac= (v2d->tot.ymax - v2d->tot.ymin) / mask_size;
                
                /* get 'zone' (i.e. which part of scroller is activated) */
-               if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
+               vsm->zone= mouse_in_scroller_handle(y, v2d->vert.ymin, v2d->vert.ymax, scrollers->vert_min, scrollers->vert_max); 
+                       
+               if ((v2d->keepzoom & V2D_LOCKZOOM_Y) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) {
                        /* default to scroll, as handles not usable */
                        vsm->zone= SCROLLHANDLE_BAR;
                }
-               else {
-                       /* check which handle we're in */
-                       vsm->zone= mouse_in_scroller_handle(y, v2d->vert.ymin, v2d->vert.ymax, scrollers->vert_min, scrollers->vert_max); 
-               }
+               
+               vsm->scrollbarwidth = scrollers->vert_max - scrollers->vert_min;
        }
+       
        UI_view2d_scrollers_free(scrollers);
+       ED_region_tag_redraw(ar);
 }
 
 /* cleanup temp customdata  */
 static void scroller_activate_exit(bContext *C, wmOperator *op)
 {
        if (op->customdata) {
+               v2dScrollerMove *vsm= op->customdata;
+
+               vsm->v2d->scroll_ui &= ~(V2D_SCROLL_H_ACTIVE|V2D_SCROLL_V_ACTIVE);
+               
                MEM_freeN(op->customdata);
-               op->customdata= NULL;                           
+               op->customdata= NULL;           
+               
+               ED_region_tag_redraw(CTX_wm_region(C));
        }
 } 
 
@@ -1126,16 +1323,20 @@ static void scroller_activate_apply(bContext *C, wmOperator *op)
                        if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
                                v2d->cur.ymin -= temp;
                        break;
-               
+                       
                case SCROLLHANDLE_MAX:
+                       
                        /* only expand view on axis if zoom is allowed */
                        if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
                                v2d->cur.xmax += temp;
                        if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
                                v2d->cur.ymax += temp;
                        break;
-               
-               default: /* SCROLLHANDLE_BAR */
+                       
+               case SCROLLHANDLE_MIN_OUTSIDE:
+               case SCROLLHANDLE_MAX_OUTSIDE:
+               case SCROLLHANDLE_BAR:
+               default:
                        /* only move view on an axis if panning is allowed */
                        if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) {
                                v2d->cur.xmin += temp;
@@ -1146,14 +1347,16 @@ static void scroller_activate_apply(bContext *C, wmOperator *op)
                                v2d->cur.ymax += temp;
                        }
                        break;
+                       
        }
        
        /* validate that view is in valid configuration after this operation */
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(CTX_wm_area(C));
+       ED_region_tag_redraw(vsm->ar);
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
 }
 
 /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
@@ -1166,7 +1369,7 @@ static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
                case MOUSEMOVE:
                {
                        /* calculate new delta transform, then store mouse-coordinates for next-time */
-                       if (vsm->zone != SCROLLHANDLE_MIN) {
+                       if (ELEM(vsm->zone, SCROLLHANDLE_BAR, SCROLLHANDLE_MAX)) {
                                /* if using bar (i.e. 'panning') or 'max' zoom widget */
                                switch (vsm->scroller) {
                                        case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves opposite to mouse) */
@@ -1177,7 +1380,7 @@ static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
                                                break;
                                }
                        }
-                       else {
+                       else if (vsm->zone == SCROLLHANDLE_MIN) {
                                /* using 'min' zoom widget */
                                switch (vsm->scroller) {
                                        case 'h': /* horizontal scroller - so only horizontal movement ('cur' moves with mouse) */
@@ -1198,9 +1401,24 @@ static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
                        break;
                        
                case LEFTMOUSE:
-                       if (event->val==0) {
-                               scroller_activate_exit(C, op);
-                               return OPERATOR_FINISHED;
+                       if (event->val==KM_RELEASE) {
+                               /* single-click was in empty space outside bubble, so scroll by 1 'page' */
+                               if (ELEM(vsm->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
+                                       if (vsm->zone == SCROLLHANDLE_MIN_OUTSIDE)
+                                               vsm->delta = -vsm->scrollbarwidth * 0.8;
+                                       else if (vsm->zone == SCROLLHANDLE_MAX_OUTSIDE)
+                                               vsm->delta = vsm->scrollbarwidth * 0.8;
+                                       
+                                       scroller_activate_apply(C, op);
+                                       scroller_activate_exit(C, op);
+                                       return OPERATOR_FINISHED;
+                               }
+                               
+                               /* otherwise, end the drag action  */
+                               if (vsm->lastx || vsm->lasty) {
+                                       scroller_activate_exit(C, op);
+                                       return OPERATOR_FINISHED;
+                               }
                        }
                        break;
        }
@@ -1227,6 +1445,18 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
                scroller_activate_init(C, op, event, in_scroller);
                vsm= (v2dScrollerMove *)op->customdata;
                
+               /* check if zoom zones are inappropriate (i.e. zoom widgets not shown), so cannot continue
+                * NOTE: see view2d.c for latest conditions, and keep this in sync with that
+                */
+               if (ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) {
+                       if ( ((vsm->scroller=='h') && (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL)==0) ||
+                                ((vsm->scroller=='v') && (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL)==0) )
+                       {
+                               /* switch to bar (i.e. no scaling gets handled) */
+                               vsm->zone= SCROLLHANDLE_BAR;
+                       }
+               }
+               
                /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */
                if (vsm->zone == SCROLLHANDLE_BAR) {
                        if ( ((vsm->scroller=='h') && (v2d->keepofs & V2D_LOCKOFS_X)) ||
@@ -1240,8 +1470,26 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        }                       
                }
                
+               /* zone is also inappropriate if scroller is not visible... */
+               if ( ((vsm->scroller=='h') && (v2d->scroll & (V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_HORIZONTAL_FULLR))) ||
+                        ((vsm->scroller=='v') && (v2d->scroll & (V2D_SCROLL_VERTICAL_HIDE|V2D_SCROLL_VERTICAL_FULLR))) )
+               {
+                       /* free customdata initialised */
+                       scroller_activate_exit(C, op);
+                               
+                       /* can't catch this event for ourselves, so let it go to someone else? */
+                       // FIXME: still this doesn't fall through to the item_activate callback for the outliner...
+                       return OPERATOR_PASS_THROUGH;
+               }
+               
+               /* activate the scroller */
+               if (vsm->scroller=='h')
+                       v2d->scroll_ui |= V2D_SCROLL_H_ACTIVE;
+               else
+                       v2d->scroll_ui |= V2D_SCROLL_V_ACTIVE;
+               
                /* still ok, so can add */
-               WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+               WM_event_add_modal_handler(C, op);
                return OPERATOR_RUNNING_MODAL;
        }
        else {
@@ -1255,7 +1503,11 @@ void VIEW2D_OT_scroller_activate(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Scroller Activate";
+       ot->description= "Scroll view by mouse click and drag";
        ot->idname= "VIEW2D_OT_scroller_activate";
+
+       /* flags */
+       ot->flag= OPTYPE_BLOCKING;
        
        /* api callbacks */
        ot->invoke= scroller_activate_invoke;
@@ -1268,6 +1520,7 @@ void VIEW2D_OT_scroller_activate(wmOperatorType *ot)
 
 static int reset_exec(bContext *C, wmOperator *op)
 {
+       uiStyle *style= U.uistyles.first;
        ARegion *ar= CTX_wm_region(C);
        View2D *v2d= &ar->v2d;
        int winx, winy;
@@ -1278,26 +1531,26 @@ static int reset_exec(bContext *C, wmOperator *op)
 
        v2d->cur.xmax= v2d->cur.xmin + winx;
        v2d->cur.ymax= v2d->cur.ymin + winy;
-
+       
        /* align */
-       if(v2d->align) {
+       if (v2d->align) {
                /* posx and negx flags are mutually exclusive, so watch out */
                if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
                        v2d->cur.xmax= 0.0f;
-                       v2d->cur.xmin= v2d->winx;
+                       v2d->cur.xmin= -winx*style->panelzoom;
                }
                else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
-                       v2d->cur.xmax= v2d->cur.xmax - v2d->cur.xmin;
+                       v2d->cur.xmax= winx*style->panelzoom;
                        v2d->cur.xmin= 0.0f;
                }
 
                /* - posx and negx flags are mutually exclusive, so watch out */
                if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
                        v2d->cur.ymax= 0.0f;
-                       v2d->cur.ymin= -v2d->winy;
+                       v2d->cur.ymin= -winy*style->panelzoom;
                }
                else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
-                       v2d->cur.ymax= v2d->cur.ymax - v2d->cur.ymin;
+                       v2d->cur.ymax= winy*style->panelzoom;
                        v2d->cur.ymin= 0.0f;
                }
        }
@@ -1306,8 +1559,9 @@ static int reset_exec(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(CTX_wm_area(C));
+       ED_region_tag_redraw(ar);
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
        
        return OPERATOR_FINISHED;
 }
@@ -1316,20 +1570,18 @@ void VIEW2D_OT_reset(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Reset View";
+       ot->description= "Reset the view";
        ot->idname= "VIEW2D_OT_reset";
        
        /* api callbacks */
        ot->exec= reset_exec;
        ot->poll= view2d_poll;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
  
 /* ********************************************************* */
 /* Registration */
 
-void ui_view2d_operatortypes(void)
+void UI_view2d_operatortypes(void)
 {
        WM_operatortype_append(VIEW2D_OT_pan);
        
@@ -1349,14 +1601,16 @@ void ui_view2d_operatortypes(void)
        WM_operatortype_append(VIEW2D_OT_reset);
 }
 
-void UI_view2d_keymap(wmWindowManager *wm)
+void UI_view2d_keymap(wmKeyConfig *keyconf)
 {
-       ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
+       wmKeyMap *keymap= WM_keymap_find(keyconf, "View2D", 0, 0);
        
        /* pan/scroll */
        WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
        
+       WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MOUSEPAN, 0, 0, 0);
+       
        WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
        
@@ -1377,8 +1631,21 @@ void UI_view2d_keymap(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, 0, 0);
        
+       /* alternatives for page up/down to scroll */
+#if 0 // XXX disabled, since this causes conflicts with hotkeys in animation editors
+               /* scroll up/down may fall through to left/right */
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", PAGEDOWNKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", PAGEUPKEY, KM_PRESS, 0, 0);
+               /* shift for moving view left/right with page up/down */
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0);
+#endif
+       
        /* zoom - drag */
        WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEZOOM, 0, 0, 0);
        
        /* borderzoom - drag */
        WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
@@ -1387,13 +1654,18 @@ void UI_view2d_keymap(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
 
        /* Alternative keymap for buttons listview */
-       keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0);
+       keymap= WM_keymap_find(keyconf, "View2D Buttons List", 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MOUSEPAN, 0, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEZOOM, 0, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "VIEW2D_OT_reset", HOMEKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
 }