]> source.dussan.org Git - tigervnc.git/commitdiff
Added ToolBar::getButtonsWidth(), ToolBar::getButtonsHeight().
authorgeorge82 <george82@3789f03b-4d11-0410-bbf8-ca57d06f2519>
Sun, 17 Apr 2005 11:54:31 +0000 (11:54 +0000)
committergeorge82 <george82@3789f03b-4d11-0410-bbf8-ca57d06f2519>
Sun, 17 Apr 2005 11:54:31 +0000 (11:54 +0000)
Modifed ToolBar::autoSize().
If toolbar has CCS_NORESIZE style, then autoSize() resizes toolbar itself
else it resizes by TB_AUTOSIZE message.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@291 3789f03b-4d11-0410-bbf8-ca57d06f2519

rfbplayer/ToolBar.cxx
rfbplayer/ToolBar.h

index c4808cc14289c0fe8581547666ef795baad8cb2b..d92d584911144ccccab0f898f390861b0c52e927 100644 (file)
@@ -33,7 +33,8 @@ ToolBar::~ToolBar() {
   DestroyWindow(getHandle());
 }
 
-bool ToolBar::create(int _tbID, HWND parentHwnd, DWORD dwStyle) {
+bool ToolBar::create(int _tbID, HWND _parentHwnd, DWORD dwStyle) {
+  parentHwnd = _parentHwnd;
   dwStyle |= WS_CHILD;
 
   // Create the ToolBar window
@@ -124,6 +125,14 @@ int ToolBar::getButtonInfo(int idButton, TBBUTTONINFO *btnInfo) {
   return SendMessage(getHandle(), TB_GETBUTTONINFO, idButton, (LPARAM)btnInfo);
 }
 
+int ToolBar::getButtonsHeight() {
+  return HIWORD(SendMessage(getHandle(), TB_GETBUTTONSIZE, 0, 0));
+}
+
+int ToolBar::getButtonsWidth() {
+  return LOWORD(SendMessage(getHandle(), TB_GETBUTTONSIZE, 0, 0));
+}
+
 bool ToolBar::setButtonInfo(int idButton, TBBUTTONINFO* btnInfo) {
   assert(idButton >= 0);
   assert(btnInfo > 0);
@@ -172,5 +181,21 @@ bool ToolBar::setButtonSize(int width, int height) {
 }
 
 void ToolBar::autoSize() {
-  SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
+  DWORD style = SendMessage(getHandle(), TB_GETSTYLE,  0, 0);
+  if (style & CCS_NORESIZE) {
+    RECT r, btnRect;
+    GetClientRect(parentHwnd, &r);
+    getButtonRect(0, &btnRect);
+    int height = getButtonsHeight() + btnRect.top * 2 + 1;
+    SetWindowPos(getHandle(), HWND_TOP, 0, 0, r.right - r.left, height, 
+      SWP_NOMOVE);
+  } else {
+    SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
+  }
+}
+
+int ToolBar::getHeight() {
+  RECT r;
+  GetWindowRect(getHandle(), &r);
+  return r.bottom - r.top + 1;
 }
index 18061739a923e0554410283a603a295ce41a648b..d1c0d0ad8bf782da456e24a33e490315314c264f 100644 (file)
@@ -67,6 +67,12 @@ public:
   // It returns index of the button if successful, or -1 otherwise.
   int getButtonInfo(int idButton, TBBUTTONINFO *btnInfo);
 
+  // getButtonsHeight() retrieves the height of the toolbar buttons.
+  int getButtonsHeight();
+
+  // getButtonsWidth() retrieves the width of the toolbar buttons.
+  int getButtonsWidth();
+
   // setButtonInfo() sets the information for an existing button in a toolbar.
   bool setButtonInfo(int idButton, TBBUTTONINFO* ptbbi);
 
@@ -94,7 +100,11 @@ public:
   // getHandle() returns handle to a toolbar window.
   HWND getHandle() { return hwndToolBar; }
 
+  // getHeight() returns the toolbar window height.
+  int getHeight();
+
 protected:
   HWND hwndToolBar;
+  HWND parentHwnd;
   int tbID;
 };