wwrcdpnl.pas

来自「infopower 4000 for delphi 2006」· PAS 代码 · 共 1,684 行 · 第 1/5 页

PAS
1,684
字号
               strGetToken(Selected[i], #9, APos);
               curFieldDisplayLabel:= strGetToken(Selected[i], #9, APos);  { 6/4/97}
               curFieldReadOnly := (strGetToken(Selected[i], #9, APos) = 'T');
            end
         end;
         if not ShowField(curfield, curFieldReadOnly) then continue;
         MaxLabelWidth:= wwMax(MaxLabelWidth,
                          Bitmap.Canvas.TextWidth(curFieldDisplayLabel));
      end;

      LabelWidth:= MaxLabelWidth;
      Bitmap.Canvas.Font := Font;
            { Limit form length }
      EditStartOffset:= Margin.LeftOffset + labelWidth + EditSpacing.VerticalView.BetweenLabelEdit;

      { Compute desired form length }
      MaxEditWidth:= 0;
      curFieldDisplayWidth:= 0;

      for i:= 0 to numFields-1 do begin
         if (Selected.count=0) or FuseTFields then
         begin
            curField:= DataSource.dataset.fields[i];
            curFieldDisplayWidth:= curField.DisplayWidth;
            curFieldReadOnly:= curField.ReadOnly;
         end
         else begin
            APos:= 1;
            curField:= DataSource.dataset.findField(strGetToken(Selected[i], #9, APos));
            if curfield<>nil then
            begin
               curFieldDisplayWidth:= strToInt(strGetToken(Selected[i], #9, APos));
               strGetToken(Selected[i], #9, APos); { Display label }
               curFieldReadOnly := (strGetToken(Selected[i], #9, APos) = 'T')
            end
         end;
         if not ShowField(curfield, curFieldReadOnly) then continue;

         MaxEditWidth:= wwmax(MaxEditWidth,
               (CurFieldDisplayWidth+1) * Bitmap.Canvas.TextWidth('0') + 3);
      end;

      MaxEditWidth:= 0;
      EditHeight:= 8;
      NextTabOrder:= 0;
      FixedEditWidth:= Width - (EditStartOffset + Margin.RightOffset + FixedEditWidthConst);
      if BorderStyle=bsSingle then FixedEditWidth:= FixedEditWidth - 4;

      for i:= 0 to numFields-1 do begin
         if (Selected.count=0) or FuseTFields then
         begin
            curField:= DAtaSource.dataset.fields[i];
            curFieldDisplayWidth:= curField.displayWidth;
            curFieldDisplayLabel:= curField.displayLabel;
            curFieldReadOnly:= curField.readonly;
         end
         else begin
            APos:= 1;
            curField:= DAtaSource.dataset.findField(strGetToken(Selected[i], #9, APos));
            if curfield<>nil then begin
               curFieldDisplayWidth:= strToInt(strGetToken(Selected[i], #9, APos));
               curFieldDisplayLabel:= strGetToken(Selected[i], #9, APos);  { 6/4/97}
               curFieldReadOnly :=strGetToken(Selected[i], #9, APos) = 'T'
            end
         end;
         if not ShowField(curfield, curFieldReadOnly) then continue;

         accept:= True;
         if Recreate then
            DoOnBeforeCreateControl(self, curField, accept);
         if not accept then continue;

         curLabel:= nil;
         curEditControl:= nil;

         if (not Recreate)  then begin
            for j:= 0 to CustomControlList.count-1 do begin
               TwwCustomControlItem(CustomControlList[j]).control.parent:= self;
            end;
            for j:= 0 to ControlCount-1 do begin
               if TControl(Controls[j]) is TWinControl then begin
                  if wwEqualStr(wwGetControlDataField(TWinControl(Controls[j])),
                                curField.fieldname) then
                  begin
                     curEditControl:= Controls[j];
                     break;
                  end
               end
            end;
            if curEditControl<>Nil then begin
               for j:= 0 to ControlCount-1 do begin
                  if TControl(Controls[j]) is TLabel then begin
                     curLabel:= TLabel(Controls[j]);
                     if TLabel(Controls[j]).FocusControl=curEditControl then
                     begin
                        curLabel:= TLabel(Controls[j]);
                        break;
                     end
                  end
               end
            end
            else continue; { 3/11/99 - No edit control exists for this field }
         end;

         if curLabel=Nil then begin
            if (rvopUseCustomControls in Options) and
               wwIsCheckbox(self, curField, checkboxOn, checkboxOff) then
               curLabel:= TwwLabel.create(self)
            else
               curLabel:= TLabel.create(self);
         end;
         self.curlabel:= curLabel;

         with curLabel do begin
            if recreate then begin
              parent:= self;
//              AutoSize:= True; { 12/23/98 - Right alignment for labels }
              AutoSize:= False;
              Width:= LabelWidth;

              font:= self.labelFont;
              Caption:= strReplaceChar(curfieldDisplayLabel, '~', ' ');
              alignment:= taRightJustify;
            end
            else begin
              if AutoSize<>False then AutoSize:= False;
              if Width<>LabelWidth then Width:= LabelWidth;
              if Alignment<>taRightJustify then alignment:= taRightJustify;
            end;

            font:= self.labelFont;

            ControlPositionLeft:= Margin.LeftOffset;
            if (rvopUseCustomControls in Options) and
               wwIsCheckbox(self, curField, checkboxOn, checkboxOff) then
               ControlPositionTop:= PrevTop + 1
            else
               ControlPositionTop:= PrevTop + 4;

            if recreate then
            begin
               Left:= ControlPositionLeft;
               Top:= ControlPositionTop;
            end
            else AddControlPosition(curLabel,
                      ControlPositionLeft, ControlPositionTop, curlabel.Width, curLabel.Height);
         end;

         if Recreate then
         begin
            if rvcTransparentLabels in ControlOptions then curLabel.transparent:= true;
            DoOnAfterCreateControl(self, curField, curLabel);
         end;

         if (rvopUseCustomControls in Options) and
            wwIsCheckbox(self, curField, checkboxOn, checkboxOff) then
         begin
            if (not Recreate) and (curEditControl<>Nil) then
            begin
               checkbox:= TwwDBCheckBox(curEditControl);
               ControlPositionLeft:= EditStartOffset;
               ControlPositionTop:= PrevTop;
               AddControlPosition(CheckBox, ControlPositionLeft, ControlPositionTop,
                                   Checkbox.Width, Checkbox.Height);
            end
            else begin
               checkbox:= TwwDBCheckBox.create(self);
               checkbox.LabelControl:= curLabel;
               curLabel.FocusControl:= checkBox;
               with checkbox do begin
                 parent:= self;
                 datasource:= self.DataSource;
                 datafield:= curfield.fieldName;
                 caption:= '';
                 valueChecked:= checkboxOn;
                 valueUnchecked:= checkboxOff;
                 Width:= 17;
                 left:= EditStartOffset; {EditPosition.LeftOffset + LabelWidth + 5;}
                 Top:= PrevTop;

                 if curFieldReadOnly or Field.calculated then
                 begin
                    tabStop:= False;
                    Enabled:=False; { 3/9/99 - Readonly checkbox }
                 end;
              end;
              if Recreate then
                 DoOnAfterCreateControl(self, curField, checkbox);
            end;

            MaxEditWidth:= wwmax(MaxEditWidth, checkbox.Width);
            PrevTop:= Prevtop + checkbox.Height + EditSpacing.VerticalView.BetweenRow;
            EditHeight:= checkbox.Height;

            { 9/20/98 - Set tab orders for checkbox }
            checkbox.TabOrder:= NextTabOrder;  { 3/11/99 - Previously didn't have checkbox.taborder }
            inc(NextTabOrder);
         end
         else if UseCustomControls and
            IsCustomEditCell(curField, customEdit) then
         with TEdit(CustomEdit) do begin
            curLabel.FocusControl:= CustomEdit;

            if Recreate then begin
               AddCustomControl(CustomEdit);
               parent:= self;
               if not wwSetControlDataSource(customEdit, datasource) then continue;
               if not wwSetControlDataField(customEdit, '') then continue;
               if not wwSetControlDataField(customEdit, curField.fieldName) then continue;
            end
            else parent:= self;

//            visible:= True; { Causes custom control's to flicker when coming up }
            Ctl3d:= True;
            if not HasFrame(customEdit) then BorderStyle:= bsSingle;
            ControlPositionLeft:= EditStartOffset;
            ControlPositionTop:= PrevTop;

            if (wwisclass(customedit.classtype,'TwwCustomRichEdit')) then
               TempWidth:= FixedEditWidth
            else
               TempWidth:= (curFieldDisplayWidth+1) * Bitmap.Canvas.TextWidth('0') + 3;

            if rvopShortenEditBox in Options then begin
               if TempWidth>FixedEditWidth then TempWidth:= FixedEditWidth;
            end;
            if rvopConsistentEditWidth in Options then begin
               if TempWidth<FixedEditWidth then TempWidth:= FixedEditWidth;
            end;

            TEdit(CustomEdit).HandleNeeded;

            if not Recreate then begin
               ControlPositionWidth:= TempWidth;
               ControlPositionHeight:= CustomEdit.Height;
               AddControlPosition(CustomEdit, ControlPositionLeft, ControlPositionTop,
                                 TempWidth, ControlPositionHeight);
            end
            else begin
               Left:= ControlPositionLeft;
               Top:= ControlPositionTop;
               OldWidth:= CustomEdit.Width; { 10/22/98 - Respect width change }
               if (Patch[0]=True) and curFieldReadOnly then
               begin
                  CustomEdit.tabStop:= not curFieldReadOnly;
                  CustomEdit.enabled:= not curFieldReadOnly;
                  TEdit(CustomEdit).Color:= ReadOnlyColor;
               end;
               DoOnAfterCreateControl(self, curField, CustomEdit);
               if CustomEdit.Width<>OldWidth then TempWidth:= CustomEdit.Width; { 10/22/98 }
               customEdit.Width:= TempWidth;
            end;

            MaxEditWidth:= wwmax(MaxEditWidth, TempWidth);
            PrevTop:= Prevtop + customEdit.Height + EditSpacing.VerticalView.BetweenRow;
            EditHeight:= customEdit.Height;

            tabOrder:= NextTabOrder;
            inc(NextTabOrder);
         end
         else if (curField is TDateTimeField) and
                 (rvopUseDateTimePicker in Options) then
         begin
            if recreate or (curEditControl=Nil) then
               EditControl:= TwwDBDateTimePicker.create(self)
            else EditControl:= TwwDBDateTimePicker(curEditControl);
            if not CreateEditControl(EditControl) then continue;
         end
         else if (not (csDesigning in ComponentState)) and
            wwIsRichEditField(curField, True) then begin
            if recreate or (curEditControl=Nil) then EditControl:= TwwDBRichEdit.create(self)
            else EditControl:= TwwDBRichEdit(curEditControl);
            if not CreateEditControl(EditControl) then continue;
         end
         else if (curField.dataType = ftMemo) then begin
            if recreate or (curEditControl=Nil) then
            begin
               if EditFrame.IsFrameEffective then
                  EditControl:= TwwDBEditMemo.create(self)
               else
                  EditControl:= TwwDBMemo.create(self)
            end
            else EditControl:= TWinControl(curEditControl);
            if not CreateEditControl(EditControl) then continue;
         end
         else if (curField.dataType = ftGraphic) then begin { 8/27/98 - Support images }
            if recreate or (curEditControl=Nil) then editControl:= TDBImage.create(self)
            else EditControl:= TWinControl(curEditControl);
            if not CreateEditControl(EditControl) then continue;
         end
         else begin
            if recreate or (curEditControl=Nil) then begin
               EditControl:= CreateDefaultEditControl(self);
//               EditControl:= TwwDBEdit.create(self);
               EditControl.controlStyle:= EditControl.ControlStyle + [csNoDesignVisible];
            end
            else EditControl:= TWinControl(curEditControl);
            if not CreateEditControl(EditControl) then continue;
         end
      end;

      PrevTop := PrevTop + Margin.BottomOffset - EditSpacing.VerticalView.BetweenRow;

      VertScrollBar.Margin:= 6;
      VertScrollBar.Increment:= EditHeight + EditSpacing.VerticalView.BetweenRow;
      VertScrollBar.Range := PrevTop;

      { Shrink edit controls to fit panel width }
      if (Height<PrevTop) then
      begin
          {$ifdef wwDelphi4up}
          ShowingVertScrollBar:= True;
          {$else}
          ShowingVertScrollBar:= False; { Skip Delphi 4 specific code for setting horz scroll range }
          {$endif}
          FixedEditWidth:= FixedEditWidth - GetSystemMetrics(SM_CXHThumb);
          if Recreate then begin
            for j:= 0 to ControlCount-1 do begin
               if TControl(Controls[j]) is TWinControl then begin
                  curEditControl:= Controls[j];
                  if ((rvopShortenEditBox in Options) or
                      (rvopConsistentEditWidth in Options) or
                      (not isSingleLineEditControl(TWinControl(curEditControl)))) then
                     if (curEditControl.Width>FixedEditWidth) then
                     begin
                        curEditControl.Width:= FixedEditWidth;
                     end
               end;
            end
          end
          else begin
             for j:= 0 to ControlPositions.count-1 do
             begin
                cp:= TControlPosition(ControlPositions[j]);
                with cp do
                begin
                   if Control is TWinControl then

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?