xoblite™ / Blackbox for Windows bb5 | RC6 preview | 0.25.2.14
http://xoblite.net/
StringItem Class Reference

#include <StringItem.h>

Public Member Functions

 StringItem (char *pszTitleANSI, wchar_t *pszTitleUnicode, char *pszCommand, char *pszInit, bool isSelected)
 
virtual ~StringItem ()
 
void CreateEditWindow ()
 
void DestroyEditWindow ()
 
void Invoke (int button)
 
bool Active (bool bActivate)
 
- Public Member Functions inherited from MenuItem
 MenuItem (int type, char *pszTitleANSI, wchar_t *pszTitleUnicode, char *pszCommand, char *pszArgument, bool isSelected)
 
virtual ~MenuItem ()
 
virtual LRESULT NcHitTest (int x, int y)
 
int IsOver (int x, int y)
 
virtual void Mouse (UINT nMsg, POINT pt)
 
virtual bool IsActive ()
 
virtual char * GetSortString ()
 
virtual void GetItemRect (RECT *r)
 
virtual void GetTitleRect (RECT *r)
 
virtual UINT GetDrawTextFormat ()
 
virtual void SetTitleANSI (char *pszTitleANSI)
 
virtual void SetTitleUnicode (wchar_t *pszTitleUnicode)
 
void AddToSelectionGroup (int group)
 
void ItemSetTimer ()
 
virtual void Timer (int nTimer)
 
void ItemKillTimer ()
 
virtual void SetWidth (int nWidth)
 
virtual int GetWidth ()
 
virtual void SetHeight (int nHeight)
 
virtual int GetHeight ()
 
virtual void SetPosition (int nLeft, int nTop)
 
virtual void SetSortPriority (int nSortPriority)
 
virtual int GetSortPriority ()
 
virtual void Attached (Menu *pMenu)
 
virtual LRESULT Command (WPARAM wParam, LPARAM lParam)
 
virtual bool OnUser (int nMessage, WPARAM wParam, LPARAM lParam, LRESULT &lResult)
 
virtual void Moving ()
 
virtual HWND GetWindow ()
 
void ToggleSelected ()
 

Public Attributes

char * m_pszTitleANSI
 
wchar_t * m_pszTitleUnicode
 
char * m_pszCommand
 
char * m_pszInit
 
HWND m_hwndEditor
 
SIZE buttonSize
 
bool editboxActive
 
- Public Attributes inherited from MenuItem
char * m_pszTitleANSI
 
wchar_t * m_pszTitleUnicode
 
int itemType
 
char * m_pszCommand
 
char * m_pszArgument
 
char * m_pszOriginalTitleANSI
 
wchar_t * m_pszOriginalTitleUnicode
 
bool m_isSelected
 
int m_selectionGroup
 
int m_currentValue
 
int m_minValue
 
int m_maxValue
 
POINT m_mousePos
 
int m_nSortPriority
 
Menum_pParent
 
Menum_pSubMenu
 
int m_nLeft
 
int m_nTop
 
int m_nWidth
 
int m_nHeight
 
bool m_bActive
 
UINT m_nTimerId
 
int m_nLastMouseButton
 

Friends

LRESULT CALLBACK EditWindowSubclassProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
 

Additional Inherited Members

- Static Public Member Functions inherited from MenuItem
static bool Compare (MenuItem *pM1, MenuItem *pM2)
 

Constructor & Destructor Documentation

◆ StringItem()

StringItem::StringItem ( char * pszTitleANSI,
wchar_t * pszTitleUnicode,
char * pszCommand,
char * pszInit,
bool isSelected )
45 : MenuItem(MENUITEM_EDITSTRING, pszTitleANSI, pszTitleUnicode, NULL, NULL, isSelected)
46{
47 m_pszTitleANSI = pszTitleANSI ? _strdup(pszTitleANSI) : _strdup("");
48 m_pszTitleUnicode = pszTitleUnicode ? _wcsdup(pszTitleUnicode) : _wcsdup(L"");
49 m_pszCommand = pszCommand ? _strdup(pszCommand) : _strdup("");
50 m_pszInit = pszInit ? _strdup(pszInit) : _strdup("");
51
52 m_hwndEditor = NULL;
53
54 editboxActive = false;
55}
#define MENUITEM_EDITSTRING
Definition MenuItem.h:43
MenuItem(int type, char *pszTitleANSI, wchar_t *pszTitleUnicode, char *pszCommand, char *pszArgument, bool isSelected)
Definition MenuItem.cpp:42
wchar_t * m_pszTitleUnicode
Definition StringItem.h:53
char * m_pszTitleANSI
Definition StringItem.h:52
char * m_pszInit
Definition StringItem.h:55
HWND m_hwndEditor
Definition StringItem.h:57
char * m_pszCommand
Definition StringItem.h:54
bool editboxActive
Definition StringItem.h:59

