123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- /*
- Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
- Available via Academic Free License >= 2.1 OR the modified BSD license.
- see: http://dojotoolkit.org/license for details
- */
- if(!dojo._hasResource["dojox.grid._Events"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
- dojo._hasResource["dojox.grid._Events"] = true;
- dojo.provide("dojox.grid._Events");
- dojo.declare("dojox.grid._Events", null, {
- // summary:
- // _Grid mixin that provides default implementations for grid events.
- // description:
- // Default synthetic events dispatched for _Grid. dojo.connect to events to
- // retain default implementation or override them for custom handling.
-
- // cellOverClass: String
- // css class to apply to grid cells over which the cursor is placed.
- cellOverClass: "dojoxGridCellOver",
-
- onKeyEvent: function(e){
- // summary: top level handler for Key Events
- this.dispatchKeyEvent(e);
- },
- onContentEvent: function(e){
- // summary: Top level handler for Content events
- this.dispatchContentEvent(e);
- },
- onHeaderEvent: function(e){
- // summary: Top level handler for header events
- this.dispatchHeaderEvent(e);
- },
- onStyleRow: function(inRow){
- // summary:
- // Perform row styling on a given row. Called whenever row styling is updated.
- //
- // inRow: Object
- // Object containing row state information: selected, true if the row is selcted; over:
- // true of the mouse is over the row; odd: true if the row is odd. Use customClasses and
- // customStyles to control row css classes and styles; both properties are strings.
- //
- // example: onStyleRow({ selected: true, over:true, odd:false })
- var i = inRow;
- i.customClasses += (i.odd?" dojoxGridRowOdd":"") + (i.selected?" dojoxGridRowSelected":"") + (i.over?" dojoxGridRowOver":"");
- this.focus.styleRow(inRow);
- this.edit.styleRow(inRow);
- },
-
- onKeyDown: function(e){
- // summary:
- // Grid key event handler. By default enter begins editing and applies edits, escape cancels an edit,
- // tab, shift-tab, and arrow keys move grid cell focus.
- if(e.altKey || e.metaKey){
- return;
- }
- var dk = dojo.keys;
- var colIdx;
- switch(e.keyCode){
- case dk.ESCAPE:
- this.edit.cancel();
- break;
- case dk.ENTER:
- if(!this.edit.isEditing()){
- colIdx = this.focus.getHeaderIndex();
- if(colIdx >= 0) {
- this.setSortIndex(colIdx);
- break;
- }else {
- this.selection.clickSelect(this.focus.rowIndex, dojo.isCopyKey(e), e.shiftKey);
- }
- dojo.stopEvent(e);
- }
- if(!e.shiftKey){
- var isEditing = this.edit.isEditing();
- this.edit.apply();
- if(!isEditing){
- this.edit.setEditCell(this.focus.cell, this.focus.rowIndex);
- }
- }
- if (!this.edit.isEditing()){
- var curView = this.focus.focusView || this.views.views[0]; //if no focusView than only one view
- curView.content.decorateEvent(e);
- this.onRowClick(e);
- dojo.stopEvent(e);
- }
- break;
- case dk.SPACE:
- if(!this.edit.isEditing()){
- colIdx = this.focus.getHeaderIndex();
- if(colIdx >= 0) {
- this.setSortIndex(colIdx);
- break;
- }else {
- this.selection.clickSelect(this.focus.rowIndex, dojo.isCopyKey(e), e.shiftKey);
- }
- dojo.stopEvent(e);
- }
- break;
- case dk.TAB:
- this.focus[e.shiftKey ? 'previousKey' : 'nextKey'](e);
- break;
- case dk.LEFT_ARROW:
- case dk.RIGHT_ARROW:
- if(!this.edit.isEditing()){
- var keyCode = e.keyCode; // IE seems to lose after stopEvent when modifier keys
- dojo.stopEvent(e);
- colIdx = this.focus.getHeaderIndex();
- if (colIdx >= 0 && (e.shiftKey && e.ctrlKey)){
- this.focus.colSizeAdjust(e, colIdx, (keyCode == dk.LEFT_ARROW ? -1 : 1)*5);
- }
- else{
- var offset = (keyCode == dk.LEFT_ARROW) ? 1 : -1;
- if(dojo._isBodyLtr()){ offset *= -1; }
- this.focus.move(0, offset);
- }
- }
- break;
- case dk.UP_ARROW:
- if(!this.edit.isEditing() && this.focus.rowIndex !== 0){
- dojo.stopEvent(e);
- this.focus.move(-1, 0);
- }
- break;
- case dk.DOWN_ARROW:
- if(!this.edit.isEditing() && this.focus.rowIndex+1 != this.rowCount){
- dojo.stopEvent(e);
- this.focus.move(1, 0);
- }
- break;
- case dk.PAGE_UP:
- if(!this.edit.isEditing() && this.focus.rowIndex !== 0){
- dojo.stopEvent(e);
- if(this.focus.rowIndex != this.scroller.firstVisibleRow+1){
- this.focus.move(this.scroller.firstVisibleRow-this.focus.rowIndex, 0);
- }else{
- this.setScrollTop(this.scroller.findScrollTop(this.focus.rowIndex-1));
- this.focus.move(this.scroller.firstVisibleRow-this.scroller.lastVisibleRow+1, 0);
- }
- }
- break;
- case dk.PAGE_DOWN:
- if(!this.edit.isEditing() && this.focus.rowIndex+1 != this.rowCount){
- dojo.stopEvent(e);
- if(this.focus.rowIndex != this.scroller.lastVisibleRow-1){
- this.focus.move(this.scroller.lastVisibleRow-this.focus.rowIndex-1, 0);
- }else{
- this.setScrollTop(this.scroller.findScrollTop(this.focus.rowIndex+1));
- this.focus.move(this.scroller.lastVisibleRow-this.scroller.firstVisibleRow-1, 0);
- }
- }
- break;
- default:
- break;
- }
- },
-
- onMouseOver: function(e){
- // summary:
- // Event fired when mouse is over the grid.
- // e: Event
- // Decorated event object contains reference to grid, cell, and rowIndex
- e.rowIndex == -1 ? this.onHeaderCellMouseOver(e) : this.onCellMouseOver(e);
- },
-
- onMouseOut: function(e){
- // summary:
- // Event fired when mouse moves out of the grid.
- // e: Event
- // Decorated event object that contains reference to grid, cell, and rowIndex
- e.rowIndex == -1 ? this.onHeaderCellMouseOut(e) : this.onCellMouseOut(e);
- },
-
- onMouseDown: function(e){
- // summary:
- // Event fired when mouse is down inside grid.
- // e: Event
- // Decorated event object that contains reference to grid, cell, and rowIndex
- e.rowIndex == -1 ? this.onHeaderCellMouseDown(e) : this.onCellMouseDown(e);
- },
-
- onMouseOverRow: function(e){
- // summary:
- // Event fired when mouse is over any row (data or header).
- // e: Event
- // Decorated event object contains reference to grid, cell, and rowIndex
- if(!this.rows.isOver(e.rowIndex)){
- this.rows.setOverRow(e.rowIndex);
- e.rowIndex == -1 ? this.onHeaderMouseOver(e) : this.onRowMouseOver(e);
- }
- },
- onMouseOutRow: function(e){
- // summary:
- // Event fired when mouse moves out of any row (data or header).
- // e: Event
- // Decorated event object contains reference to grid, cell, and rowIndex
- if(this.rows.isOver(-1)){
- this.onHeaderMouseOut(e);
- }else if(!this.rows.isOver(-2)){
- this.rows.setOverRow(-2);
- this.onRowMouseOut(e);
- }
- },
-
- onMouseDownRow: function(e){
- // summary:
- // Event fired when mouse is down inside grid row
- // e: Event
- // Decorated event object that contains reference to grid, cell, and rowIndex
- if(e.rowIndex != -1)
- this.onRowMouseDown(e);
- },
- // cell events
- onCellMouseOver: function(e){
- // summary:
- // Event fired when mouse is over a cell.
- // e: Event
- // Decorated event object contains reference to grid, cell, and rowIndex
- if(e.cellNode){
- dojo.addClass(e.cellNode, this.cellOverClass);
- }
- },
-
- onCellMouseOut: function(e){
- // summary:
- // Event fired when mouse moves out of a cell.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- if(e.cellNode){
- dojo.removeClass(e.cellNode, this.cellOverClass);
- }
- },
-
- onCellMouseDown: function(e){
- // summary:
- // Event fired when mouse is down in a header cell.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- },
- onCellClick: function(e){
- // summary:
- // Event fired when a cell is clicked.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- this._click[0] = this._click[1];
- this._click[1] = e;
- if(!this.edit.isEditCell(e.rowIndex, e.cellIndex)){
- this.focus.setFocusCell(e.cell, e.rowIndex);
- }
- // in some cases click[0] is null which causes false doubeClicks. Fixes #100703
- if(this._click.length > 1 && this._click[0] == null){
- this._click.shift();
- }
- this.onRowClick(e);
- },
- onCellDblClick: function(e){
- // summary:
- // Event fired when a cell is double-clicked.
- // e: Event
- // Decorated event object contains reference to grid, cell, and rowIndex
- var event;
- if(this._click.length > 1 && dojo.isIE){
- event = this._click[1];
- }else if(this._click.length > 1 && this._click[0].rowIndex != this._click[1].rowIndex){
- event = this._click[0];
- }else{
- event = e;
- }
- this.focus.setFocusCell(event.cell, event.rowIndex);
- this.edit.setEditCell(event.cell, event.rowIndex);
- this.onRowDblClick(e);
- },
- onCellContextMenu: function(e){
- // summary:
- // Event fired when a cell context menu is accessed via mouse right click.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- this.onRowContextMenu(e);
- },
- onCellFocus: function(inCell, inRowIndex){
- // summary:
- // Event fired when a cell receives focus.
- // inCell: Object
- // Cell object containing properties of the grid column.
- // inRowIndex: Integer
- // Index of the grid row
- this.edit.cellFocus(inCell, inRowIndex);
- },
- // row events
- onRowClick: function(e){
- // summary:
- // Event fired when a row is clicked.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- this.edit.rowClick(e);
- this.selection.clickSelectEvent(e);
- },
- onRowDblClick: function(e){
- // summary:
- // Event fired when a row is double clicked.
- // e: Event
- // decorated event object which contains reference to grid, cell, and rowIndex
- },
- onRowMouseOver: function(e){
- // summary:
- // Event fired when mouse moves over a data row.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- },
- onRowMouseOut: function(e){
- // summary:
- // Event fired when mouse moves out of a data row.
- // e: Event
- // Decorated event object contains reference to grid, cell, and rowIndex
- },
-
- onRowMouseDown: function(e){
- // summary:
- // Event fired when mouse is down in a row.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- },
- onRowContextMenu: function(e){
- // summary:
- // Event fired when a row context menu is accessed via mouse right click.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- dojo.stopEvent(e);
- },
- // header events
- onHeaderMouseOver: function(e){
- // summary:
- // Event fired when mouse moves over the grid header.
- // e: Event
- // Decorated event object contains reference to grid, cell, and rowIndex
- },
- onHeaderMouseOut: function(e){
- // summary:
- // Event fired when mouse moves out of the grid header.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- },
- onHeaderCellMouseOver: function(e){
- // summary:
- // Event fired when mouse moves over a header cell.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- if(e.cellNode){
- dojo.addClass(e.cellNode, this.cellOverClass);
- }
- },
- onHeaderCellMouseOut: function(e){
- // summary:
- // Event fired when mouse moves out of a header cell.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- if(e.cellNode){
- dojo.removeClass(e.cellNode, this.cellOverClass);
- }
- },
-
- onHeaderCellMouseDown: function(e) {
- // summary:
- // Event fired when mouse is down in a header cell.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- },
- onHeaderClick: function(e){
- // summary:
- // Event fired when the grid header is clicked.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- },
- onHeaderCellClick: function(e){
- // summary:
- // Event fired when a header cell is clicked.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- this.setSortIndex(e.cell.index);
- this.onHeaderClick(e);
- },
- onHeaderDblClick: function(e){
- // summary:
- // Event fired when the grid header is double clicked.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- },
- onHeaderCellDblClick: function(e){
- // summary:
- // Event fired when a header cell is double clicked.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- this.onHeaderDblClick(e);
- },
- onHeaderCellContextMenu: function(e){
- // summary:
- // Event fired when a header cell context menu is accessed via mouse right click.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- this.onHeaderContextMenu(e);
- },
- onHeaderContextMenu: function(e){
- // summary:
- // Event fired when the grid header context menu is accessed via mouse right click.
- // e: Event
- // Decorated event object which contains reference to grid, cell, and rowIndex
- if(!this.headerMenu){
- dojo.stopEvent(e);
- }
- },
- // editing
- onStartEdit: function(inCell, inRowIndex){
- // summary:
- // Event fired when editing is started for a given grid cell
- // inCell: Object
- // Cell object containing properties of the grid column.
- // inRowIndex: Integer
- // Index of the grid row
- },
- onApplyCellEdit: function(inValue, inRowIndex, inFieldIndex){
- // summary:
- // Event fired when editing is applied for a given grid cell
- // inValue: String
- // Value from cell editor
- // inRowIndex: Integer
- // Index of the grid row
- // inFieldIndex: Integer
- // Index in the grid's data store
- },
- onCancelEdit: function(inRowIndex){
- // summary:
- // Event fired when editing is cancelled for a given grid cell
- // inRowIndex: Integer
- // Index of the grid row
- },
- onApplyEdit: function(inRowIndex){
- // summary:
- // Event fired when editing is applied for a given grid row
- // inRowIndex: Integer
- // Index of the grid row
- },
- onCanSelect: function(inRowIndex){
- // summary:
- // Event to determine if a grid row may be selected
- // inRowIndex: Integer
- // Index of the grid row
- // returns: Boolean
- // true if the row can be selected
- return true;
- },
- onCanDeselect: function(inRowIndex){
- // summary:
- // Event to determine if a grid row may be deselected
- // inRowIndex: Integer
- // Index of the grid row
- // returns: Boolean
- // true if the row can be deselected
- return true;
- },
- onSelected: function(inRowIndex){
- // summary:
- // Event fired when a grid row is selected
- // inRowIndex: Integer
- // Index of the grid row
- this.updateRowStyles(inRowIndex);
- },
- onDeselected: function(inRowIndex){
- // summary:
- // Event fired when a grid row is deselected
- // inRowIndex: Integer
- // Index of the grid row
- this.updateRowStyles(inRowIndex);
- },
- onSelectionChanged: function(){
- }
- });
- }
|