Skip to content

Commit

Permalink
Changed g_szSelectedItem to a string.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbbert committed Nov 28, 2024
1 parent 728384b commit a62cff5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
31 changes: 9 additions & 22 deletions src/osd/winui/messui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct _device_entry
// GLOBAL VARIABLES
//============================================================

char g_szSelectedItem[MAX_PATH];
string g_szSelectedItem;


//============================================================
Expand Down Expand Up @@ -277,19 +277,6 @@ static const struct TabViewCallbacks s_softwareTabViewCallbacks =
//============================================================
// IMPLEMENTATION
//============================================================
static char *strncpyz(char *dest, const char *source, size_t len)
{
char *s;
if (len) {
s = strncpy(dest, source, len - 1);
dest[len-1] = '\0';
}
else {
s = dest;
}
return s;
}


static const device_entry *lookupdevice(string d)
{
Expand Down Expand Up @@ -1518,7 +1505,7 @@ static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem)
int drvindex = Picker_GetSelectedItem(hwndList);
if (drvindex < 0)
{
g_szSelectedItem[0] = 0;
g_szSelectedItem.clear();
return;
}

Expand All @@ -1531,10 +1518,10 @@ static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem)
MessSpecifyImage(drvindex, NULL, pszFullName);

// Set up g_szSelectedItem, for the benefit of UpdateScreenShot()
strncpyz(g_szSelectedItem, pszName, std::size(g_szSelectedItem));
LPSTR s = strrchr(g_szSelectedItem, '.');
if (s)
*s = '\0';
g_szSelectedItem = pszName;
size_t t = g_szSelectedItem.find_last_of(".");
if (t != string::npos)
g_szSelectedItem.erase(t);

UpdateScreenShot();
}
Expand Down Expand Up @@ -1583,7 +1570,7 @@ static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem)
static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem)
{
if (!s_bIgnoreSoftwarePickerNotifies)
g_szSelectedItem[0] = 0;
g_szSelectedItem.clear();
}


Expand All @@ -1597,15 +1584,15 @@ static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem)
int drvindex = Picker_GetSelectedItem(hwndList);
if (drvindex < 0)
{
g_szSelectedItem[0] = 0;
g_szSelectedItem.clear();
return;
}

// Get the fullname for this file
LPCSTR pszFullName = SoftwareList_LookupFullname(hwndSoftwareList, nItem); // for the screenshot and SetSoftware.

// For UpdateScreenShot()
strncpyz(g_szSelectedItem, pszFullName, std::size(g_szSelectedItem));
g_szSelectedItem = pszFullName;
UpdateScreenShot();
// use SOFTWARENAME option to properly load a multipart set
SetSelectedSoftware(drvindex, "", pszFullName);
Expand Down
2 changes: 1 addition & 1 deletion src/osd/winui/messui.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef WINUI_MESSUI_H
#define WINUI_MESSUI_H

extern char g_szSelectedItem[MAX_PATH];
extern string g_szSelectedItem;

void InitMessPicker(void);
void MessUpdateSoftwareList(void);
Expand Down
6 changes: 3 additions & 3 deletions src/osd/winui/screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ HBITMAP DIBToDDB(HDC hDC, HANDLE hDIB, LPMYBITMAPINFO desc)


// main call from winui to display a picture
BOOL LoadScreenShot(int nGame, LPCSTR lpSoftwareName, int nType)
BOOL LoadScreenShot(int nGame, string lpSoftwareName, int nType)
{
/* Delete the last ones */
//printf("LoadScreenShot: A\n");fflush(stdout);
Expand All @@ -711,8 +711,8 @@ BOOL LoadScreenShot(int nGame, LPCSTR lpSoftwareName, int nType)

// If software item, see if picture exist (correct parent is passed in lpSoftwareName)
//printf("LoadScreenShot: C\n");fflush(stdout);
if (lpSoftwareName)
loaded = LoadDIB(lpSoftwareName, &m_hDIB, &m_hPal, nType);
if (!lpSoftwareName.empty())
loaded = LoadDIB(lpSoftwareName.c_str(), &m_hDIB, &m_hPal, nType);

// If game, see if picture exist. Or, if no picture for the software, use game's picture.
//printf("LoadScreenShot: D\n");fflush(stdout);
Expand Down
2 changes: 1 addition & 1 deletion src/osd/winui/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef struct _mybitmapinfo
int bmColors;
} MYBITMAPINFO, *LPMYBITMAPINFO;

extern BOOL LoadScreenShot(int nGame, LPCSTR lpSoftwareName, int nType);
extern BOOL LoadScreenShot(int nGame, std::string lpSoftwareName, int nType);
extern HANDLE GetScreenShotHandle(void);
extern int GetScreenShotWidth(void);
extern int GetScreenShotHeight(void);
Expand Down
11 changes: 5 additions & 6 deletions src/osd/winui/winui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ void UpdateSoftware(void)


/* Adjust the list view and screenshot button based on GetShowScreenShot() */
void UpdateScreenShot(void)
void UpdateScreenShot()
{
/* first time through can't do this stuff */
//printf("Update Screenshot: A\n");fflush(stdout);
Expand Down Expand Up @@ -1414,16 +1414,15 @@ void UpdateScreenShot(void)
//printf("Update Screenshot: H\n");fflush(stdout);
if (have_selection)
{
if (g_szSelectedItem[0])
if (!g_szSelectedItem.empty())
LoadScreenShot(Picker_GetSelectedItem(hwndList), g_szSelectedItem, TabView_GetCurrentTab(hTabCtrl));
else
LoadScreenShot(Picker_GetSelectedItem(hwndList), NULL, TabView_GetCurrentTab(hTabCtrl));
LoadScreenShot(Picker_GetSelectedItem(hwndList), "", TabView_GetCurrentTab(hTabCtrl));
}

// figure out if we have a history or not, to place our other windows properly
//printf("Update Screenshot: I\n");fflush(stdout);
string t_software = string(g_szSelectedItem);
UpdateHistory(t_software);
UpdateHistory(g_szSelectedItem);

// setup the picture area

Expand Down Expand Up @@ -4906,7 +4905,7 @@ static const TCHAR *GamePicker_GetItemString(HWND hwndPicker, int nItem, int nCo
static void GamePicker_LeavingItem(HWND hwndPicker, int nItem)
{
// leaving item
g_szSelectedItem[0] = 0;
g_szSelectedItem.clear();
}


Expand Down

0 comments on commit a62cff5

Please sign in to comment.