[haiku-commits] r39199 - in haiku/trunk: headers/libs/print/libprint src/libs/print/libprint

  • From: michael.w.pfeiffer@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 30 Oct 2010 11:43:26 +0200 (CEST)

Author: laplace
Date: 2010-10-30 11:43:26 +0200 (Sat, 30 Oct 2010)
New Revision: 39199
Changeset: http://dev.haiku-os.org/changeset/39199

Modified:
   haiku/trunk/headers/libs/print/libprint/AddPrinterDlg.h
   haiku/trunk/src/libs/print/libprint/AddPrinterDlg.cpp
Log:
* Use Layout API


Modified: haiku/trunk/headers/libs/print/libprint/AddPrinterDlg.h
===================================================================
--- haiku/trunk/headers/libs/print/libprint/AddPrinterDlg.h     2010-10-30 
08:54:52 UTC (rev 39198)
+++ haiku/trunk/headers/libs/print/libprint/AddPrinterDlg.h     2010-10-30 
09:43:26 UTC (rev 39199)
@@ -17,10 +17,10 @@
 
 class ProtocolClassItem : public BStringItem {
 public:
-       ProtocolClassItem(const ProtocolClassCap* cap);
+                                       ProtocolClassItem(const 
ProtocolClassCap* cap);
 
-       int getProtocolClass();
-       const char *getDescription();
+               int                     getProtocolClass();
+               const char*     getDescription();
 
 private:
        const ProtocolClassCap *fProtocolClassCap;      
@@ -28,14 +28,14 @@
 
 class AddPrinterView : public BView {
 public:
-                                       AddPrinterView(BRect frame, 
PrinterData* printerData,
+                                       AddPrinterView(PrinterData* printerData,
                                                const PrinterCap* printerCap);
                                        ~AddPrinterView();
        virtual void    AttachedToWindow();
-                       void    FrameResized(float w, float h);
                        void    MessageReceived(BMessage* msg);
 
-       void Save();
+                       void    Save();
+
 private:
        ProtocolClassItem*      CurrentSelection();
 

Modified: haiku/trunk/src/libs/print/libprint/AddPrinterDlg.cpp
===================================================================
--- haiku/trunk/src/libs/print/libprint/AddPrinterDlg.cpp       2010-10-30 
08:54:52 UTC (rev 39198)
+++ haiku/trunk/src/libs/print/libprint/AddPrinterDlg.cpp       2010-10-30 
09:43:26 UTC (rev 39199)
@@ -1,85 +1,11 @@
 #include "AddPrinterDlg.h"
 
+#include <GroupLayoutBuilder.h>
+
 #include "PrinterCap.h"
 #include "PrinterData.h"
 
-#define DIALOG_WIDTH 400
 
-#define BUTTON_WIDTH           70
-#define BUTTON_HEIGHT          20
-#define TEXT_HEIGHT         16
-
-#define BOX_TOP_INSET       18
-#define BOX_BOTTOM_INSET    10
-#define BOX_H_INSET         10
-
-#define PROTOCOL_CLASS_BOX_H      10
-#define PROTOCOL_CLASS_BOX_V      10
-#define PROTOCOL_CLASS_BOX_WIDTH  DIALOG_WIDTH - 20
-#define PROTOCOL_CLASS_BOX_HEIGHT 125
-
-#define PROTOCOL_CLASS_H          BOX_H_INSET
-#define PROTOCOL_CLASS_V          BOX_TOP_INSET
-#define PROTOCOL_CLASS_WIDTH      PROTOCOL_CLASS_BOX_WIDTH - 2 * BOX_H_INSET 
-#define PROTOCOL_CLASS_HEIGHT     PROTOCOL_CLASS_BOX_HEIGHT - BOX_TOP_INSET - 
BOX_BOTTOM_INSET
-
-#define DESCRIPTION_BOX_H         PROTOCOL_CLASS_BOX_H
-#define DESCRIPTION_BOX_V         PROTOCOL_CLASS_BOX_V + 
PROTOCOL_CLASS_BOX_HEIGHT + 10
-#define DESCRIPTION_BOX_WIDTH     PROTOCOL_CLASS_BOX_WIDTH
-#define DESCRIPTION_BOX_HEIGHT    125
-
-#define DESCRIPTION_H         BOX_H_INSET
-#define DESCRIPTION_V         BOX_TOP_INSET
-#define DESCRIPTION_WIDTH     DESCRIPTION_BOX_WIDTH - 2 * BOX_H_INSET 
-#define DESCRIPTION_HEIGHT    DESCRIPTION_BOX_HEIGHT - BOX_TOP_INSET - 
BOX_BOTTOM_INSET
-
-#define DIALOG_HEIGHT         DESCRIPTION_BOX_V + DESCRIPTION_BOX_HEIGHT + 
BUTTON_HEIGHT + 20
-
-#define OK_H                           (DIALOG_WIDTH  - BUTTON_WIDTH  - 11)
-#define OK_V                           (DIALOG_HEIGHT - BUTTON_HEIGHT - 11)
-#define OK_TEXT                                "OK"
-
-#define CANCEL_H                       (OK_H - BUTTON_WIDTH - 12)
-#define CANCEL_V                       OK_V
-#define CANCEL_TEXT                    "Cancel"
-
-const BRect PROTOCOL_CLASS_BOX_RECT(
-       PROTOCOL_CLASS_BOX_H,
-       PROTOCOL_CLASS_BOX_V,
-       PROTOCOL_CLASS_BOX_H + PROTOCOL_CLASS_BOX_WIDTH ,
-       PROTOCOL_CLASS_BOX_V + PROTOCOL_CLASS_BOX_HEIGHT);
-
-const BRect PROTOCOL_CLASS_RECT(
-       PROTOCOL_CLASS_H,
-       PROTOCOL_CLASS_V,
-       PROTOCOL_CLASS_H + PROTOCOL_CLASS_WIDTH - B_V_SCROLL_BAR_WIDTH,
-       PROTOCOL_CLASS_V + PROTOCOL_CLASS_HEIGHT);
-
-const BRect DESCRIPTION_BOX_RECT(
-       DESCRIPTION_BOX_H,
-       DESCRIPTION_BOX_V,
-       DESCRIPTION_BOX_H + DESCRIPTION_BOX_WIDTH,
-       DESCRIPTION_BOX_V + DESCRIPTION_BOX_HEIGHT);
-       
-const BRect DESCRIPTION_RECT(
-       DESCRIPTION_H,
-       DESCRIPTION_V,
-       DESCRIPTION_H + DESCRIPTION_WIDTH - B_V_SCROLL_BAR_WIDTH,
-       DESCRIPTION_V + DESCRIPTION_HEIGHT);
-
-const BRect OK_RECT(
-       OK_H,
-       OK_V,
-       OK_H + BUTTON_WIDTH,
-       OK_V + BUTTON_HEIGHT);
-
-const BRect CANCEL_RECT(
-       CANCEL_H,
-       CANCEL_V,
-       CANCEL_H + BUTTON_WIDTH,
-       CANCEL_V + BUTTON_HEIGHT);
-
-
 enum MSGS {
        kMsgCancel = 1,
        kMsgOK,
@@ -107,14 +33,13 @@
 }
 
 
-AddPrinterView::AddPrinterView(BRect frame, PrinterData* printerData,
+AddPrinterView::AddPrinterView(PrinterData* printerData,
        const PrinterCap* printerCap)
        :
-       BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
+       BView("addPrinter", B_WILL_DRAW),
        fPrinterData(printerData),
        fPrinterCap(printerCap)
 {
-       SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
 }
 
 
@@ -127,29 +52,25 @@
 AddPrinterView::AttachedToWindow()
 {
        // protocol class box
-       BBox *box;
-       box = new BBox(PROTOCOL_CLASS_BOX_RECT, NULL,
-               B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
-       box->SetLabel("Protocol Classes:");
-       AddChild(box);
+       BBox* protocolClassBox = new BBox("protocolClass");
+       protocolClassBox->SetLabel("Protocol Classes:");
        
        // protocol class
-       fProtocolClassList = new BListView(
-               PROTOCOL_CLASS_RECT, 
-               "protocolClassList", 
-               B_SINGLE_SELECTION_LIST, 
-               B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
-       box->AddChild(new BScrollView(
+       fProtocolClassList = new BListView("protocolClassList");
+       fProtocolClassList->SetExplicitMinSize(BSize(500, 200));
+       BScrollView* protocolClassScroller = new BScrollView(
                "protocolClassListScroller", 
                fProtocolClassList, 
-               B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, 
                0, 
                false, 
-               true));
+               true,
+               B_NO_BORDER);
        fProtocolClassList->SetSelectionMessage(
                new BMessage(kMsgProtocolClassChanged));
        fProtocolClassList->SetTarget(this);
        
+       protocolClassBox->AddChild(protocolClassScroller);
+
        int count = fPrinterCap->countCap(PrinterCap::kProtocolClass);
        ProtocolClassCap **protocolClasses =
                (ProtocolClassCap 
**)fPrinterCap->enumCap(PrinterCap::kProtocolClass);
@@ -166,31 +87,47 @@
        }
        
        // description of protocol class box
-       box = new BBox(DESCRIPTION_BOX_RECT, NULL, B_FOLLOW_ALL_SIDES);
-       box->SetLabel("Description:");
-       AddChild(box);
+       BBox* descriptionBox = new BBox("descriptionBox");
+       descriptionBox->SetLabel("Description:");
 
        // description of protocol class
-       BRect textRect(DESCRIPTION_RECT);
-       textRect.OffsetTo(0, 0);
-       fDescription = new BTextView(DESCRIPTION_RECT, "description", textRect,
-               B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
-       fDescription->SetViewColor(box->ViewColor());
-       box->AddChild(new BScrollView("descriptionScroller", fDescription, 
-               B_FOLLOW_ALL_SIDES, 0, false, true, B_NO_BORDER));
+       fDescription = new BTextView("description");
+       fDescription->SetExplicitMinSize(BSize(200, 200));
+       fDescription->SetViewColor(descriptionBox->ViewColor());
+       BScrollView* descriptionScroller = new 
BScrollView("descriptionScroller",
+                       fDescription,
+                       0,
+                       false,
+                       true,
+                       B_NO_BORDER);
        fDescription->MakeEditable(false);
 
-       // cancel
-       BButton *button;
-       button = new BButton(CANCEL_RECT, "", CANCEL_TEXT, new 
BMessage(kMsgCancel),
-               B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
-       AddChild(button);
+       descriptionBox->AddChild(descriptionScroller);
 
-       // ok
-       button = new BButton(OK_RECT, "", OK_TEXT, new BMessage(kMsgOK),
-               B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
-       AddChild(button);
-       button->MakeDefault(true);
+       // separator line
+       BBox *separator = new BBox("separator");
+       separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
+
+       // buttons
+       BButton* cancel = new BButton("cancel", "Cancel",
+               new BMessage(kMsgCancel));
+       BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK));
+       ok->MakeDefault(true);
+
+       SetLayout(new BGroupLayout(B_VERTICAL));
+       AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
+               .Add(protocolClassBox)
+               .Add(descriptionBox)
+               .AddGlue()
+               .Add(separator)
+               .AddGroup(B_HORIZONTAL, 10, 1.0f)
+                       .AddGlue()
+                       .Add(cancel)
+                       .Add(ok)
+               .End()
+               .SetInsets(0, 0, 0, 0)
+       );
+
        
        // update description
        BMessage updateDescription(kMsgProtocolClassChanged);
@@ -198,17 +135,6 @@
 }
 
 
-void
-AddPrinterView::FrameResized(float w, float h)
-{
-       BView::FrameResized(w, h);
-       // update text rectangle
-       BRect rect(fDescription->TextRect());
-       rect.right = rect.left + fDescription->Frame().Width();
-       fDescription->SetTextRect(rect);
-}
-
-
 ProtocolClassItem*
 AddPrinterView::CurrentSelection()
 {
@@ -248,21 +174,19 @@
 AddPrinterDlg::AddPrinterDlg(PrinterData* printerData,
        const PrinterCap *printerCap)
        :
-       DialogWindow(BRect(100, 100, 100 + DIALOG_WIDTH, 100 + DIALOG_HEIGHT),
+       DialogWindow(BRect(100, 100, 120, 120),
                "Add Printer", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
-               B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
+               B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS
+                       | B_AUTO_UPDATE_SIZE_LIMITS)
 {
        SetResult(B_ERROR);
 
-       // increase min. window size    
-       float minWidth, maxWidth, minHeight, maxHeight;
-       GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
-       minHeight = DIALOG_HEIGHT;
-       minWidth = DIALOG_WIDTH;
-       SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
-       
-       fAddPrinterView = new AddPrinterView(Bounds(), printerData, printerCap);
-       AddChild(fAddPrinterView);
+       fAddPrinterView = new AddPrinterView(printerData, printerCap);
+       SetLayout(new BGroupLayout(B_VERTICAL));
+       AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
+               .Add(fAddPrinterView)
+               .SetInsets(10, 10, 10, 10)
+       );
 }
 
 


Other related posts:

  • » [haiku-commits] r39199 - in haiku/trunk: headers/libs/print/libprint src/libs/print/libprint - michael . w . pfeiffer