CString CToolbarHelper::GetTip(UINT nID, LPPOINT pPoint) const { if (!nID) { return _T(""); // separator } // are we over the dropbutton? BOOL bOverDropBtn = FALSE; if (pPoint) { CSize sizeBtn(m_pToolbar->GetToolBarCtrl().GetButtonSize()); CRect rButton; m_pToolbar->GetToolBarCtrl().GetRect(nID, rButton); rButton.left += sizeBtn.cx; if (rButton.PtInRect(*pPoint)) { bOverDropBtn = TRUE; } } CString sTip; // do we have a mapping for this THButton dm; if (m_mapTHButtons.Lookup(nID, dm)) { if (!bOverDropBtn) { // try the default item first if (dm.nDefCmdID && IsCmdEnabled(dm.nDefCmdID)/* && (dm.nDefCmdID != nID)*/) { sTip = GetTip(dm.nDefCmdID); if (!sTip.IsEmpty()) { return sTip; } } } // try override tip if (_tcslen(dm.szTip)) { return dm.szTip; } } return GetTip(nID); }
void CToolsHelper::AppendToolsToToolbar(const CUserToolArray& aTools, CToolBar& toolbar, UINT nCmdAfter) { // remove tools first RemoveToolsFromToolbar(toolbar, nCmdAfter); // then re-add if (aTools.GetSize()) { // figure out if we want the large or small images CSize sizeBtn(toolbar.GetToolBarCtrl().GetButtonSize()); sizeBtn -= CSize(7, 7); // btn borders from BarTool.cpp CSysImageList sil((sizeBtn.cx > 16)); VERIFY(sil.Initialize()); // start adding after the pref button int nStartPos = toolbar.CommandToIndex(nCmdAfter) + 1; int nAdded = 0; for (int nTool = 0; nTool < aTools.GetSize(); nTool++) { const USERTOOL& tool = aTools[nTool]; HICON hIcon = GetToolIcon(sil, tool); if (hIcon) { CImageList* pIL = toolbar.GetToolBarCtrl().GetImageList(); int nImage = pIL->Add(hIcon); TBBUTTON tbb = { nImage, nTool + m_nStartID, 0, TBSTYLE_BUTTON, 0, 0, (UINT)-1 }; if (toolbar.GetToolBarCtrl().InsertButton(nStartPos + nAdded, &tbb)) nAdded++; else // remove image pIL->Remove(nImage); // cleanup ::DestroyIcon(hIcon); } } // add a separator if any buttons added if (nAdded) { TBBUTTON tbb = { -1, 0, 0, TBSTYLE_SEP, 0, 0, (UINT)-1 }; toolbar.GetToolBarCtrl().InsertButton(nStartPos, &tbb); } } }
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT ) style |= wxBORDER_SIMPLE; SetWindowStyle(style); WXDWORD exStyle = 0; WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; wxSize sizeText(size), sizeBtn(size); sizeBtn.x = GetBestSpinnerSize(IsVertical(style)).x / 2; if ( sizeText.x == wxDefaultCoord ) { // DEFAULT_ITEM_WIDTH is the default width for the text control sizeText.x = DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN + sizeBtn.x; } sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; if ( sizeText.x <= 0 ) { wxLogDebug(_T("not enough space for wxSpinCtrl!")); } wxPoint posBtn(pos); posBtn.x += sizeText.x + MARGIN_BETWEEN; // we need to turn '\n's into "\r\n"s for the multiline controls wxString valueWin; if ( m_windowStyle & wxTE_MULTILINE ) { valueWin = wxTextFile::Translate(value, wxTextFileType_Dos); } else // single line { valueWin = value; } // we must create the list control before the spin button for the purpose // of the dialog navigation: if there is a static text just before the spin // control, activating it by Alt-letter should give focus to the text // control, not the spin and the dialog navigation code will give focus to // the next control (at Windows level), not the one after it // create the text window m_hwndBuddy = (WXHWND)::CreateWindowEx ( exStyle, // sunken border _T("EDIT"), // window class valueWin, // no window title msStyle, // style (will be shown later) pos.x, pos.y, // position 0, 0, // size (will be set later) GetHwndOf(parent), // parent (HMENU)-1, // control id wxGetInstance(), // app instance NULL // unused client data ); if ( !m_hwndBuddy ) { wxLogLastError(wxT("CreateWindow(buddy text window)")); return false; } // initialize wxControl if ( !CreateControl(parent, id, posBtn, sizeBtn, style, validator, name) ) return false; // now create the real HWND WXDWORD spiner_style = WS_VISIBLE | UDS_ALIGNRIGHT | UDS_EXPANDABLE | UDS_NOSCROLL; if ( !IsVertical(style) ) spiner_style |= UDS_HORZ; if ( style & wxSP_WRAP ) spiner_style |= UDS_WRAP; if ( !MSWCreateControl(UPDOWN_CLASS, spiner_style, posBtn, sizeBtn, _T(""), 0) ) return false; // subclass the text ctrl to be able to intercept some events wxSetWindowUserData(GetBuddyHwnd(), this); m_wndProcBuddy = (WXFARPROC)wxSetWindowProc(GetBuddyHwnd(), wxBuddyTextCtrlWndProc); // set up fonts and colours (This is nomally done in MSWCreateControl) InheritAttributes(); if (!m_hasFont) SetFont(GetDefaultAttributes().font); // set the size of the text window - can do it only now, because we // couldn't call DoGetBestSize() before as font wasn't set if ( sizeText.y <= 0 ) { int cx, cy; wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); } SetInitialSize(size); (void)::ShowWindow(GetBuddyHwnd(), SW_SHOW); // associate the list window with the spin button (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)GetBuddyHwnd(), 0); // do it after finishing with m_hwndBuddy creation to avoid generating // initial wxEVT_COMMAND_TEXT_UPDATED message ms_allTextSpins.Add(this); return true; }
bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, int min, int max, int initial, const wxString& name) { // this should be in ctor/init function but I don't want to add one to 2.8 // to avoid problems with default ctor which can be inlined in the user // code and so might not get this fix without recompilation m_oldValue = INT_MIN; // before using DoGetBestSize(), have to set style to let the base class // know whether this is a horizontal or vertical control (we're always // vertical) style |= wxSP_VERTICAL; if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT ) #ifdef __WXWINCE__ style |= wxBORDER_SIMPLE; #else style |= wxBORDER_SUNKEN; #endif SetWindowStyle(style); WXDWORD exStyle = 0; WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; // calculate the sizes: the size given is the toal size for both controls // and we need to fit them both in the given width (height is the same) wxSize sizeText(size), sizeBtn(size); sizeBtn.x = wxSpinButton::DoGetBestSize().x; if ( sizeText.x <= 0 ) { // DEFAULT_ITEM_WIDTH is the default width for the text control sizeText.x = DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN + sizeBtn.x; } sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; if ( sizeText.x <= 0 ) { wxLogDebug(_T("not enough space for wxSpinCtrl!")); } wxPoint posBtn(pos); posBtn.x += sizeText.x + MARGIN_BETWEEN; // we must create the text control before the spin button for the purpose // of the dialog navigation: if there is a static text just before the spin // control, activating it by Alt-letter should give focus to the text // control, not the spin and the dialog navigation code will give focus to // the next control (at Windows level), not the one after it // create the text window m_hwndBuddy = (WXHWND)::CreateWindowEx ( exStyle, // sunken border _T("EDIT"), // window class NULL, // no window title msStyle, // style (will be shown later) pos.x, pos.y, // position 0, 0, // size (will be set later) GetHwndOf(parent), // parent (HMENU)-1, // control id wxGetInstance(), // app instance NULL // unused client data ); if ( !m_hwndBuddy ) { wxLogLastError(wxT("CreateWindow(buddy text window)")); return false; } // create the spin button if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) ) { return false; } wxSpinButtonBase::SetRange(min, max); // subclass the text ctrl to be able to intercept some events wxSetWindowUserData(GetBuddyHwnd(), this); m_wndProcBuddy = (WXFARPROC)wxSetWindowProc(GetBuddyHwnd(), wxBuddyTextWndProc); // set up fonts and colours (This is nomally done in MSWCreateControl) InheritAttributes(); if (!m_hasFont) SetFont(GetDefaultAttributes().font); // set the size of the text window - can do it only now, because we // couldn't call DoGetBestSize() before as font wasn't set if ( sizeText.y <= 0 ) { int cx, cy; wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); } SetInitialSize(size); (void)::ShowWindow(GetBuddyHwnd(), SW_SHOW); // associate the text window with the spin button (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); SetValue(initial); // Set the range in the native control SetRange(min, max); if ( !value.empty() ) { SetValue(value); m_oldValue = (int) wxAtol(value); } else { SetValue(wxString::Format(wxT("%d"), initial)); m_oldValue = initial; } // do it after finishing with m_hwndBuddy creation to avoid generating // initial wxEVT_COMMAND_TEXT_UPDATED message ms_allSpins.Add(this); return true; }
bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, int min, int max, int initial, const wxString& name) { // before using DoGetBestSize(), have to set style to let the base class // know whether this is a horizontal or vertical control (we're always // vertical) style |= wxSP_VERTICAL; if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT ) #ifdef __WXWINCE__ style |= wxBORDER_SIMPLE; #else style |= wxBORDER_SUNKEN; #endif SetWindowStyle(style); WXDWORD exStyle = 0; WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; // Scroll text automatically if there is not enough space to show all of // it, this is better than not allowing to enter more digits at all. msStyle |= ES_AUTOHSCROLL; // propagate text alignment style to text ctrl if ( style & wxALIGN_RIGHT ) msStyle |= ES_RIGHT; else if ( style & wxALIGN_CENTER ) msStyle |= ES_CENTER; // calculate the sizes: the size given is the total size for both controls // and we need to fit them both in the given width (height is the same) wxSize sizeText(size), sizeBtn(size); sizeBtn.x = wxSpinButton::DoGetBestSize().x; if ( sizeText.x <= 0 ) { // DEFAULT_ITEM_WIDTH is the default width for the text control sizeText.x = DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN + sizeBtn.x; } sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; if ( sizeText.x <= 0 ) { wxLogDebug(wxT("not enough space for wxSpinCtrl!")); } wxPoint posBtn(pos); posBtn.x += sizeText.x + MARGIN_BETWEEN; // we must create the text control before the spin button for the purpose // of the dialog navigation: if there is a static text just before the spin // control, activating it by Alt-letter should give focus to the text // control, not the spin and the dialog navigation code will give focus to // the next control (at Windows level), not the one after it // create the text window m_hwndBuddy = (WXHWND)::CreateWindowEx ( exStyle, // sunken border wxT("EDIT"), // window class NULL, // no window title msStyle, // style (will be shown later) pos.x, pos.y, // position 0, 0, // size (will be set later) GetHwndOf(parent), // parent (HMENU)-1, // control id wxGetInstance(), // app instance NULL // unused client data ); if ( !m_hwndBuddy ) { wxLogLastError(wxT("CreateWindow(buddy text window)")); return false; } // create the spin button if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) ) { return false; } wxSpinButtonBase::SetRange(min, max); // subclass the text ctrl to be able to intercept some events gs_spinForTextCtrl[GetBuddyHwnd()] = this; m_wndProcBuddy = (WXFARPROC)wxSetWindowProc(GetBuddyHwnd(), wxBuddyTextWndProc); // set up fonts and colours (This is nomally done in MSWCreateControl) InheritAttributes(); if (!m_hasFont) SetFont(GetDefaultAttributes().font); // set the size of the text window - can do it only now, because we // couldn't call DoGetBestSize() before as font wasn't set if ( sizeText.y <= 0 ) { int cx, cy; wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); } SetInitialSize(size); (void)::ShowWindow(GetBuddyHwnd(), SW_SHOW); // associate the text window with the spin button (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); // If the initial text value is actually a number, it overrides the // "initial" argument specified later. long initialFromText; if ( value.ToLong(&initialFromText) ) initial = initialFromText; SetValue(initial); m_oldValue = initial; // Set the range in the native control SetRange(min, max); // Also set the text part of the control if it was specified independently // but don't generate an event for this, it would be unexpected. m_blockEvent = true; if ( !value.empty() ) SetValue(value); m_blockEvent = false; return true; }