1 /* 2 LICENSE 3 ------- 4 Copyright 2005-2013 Nullsoft, Inc. 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without modification, 8 are permitted provided that the following conditions are met: 9 10 * Redistributions of source code must retain the above copyright notice, 11 this list of conditions and the following disclaimer. 12 13 * Redistributions in binary form must reproduce the above copyright notice, 14 this list of conditions and the following disclaimer in the documentation 15 and/or other materials provided with the distribution. 16 17 * Neither the name of Nullsoft nor the names of its contributors may be used to 18 endorse or promote products derived from this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 21 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 26 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 27 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef _MILKDROP_MENU_H_ 31 #define _MILKDROP_MENU_H_ 1 32 33 //---------------------------------------- 34 35 #include <windows.h> 36 37 //---------------------------------------- 38 39 typedef enum { 40 MENUITEMTYPE_BUNK, 41 MENUITEMTYPE_BOOL, 42 MENUITEMTYPE_INT, 43 MENUITEMTYPE_FLOAT, 44 MENUITEMTYPE_LOGFLOAT, 45 MENUITEMTYPE_BLENDABLE, 46 MENUITEMTYPE_LOGBLENDABLE, 47 MENUITEMTYPE_STRING, 48 MENUITEMTYPE_UIMODE, 49 //MENUITEMTYPE_OSC, 50 } MENUITEMTYPE; 51 #define MAX_CHILD_MENUS 16 52 typedef void (*MilkMenuCallbackFnPtr)(LPARAM param1, LPARAM param2); // MilkMenuCallbackFnPtr is synonym for "pointer to function returning void, and taking 2 lparams" 53 54 //---------------------------------------- 55 class CMilkMenuItem 56 { 57 public: 58 CMilkMenuItem(); 59 ~CMilkMenuItem(); 60 61 wchar_t m_szName[64]; 62 wchar_t m_szToolTip[1024]; 63 MENUITEMTYPE m_type; 64 float m_fMin; // note: has different meanings based on the MENUITEMTYPE 65 float m_fMax; // note: has different meanings based on the MENUITEMTYPE 66 unsigned int m_wParam; 67 unsigned int m_lParam; 68 MilkMenuCallbackFnPtr m_pCallbackFn; // Callback Function pointer; if non-NULL, this functino will be called whenever the menu item is modified by the user. 69 ptrdiff_t m_var_offset; // dist of variable's mem loc., in bytes, from pg->m_pState. 70 LPARAM m_original_value; // can hold a float or int 71 int m_nLastCursorPos; // for strings; remembers most recent pos. of the cursor 72 bool m_bEnabled; 73 74 // special data used for MENUITEMTYPE_OSCILLATOR: 75 //int m_nSubSel; 76 //bool m_bEditingSubSel; 77 78 CMilkMenuItem *m_pNext; 79 }; 80 //---------------------------------------- 81 82 //---------------------------------------- 83 class CMilkMenu 84 { 85 public: 86 CMilkMenu(); 87 ~CMilkMenu(); 88 89 void Init(wchar_t *szName); 90 void Finish(); 91 void AddChildMenu(CMilkMenu *pChildMenu); 92 void AddItem(wchar_t *szName, void *var, MENUITEMTYPE type, wchar_t *szToolTip, 93 float min=0, float max=0, MilkMenuCallbackFnPtr pCallback=NULL, 94 unsigned int wParam=0, unsigned int lParam=0); SetParentPointer(CMilkMenu * pParentMenu)95 void SetParentPointer(CMilkMenu *pParentMenu) { m_pParentMenu = pParentMenu; } 96 LRESULT HandleKeydown(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); 97 void DrawMenu(RECT rect, int xR, int yB, int bCalcRect=0, RECT* pCalcRect=NULL); 98 void OnWaitStringAccept(wchar_t *szNewString); 99 void EnableItem(wchar_t* szName, bool bEnable); GetCurItem()100 CMilkMenuItem* GetCurItem() // NOTE: ONLY WORKS IF AN *ITEM* IS HIGHLIGHTED; NOT A CHILD MENU 101 { 102 CMilkMenuItem *pItem = m_pFirstChildItem; 103 for (int i=m_nChildMenus; i < m_nCurSel; i++) 104 pItem = pItem->m_pNext; 105 return pItem; 106 } GetName()107 const wchar_t* GetName() { return m_szMenuName; } Enable(bool bEnabled)108 void Enable(bool bEnabled) { m_bEnabled = bEnabled; } IsEnabled()109 bool IsEnabled() { return m_bEnabled; } 110 bool ItemIsEnabled(int i); 111 112 protected: 113 void Reset(); 114 CMilkMenu *m_pParentMenu; 115 CMilkMenu *m_ppChildMenu[MAX_CHILD_MENUS]; // pointers are kept here, but these should be cleaned up by the app. 116 CMilkMenuItem *m_pFirstChildItem; // linked list; these are dynamically allocated, and automatically cleaned up in destructor 117 wchar_t m_szMenuName[64]; 118 int m_nChildMenus; 119 int m_nChildItems; 120 int m_nCurSel; 121 bool m_bEditingCurSel; 122 bool m_bEnabled; 123 }; 124 //---------------------------------------- 125 126 #endif //_MILKDROP_MENU_H_