View Javadoc

1   /**
2    * 
3    */
4   package org.sirius.server.win32.classes;
5   
6   import javax.jws.WebService;
7   
8   import org.sirius.server.win32.constants.IMenuFlag;
9   import org.sirius.server.win32.constants.IWMConsts;
10  import org.sirius.server.win32.core.types.WinDefExt.MENUINFO;
11  import org.sirius.server.win32.core.types.WinDefExt.MENUITEMINFO;
12  
13  import com.sun.jna.Pointer;
14  import com.sun.jna.platform.win32.WinDef;
15  
16  /**
17   * @author Myk Kolisnyk
18   * .
19   */
20  @WebService
21  public class Menu extends Common implements IMenuFlag, IWMConsts, WinDef {
22  
23      /**
24       * .
25       */
26      public Menu() {
27          // TODO Auto-generated constructor stub
28      }
29  
30      /**
31       * .
32       * @param hMenu .
33       * @param fByPos .
34       * @param gmdiFlags .
35       * @return .
36       */
37      public final int getMenuDefaultItem(final long hMenu, final int fByPos,
38              final int gmdiFlags) {
39          HMENU handle = longToHmenu(hMenu);
40          return getUser32().GetMenuDefaultItem(handle, fByPos, gmdiFlags);
41      }
42  
43      /**
44       * .
45       * @param hmenu .
46       * @param lpcmi .
47       * @return .
48       */
49      public final boolean getMenuInfo(final long hmenu, final MENUINFO lpcmi) {
50          HMENU handle = longToHmenu(hmenu);
51          return getUser32().GetMenuInfo(handle, lpcmi);
52      }
53  
54      /**
55       * .
56       * @param hMenu .
57       * @return .
58       */
59      public final int getMenuItemCount(final long hMenu) {
60          HMENU handle = longToHmenu(hMenu);
61          return getUser32().GetMenuItemCount(handle);
62      }
63  
64      /**
65       * .
66       * @param hMenu .
67       * @param nPos .
68       * @return .
69       */
70      public final int getMenuItemID(final long hMenu, final int nPos) {
71          HMENU handle = longToHmenu(hMenu);
72          return getUser32().GetMenuItemID(handle, nPos);
73      }
74  
75      /**
76       * .
77       * @param hMenu .
78       * @param uItem .
79       * @param fByPosition .
80       * @param lpmii .
81       * @return .
82       */
83      public final boolean getMenuItemInfo(final long hMenu, final int uItem,
84              final boolean fByPosition, final MENUITEMINFO lpmii) {
85          HMENU handle = longToHmenu(hMenu);
86          return getUser32().GetMenuItemInfo(handle, uItem, fByPosition, lpmii);
87      }
88  
89      /**
90       * .
91       * @param hWnd .
92       * @param hMenu .
93       * @param uItem .
94       * @param rect .
95       * @return .
96       */
97      public final boolean getMenuItemRect(final long hWnd, final long hMenu,
98              final int uItem, final RECT rect) {
99          HWND handle = longToHwnd(hWnd);
100         HMENU menuHandle = longToHmenu(hMenu);
101         return getUser32().GetMenuItemRect(handle, menuHandle, uItem, rect);
102     }
103 
104     /**
105      * .
106      * @param hMenu .
107      * @param uId .
108      * @param uFlags .
109      * @return .
110      */
111     public final int getMenuState(
112             final long hMenu,
113             final int uId,
114             final int uFlags) {
115         HMENU handle = longToHmenu(hMenu);
116         return getUser32().GetMenuState(handle, uId, uFlags);
117     }
118 
119     /**
120      * .
121      * @param hMenu .
122      * @param uIDItem .
123      * @param lpString .
124      * @param nMaxCount .
125      * @param uFlag .
126      * @return .
127      */
128     public final int getMenuString(
129             final long hMenu,
130             final int uIDItem,
131             final char[] lpString,
132             final int nMaxCount,
133             final int uFlag) {
134         HMENU handle = longToHmenu(hMenu);
135         return getUser32()
136                 .GetMenuString(handle, uIDItem, lpString, nMaxCount, uFlag);
137     }
138 
139     /**
140      * .
141      * @param hMenu .
142      * @param nPos .
143      * @return .
144      */
145     public final long getSubMenu(final long hMenu, final int nPos) {
146         HMENU handle = longToHmenu(hMenu);
147         return Pointer
148                 .nativeValue(getUser32().GetSubMenu(handle, nPos).getPointer());
149     }
150 
151     /**
152      * .
153      * @param hMenu .
154      * @return .
155      */
156     public final boolean isMenu(final long hMenu) {
157         HMENU handle = longToHmenu(hMenu);
158         return getUser32().IsMenu(handle);
159     }
160 
161     /**
162      * .
163      * @param hwnd .
164      * @param hMenu .
165      * @param iPos .
166      * @return .
167      */
168     public final boolean pickItem(
169             final long hwnd,
170             final long hMenu,
171             final int iPos) {
172         int count = getMenuItemCount(hMenu);
173         if (count < iPos) {
174             return false;
175         }
176 
177         HWND handle = longToHwnd(hwnd);
178 
179         WPARAM wParam = new WPARAM();
180         LPARAM lParam = new LPARAM();
181         int id = getMenuItemID(hMenu, iPos);
182 
183         wParam.setValue(id);
184         lParam.setValue(0);
185 
186         getUser32().PostMessage(handle, WM_COMMAND, wParam, lParam);
187 
188         return true;
189     }
190 }