我在MS Windows 8.1上使用Gtk3中的GtkFixed模型时遇到问题。我正在使用GtkFixed模型,因为我有一个主窗口,其中显示位图,并且在位图顶部需要一个“浮动”小部件或堆叠小部件,以显示它的放大部分。我有位图视图的滚动条,需要知道如何获得绘图区域的准确高度,以便在调整窗口大小时调整滚动区域的大小。如何获得没有边框和标题栏的窗口大小 - 窗口客户区高度?我在'configure-event'和'size-allocate'信号中捕获了窗口高度,并且还使用了gtk_widget_get_allocation但是返回的高度大于窗口的实际像素高度,所以当我去调整滚动条的大小时它被卡在无限循环中的区域,因为主窗口每次都被放大。如何获得绘图区域的正确高度,以便我可以调整滚动区域的大小并正确定位浮动缩放小部件?
SlideWindow::SlideWindow()
{
// other init stuff here not related...
zoomWidgetWidth=320;
zoomWidgetHeight=240;
zoomGap=100;
}
// below function is static so safe for callback
void SlideWindow::sizeAllocateCallback(GtkWidget *mainWidget, GdkRectangle *allocation, gpointer data)
{
SlideWindow *slideWindow=(SlideWindow*) data;
int moveX=allocation->width - zoomWidgetWidth - zoomGap
int moveY=allocation->height - zoomWidgetHeight - zoomGap;
if (moveX < 100) moveX=100;
if (moveY < 100) moveY=100;
std::cout << "Main window width=" << allocation->width << " height=" << allocation->height << std::endl; // this just loops and gets bigger and bigger
gtk_fixed_move(slideWindow->fixedWidget, slideWindow->zoomWidget, moveX, moveY);
gtk_widget_set_size_request(slideWindow->scrollWidget, allocation->width, allocation->height); // this causes an infinite loop because the main window is then resized to fit the enlarged scroll area
}
stackoverflow上有人提到使用函数gdk_window_get_origin y坐标减去gdk_window_get_frame_extents函数的y坐标来获取标题栏的总大小,但两个函数都返回相同的Y位置:
// In size allocate callback:
GdkRectangle rect;
GdkWindow *gdkWindow = gtk_widget_get_window(mainWidget);
gdk_window_get_frame_extents(gdkWindow, &rect);
gint originX, originY;
gdk_window_get_origin(gdkWindow, &originX, &originY);
std::cout << " Window frame extents: x=" << rect.x << " width=" <<
rect.width << " y=" << rect.y << " height=" << rect.height;
std::cout << " originX=" << originX << " originY=" << originY << std::endl;
// Here originY==rect.y on Windows