Skip to content

Commit

Permalink
Remembered treeview or not, fixed focus problem
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Oct 22, 2010
1 parent 10ffb73 commit 3b4b5cb
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 21 deletions.
1 change: 1 addition & 0 deletions dialogs/world_prefs/GenPropertyPage.h
Expand Up @@ -65,6 +65,7 @@ class CGenPropertyPage : public CPropertyPage
CListCtrl * m_ctlList; // the list control which displays the items
CStatic * m_ctlSummary; // count of items shown
bool m_bWantTreeControl; // true if it wants to show a tree control instead of a list control
bool m_bReloadList; // true to reload the list in the idle loop

// count of columns is used for arrays below
int m_iColumnCount; // how many columns there are
Expand Down
11 changes: 8 additions & 3 deletions dialogs/world_prefs/configuration.cpp
Expand Up @@ -206,7 +206,7 @@ void CMUSHclientDoc:: LoadPrefsP7 (CPrefsP7 &page7)
page7.CompareObjects,
&m_AliasesFindInfo,
XML_ALIASES,
true); // tree control
m_bTreeviewAliases); // tree control

page7.m_iColumnCount = CPrefsP7::eColumnCount;
page7.m_iColWidth = new int [CPrefsP7::eColumnCount];
Expand Down Expand Up @@ -248,7 +248,7 @@ void CMUSHclientDoc:: LoadPrefsP8 (CPrefsP8 &page8)
page8.CompareObjects,
&m_TriggersFindInfo,
XML_TRIGGERS,
true); // tree control
m_bTreeviewTriggers); // tree control

page8.m_iColumnCount = CPrefsP8::eColumnCount;
page8.m_iColWidth = new int [CPrefsP8::eColumnCount];
Expand Down Expand Up @@ -585,7 +585,7 @@ void CMUSHclientDoc:: LoadPrefsP16 (CPrefsP16 &page16)
page16.CompareObjects,
&m_TimersFindInfo,
XML_TIMERS,
true); // tree control
m_bTreeviewAliases); // tree control


page16.m_iColumnCount = CPrefsP16::eColumnCount;
Expand Down Expand Up @@ -2180,6 +2180,11 @@ Frame.DelayDebugStatus ("World config - loading pages");
m_strLastSelectedTimer = page16.m_strSelectedItem ;
m_strLastSelectedVariable = page18.m_strSelectedItem ;

// remember whether they are using tree or list controls
m_bTreeviewAliases = page7.m_bWantTreeControl;
m_bTreeviewTriggers = page8.m_bWantTreeControl;
m_bTreeviewTimers = page16.m_bWantTreeControl;

if (iResult != IDOK)
{
Frame.SetStatusNormal ();
Expand Down
63 changes: 46 additions & 17 deletions dialogs/world_prefs/genpropertypage.cpp
Expand Up @@ -33,6 +33,8 @@ CGenPropertyPage::CGenPropertyPage(const UINT nID) :
m_strColumnHeadings = NULL;
m_iColumnCount = 0;
m_bWantTreeControl = false;
m_bReloadList = false;


} // end of CGenPropertyPage::CGenPropertyPage

Expand Down Expand Up @@ -267,7 +269,7 @@ void CGenPropertyPage::OnAddItem(CDialog & dlg)

// redraw the list
if (GetFilterFlag ())
LoadList (); // full reload because it may have changed filter requirements
m_bReloadList = true; // full reload because it may have changed filter requirements

// get dispatch id from the script and put it into the item

Expand Down Expand Up @@ -571,7 +573,7 @@ void CGenPropertyPage::OnChangeItem(CDialog & dlg)

// redraw the list
if (GetFilterFlag ())
LoadList (); // full reload because it may have changed filter requirements
m_bReloadList = true; // full reload because it may have changed filter requirements

// resort the list

Expand Down Expand Up @@ -831,6 +833,11 @@ HTREEITEM CGenPropertyPage::add_tree_item (CObject * pItem,
if (strDescription.GetLength () > 100)
strDescription = strDescription.Left (100) + " ...";


/*
// looks a bit wanky
CString strLabel = GetLabel (pItem);
// add the label if it exists
Expand All @@ -841,6 +848,8 @@ HTREEITEM CGenPropertyPage::add_tree_item (CObject * pItem,
strDescription = strDescription + "]";
}
*/

// insert it
HTREEITEM hNewItem = m_cTreeCtrl.InsertItem (strDescription, hParent);

Expand Down Expand Up @@ -1068,6 +1077,8 @@ void CGenPropertyPage::LoadList (void)

SortItems ();

bool bSelected = false;

// put selected item back
if (!m_strSelectedItem.IsEmpty ())
{
Expand All @@ -1087,11 +1098,14 @@ void CGenPropertyPage::LoadList (void)
{
// select the new item
m_cTreeCtrl.SelectItem (hItem);
m_cTreeCtrl.EnsureVisible (hItem);
m_cTreeCtrl.EnsureVisible (hItem);
bSelected = true;
break;
}
} // end for each item

if (bSelected)
break;
} // end for each group

} // end of tree control
Expand All @@ -1107,25 +1121,24 @@ void CGenPropertyPage::LoadList (void)
{
m_ctlList->SetItemState (nItem, LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
m_ctlList->EnsureVisible (nItem, FALSE);
m_ctlList->EnsureVisible (nItem, FALSE);
bSelected = true;
break;
}

} // end of dealing with each item

