📄 maincontrols.cpp
字号:
break;
case SB_BOTTOM:
ScrollXOffset = ScrollXOffsetMax;
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
ScrollXOffset = HIWORD(wParam);
break;
}
if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax;
if(ScrollXOffset < 0) ScrollXOffset = 0;
if(prevX != ScrollXOffset) {
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = ScrollXOffset;
SetScrollInfo(HorizScrollBar, SB_CTL, &si, TRUE);
InvalidateRect(MainWindow, NULL, FALSE);
}
}
//-----------------------------------------------------------------------------
// Cause the status bar and the list view to be in sync with the actual data
// structures describing the settings and the I/O configuration. Listview
// does callbacks to get the strings it displays, so it just needs to know
// how many elements to populate.
//-----------------------------------------------------------------------------
void RefreshControlsToSettings(void)
{
int i;
if(!IoListOutOfSync) {
IoListSelectionPoint = -1;
for(i = 0; i < Prog.io.count; i++) {
if(ListView_GetItemState(IoList, i, LVIS_SELECTED)) {
IoListSelectionPoint = i;
break;
}
}
}
ListView_DeleteAllItems(IoList);
for(i = 0; i < Prog.io.count; i++) {
LVITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
lvi.state = lvi.stateMask = 0;
lvi.iItem = i;
lvi.iSubItem = 0;
lvi.pszText = LPSTR_TEXTCALLBACK;
lvi.lParam = i;
if(ListView_InsertItem(IoList, &lvi) < 0) oops();
}
if(IoListSelectionPoint >= 0) {
for(i = 0; i < Prog.io.count; i++) {
ListView_SetItemState(IoList, i, 0, LVIS_SELECTED);
}
ListView_SetItemState(IoList, IoListSelectionPoint, LVIS_SELECTED,
LVIS_SELECTED);
ListView_EnsureVisible(IoList, IoListSelectionPoint, FALSE);
}
IoListOutOfSync = FALSE;
if(Prog.mcu) {
SendMessage(StatusBar, SB_SETTEXT, 0, (LPARAM)Prog.mcu->mcuName);
} else {
SendMessage(StatusBar, SB_SETTEXT, 0, (LPARAM)_("no MCU selected"));
}
char buf[256];
sprintf(buf, _("cycle time %.2f ms"), (double)Prog.cycleTime/1000.0);
SendMessage(StatusBar, SB_SETTEXT, 1, (LPARAM)buf);
if(Prog.mcu && (Prog.mcu->whichIsa == ISA_ANSIC ||
Prog.mcu->whichIsa == ISA_INTERPRETED))
{
strcpy(buf, "");
} else {
sprintf(buf, _("processor clock %.4f MHz"),
(double)Prog.mcuClock/1000000.0);
}
SendMessage(StatusBar, SB_SETTEXT, 2, (LPARAM)buf);
for(i = 0; i < NUM_SUPPORTED_MCUS; i++) {
if(&SupportedMcus[i] == Prog.mcu) {
CheckMenuItem(ProcessorMenu, MNU_PROCESSOR_0+i, MF_CHECKED);
} else {
CheckMenuItem(ProcessorMenu, MNU_PROCESSOR_0+i, MF_UNCHECKED);
}
}
// `(no microcontroller)' setting
if(!Prog.mcu) {
CheckMenuItem(ProcessorMenu, MNU_PROCESSOR_0+i, MF_CHECKED);
} else {
CheckMenuItem(ProcessorMenu, MNU_PROCESSOR_0+i, MF_UNCHECKED);
}
}
//-----------------------------------------------------------------------------
// Regenerate the I/O list, keeping the selection in the same place if
// possible.
//-----------------------------------------------------------------------------
void GenerateIoListDontLoseSelection(void)
{
int i;
IoListSelectionPoint = -1;
for(i = 0; i < Prog.io.count; i++) {
if(ListView_GetItemState(IoList, i, LVIS_SELECTED)) {
IoListSelectionPoint = i;
break;
}
}
IoListSelectionPoint = GenerateIoList(IoListSelectionPoint);
// can't just update the listview index; if I/O has been added then the
// new selection point might be out of range till we refill it
IoListOutOfSync = TRUE;
RefreshControlsToSettings();
}
//-----------------------------------------------------------------------------
// Called when the main window has been resized. Adjust the size of the
// status bar and the listview to reflect the new window size.
//-----------------------------------------------------------------------------
void MainWindowResized(void)
{
RECT main;
GetClientRect(MainWindow, &main);
RECT status;
GetWindowRect(StatusBar, &status);
int statusHeight = status.bottom - status.top;
MoveWindow(StatusBar, 0, main.bottom - statusHeight, main.right,
statusHeight, TRUE);
// Make sure that the I/O list can't disappear entirely.
if(IoListHeight < 30) {
IoListHeight = 30;
}
IoListTop = main.bottom - IoListHeight - statusHeight;
// Make sure that we can't drag the top of the I/O list above the
// bottom of the menu bar, because it then becomes inaccessible.
if(IoListTop < 5) {
IoListHeight = main.bottom - statusHeight - 5;
IoListTop = main.bottom - IoListHeight - statusHeight;
}
MoveWindow(IoList, 0, IoListTop, main.right, IoListHeight, TRUE);
RefreshScrollbars();
InvalidateRect(MainWindow, NULL, FALSE);
}
//-----------------------------------------------------------------------------
// Toggle whether we are in simulation mode. A lot of options are only
// available in one mode or the other.
//-----------------------------------------------------------------------------
void ToggleSimulationMode(void)
{
InSimulationMode = !InSimulationMode;
if(InSimulationMode) {
EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_ENABLED);
EnableMenuItem(SimulateMenu, MNU_SINGLE_CYCLE, MF_ENABLED);
EnableMenuItem(FileMenu, MNU_OPEN, MF_GRAYED);
EnableMenuItem(FileMenu, MNU_SAVE, MF_GRAYED);
EnableMenuItem(FileMenu, MNU_SAVE_AS, MF_GRAYED);
EnableMenuItem(FileMenu, MNU_NEW, MF_GRAYED);
EnableMenuItem(FileMenu, MNU_EXPORT, MF_GRAYED);
EnableMenuItem(TopMenu, 1, MF_GRAYED | MF_BYPOSITION);
EnableMenuItem(TopMenu, 2, MF_GRAYED | MF_BYPOSITION);
EnableMenuItem(TopMenu, 3, MF_GRAYED | MF_BYPOSITION);
EnableMenuItem(TopMenu, 5, MF_GRAYED | MF_BYPOSITION);
CheckMenuItem(SimulateMenu, MNU_SIMULATION_MODE, MF_CHECKED);
ClearSimulationData();
// Recheck InSimulationMode, because there could have been a compile
// error, which would have kicked us out of simulation mode.
if(UartFunctionUsed() && InSimulationMode) {
ShowUartSimulationWindow();
}
} else {
RealTimeSimulationRunning = FALSE;
KillTimer(MainWindow, TIMER_SIMULATE);
EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_GRAYED);
EnableMenuItem(SimulateMenu, MNU_STOP_SIMULATION, MF_GRAYED);
EnableMenuItem(SimulateMenu, MNU_SINGLE_CYCLE, MF_GRAYED);
EnableMenuItem(FileMenu, MNU_OPEN, MF_ENABLED);
EnableMenuItem(FileMenu, MNU_SAVE, MF_ENABLED);
EnableMenuItem(FileMenu, MNU_SAVE_AS, MF_ENABLED);
EnableMenuItem(FileMenu, MNU_NEW, MF_ENABLED);
EnableMenuItem(FileMenu, MNU_EXPORT, MF_ENABLED);
EnableMenuItem(TopMenu, 1, MF_ENABLED | MF_BYPOSITION);
EnableMenuItem(TopMenu, 2, MF_ENABLED | MF_BYPOSITION);
EnableMenuItem(TopMenu, 3, MF_ENABLED | MF_BYPOSITION);
EnableMenuItem(TopMenu, 5, MF_ENABLED | MF_BYPOSITION);
CheckMenuItem(SimulateMenu, MNU_SIMULATION_MODE, MF_UNCHECKED);
if(UartFunctionUsed()) {
DestroyUartSimulationWindow();
}
}
UpdateMainWindowTitleBar();
DrawMenuBar(MainWindow);
InvalidateRect(MainWindow, NULL, FALSE);
ListView_RedrawItems(IoList, 0, Prog.io.count - 1);
}
//-----------------------------------------------------------------------------
// Start real-time simulation. Have to update the controls grayed status
// to reflect this.
//-----------------------------------------------------------------------------
void StartSimulation(void)
{
RealTimeSimulationRunning = TRUE;
EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_GRAYED);
EnableMenuItem(SimulateMenu, MNU_STOP_SIMULATION, MF_ENABLED);
StartSimulationTimer();
UpdateMainWindowTitleBar();
}
//-----------------------------------------------------------------------------
// Stop real-time simulation. Have to update the controls grayed status
// to reflect this.
//-----------------------------------------------------------------------------
void StopSimulation(void)
{
RealTimeSimulationRunning = FALSE;
EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_ENABLED);
EnableMenuItem(SimulateMenu, MNU_STOP_SIMULATION, MF_GRAYED);
KillTimer(MainWindow, TIMER_SIMULATE);
UpdateMainWindowTitleBar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -