001package org.vishia.gral.base; 002 003import org.vishia.gral.ifc.GralWidget_ifc; 004 005/**This interface is implemented in the Widget adaption for the Gral level. 006 * It should not be known by the user, except the user creates new widget types. 007 * The interface is the connection from Mouse listeners in the graphic implementation layer (swt, swing) 008 * to the gral widgets. 009 * See {@link org.vishia.gral.swt.SwtGralMouseListener} for an usage in graphic implementation layer. 010 * 011 * 012 * @author Hartmut Schorrig 013 * 014 */ 015public interface GralMouseWidgetAction_ifc 016{ 017 /**Version, history and licence 018 * 019 * <ul> 020 * <li>2013-10-13 Hartmut new: {@link #mouse1Double(int, int, int, int, int, GralWidget)}. 021 * #new 022 * <li>2013-05-13 Hartmut chg: All methods changed, parameter key, position. 023 * </ul> 024 * 025 * <b>Copyright/Copyleft</b>: 026 * For this source the LGPL Lesser General Public License, 027 * published by the Free Software Foundation is valid. 028 * It means: 029 * <ol> 030 * <li> You can use this source without any restriction for any desired purpose. 031 * <li> You can redistribute copies of this source to everybody. 032 * <li> Every user of this source, also the user of redistribute copies 033 * with or without payment, must accept this license for further using. 034 * <li> But the LPGL ist not appropriate for a whole software product, 035 * if this source is only a part of them. It means, the user 036 * must publish this part of source, 037 * but don't need to publish the whole source of the own product. 038 * <li> You can study and modify (improve) this source 039 * for own using or for redistribution, but you have to license the 040 * modified sources likewise under this LGPL Lesser General Public License. 041 * You mustn't delete this Copyright/Copyleft inscription in this source file. 042 * </ol> 043 * If you are indent to use this sources without publishing its usage, you can get 044 * a second license subscribing a special contract with the author. 045 * 046 * @author Hartmut Schorrig = hartmut.schorrig@vishia.de 047 * 048 * 049 */ 050 public final static int version = 0x20120303; 051 052 053 /**Bit mask to determine which mouse action should invoke the {@link GralWidget#getActionChange()}. 054 * It is the second parameter of {@link GralWidget#setActionMouse(GralMouseWidgetAction_ifc, int)}. 055 * Use an | of this conditions. mUserAll includes any key of mouse. 056 */ 057 public final static int mUser1down = 1, mUser2down = 0x2, mUser3down = 0x4, mUserAlldown = 0xf 058 , mUser1up = 0x10, mUser2up = 0x20, mUser3up = 0x40, mUserAllup = 0xf 059 , mUserDouble = 0x100 060 , mUserAll = 0xffff; 061 062 /**Called from the graphic implementation layer if the standard left mouse button is pressed. 063 * @param xMousePixel 064 * @param yMousePixel 065 */ 066 void mouse1Down(int key, int xMousePixel, int yMousePixel, int xWidgetSizePixel, int yWidgetSizePixel, GralWidget widgg); 067 068 void mouse1Up(int key, int xMousePixel, int yMousePixel, int xWidgetSizePixel, int yWidgetSizePixel, GralWidget widgg); 069 070 /**Called from the graphic implementation layer if the standard right mouse button is pressed. 071 * @param xMousePixel 072 * @param yMousePixel 073 */ 074 void mouse2Down(int key, int xMousePixel, int yMousePixel, int xWidgetSizePixel, int yWidgetSizePixel, GralWidget widgg); 075 076 void mouse2Up(int key, int xMousePixel, int yMousePixel, int xWidgetSizePixel, int yWidgetSizePixel, GralWidget widgg); 077 078 079 void mouse1Double(int key, int xMousePixel, int yMousePixel, int xWidgetSizePixel, int yWidgetSizePixel, GralWidget widgg); 080 081 082 083 /**It is called if the mouse button is pressed, and then the mouse cursor is removed from the widget. 084 * The mouse-button-up action won't be called then. Usual the user should done its action 085 * while the button-up is detected, non on button down. It is an advantage for handling, 086 * because on button-up the hit widget should be marked visible firstly. 087 * 088 */ 089 //void removeMouseCursorFromWidgetWhilePressed(); 090 091 092 093 /**This routine is called only if a mouse button is pressed while moving the mouse cursor. 094 * @param xMousePixel The current mouse cursor x value 095 * @param yMousePixel The current mouse cursor y value 096 * @param xWidgetSizePixel Width of the associated widget. 097 * @param yWidgetSizePixel Height of the associated widget. 098 * @return true if the mouse should be still accepted as pressed, 099 * false if the mouse button up action should be prevented. The mouse is not accepted as pressed any more. 100 */ 101 boolean mouseMoved(int xMousePixel, int yMousePixel, int xWidgetSizePixel, int yWidgetSizePixel); 102 103 104 105 /**Invoke the proper action for mouse events. 106 * This routine is used inside the graphic implementing mouse handlers. 107 * The action with the 'when' designation is searched. If found it is invoked with its own arguments 108 * and then with the mouse position in line and column grid values of the panel and a possible delta position. 109 * @param widgg The widget where the mouse handling is associated to 110 * @param keyCode The possible additional modifying key (ctrl, alt, sh) and the mouse key 111 * @param when which mouse action should be used. 112 * @param mouse_x The pixel position of the mouse inside the panel 113 * @param mouse_y 114 * @param dx An additional delta-position in pixel. 115 * @param dy 116 * @throws any exception which is catched in the mouse listener. 117 * NOTE: yet unused. Write a class with gral mouse adaption! 118 public static void executeActionForMouse(GralWidget widgg, int keyCode, GralWidget_ifc.ActionChangeWhen when, int mouse_x, int mouse_y, int dx, int dy) { 119 GralWidget_ifc.ActionChange action = widgg.getActionChangeStrict(when, true); 120 if(action !=null){ 121 //TODO: calc grid positions from pixel! 122 Object[] args = action.args(); 123 if(args == null){ action.action().exec(keyCode, widgg, new Integer(mouse_x), new Integer(mouse_y), new Integer(dx), new Integer(dy)); } 124 else { 125 //additional 2 arguments: copy in one args2. 126 Object[] args2 = new Object[args.length +4]; 127 System.arraycopy(args, 0, args2, 0, args.length); 128 args2[args.length] = new Integer(mouse_y); 129 args2[args.length+1] = new Integer(mouse_x); 130 args2[args.length+2] = new Integer(dy); 131 args2[args.length+3] = new Integer(dx); 132 action.action().exec(keyCode, widgg, args2); 133 } 134 } 135 } 136 */ 137 138 139}