// set the 1st item to be selected - we do this here because sorting the
// list means our first item is not necessarily the 1st item in the list
if (nItem == -1)
{
if (!m_ObjectMap->IsEmpty ()) // provided we have any
m_ctlList->SetItemState (0, LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
}

} // end of list control
} // end of having a previously-selected item


// set the 1st item to be selected - we do this here because sorting the
// list means our first item is not necessarily the 1st item in the list
if (!bSelected && !m_bWantTreeControl)
if (!m_ObjectMap->IsEmpty ()) // provided we have any
m_ctlList->SetItemState (0, LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);

CString strSummary = TFormat ("%i item%s.", PLURAL (iCount));

if (iNotShown)
Expand Down Expand Up @@ -1155,6 +1168,22 @@ void CGenPropertyPage::LoadList (void)

LRESULT CGenPropertyPage::OnKickIdle(WPARAM, LPARAM)
{
/*
Note: I was getting access violations at times, in particular when you
double-clicked to edit an entry in tree-view. I think now that this is because
LoadList deleted all items and re-added them, which meant that the tree item
which was being edited got yanked out while the Windows message was still being
processed by the system, and so it got a missing or NULL CWnd item when it didn't
expect it. I now defer reloading the list to the idle loop.
*/

if (m_bReloadList)
{
m_bReloadList = false;
LoadList ();
}

UpdateDialogControls (AfxGetApp()->m_pMainWnd, false);
return 0;
} // end of CGenPropertyPage::OnKickIdle
Expand Down Expand Up @@ -1465,11 +1494,11 @@ BOOL CGenPropertyPage::OnInitDialog()
// recover column sequence

m_ctlList->SendMessage (LVM_SETCOLUMNORDERARRAY, m_iColumnCount, (DWORD) iColOrder);

LoadList ();


delete [] iColOrder;

m_bReloadList = true; // defer so focus gets set correctly

return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
} // end of CGenPropertyPage::OnInitDialog
Expand Down Expand Up @@ -1742,7 +1771,7 @@ CString strContents;
m_doc->SetModifiedFlag (TRUE);

// reload the list - we don't know how many were added, and indeed, what they were
LoadList ();
m_bReloadList = true; // full reload because it may have changed filter requirements

} // end of CGenPropertyPage::OnPasteItem

Expand Down
6 changes: 6 additions & 0 deletions doc.h
Expand Up @@ -874,6 +874,12 @@ class CMUSHclientDoc : public CDocument
COLORREF m_OutputLinePreambleNotesTextColour; // text colour - Note preamble
COLORREF m_OutputLinePreambleNotesBackColour; // back colour - Note preamble

// version 4.65

unsigned short m_bTreeviewTriggers; // show triggers in tree view?
unsigned short m_bTreeviewAliases; // show aliases in tree view?
unsigned short m_bTreeviewTimers; // show timers in tree view?

// end of stuff saved to disk **************************************************************

// stuff from pre version 11, read from disk but not saved
Expand Down
4 changes: 4 additions & 0 deletions doc_construct.cpp
Expand Up @@ -420,6 +420,10 @@ int i;

m_iOutputWindowRedrawCount = 0;

m_bTreeviewTriggers = true;
m_bTreeviewAliases = true;
m_bTreeviewTimers = true;

// set up some default triggers for MUSHes

/*
Expand Down
6 changes: 5 additions & 1 deletion scriptingoptions.cpp
Expand Up @@ -186,7 +186,11 @@ tConfigurationNumericOption OptionsTable [] = {
{"timestamp_notes_back_colour", RGB (0, 0, 0), O(m_OutputLinePreambleNotesBackColour), 0, 0xFFFFFF, OPT_RGB_COLOUR | OPT_UPDATE_VIEWS},
{"timestamp_output_back_colour", RGB (0, 0, 0), O(m_OutputLinePreambleOutputBackColour),0, 0xFFFFFF, OPT_RGB_COLOUR | OPT_UPDATE_VIEWS},
{"translate_backslash_sequences", false, O(m_bTranslateBackslashSequences)},
{"translate_german", false, O(m_bTranslateGerman)},
{"translate_german", false, O(m_bTranslateGerman)},
{"treeview_triggers", true, O(m_bTreeviewTriggers)},
{"treeview_aliases", true, O(m_bTreeviewAliases)},
{"treeview_timers", true, O(m_bTreeviewTimers)},

{"underline_hyperlinks", true, O(m_bUnderlineHyperlinks), 0, 0, OPT_SERVER_CAN_WRITE},
{"unpause_on_send", true, O(m_bUnpauseOnSend)},
{"use_custom_link_colour", true, O(m_bUseCustomLinkColour), 0, 0, OPT_SERVER_CAN_WRITE},
Expand Down

0 comments on commit 3b4b5cb

Please sign in to comment.