◆ ~StringItem()

StringItem::~StringItem ( )
virtual
58{
60
62 m_pszTitleANSI = NULL;
64 m_pszTitleUnicode = NULL;
65 if (m_pszCommand) free(m_pszCommand);
66 m_pszCommand = NULL;
67 if (m_pszInit) free(m_pszInit);
68 m_pszInit = NULL;
69}
void DestroyEditWindow()
Definition StringItem.cpp:125

Member Function Documentation

◆ CreateEditWindow()

void StringItem::CreateEditWindow ( )
74{
75 if (!m_hwndEditor)
76 {
77 RECT workArea;
78 ZeroMemory(&workArea, sizeof(workArea));
79 SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
80
81 int editboxWidth = (workArea.right - workArea.left) / 2;
82 int editboxHeight = 15 * pSettings->scalingFactorHiDPI; // Using a regular DPI fixed font size of 15 pixels... (Segoe UI)
83 editboxHeight += 12; // Add vertical padding to allow for a WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE sunken double border (see extended window styles below)
84 int editboxX = editboxWidth / 2;
85 int editboxY = ((workArea.bottom - workArea.top) / 2) - (editboxHeight / 2);
86
87 m_hwndEditor = CreateWindowEx(
88 WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE, // window style
89 "EDIT", // window class
90 NULL, // window name
91 WS_POPUP | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL, // window parameters
92 editboxX, // x position
93 editboxY, // y position
94 editboxWidth, // window width
95 editboxHeight, // window height
96 m_pParent->GetWindow(), // parent window
97 NULL, // no menu
98 m_pParent->hMenuInstance, // hInstance
99 NULL // no window creation data
100 );
101
102 if (!m_hwndEditor)
103 {
104 MessageBox(0, "Error creating menu string editor window!", "BBMenu", MB_OK | MB_ICONERROR | MB_TOPMOST);
105 Log("Menu", "Error creating string editor window!");
106 m_hwndEditor = NULL;
107 }
108 else
109 {
110 SendMessage(m_hwndEditor, (UINT)WM_SETFONT, (WPARAM)pMenuCommon->m_hEditStringFont, TRUE);
111 SendMessage(m_hwndEditor, (UINT)EM_SETLIMITTEXT, (WPARAM)255, 0); // Allow maximum 255 characters in the edit control
112 SendMessage(m_hwndEditor, WM_SETTEXT, 0, (LPARAM)m_pszInit);
113 SendMessage(m_hwndEditor, EM_SETSEL, (WPARAM)0, (LPARAM)-1); // Select all text in the edit control
114
115 // Add a subclass to the edit window to be able to respond to the Enter key (not visible to the parent WndProc) being pressed...
116 SetWindowSubclass(m_hwndEditor, EditWindowSubclassProc, 0, 0);
117
118 ShowWindow(m_hwndEditor, SW_SHOW);
119 SetWindowPos(m_hwndEditor, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
120 SetForegroundWindow(m_hwndEditor);
121 }
122 }
123}
MenuCommon * pMenuCommon
Definition Blackbox.cpp:41
void Log(LPCSTR des, LPCSTR line)
Definition BBApi.cpp:638
Settings * pSettings
Definition Blackbox.cpp:46
HFONT m_hEditStringFont
Definition MenuCommon.h:127
Menu * m_pParent
Definition MenuItem.h:180
int scalingFactorHiDPI
Definition Settings.h:327
friend LRESULT CALLBACK EditWindowSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
Definition StringItem.cpp:138

◆ DestroyEditWindow()

void StringItem::DestroyEditWindow ( )
126{
127 if (m_hwndEditor)
128 {
130 editboxActive = false;
131 ShowWindow(m_hwndEditor, SW_HIDE);
132 RemoveWindowSubclass(m_hwndEditor, EditWindowSubclassProc, 0);
133 DestroyWindow(m_hwndEditor);
134 m_hwndEditor = NULL;
135 }
136}
bool menuEditboxAlreadyActive
Definition Settings.h:388

◆ Invoke()

void StringItem::Invoke ( int button)
virtual

Reimplemented from MenuItem.

171{
172 if ((button == 1) && !editboxActive)
173 {
174 // Execute the broam command+parameters associated with the StringItem, without prior editing...
175 // (cf. e.g. a browser bookmark menu item scenario -> Open/execute (left click) or edit (right click) the bookmark via a single menu item)
176 pMenuCommon->Invoke(this, 1);
177 return;
178 }
179
180 //====================
181
182 else if (editboxActive)
183 {
185 editboxActive = false;
187
188 // Fetch the newly edited string from the edit box...
189 char editedValue[255];
190 SendMessage(m_hwndEditor, WM_GETTEXT, 255, (LPARAM)&editedValue);
191 editedValue[sizeof(editedValue)-1] = '\0'; // Failsafe
192
193 // Update the menu item title as applicable...
194
195 if ((strlen(m_pszTitleANSI) >= 3) && !_strnicmp(&m_pszTitleANSI[strlen(m_pszTitleANSI)-3], "...", 3))
196 {
197 // Hidden init string -> Nothing to do here... (for now at least?)
198 }
199 else // Visible init string...
200 {
201 if (strlen(m_pszInit) > 0) // -> Prior init string existed -> Replace it with the newly edited one...
202 {
203 char* ptr1 = strstr(m_pszTitleANSI, m_pszInit);
204 if (ptr1 != NULL)
205 {
206 char* ptr0 = &m_pszTitleANSI[0];
207 char* ptr2 = ptr1 + strlen(m_pszInit);
208
209 char newTitle[MAX_LINE_LENGTH];
210// strncpy(newTitle, m_pszTitleANSI, (int)(ptr1-ptr0));
211 strncpy_s(newTitle, sizeof(newTitle), m_pszTitleANSI, (int)(ptr1-ptr0));
212 newTitle[(int)(ptr1-ptr0)] = '\0';
213 if (strlen(editedValue) > 0) strcat(newTitle, editedValue);
214 strcat(newTitle, ptr2);
215 newTitle[sizeof(newTitle)-1] = '\0'; // Failsafe
216
217// if (pSettings->debugLogging) SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_INFORMATION_MESSAGE, (LPARAM)newTitle);
218
220 m_pszTitleANSI = newTitle ? _strdup(newTitle) : _strdup("");
221
223 wchar_t newTitleUnicode[MAX_LINE_LENGTH];
224 MultiByteToWideChar(CP_UTF8, 0, newTitle, strlen(newTitle)+1, newTitleUnicode, MAX_LINE_LENGTH);
225 m_pszTitleUnicode = newTitleUnicode ? _wcsdup(newTitleUnicode) : _wcsdup(L"");
226 }
227 }
228 else // -> No prior init string existed -> Look for the default edit string <> brackets and insert the newly edited string in between them...
229 {
230 if (strlen(editedValue) > 0)
231 {
232 char* ptr0 = &m_pszTitleANSI[0];
233 char* ptr1 = strstr(m_pszTitleANSI, "<>");
234 if (ptr1 != NULL)
235 {
236 char newTitle[MAX_LINE_LENGTH];
237// strncpy(newTitle, m_pszTitleANSI, (int)(ptr1-ptr0)+1);
238 strncpy_s(newTitle, sizeof(newTitle), m_pszTitleANSI, (int)(ptr1-ptr0)+1);
239 newTitle[(int)(ptr1-ptr0)+1] = '\0';
240 if (strlen(editedValue) > 0) strcat(newTitle, editedValue);
241 strcat(newTitle, ptr1+1);
242 newTitle[sizeof(newTitle)-1] = '\0'; // Failsafe
243
244// if (pSettings->debugLogging) SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_INFORMATION_MESSAGE, (LPARAM)newTitle);
245
247 m_pszTitleANSI = newTitle ? _strdup(newTitle) : _strdup("");
248
250 wchar_t newTitleUnicode[MAX_LINE_LENGTH];
251 MultiByteToWideChar(CP_UTF8, 0, newTitle, strlen(newTitle)+1, newTitleUnicode, MAX_LINE_LENGTH);
252 m_pszTitleUnicode = newTitleUnicode ? _wcsdup(newTitleUnicode) : _wcsdup(L"");
253 }
254 }
255 }
256
259 }
260
261 // Save the newly edited string as the new menu item init string...
262 if (m_pszInit) free(m_pszInit);
263 m_pszInit = editedValue ? _strdup(editedValue) : _strdup("");
264
265 // Set the menu item as selected if so applicable...
267 {
268 m_pParent->ClearSelectionGroup(m_selectionGroup);
269 m_isSelected = true;
270 }
271
272 //====================
273
274 // Send the broam command associated with the StringItem...
275 char broam[MAX_LINE_LENGTH];
276
277 if (IsInString(m_pszCommand, "@BBInterface"))
278 {
279 // Add "" encapsulation to the broam parameters string to
280 // allow spaces in strings sent back to BBInterface...
281 int nLen = strlen(editedValue);
282 memmove(editedValue+1, editedValue, strlen(editedValue));
283 editedValue[0] = editedValue[nLen+1] = '\"';
284 editedValue[nLen+2] = '\0';
285
286// SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_INFORMATION_MESSAGE, (LPARAM)"StringItem::Invoke() broadcasting back...");
287// SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_INDENTED_MESSAGE, (LPARAM)m_pszCommand);
288// SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_INDENTED_MESSAGE, (LPARAM)editedValue);
289 }
290
291 sprintf(broam, "%s %s", m_pszCommand, editedValue);
292// SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_INDENTED_MESSAGE, (LPARAM)broam);
293 SendMessage(GetBBWnd(), BB_BROADCAST, 0, (LPARAM)broam);
294
295 //====================
296
297 // Hide the editor window...
299 SetWindowPos(m_pParent->GetWindow(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
300
301 // Update the menu...
302 m_pParent->Invalidate();
303 m_pParent->Validate();
304 m_pParent->UpdateMenuWindow();
305 }
306
307 //====================
308
309 else
310 {
311 // Allow only a single menu item editbox to be active at a time...
313 {
314 // Show the editor window and "OK?" button...
316 editboxActive = true;
318 SetWindowPos(m_pParent->GetWindow(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
320 }
321 else if (pSettings->menuEditboxStringItemPtr != NULL)
322 {
323 // Hide the editor window belonging to another menu item...
325 si->DestroyEditWindow();
326 si->editboxActive = false;
329 SetWindowPos(m_pParent->GetWindow(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
330 }
331
332 // Update the menu...
333 m_pParent->Invalidate();
334 m_pParent->Validate();
335 m_pParent->UpdateMenuWindow();
336 }
337}
bool IsInString(LPCSTR inputString, LPCSTR searchString)
Definition BBApi.cpp:2519
HWND GetBBWnd()
Definition BBApi.cpp:128
#define BB_BROADCAST
Definition BBApi.h:245
#define MAX_LINE_LENGTH
Definition BBApi.h:64
#define GROUP_DEFAULT
Definition MenuItem.h:62
void Invoke(MenuItem *item, int button)
Definition MenuCommon.cpp:1150
bool m_isSelected
Definition MenuItem.h:101
int m_selectionGroup
Definition MenuItem.h:102
virtual void SetTitleANSI(char *pszTitleANSI)
Definition MenuItem.cpp:449
virtual void SetTitleUnicode(wchar_t *pszTitleUnicode)
Definition MenuItem.cpp:456
MenuItem * menuEditboxStringItemPtr
Definition Settings.h:389
StringItem(char *pszTitleANSI, wchar_t *pszTitleUnicode, char *pszCommand, char *pszInit, bool isSelected)
Definition StringItem.cpp:45
void CreateEditWindow()
Definition StringItem.cpp:73

◆ Active()

bool StringItem::Active ( bool bActivate)
virtual

Reimplemented from MenuItem.

342{
343 if (editboxActive) return false;
344 else return MenuItem::Active(bActivate);
345}
virtual bool Active(bool bActive)
Definition MenuItem.cpp:257

Friends And Related Symbol Documentation

◆ EditWindowSubclassProc

LRESULT CALLBACK EditWindowSubclassProc ( HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam,
UINT_PTR uIdSubclass,
DWORD_PTR dwRefData )
friend
139{
141 {
142 if (message == WM_KEYDOWN)
143 {
144 if (wParam == VK_RETURN)
145 {
146 // Pressing the return key -> Same action as *right* clicking the "OK" button, i.e. invoke action + keep the menu open...
148 }
149 else if (wParam == VK_ESCAPE)
150 {
151 // Pressing the escape key -> Hide the editor window *without* invoking any action, i.e. discard any edits + keep the menu open...
153 si->DestroyEditWindow();
154 si->editboxActive = false;
157
158 si->m_pParent->Invalidate();
159 si->m_pParent->Validate();
160 si->m_pParent->UpdateMenuWindow();
161 }
162 }
163 }
164
165 return DefSubclassProc(hwnd, message, wParam, lParam);
166}
virtual void Invoke(int button)
Definition MenuItem.cpp:371

Member Data Documentation

◆ m_pszTitleANSI

char* StringItem::m_pszTitleANSI

◆ m_pszTitleUnicode

wchar_t* StringItem::m_pszTitleUnicode

◆ m_pszCommand

char* StringItem::m_pszCommand

◆ m_pszInit

char* StringItem::m_pszInit

◆ m_hwndEditor

HWND StringItem::m_hwndEditor

◆ buttonSize

SIZE StringItem::buttonSize

◆ editboxActive

bool StringItem::editboxActive