nuiSize nuiPopupMenu::AdjustRectsPos(nuiSize& rX, nuiSize& rY, uint depth, nuiRect CurRect) { nuiTopLevel* pRoot = GetTopLevel(); NGL_ASSERT(pRoot); NGL_ASSERT(depth+1 < mRects.size()); nuiRect MainRect = pRoot->GetRect(); nuiRect& prevRect(mRects[depth]->mRect); // prevRect is the previous rect in the hierarchy (NOT the previous rect of this sub menu) depth++; nuiMenuRect* pMenuRect = mRects[depth]; nuiRect& rRect(pMenuRect->mRect); nuiSize x, y; x = rX + (mXdir * rRect.GetWidth()) - (mXdir < 0 ? prevRect.GetWidth() : 0); // Compute X so that the rect doesn't get out of the main container y = rY + (mYdir * rRect.GetHeight()) + (mYdir < 0 ? CurRect.GetHeight() : 0); // Compute Y so that the rect doesn't get out of the main container if (x > MainRect.GetWidth() || x < 0) // Should we change the current x direction? mXdir *= -1; if (y > MainRect.GetHeight() || y < 0) // Should we change the current y direction? mYdir *= -1; rX = rX - ((mXdir < 0) ? rRect.GetWidth() + prevRect.GetWidth() : 0); rY = rY - ((mYdir < 0) ? rRect.GetHeight() - CurRect.GetHeight() : 0); if (rY < 0) rY = 0; if ( ( (mYdir > 0) && (MainRect.GetHeight() < (rY + rRect.GetHeight()) ) ) || ( (mYdir < 0) && (0 > (rY - rRect.GetHeight()) ) ) ) { nuiSize heightDiff = MainRect.GetHeight() - rRect.GetHeight(); if (heightDiff > 0) { rY = heightDiff; } else { nuiRect r( ToNearest(rX + rRect.GetWidth() - SB_WIDTH), 0, ToNearest(SB_WIDTH), ToNearest(MainRect.GetHeight())); pMenuRect->mpSBar->GetRange().SetRange(0.f, rRect.GetHeight()); pMenuRect->mpSBar->GetRange().SetPageSize(MainRect.GetHeight()); pMenuRect->mpSBar->GetRange().SetIncrement(10.f); pMenuRect->mpSBar->SetLayout(r); pMenuRect->mpSBar->SetVisible(true); pMenuRect->mpSBar->SetSelected(false); pMenuRect->mpSBar->SetEnabled(true); rY = -pMenuRect->mpSBar->GetRange().GetValue(); return (SB_WIDTH); } } if (pMenuRect->mpSBar) { pMenuRect->mpSBar->SetVisible(false); pMenuRect->mpSBar->SetEnabled(false); } return (0.f); }
void nuiSlider::HookMouse() { mClicked = true; mThumbClicked = true; mInteractiveValueChanged = true; Grab(); Invalidate(); mClickValue = mRange.GetValue(); nglMouseInfo info; GetTopLevel()->GetMouseInfo(info); mClickX = info.X; mClickY = info.Y; GlobalToLocal(mClickX, mClickY); }
// // Open preview in standalone window // void CPreview::ShowFileModal(void) { GdkRectangle rc; char buf[FILENAME_MAX+128]; GtkWindow *pParent = GTK_WINDOW(GetTopLevel()); if (m_FileType!=TYPE_IMAGE && m_FileType!=TYPE_CAT && m_FileType!=TYPE_PHOT && m_FileType!=TYPE_TABLE) return; // Dialog with buttons GtkWidget *pDlg = gtk_dialog_new_with_buttons("", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(pDlg)); // Dialog size GdkScreen *scr = gtk_window_get_screen(pParent); int mon = gdk_screen_get_monitor_at_window(scr, GTK_WIDGET(pParent)->window); gdk_screen_get_monitor_geometry(scr, mon, &rc); if (rc.width>0 && rc.height>0) gtk_window_set_default_size(GTK_WINDOW(pDlg), RoundToInt(0.7*rc.width), RoundToInt(0.7*rc.height)); // Dialog icon char *icon = get_icon_file("preview"); gtk_window_set_icon(GTK_WINDOW(pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // Preview widget GtkWidget *preview = cmpack_preview_new_with_model(m_Data); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pDlg)->vbox), preview, TRUE, TRUE, 0); if (m_FileType == TYPE_TABLE) { cmpack_preview_set_x_axis(CMPACK_PREVIEW(preview), FALSE, FALSE, m_MinX, m_MaxX, m_EpsX); cmpack_preview_set_y_axis(CMPACK_PREVIEW(preview), FALSE, m_ReverseY, m_MinY, m_MaxY, m_EpsY); } bool chart_invert = CConfig::GetBool(CConfig::NEGATIVE_CHARTS); cmpack_preview_set_negative(CMPACK_PREVIEW(preview), chart_invert); bool rows_upward = CConfig::GetBool(CConfig::ROWS_UPWARD); cmpack_preview_set_image_orientation(CMPACK_PREVIEW(preview), rows_upward ? CMPACK_ROWS_UPWARDS : CMPACK_ROWS_DOWNWARDS); // Display the preview dialog gchar *basename = g_path_get_basename(m_Path); sprintf(buf, "%s - %s", basename, g_AppTitle); g_free(basename); gtk_window_set_title(GTK_WINDOW(pDlg), buf); gtk_widget_show_all(pDlg); gtk_dialog_run(GTK_DIALOG(pDlg)); gtk_widget_destroy(pDlg); }
bool nuiWindowManager::ActivateWindow(nuiWindow* pWin) { nuiTopLevel* pRoot = GetTopLevel(); NGL_ASSERT(pRoot != NULL); pRoot->CancelGrab(); pRoot->SetFocus(NULL); mWindows.remove(pWin); mWindows.push_back(pWin); RaiseChildToFront(pWin); pWin->Invalidate(); Invalidate(); return true; }
nuiSize nuiPopupMenu::AdjustPosToSize(nuiMenuRect* rPosRect) { nuiTopLevel* pRoot = GetTopLevel(); NGL_ASSERT(pRoot); nuiRect MainRect = pRoot->GetRect(); // adjust horizontally if (rPosRect->mRect.Right() > MainRect.GetWidth()) { rPosRect->mRect.Set(rPosRect->mRect.Left() - (rPosRect->mRect.Right() - MainRect.GetWidth()), rPosRect->mRect.Top(), rPosRect->mRect.GetWidth(), rPosRect->mRect.GetHeight()); } // adjust vertically if (rPosRect->mRect.Bottom() > MainRect.GetHeight()) { rPosRect->mRect.Set(rPosRect->mRect.Left(), rPosRect->mRect.Top() - (rPosRect->mRect.Bottom() - MainRect.GetHeight()) - NUI_POPUP_MARGIN, rPosRect->mRect.GetWidth(), rPosRect->mRect.GetHeight()); } // check for scrollbar if (rPosRect->mRect.GetHeight() > MainRect.GetHeight()) { nuiRect r( ToNearest(rPosRect->mRect.Right() - SB_WIDTH), 0, ToNearest(SB_WIDTH), ToNearest(MainRect.GetHeight())); rPosRect->mpSBar->GetRange().EnableEvents(false); rPosRect->mpSBar->GetRange().SetRange(0.f, rPosRect->mRect.GetHeight()); rPosRect->mpSBar->GetRange().SetPageSize(MainRect.GetHeight()); rPosRect->mpSBar->GetRange().SetIncrement(10.f); rPosRect->mpSBar->GetRange().EnableEvents(true); rPosRect->mpSBar->SetLayout(r); rPosRect->mpSBar->SetVisible(true); rPosRect->mpSBar->SetEnabled(true); nuiSize decal = rPosRect->mpSBar->GetRange().GetValue(); rPosRect->mRect.Set(rPosRect->mRect.Left(), 0.f, rPosRect->mRect.GetWidth(), rPosRect->mRect.GetHeight()); return (decal); } else if (rPosRect->mpSBar) { rPosRect->mpSBar->SetVisible(false); rPosRect->mpSBar->SetEnabled(false); } return -1.f; }
void nuiPopupMenu::AdjustScrolling(nuiTreeNode* pNode) { // range changes, OnScrollBarChange() will be called nuiTopLevel* pRoot = GetTopLevel(); NGL_ASSERT(pRoot); nuiRect MainRect = pRoot->GetRect(); nuiRect NodeRect = pNode->GetElement()->GetRect(); if (pNode->GetDepth()-1 >= mRects.size()) return; nuiMenuRect* pMenuRect = mRects[pNode->GetDepth()-1]; nuiRange& rRange = pMenuRect->mpSBar->GetRange(); if (NodeRect.Bottom() > MainRect.Bottom()) { mScrolledFromKeyboard = true; rRange.SetValue(rRange.GetValue() + (NodeRect.Bottom() - MainRect.Bottom())); } else if (NodeRect.Top() < 0.f) { mScrolledFromKeyboard = true; rRange.SetValue(rRange.GetValue() + NodeRect.Top()); } }
bool nuiSimpleContainer::DelChild(nuiWidgetPtr pChild) { CheckValid(); NGL_ASSERT(pChild->GetParent() == this) if (GetDebug()) { NGL_OUT(_T("[%s] Del Child 0x%x <--- 0x%x (%s)\n"), GetObjectClass().GetChars(), this, pChild); } nuiWidgetList::iterator it = mpChildren.begin(); nuiWidgetList::iterator end = mpChildren.end(); for ( ; it != end; ++it) { if (*it == pChild) { mpChildren.erase(it); if (!pChild->IsTrashed()) { nuiTopLevel* pRoot = GetTopLevel(); Trashed(); Invalidate(); if (pRoot) pRoot->AdviseObjectDeath(pChild); pChild->SetParent(NULL); } ChildDeleted(this, pChild); Invalidate(); InvalidateLayout(); DebugRefreshInfo(); pChild->Release(); return true; } } DebugRefreshInfo(); return false; }
void nuiMessageBox::Init(const nglString& rTitle, nuiWidget* pContents, nuiMessageBoxType type, bool showIcon) { SetObjectClass(_T("nuiMessageBox")); mType = type; mKeyDown = false; mClickedButton = ButtonCancel; nuiVBox* pVBox = new nuiVBox(); pVBox->SetExpand(nuiExpandShrinkAndGrow); pVBox->SetObjectName(_T("nuiMessageBox::Client")); AddChild(pVBox); nuiLabel* pTitle = new nuiLabel(rTitle); pTitle->SetObjectName(_T("nuiMessageBox::Title")); pTitle->SetObjectClass(_T("nuiMessageBox::Title")); pVBox->AddCell(pTitle); nuiHBox* pHBox = new nuiHBox(2); pHBox->SetExpand(nuiExpandShrinkAndGrow); pHBox->SetObjectName(_T("nuiMessageBox::Contents")); pVBox->AddCell(pHBox); pVBox->SetCellExpand(pVBox->GetNbCells()-1, nuiExpandShrinkAndGrow); if (showIcon) { nuiSimpleContainer* pIcon = new nuiSimpleContainer(); nglString objectName; objectName.Format(_T("nuiMessageBox::Icon"), rTitle.GetChars()); pIcon->SetObjectName(objectName); pHBox->SetCell(0, pIcon, nuiCenter); } pHBox->SetCell(1, pContents); pHBox->SetCellExpand(1, nuiExpandShrinkAndGrow); mpBtnBox = new nuiHBox(); mpBtnBox->SetObjectName(_T("nuiMessageBox::ButtonBox")); pVBox->AddCell(mpBtnBox); mpBtnBox->AddCell(NULL); mpBtnBox->SetCellExpand(mpBtnBox->GetNbCells()-1, nuiExpandShrinkAndGrow); switch (mType) { case eMB_OK: mpBtnBox->AddCell(CreateOK()); mpBtnBox->SetPosition(nuiCenter); break; case eMB_Cancel: mpBtnBox->AddCell(CreateCancel()); mpBtnBox->SetPosition(nuiCenter); break; case eMB_OKCancel: mpBtnBox->AddCell(CreateOK()); mpBtnBox->AddCell(CreateCancel()); break; case eMB_RetryOKCancel: mpBtnBox->AddCell(CreateRetry()); mpBtnBox->AddCell(CreateOK()); mpBtnBox->AddCell(CreateCancel()); break; case eMB_YesNo: mpBtnBox->AddCell(CreateYes()); mpBtnBox->AddCell(CreateNo()); break; case eMB_Custom: break; } SetPosition(nuiCenter); GetTopLevel()->SetFocus(this); // default decoration nuiDefaultDecoration::MessageBox(this); }
nuiWidgetPtr nuiContainer::DispatchMouseMove(const nglMouseInfo& rInfo) { CheckValid(); nuiAutoRef; if (!mMouseEventEnabled || mTrashed) return false; nuiWidgetPtr pHandled=NULL; bool inside=false,res=false; bool hasgrab = HasGrab(rInfo.TouchId); if (IsDisabled() && !hasgrab) return NULL; nglMouseInfo info(rInfo); GlobalToLocal(info.X, info.Y); // Get a chance to preempt the mouse event before the children get it: if (PreMouseMoved(info)) return this; if (IsInsideFromRoot(rInfo.X, rInfo.Y) || hasgrab) { inside = true; // If the object has the grab we should not try to notify its children of mouse events! if (!hasgrab) { IteratorPtr pIt; for (pIt = GetLastChild(false); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem) { if (pItem->IsVisible()) { pHandled = pItem->DispatchMouseMove(rInfo); } } if (pHandled) { // stop as soon as someone caught the event delete pIt; return pHandled; } } delete pIt; } res = MouseMoved(info); res |= MovedMouse(info); } else { if (GetHover()) { res = MouseMoved(info); res |= MovedMouse(info); } } if (!pHandled && (res | (!mClickThru)) && inside) { nuiTopLevelPtr pRoot = GetTopLevel(); if (pRoot) return this; } if (pHandled) return pHandled; return (res && inside) ? this : NULL; }